using System; using System.Data; using System.Collections.Generic; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using DSWeb.Areas.CommMng.DAL; using DSWeb.MvcShipping.Helper; using System.Data.SqlClient; using DSWeb.DataAccess; using DSWeb.EntityDA; using DSWeb.MvcContainer.Models.MsOpCtnr; using DSWeb.MvcShipping.Helper.Repository; using HcUtility.Core; using DSWeb.MvcShipping.DAL.MsOpSeaeDAL; using DSWeb.MvcShipping.Models.MsChFee; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using DSWeb.Areas.MvcShipping.DAL; using DSWeb.MvcShipping.Models.MsOpAmend; using DSWeb.MvcShipping.DAL.ChMonthCloseDAL; using DSWeb.MvcShipping.Models.MsOpSeae; namespace DSWeb.MvcContainer.DAL.MsOpCtnrDAL { public class MsOpCtnrDAL { static public List GetDataList(string strCondition, int start, int limit, string userid, string username, string companyid, out int total, string sort = null) { var rangstr = GetRangDAStr("index", userid, username, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append(@"select "); strSql.Append(" BSNO,BLTYPE,BSSTATUS,CUSTNO, "); strSql.Append(" BILLNO,CUSTOMERNAME,CNTRSOURCE,PORT,YARD,[MBLNO],[BSSOURCE],[BSSOURCEDETAIL],[VESSEL],[VOYNO],[ETD],[SALE],[PORTLOAD],[PORTDISCHARGE],[BillFeeStatus],[SALECORPID],"); strSql.Append(" convert(char(10),BSDATE,20) AS BSDATE,convert(char(10),ACCDATE,20) AS ACCDATE,"); strSql.Append(" OP,CORPID,DRFEENAME,CRFEENAME,REMARK,FEESTATUS,RETURNTYPE,RETURNDATE,RETURNYARD,"); strSql.Append("(SELECT top 1 SHOWNAME FROM dbo.[user] WHERE(GID = CREATEUSER)) AS CREATEUSER,"); strSql.Append("(SELECT top 1 SHOWNAME FROM dbo.[user] WHERE(GID = MODIFIEDUSER)) AS MODIFIEDUSER,"); strSql.Append("dbo.F_GetBillDrFeeStatus(BSNO) DRFEESTATUS,(CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF ,"); strSql.Append("dbo.F_GetBillCrFeeStatus(BSNO) CRFEESTATUS,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,"); //strSql.Append("CASE FEESTATUS WHEN 0 THEN '未锁定' ELSE '已锁定' END AS FEESTATUS,"); strSql.Append(" convert(char(10),CREATETIME,20) AS CREATETIME,convert(char(10),MODIFIEDTIME,20) AS MODIFIEDTIME,CNTRTOTAL "); strSql.Append(",(CASE ISCREATEFEE WHEN 1 THEN '是' ELSE '' END) ISCREATEFEEREF,OWNERCTN,ENDRENTDATE "); strSql.Append(",CREATEBSFEE,(CASE CREATEBSFEE WHEN 1 THEN '是' ELSE '' END) CREATEBSFEEREF "); strSql.Append(" from op_ctnmng where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } if (!string.IsNullOrEmpty(sort)) { var so = JsonConvert.Deserialize>(sort); string orderbyStr = " order by "; foreach (var s in so) { orderbyStr += s.property + " " + s.direction + ","; } orderbyStr = orderbyStr.Substring(0, orderbyStr.Length - 1); strSql.Append(orderbyStr); } else { strSql.Append(" order by BSDATE DESC "); } int totalCount = 0; StringBuilder sb = PagerHelper.PageSQL(strSql.ToString(), start, limit, out totalCount); total = totalCount; return SetData(sb); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CtnrList data = new CtnrList(); #region Set DB data to Object data.BSNO = reader["BSNO"].ToString(); data.BLTYPE = reader["BLTYPE"].ToString(); data.BSSTATUS = Convert.ToBoolean((reader["BSSTATUS"])); data.FEESTATUS = Convert.ToBoolean((reader["FEESTATUS"])); data.BSSTATUSREF = Convert.ToString(reader["BSSTATUSREF"]);// 业务状态 data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);// 费用状态 data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"])); data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"])); data.CUSTNO = reader["CUSTNO"].ToString(); data.BILLNO = reader["BILLNO"].ToString(); data.CUSTNO = reader["CUSTNO"].ToString(); data.BILLNO = reader["BILLNO"].ToString(); data.CUSTOMERNAME = reader["CUSTOMERNAME"].ToString(); data.CNTRSOURCE = reader["CNTRSOURCE"].ToString(); data.BSDATE = reader["BSDATE"].ToString(); data.ACCDATE = reader["ACCDATE"].ToString(); data.OP = reader["OP"].ToString(); data.CORPID = reader["CORPID"].ToString(); data.PORT = reader["PORT"].ToString(); data.YARD = reader["YARD"].ToString(); data.DRFEENAME = reader["DRFEENAME"].ToString(); data.CRFEENAME = reader["CRFEENAME"].ToString(); data.REMARK = reader["REMARK"].ToString(); data.CREATEUSER = reader["CREATEUSER"].ToString(); data.CREATETIME = reader["CREATETIME"].ToString(); data.MODIFIEDUSER = reader["MODIFIEDUSER"].ToString(); data.MODIFIEDTIME = reader["MODIFIEDTIME"].ToString(); data.MBLNO = reader["MBLNO"].ToString(); data.BSSOURCE = reader["BSSOURCE"].ToString(); data.BSSOURCEDETAIL = reader["BSSOURCEDETAIL"].ToString(); data.VESSEL = reader["VESSEL"].ToString(); data.VOYNO = reader["VOYNO"].ToString(); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");//到港日期 data.SALE = reader["SALE"].ToString(); data.PORTLOAD = reader["PORTLOAD"].ToString(); data.PORTDISCHARGE = reader["PORTDISCHARGE"].ToString(); data.BillFeeStatus = reader["BillFeeStatus"].ToString(); data.SALECORPID = reader["SALECORPID"].ToString(); if (reader["RETURNDATE"] != DBNull.Value) data.RETURNDATE = Convert.ToDateTime(reader["RETURNDATE"]).ToString("yyyy-MM-dd");//到港日期 data.RETURNTYPE = reader["RETURNTYPE"].ToString(); data.CNTRTOTAL = reader["CNTRTOTAL"].ToString(); data.ISCREATEFEEREF = reader["ISCREATEFEEREF"].ToString(); data.RETURNYARD = reader["RETURNYARD"].ToString(); data.OWNERCTN = reader["OWNERCTN"].ToString(); if (reader["ENDRENTDATE"] != DBNull.Value) data.ENDRENTDATE = Convert.ToDateTime(reader["ENDRENTDATE"]).ToString("yyyy-MM-dd"); data.CREATEBSFEEREF = reader["CREATEBSFEEREF"].ToString(); #endregion headList.Add(data); } reader.Close(); } return headList; } public static List GetDynaList(string strCondition, string sort) { var strSql = new StringBuilder(); strSql.Append(" select GID,CTNGID,CNTRNO,CTNSTATUS,BSSTATUS,FEESTATUS,"); strSql.Append("convert(char(10),CTNSTATUSTIME,20) AS CTNSTATUSTIME,TRANSTYPE, "); strSql.Append("PORT,YARD,CTNEF,CUSTNO,MBLNO,REMARK,CREATEUSER,CREATETIME,MODIFYTIME,MODIFYUSER "); strSql.Append(",(CASE CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF,[BSNO],[ETD],[ETA]"); strSql.Append(",[PORTLOAD_STATOIN],[PORTLOAD_CNT_TIME],[PORTLOAD],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN]"); strSql.Append(",[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS],[DESTPORT_OVER_DAYS_FEE],[DESTPORT_OVER_DAYS_AMT],[AGENTNAME]"); strSql.Append(",[VESSEL],[VOYNO],[HBLNO],(select ShowName from [user] where GID=op_ctnmng_ctnstatus.CREATEUSER) as CREATEUSERREF "); strSql.Append(",(select ShowName from [user] where GID=op_ctnmng_ctnstatus.MODIFYUSER) as MODIFYUSERREF "); strSql.Append(",dbo.F_GetBillDrFeeStatus(GID) DRFEESTATUS,(CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF "); strSql.Append(",dbo.F_GetBillCrFeeStatus(GID) CRFEESTATUS,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF"); strSql.Append(",(select CTNALL from op_ctnmng_ctndetail where CTNGID=op_ctnmng_ctnstatus.CTNGID) as CTNALL "); strSql.Append(",ACCDATE,OP,CORPID,SALECORPID,CREATEBSFEE,(CASE CREATEBSFEE WHEN 1 THEN '是' ELSE '' END) CREATEBSFEEREF "); strSql.Append(" FROM op_ctnmng_ctnstatus "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by MODIFYTIME DESC "); } return SetCtnrDyDetailData(strSql); } static public CtnrDyDetail GetDyna(string condition) { CtnrDyDetail data = null; var list = GetDynaList(condition, ""); if (list.Count > 0) data = list[0]; if (data == null) { data = new CtnrDyDetail(); } return data; } static public CtnrDyDetail SetDynaStatus(CtnrDyDetail headData) { if (!string.IsNullOrEmpty(headData.DEST_RTCNT_TIME) && (Convert.ToDateTime(headData.DEST_RTCNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; headData.CTNEF = "E"; headData.CTNSTATUS = "已还箱"; headData.CTNSTATUSTIME = headData.DEST_RTCNT_TIME; headData.PORT = headData.DESTPORT; headData.YARD = headData.DESTPORT_STATOIN; } else if (!string.IsNullOrEmpty(headData.DEST_CNT_TIME)&& (Convert.ToDateTime(headData.DEST_CNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; headData.CTNSTATUS = "待还箱"; headData.CTNSTATUSTIME = headData.DEST_CNT_TIME; headData.PORT = headData.DESTPORT; headData.YARD = headData.DESTPORT_STATOIN; } else if (!string.IsNullOrEmpty(headData.ETA)&& (Convert.ToDateTime(headData.ETA) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; headData.CTNSTATUS = "待提箱"; headData.CTNSTATUSTIME = headData.ETA; headData.PORT = headData.DESTPORT; headData.YARD = headData.DESTPORT_STATOIN; } else if (!string.IsNullOrEmpty(headData.ETD)&& (Convert.ToDateTime(headData.ETD) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; headData.CTNSTATUS = "已开船"; headData.CTNSTATUSTIME = headData.ETD; headData.PORT = headData.PORTLOAD; headData.YARD = headData.PORTLOAD_STATOIN; } else if (!string.IsNullOrEmpty(headData.PORTLOAD_CNT_TIME)&& (Convert.ToDateTime(headData.PORTLOAD_CNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; headData.CTNSTATUS = "待开船"; headData.CTNSTATUSTIME = headData.PORTLOAD_CNT_TIME; headData.PORT = headData.PORTLOAD; headData.YARD = headData.PORTLOAD_STATOIN; } return headData; } public static List GetCtnrList(string strCondition, string sort) { var strSql = new StringBuilder(); strSql.Append(" select c.CTNGID,c.CTNALL,c.CNTRNO,c.CNTRSOURCE,c.CTNSTATUS,s.CTNSTATUS CURSTATUS,"); strSql.Append("convert(char(10),s.CTNSTATUSTIME,20) AS CTNSTATUSTIME, "); strSql.Append("s.PORT,s.YARD,s.CTNEF,s.CUSTNO,s.MBLNO,s.BSNO,s.REMARK,c.ISSTOP "); strSql.Append(",(CASE s.CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF "); strSql.Append(",(CASE c.ISSTOP WHEN 1 THEN '停用' ELSE '' END) ISSTOPREF "); strSql.Append(",c.ISBERETURN,(CASE c.ISBERETURN WHEN 1 THEN '是' ELSE '' END) ISBERETURNREF "); strSql.Append(",c.OWNERCTN,c.ENDRENTDATE,c.NOTYPE,c.CTNCOLOR,c.ISLOCKBOX,c.ISSLOT,C.ISLOCK "); strSql.Append(",(CASE c.ISLOCKBOX WHEN 1 THEN '是' ELSE '' END) ISLOCKBOXREF,(CASE c.ISSLOT WHEN 1 THEN '是' ELSE '' END) ISSLOTREF "); strSql.Append(",(CASE c.ISLOCK WHEN 1 THEN '是' ELSE '' END) ISLOCKREF FROM op_ctnmng_ctndetail C "); strSql.Append(" left join (SELECT [CTNGID],[CNTRNO],[CTNSTATUS],[CTNSTATUSTIME],[PORT],[YARD],[CTNEF],[CUSTNO],[MBLNO],BSNO,REMARK,ROW_NUMBER() OVER ( PARTITION BY CTNGID ORDER BY CTNSTATUSTIME DESC,CREATETIME DESC ) rid from op_ctnmng_ctnstatus) s "); strSql.Append(" on (s.rid=1 and s.CTNGID=c.CTNGID) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by c.CTNGID "); } return SetCtnrDetailData(strSql); } static public CtnrDetail GetCtnData(string condition) { CtnrDetail data = null; var list = GetCtnrList(condition,""); if (list.Count > 0) data = list[0]; if (data == null) { data = new CtnrDetail(); } return data; } public static List GetDetailList(string strCondition, string sort) { var strSql = new StringBuilder(); strSql.Append(" select mng.GID,mng.BSNO,mng.CURR,detail.CTNGID,detail.CTNALL,detail.CNTRNO,detail.CNTRSOURCE,S.CTNSTATUS,"); strSql.Append("convert(char(10),S.CTNSTATUSTIME,20) AS CTNSTATUSTIME, "); strSql.Append("S.PORT,S.YARD,S.CTNEF,S.CUSTNO,S.MBLNO,S.REMARK,DR,CR,(SELECT SUM(CR) FROM op_ctnmng_detail WHERE CTNGID=detail.CTNGID) MXCR,DRFEENAME,CRFEENAME "); strSql.Append(",(CASE S.CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF,detail.RETURNYARD "); strSql.Append(",detail.OWNERCTN,detail.ENDRENTDATE,detail.NOTYPE,detail.CTNCOLOR,detail.ISLOCKBOX,detail.ISSLOT "); strSql.Append(",(CASE detail.ISLOCKBOX WHEN 1 THEN '是' ELSE '' END) ISLOCKBOXREF,(CASE detail.ISSLOT WHEN 1 THEN '是' ELSE '' END) ISSLOTREF,sn.BSNO NBSNO "); strSql.Append(" FROM op_ctnmng_ctndetail detail left join op_ctnmng_detail mng "); strSql.Append(" on detail.CTNGID=mng.CTNGID "); strSql.Append(" left join op_ctnmng_ctnstatus s on (s.CTNGID=detail.CTNGID AND s.BSNO=mng.BSNO) "); strSql.Append(" left join (SELECT CTNGID,BSNO,ROW_NUMBER() OVER ( PARTITION BY CTNGID ORDER BY CTNSTATUSTIME DESC,CREATETIME DESC ) rid from op_ctnmng_ctnstatus) sn "); strSql.Append(" on (sn.rid=1 and sn.CTNGID=detail.CTNGID) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by detail.CTNGID "); } return SetCtnrDetailAXData(strSql); } public static List GetSearchDetailList(string strCondition, string sort) { var strSql = new StringBuilder(); strSql.Append(" select detail.CTNGID,detail.CTNALL,detail.CNTRNO,detail.CNTRSOURCE,detail.CTNSTATUS,s.CTNSTATUS CURSTATUS,"); strSql.Append("convert(char(10),detail.CTNSTATUSTIME,20) AS CTNSTATUSTIME, "); strSql.Append("s.PORT,s.YARD,detail.CTNEF,s.CUSTNO,s.MBLNO,s.BSNO,detail.REMARK,detail.ISSTOP "); strSql.Append(",(CASE detail.CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF "); strSql.Append(",(CASE detail.ISSTOP WHEN 1 THEN '停用' ELSE '' END) ISSTOPREF "); strSql.Append(",detail.ISBERETURN,(CASE detail.ISBERETURN WHEN 1 THEN '是' ELSE '' END) ISBERETURNREF "); strSql.Append(",detail.OWNERCTN,detail.ENDRENTDATE,detail.NOTYPE,detail.CTNCOLOR,detail.ISLOCKBOX,detail.ISSLOT,detail.ISLOCK "); strSql.Append(",(CASE detail.ISLOCKBOX WHEN 1 THEN '是' ELSE '' END) ISLOCKBOXREF,(CASE detail.ISSLOT WHEN 1 THEN '是' ELSE '' END) ISSLOTREF "); strSql.Append(",(CASE detail.ISLOCK WHEN 1 THEN '是' ELSE '' END) ISLOCKREF FROM op_ctnmng_ctndetail detail left join op_ctnmng_detail mng "); strSql.Append(" on detail.CTNGID=mng.CTNGID "); strSql.Append(" left join (SELECT [CTNGID],[CNTRNO],[CTNSTATUS],[CTNSTATUSTIME],[PORT],[YARD],[CTNEF],[CUSTNO],[MBLNO],BSNO,REMARK,ROW_NUMBER() OVER ( PARTITION BY CTNGID ORDER BY CTNSTATUSTIME DESC,CREATETIME DESC ) rid from op_ctnmng_ctnstatus) s "); strSql.Append(" on (s.rid=1 and s.CTNGID=detail.CTNGID) "); strSql.Append(" left join op_ctnmng ctn on ctn.bsno = mng.bsno "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by detail.CTNGID "); } return SetCtnrDetailData(strSql); } public static bool Delete(List list, out string msg) { string message; string ids = ""; bool result = true; foreach (var m in list) { ids += "'" + m.BSNO + "',"; } ids = ids.Substring(0, ids.Length - 1); Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { foreach (var items in list) { if (items.BLTYPE== "买箱"|| items.BLTYPE == "租入") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("DELETE FROM op_ctnmng_ctndetail where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (items.BLTYPE == "卖箱" || items.BLTYPE == "退租") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (items.BLTYPE == "返箱") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISBERETURN=1 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (items.BLTYPE == "租出" && items.RETURNTYPE == "返箱") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISBERETURN=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } var strSqlMng = new StringBuilder(); strSqlMng.Append("DELETE FROM op_ctnmng_detail WHERE BSNO='" + items.BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlMng.ToString(), null); var strSql = new StringBuilder(); strSql.Append("DELETE FROM op_ctnmng WHERE BSNO='" + items.BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null); var strSql2 = new StringBuilder(); strSql2.Append("DELETE FROM op_ctnmng_ctnstatus WHERE BSNO='" + items.BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), null); } message = "删除成功!"; sqlTran.Commit(); } catch (Exception ee) { result = false; message = ee.Message; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } msg = message; return result; } public static DBResult CreateBsFee(List list,string userid,string username,string companyid) { var result = new DBResult(); var errostr = ""; T_ALL_DA T_ALL_DA = new T_ALL_DA(); foreach (var items in list) { var ctnlist = GetCtnrList("c.BSNO='"+items.BSNO+"' and isnull(s.BSNO,'')='' ",""); if (ctnlist != null && ctnlist.Count > 0) { errostr = errostr + "单号:"+items.BILLNO+" 箱号("; foreach (var ctn in ctnlist) { errostr = errostr + " "+ctn.CNTRNO; } errostr = errostr + ")"; } else { var feelist = new List(); var ctndetaillist = GetDetailList("detail.BSNO='"+items.BSNO+"'", "sn.BSNO"); if (ctndetaillist != null && ctndetaillist.Count > 0) { foreach (var ctndetail in ctndetaillist) { if (!string.IsNullOrEmpty(ctndetail.DR)|| !string.IsNullOrEmpty(ctndetail.CR)) { var FEETYPE = 1; if (!string.IsNullOrEmpty(ctndetail.DR)){ FEETYPE = 1; } if (!string.IsNullOrEmpty(ctndetail.CR)) { if (Convert.ToDecimal(ctndetail.CR) != 0) FEETYPE = 2; } var fee = feelist.Find(x => x.NBSNO == ctndetail.NBSNO && x.FEETYPE == FEETYPE&&x.CURR==ctndetail.CURR); if (fee == null) { var newfee = new CreateFee(); if (!string.IsNullOrEmpty(ctndetail.DR)){ if (Convert.ToDecimal(ctndetail.DR) != 0) { newfee.AMOUNT = Convert.ToDecimal(ctndetail.DR); newfee.FEETYPE = 1; } } if (!string.IsNullOrEmpty(ctndetail.CR)) { if (Convert.ToDecimal(ctndetail.CR) != 0) { newfee.AMOUNT = Convert.ToDecimal(ctndetail.CR); newfee.FEETYPE = 2; } } var NEWBSNO = ""; var SALE = ""; var oplist =MsOpBillDAL.GetDataList("PARENTID='"+ctndetail.NBSNO+"'","","",""); foreach (var opbs in oplist) { SALE = opbs.SALE; if (!opbs.FEESTATUS) { NEWBSNO = opbs.BSNO; } } if (string.IsNullOrEmpty(NEWBSNO)) { var head = new MsOpAmend(); head.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); head.CREATEUSER = username; var period = ChMonthCloseDAL.GetData("", companyid); if (Convert.ToDateTime(period.FDAY) > DateTime.Now) { head.ACCDATE = period.PERIOD; } else { head.ACCDATE = DateTime.Now.ToString("yyyy-MM"); } head.PARENTID = ctndetail.NBSNO; head.BSNO = Guid.NewGuid().ToString(); head.SALE = SALE; head.DbOperationType = DbOperationType.DbotIns; head.REASON = "箱管"; head.GID = Guid.NewGuid().ToString(); var modb = new ModelObjectDB(); result = modb.Save(head); NEWBSNO = head.BSNO; } newfee.NBSNO = ctndetail.NBSNO; newfee.BSNO = NEWBSNO; newfee.CURR = ctndetail.CURR; feelist.Add(newfee); } else { fee.AMOUNT = fee.AMOUNT + Convert.ToDecimal(ctndetail.DR); } } } foreach (var fee in feelist) { var chfee = new MsChFee(); chfee.GId = Guid.NewGuid().ToString(); chfee.BsNo = fee.BSNO; chfee.FeeType = fee.FEETYPE; chfee.FeeName = items.DRFEENAME; chfee.UnitPrice = fee.AMOUNT; chfee.Amount = fee.AMOUNT; chfee.TaxUnitPrice = fee.AMOUNT; chfee.NoTaxAmount = fee.AMOUNT; chfee.FeeStatus = 1; chfee.Unit = "单票"; chfee.CustomerName = items.CUSTOMERNAME; chfee.Currency = fee.CURR; chfee.Remark = items.BILLNO; chfee.EnteroPerator = userid; chfee.EnterDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); if (fee.CURR == "RMB") chfee.ExChangerate = 1; else chfee.ExChangerate = MsChFeeDAL.GetExrate(DateTime.Now.ToString(), companyid, fee.CURR); chfee.AccTaxRate = 0; chfee.INPUTMODE = "箱管生成"; chfee.TaxRate = 0; chfee.MODIFIEDUSER = userid; chfee.MODIFIEDUSER = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); chfee.Sort = "100"; chfee.WmsOutBsNo = items.BILLNO; chfee.DbOperationType = DbOperationType.DbotIns; var modbDy = new ModelObjectRepository(); modbDy.Save(chfee); } var blUpSQL = " update OP_CTNMNG set CREATEBSFEE=1 where bsno='"+items.BSNO+"' "; bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL); } } } if (!string.IsNullOrEmpty(errostr)) { result.Message = errostr + " 没有关联业务不能生成到业务!"; result.Success = false; } else { result.Success = true; } return result; } public static DBResult CreateCtnBsFee(List list, string userid, string username, string companyid) { var result = new DBResult(); var errostr = ""; T_ALL_DA T_ALL_DA = new T_ALL_DA(); var feelist = new List(); foreach (var items in list) { if (string.IsNullOrEmpty(items.BSNO)) { errostr = errostr + " " + items.CNTRNO; } else { var fee = feelist.Find(x => x.NBSNO == items.GID); if (fee == null) { var newfee = new CreateFee(); var NEWBSNO = ""; var SALE = ""; var oplist = MsOpBillDAL.GetDataList("PARENTID='" + items.BSNO + "'", "", "", ""); foreach (var opbs in oplist) { SALE = opbs.SALE; if (!opbs.FEESTATUS) { NEWBSNO = opbs.BSNO; } } if (string.IsNullOrEmpty(NEWBSNO)) { var head = new MsOpAmend(); head.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); head.CREATEUSER = username; var period = ChMonthCloseDAL.GetData("", companyid); if (Convert.ToDateTime(period.FDAY) > DateTime.Now) { head.ACCDATE = period.PERIOD; } else { head.ACCDATE = DateTime.Now.ToString("yyyy-MM"); } head.PARENTID = items.BSNO; head.BSNO = Guid.NewGuid().ToString(); head.SALE = SALE; head.DbOperationType = DbOperationType.DbotIns; head.REASON = "箱管"; head.GID = Guid.NewGuid().ToString(); var modb = new ModelObjectDB(); result = modb.Save(head); NEWBSNO = head.BSNO; } newfee.NBSNO = items.GID; newfee.BSNO = NEWBSNO; feelist.Add(newfee); } } } if (feelist != null && feelist.Count!=0) { foreach (var fee in feelist) { var blUpSQL = " update ch_fee set BSNO='"+fee.BSNO+ "',WMSOUTBSNO='" + fee.NBSNO+"' where BSNO='"+fee.NBSNO+"' "; bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL); var blUpSQL2 = " update OP_CTNMNG_CTNSTATUS set CREATEBSFEE=1 where GID='" + fee.NBSNO+ "' "; bool bl2 = T_ALL_DA.GetExecuteSqlCommand(blUpSQL2); } } if (!string.IsNullOrEmpty(errostr)) { result.Message ="箱号:"+ errostr + " 没有关联业务不能生成到业务!"; result.Success = false; } else { result.Success = true; } return result; } public static bool DeleteAll(string BSNO,bool isdeletectn) { bool result = true; Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { if (isdeletectn) { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("DELETE FROM op_ctnmng_ctndetail WHERE BSNO = '" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else { var strSqlCtnr2 = new StringBuilder(); strSqlCtnr2.Append("update op_ctnmng_ctndetail set ISSTOP=0 WHERE BSNO = '" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr2.ToString(), null); } var strSqlMng = new StringBuilder(); strSqlMng.Append("DELETE FROM op_ctnmng_detail WHERE BSNO ='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlMng.ToString(), null); var strSql = new StringBuilder(); strSql.Append("DELETE FROM op_ctnmng WHERE BSNO ='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null); var strSql2 = new StringBuilder(); strSql2.Append("DELETE FROM op_ctnmng_ctnstatus WHERE BSNO ='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), null); sqlTran.Commit(); } catch (Exception ee) { result = false; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static bool DeleteAll(CtnrList head) { bool result = true; Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { if (head.BLTYPE == "卖箱" || head.BLTYPE == "退租") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + head.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (head.BLTYPE == "返箱") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISBERETURN=1 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + head.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (head.BLTYPE == "租出" && head.RETURNTYPE == "返箱") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISBERETURN=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + head.BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } var strSqlMng = new StringBuilder(); strSqlMng.Append("DELETE FROM op_ctnmng_detail WHERE BSNO ='" + head.BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlMng.ToString(), null); var strSql = new StringBuilder(); strSql.Append("DELETE FROM op_ctnmng WHERE BSNO ='" + head.BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null); var strSql2 = new StringBuilder(); strSql2.Append("DELETE FROM op_ctnmng_ctnstatus WHERE BSNO ='" + head.BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), null); sqlTran.Commit(); } catch (Exception ee) { result = false; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static bool UpCtnStop(string bSNO, List detailBodyList) { bool result = true; Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { foreach (var item in detailBodyList) { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set CTNSTATUS='不可用', ISSTOP=1,RETURNYARD='" + item.RETURNYARD + "' WHERE CTNGID = '" + item.CTNGID+ "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } sqlTran.Commit(); } catch (Exception ee) { result = false; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static bool UpCtnIsReturn(string bSNO, List detailBodyList,string isreturn="1") { bool result = true; Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { foreach (var item in detailBodyList) { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set CTNSTATUS='不可用',ISBERETURN=1,RETURNYARD='" + item.RETURNYARD+"' WHERE CTNGID = '" + item.CTNGID + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } sqlTran.Commit(); } catch (Exception ee) { result = false; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static DBResult DeleteReturnDetail(List list) { var result = new DBResult(); string ids = ""; foreach (var m in list) { ids += "'" + m.GID + "',"; } ids = ids.Substring(0, ids.Length - 1); Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("delete from op_ctnmng_return where GID IN (" + ids + ") "); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); result.Success = true; result.Message = "删除成功"; sqlTran.Commit(); } catch (Exception ee) { result.Success = false; result.Message = "删除出错," + ee.Message; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static DBResult DeleteCtnDetail(List list,string BSNO, bool isdeletectn) { var result = new DBResult(); string ids = ""; foreach (var m in list) { ids += "'" + m.CTNGID + "',"; } ids = ids.Substring(0, ids.Length - 1); Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { if (isdeletectn) { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("DELETE FROM op_ctnmng_ctndetail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID IN (" + ids + ") "); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } var strSqlMng = new StringBuilder(); strSqlMng.Append("DELETE FROM op_ctnmng_detail WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlMng.ToString(), null); var strSql2 = new StringBuilder(); strSql2.Append("DELETE FROM op_ctnmng_ctnstatus WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), null); result.Success = true; result.Message = "删除成功"; sqlTran.Commit(); } catch (Exception ee) { result.Success = false; result.Message = "删除出错,"+ee.Message; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static DBResult CtnAdd(string bsno, List bodyList,string userid) { var result = new DBResult(); var OpSea = MsOpBillDAL.GetData("BSNO='"+bsno+"'"); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { foreach (var enumValue in bodyList) { var SIZE = enumValue.CTNALL.ToString().Trim().Substring(0, 2); string CTN = enumValue.CTNALL.ToString().Trim().Substring(2); if (enumValue.CTNALL.IndexOf("'") > 0) CTN = enumValue.CTNALL.ToString().Trim().Substring(3); int TEU =1; var iTEU = enumValue.CTNALL.ToString().Trim().Substring(0, 1); if (iTEU == "4") { TEU = TEU * 2; } else if (iTEU == "L") { TEU = 0; } var cmdInsert = db.GetSqlStringCommand(@"insert into op_ctn (CTN_ID,BSNO,CTNCODE,[SIZE],CTN,CTNNUM,TEU,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,KINDPKGS,TAREWEIGHT,GOODSNAME,CTNSTATUS,MASTERNO,WEIGHTYPE,WEIGHKGS,WEIGHATTN,WEIGHTEL,WEIGHSIGN,WEIGHDATE,TRUCKER,TRUCKFEE,FREESTORAGEDAY,STORAGEDAY,STORAGEPRICE,STORAGEFEE,FREECTNDAY,CTNDAY,CTNPRICE,CTNFEE,TRUCKNO,VGMCONNCOM,VGMADDR,VGMEMAIL,PCTN_ID) values (NEWID()" + ",'" + bsno + "','" +1 + "','" +SIZE + "','" + CTN + "',1," + TEU.ToString() + ",'" + enumValue.CTNALL.Replace("'", "''") + "','" + enumValue.CNTRNO + "','',0,0,0,'','',0,'','','','',0,'','','','','',0,0,0,0,0,0,0,0,0,'','','','','" + enumValue.CTNGID + "')"); db.ExecuteNonQuery(cmdInsert, tran); var headData =new CtnrDyDetail(); headData.GID = Guid.NewGuid().ToString(); headData.CTNGID = enumValue.CTNGID; headData.CNTRNO = enumValue.CNTRNO; headData.CTNSTATUS = "在途"; headData.CTNSTATUSTIME= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.CTNEF = "F"; headData.BSNO = OpSea.BSNO; headData.MBLNO = OpSea.MBLNO; headData.HBLNO = OpSea.HBLNO; headData.VESSEL = OpSea.VESSEL; headData.VOYNO = OpSea.VOYNO; headData.ACCDATE= DateTime.Now.ToString("yyyy-MM"); headData.ETD = OpSea.ETD; headData.ETA = OpSea.ETA; headData.PORTLOAD = OpSea.PORTLOAD; headData.DESTPORT = OpSea.PORTDISCHARGE; headData.AGENTNAME = OpSea.AGENTID; headData.CUSTNO = OpSea.CUSTNO; headData.DbOperationType = DbOperationType.DbotIns; headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.CREATEUSER = userid; headData.MODIFYTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.MODIFYUSER = userid; if (OpSea.OPLBNAME == "海运进口") { headData.PORT = OpSea.PORTDISCHARGE; headData.YARD = OpSea.YARD; } else { headData.PORT = OpSea.PORTLOAD; headData.YARD = OpSea.YARD; } var modb = new ModelObjectDB(); modb.Save(headData); enumValue.DbOperationType = DbOperationType.DbotUpd; enumValue.CTNSTATUS ="不可用"; modb.Save(enumValue); } } 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 CtnBsAdd(string bsno, List bodyList, string userid) { var result = new DBResult(); var OpSea = MsOpBillDAL.GetData("BSNO='" + bsno + "'"); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { foreach (var enumValue in bodyList) { if (string.IsNullOrEmpty(enumValue.PCTN_ID)) { var ctndetail = GetCtnData("c.CNTRNO='"+ enumValue.CNTRNO + "'"); if (!string.IsNullOrEmpty(ctndetail.CNTRNO)) { var headData = new CtnrDyDetail(); headData.GID = Guid.NewGuid().ToString(); headData.CTNGID = ctndetail.CTNGID; headData.CNTRNO = enumValue.CNTRNO; headData.CTNSTATUS = "在途"; headData.CTNSTATUSTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.CTNEF = "F"; headData.BSNO = OpSea.BSNO; headData.MBLNO = OpSea.MBLNO; headData.HBLNO = OpSea.HBLNO; headData.VESSEL = OpSea.VESSEL; headData.VOYNO = OpSea.VOYNO; headData.ETD = OpSea.ETD; headData.ETA = OpSea.ETA; headData.ACCDATE = DateTime.Now.ToString("yyyy-MM"); headData.PORTLOAD = OpSea.PORTLOAD; headData.DESTPORT = OpSea.PORTDISCHARGE; headData.AGENTNAME = OpSea.AGENTID; headData.CUSTNO = OpSea.CUSTNO; headData.DbOperationType = DbOperationType.DbotIns; headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.CREATEUSER = userid; headData.MODIFYTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.MODIFYUSER = userid; var modb = new ModelObjectDB(); result=modb.Save(headData); if (result.Success) { ctndetail.DbOperationType = DbOperationType.DbotUpd; ctndetail.CTNSTATUS = "不可用"; modb.Save(ctndetail); var cmdInsert = db.GetSqlStringCommand(@"update op_ctn set PCTN_ID='"+ ctndetail.CTNGID+ "' where ='" + enumValue.CTN_ID + "'"); 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 SaveSellDetail(CtnrList head, List list, string BSNO,string USERID) { var result = new DBResult(); string ids = ""; foreach (var m in list) { ids += "'" + m.CTNGID + "',"; } ids = ids.Substring(0, ids.Length - 1); Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { var strSql2 = new StringBuilder(); strSql2.Append("update op_ctnmng_ctnstatus set BSNO='' WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), null); foreach (CtnrDetail item in list) { CtnrDyDetail dyDetail = new CtnrDyDetail(); dyDetail.GID = Guid.NewGuid().ToString().Replace("-", ""); dyDetail.CNTRNO = item.CNTRNO; dyDetail.CREATETIME = DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss"); dyDetail.CREATEUSER = USERID; dyDetail.CTNEF = item.CTNEF; dyDetail.CTNGID = item.CTNGID; dyDetail.CTNSTATUS = item.CTNSTATUS; dyDetail.CTNSTATUSTIME = item.CTNSTATUSTIME; dyDetail.MBLNO = item.MBLNO; dyDetail.YARD = item.YARD; dyDetail.PORT = item.PORT; dyDetail.CUSTNO = item.CUSTNO; dyDetail.REMARK = item.REMARK; dyDetail.BSNO = head.BSNO; var modbDy = new ModelObjectRepository(); dyDetail.ModelUIStatus = "I"; dyDetail.DbOperationType = DbOperationType.DbotIns; result = modbDy.Save(dyDetail); } result.Success = true; result.Message = "删除成功"; sqlTran.Commit(); } catch (Exception ee) { result.Success = false; result.Message = "删除出错," + ee.Message; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static DBResult DeleteCtnDetail(CtnrList head,List list, string BSNO, bool isdeletectn) { var result = new DBResult(); string ids = ""; foreach (var m in list) { ids += "'" + m.CTNGID + "',"; } ids = ids.Substring(0, ids.Length - 1); Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { if (head.BLTYPE == "卖箱" || head.BLTYPE == "退租") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID in(select CTNGID from op_ctnmng_detail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (head.BLTYPE == "返箱") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISBERETURN=1 where CTNGID in(select CTNGID from op_ctnmng_detail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } else if (head.BLTYPE == "租出" && head.RETURNTYPE == "返箱") { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("update op_ctnmng_ctndetail set ISBERETURN=0 where CTNGID in(select CTNGID from op_ctnmng_detail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "')"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); } var strSqlMng = new StringBuilder(); strSqlMng.Append("DELETE FROM op_ctnmng_detail WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlMng.ToString(), null); var strSql2 = new StringBuilder(); strSql2.Append("DELETE FROM op_ctnmng_ctnstatus WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), null); result.Success = true; result.Message = "删除成功"; sqlTran.Commit(); } catch (Exception ee) { result.Success = false; result.Message = "删除出错," + ee.Message; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static bool DeleteMng(string BSNO, out string msg) { string message; Database db = DatabaseFactory.CreateDatabase(); string DelSql = "DELETE FROM op_ctnmng WHERE BSNO ='"+BSNO+"'"; bool result = false; try { result = db.ExecuteNonQuery(CommandType.Text, DelSql) > 0; if (result) { message = "删除成功!"; } else { message = "删除失败!"; } } catch (Exception ex) { result = false; message = ex.Message; } msg = message; return result; } public static DBResult DeleteCtnReturnDetail(List list, string BSNO) { var result = new DBResult(); string ids = ""; foreach (var m in list) { ids += "'" + m.GID + "',"; } ids = ids.Substring(0, ids.Length - 1); Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { var strSqlCtnr = new StringBuilder(); strSqlCtnr.Append("DELETE FROM op_ctnmng_return where GID IN (" + ids + ") AND BSNO='" + BSNO + "'"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlCtnr.ToString(), null); result.Success = true; result.Message = "删除成功"; sqlTran.Commit(); } catch (Exception ee) { result.Success = false; result.Message = "删除出错," + ee.Message; sqlTran.Rollback(); } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return result; } public static CtnrList GetData(string conditions, string userid, string username, string companyid) { int total = 0; var TList = GetDataList(conditions, 0, 1, userid, username, companyid, out total); CtnrList ctnr = new CtnrList(); if (TList.Count > 0) { ctnr = GetDataList(conditions, 0, 1, userid, username, companyid, out total)[0]; } return ctnr; } static public CtnrDetailAX GetCtnrDetailData(string condition) { var _t = ""; var list = GetDetailList(condition, _t); if (list.Count > 0) return list[0]; return new CtnrDetailAX(); } private static List SetCtnrDetailAXData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CtnrDetailAX data = new CtnrDetailAX(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CTNGID = Convert.ToString(reader["CTNGID"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.CNTRSOURCE = Convert.ToString(reader["CNTRSOURCE"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]); data.CTNSTATUSTIME = Convert.ToString(reader["CTNSTATUSTIME"]); data.PORT = Convert.ToString(reader["PORT"]); data.YARD = Convert.ToString(reader["YARD"]); data.CTNEF = Convert.ToString(reader["CTNEF"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.DRFEENAME = Convert.ToString(reader["DRFEENAME"]); data.CRFEENAME = Convert.ToString(reader["CRFEENAME"]); data.DR = Convert.ToString(reader["DR"]); data.CR = Convert.ToString(reader["CR"]); data.MXCR = Convert.ToString(reader["MXCR"]); data.CTNEFREF = Convert.ToString(reader["CTNEFREF"]); data.RETURNYARD= Convert.ToString(reader["RETURNYARD"]); data.OWNERCTN = reader["OWNERCTN"].ToString(); if (reader["ENDRENTDATE"] != DBNull.Value) data.ENDRENTDATE = Convert.ToDateTime(reader["ENDRENTDATE"]).ToString("yyyy-MM-dd"); data.NOTYPE = reader["NOTYPE"].ToString(); data.CTNCOLOR = reader["CTNCOLOR"].ToString(); data.ISLOCKBOX = reader["ISLOCKBOX"].ToString(); data.ISSLOT = reader["ISSLOT"].ToString(); data.ISLOCKBOXREF = reader["ISLOCKBOXREF"].ToString(); data.ISSLOTREF = reader["ISSLOTREF"].ToString(); data.NBSNO = reader["NBSNO"].ToString(); data.CURR = reader["CURR"].ToString(); #endregion headList.Add(data); } reader.Close(); } return headList; } private static List SetCtnrDyDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CtnrDyDetail data = new CtnrDyDetail(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CTNGID = Convert.ToString(reader["CTNGID"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]); data.CTNSTATUSTIME = Convert.ToString(reader["CTNSTATUSTIME"]); data.PORT = Convert.ToString(reader["PORT"]); data.YARD = Convert.ToString(reader["YARD"]); data.CTNEF = Convert.ToString(reader["CTNEF"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CTNEFREF = Convert.ToString(reader["CTNEFREF"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd"); if (reader["ETA"] != DBNull.Value) data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd"); data.AGENTNAME = Convert.ToString(reader["AGENTNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD_STATOIN = Convert.ToString(reader["PORTLOAD_STATOIN"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); if (reader["PORTLOAD_CNT_TIME"] != DBNull.Value) data.PORTLOAD_CNT_TIME = Convert.ToDateTime(reader["PORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["PORTLOAD_FREE_DAYS"] != DBNull.Value) data.PORTLOAD_FREE_DAYS = Convert.ToDecimal(reader["PORTLOAD_FREE_DAYS"]); if (reader["PORTLOAD_OVER_DAYS"] != DBNull.Value) data.PORTLOAD_OVER_DAYS = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS"]); if (reader["PORTLOAD_OVER_DAYS_FEE"] != DBNull.Value) data.PORTLOAD_OVER_DAYS_FEE = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS_FEE"]); if (data.ETD != "" && (data.PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.ETD) < DateTime.Now))) { var _days = Convert.ToDateTime(data.ETD) - Convert.ToDateTime(data.PORTLOAD_CNT_TIME); if ((_days.Days + 1 - data.PORTLOAD_FREE_DAYS) > 0) data.PORTLOAD_OVER_DAYS = _days.Days + 1 - data.PORTLOAD_FREE_DAYS; else data.PORTLOAD_OVER_DAYS = 0; } else if (data.ETD != "" && (data.PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.ETD) >= DateTime.Now))) { var _days = Convert.ToDateTime(data.ETD) - Convert.ToDateTime(DateTime.Now); if ((_days.Days + 1 - data.PORTLOAD_FREE_DAYS) > 0) data.PORTLOAD_OVER_DAYS = _days.Days + 1 - data.PORTLOAD_FREE_DAYS; else data.PORTLOAD_OVER_DAYS = 0; } data.PORTLOAD_OVER_DAYS_AMT = data.PORTLOAD_OVER_DAYS * data.PORTLOAD_OVER_DAYS_FEE; data.DESTPORT = Convert.ToString(reader["DESTPORT"]); if (reader["DEST_CNT_TIME"] != DBNull.Value) data.DEST_CNT_TIME = Convert.ToDateTime(reader["DEST_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["DEST_RTCNT_TIME"] != DBNull.Value) data.DEST_RTCNT_TIME = Convert.ToDateTime(reader["DEST_RTCNT_TIME"]).ToString("yyyy-MM-dd"); data.DESTPORT_STATOIN = Convert.ToString(reader["DESTPORT_STATOIN"]); if (reader["DESTPORT_FREE_DAYS"] != DBNull.Value) data.DESTPORT_FREE_DAYS = Convert.ToDecimal(reader["DESTPORT_FREE_DAYS"]); if (reader["DESTPORT_OVER_DAYS_FEE"] != DBNull.Value) data.DESTPORT_OVER_DAYS_FEE = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS_FEE"]); if (data.DEST_RTCNT_TIME != "" && (data.ETA != "" && (Convert.ToDateTime(data.ETA) < DateTime.Now))) { var _days = Convert.ToDateTime(data.DEST_RTCNT_TIME) - Convert.ToDateTime(data.ETA); if ((_days.Days + 1 - data.DESTPORT_FREE_DAYS) > 0) data.DESTPORT_OVER_DAYS = _days.Days + 1 - data.DESTPORT_FREE_DAYS; else data.DESTPORT_OVER_DAYS = 0; } else if (data.DEST_RTCNT_TIME == "" && (data.ETA != "" && (Convert.ToDateTime(data.ETA) < DateTime.Now))) { var _days = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) - Convert.ToDateTime(data.ETA); if ((_days.Days + 1 - data.DESTPORT_FREE_DAYS) > 0) data.DESTPORT_OVER_DAYS = _days.Days + 1 - data.DESTPORT_FREE_DAYS; else data.DESTPORT_OVER_DAYS = 0; } data.DESTPORT_OVER_DAYS_AMT = data.DESTPORT_OVER_DAYS * data.DESTPORT_OVER_DAYS_FEE; 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.MODIFYUSER = Convert.ToString(reader["MODIFYUSER"]); if (reader["MODIFYTIME"] != DBNull.Value) data.MODIFYTIME = Convert.ToDateTime(reader["MODIFYTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.TRANSTYPE = Convert.ToString(reader["TRANSTYPE"]); if (reader["BSSTATUS"] != DBNull.Value) data.BSSTATUS = Convert.ToBoolean((reader["BSSTATUS"])); if (reader["FEESTATUS"] != DBNull.Value) data.FEESTATUS = Convert.ToBoolean((reader["FEESTATUS"])); data.BSSTATUSREF = Convert.ToString(reader["BSSTATUSREF"]);// 业务状态 data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);// 费用状态 data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"])); data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"])); data.CREATEBSFEEREF = reader["CREATEBSFEEREF"].ToString(); data.ACCDATE = reader["ACCDATE"].ToString(); data.OP = reader["OP"].ToString(); data.CORPID = reader["CORPID"].ToString(); data.SALECORPID = reader["SALECORPID"].ToString(); data.BSNO = reader["BSNO"].ToString(); #endregion headList.Add(data); } reader.Close(); } return headList; } private static List SetCtnrDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CtnrDetail data = new CtnrDetail(); #region Set DB data to Object data.CTNGID = Convert.ToString(reader["CTNGID"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.CNTRSOURCE = Convert.ToString(reader["CNTRSOURCE"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.CURSTATUS = Convert.ToString(reader["CURSTATUS"]); data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]); data.CTNSTATUSTIME = Convert.ToString(reader["CTNSTATUSTIME"]); data.PORT = Convert.ToString(reader["PORT"]); data.YARD = Convert.ToString(reader["YARD"]); data.CTNEF = Convert.ToString(reader["CTNEF"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CTNEFREF = Convert.ToString(reader["CTNEFREF"]); if (reader["ISSTOP"] != DBNull.Value) data.ISSTOP = Convert.ToBoolean(reader["ISSTOP"]);//业务状态 data.ISSTOPREF = Convert.ToString(reader["ISSTOPREF"]); if (reader["ISBERETURN"] != DBNull.Value) data.ISBERETURN = Convert.ToBoolean(reader["ISBERETURN"]);//业务状态 data.ISBERETURNREF = Convert.ToString(reader["ISBERETURNREF"]); data.OWNERCTN = reader["OWNERCTN"].ToString(); if (reader["ENDRENTDATE"] != DBNull.Value) data.ENDRENTDATE = Convert.ToDateTime(reader["ENDRENTDATE"]).ToString("yyyy-MM-dd"); data.NOTYPE = reader["NOTYPE"].ToString(); data.CTNCOLOR = reader["CTNCOLOR"].ToString(); data.ISLOCKBOX = reader["ISLOCKBOX"].ToString(); data.ISSLOT = reader["ISSLOT"].ToString(); data.ISLOCKBOXREF = reader["ISLOCKBOXREF"].ToString(); data.ISSLOTREF = reader["ISSLOTREF"].ToString(); data.ISLOCK= reader["ISLOCK"].ToString(); data.ISLOCKREF = reader["ISLOCKREF"].ToString(); data.BSNO= reader["BSNO"].ToString(); #endregion headList.Add(data); } reader.Close(); } return headList; } #region 还箱地点 /// /// 获取提单号下录入的箱型 /// /// static public List GetCtnReturnList(string strCondition,string sort) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[BSNO],[PORT],[YARD],[AGENT],[REMARK],[CREATEUSER],[CREATETIME] from op_ctnmng_return where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME "); } return SetCtnReturnData(strSql); } private static List SetCtnReturnData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CtnrReturn data = new CtnrReturn(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.PORT = Convert.ToString(reader["PORT"]); data.YARD = Convert.ToString(reader["YARD"]); data.AGENT = Convert.ToString(reader["AGENT"]); data.REMARK = Convert.ToString(reader["REMARK"]); //if (reader["TimeMark"] != DBNull.Value) // data.TimeMark = Convert.ToDecimal(reader["TimeMark"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 箱型 /// /// 获取提单号下录入的箱型 /// /// static public List GetCodeCtnList() { String strSql = @"SELECT DISTINCT CTN AS CTNALL FROM code_ctn"; return SetCodeCtnData(strSql); } private static List SetCodeCtnData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeCtnModel data = new CodeCtnModel(); #region Set DB data to Object data.CTN = Convert.ToString(reader["CTNALL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 批量修改 public static DBResult Modify(List bodyList, CtnrDyDetail modifydata,string userid,string companyid) { var result = new DBResult(); string GIDstr = ""; if (bodyList != null) { foreach (var enumValue in bodyList) { if (!string.IsNullOrEmpty(GIDstr)) { GIDstr = GIDstr + ",'" + enumValue.GID + "'"; } else { GIDstr = "'" + enumValue.GID + "'"; } } } if (!string.IsNullOrEmpty(GIDstr)) { var dynalist = MsOpCtnrDAL.GetDynaList("GID IN ("+GIDstr+")", ""); foreach (var dyna in dynalist) { if (!string.IsNullOrEmpty(modifydata.VESSEL)) dyna.VESSEL = modifydata.VESSEL; if (!string.IsNullOrEmpty(modifydata.VOYNO)) dyna.VOYNO = modifydata.VOYNO; if (!string.IsNullOrEmpty(modifydata.PORTLOAD_CNT_TIME)) dyna.PORTLOAD_CNT_TIME = modifydata.PORTLOAD_CNT_TIME; if (!string.IsNullOrEmpty(modifydata.ETD)) dyna.ETD = modifydata.ETD; if (!string.IsNullOrEmpty(modifydata.TRANSTYPE)) dyna.TRANSTYPE = modifydata.TRANSTYPE; if (!string.IsNullOrEmpty(modifydata.PORTLOAD_STATOIN)) dyna.PORTLOAD_STATOIN = modifydata.PORTLOAD_STATOIN; if (!string.IsNullOrEmpty(modifydata.PORTLOAD)) dyna.PORTLOAD = modifydata.PORTLOAD; if (!string.IsNullOrEmpty(modifydata.ETD)) dyna.ETD = modifydata.ETD; if (!string.IsNullOrEmpty(modifydata.DESTPORT)) dyna.DESTPORT = modifydata.DESTPORT; if (!string.IsNullOrEmpty(modifydata.ETA)) dyna.ETA = modifydata.ETA; if (!string.IsNullOrEmpty(modifydata.DESTPORT_STATOIN)) dyna.DESTPORT_STATOIN = modifydata.DESTPORT_STATOIN; if (!string.IsNullOrEmpty(modifydata.DEST_CNT_TIME)) dyna.DEST_CNT_TIME = modifydata.DEST_CNT_TIME; if (!string.IsNullOrEmpty(modifydata.DEST_RTCNT_TIME)) dyna.DEST_RTCNT_TIME = modifydata.DEST_RTCNT_TIME; dyna.DbOperationType = DbOperationType.DbotUpd; dyna.ModelUIStatus = "E"; dyna.MODIFYTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); dyna.MODIFYUSER =userid; if (dyna.ETA == "") dyna.ETA = null; if (dyna.ETD == "") dyna.ETD = null; if (dyna.PORTLOAD_CNT_TIME == "") dyna.PORTLOAD_CNT_TIME = null; if (dyna.DEST_CNT_TIME == "") dyna.DEST_CNT_TIME = null; if (dyna.DEST_RTCNT_TIME == "") dyna.DEST_RTCNT_TIME = null; var modb = new ModelObjectDB(); MsOpCtnrDAL.SetDynaStatus(dyna); result = modb.Save(dyna); } } return result; } #endregion /// /// 获取费用状态的显示文字 /// /// /// public static string getfeestatus(string feestatusint) { var result = ""; if (feestatusint == "0:") { return "审核通过"; } else if (feestatusint == "1:") { return "录入状态"; } else if (feestatusint == "2:") { return "提交审核"; } else if (feestatusint == "8:") { return "部分结算"; } else if (feestatusint == "9:") { return "结算完毕"; } else if (feestatusint == "") { return "未录入"; } else if (feestatusint == "3:") { return "申请修改"; } else if (feestatusint == "4:") { return "申请删除"; } else if (feestatusint == "6:") { return "驳回提交"; } else if (feestatusint == "7:") { return "驳回申请"; } else if (feestatusint.IndexOf("9:") > -1) { return "部分结算"; } else if (feestatusint.IndexOf("8:") > -1) { return "部分结算"; } else if (feestatusint.IndexOf("0:") > -1) { return "部分审核"; } else if (feestatusint.IndexOf("2:") > -1) { return "部分提交"; } else if (feestatusint.IndexOf("6:") > -1) { return "驳回提交"; } else if (feestatusint.IndexOf("7:") > -1) { return "驳回申请"; } return result; } #region 权限范围 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 "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modCtnMng' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; 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"]); break; } reader.Close(); } if (visiblerange == "4") { str = "1=2"; } else if (visiblerange == "3") { str = " (OP='" + username + "' OR SALE='" + username + "' OR CREATEUSER='" + userid + "')"; } else if (visiblerange == "2") { if (tb == "index") { var rangeDa = new RangeDA(); var deptid = rangeDa.GetDEPTGID(userid); str = " (SALE in (select showname from vw_user where deptgid='" + deptid + "') OR OP in (select showname from vw_user where deptgid='" + deptid + "') OR CREATEUSER in (select userid from vw_user where deptgid='" + deptid + "'))"; //var userstr = new StringBuilder(); //userstr.Append(" 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 + "')"); //Database userdb = DatabaseFactory.CreateDatabase(); //using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) //{ // str = ""; // while (reader.Read()) // { // if (str == "") // { // str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.DOC='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.FRCUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "'"; // } // else // { // str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.DOC='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.FRCUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "'"; // }; // } // str = str + ")"; // reader.Close(); //} } else { str = " UPPER(CORPID)='" + 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 = " (Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'"; } else { str = str + " or Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else { str = " UPPER(Corpid)='" + companyid + "'"; } } else if (visiblerange == "6") { if (tb == "index") { 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())) { str = ""; while (reader.Read()) { if (str == "") { str = " (SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR CREATEUSER='" + Convert.ToString(reader["OPID"]) + "' "; } else { str = str + " or SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR CREATEUSER='" + Convert.ToString(reader["OPID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else { str = " UPPER(Corpid)='" + companyid + "'"; } } else if (visiblerange == "1") { str = " UPPER(Corpid)='" + companyid + "'"; } return str; } #endregion #region 生成应收应付费用 public static bool CreateCost(CtnrList head, List CtnrListAX, string userid, out string msg) { //判断该单号是否已生成过费用 Database db = DatabaseFactory.CreateDatabase(); string check = @"SELECT count(*) from op_ctnmng where ISCREATEFEE=1 and BSNO = '" + head.BSNO + "' "; if (Convert.ToInt32(db.ExecuteScalar(CommandType.Text, check)) > 0) { msg = "已经生成过费用,不允许重复生成!"; return false; } List list = new List(); foreach (var item in CtnrListAX) { //dr += Convert.ToDecimal(item.DR); //cr += Convert.ToDecimal(item.CR); //crFeeName = item.DRFEENAME; //drFeeName = item.CRFEENAME; if (!string.IsNullOrEmpty(item.CR) && item.CR != "0") { CtnrCost s = new CtnrCost(); s.BSNO = head.BSNO; s.CUSTOMERNAME = head.CUSTOMERNAME; s.FEENAME =item.CRFEENAME; s.CURR = item.CURR; s.FEE =Convert.ToDecimal(item.CR); s.REMARK = item.CNTRNO; s.FEETYPE = "2"; list.Add(s); } if (!string.IsNullOrEmpty(item.DR) && item.DR != "0") { CtnrCost t = new CtnrCost(); t.BSNO = head.BSNO; t.CUSTOMERNAME = head.CUSTOMERNAME; t.FEENAME = item.DRFEENAME; t.CURR = item.CURR; t.FEE = Convert.ToDecimal(item.DR); t.REMARK = item.CNTRNO; t.FEETYPE = "1"; list.Add(t); } } bool rst = false; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { foreach (var cm in list) { //if (cm.FEE > 0) //{ StringBuilder sb = new StringBuilder(); sb.Append(@"insert into ch_fee (GID,BSNO,FEETYPE,FEENAME,REMARK,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,"); sb.Append(@"AMOUNT,CURRENCY,EXCHANGERATE,FEESTATUS,NOTAXAMOUNT,TAXUNITPRICE,ENTEROPERATOR,WMSOUTBSNO) "); sb.Append(@" VALUES("); sb.Append("'" + Guid.NewGuid() + "',");//GID sb.Append("'" + cm.BSNO + "',");//BSNO sb.Append("'" + cm.FEETYPE + "', ");//FEETYPE sb.Append("'" + cm.FEENAME + "',");//FEENAME sb.Append("'" + cm.REMARK + "',");//REMARK sb.Append("'" + cm.CUSTOMERNAME + "',");//CUSTOMERNAME sb.Append("'" + "单票" + "',");//UNIT sb.Append(cm.FEE + ",");//UNITPRICE sb.Append("1" + ",");//QUANTITY sb.Append(cm.FEE + ",");//AMOUNT sb.Append("'" + cm.CURR + "',");//CURRENCY sb.Append("1" + ",");//EXCHANGERATE sb.Append("1" + ",");//FEESTATUS sb.Append(cm.FEE + ",");//NOTAXAMOUNT sb.Append(cm.FEE + ",");//TAXUNITPRICE sb.Append("'" + userid + "',");//ENTEROPERATOR sb.Append("'" + head.BSNO + "'");//ENTEROPERATOR sb.Append(")"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sb.ToString(), null); //} } SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "update op_ctnmng set ISCREATEFEE=1 where BSNO='" + head.BSNO + "'", null); sqlTran.Commit(); msg = "生成成功!"; rst = true; } catch (Exception) { msg = "生成失败!"; sqlTran.Rollback(); rst = false; } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return rst; } public static bool CancelCost(CtnrList head, string userid, out string msg) { Database db = DatabaseFactory.CreateDatabase(); bool rst = false; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { StringBuilder sb = new StringBuilder(); sb.Append("delete from ch_fee where BSNO = '" + head.BSNO + "' and WMSOUTBSNO='"+head.BSNO+"' "); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sb.ToString(), null); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "update op_ctnmng set ISCREATEFEE=0 where BSNO='"+head.BSNO+"'", null); sqlTran.Commit(); msg = "取消费用成功!"; rst = true; } catch (Exception) { msg = "取消费用失败!"; sqlTran.Rollback(); rst = false; } finally { SqlHelper.CloseConnection(); sqlTran.Dispose(); } } return rst; } public static bool GetFeeCount(string BSNO) { var isfee = false; var strSql = new StringBuilder(); strSql.Append("Select count(*) as count "); strSql.Append(" from ch_fee "); strSql.Append(" where BSNO='" + BSNO + "'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } #endregion } }