using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsOpSocCtn; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using HcUtility.Core; using System.Data.SqlClient; using DSWeb.DataAccess; using DSWeb.MvcShipping.Models.MsCodeServiceFeeTemplate; using DSWeb.MvcShipping.DAL.MsCodeServiceFeeTemplateDAL; using System.Web; using DSWeb.MvcShipping.Models.MsSysBillNoSet; using DSWeb.MvcShipping.DAL.MsSysBillNoSet; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using DSWeb.MvcShipping.Models.MsChFee; namespace DSWeb.MvcShipping.DAL.MsOpSocCtnDAL { public class MsOpSocCtnDAL { #region Inquery DataList static public List GetDataList(int start, int limit, out int totel, string strCondition, string userid, string usercode, string companyid, string sort = null) { var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME DESC "); } strSql.Append(@") as num , "); strSql.Append(" [BSNO],[CONTRACTNO],[CONTRACTDATE],[CUSTOMERNAME],[CUSTOMERATTN],[CUSTOMERTEL],[BSSTATUS],[CLOSEDOCDATE],CNTRTOTAL"); strSql.Append(",[CLOSEFEEDATE],[CORPID],[PORTLOAD],[PORTDISCHARGE],[DEPOSIT],[RENT],[RETURNDEPOSITDATE],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=b.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=b.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(",ISNULL((select COUNT(1) FROM op_socctn_ctndetail WHERE ISNULL(BS_BSNO,'')<>'' AND BSNO=B.BSNO),0) as LOADCTNCOUNT"); strSql.Append(" from op_socctn_contract b "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); // totel = getTotalCount(strCondition); return SetData(strSql.ToString()); } public static int getTotalCount(string strCondition) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) from op_socctn_contract b"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } static public string GetDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } // String strSql = "SELECT [BSNO],[CONTRACTNO],[CONTRACTDATE],[CUSTOMERNAME],[CUSTOMERATTN],[CUSTOMERTEL],[BSSTATUS],[CLOSEDOCDATE],CNTRTOTAL"; strSql = strSql + ",[CLOSEFEEDATE],[CORPID],[PORTLOAD],[PORTDISCHARGE],[DEPOSIT],[RENT],[RETURNDEPOSITDATE],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"; strSql = strSql + ",(select ShowName from [user] where GID=b.CREATEUSER) as CREATEUSERREF"; strSql = strSql + ",(select ShowName from [user] where GID=b.MODIFIEDUSER) as MODIFIEDUSERREF"; strSql = strSql + ",ISNULL((select COUNT(1) FROM op_socctn_ctndetail WHERE ISNULL(BS_BSNO,'')<>'' AND BSNO=B.BSNO),0) as LOADCTNCOUNT"; strSql = strSql + " from op_socctn_contract b "; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by CREATETIME desc"; } return strSql.ToString(); } static public MsOpSocCtnContract GetData(string condition) { var strSql = new StringBuilder(); strSql.Append("SELECT [BSNO],[CONTRACTNO],[CONTRACTDATE],[CUSTOMERNAME],[CUSTOMERATTN],[CUSTOMERTEL],[BSSTATUS],[CLOSEDOCDATE],CNTRTOTAL"); strSql.Append(",[CLOSEFEEDATE],[CORPID],[PORTLOAD],[PORTDISCHARGE],[DEPOSIT],[RENT],[RETURNDEPOSITDATE],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=b.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=b.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(",ISNULL((select COUNT(1) FROM op_socctn_ctndetail WHERE ISNULL(BS_BSNO,'')<>'' AND BSNO=B.BSNO),0) as LOADCTNCOUNT"); strSql.Append(" from op_socctn_contract b "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } var list=SetData(strSql.ToString()); if (list.Count > 0) { return list[0]; } return new MsOpSocCtnContract(); } private static List SetData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpSocCtnContract data = new MsOpSocCtnContract(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.BSSTATUS = Convert.ToString(reader["BSSTATUS"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); if (reader["CONTRACTDATE"] != DBNull.Value) data.CONTRACTDATE = Convert.ToDateTime(reader["CONTRACTDATE"]).ToString("yyyy-MM-dd"); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CUSTOMERATTN = Convert.ToString(reader["CUSTOMERATTN"]); data.CUSTOMERTEL = Convert.ToString(reader["CUSTOMERTEL"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); if (reader["CLOSEDOCDATE"] != DBNull.Value) data.CLOSEDOCDATE = Convert.ToDateTime(reader["CLOSEDOCDATE"]).ToString("yyyy-MM-dd"); if (reader["CLOSEFEEDATE"] != DBNull.Value) data.CLOSEFEEDATE = Convert.ToDateTime(reader["CLOSEFEEDATE"]).ToString("yyyy-MM-dd"); if (reader["DEPOSIT"] != DBNull.Value) data.DEPOSIT = Convert.ToDecimal(reader["DEPOSIT"]); if (reader["RENT"] != DBNull.Value) data.RENT = Convert.ToDecimal(reader["RENT"]); if (reader["RETURNDEPOSITDATE"] != DBNull.Value) data.RETURNDEPOSITDATE = Convert.ToDateTime(reader["RETURNDEPOSITDATE"]).ToString("yyyy-MM-dd"); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]); data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]); if (reader["LOADCTNCOUNT"] != DBNull.Value) data.LOADCTNCOUNT = Convert.ToInt32(reader["LOADCTNCOUNT"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult DeleteOpSocContract(MsOpSocCtnContract headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdDelete = db.GetSqlStringCommand("delete from op_socctn_ctn where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDelete, tran); var cmdDeleteDetail = db.GetSqlStringCommand("delete from op_socctn_ctndetail where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDeleteDetail, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult LockOpSocContract(MsOpSocCtnContract headData,string type,string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdDelete = db.GetSqlStringCommand("update op_socctn_contract set BSSTATUS='"+type+"',MODIFIEDUSER='" + userid + "',MODIFIEDTIME=GETDATE() where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDelete, tran); //if (type == "1") //{ // var cmdDelete = db.GetSqlStringCommand("update op_socctn_contract set BSSTATUS='正在执行',MODIFIEDUSER='"+userid+ "',MODIFIEDTIME=GETDATE() where BSNO='" + headData.BSNO + "'"); // db.ExecuteNonQuery(cmdDelete, tran); //} //else { // var cmdDelete = db.GetSqlStringCommand("update op_socctn_contract set BSSTATUS='新建',MODIFIEDUSER='" + userid + "',MODIFIEDTIME=GETDATE() where BSNO='" + headData.BSNO + "'"); // db.ExecuteNonQuery(cmdDelete, tran); //} tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "更新成功"; return result; } public static DBResult LockOpSocBs(MsOpSocCtnContract headData, string type, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdDelete = db.GetSqlStringCommand("update op_socctn_bs set BSSTATUS='" + type + "',MODIFIEDUSER='" + userid + "',MODIFIEDTIME=GETDATE() where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDelete, tran); var strSql = new StringBuilder(); strSql.Append("update op_socctn_ctndetail set CTNSTATUS='待使用',BS_BSNO='' "); strSql.Append(" where BS_BSNO=@BS_BSNO "); var cmdupdate = db.GetSqlStringCommand(strSql.ToString()); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BS_BSNO", DbType.String, headData.BSNO); db.ExecuteNonQuery(cmdupdate, tran); //if (type == "1") //{ // var cmdDelete = db.GetSqlStringCommand("update op_socctn_contract set BSSTATUS='正在执行',MODIFIEDUSER='"+userid+ "',MODIFIEDTIME=GETDATE() where BSNO='" + headData.BSNO + "'"); // db.ExecuteNonQuery(cmdDelete, tran); //} //else { // var cmdDelete = db.GetSqlStringCommand("update op_socctn_contract set BSSTATUS='新建',MODIFIEDUSER='" + userid + "',MODIFIEDTIME=GETDATE() where BSNO='" + headData.BSNO + "'"); // db.ExecuteNonQuery(cmdDelete, tran); //} tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "更新成功"; return result; } static public List GetBsDataList(int start, int limit, out int totel, string strCondition, string userid, string usercode, string companyid, string sort = null) { var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME DESC "); } strSql.Append(@") as num , "); strSql.Append(" [BSNO],[MBLNO],[CORPID],[VESSEL],[VOYNO],[ETD],[PORTLOAD],[PORTDISCHARGE],CNTRTOTAL,BSSTATUS"); strSql.Append(",[TRANSPORT],[ETA],[AGENT],[RTCTNDATE],[RTCTNYARD],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=b.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=b.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(" from op_socctn_bs b "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); // totel = getBsTotalCount(strCondition); return SetBsData(strSql.ToString()); } public static int getBsTotalCount(string strCondition) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) from op_socctn_bs b"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } static public string GetBsDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null) { String strSql = "SELECT [BSNO],[MBLNO],[CORPID],[VESSEL],[VOYNO],[ETD],[PORTLOAD],[PORTDISCHARGE],CNTRTOTA,BSSTATUSL"; strSql = strSql + ",[TRANSPORT],[ETA],[AGENT],[RTCTNDATE],[RTCTNYARD],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"; strSql = strSql + " from op_socctn_bs b "; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by CREATETIME desc"; } return strSql.ToString(); } static public MsOpSocCtnBs GetBsData(string condition) { var strSql = new StringBuilder(); strSql.Append(" SELECT [BSNO],[MBLNO],[CORPID],[VESSEL],[VOYNO],[ETD],[PORTLOAD],[PORTDISCHARGE],CNTRTOTAL,BSSTATUS"); strSql.Append(",[TRANSPORT],[ETA],[AGENT],[RTCTNDATE],[RTCTNYARD],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=b.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=b.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(" from op_socctn_bs b "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } var list = SetBsData(strSql.ToString()); if (list.Count > 0) { return list[0]; } return new MsOpSocCtnBs(); } private static List SetBsData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpSocCtnBs data = new MsOpSocCtnBs(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.BSSTATUS = Convert.ToString(reader["BSSTATUS"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.CORPID = Convert.ToString(reader["CORPID"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd"); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.TRANSPORT = Convert.ToString(reader["TRANSPORT"]); if (reader["ETA"] != DBNull.Value) data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd"); data.AGENT = Convert.ToString(reader["AGENT"]); if (reader["RTCTNDATE"] != DBNull.Value) data.RTCTNDATE = Convert.ToDateTime(reader["RTCTNDATE"]).ToString("yyyy-MM-dd"); data.RTCTNYARD = Convert.ToString(reader["RTCTNYARD"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 明细表 #region OpSocCtnCtn static public List GetOpSocCtnCtnList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [CTN_ID],[BSNO],[CTNALL],[CTNNUM],[DEPOSITPRICE],[DEPOSIT],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=OP_SOCCTN_CTN.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=OP_SOCCTN_CTN.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(" from op_socctn_ctn "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { // strSql.Append(" order by LINKGID,INSTATOINTIME desc,INPUTTIME desc "); strSql.Append(" order by CREATETIME "); } return SetOpSocCtnCtnData(strSql); } static public string GetOpSocCtnCtnListStr(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [CTN_ID],[BSNO],[CTNALL],[CTNNUM],[DEPOSITPRICE],[DEPOSIT],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=op_socctn_ctn.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=op_socctn_ctn.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(" from op_socctn_ctn "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME "); } return strSql.ToString(); } private static List SetOpSocCtnCtnData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpSocCtnCtn data = new MsOpSocCtnCtn(); #region Set DB data to Object data.CTN_ID = Convert.ToString(reader["CTN_ID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); if (reader["CTNNUM"] != DBNull.Value) data.CTNNUM = Convert.ToInt32(reader["CTNNUM"]); if (reader["DEPOSITPRICE"] != DBNull.Value) data.DEPOSITPRICE = Convert.ToDecimal(reader["DEPOSITPRICE"]); if (reader["DEPOSIT"] != DBNull.Value) data.DEPOSIT = Convert.ToDecimal(reader["DEPOSIT"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveOpSocCtnCtn(List bodyList, string BSNO, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"insert into op_socctn_ctn (CTN_ID,BSNO,CTNALL,CTNNUM,DEPOSITPRICE,DEPOSIT,REMARK,CREATEUSER,CREATETIME,[MODIFIEDUSER],[MODIFIEDTIME]) values (@CTN_ID,@BSNO,@CTNALL,@CTNNUM,@DEPOSITPRICE,@DEPOSIT,@REMARK,@CREATEUSER,@CREATETIME,@MODIFIEDUSER,@MODIFIEDTIME ) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_socctn_ctn set CTNALL=@CTNALL,CTNNUM=@CTNNUM,DEPOSITPRICE=@DEPOSITPRICE,DEPOSIT=@DEPOSIT ,REMARK=@REMARK,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where CTN_ID=@CTN_ID "); var headList = new List(); decimal DEPOSIT = 0; if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.BSNO == "*" || enumValue.BSNO == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@CTN_ID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, BSNO); db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL); db.AddInParameter(cmdInsert, "@CTNNUM", DbType.Int32, enumValue.CTNNUM); db.AddInParameter(cmdInsert, "@DEPOSITPRICE", DbType.Decimal, enumValue.DEPOSITPRICE); db.AddInParameter(cmdInsert, "@DEPOSIT", DbType.Decimal, enumValue.DEPOSIT); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@CTN_ID", DbType.String, enumValue.CTN_ID); db.AddInParameter(cmdUpdate, "@CTNALL", DbType.String, enumValue.CTNALL); db.AddInParameter(cmdUpdate, "@CTNNUM", DbType.Int32, enumValue.CTNNUM); db.AddInParameter(cmdUpdate, "@DEPOSITPRICE", DbType.Decimal, enumValue.DEPOSITPRICE); db.AddInParameter(cmdUpdate, "@DEPOSIT", DbType.Decimal, enumValue.DEPOSIT); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdUpdate, tran); } DEPOSIT = DEPOSIT + enumValue.DEPOSIT; var isfind = false; headList.ForEach(i => { if (i.CTNALL == enumValue.CTNALL) { i.CTNNUM = i.CTNNUM + enumValue.CTNNUM; isfind = true; } }); if (!isfind) { MsOpSocCtnCtn data = new MsOpSocCtnCtn(); data.CTNALL = enumValue.CTNALL; data.CTNNUM = enumValue.CTNNUM; headList.Add(data); } } } string strCNTRTOTAL = ""; foreach (var items in headList) { strCNTRTOTAL = strCNTRTOTAL +" "+ items.CTNALL + "*" + items.CTNNUM; } var cmdUpdateBS = db.GetSqlStringCommand( @"update op_socctn_contract set CNTRTOTAL=@CNTRTOTAL,DEPOSIT=@DEPOSIT where BSNO=@BSNO "); cmdUpdateBS.Parameters.Clear(); db.AddInParameter(cmdUpdateBS, "@CNTRTOTAL", DbType.String, strCNTRTOTAL); db.AddInParameter(cmdUpdateBS, "@DEPOSIT", DbType.Decimal, DEPOSIT); db.AddInParameter(cmdUpdateBS, "@BSNO", DbType.String,BSNO); db.ExecuteNonQuery(cmdUpdateBS, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DBResult InsertSocCtnCtn(List bodyList, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"insert into op_socctn_ctn (CTN_ID,BSNO,CTNALL,CTNNUM,DEPOSITPRICE,DEPOSIT,REMARK,CREATEUSER,CREATETIME) values (@CTN_ID,@BSNO,@CTNALL,@CTNNUM,@DEPOSITPRICE,@DEPOSIT,@REMARK,@CREATEUSER,@CREATETIME ) "); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@CTN_ID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL); db.AddInParameter(cmdInsert, "@CTNNUM", DbType.Int32, enumValue.CTNNUM); db.AddInParameter(cmdInsert, "@DEPOSITPRICE", DbType.Decimal, enumValue.DEPOSITPRICE); db.AddInParameter(cmdInsert, "@DEPOSIT", DbType.Decimal, enumValue.DEPOSIT); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdInsert, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DBResult DeleteOpSocCtnCtn(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_socctn_ctn where CTN_ID='" + enumValue.CTN_ID + "'"); db.ExecuteNonQuery(cmdDelete, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult CreateOpSocCtnCtn(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var headList = new List(); var BSNO = ""; if (headData != null) { foreach (var enumValue in headData) { BSNO = enumValue.BSNO; var ctndetaillist = GetOpSocCtnCtnDetailList("D.CTN_ID='"+ enumValue.CTN_ID + "'"); if (ctndetaillist.Count <= enumValue.CTNNUM) { for (var i= ctndetaillist.Count;i< enumValue.CTNNUM; i++) { MsOpSocCtnCtnDetail data = new MsOpSocCtnCtnDetail(); data.BSNO = enumValue.BSNO; data.CTN_ID = enumValue.CTN_ID; data.CTNALL = enumValue.CTNALL; data.DEPOSITPRICE = enumValue.DEPOSITPRICE; data.CTNSTATUS = "未入场"; data.CTNGID = Guid.NewGuid().ToString(); headList.Add(data); } } } } if (headList != null && headList.Count > 0) { InsertSocCtnCtnDetail(headList,BSNO); } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "生成出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "生成成功"; return result; } #endregion #region OpSocCtnCtnDetail static public List GetOpSocCtnCtnDetailList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT D.[CTNGID],D.[CTN_ID],D.[BSNO],D.[CTNALL],D.[CNTRNO],D.[CTNSTATUS],D.[YARD],D.[INPUTYARDDATE],D.[OUTYARDDATE]"); strSql.Append(",D.[RTCTNDATE],D.[RTCTNYARD],D.[DEPOSITPRICE],D.[REMARK],D.[CREATEUSER],D.[CREATETIME],D.[MODIFIEDUSER],D.[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=D.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=D.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(",B.CONTRACTNO,D.PORTDISCHARGE"); strSql.Append(" from op_socctn_ctnDetail D "); strSql.Append(" left join op_socctn_contract B ON (B.BSNO=D.BSNO) "); strSql.Append(" left join op_socctn_bs BS ON (BS.BSNO=D.BS_BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { // strSql.Append(" order by LINKGID,INSTATOINTIME desc,INPUTTIME desc "); strSql.Append(" order by CREATETIME "); } return SetOpSocCtnCtnDetailData(strSql); } static public string GetOpSocCtnCtnDetailListStr(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT D.[CTNGID],D.[CTN_ID],D.[BSNO],D.[CTNALL],D.[CNTRNO],D.[CTNSTATUS],D.[YARD],D.[INPUTYARDDATE],D.[OUTYARDDATE]"); strSql.Append(",D.[RTCTNDATE],D.[RTCTNYARD],D.[DEPOSITPRICE],D.[REMARK],D.[CREATEUSER],D.[CREATETIME],D.[MODIFIEDUSER],D.[MODIFIEDTIME]"); strSql.Append(",(select ShowName from [user] where GID=D.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=D.MODIFIEDUSER) as MODIFIEDUSERREF"); strSql.Append(",B.CONTRACTNO,D.PORTDISCHARGE"); strSql.Append(" from op_socctn_ctnDetail D "); strSql.Append(" left join op_socctn_contract C ON (C.BSNO=D.BSNO) "); strSql.Append(" left join op_socctn_bs BS ON (BS.BSNO=D.BS_BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME "); } return strSql.ToString(); } private static List SetOpSocCtnCtnDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpSocCtnCtnDetail data = new MsOpSocCtnCtnDetail(); #region Set DB data to Object data.CTNGID = Convert.ToString(reader["CTNGID"]); data.CTN_ID = Convert.ToString(reader["CTN_ID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]); if (reader["INPUTYARDDATE"] != DBNull.Value) data.INPUTYARDDATE = Convert.ToDateTime(reader["INPUTYARDDATE"]).ToString("yyyy-MM-dd"); if (reader["OUTYARDDATE"] != DBNull.Value) data.OUTYARDDATE = Convert.ToDateTime(reader["OUTYARDDATE"]).ToString("yyyy-MM-dd"); if (reader["RTCTNDATE"] != DBNull.Value) data.RTCTNDATE = Convert.ToDateTime(reader["RTCTNDATE"]).ToString("yyyy-MM-dd"); data.RTCTNYARD = Convert.ToString(reader["RTCTNYARD"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); ; data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); data.YARD = Convert.ToString(reader["YARD"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); if (reader["DEPOSITPRICE"] != DBNull.Value) data.DEPOSITPRICE = Convert.ToDecimal(reader["DEPOSITPRICE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveOpSocCtnCtnDetail(List bodyList, string BSNO, string userid) { var result = new DBResult(); var isover = true; var BSNOLIST = new List(); var RTCTNDATE = ""; Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"insert into op_socctn_ctnDetail ([CTNGID],[CTN_ID],[BSNO],[CTNALL],[CNTRNO],[CTNSTATUS],YARD,[INPUTYARDDATE],[OUTYARDDATE],[RTCTNDATE],[RTCTNYARD],[DEPOSITPRICE],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]) values (@CTNGID,@CTN_ID,@BSNO,@CTNALL,@CNTRNO,@CTNSTATUS,@YARD,@INPUTYARDDATE,@OUTYARDDATE,@RTCTNDATE,@RTCTNYARD,@DEPOSITPRICE,@REMARK,@CREATEUSER,@CREATETIME,@MODIFIEDUSER,@MODIFIEDTIME ) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_socctn_ctnDetail set CTNALL=@CTNALL,CNTRNO=@CNTRNO,YARD=@YARD,INPUTYARDDATE=@INPUTYARDDATE,OUTYARDDATE=@OUTYARDDATE,RTCTNDATE=@RTCTNDATE,RTCTNYARD=@RTCTNYARD,DEPOSITPRICE=@DEPOSITPRICE ,REMARK=@REMARK,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where CTNGID=@CTNGID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.INPUTYARDDATE == "") enumValue.INPUTYARDDATE = null; else { enumValue.INPUTYARDDATE = Convert.ToDateTime(enumValue.INPUTYARDDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.OUTYARDDATE == "") enumValue.OUTYARDDATE = null; else { enumValue.OUTYARDDATE = Convert.ToDateTime(enumValue.OUTYARDDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.RTCTNDATE == "") { enumValue.RTCTNDATE = null; isover = false; } else { enumValue.RTCTNDATE = Convert.ToDateTime(enumValue.RTCTNDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); if (string.IsNullOrEmpty(RTCTNDATE) || Convert.ToDateTime(enumValue.RTCTNDATE.Replace("GMT+0800 (中国标准时间)", "")) > Convert.ToDateTime(RTCTNDATE)) RTCTNDATE = Convert.ToDateTime(enumValue.RTCTNDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); if (!BSNOLIST.Contains(enumValue.BSNO)) BSNOLIST.Add(enumValue.BSNO); } if (enumValue.CTNGID == "*" || enumValue.CTNGID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@CTNGID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@CTN_ID", DbType.String, enumValue.CTN_ID); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, BSNO); db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL); db.AddInParameter(cmdInsert, "@CNTRNO", DbType.String, enumValue.CNTRNO); db.AddInParameter(cmdInsert, "@CTNSTATUS", DbType.String, enumValue.CTNSTATUS); db.AddInParameter(cmdInsert, "@YARD", DbType.String, enumValue.YARD); db.AddInParameter(cmdInsert, "@INPUTYARDDATE", DbType.String, enumValue.INPUTYARDDATE); db.AddInParameter(cmdInsert, "@OUTYARDDATE", DbType.String, enumValue.OUTYARDDATE); db.AddInParameter(cmdInsert, "@RTCTNDATE", DbType.String, enumValue.RTCTNDATE); db.AddInParameter(cmdInsert, "@RTCTNYARD", DbType.String, enumValue.RTCTNYARD); db.AddInParameter(cmdInsert, "@DEPOSITPRICE", DbType.Decimal, enumValue.DEPOSITPRICE); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@CTNGID", DbType.String, enumValue.CTNGID); db.AddInParameter(cmdUpdate, "@CTNALL", DbType.String, enumValue.CTNALL); db.AddInParameter(cmdUpdate, "@CNTRNO", DbType.String, enumValue.CNTRNO); db.AddInParameter(cmdUpdate, "@CTNSTATUS", DbType.String, enumValue.CTNSTATUS); db.AddInParameter(cmdUpdate, "@YARD", DbType.String, enumValue.YARD); db.AddInParameter(cmdUpdate, "@INPUTYARDDATE", DbType.String, enumValue.INPUTYARDDATE); db.AddInParameter(cmdUpdate, "@OUTYARDDATE", DbType.String, enumValue.OUTYARDDATE); db.AddInParameter(cmdUpdate, "@RTCTNDATE", DbType.String, enumValue.RTCTNDATE); db.AddInParameter(cmdUpdate, "@RTCTNYARD", DbType.String, enumValue.RTCTNYARD); db.AddInParameter(cmdUpdate, "@DEPOSITPRICE", DbType.Decimal, enumValue.DEPOSITPRICE); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdUpdate, tran); } var strSql2 = new StringBuilder(); strSql2.Append("update op_socctn_ctndetail set CTNSTATUS=(CASE WHEN ISNULL(RTCTNDATE,'')<>'' THEN '已还箱' ELSE (CASE WHEN ISNULL(BS_BSNO,'')<>'' THEN '使用中' ELSE (CASE WHEN ISNULL(INPUTYARDDATE,'')<>'' THEN '待使用' ELSE '未进场' END) END) END) "); strSql2.Append(" where CTNGID=@CTNGID "); var cmdupdate2 = db.GetSqlStringCommand(strSql2.ToString()); cmdupdate2.Parameters.Clear(); db.AddInParameter(cmdupdate2, "@CTNGID", DbType.String, enumValue.CTNGID); db.ExecuteNonQuery(cmdupdate2, tran); } } if (isover && !string.IsNullOrEmpty(RTCTNDATE)) { var strSql3 = new StringBuilder(); strSql3.Append("update op_socctn_bs set BSSTATUS='已完成' "); strSql3.Append(" where BSNO=@BSNO "); var cmdupdate3 = db.GetSqlStringCommand(strSql3.ToString()); cmdupdate3.Parameters.Clear(); db.AddInParameter(cmdupdate3, "@BSNO", DbType.String, BSNO); db.ExecuteNonQuery(cmdupdate3, tran); } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"+e.Message; return result; } } UpdateCtnContractBsStatus(BSNOLIST); result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DBResult UpdateCtnContractBsStatus(List BSNOLIST) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { foreach (var items in BSNOLIST) { var OpSocCtn = GetData("BSNO='" + items + "'"); if (OpSocCtn.BSSTATUS == "新建" || OpSocCtn.BSSTATUS == "正在执行") { var ctndetailist = GetOpSocCtnCtnDetailList("d.BSNO='" + items + "'"); var RTCTNDATE = ""; var isover = true; if (ctndetailist != null) { foreach (var ctndetail in ctndetailist) { if (ctndetail.RTCTNDATE == "") { isover = false; } else { if (string.IsNullOrEmpty(RTCTNDATE) || Convert.ToDateTime(ctndetail.RTCTNDATE) > Convert.ToDateTime(RTCTNDATE)) RTCTNDATE = Convert.ToDateTime(ctndetail.RTCTNDATE).ToString("yyyy-MM-dd"); } } } if (isover && !string.IsNullOrEmpty(RTCTNDATE)) { var strSql4 = new StringBuilder(); strSql4.Append("update op_socctn_contract set BSSTATUS='押金返还',RETURNDEPOSITDATE=@RETURNDEPOSITDATE "); strSql4.Append(" where BSNO=@BSNO "); var cmdupdate4 = db.GetSqlStringCommand(strSql4.ToString()); cmdupdate4.Parameters.Clear(); db.AddInParameter(cmdupdate4, "@BSNO", DbType.String, items); db.AddInParameter(cmdupdate4, "@RETURNDEPOSITDATE", DbType.String, Convert.ToDateTime(RTCTNDATE).AddDays(7).ToString("yyyy-MM-dd")); db.ExecuteNonQuery(cmdupdate4); } } } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DBResult InsertSocCtnCtnDetail(List bodyList, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"insert into op_socctn_ctnDetail ([CTNGID],[CTN_ID],[BSNO],[CTNALL],[CNTRNO],[CTNSTATUS],YARD,[INPUTYARDDATE],[OUTYARDDATE],[RTCTNDATE],[RTCTNYARD],[DEPOSITPRICE],[REMARK],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]) values (@CTNGID,@CTN_ID,@BSNO,@CTNALL,@CNTRNO,@CTNSTATUS,@YARD,@INPUTYARDDATE,@OUTYARDDATE,@RTCTNDATE,@RTCTNYARD,@DEPOSITPRICE,@REMARK,@CREATEUSER,@CREATETIME,@MODIFIEDUSER,@MODIFIEDTIME ) "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.INPUTYARDDATE == "") enumValue.INPUTYARDDATE = null; else { enumValue.INPUTYARDDATE = Convert.ToDateTime(enumValue.INPUTYARDDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.OUTYARDDATE == "") enumValue.OUTYARDDATE = null; else { enumValue.OUTYARDDATE = Convert.ToDateTime(enumValue.OUTYARDDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.RTCTNDATE == "") enumValue.RTCTNDATE = null; else { enumValue.RTCTNDATE = Convert.ToDateTime(enumValue.RTCTNDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@CTNGID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@CTN_ID", DbType.String, enumValue.CTN_ID); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL); db.AddInParameter(cmdInsert, "@CNTRNO", DbType.String, enumValue.CNTRNO); db.AddInParameter(cmdInsert, "@CTNSTATUS", DbType.String, enumValue.CTNSTATUS); db.AddInParameter(cmdInsert, "@YARD", DbType.String, enumValue.YARD); db.AddInParameter(cmdInsert, "@INPUTYARDDATE", DbType.String, enumValue.INPUTYARDDATE); db.AddInParameter(cmdInsert, "@OUTYARDDATE", DbType.String, enumValue.OUTYARDDATE); db.AddInParameter(cmdInsert, "@RTCTNDATE", DbType.String, enumValue.RTCTNDATE); db.AddInParameter(cmdInsert, "@RTCTNYARD", DbType.String, enumValue.RTCTNYARD); db.AddInParameter(cmdInsert, "@DEPOSITPRICE", DbType.Decimal, enumValue.DEPOSITPRICE); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdInsert, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DBResult ModifyCtnDetail(List bodyList, MsOpSocCtnCtnDetail modifydata, string companyid, string userid) { var result = new DBResult(); string errstr = ""; string tmperrstr = ""; int i = 0; Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var strSql = new StringBuilder(); strSql.Append("update op_socctn_ctndetail set MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME "); if (modifydata.INPUTYARDDATE != "" && modifydata.INPUTYARDDATE != null) strSql.Append(",INPUTYARDDATE=@INPUTYARDDATE"); if (modifydata.OUTYARDDATE != "" && modifydata.OUTYARDDATE != null) strSql.Append(",OUTYARDDATE=@OUTYARDDATE"); if (modifydata.PORTDISCHARGE != "" && modifydata.PORTDISCHARGE != null) strSql.Append(",PORTDISCHARGE=@PORTDISCHARGE"); strSql.Append(" where CTNGID=@CTNGID "); var cmdupdate = db.GetSqlStringCommand(strSql.ToString()); if (bodyList != null) { foreach (var enumValue in bodyList) { var isPost = true; if (isPost) { cmdupdate.Parameters.Clear(); if (modifydata.INPUTYARDDATE != "" && modifydata.INPUTYARDDATE != null) db.AddInParameter(cmdupdate, "@INPUTYARDDATE", DbType.String, modifydata.INPUTYARDDATE); if (modifydata.OUTYARDDATE != "" && modifydata.OUTYARDDATE != null) db.AddInParameter(cmdupdate, "@OUTYARDDATE", DbType.String, modifydata.OUTYARDDATE); if (modifydata.PORTDISCHARGE != "" && modifydata.PORTDISCHARGE != null) db.AddInParameter(cmdupdate, "@PORTDISCHARGE", DbType.String, modifydata.PORTDISCHARGE); db.AddInParameter(cmdupdate, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdupdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdupdate, "@CTNGID", DbType.String, enumValue.CTNGID); db.ExecuteNonQuery(cmdupdate, tran); i = i + 1; } } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "修改出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "修改成功" + i.ToString() + "票"; if (errstr != "") { result.Message = result.Message + "(其中" + errstr + " 无法修改)"; } return result; } public static DBResult InsertCtn(DataTable dt, string userid, string companyid) { DBResult result = new DBResult(); var i = 0; Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (dt.Rows.Count > 0) { var billNoList = new List(); foreach (DataRow row in dt.Rows) { var CTNNO = Convert.ToString(row["CNTR"]); var SO = Convert.ToString(row["SO#"]); var CTNSIZE = Convert.ToString(row["SIZE"]); if (!string.IsNullOrEmpty(CTNNO)&& !string.IsNullOrEmpty(SO)&&CTNNO.Length<30) { var strSql = new StringBuilder(); strSql.Append("update op_socctn_ctndetail set MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME "); strSql.Append(",CNTRNO=@CNTRNO"); strSql.Append(" where CTNGID in (SELECT TOP 1 CTNGID FROM op_socctn_ctndetail "); strSql.Append(" where CTNALL='"+ CTNSIZE + "' AND ISNULL(CNTRNO,'')='' AND BSNO IN (SELECT BSNO FROM op_socctn_contract WHERE CONTRACTNO='"+ SO + "')) "); var cmdupdate = db.GetSqlStringCommand(strSql.ToString()); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdupdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdupdate, "@CNTRNO", DbType.String, CTNNO); db.ExecuteNonQuery(cmdupdate, tran); } } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "修改出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Message = "上传成功!,共上传" + i.ToString() + "条数据!"; return result; } public static DBResult InsertCtnYard(DataTable dt, string userid, string companyid) { DBResult result = new DBResult(); var i = 0; Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (dt.Rows.Count > 0) { var billNoList = new List(); foreach (DataRow row in dt.Rows) { var CTNNO = Convert.ToString(row["箱号"]); if (!string.IsNullOrEmpty(CTNNO)) { var INPUTYARDDATE = Convert.ToString(row["进场日期"]); var YARD = Convert.ToString(row["场站"]); var strSql = new StringBuilder(); strSql.Append("update op_socctn_ctndetail set MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME "); if (INPUTYARDDATE != "" && INPUTYARDDATE != null) strSql.Append(",INPUTYARDDATE=@INPUTYARDDATE"); if (YARD != "" && YARD != null) strSql.Append(",YARD=@YARD"); strSql.Append(" where CNTRNO=@CNTRNO "); var cmdupdate = db.GetSqlStringCommand(strSql.ToString()); cmdupdate.Parameters.Clear(); if (INPUTYARDDATE != "" && INPUTYARDDATE != null) db.AddInParameter(cmdupdate, "@INPUTYARDDATE", DbType.String, INPUTYARDDATE); if (YARD != "" && YARD != null) db.AddInParameter(cmdupdate, "@YARD", DbType.String, YARD); db.AddInParameter(cmdupdate, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdupdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdupdate, "@CNTRNO", DbType.String, CTNNO); db.ExecuteNonQuery(cmdupdate, tran); var strSql2 = new StringBuilder(); strSql2.Append("update op_socctn_ctndetail set CTNSTATUS=(CASE WHEN ISNULL(RTCTNDATE,'')<>'' THEN '已还箱' ELSE (CASE WHEN ISNULL(BS_BSNO,'')<>'' THEN '使用中' ELSE (CASE WHEN ISNULL(INPUTYARDDATE,'')<>'' THEN '待使用' ELSE '未进场' END) END) END) "); strSql2.Append(" where CNTRNO=@CNTRNO "); var cmdupdate2 = db.GetSqlStringCommand(strSql2.ToString()); cmdupdate2.Parameters.Clear(); db.AddInParameter(cmdupdate2, "@CNTRNO", DbType.String, CTNNO); db.ExecuteNonQuery(cmdupdate2, tran); } } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "修改出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Message = "上传成功!,共上传" + i.ToString() + "条数据!"; return result; } public static DBResult DeleteOpSocCtnCtnDetail(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_socctn_ctndetail where CTNGID='" + enumValue.CTNGID + "'"); db.ExecuteNonQuery(cmdDelete, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult AuditOpCtnDetail(List headData, string type, string username) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdUpdate = db.GetSqlStringCommand("update op_socctn_ctndetail set AUDITSTATUS='提交审核' where CTNGID='" + enumValue.CTNGID + "'"); if (type == "2") cmdUpdate = db.GetSqlStringCommand("update op_socctn_ctndetail set AUDITSTATUS='录入状态' where CTNGID='" + enumValue.CTNGID + "'"); if (type == "6") cmdUpdate = db.GetSqlStringCommand("update op_socctn_ctndetail set AUDITSTATUS='申请修改' where CTNGID='" + enumValue.CTNGID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "提交成功"; return result; } #endregion public static DBResult UpdateOpSocCtnBsCtn(List headList,string bsno,string type, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var head in headList) { if (type == "1") { var strSql = new StringBuilder(); strSql.Append("update op_socctn_ctndetail set BS_BSNO='"+bsno+"' "); strSql.Append(" where CTNGID=@CTNGID "); var cmdupdate = db.GetSqlStringCommand(strSql.ToString()); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@CTNGID", DbType.String, head.CTNGID); db.ExecuteNonQuery(cmdupdate, tran); } else { var strSql = new StringBuilder(); strSql.Append("update op_socctn_ctndetail set BS_BSNO='' "); strSql.Append(" where CTNGID=@CTNGID "); var cmdupdate = db.GetSqlStringCommand(strSql.ToString()); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@CTNGID", DbType.String, head.CTNGID); db.ExecuteNonQuery(cmdupdate, tran); } var strSql2 = new StringBuilder(); strSql2.Append("update op_socctn_ctndetail set CTNSTATUS=(CASE WHEN ISNULL(RTCTNDATE,'')<>'' THEN '已还箱' ELSE (CASE WHEN ISNULL(BS_BSNO,'')<>'' THEN '使用中' ELSE (CASE WHEN ISNULL(INPUTYARDDATE,'')<>'' THEN '待使用' ELSE '未进场' END) END) END) "); strSql2.Append(" where CTNGID=@CTNGID "); var cmdupdate2 = db.GetSqlStringCommand(strSql2.ToString()); cmdupdate2.Parameters.Clear(); db.AddInParameter(cmdupdate2, "@CTNGID", DbType.String, head.CTNGID); db.ExecuteNonQuery(cmdupdate2, tran); } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "更新成功"; return result; } public static DBResult UpdateOpSocCtnBs(string bsno) { var result = new DBResult(); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var str = "select CTNALL,COUNT(1) CT FROM op_socctn_ctndetail where BS_BSNO='" + bsno + "' group by CTNALL order by CTNALL"; var ds = T_ALL_DA.GetAllSQL(str); var strCNTRTOTAL = ""; if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataTable myTable in ds.Tables) { foreach (DataRow myRow in myTable.Rows)//遍历表 { strCNTRTOTAL += myRow["CTNALL"].ToString().Replace("'", "''").Trim() + "*" + myRow["CT"].ToString().Trim() + " "; } } } } Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var strSql2 = new StringBuilder(); strSql2.Append("update op_socctn_bs set CNTRTOTAL=@CNTRTOTAL "); strSql2.Append(" where BSNO=@BSNO "); var cmdupdate2 = db.GetSqlStringCommand(strSql2.ToString()); cmdupdate2.Parameters.Clear(); db.AddInParameter(cmdupdate2, "@CNTRTOTAL", DbType.String, strCNTRTOTAL); db.AddInParameter(cmdupdate2, "@BSNO", DbType.String,bsno); db.ExecuteNonQuery(cmdupdate2, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "更新成功"; return result; } #endregion #region 判断编码是否有重复 static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" Count(BSNO) AS CT "); strSql.Append(" from op_socctn_ctndetail "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where ISNULL(BS_BSNO,'')<>'' AND " + strCondition); } var ct=0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ct = Convert.ToInt16(reader["CT"]); } reader.Close(); } return ct; } #endregion #region EXCEL导入 #endregion #region Rang权限范围 public static string GetRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT"); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL"); strSql.Append(" from VW_User_Authority"); strSql.Append(" where [NAME]='modOpOtherList' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " (OP='" + username + "' OR CREATEUSER='" + userid + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')"; } else if (visiblerange == "3") { str = " (OP='" + username + "' OR CREATEUSER='" + userid + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR CREATEUSER in (select GID from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))"; } else if (visiblerange == "1") { str = " (UPPER(op_other.Corpid)='" + companyid + "' or op_other.SALECORPID='" + companyid + "') "; } else if (visiblerange == "5") { if (tb == "index") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (op_other.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or op_other.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "' "; } else { str = str + " or op_other.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or op_other.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else { str = " (UPPER(op_other.Corpid)='" + companyid + "') "; } } else if (visiblerange == "6") { if (tb == "index") { var opstr = ""; var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { while (reader.Read()) { if (opstr == "") { opstr = " ('" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { opstr = opstr + ",'" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } if (opstr != "") opstr = opstr + ")"; reader.Close(); } if (opstr == "") opstr = "('" + username + "')"; str = " (OP in " + opstr + " or CREATEUSER in " + opstr + " or CUSTSERVICE IN " + opstr + " or SALE IN " + opstr + " )"; } else { str = " (UPPER(op_other.Corpid)='" + companyid + "') "; } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } #endregion #region 添加日志 public static DBResult setLog(MsOpSocCtnContract modeldata, string strUserID) { DBResult result = new DBResult(); if (modeldata == null) { result.Success = false; result.Message = "没有输入任何需要修改的数据"; return result; } // Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { #region 把【仓储结算关联表wms_settlement_date】中数据【ISDELETE】设为【1】 string strSql = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除信息','删除操作','SOC箱业务 合同号:" + modeldata.CONTRACTNO + "','" + strUserID + "')"; int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null); #endregion sqlTran.Commit(); } catch (Exception) { sqlTran.Rollback(); result.Success = false; result.Message = "操作出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "操作数据成功"; return result; } #endregion } }