using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsSeaiFee; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; namespace DSWeb.Areas.MvcShipping.DAL { public partial class MsSeaiFeeDAL { #region Inquery DataList static public List GetDataList(string strCondition, string userid, string usercode, string orgcode,string sort=null) { /* var rangstr = GetRangDAStr("index", userid, usercode, orgcode); 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,BSSTATUS,FEESTATUS,BSDATE,ACCDATE,MBLNO,HBLNO,CUSTNO"); strSql.Append(",TRANSNO,CUSTOMERNAME,BLTYPE,SHIPPERID,CONSIGNEEID,NOTIFYPARTYID"); strSql.Append(",AGENTID,YARD,VESSEL,VOYNO,ETD,CLOSINGDATE,ETA,PORTLOAD,PORTDISCHARGEID"); strSql.Append(",PORTDISCHARGE,BLFRT,SERVICE,CNTRTOTAL,INPUTBY,OP,CUSTSERVICE"); strSql.Append(",LANE,SALE,CARRIER,FORWARDER,CUSTOMSER,TRUCKER,BSSOURCE,BSSOURCEDETAIL"); strSql.Append(",ORDTYPE,ORDERNO"); strSql.Append(",CORPID,SALEDEPT,MBLFRT,PKGS,KGS,CBM,CREATETIME,NETWEIGHT,GOODSNAME,TRADETYPE"); strSql.Append(" from op_seai "); 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 BSDATE desc"); } return SetData(strSql); } static public MsOpSeai GetData(string condition, string userid, string usercode, string orgcode) { var list = GetDataList(condition,userid,usercode,orgcode); if (list.Count > 0) return list[0]; return new MsOpSeai(); } 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()) { MsOpSeai data = new MsOpSeai(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); if (reader["BSDATE"] != DBNull.Value) data.BSDATE = Convert.ToDateTime(reader["BSDATE"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]); if (reader["CLOSINGDATE"] != DBNull.Value) data.CLOSINGDATE = Convert.ToDateTime(reader["CLOSINGDATE"]); if (reader["ETA"] != DBNull.Value) data.ETA = Convert.ToDateTime(reader["ETA"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.TRANSNO = Convert.ToString(reader["TRANSNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); // data.TimeMark = Convert.ToDecimal(reader["TimeMark"]); data.BLTYPE = Convert.ToString(reader["BLTYPE"]); data.SHIPPERID = Convert.ToString(reader["SHIPPERID"]); data.CONSIGNEEID = Convert.ToString(reader["CONSIGNEEID"]); data.NOTIFYPARTYID = Convert.ToString(reader["NOTIFYPARTYID"]); data.AGENTID = Convert.ToString(reader["AGENTID"]); data.YARD = Convert.ToString(reader["YARD"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGEID = Convert.ToString(reader["PORTDISCHARGEID"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.BLFRT = Convert.ToString(reader["BLFRT"]); data.SERVICE = Convert.ToString(reader["SERVICE"]); data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.LANE = Convert.ToString(reader["LANE"]); data.SALE = Convert.ToString(reader["SALE"]); data.CARRIER = Convert.ToString(reader["CARRIER"]); data.FORWARDER = Convert.ToString(reader["FORWARDER"]); data.CUSTOMSER = Convert.ToString(reader["CUSTOMSER"]); data.TRUCKER = Convert.ToString(reader["TRUCKER"]); data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]); data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]); data.ORDTYPE = Convert.ToString(reader["ORDTYPE"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.MBLFRT = Convert.ToString(reader["MBLFRT"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.SALEDEPT = Convert.ToString(reader["SALEDEPT"]); if (reader["PKGS"] != DBNull.Value) data.PKGS = Convert.ToInt32(reader["PKGS"]); if (reader["KGS"] != DBNull.Value) data.KGS = Convert.ToDecimal(reader["KGS"]); if (reader["CBM"] != DBNull.Value) data.CBM = Convert.ToDecimal(reader["CBM"]); if (reader["NETWEIGHT"] != DBNull.Value) data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.TRADETYPE = Convert.ToString(reader["TRADETYPE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion static public List GetCtnUnitList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("SIZE,CTN,SUM(CTNNUM) AS CTNNUM,SUM(TEU) AS TEU,CTNALL"); strSql.Append(" from OP_CTN "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" GROUP BY SIZE,CTN,CTNALL "); return SetCtnUnitData(strSql); } private static List SetCtnUnitData(StringBuilder strSql) { var bodyList = new List(); decimal TEUNUM ; TEUNUM = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { MsFeeUnit data = new MsFeeUnit(); while (reader.Read()) { #region Set DB data to Object data.UNIT = Convert.ToString(reader["CTNALL"]); data.QUANTITY = Convert.ToDecimal(reader["CTNNUM"]); TEUNUM =TEUNUM+Convert.ToDecimal(reader["TEU"]); #endregion bodyList.Add(data); } data.UNIT = "TEU"; data.QUANTITY = TEUNUM; reader.Close(); } return bodyList; } #region 参照部分 /* public static string GetRangDAStr(string tb, string userid, string usercode, string orgcode) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modTruckBulk' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; 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"]); break; } reader.Close(); } if (visiblerange == "4") { str = "1=2"; } else if (visiblerange == "3") { if (tb == "index") { str = " (UserCode='" + usercode + "' or SalesCode='" + usercode + "')"; } else { str = " UPPER(OrgCode)='" + orgcode + "'"; } } else if (visiblerange == "2") { if (tb == "index") { var rangeDa = new RangeDA(); var companyid = rangeDa.GetCORPID(userid); var deptname = rangeDa.GetDEPTNAME(userid); str = " (UserCode in (select codename 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 SalesCode in (select codename 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 { str = " UPPER(OrgCode)='" + orgcode + "'"; } } else if (visiblerange == "1") { str = " UPPER(OrgCode)='" + orgcode + "'"; } return str; } */ #endregion } }