using DSWeb.Areas.CommMng.Models; using DSWeb.Areas.OA.Models.WorkFlow; using DSWeb.Common.DB; using DSWeb.EntityDA; using DSWeb.MvcShipping.DAL.MsInfoClient; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Models.MsCtExplan; using DSWeb.MvcShipping.Models.MsInfoClient; using DSWeb.SoftMng.BLL; using DSWeb.SoftMng.Models.MsInfoClass; using DSWeb.SoftMng.Models.MsInfoClientItem; using DSWeb.TruckMng.Helper.Repository; using HcUtility.Comm; using HcUtility.Core; using Microsoft.Practices.EnterpriseLibrary.Data; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using Spire.Pdf; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient;//使用sqlcomm using System.IO;//用于向数据库中存取图片 using System.Linq; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Mvc; using System.Security.Cryptography; using System.Threading; using DSWeb.Areas.Dispatch.Helper; using DSWeb.MvcShipping.Models.MsOpBillYj; using NPOI.SS.Formula.Functions; using javax.xml.crypto; using NPOI.OpenXmlFormats.Dml; using sun.security.jgss; using Quartz.Util; using DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL; using DSWeb.MvcShipping.Models.MsOpSeae; using DSWeb.MvcShipping.DAL.MsOpSeaeDAL; using Aspose.Cells.Drawing; namespace DSWeb.Areas.CommMng.DAL { public class BasicDataRefDAL { #region 费用代码 public static List GetFeeTypeRefList() { return GetFeeTypeRefList(String.Empty); } public static List GetFeeTypeRefList(string sCondition) { var strSql = new StringBuilder(); strSql.Append("Select FeeCode,Name,CodeAndName "); strSql.Append(" from vMsTruckFeeType "); if (!string.IsNullOrEmpty(sCondition)) { strSql.Append(" where " + sCondition); } strSql.Append(" order by FeeCode"); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new FeeTypeRefModel(); evData.FeeCode = Convert.ToString(reader["FeeCode"]); evData.Name = Convert.ToString(reader["Name"]); evData.CodeAndName = Convert.ToString(reader["CodeAndName"]); evList.Add(evData); } reader.Close(); } return evList; } public static List GetFeeGroupRefList() { return GetFeeGroupRefList(String.Empty); } public static List GetFeeGroupRefList(string sCondition) { var strSql = new StringBuilder(); strSql.Append("Select feegroupcode FeeCode,feegroupname Name,feegroupcode+'_'+feegroupname CodeAndName "); strSql.Append(" from code_fee_group "); if (!string.IsNullOrEmpty(sCondition)) { strSql.Append(" where " + sCondition); } strSql.Append(" order by feegroupcode"); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new FeeTypeRefModel(); evData.FeeCode = Convert.ToString(reader["FeeCode"]); evData.Name = Convert.ToString(reader["Name"]); evData.CodeAndName = Convert.ToString(reader["CodeAndName"]); evList.Add(evData); } reader.Close(); } return evList; } #endregion #region 用户 static public List GetActionUserRefList(string strCondition, string modulename, string dbname = "") { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,UserCode,UserName,CodeAndName,CORPID,DEPTGID,DEPTNAME"); strSql.Append(" from vMsActionUser where MODULENAME='" + modulename + "' "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetUserRefData(strSql, dbname); } static public List GetUserRefList() { return GetUserRefList(string.Empty); } /// /// UserCode,UserName,CodeAndName,CORPID,DEPTGID,DEPTNAME /// /// /// /// static public List GetUserRefList(string strCondition, string dbname = "") { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,UserCode,UserName,CodeAndName,CORPID,DEPTGID,DEPTNAME"); strSql.Append(" from vMsTruckUser "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetUserRefData(strSql, dbname); } private static List SetUserRefData(StringBuilder strSql, string dbname = "") { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); if (dbname != "") db = DatabaseFactory.CreateDatabase(dbname); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { UserRefModel data = new UserRefModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.UserCode = Convert.ToString(reader["UserCode"]); data.UserName = Convert.ToString(reader["UserName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.DEPTGID = Convert.ToString(reader["DEPTGID"]); data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]); #endregion headList.Add(data); } reader.Close(); } UserRefModel adata = new UserRefModel(); #region Set DB data to Object adata.GID = ""; adata.UserCode = ""; adata.UserName = ""; adata.CodeAndName = ""; adata.CORPID = ""; adata.DEPTGID = ""; adata.DEPTNAME = ""; #endregion headList.Add(adata); return headList; } static public List GetUserLinkRefList(string strCondition, string COMPANYID) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("l.USERID GID,u.CODENAME UserCode,u.SHOWNAME UserName,u.CODENAME+'-'+u.SHOWNAME CodeAndName,"); strSql.Append("l.OFFICEPHONE Tel,l.FAX Fax,l.EMAIL1 Email,l.DEPTNAME,c.COMPANYID"); strSql.Append(" from [user] u left join user_baseinfo l on (u.gid=l.USERID) "); strSql.Append(" left join user_company c on (u.gid=c.USERID) "); var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='OPONLYSUBCOMPANY'"); if (SeaeDefaultSort.PARAMVALUE != "" && SeaeDefaultSort.PARAMVALUE == "1") strSql.Append(" where c.companyid='" + COMPANYID + "' "); else strSql.Append(" where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" order by u.CODENAME,u.SHOWNAME "); return SetUserLinkRefData(strSql); } static public UserLinkRefModel GetUserLinkRef(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("l.USERID GID,u.USERNAME UserCode,u.SHOWNAME UserName,u.CODENAME+'-'+u.SHOWNAME CodeAndName,"); strSql.Append("l.OFFICEPHONE Tel,l.FAX Fax,l.EMAIL1 Email,l.DEPTNAME,c.COMPANYID"); strSql.Append(" from [user] u left join user_baseinfo l on (u.gid=l.USERID) "); strSql.Append(" left join user_company c on (u.gid=c.USERID) "); strSql.Append(" where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" order by u.CODENAME,u.SHOWNAME "); var list = SetUserLinkRefData(strSql); if (list.Count > 0) return list[0]; return new UserLinkRefModel(); } private static List SetUserLinkRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { UserLinkRefModel data = new UserLinkRefModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.UserCode = Convert.ToString(reader["UserCode"]); data.UserName = Convert.ToString(reader["UserName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.Tel = Convert.ToString(reader["Tel"]); data.Fax = Convert.ToString(reader["Fax"]); data.Email = Convert.ToString(reader["Email"]); data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]); data.CORPID = Convert.ToString(reader["COMPANYID"]); #endregion headList.Add(data); } reader.Close(); } UserLinkRefModel adata = new UserLinkRefModel(); #region Set DB data to Object adata.GID = ""; adata.UserCode = ""; adata.UserName = ""; adata.CodeAndName = ""; adata.Tel = ""; adata.Fax = ""; adata.Email = ""; #endregion headList.Add(adata); return headList; } #endregion #region 配料 public static List GetPluRefList() { return GetPluRefList(String.Empty); } public static List GetPluRefList(string sCondition) { var strSql = new StringBuilder(); strSql.Append("Select PluCode,PluName,PluCode+'-'+PluName as CodeAndName,Unit,Spec,Price "); strSql.Append(" from tMsTruckPlu "); if (!string.IsNullOrEmpty(sCondition)) { strSql.Append(" where " + sCondition); } strSql.Append(" order by PluCode"); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new PluRefModel(); evData.PluCode = Convert.ToString(reader["PluCode"]); evData.PluName = Convert.ToString(reader["PluName"]); evData.CodeAndName = Convert.ToString(reader["CodeAndName"]); evData.Unit = Convert.ToString(reader["Unit"]); evData.Spec = Convert.ToString(reader["Spec"]); evData.Price = Convert.ToDecimal(reader["Price"]); evList.Add(evData); } reader.Close(); } return evList; } #endregion #region 客户参照,对应95004(vMsTruckClient) static public List GetCustomRefList() { return GetCustomRefList(string.Empty); } static public List GetCustomRefList(string strCondition, string IsEnableCustRange = "0", string userid = "", string isall = "0") { var strSql = GetCustomRefList_GetSqlStr(strCondition, IsEnableCustRange, userid, isall); return SetCustomRefData(strSql); } public static StringBuilder GetCustomRefList_GetSqlStr(string strCondition, string IsEnableCustRange = "0", string userid = "", string isall = "0") { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,CODENAME + '-' + description AS CodeAndFull,BillRises1"); strSql.Append(",UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE,OP,DOC,CUSTSERVICE,FEEFRT,BSSOURCE,[EMAIL],[TEL],SALECORPID "); strSql.Append(",(select top 1 CONTRACTNO from info_client_contract WHERE LINKID=info_Client.GID order by STARTDATE desc) CONTRACTNO "); strSql.Append(" from info_Client where 1=1 "); // BLSTATUS=0 if (isall != "1") { var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } } if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } if (IsEnableCustRange == "1") strSql.Append(" and (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range )) "); strSql.Append(" ORDER BY CODENAME "); return strSql; } static public string GetHTStorageName() { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,BillRises1"); strSql.Append(",UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE,OP,DOC,CUSTSERVICE,FEEFRT,BSSOURCE,[EMAIL],[TEL],SALECORPID "); strSql.Append(",'' CONTRACTNO "); strSql.Append(" from info_Client where 1=1 AND ISWAREHOUSE = '1' "); // BLSTATUS=0 var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } strSql.Append(" ORDER BY CODENAME "); return SetCustomRefData(strSql)[0].CustName.ToString(); } private static List SetCustomRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CustomRefModel data = new CustomRefModel(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.CustCode = Convert.ToString(reader["CustCode"]); data.CustName = Convert.ToString(reader["CustName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.BillRises1 = Convert.ToString(reader["BillRises1"]); data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]); data.DESCRIPTION = Convert.ToString(reader["description"]); data.KFCodename = Convert.ToString(reader["KFCodename"]); data.SALE = Convert.ToString(reader["SALE"]); data.FEEFRT = Convert.ToString(reader["FEEFRT"]); data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]); data.EMAIL = Convert.ToString(reader["EMAIL"]); data.TEL = Convert.ToString(reader["TEL"]); data.SALECORPID = Convert.ToString(reader["SALECORPID"]); data.OP = Convert.ToString(reader["OP"]); data.DOC = Convert.ToString(reader["DOC"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); #endregion headList.Add(data); } reader.Close(); } CustomRefModel adata = new CustomRefModel(); #region Set DB data to Object adata.GId = ""; adata.CustCode = ""; adata.CustName = ""; adata.CodeAndName = ""; adata.BillRises1 = ""; adata.UNITPRICE = ""; adata.DESCRIPTION = ""; adata.KFCodename = ""; adata.SALE = ""; adata.FEEFRT = ""; adata.BSSOURCE = ""; #endregion headList.Add(adata); return headList; } static public List GetCustomYardRefList(string strCondition, string IsEnableCustRange = "0", string userid = "") { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,ADDR"); strSql.Append(" from info_client where 1=1 "); var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } if (!string.IsNullOrEmpty(strCondition)) { //if (IsEnableCustRange == "1") // strSql.Append(" and SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) "); strSql.Append(" and " + strCondition); } return SetCustomYardRefData(strSql); } public static string GetCustomerCode(string customername) { var condition = " SHORTNAME='" + customername + "' "; var _list = GetCustomYardRefList(condition); if (_list != null && _list.Count > 0) { return _list[0].CustCode; } return ""; } private static List SetCustomYardRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CustomYardRefModel data = new CustomYardRefModel(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.CustCode = Convert.ToString(reader["CustCode"]); data.CustName = Convert.ToString(reader["CustName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.ADDR = Convert.ToString(reader["ADDR"]); #endregion headList.Add(data); } reader.Close(); } CustomYardRefModel adata = new CustomYardRefModel(); #region Set DB data to Object adata.GId = ""; adata.CustCode = ""; adata.CustName = ""; adata.CodeAndName = ""; #endregion headList.Add(adata); return headList; } static public List GetCustomInvRefList(string strCondition, string IsEnableCustRange = "0", string userid = "") { var strSql = GetCustomInvRefList_SqlStr(strCondition, IsEnableCustRange, userid); return SetCustomInvRefData(strSql); } static public List GetCustomInvRef(string strCondition, string IsEnableCustRange = "0", string userid = "") { var strSql = GetCustomInvRefList_SqlStr(strCondition, IsEnableCustRange, userid); return SetCustomInvRefData(strSql, false); } public static StringBuilder GetCustomInvRefList_SqlStr(string strCondition, string IsEnableCustRange = "0", string userid = "") { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION]"); strSql.Append(",RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='USD' AND LINKID=info_client.GID) usdbank,usdaccount,TaxNo,Addr,Tel,EMAIL"); strSql.Append(" from info_client where 1=1 "); var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } if (IsEnableCustRange == "1") strSql.Append(" and (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range )) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and (" + strCondition + ")"); } return strSql; } private static List SetCustomInvRefData(StringBuilder strSql, bool islist = true) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); if (islist) headList.Add(new CustomInvRefModel()); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CustomInvRefModel data = new CustomInvRefModel(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.CustCode = Convert.ToString(reader["CustCode"]); data.CustName = Convert.ToString(reader["CustName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]); data.BillRises1 = Convert.ToString(reader["BillRises1"]); data.RMBBillRises = Convert.ToString(reader["RmbBillRises"]); data.RMBBank = Convert.ToString(reader["Rmbbank"]); data.RMBAccount = Convert.ToString(reader["Rmbaccount"]); data.USDBillRises = Convert.ToString(reader["usdBillRises"]); data.USDBank = Convert.ToString(reader["usdbank"]); data.USDAccount = Convert.ToString(reader["usdaccount"]); data.TaxNo = Convert.ToString(reader["TaxNo"]); data.Addr = Convert.ToString(reader["Addr"]); data.Tel = Convert.ToString(reader["Tel"]); data.INVADDRTEL = Convert.ToString(reader["INVADDRTEL"]); if (data.BillRises1 == "") data.BillRises1 = Convert.ToString(reader["DESCRIPTION"]); if (data.RMBBillRises == "") data.RMBBillRises = Convert.ToString(reader["DESCRIPTION"]); if (data.USDBillRises == "") data.USDBillRises = Convert.ToString(reader["DESCRIPTION"]); data.EMail = Convert.ToString(reader["EMAIL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetCustomContactRefList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("LinkId,CODENAME,SHOWNAME,Tel,EMAIL"); strSql.Append(" from info_client_contact "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetCustomContactRefData(strSql); } private static List SetCustomContactRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CustomContactRefModel data = new CustomContactRefModel(); #region Set DB data to Object data.LinkId = Convert.ToString(reader["LinkId"]); data.Code = Convert.ToString(reader["CODENAME"]); data.Name = Convert.ToString(reader["SHOWNAME"]); data.Tel = Convert.ToString(reader["Tel"]); data.EMail = Convert.ToString(reader["EMAIL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetAirLinesList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,BillRises1"); strSql.Append(",UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE,ISAGENTCN "); strSql.Append(" from info_Client where 1=1 "); // BLSTATUS=0 var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" ORDER BY CODENAME "); return SetAirLinesData(strSql); } private static List SetAirLinesData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CustomRefModel data = new CustomRefModel(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.CustCode = Convert.ToString(reader["CustCode"]); data.CustName = Convert.ToString(reader["CustName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.BillRises1 = Convert.ToString(reader["BillRises1"]); data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]); data.DESCRIPTION = Convert.ToString(reader["description"]); data.KFCodename = Convert.ToString(reader["KFCodename"]); data.SALE = Convert.ToString(reader["SALE"]); data.ISAGENTCN = Convert.ToString(reader["ISAGENTCN"]); #endregion headList.Add(data); } reader.Close(); } CustomRefModel adata = new CustomRefModel(); #region Set DB data to Object adata.GId = ""; adata.CustCode = ""; adata.CustName = ""; adata.CodeAndName = ""; adata.BillRises1 = ""; adata.UNITPRICE = ""; adata.DESCRIPTION = ""; adata.KFCodename = ""; adata.SALE = ""; #endregion headList.Add(adata); return headList; } #endregion #region 客户参照,对应95004.内贸空运 获取vip价格 static public List GetCustom_SPPrice() { return GetCustom_SPPrice(string.Empty); } static public List GetCustom_SPPrice(string strCondition) { var strSql = new StringBuilder(); strSql.Append(" SELECT Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,BillRises1 "); strSql.Append(" ,UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE "); strSql.Append(" ,(case when (select dbo.Get_ClientFee(SHORTNAME,'VIP单价'))>0 "); strSql.Append(" or (select dbo.Get_ClientFee(SHORTNAME,'VIP单票'))>0 then 1 else 0 end )ISVIP "); strSql.Append(" ,(select dbo.Get_ClientFee(SHORTNAME,'VIP单价')) VIPDJ "); strSql.Append(" ,(select dbo.Get_ClientFee(SHORTNAME,'VIP单票')) VIPDP "); strSql.Append(" from info_Client where 1=1 "); var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" ORDER BY CODENAME "); return SetCustom_SPPrice(strSql); } private static List SetCustom_SPPrice(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CustomVIPModel data = new CustomVIPModel(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.CustCode = Convert.ToString(reader["CustCode"]); data.CustName = Convert.ToString(reader["CustName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.BillRises1 = Convert.ToString(reader["BillRises1"]); data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]); data.DESCRIPTION = Convert.ToString(reader["description"]); data.KFCodename = Convert.ToString(reader["KFCodename"]); data.SALE = Convert.ToString(reader["SALE"]); data.ISVIP = Convert.ToString(reader["ISVIP"]); data.VIPDJ = Convert.ToString(reader["VIPDJ"]); data.VIPDP = Convert.ToString(reader["VIPDP"]); #endregion headList.Add(data); } reader.Close(); } CustomVIPModel adata = new CustomVIPModel(); #region Set DB data to Object adata.GId = ""; adata.CustCode = ""; adata.CustName = ""; adata.CodeAndName = ""; adata.BillRises1 = ""; adata.UNITPRICE = ""; adata.DESCRIPTION = ""; adata.KFCodename = ""; adata.SALE = ""; #endregion headList.Add(adata); return headList; } #endregion #region 客户银行账户列表 static public List GetMsClientAccount(string condition) { return GetMsClientAccountData(condition); } static public List GetMsClientAccountData(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,BANKNAME,ACCOUNT,BANKNAME+'-'+ACCOUNT BANKNAME_ACCOUNT"); strSql.Append(" from info_client_bank "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetMsClientAccountData(strSql); } private static List SetMsClientAccountData(StringBuilder strSql) { var headList = new List(); MsClientAccount adata = new MsClientAccount(); #region Set DB data to Object adata.GID = ""; adata.BANKNAME = ""; adata.ACCOUNT = ""; adata.BANKNAME_ACCOUNT = ""; #endregion Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsClientAccount data = new MsClientAccount(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BANKNAME = Convert.ToString(reader["BANKNAME"]); data.ACCOUNT = Convert.ToString(reader["ACCOUNT"]); data.BANKNAME_ACCOUNT = Convert.ToString(reader["BANKNAME_ACCOUNT"]); #endregion headList.Add(data); } reader.Close(); } headList.Add(adata); return headList; } #endregion #region 业务来源 static public List GetSourceList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("SOURCEID,SOURCENAME,CORPID,SOURCECODE"); strSql.Append(" from code_source "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetSourceData(strSql); } static public SourceModel GetSourceData(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("SOURCEID,SOURCENAME,CORPID,SOURCECODE"); strSql.Append(" from code_source "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var list = SetSourceData(strSql, true); if (list.Count > 0) return list[0]; return new SourceModel(); } private static List SetSourceData(StringBuilder strSql, bool isdata = false) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { SourceModel data = new SourceModel(); #region Set DB data to Object data.SourceID = Convert.ToString(reader["SOURCEID"]); data.SourceName = Convert.ToString(reader["SOURCENAME"]); data.CorpID = Convert.ToString(reader["CORPID"]); data.SOURCECODE = Convert.ToString(reader["SOURCECODE"]); #endregion headList.Add(data); } reader.Close(); } if (!isdata) { SourceModel adata = new SourceModel(); #region Set DB data to Object adata.SourceID = ""; adata.SourceName = ""; adata.CorpID = ""; #endregion headList.Add(adata); } return headList; } static public List GetSourceDetailList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("SOURCEDETAILID,SOURCEID,SOURCEDETAIL"); strSql.Append(" from code_source_detail "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetSourceDetailData(strSql); } private static List SetSourceDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { SourceDetailModel data = new SourceDetailModel(); #region Set DB data to Object data.SourceDetailID = Convert.ToString(reader["SOURCEDETAILID"]); data.SourceID = Convert.ToString(reader["SOURCEID"]); data.SourceDetail = Convert.ToString(reader["SOURCEDETAIL"]); #endregion headList.Add(data); } reader.Close(); } SourceDetailModel adata = new SourceDetailModel(); #region Set DB data to Object adata.SourceDetailID = ""; adata.SourceID = ""; adata.SourceDetail = ""; #endregion headList.Add(adata); return headList; } #endregion #region 部门 static public List GetDeptList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,DEPTNO + '-' + DEPTNAME AS NOANDNAME"); strSql.Append(" from sys_dept "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetDeptData(strSql); } private static List SetDeptData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { DeptModel data = new DeptModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.Deptno = Convert.ToString(reader["DEPTNO"]); data.DeptName = Convert.ToString(reader["DEPTNAME"]); data.Manage1 = Convert.ToString(reader["MANAGE1"]); data.NOANDNAME = Convert.ToString(reader["NOANDNAME"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 船名航次参照,对应95003(vMsTruckVoyInfo) static public List GetVoyRefList() { return GetVoyRefList(string.Empty); } static public List GetVoyRefList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("VoyCode,VoyName,CodeAndName"); strSql.Append(" from vMsTruckVoyInfo "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetVoyRefData(strSql); } private static List SetVoyRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { VoyRefModel data = new VoyRefModel(); #region Set DB data to Object data.VoyCode = Convert.ToString(reader["VoyCode"]); data.VoyName = Convert.ToString(reader["VoyName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 船名 static public List GetVesselList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VSID,VESSEL,CNAME,CARRIER,EDICODE,VESSEL+' '+CNAME CodeAndName"); strSql.Append(" from code_vessel "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetVesselData(strSql); } private static List SetVesselData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { VesselModel data = new VesselModel(); #region Set DB data to Object data.VSID = Convert.ToString(reader["VSID"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.CNAME = Convert.ToString(reader["CNAME"]); data.EDICODE = Convert.ToString(reader["EDICODE"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetVoyNoList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VOID,VSID,VOYNO,PORTLOAD,PORTDISCHARGE,ETD,CLOSINGDATE,ETA,CORPID,YARDID,ENTREPORT,VESSEL,ATD,CLOSEDOCDATE "); strSql.Append(" from code_voyno "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetVoyNoData(strSql); } private static List SetVoyNoData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { VoyNoModel data = new VoyNoModel(); #region Set DB data to Object data.VSID = Convert.ToString(reader["VSID"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd"); if (reader["CLOSINGDATE"] != DBNull.Value) data.CLOSINGDATE = Convert.ToDateTime(reader["CLOSINGDATE"]).ToString("yyyy-MM-dd"); if (reader["ETA"] != DBNull.Value) data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd"); if (reader["ATD"] != DBNull.Value) data.ATD = Convert.ToDateTime(reader["ATD"]).ToString("yyyy-MM-dd"); if (reader["CLOSEDOCDATE"] != DBNull.Value) data.CLOSEDOCDATE = Convert.ToDateTime(reader["CLOSEDOCDATE"]).ToString("yyyy-MM-dd HH:mm"); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 箱型表参照,对应95005(vMsTruckCtn) static public List GetCtnRefList() { return GetCtnRefList(string.Empty); } static public List GetCtnRefList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("CtnCode,CtnName,CodeAndName"); strSql.Append(" from vMsTruckCtn "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetCtnRefData(strSql); } private static List SetCtnRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CtnRefModel data = new CtnRefModel(); #region Set DB data to Object data.CtnCode = Convert.ToString(reader["CtnCode"]); data.CtnName = Convert.ToString(reader["CtnName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); #endregion headList.Add(data); } reader.Close(); } CtnRefModel adata = new CtnRefModel(); #region Set DB data to Object adata.CtnCode = ""; adata.CtnName = ""; adata.CodeAndName = ""; #endregion headList.Add(adata); return headList; } static public List GetCtnDispList() { return GetCtnDispList(string.Empty); } static public List GetCtnDispList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select CtnCode,CtnName,CodeAndName,sort from [vMsImportCtnDisp]"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" order by sort "); return SetCtnRefData(strSql); } #endregion #region 国家参照,(Import_country) static public List GetCountryRefList() { return GetCountryRefList(string.Empty); } static public List GetCountryRefList(string strCondition) { var strSql = new StringBuilder(); // SELECT id,country_code,country,(country_code+'_'+country) as country_codeandname //from import_country strSql.Append("SELECT countryid,country,(countryid+'_'+country) as country_idandname"); strSql.Append(" from code_country "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetcountryRefData(strSql); } private static List SetcountryRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CountryModel data = new CountryModel(); #region Set DB data to Object // data.id = Convert.ToString(reader["id"]); data.countryid = Convert.ToString(reader["countryid"]); data.country = Convert.ToString(reader["country"]); data.country_idandname = Convert.ToString(reader["country_idandname"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 商品名称参照,(Import_Cargoinfo) static public List GetCargoRefList() { return GetCargoRefList(string.Empty); } static public List GetCargoRefList(string strCondition) { var strSql = new StringBuilder(); strSql.Append(" select *,code+'_'+name codeandname from import_cargoinfo "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" order by code "); return SetCargoRefData(strSql); } private static List SetCargoRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CargoModel data = new CargoModel(); #region Set DB data to Object data.id = Convert.ToString(reader["id"]); data.code = Convert.ToString(reader["code"]); data.name = Convert.ToString(reader["name"]); data.codeandname = Convert.ToString(reader["codeandname"]); // data.tariff = Convert.ToString(reader["tariff"]); // data.tax = Convert.ToString(reader["tax"]); // data.tax_zz = Convert.ToString(reader["tax_zz"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 商品名称参照 含tax,(Import_Cargoinfo) static public List GetCargoTax() { return GetCargoTax(string.Empty); } static public List GetCargoTax(string strCondition) { //tariff 关税等级: 0最惠国 1普通 2零关税 var strSql = GetCargoTax_Sqlstr(strCondition); return SetCargoTax(strSql); } public static StringBuilder GetCargoTax_Sqlstr(string strCondition) { var strSql = new StringBuilder(); strSql.Append(" select ci.id,name,code+'_'+name codeandname,code, "); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 "); strSql.Append("and EnumTypeID=9000 and EnumValueID=cc.tariff) as tariff, "); strSql.Append("case cc.tariff when 0 then ci.tax_zhg/100 when 1 then ci.tax_pt/100 when 2 then 0 end tax, "); strSql.Append("ci.tax_zz/100 as tax_zz,ci.tax_cl as tax_cl from code_country cc,import_cargoinfo ci "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return strSql; } private static List SetCargoTax(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CargoModel data = new CargoModel(); #region Set DB data to Object data.id = Convert.ToString(reader["id"]); data.code = Convert.ToString(reader["code"]); data.name = Convert.ToString(reader["name"]); data.codeandname = Convert.ToString(reader["codeandname"]); data.tariff = Convert.ToString(reader["tariff"]); data.tax = Convert.ToString(reader["tax"]); data.tax_zz = Convert.ToString(reader["tax_zz"]); data.tax_cl = Convert.ToString(reader["tax_cl"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 商品ciq名称参照,(Import_Cargociq) static public List GetCargociqRefList(string strCondition = "") { if (strCondition.Trim().Length > 0) if (strCondition.Trim().Substring(strCondition.Trim().Length - 1, 1) == "=") { return new List(); } var strSql = GetCargociqRefList_Sqlstr(strCondition); return SetCargociqRefData(strSql); } public static StringBuilder GetCargociqRefList_Sqlstr(string strCondition = "") { var strSql = new StringBuilder(); strSql.Append("SELECT *,ciqcode+'_'+ciqname as codeandname"); strSql.Append(" from import_cargociq "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" order by ciqcode "); return strSql; } private static List SetCargociqRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CargociqModel data = new CargociqModel(); #region Set DB data to Object data.id = Convert.ToString(reader["id"]); data.ciqcode = Convert.ToString(reader["ciqcode"]); data.ciqname = Convert.ToString(reader["ciqname"]); data.codeandname = Convert.ToString(reader["codeandname"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 公司名称,(company) static public List GetcompanyList() { return GetcompanyList(string.Empty); } static public List GetcompanyList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT *"); strSql.Append(" from company where isdeleted=0 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetcompanyData(strSql); } private static List SetcompanyData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { companyModel data = new companyModel(); #region Set DB data to Object data.gid = Convert.ToString(reader["gid"]); data.code = Convert.ToString(reader["codename"]); data.name = Convert.ToString(reader["name"]); data.isdisable = Convert.ToString(reader["isdisable"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 币别,(currid) static public List GetcurrRefList() { return GetcurrRefList(string.Empty); } static public List GetcurrRefList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select gid,codename,defaultrate from code_currency "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetcurrData(strSql); } private static List SetcurrData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { currModel data = new currModel(); #region Set DB data to Object data.gid = Convert.ToString(reader["gid"]); data.codename = Convert.ToString(reader["codename"]); data.defaultrate = Convert.ToString(reader["defaultrate"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 进口贸易提醒,(import_remind) static public List GetRemindList() { return GetRemindList(string.Empty); } static public List GetRemindList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select id,Remindname,Remindsql from Import_remind "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetRemindData(strSql); } private static List SetRemindData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { RemindModel data = new RemindModel(); #region Set DB data to Object data.RemindName = Convert.ToString(reader["Remindname"]); data.RemindSql = Convert.ToString(reader["Remindsql"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 贸易商/购货方combox,(seller buyer info_client) static public List GetTrader() { return GetTrader(string.Empty); } static public List GetTrader(string strCondition) { var strSql = GetTrader_Getsqlstr(strCondition); return SetTrader(strSql); } public static StringBuilder GetTrader_Getsqlstr(string strCondition) { var strSql = new StringBuilder(); strSql.Append(" select gid,shortname as name,codename code,codename+'_'+shortname codename,description,EnFullName "); strSql.Append(" ,codename+'_'+EnFullName codeEnname,ISSTOP,RCVMode from info_client where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } strSql.Append(" and " + strCondition); } strSql.Append(" order by codename "); return strSql; } private static List SetTrader(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { TraderModel data = new TraderModel(); #region Set DB data to Object data.gid = Convert.ToString(reader["gid"]); data.name = Convert.ToString(reader["name"]); data.code = Convert.ToString(reader["code"]); data.codename = Convert.ToString(reader["codename"]); data.description = Convert.ToString(reader["description"]); data.EnFullName = Convert.ToString(reader["EnFullName"]); data.codeEnName = Convert.ToString(reader["codeEnName"]); data.ISSTOP = Convert.ToString(reader["ISSTOP"]); data.RCVMode = Convert.ToString(reader["RCVMode"]); #endregion headList.Add(data); } reader.Close(); } // TraderModel data1 = new TraderModel(); #region Set DB data to Object data1.gid = ""; data1.name = ""; data1.codename = ""; data1.description = ""; #endregion headList.Add(data1); return headList; } static public List GetPCTrader(string strCondition) { var strSql = GetPCTrader_Getsqlstr(strCondition); return SetPCTrader(strSql); } public static StringBuilder GetPCTrader_Getsqlstr(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select gid,shortname as name,codename+'_'+shortname codename,description,EnFullName,codename+'_'+EnFullName codeEnname,ADDR from info_client where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'"); if (InfoClintBlstatus.PARAMVALUE != "") { if (InfoClintBlstatus.PARAMVALUE == "1") { strSql.Append(" and BLSTATUS=0 "); } } strSql.Append(" and " + strCondition); } strSql.Append(" order by codename "); return strSql; } private static List SetPCTrader(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { TraderModel data = new TraderModel(); #region Set DB data to Object data.gid = Convert.ToString(reader["gid"]); data.name = Convert.ToString(reader["name"]); data.codename = Convert.ToString(reader["codename"]); data.description = Convert.ToString(reader["description"]); data.EnFullName = Convert.ToString(reader["EnFullName"]); data.codeEnName = Convert.ToString(reader["codeEnName"]); data.ADDR = Convert.ToString(reader["ADDR"]); #endregion headList.Add(data); } reader.Close(); } // TraderModel data1 = new TraderModel(); #region Set DB data to Object data1.gid = ""; data1.name = ""; data1.codename = ""; data1.description = ""; #endregion headList.Add(data1); return headList; } #endregion #region 获取银行名字列表 static public List GetBank() { return GetBank(string.Empty); } static public List GetBank(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select gid, bankname,FINANCESOFTCODE,FINANCESOFTCODE+'_'+bankname codename from sys_bank "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetBank(strSql); } private static List SetBank(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { BankModel data = new BankModel(); #region Set DB data to Object data.gid = Convert.ToString(reader["gid"]); data.bankname = Convert.ToString(reader["bankname"]); data.codename = Convert.ToString(reader["codename"]); data.FINANCESOFTCODE = Convert.ToString(reader["FINANCESOFTCODE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 获取 其他科目代码 ,用于给科目列表combox提供store static public List GetAccitems(string strUserID) { return GetAccitems(string.Empty, strUserID); } static public List GetAccitems(string strCondition, string strUserID) { string strCwACCDATE = GetCwACCDATE(strUserID); var strSql = new StringBuilder(); strSql.Append("select GID,ACCID,ACCNAME,ACCID+'-'+ACCNAME AS ACCIDNAME,DC,ISFCY,REMARKS,DETAILED,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC from cw_accitems where ([year]=SUBSTRING('" + strCwACCDATE + "',1,4) or [year]='' or [year] is null)"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" order by ACCID "); return SetAccitems(strSql); } private static List SetAccitems(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { AccitemsModel data = new AccitemsModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.ACCID = Convert.ToString(reader["ACCID"]); data.ACCNAME = Convert.ToString(reader["ACCNAME"]); data.ACCIDNAME = Convert.ToString(reader["ACCIDNAME"]); data.DC = Convert.ToString(reader["DC"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); data.DETAILED = Convert.ToString(reader["DETAILED"]); data.ISFCY = Convert.ToBoolean(reader["ISFCY"]); data.ISDEPTACC = Convert.ToBoolean(reader["ISDEPTACC"]); data.ISEMPLACC = Convert.ToBoolean(reader["ISEMPLACC"]); data.ISCORPACC = Convert.ToBoolean(reader["ISCORPACC"]); data.ISITEMACC = Convert.ToBoolean(reader["ISITEMACC"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetMngAccitems(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select GID,ACCID,ACCNAME,ACCID+'-'+ACCNAME AS ACCIDNAME,DC,ISFCY,REMARKS,DETAILED,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC from cw_accitems where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetAccitems(strSql); } #endregion #region 查询用户权限 static public List GetAR(string modName, string USERID) { var strSql = new StringBuilder(); strSql.Append(" select GID,visiblerange,operaterange from user_authority_range where authorityid=( "); strSql.Append(" select gid from user_authority_info where (name='" + modName + "' or DESCRIPTION='" + modName + "') and isdelete=0 "); strSql.Append(" and userid='" + USERID + "') "); return SetAR(strSql); } private static List SetAR(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { AuthorityRangemb data = new AuthorityRangemb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.VISIBLERANGE = Convert.ToString(reader["VISIBLERANGE"]); data.OPERATERANGE = Convert.ToString(reader["OPERATERANGE"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } /// /// 获得可视范围的查询子句。相关字段存储的应当都是相应ID /// /// 权限名字 user_authority_info.NAME /// /// 用于查询语句中的,公司ID的字段或表达式 SQL层面的 /// 用于查询语句中的,人的ID的字段或表达式 SQL层面的 /// 用于查询语句中的,部门的ID的字段或表达式 SQL层面的 /// public static string GetVisableRange(string modName, string USERID, string COMPANYFIELDNAME, string USERFIELD = "", string DEPTFIELDNAME = "") { var evList = BasicDataRefDAL.GetAR(modName, USERID); AuthorityRangemb head = null; var result = ""; var VISIBLERANGE = "3"; if (evList.Count > 0) head = evList[0]; if (head == null) { head = new AuthorityRangemb(); } else { VISIBLERANGE = head.VISIBLERANGE; } //0 全部 if (VISIBLERANGE == "0") { result = "1=1"; } else if (VISIBLERANGE == "1") {//1 分公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in (select companyid from vw_user where userid='" + USERID + "')"; } else if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in (select USERID from vw_user where companyid =(select companyid from vw_user where userid='" + USERID + "'))"; } } else if (VISIBLERANGE == "2") { if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = DEPTFIELDNAME + " in (select deptgid from vw_user where userid='" + USERID + "')"; } else if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in (select USERID from vw_user where deptgid =(select deptgid from vw_user where userid='" + USERID + "'))"; } } else if (VISIBLERANGE == "3") { if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " ='" + USERID + "' "; } } else if (VISIBLERANGE == "4") { if (!string.IsNullOrEmpty(USERFIELD)) { result = "1=2"; } } else if (VISIBLERANGE == "5") {//选择公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where userid='" + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } else if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='" + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } else if (VISIBLERANGE == "6") {//选择个人 if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in(select OPID from user_authority_range_op where userid='" + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } if (head == null || result == "") { result = "1=2"; } return result; } /// /// 可操作范围查询子句 /// /// /// /// /// /// /// public static string GetOperateRange(string modName, string USERID, string COMPANYFIELDNAME, string USERFIELD = "", string DEPTFIELDNAME = "") { var evList = BasicDataRefDAL.GetAR(modName, USERID); AuthorityRangemb head = null; var result = ""; var OPERATERANGE = "3"; if (evList.Count > 0) head = evList[0]; if (head == null) { head = new AuthorityRangemb(); } else { OPERATERANGE = head.OPERATERANGE; } //0 全部 if (OPERATERANGE == "0") { result = "1=1"; } else if (OPERATERANGE == "1") {//1 分公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "')"; } else if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in(select USERID from vw_user where companyid =(select companyid from vw_user where userid='" + USERID + "'))"; } } else if (OPERATERANGE == "2") { if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = DEPTFIELDNAME + " in(select deptid from vw_user where userid='" + USERID + "')"; } else if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in(select USERID from vw_user where deptid =(select deptid from vw_user where userid='" + USERID + "'))"; } } else if (OPERATERANGE == "3") { if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " ='" + USERID + "' "; } } else if (OPERATERANGE == "4") { if (!string.IsNullOrEmpty(USERFIELD)) { result = "1=2"; } } else if (OPERATERANGE == "5") {//选择公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where userid='" + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } else if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='" + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } else if (OPERATERANGE == "6") {//选择个人 if (!string.IsNullOrEmpty(USERFIELD)) { result = USERFIELD + " in(select OPID from user_authority_range_op where userid='" + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } if (head == null || result == "") { result = "1=2"; } return result; } /// /// 组织权限语句的方法 通用版(目前内贸和运价报价模块使用) /// /// /// /// /// /// /// public static string GetRangeCondition(RangeType rangetype, string modName, string USERID, string COMPANYFIELDNAME, string[] USERFIELDArray, string DEPTFIELDNAME = "") { var RANGENAME = ""; if (rangetype == RangeType.Visable) { RANGENAME = "VISIBLERANGE"; } if (rangetype == RangeType.Operate) { RANGENAME = "OPERATERANGE"; } if (RANGENAME == "") return " 1=2 "; var evList = BasicDataRefDAL.GetAR(modName, USERID); if (evList.Count == 0) return " 1=2 "; AuthorityRangemb head = null; var result = ""; var RANGEVALUE = "3"; if (evList.Count > 0) head = evList[0]; if (head == null) { head = new AuthorityRangemb(); } else { if (rangetype == RangeType.Visable) { RANGEVALUE = head.VISIBLERANGE; } if (rangetype == RangeType.Operate) { RANGEVALUE = head.OPERATERANGE; } } //0 全部 if (RANGEVALUE == "0") { result = "1=1"; } else if (RANGEVALUE == "1") {//1 分公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select top 1 companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')"; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" + " union all select SHOWNAME from vw_user where companyid in(select top 1 companyid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = "(" + _S + ")"; } } else if (RANGEVALUE == "2") { if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select top 1 companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')"; result += " and " + DEPTFIELDNAME + " in(select top 1 deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "' union all select top 1 deptname from vw_user where userid='" + USERID + "' or showname='" + USERID + "' ) "; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in( select USERID from vw_user where deptgid in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" + "union all select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = "(" + _S + ")"; } } else if (RANGEVALUE == "3") { if (USERFIELDArray.Length > 0) { //result = USERFIELD + " ='" + USERID + "' "; var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " ='" + USERID + "' or " + USERFIELD + " =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = "(" + _S + ")"; } } else if (RANGEVALUE == "4") { if (USERFIELDArray.Length > 0) { result = "1=2"; } } else if (RANGEVALUE == "5") {//选择公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='" + modName + "' or DESCRIPTION='" + modName + "') and " + RANGENAME + " = 1)"; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + " exists(select 1 from vw_user where companyid in " + "(select companyid from user_authority_range_company where AUTHORITYID = " + "(select GID from user_authority_info where Name = '" + modName + "' or DESCRIPTION = '" + modName + "') and " + RANGENAME + " = 1 " + ") and(userid = " + USERFIELD + " or SHOWNAME = " + USERFIELD + "))"; } result = "(" + _S + ")"; //result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } else if (RANGEVALUE == "6") {//选择个人 if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" + "or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "')" + "and " + RANGENAME + " = 1 union all select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" + " or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "') and " + RANGENAME + " = 1))"; } result = "(" + _S + ")"; //result = USERFIELD + " in(select OPID from user_authority_range_op where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } if (head == null || result == "") { result = "1=2"; } return result; } public enum RangeType { Visable, Operate } /// /// 获得可视范围的查询子句。相关字段存储的 user或dept可以是相应ID或中文名 company必须是ID /// var rangestr = BasicDataRefDAL.GetVisableRange("modYAXIANG", USERID, "COMPANYID", new string[]{ "CREATEUSER"}, "DEPTID"); /// /// 权限名字 user_authority_info.NAME或description /// /// 用于查询语句中的,公司ID的字段或表达式 SQL层面的 /// 用于查询语句中的,人的ID的字段或表达式 SQL层面的 /// 用于查询语句中的,部门的ID的字段或表达式 SQL层面的 /// public static string GetVisableRange2(string modName, string USERID, string COMPANYFIELDNAME, string[] USERFIELDArray, string DEPTFIELDNAME = "") { var evList = BasicDataRefDAL.GetAR(modName, USERID); AuthorityRangemb head = null; var result = ""; var VISIBLERANGE = "3"; if (evList.Count > 0) head = evList[0]; if (head == null) { head = new AuthorityRangemb(); } else { VISIBLERANGE = head.VISIBLERANGE; } //0 全部 if (VISIBLERANGE == "0") { result = "1=1"; } else if (VISIBLERANGE == "1") {//1 分公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')"; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" + " union all select SHOWNAME from vw_user where companyid in(select companyid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = _S; } } else if (VISIBLERANGE == "2") {//限定部门 此时dept参数必须要有 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')"; result += " and " + DEPTFIELDNAME + " in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "' union all select deptname from vw_user where userid='" + USERID + "' or showname='" + USERID + "' ) "; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in( select USERID from vw_user where deptgid in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" + "union all select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = _S; } } else if (VISIBLERANGE == "3") { if (USERFIELDArray.Length > 0) { //result = USERFIELD + " ='" + USERID + "' "; var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " ='" + USERID + "' or " + USERFIELD + " =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = _S; } } else if (VISIBLERANGE == "4") { if (USERFIELDArray.Length > 0) { result = "1=2"; } } else if (VISIBLERANGE == "5") {//选择公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='" + modName + "' or DESCRIPTION='" + modName + "') and VISIBLERANGE = 1)"; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + " exists(select 1 from vw_user where companyid in " + "(select companyid from user_authority_range_company where AUTHORITYID = " + "(select GID from user_authority_info where Name = '" + modName + "' or DESCRIPTION = '" + modName + "') and VISIBLERANGE = 1 " + ") and(userid = " + USERFIELD + " or SHOWNAME = " + USERFIELD + "))"; } result = _S; //result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } else if (VISIBLERANGE == "6") {//选择个人 if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" + "or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "')" + "and VISIBLERANGE = 1 union all select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" + " or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "') and VISIBLERANGE = 1))"; } result = _S; //result = USERFIELD + " in(select OPID from user_authority_range_op where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)"; } } if (head == null || result == "") { result = "1=2"; } return result; } /// /// 可操作范围查询子句 /// /// /// /// /// /// /// public static string GetOperateRange2(string modName, string USERID, string COMPANYFIELDNAME, string[] USERFIELDArray, string DEPTFIELDNAME = "") { var evList = BasicDataRefDAL.GetAR(modName, USERID); AuthorityRangemb head = null; var result = ""; var OPERATERANGE = "3"; if (evList.Count > 0) head = evList[0]; if (head == null) { head = new AuthorityRangemb(); } else { OPERATERANGE = head.OPERATERANGE; } //0 全部 if (OPERATERANGE == "0") { result = "1=1"; } else if (OPERATERANGE == "1") {//1 分公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')"; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" + " union all select SHOWNAME from vw_user where companyid in(select companyid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = _S; } } else if (OPERATERANGE == "2") { if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')"; result += " and " + DEPTFIELDNAME + " in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "' union all select deptname from vw_user where userid='" + USERID + "' or showname='" + USERID + "' ) "; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in( select USERID from vw_user where deptgid in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" + "union all select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = _S; } } else if (OPERATERANGE == "3") { if (USERFIELDArray.Length > 0) { //result = USERFIELD + " ='" + USERID + "' "; var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " ='" + USERID + "' or " + USERFIELD + " =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))"; } result = _S; } } else if (OPERATERANGE == "4") { if (USERFIELDArray.Length > 0) { result = "1=2"; } } else if (OPERATERANGE == "5") {//选择公司 if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) { result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='" + modName + "' or DESCRIPTION='" + modName + "') and OPERATERANGE = 1)"; } else if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + " exists(select 1 from vw_user where companyid in " + "(select companyid from user_authority_range_company where AUTHORITYID = " + "(select GID from user_authority_info where Name = '" + modName + "' or DESCRIPTION = '" + modName + "') and OPERATERANGE = 1 " + ") and(userid = " + USERFIELD + " or SHOWNAME = " + USERFIELD + "))"; } result = _S; //result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)"; } } else if (OPERATERANGE == "6") {//选择个人 if (USERFIELDArray.Length > 0) { var _S = ""; foreach (var USERFIELD in USERFIELDArray) { if (_S != "") _S += " or "; _S = _S + USERFIELD + " in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" + "or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "')" + "and OPERATERANGE = 1 union all select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" + " or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "') and OPERATERANGE = 1))"; } result = _S; //result = USERFIELD + " in(select OPID from user_authority_range_op where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)"; } } #region 旧的单关键字段算法 //else //if (OPERATERANGE == "1") //{//1 分公司 // if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) // { // result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "')"; // } // else if (!string.IsNullOrEmpty(USERFIELD)) // { // result = USERFIELD + " in(select USERID from vw_user where companyid =(select companyid from vw_user where userid='" + USERID + "'))"; // } //} //else //if (OPERATERANGE == "2") //{ // if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) // { // result = DEPTFIELDNAME + " in(select deptid from vw_user where userid='" + USERID + "')"; // } // else if (!string.IsNullOrEmpty(USERFIELD)) // { // result = USERFIELD + " in(select USERID from vw_user where deptid =(select deptid from vw_user where userid='" + USERID + "'))"; // } //} //else //if (OPERATERANGE == "3") //{ // if (!string.IsNullOrEmpty(USERFIELD)) // { // result = USERFIELD + " ='" + USERID + "' "; // } //} //else //if (OPERATERANGE == "4") //{ // if (!string.IsNullOrEmpty(USERFIELD)) // { // result = "1=2"; // } //} //else //if (OPERATERANGE == "5") //{//选择公司 // if (!string.IsNullOrEmpty(COMPANYFIELDNAME)) // { // result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)"; // } // else if (!string.IsNullOrEmpty(USERFIELD)) // { // result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)"; // } //} //else //if (OPERATERANGE == "6") //{//选择个人 // if (!string.IsNullOrEmpty(USERFIELD)) // { // result = USERFIELD + " in(select OPID from user_authority_range_op where userid='" // + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)"; // } //} #endregion if (head == null || result == "") { result = "1=2"; } return result; } /// /// 返回查询子句 /// 用于判断USERID是否具有对【head这条业务】的【ModName权限】的使用权 /// /// /// /// public static string CanOperateStr_INVOICE(string ModName, string USERID) { var rangestr = BasicDataRefDAL.GetOperateRange(ModName, USERID, "COMPANYID", "OPERATOR"); return rangestr; } //public class USERINFO { // public string USERID { get; set; } // public string USERID { get; set; } // public string USERID { get; set; } // public string USERID { get; set; } // public USERINFO(HttpSessionStateBase CurrSession) { // new USERINFO(CurrSession["USERID"].ToString(), CurrSession["SHOWNAME"].ToString(), CurrSession["COMPANYID"].ToString(), CurrSession["DEPTNAME"].ToString()); // } // public USERINFO(string USERID, string SHOWNAME, string COMPANYID, string DEPTNAME) { // } //} #endregion #region 获取本部门领取且未支取的支票号 static public List GetUnusedCHEQUENUM(string DEPTID, string BXGID) { var strSql = new StringBuilder(); strSql.Append(" select '外代IC卡' chequeno union all "); strSql.Append(" select '外运IC卡' chequeno union all "); strSql.Append(" select '挂账' chequeno union all "); strSql.Append(" select chequeno from( "); strSql.Append(" select cfc.chequeno,bxgid from ch_fee_cheque cfc "); strSql.Append(" left join ch_fee on ch_fee.chequenum=cfc.chequeno "); strSql.Append(" where cfc.billno in (select gid from OA_Jiekuan where deptid='" + DEPTID + "') "); strSql.Append(" and cfc.chequeno is not null and cfc.chequeno<>'')t "); strSql.Append(" where bxgid is null or bxgid='" + BXGID + "' "); return SetUnusedCHEQUENUM(strSql); } private static List SetUnusedCHEQUENUM(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CHEQUENUMmb data = new CHEQUENUMmb(); #region Set DB data to Object data.CHEQUENUM = Convert.ToString(reader["CHEQUENO"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 获取工作流typeno 用于在工作流管理界面选择typeno static public List GetTYPENO(string condition) { var strSql = new StringBuilder(); strSql.Append(" select GID,name+'_'+description as name,typeno from workflow_type "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } return SetTYPENO(strSql); } private static List SetTYPENO(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WorkFlowmb data = new WorkFlowmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.NAME = Convert.ToString(reader["NAME"]); data.TYPENO = Convert.ToString(reader["TYPENO"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 通过工作流名字查找工作流编号 /* static public List GetWorkFlowID(string NAME, string OrgCode) { var strSql = new StringBuilder(); strSql.Append(" select GID,[Name] from workflow where "); strSql.Append(" [type]=(select typeno from workflow_type where name= '" + NAME + "') "); strSql.Append(" and companyid=(select gid from company where codename='" + OrgCode + "' ) "); return SetWorkFlowID(strSql); } private static List SetWorkFlowID(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WorkFlowmb data = new WorkFlowmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.NAME = Convert.ToString(reader["NAME"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; }*/ #endregion #region 通过workflow_type.name,userid查找workflow_step的内容 static public List GetWorkFlowStep(string WorkFlowName, string UserID) { var strSql = new StringBuilder(); strSql.Append(" select * from workflow_step where WORKFLOWID in "); strSql.Append(" (select gid from workflow where [type]=(select [typeno] from workflow_type where [name]='" + WorkFlowName + "')) "); strSql.Append(" and AUDITOR='" + UserID + "' order by STEPNO"); return SetWorkFlowStep(strSql); } private static List SetWorkFlowStep(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { DSWeb.Areas.CommMng.Models.WorkFlowStepmb data = new DSWeb.Areas.CommMng.Models.WorkFlowStepmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.NAME = Convert.ToString(reader["NAME"]); data.STEPNO = Convert.ToString(reader["STEPNO"]); data.NEEDALLPASS = Convert.ToString(reader["NEEDALLPASS"]); data.ISMUST = Convert.ToString(reader["ISMUST"]); data.ISLAST = Convert.ToString(reader["ISLAST"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 获取该用户,在该工作流程的该步骤中 可以操作的业务编号列表 /* static public List GetWorkFlowState(string WorkFlowID, int StepNo, string USERID) { var strSql = new StringBuilder(); strSql.Append(" select * from workflow_using "); strSql.Append(" where workflowid='" + WorkFlowID + "' "); strSql.Append(" and stepno=( "); strSql.Append(" select stepno from workflow_step "); strSql.Append(" where workflowid='" + WorkFlowID + "' "); strSql.Append(" and auditor='" + USERID + "' "); strSql.Append(" and stepno=" + StepNo.ToString() + ") "); return SetWorkFlowState(strSql); } private static List SetWorkFlowState(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WorkFlow_Usingmb data = new WorkFlow_Usingmb(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]); data.STEPNO = Convert.ToString(reader["STEPNO"]); data.REJECTOR_ID = Convert.ToString(reader["REJECTOR_ID"]); data.REJECT_TIME = Convert.ToString(reader["REJECT_TIME"]); data.FINISHED = Convert.ToString(reader["FINISHED"]); data.ISDELETE = Convert.ToString(reader["ISDELETE"]); data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]); data.DELETETIME = Convert.ToString(reader["DELETETIME"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } */ #endregion #region 键值维护表 crm_key_code static public List GetCrmKeyCodeList(string strCondition) { String strSql = "SELECT ID as GID,KEYTYPE,KEYVALUE from crm_key_code "; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where 1=1 " + strCondition; } return SetCrmKeyCodeData(strSql); } private static List SetCrmKeyCodeData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CrmKeyCodeModel data = new CrmKeyCodeModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.KEYTYPE = Convert.ToString(reader["KEYTYPE"]); data.KEYVALUE = Convert.ToString(reader["KEYVALUE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 品名 static public List GetCodeMsdsGoodsList(string condition) { String strSql = "SELECT GID,GOODNAME GOODCODE,(CHEMICALCGOODSNAME+ '-' + GOODNAME+'-'+DCLASS) as CodeAndName,(CHEMICALCGOODSNAME+ '-' + CHEMICALCGOODSNAME) as GOODNAME,'' GoodsTypeGID,'' GoodsTypeName from code_msds "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } strSql += " order by CodeAndName"; return SetCodeGoodsData(strSql); } static public List GetCodeGoodsList(string condition) { String strSql = "SELECT GID,GOODCODE,(GOODCODE+'-'+GOODNAME) as CodeAndName,GOODNAME,GoodsTypeGID,GoodsTypeName=(select top 1 GoodsTypeName from code_goodsType where gid=code_goods.GoodsTypeGID) from code_goods "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } strSql += " order by CodeAndName"; return SetCodeGoodsData(strSql); } static public List GetImportCodeGoodsList(string condition) { String strSql = "SELECT CNNAME GID,CNNAME GOODCODE,CNNAME as CodeAndName,CNNAME GOODNAME,'' GoodsTypeGID,'' GoodsTypeName from Import_Cargoname "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } strSql += " order by CNNAME"; return SetCodeGoodsData(strSql); } private static List SetCodeGoodsData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeGoodsModel data = new CodeGoodsModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]);//货物代码 data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//商品编码 data.GOODCODE = Convert.ToString(reader["GOODCODE"]);//商品编码 data.GOODNAME = Convert.ToString(reader["GOODNAME"]);//商品名称 data.GoodsTypeGID = Convert.ToString(reader["GoodsTypeGID"]);// data.GoodsTypeName = Convert.ToString(reader["GoodsTypeName"]);// #endregion headList.Add(data); } reader.Close(); } CodeGoodsModel adata = new CodeGoodsModel(); #region Set DB data to Object adata.GID = "";//货物代码 adata.CodeAndName = "";//商品编码 adata.GOODCODE = "";//商品编码 adata.GOODNAME = "";//商品名称 adata.GoodsTypeGID = ""; adata.GoodsTypeName = ""; #endregion headList.Add(adata); return headList; } #endregion #region 品名明细表 static public List GetCodeGoodsDetailList(string condition) { String strSql = "SELECT *,GOODNAME=(select top 1 GOODNAME from code_goods where gid=code_goods_detail.LINKGID) from code_goods_detail "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } strSql += " order by GOODSDETAILNAME"; return SetCodeGoodsDetailData(strSql); } private static List SetCodeGoodsDetailData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeGoodsDetailModel data = new CodeGoodsDetailModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//惟一编号 data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//品名GID data.GOODSDETAILNAME = (reader["GOODSDETAILNAME"] == null ? "" : Convert.ToString(reader["GOODSDETAILNAME"]));//品牌名称 data.REMARK = (reader["REMARK"] == null ? "" : Convert.ToString(reader["REMARK"]));//备注 data.GOODSDETAILPKGS = (reader["GOODSDETAILPKGS"] == null ? 0 : Convert.ToDecimal(reader["GOODSDETAILPKGS"]));//规格件数 data.GOODNAME = (reader["GOODNAME"] == null ? "" : Convert.ToString(reader["GOODNAME"]));//品名 #endregion headList.Add(data); } reader.Close(); } CodeGoodsDetailModel adata = new CodeGoodsDetailModel(); #region Set DB data to Object adata.GID = "";//惟一编号 adata.LINKGID = "";//品名GID adata.GOODSDETAILNAME = "";//品牌名称 adata.REMARK = "";//备注 adata.GOODSDETAILPKGS = 0;//规格件数 adata.GOODNAME = "";//品名 #endregion headList.Add(adata); return headList; } #endregion #region 新版键值维护表 tSysEnumValue static public List GetTSysEnumValueList(string strCondition) { String strSql = "select *,CodeAndName=(EnumValueID+' | '+EnumValueName) from tSysEnumValue";//需求编号:SR2017081100003 if (!string.IsNullOrEmpty(strCondition)) { strSql += " where LangId=0 " + strCondition; } return SetTSysEnumValueData(strSql); } static public List GetTSysEnumValueListByTypeid(string typeid) { String strSql = "select *,CodeAndName=(EnumValueID+' | '+EnumValueName) from tSysEnumValue";//需求编号:SR2017081100003 strSql += " where LangId=0 and enumtypeid='" + typeid + "'"; return SetTSysEnumValueData(strSql); } private static List SetTSysEnumValueData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { TSysEnumValueDataModel data = new TSysEnumValueDataModel(); #region Set DB data to Object data.EnumValueID = Convert.ToString(reader["EnumValueID"]);//需求编号:SR2017081100003 data.EnumValueName = Convert.ToString(reader["EnumValueName"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//需求编号:SR2017081100003 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 国际港口(进口装货港、出口卸货港) static public List GetCodeDisportList(string condition) { String strSql = GetCodeDisportList_Sqlstr(condition); return SetCodeDisportData(strSql); } static public List GetCodeDisportbyEDICODE(string EDICODE) { String strSql = "SELECT *,(PORT+'-'+EDICODE) as CodeAndName,(select LANE from code_lanes where GID=Code_Disport.LANEGID) LANE from Code_Disport where EDICODE='" + EDICODE + "'"; return SetCodeDisportData(strSql); } static public List GetCodeRailwayPortList(string condition) { String strSql = "SELECT PORTENAME PORT,PORTCNAME CNAME,'' EDICODE,(PORTENAME+'-'+PORTCNAME) as CodeAndName,'' LANE from code_railwayport where "; if (condition != "") strSql = strSql + condition; strSql = strSql + " ORDER BY PORTENAME "; return SetCodeDisportData(strSql); } public static string GetCodeDisportList_Sqlstr(string condition) { String strSql = "SELECT *,(PORT+'-'+EDICODE+'('+CNAME+')') as CodeAndName,(select LANE from code_lanes where GID=Code_Disport.LANEGID) LANE from Code_Disport where "; if (condition != "") strSql = strSql + condition + " and "; strSql = strSql + " EDICODE<>'' ORDER BY PORT "; return strSql; } public static string GetCodeDisportList_DisplayWithCNAME_Sqlstr(string condition) { String strSql = "SELECT *,(PORT+'-'+EDICODE+'-'+CNAME) as CodeAndName,(select LANE from code_lanes where GID=Code_Disport.LANEGID) LANE from Code_Disport where "; if (condition != "") strSql = strSql + condition + " and "; strSql = strSql + " EDICODE<>'' ORDER BY PORT "; return strSql; } private static List SetCodeDisportData(String strSql) { var headList = new List(); #region 在开头插入空值 CodeDisportModel data2 = new CodeDisportModel(); data2.PORT = "";//港口英文名称 data2.CNAME = "";//中文名称 data2.EDICODE = "";//中文名称 data2.CodeAndName = "";//中文名称 data2.LANE = "";//中文名称 headList.Add(data2); #endregion Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeDisportModel data = new CodeDisportModel(); #region Set DB data to Object data.PORT = Convert.ToString(reader["PORT"]);//港口英文名称 data.CNAME = Convert.ToString(reader["CNAME"]);//中文名称 data.EDICODE = Convert.ToString(reader["EDICODE"]);//中文名称 data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//中文名称 data.LANE = Convert.ToString(reader["LANE"]);//航线 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 国内港口(出口装货港、进口卸货港) static public List GetCodeLoadportList(string condition) { String strSql = GetCodeLoadportList_Sqlstr(condition); return SetCodeLoadportData(strSql); } public static string GetCodeLoadportList_Sqlstr(string condition) { String strSql = "SELECT *,(PORT+'-'+CNAME) as CodeAndName from Code_Loadport WHERE EDICODE<>'' "; if (condition != "") strSql = strSql + " and " + condition; return strSql; } static public List GetCodeLoadportList() { String strSql = "SELECT *,(PORT+'-'+CNAME) as CodeAndName from Code_Loadport WHERE EDICODE<>'' "; return SetCodeLoadportData(strSql); } static public List GetLoadportbyEDI(string EDICODE) { String strSql = "SELECT *,(PORT+'-'+CNAME) as CodeAndName from Code_Loadport WHERE EDICODE='" + EDICODE + "' "; return SetCodeLoadportData(strSql); } private static List SetCodeLoadportData(String strSql) { var headList = new List(); #region 在最开头插入空值 CodeLoadportModel data2 = new CodeLoadportModel(); data2.PORT = "";//港口英文名称 data2.CNAME = "";//中文名称 data2.EDICODE = "";//中文名称 data2.CodeAndName = "";//中文名称 headList.Add(data2); #endregion Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeLoadportModel data = new CodeLoadportModel(); #region Set DB data to Object data.PORT = Convert.ToString(reader["PORT"]);//港口英文名称 data.CNAME = Convert.ToString(reader["CNAME"]);//中文名称 data.EDICODE = Convert.ToString(reader["EDICODE"]);//中文名称 data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//中文名称 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 品名类型 static public List Getsys_templateList() { String strSql = "select GID,[TEMPLATE],[TEMPLATETYPE],[COMPANYID],[TEMPLDATE_DESC] from sys_template where TEMPLATETYPE='发票备注'"; return Setsys_templateData(strSql); } private static List Setsys_templateData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { sys_template data = new sys_template(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]);//货物代码 data.TEMPLATE = Convert.ToString(reader["TEMPLATE"]); data.TEMPLATETYPE = Convert.ToString(reader["TEMPLATETYPE"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); data.TEMPLDATE_DESC = Convert.ToString(reader["TEMPLDATE_DESC"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 品名类型 static public List GetCodeGoodsTypeList() { String strSql = "select *,(GoodsTypeCode+'-'+GoodsTypeName) as CodeAndName from Code_GoodsType"; return SetCodeGoodsTypeData(strSql); } private static List SetCodeGoodsTypeData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeGoodsTypeModel data = new CodeGoodsTypeModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]);//货物代码 data.CodeAndName = Convert.ToString(reader["CodeAndName"]); data.GoodsTypeCode = Convert.ToString(reader["GoodsTypeCode"]); data.GoodsTypeName = Convert.ToString(reader["GoodsTypeName"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 箱型 static public List GetCodeCtnList() { String strSql = "select * from [code_ctn] ORDER BY CTNID "; return SetCodeCtnData(strSql); } private static List SetCodeCtnData(String strSql, bool isempty = true) { var headList = new List(); if (isempty) { CodeCtnModel data2 = new CodeCtnModel(); data2.CTN = ""; data2.DLIKGS = 0M; headList.Add(data2); } 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["CTN"]); if (reader["DLIKGS"] != DBNull.Value) data.DLIKGS = Convert.ToDecimal(reader["DLIKGS"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetCodeCtnList(string condition, bool isempty = true) { String strSql = "select * from [code_ctn] "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } strSql += " ORDER BY CTNID"; return SetCodeCtnData(strSql, isempty); } #endregion #region 集装箱显示 static public CtnDispModel GetCtnDisp() { String strSql = "SELECT top 1 * from code_ctn_disp"; return SetCtnDispData(strSql); } private static CtnDispModel SetCtnDispData(String strSql) { var headList = new CtnDispModel(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CtnDispModel data = new CtnDispModel(); #region Set DB data to Object data.ID = Convert.ToString(reader["ID"]); data.CNT1 = Convert.ToString(reader["CNT1"]); data.CNT2 = Convert.ToString(reader["CNT2"]); data.CNT3 = Convert.ToString(reader["CNT3"]); data.CNT4 = Convert.ToString(reader["CNT4"]); data.CNT5 = Convert.ToString(reader["CNT5"]); data.CNT6 = Convert.ToString(reader["CNT6"]); data.CNT7 = Convert.ToString(reader["CNT7"]); data.CNT8 = Convert.ToString(reader["CNT8"]); data.CNT9 = Convert.ToString(reader["CNT9"]); data.CNT10 = Convert.ToString(reader["CNT10"]); data.CORPID = Convert.ToString(reader["CORPID"]); #endregion headList = data; } reader.Close(); } return headList; } #endregion #region 航线 static public List GetCodeLaneList() { String strSql = "select * from [code_lanes] ORDER BY LANE"; return SetCodeLaneData(strSql); } private static List SetCodeLaneData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { LaneModel data = new LaneModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.LANEID = Convert.ToString(reader["LANEID"]); data.LANE = Convert.ToString(reader["LANE"]); data.LANEEN = Convert.ToString(reader["LANEEN"]); data.EDICODE = Convert.ToString(reader["EDICODE"]); data.OP = Convert.ToString(reader["OP"]); data.DOC = Convert.ToString(reader["DOC"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); #endregion headList.Add(data); } reader.Close(); } LaneModel adata = new LaneModel(); #region Set DB data to Object adata.GID = ""; adata.LANEID = ""; adata.LANE = ""; adata.LANEEN = ""; adata.EDICODE = ""; #endregion headList.Add(adata); return headList; } #endregion #region 付费方式 static public List GetCodeFrtList() { String strSql = "select * from code_frt ORDER BY FRT"; return SetCodeFrtData(strSql); } private static List SetCodeFrtData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeFrtModel data = new CodeFrtModel(); #region Set DB data to Object data.FEID = Convert.ToString(reader["FEID"]); data.FRT = Convert.ToString(reader["FRT"]); data.FRTCNAME = Convert.ToString(reader["FRTCNAME"]); data.EDICODE = Convert.ToString(reader["EDICODE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 签单方式 static public List GetCodeBLTYPEList() { String strSql = "select * from code_issutype ORDER BY BLTYPE"; return SetCodeBLTYPEData(strSql); } private static List SetCodeBLTYPEData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeBLTYPEModel data = new CodeBLTYPEModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BLTYPE = Convert.ToString(reader["BLTYPE"]); data.NOBILL = Convert.ToString(reader["NOBILL"]); data.COPYNOBILL = Convert.ToString(reader["COPYNOBILL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 运输条款 static public List GetCodeSERVICEList() { String strSql = "select * from code_service ORDER BY SERVICE"; return SetCodeSERVICEData(strSql); } private static List SetCodeSERVICEData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeSERVICEModel data = new CodeSERVICEModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.SERVICE = Convert.ToString(reader["SERVICE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 提单模板 static public List GetCodeTemplateList() { String strSql = "select * from code_template "; return SetCodeTemplateData(strSql); } private static List SetCodeTemplateData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeTemplateModel data = new CodeTemplateModel(); #region Set DB data to Object data.TEMPLATEID = Convert.ToString(reader["TEMPLATEID"]); data.TEMPLATE = Convert.ToString(reader["TEMPLATE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 件数包装 static public List GetCodePackageList() { String strSql = "select * from [code_package] order by PKGS"; return SetCodePackageData(strSql); } private static List SetCodePackageData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodePackageModel data = new CodePackageModel(); #region Set DB data to Object data.PKGS = Convert.ToString(reader["PKGS"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 币别 static public List GetCodeCurrencyList(string condition) { String strSql = "select * from [code_currency]"; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } return SetCodeCurrencyData(strSql); } private static List SetCodeCurrencyData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CodeCurrencyModel data = new CodeCurrencyModel(); #region Set DB data to Object data.CODENAME = Convert.ToString(reader["CODENAME"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 委托单位_联系人 static public List GetInfoClientContactList(string condition) { String strSql = "select * from [info_client_contact]"; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } return SetInfoClientContactData(strSql); } private static List SetInfoClientContactData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { InfoClientContactModel data = new InfoClientContactModel(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.SHOWNAME = Convert.ToString(reader["SHOWNAME"]); data.EMAIL = Convert.ToString(reader["EMAIL"]); data.TEL = Convert.ToString(reader["TEL"]); data.FAX = Convert.ToString(reader["FAX"]); #endregion headList.Add(data); } reader.Close(); } var _blank = new InfoClientContactModel(); headList.Add(_blank); return headList; } static public List GetInfoClientMailTel(string CUSTOMERNAME) { var ContactList = GetInfoClientContactList(" LINKID in(select GID from info_client where shortname='" + CUSTOMERNAME + "') and isnull(email,'')<>'' "); if (!string.IsNullOrWhiteSpace(CUSTOMERNAME)) { var infoclient = MsInfoClientDAL.GetData(" shortname='" + CUSTOMERNAME + "' "); var _infoclient = new InfoClientContactModel(); _infoclient.SHOWNAME = infoclient.SHORTNAME; _infoclient.TEL = infoclient.TEL; _infoclient.EMAIL = infoclient.EMAIL; if (!string.IsNullOrWhiteSpace(_infoclient.EMAIL)) ContactList.Add(_infoclient); var _infoclient2 = new InfoClientContactModel(); _infoclient2.SHOWNAME = "注意:下拉选项当中带汉字名字,选中后会使用其后方的邮箱地址(不带汉字);你也可以手动输入邮箱,但这时输入的内容请不要带其他汉字,否则无法正确发送邮件。"; ContactList.Add(_infoclient2); } return ContactList; } #endregion #region 项目 static public List GetCwItemList(string condition, string strUserID) { string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID); String strSql = "SELECT *,(FINANCESOFTCODE+'-'+ITEMNAME) as CodeAndName from cw_item where [STARTGID]='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) order by ITEMCODE,ITEMNAME"; return SetCwItemData(strSql); } private static List SetCwItemData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { CwItemModel data = new CwItemModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码 data.ITEMCODE = (reader["ITEMCODE"] == null ? "" : Convert.ToString(reader["ITEMCODE"]));//年 data.ITEMNAME = (reader["ITEMNAME"] == null ? "" : Convert.ToString(reader["ITEMNAME"]));//月 data.FINANCESOFTCODE = (reader["FINANCESOFTCODE"] == null ? "" : Convert.ToString(reader["FINANCESOFTCODE"]));//月 data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司代码 data.ISDELETE = (reader["ISDELETE"] == null ? false : Convert.ToBoolean(reader["ISDELETE"]));//是否删除 data.DELETEUSER = (reader["DELETEUSER"] == null ? "" : Convert.ToString(reader["DELETEUSER"]));//删除人 string kjdE = reader["DELETETIME"].ToString();//删除时间 if (reader["DELETETIME"] != null && reader["DELETETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["DELETETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["DELETETIME"].ToString().Trim() != "") { data.DELETETIME = Convert.ToDateTime(reader["DELETETIME"]);//删除时间 } data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人gid if (data.CREATETIME != null) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间 data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid if (data.MODIFIEDTIME != null) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间 data.CodeAndName = (reader["CodeAndName"] == null ? "" : Convert.ToString(reader["CodeAndName"])); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 获得总账管理的当前账套GID static public String GetCwSTARTGID(string strUSERID) { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strSTARTGID = T_ALL_DA.GetStrSQL("GID", "select top 1 GID from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "')"); return strSTARTGID; } #endregion #region 获得总账管理的当前账套名称 static public String GetCwSTARTNAME(string strUSERID) { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strSTARTNAME = T_ALL_DA.GetStrSQL("STARTNAME", "select top 1 STARTNAME from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "')"); return strSTARTNAME; } #endregion #region 获得总账管理的当前账套启用年月 static public String GetCwSTARTMONTH(string strUSERID) { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strSTARTMONTH = T_ALL_DA.GetStrSQL("STARTMONTH", "select top 1 STARTMONTH from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "') order by STARTMONTH desc"); return strSTARTMONTH; } #endregion #region 获得总账管理的当前会计期间 static public String GetCwACCDATE(string strUSERID) { string strCwSTARTGID = GetCwSTARTGID(strUSERID); string strSTARTMONTH = GetCwSTARTMONTH(strUSERID); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strACCDATE = T_ALL_DA.GetStrSQL("ACCDATE", "select isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from cw_carry_over WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' ORDER by ACCDATE DESC),'" + strSTARTMONTH + "') as ACCDATE"); return strACCDATE; } static public String GetCwACCDATE(string strUSERID, string strCwSTARTGID) { string strSTARTMONTH = GetCwSTARTMONTH(strUSERID); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strACCDATE = T_ALL_DA.GetStrSQL("ACCDATE", "select isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from cw_carry_over WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' ORDER by ACCDATE DESC),'" + strSTARTMONTH + "') as ACCDATE"); return strACCDATE; } #endregion #region 获得出纳管理的当前账套GID static public String GetCtSTARTGID(string strUSERID) { string strCwSTARTGID = GetCwSTARTGID(strUSERID); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strSTARTGID = T_ALL_DA.GetStrSQL("GID", "select GID from ct_design_startusing WITH(NOLOCK) where ISENABLE=1 and (ISDELETE=0 or ISDELETE is null) and STARTGID='" + strCwSTARTGID + "'"); return strSTARTGID; } #endregion #region 获得出纳管理的当前会计期间 static public String GetCtACCDATE(string strUSERID) { string sCtSTARTGID = GetCtSTARTGID(strUSERID); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string strACCDATE = T_ALL_DA.GetStrSQL("ACCDATE", "select isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from ct_carry_over WITH(NOLOCK) where STARTGID='" + sCtSTARTGID + "' and ISCARRY=1 ORDER by STARTGID,ACCDATE DESC),ISNULL((select top 1 STARTMONTH from ct_design_startusing WITH(NOLOCK) where STARTGID='" + sCtSTARTGID + "' and ISENABLE=1 and (ISDELETE=0 or ISDELETE is null) order by STARTMONTH desc),'')) as ACCDATE"); return strACCDATE; } #endregion #region 科目币别表查询 static public List GetCwAccitemsCurrencyList(string strCondition, string strUserID) { string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID); var strSql = new StringBuilder(); strSql.Append("SELECT CURRENCY from cw_accitems_currency where LINKGID in (SELECT GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "')"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" group by CURRENCY"); strSql.Append(" order by CURRENCY"); return SetMsCwAccitemsCurrencyData(strSql); } private static List SetMsCwAccitemsCurrencyData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { int k = 0; while (reader.Read()) { k++; CwAccitemsCurrencyModel data = new CwAccitemsCurrencyModel(); #region Set DB data to Object data.CURRENCY = (reader["CURRENCY"] == null ? "" : Convert.ToString(reader["CURRENCY"]).Trim());//币别 #endregion headList.Add(data); } // if (k == 0) { CwAccitemsCurrencyModel data = new CwAccitemsCurrencyModel(); #region Set DB data to Object data.LINKGID = "";//科目GID data.CURRENCY = "RMB";//币别 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 业务类型 static public List GetOPLBList(string condition) { String strSql = "SELECT OPLB,OPLBNAME from [v_op_bs]"; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } strSql += " GROUP by OPLB,OPLBNAME ORDER BY OPLBNAME"; return SetOPLBData(strSql); } private static List SetOPLBData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { OPLBModel data = new OPLBModel(); #region Set DB data to Object data.OPLB = Convert.ToString(reader["OPLB"]); data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 获取 总账科目信息 static public List GetCwAccitemsGl(string strCondition, string strUserID) { string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID); string strCwACCDATE = GetCwACCDATE(strUserID); var strSql = new StringBuilder(); strSql.Append("select *,ACCID+'-'+ACCNAME AS ACCIDNAME from cw_accitems_gl where [year]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'"); // strSql.Append("select *,ACCID+'-'+ACCNAME+'('+[YEAR]+')' AS ACCIDNAME from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } // strSql.Append(" ORDER BY [YEAR] DESC "); return SetCwAccitemsGl(strSql); } private static List SetCwAccitemsGl(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CwAccitemsGlModel data = new CwAccitemsGlModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码 data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码 data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称 data.ACCIDNAME = Convert.ToString(reader["ACCIDNAME"]); data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志) data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向 data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币 data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门 data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员 data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门 data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目 data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注 data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年 data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月 data.PACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码 data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益) data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用 data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim()); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 获取 总账科目信息(包含上级科目) static public List GetCwAccitemsGlAll(string strCondition, string strUserID, string CwSTARTGID = "", string CwACCDATE = "") { string strCwSTARTGID = CwSTARTGID; if (strCwSTARTGID == "") { strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID); } string strCwACCDATE = CwACCDATE; if (strCwACCDATE == "") { strCwACCDATE = GetCwACCDATE(strUserID, strCwSTARTGID); } var pacclist = GetCwAccitemsGlPAll(strCwSTARTGID, strCwACCDATE); var strSql = new StringBuilder(); strSql.Append("select *,ACCID+ACCNAME AS ACCIDNAME from cw_accitems_gl where [year]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetCwAccitemsGlAll(strSql, pacclist); } static public CwAccitemsGlModel GetCwAccitems(string accid, List accitemsGlAll) { var accitems = accitemsGlAll.Find(t => t.ACCID == accid); if (accitems == null) accitems = new CwAccitemsGlModel(); return accitems; } private static List SetCwAccitemsGlAll(StringBuilder strSql, List pacclist) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CwAccitemsGlModel data = new CwAccitemsGlModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码 data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志) data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向 data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币 data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门 data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员 data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门 data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目 data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注 data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年 data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月 data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益) data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用 data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim()); //data.ACCIDNAME = (reader["ACCIDNAME"] == null ? "" : Convert.ToString(reader["ACCIDNAME"]).Trim());//科目名称 // string sPACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码 string sACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码 string sACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称 data.ACCLNAME = sACCNAME; data.PACCGID = sPACCGID;//父级科目代码 data.ACCID = sACCID;//科目代码 data.ACCNAME = setCAGA(sPACCGID, sACCNAME, pacclist);//科目名称 data.ACCIDNAME = sACCID + "-" + data.ACCNAME;//科目名称 #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetCwAccitemsGlPAll(string strCwSTARTGID, string strCwACCDATE) { var strSql = new StringBuilder(); strSql.Append("select *,ACCID+ACCNAME AS ACCIDNAME from cw_accitems_gl where [year]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' AND ISENABLE=1 AND DETAILED<>1"); return SetCwAccitemsGlPAll(strSql); } private static List SetCwAccitemsGlPAll(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CwAccitemsGlModel data = new CwAccitemsGlModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码 data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志) data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向 data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币 data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门 data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员 data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门 data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目 data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注 data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年 data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月 data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益) data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用 data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim()); //data.ACCIDNAME = (reader["ACCIDNAME"] == null ? "" : Convert.ToString(reader["ACCIDNAME"]).Trim());//科目名称 // string sPACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码 string sACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码 string sACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称 data.PACCGID = sPACCGID;//父级科目代码 data.ACCID = sACCID;//科目代码 data.ACCNAME = sACCNAME;//科目名称 #endregion headList.Add(data); } reader.Close(); } return headList; } static public String setCAGA(string sPACCGID, string sACCNAME) { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string sSQL = "select *,(ACCNAME+'_" + sACCNAME + "') AS ACCIDNAME from cw_accitems_gl where gid='" + sPACCGID + "'"; DataSet ds = T_ALL_DA.GetAllSQL(sSQL); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { sPACCGID = ds.Tables[0].Rows[0]["PACCGID"].ToString(); sACCNAME = ds.Tables[0].Rows[0]["ACCIDNAME"].ToString(); if (sPACCGID.Length > 20) { sACCNAME = setCAGA(sPACCGID, sACCNAME); } } } return sACCNAME; } static public String setCAGA(string sPACCGID, string sACCNAME, List pacclist) { pacclist.ForEach(i => { if (i.GID == sPACCGID) { sPACCGID = i.PACCGID; sACCNAME = i.ACCNAME + "_" + sACCNAME; if (sPACCGID.Length > 26) { sACCNAME = setCAGA(sPACCGID, sACCNAME, pacclist); } } }); return sACCNAME; } #endregion #region 获取 接口科目信息 static public List GetCwAccitems(string strCondition) { var strSql = new StringBuilder(); //strSql.Append("SELECT [GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS],ACCID+'_'+ACCNAME AS ACCIDNAME FROM ((SELECT [GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS] FROM cw_accitems where ACCID is not null and ACCID<>'') UNION (SELECT [GID],FINANCESOFTCODE as [ACCID],BANKNAME as [ACCNAME],1 as [DETAILED],'借' as [DC],0 as [ISFCY],0 as [ISDEPTACC],0 as [ISEMPLACC],0 as [ISCORPACC],0 as [ISITEMACC],'' as [REMARKS] FROM sys_bank where FINANCESOFTCODE is not null and FINANCESOFTCODE<>'')) as a where 1=1"); strSql.Append("SELECT [GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS],ACCID+'_'+ACCNAME AS ACCIDNAME FROM cw_accitems where ACCID is not null and ACCID<>''"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" order by ACCID"); return SetCwAccitems(strSql); } private static List SetCwAccitems(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CwAccitemsGlModel data = new CwAccitemsGlModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim()); data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码 data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称 data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志) data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向 data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币 data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门 data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员 data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门 data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目 data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注 data.ACCIDNAME = (reader["ACCIDNAME"] == null ? "" : Convert.ToString(reader["ACCIDNAME"]).Trim()); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion // #region 获取指定表内,符合条件的列的数量,主要用于防止删除主表 static public int GetExist(string tablename, string condition) { var strSql = new StringBuilder(); strSql.Append("Select count(*) _count from " + tablename); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } var _count = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { _count = Convert.ToInt16(reader["_count"]); } reader.Close(); } return _count; } //fieldname相同 fieldname2不相同(通常用于判断 某单据号相同而GID号不同 以防止不同业务同单据号) static public int GetExist(string tablename, string fieldname, string value, string fieldname2, string value2) { var strSql = new StringBuilder(); var tvalue = value.Trim(); var condition = new StringBuilder(); if (tvalue == "null" || tvalue == "Null" || tvalue == "NULL") { condition.Append(" is null "); } else { condition.Append(fieldname + "='" + tvalue + "'"); } condition.Append(string.Format(" and {0}<>'{1}' ", fieldname2.Trim(), value2.Trim())); strSql.Append("Select count(*) _count from " + tablename); strSql.Append(" where " + condition.ToString()); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { _count = Convert.ToInt16(reader["_count"]); } reader.Close(); } return _count; } //返回 某表中 某字段=某值的列 的数量 static public int GetExist(string tablename, string fieldname, string value) { var strSql = new StringBuilder(); var tvalue = value.Trim(); var condition = new StringBuilder(); if (tvalue == "null" || tvalue == "Null" || tvalue == "NULL") { condition.Append(" is null "); } else { condition.Append(fieldname + "='" + tvalue + "'"); } strSql.Append("Select count(*) _count from " + tablename); strSql.Append(" where " + condition.ToString()); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { _count = Convert.ToInt16(reader["_count"]); } reader.Close(); } return _count; } //返回 某表中 某字段=某值 且 某字段=某值... 的列 的数量 static public int GetExist(string tablename, string keyname, string keyvalue, List fieldnamelist, List valuelist) { var strSql = new StringBuilder(); if (fieldnamelist.Count != valuelist.Count) return 999; var condition = new StringBuilder(); var _listcount = 0; foreach (var fieldname in fieldnamelist) { var value = valuelist[_listcount]; var tvalue = value.Trim(); if (condition.ToString() != "") condition.Append(" and "); if (tvalue == "null" || tvalue == "Null" || tvalue == "NULL") { condition.Append(fieldname + " is null "); } else { condition.Append(fieldname + "='" + tvalue + "'"); } _listcount++; } strSql.Append("Select count(*) _count from " + tablename); strSql.Append(" where " + keyname + "<>'" + keyvalue + "' and " + condition.ToString()); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { _count = Convert.ToInt16(reader["_count"]); } reader.Close(); } return _count; } static public bool HaveExist(string tablename, string fieldname, string value) { var _count = GetExist(tablename, fieldname, value); bool r = false; if (_count > 0) { r = true; } return r; } static public bool HaveExist(string tablename, string fieldname, string value, string fieldname2, decimal value2) { return HaveExist(tablename, fieldname, value, fieldname2, value2.ToString()); } /// /// fieldname相同 fieldname2不相同 /// /// /// /// /// /// /// static public bool HaveExist(string tablename, string fieldname, string value, string fieldname2, string value2) { var _count = GetExist(tablename, fieldname, value, fieldname2, value2); bool r = false; if (_count > 0) { r = true; } return r; } static public bool HaveExist(string tablename, string condition) { var _count = GetExist(tablename, condition); bool r = false; if (_count > 0) { r = true; } return r; } #endregion #region 获取 出纳摘要信息 static public List GetEXPLAN(string strCondition, string strUserID) { string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(strUserID); var strSql = new StringBuilder(); strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_explan_detail.MODIFIEDUSER) from ct_explan_detail where 1=1"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and LINKGID in (select GID from ct_explan where STARTGID='" + strCtSTARTGID + "' and " + strCondition + ")"); } strSql.Append(" order by EXPLAN"); return SetEXPLAN(strSql); } private static List SetEXPLAN(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsCtExplanDetail data = new MsCtExplanDetail(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码 data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//摘要GID data.EXPLAN = (reader["EXPLAN"] == null ? "" : Convert.ToString(reader["EXPLAN"]));//内容 data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid if (data.MODIFIEDTIME != null) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间 data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//更改人 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 通用查询方法 参数是查询语句,必须把GID和值as成GID和GValue static public List GeneralSelect(string strCondition) { var strSql = new StringBuilder(); strSql.Append(strCondition); return SetGeneralSelect(strSql); } static public List GeneralSelect(string tablename, string keyname, string valuename, string condition) {//keyname=GVALUE一般用于displayname var strSql = new StringBuilder(); strSql.Append(string.Format("select {1} as GID,{2} as GVALUE from {0}", tablename, keyname, valuename)); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } return SetGeneralSelect(strSql); } static public List GeneralSelect2(string strCondition) { var strSql = new StringBuilder(); strSql.Append(strCondition); return SetGeneralSelect3(strSql); } #region 将GVALUE的值集合成逗号隔开的 static public List GeneralSelect_commaList(string tablename, string valuename, string condition) { var strSql = new StringBuilder(); strSql.Append(string.Format("select distinct {1} as GVALUE from {0}", tablename, valuename)); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } return SetGeneralSelect2(strSql); } #endregion #region 获取指定表中,符合条件的字段值,返回一个用逗号隔开各个字段的string /// /// 获取指定表中,符合条件的字段值,返回一个用逗号隔开各个字段的string /// /// /// /// /// static public string GeneralSelect_commaString(string tablename, string valuename, string condition) { var itemlist = GeneralSelect_commaList(tablename, valuename, condition); var result = ""; if (itemlist.Count > 0) { foreach (var item in itemlist) { if (result != "") { result += ","; } result += "'" + item.GVALUE + "'"; } return result; } else return ""; } #endregion public static List GeneralGet(string tablename, string condition = "") { var _condition = condition; if (tablename == "company" || tablename == "sys_company") { if (!string.IsNullOrEmpty(_condition)) { _condition += " and ISDELETED=0 "; } else { _condition += " ISDELETED=0 "; } return GeneralSelect("company", "GID", "NAME", _condition); } else if (tablename == "client") { return GeneralSelect("info_client", "GID", "SHORTNAME", _condition); } else if (tablename == "client_airline") { return GeneralSelect("info_client", "CODENAME", "SHORTNAME", " ISAIRLINES=1 "); } return new List(); } public static string GeneralGet_String(string tablename, string condition = "") { var idlist = BasicDataRefDAL.GeneralGet(tablename, condition); var result = ""; if (idlist.Count > 0) { result = idlist[0].GVALUE.ToString(); } return result; } private static List SetGeneralSelect(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { GeneralModel data = new GeneralModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"])); data.GVALUE = (reader["GVALUE"] == null ? "" : Convert.ToString(reader["GVALUE"])); #endregion headList.Add(data); } reader.Close(); } return headList; } private static List SetGeneralSelect2(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { GeneralModel data = new GeneralModel(); #region Set DB data to Object data.GVALUE = (reader["GVALUE"] == null ? "" : Convert.ToString(reader["GVALUE"])); #endregion headList.Add(data); } reader.Close(); } return headList; } private static List SetGeneralSelect3(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { GeneralModel data = new GeneralModel(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"])); data.GVALUE = (reader["GVALUE"] == null ? "" : Convert.ToString(reader["GVALUE"])); data.GVALUE2 = (reader["GVALUE2"] == null ? "" : Convert.ToString(reader["GVALUE2"])); #endregion headList.Add(data); } reader.Close(); } return headList; } #region 获取指定表内的某列数据前50行,指定查询条件和排序方式 主要用于提供“近期数据”内容的combox public static List GeneralSelect_Top(string TABLENAME, string FIELDNAME, string condition, string topnum = "50") { var result = new List(); var sqlstr = "select TOP " + topnum + " " + FIELDNAME + " as GID," + FIELDNAME + " as GVALUE from " + TABLENAME + " where " + condition; result = GeneralSelect(sqlstr); return result; } #endregion #region 获取指定表内的,指定查询条件的,某字段distinct值 public static List GeneralSelect_Distinct(string TABLENAME, string FIELDNAME, string condition) { var result = new List(); var sqlstr = "select distinct " + FIELDNAME + " as GID," + FIELDNAME + " as GVALUE from " + TABLENAME + " where " + condition; result = GeneralSelect(sqlstr); return result; } #endregion #endregion #region 将带逗号的内容拆成单个,并将出现频率最高的放置在最前。参数为(表名 列名 查询条件) /// /// 将带逗号的内容拆成单个,并将出现频率最高的放置在最前。参数为(表名 列名 查询条件) /// /// /// /// /// static public List GetCommaWord(string tablename, string columnname, string condition) { var strSql = new StringBuilder(); var column = " case isnull(" + columnname + ",'') when '' then '' else " + columnname + "+',' end "; strSql.Append(" WITH TB_2 AS ( "); strSql.Append(" SELECT " + column + " as " + columnname + " ,CHARINDEX(','," + column + ") STA,CHARINDEX(','," + column + ")-1 LENS FROM " + tablename + " where 1=1 "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" and " + condition); } strSql.Append(" UNION ALL "); strSql.Append(" SELECT " + columnname + " ,CHARINDEX(','," + columnname + ",STA+1) STA,CHARINDEX(','," + columnname + ",STA+1)-STA-1 LENS FROM TB_2 WHERE STA<>0) "); strSql.Append(" SELECT distinct SUBSTRING(" + columnname + ",STA-LENS,LENS) VALUE,count(SUBSTRING(" + columnname + ",STA-LENS,LENS)) count FROM TB_2 "); strSql.Append(" WHERE STA<>0 "); strSql.Append(" group by SUBSTRING(" + columnname + ",STA-LENS,LENS) "); strSql.Append(" order by count(SUBSTRING(" + columnname + ",STA-LENS,LENS)) DESC "); return SetCommaWord(strSql); } private static List SetCommaWord(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { DICModel data = new DICModel(); #region Set DB data to Object data.KEYFIELD = (reader["VALUE"] == null ? "" : Convert.ToString(reader["VALUE"]));//惟一值 data.VALUEFIELD = (reader["count"] == null ? "" : Convert.ToString(reader["count"]));//惟一值 #endregion headList.Add(data); } #region 空白项 DICModel data2 = new DICModel(); data2.KEYFIELD = "";//惟一值 data2.VALUEFIELD = "0";//惟一值 #endregion headList.Add(data2); reader.Close(); } return headList; } //符合条件的表、字段中,实际已存在的用逗号隔开的部分,是否包含指定文字; /// /// 符合条件的表、字段中,实际已存在的用逗号隔开的部分,是否包含指定文字; /// /// /// /// /// /// static public bool GetCommaWordExist(string tablename, string columnname, string ExistValue, string condition) { var _list = GetCommaWord(tablename, columnname, condition); if (_list.Count() == 0) { return false; } else { foreach (var item in _list) { if (item.KEYFIELD == ExistValue.Trim()) { return true; } } return false; } } #endregion #region 将逗号隔开的字符串 转化成:1 string[];2:用于sql的带单引号string;3:一个stringList 并按字母顺序排序 public static string[] getStringArray(string str, char splitword = ',') { var stringlist = str.Split(splitword); return stringlist; } public static string getSqlString(string str, char splitword = ',') { var stringlist = str.Split(splitword); var result = ""; foreach (var item in stringlist) { if (result != "") result += ","; result += "'" + item + "'"; } return result; } public static List getStrListfromCommaStr(string str, char splitword = ',') { var stringlist = str.Split(splitword).ToList(); stringlist.OrderBy(o => o.ToString()); return stringlist; } #endregion #region 判断字符串中是否包含中文 /// /// 判断字符串中是否包含中文 /// /// 需要判断的字符串 /// 判断结果 public static bool isHasChinese(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"[\u4e00-\u9fa5]"); } #endregion #region 直接DelCtnDetailList执行sql命令(小心使用) static public int ExecSql(string StrSql) { Database db = DatabaseFactory.CreateDatabase(); var _count = -1; try { _count = db.ExecuteNonQuery(CommandType.Text, StrSql); } catch { return _count; } return _count; } static public int ExecSql_DB(string StrSql, string DBNAME = "") { Database db = DatabaseFactory.CreateDatabase(DBNAME); var _count = db.ExecuteNonQuery(CommandType.Text, StrSql); return _count; } static public int ExecSql(SqlCommand StrSqlComm) { Database db = DatabaseFactory.CreateDatabase(); var _count = db.ExecuteNonQuery(StrSqlComm); return _count; } #endregion #region 返回实体类的属性名与列表 public static List getProperties(T t) { var tStr = new List(); if (t == null) { return tStr; } System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); if (properties.Length <= 0) { return tStr; } foreach (System.Reflection.PropertyInfo item in properties) { string name = item.Name; object value = item.GetValue(t, null); if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String")) { var _sl = new FieldModel(); _sl.FieldName = name; if (value != null) { _sl.FieldValue = value.ToString(); } tStr.Add(_sl); //tStr += string.Format("{0}:{1},", name, value); } else { //getProperties(value); } } return tStr; } #endregion #region 获取 InfoClass管理分类表 static public List GetMsInfoClass(string strCondition, string strUserID) { var strSql = new StringBuilder(); strSql.Append("select * from InfoClass where 1=1"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" order by sortID"); return SetMsInfoClass(strSql); } private static List SetMsInfoClass(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsInfoClassEntity data = new MsInfoClassEntity(); #region Set DB data to Object data.ID = (reader["ID"] == null ? 0 : Convert.ToInt32(reader["ID"])); data.PARENTID = (reader["PARENTID"] == null ? "" : Convert.ToString(reader["PARENTID"])); data.CLASSID = (reader["CLASSID"] == null ? "" : Convert.ToString(reader["CLASSID"])); data.CLASSNAMEENG = (reader["CLASSNAMEENG"] == null ? "" : Convert.ToString(reader["CLASSNAMEENG"])); data.CLASSNAME = (reader["CLASSNAME"] == null ? "" : Convert.ToString(reader["CLASSNAME"])); data.CLASSICON = (reader["CLASSICON"] == null ? "" : Convert.ToString(reader["CLASSICON"])); data.CLASSKEY = (reader["CLASSKEY"] == null ? "" : Convert.ToString(reader["CLASSKEY"])); data.CLASSLOCATION = (reader["CLASSLOCATION"] == null ? 0 : Convert.ToInt32(reader["CLASSLOCATION"])); data.CLASSATTRIB = (reader["CLASSATTRIB"] == null ? 0 : Convert.ToInt32(reader["CLASSATTRIB"])); data.HASCHILD = (reader["HASCHILD"] == null ? false : Convert.ToBoolean(reader["HASCHILD"])); data.ISUSED = (reader["ISUSED"] == null ? false : Convert.ToBoolean(reader["ISUSED"])); data.ISSORT = (reader["ISSORT"] == null ? false : Convert.ToBoolean(reader["ISSORT"])); data.SORTATTRIB = (reader["SORTATTRIB"] == null ? false : Convert.ToBoolean(reader["SORTATTRIB"])); data.SORTID = (reader["SORTID"] == null ? 0 : Convert.ToInt32(reader["SORTID"])); data.AUTHOR = (reader["AUTHOR"] == null ? "" : Convert.ToString(reader["AUTHOR"])); data.CREATEDATE = Convert.ToDateTime(reader["CREATEDATE"]); data.LASTMODIFYDATE = Convert.ToDateTime(reader["LASTMODIFYDATE"]); data.DEL_SIGN = (reader["DEL_SIGN"] == null ? false : Convert.ToBoolean(reader["DEL_SIGN"])); #endregion headList.Add(data); } #region 空白项 MsInfoClassEntity data2 = new MsInfoClassEntity(); data2.ID = 0; data2.PARENTID = ""; data2.CLASSID = ""; data2.CLASSNAMEENG = ""; data2.CLASSNAME = ""; data2.CLASSICON = ""; data2.CLASSKEY = ""; data2.CLASSLOCATION = 0; data2.CLASSATTRIB = 0; data2.HASCHILD = false; data2.ISUSED = false; data2.ISSORT = false; data2.SORTATTRIB = false; data2.SORTID = 0; data2.AUTHOR = ""; data2.CREATEDATE = DateTime.Now; data2.LASTMODIFYDATE = DateTime.Now; data2.DEL_SIGN = false; #endregion headList.Add(data2); reader.Close(); } return headList; } #endregion #region 获取 客户子项目 static public List GetMsInfoClientItem(string strCondition, string strUserID) { var strSql = new StringBuilder(); strSql.Append("select * from info_client_item where 1=1"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetMsInfoClientItem(strSql); } private static List SetMsInfoClientItem(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsInfoClientItemEntity data = new MsInfoClientItemEntity(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//惟一值 data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//客户GID data.ITEMNAME = (reader["ITEMNAME"] == null ? "" : Convert.ToString(reader["ITEMNAME"]));//项目名称 data.STARTTIME = Convert.ToDateTime(reader["STARTTIME"]);//起始时间 data.ENDTIME = Convert.ToDateTime(reader["ENDTIME"]);//结束时间 data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人gid data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间 data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更改时间 #endregion headList.Add(data); } #region 空白项 MsInfoClientItemEntity data2 = new MsInfoClientItemEntity(); data2.GID = "";//惟一值 data2.LINKGID = "";//客户GID data2.ITEMNAME = "";//项目名称 data2.STARTTIME = DateTime.Now;//起始时间 data2.ENDTIME = DateTime.Now;//结束时间 data2.CREATEUSER = "";//创建人gid data2.CREATETIME = DateTime.Now;//创建时间 data2.MODIFIEDUSER = "";//更改操作人gid data2.MODIFIEDTIME = DateTime.Now;//最后一次更改时间 #endregion headList.Add(data2); reader.Close(); } return headList; } #endregion #region 良通捷运 目的地列表 static public List GetDetiNation_LTJY(string strCondition, string strUserID) { var strSql = new StringBuilder(); strSql.Append("select DISTINCT NAME,DISTANCE from PC_LTJY_Distance where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetDetiNation_LTJY(strSql); } private static List SetDetiNation_LTJY(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { DICModel data = new DICModel(); #region Set DB data to Object data.KEYFIELD = (reader["NAME"] == null ? "" : Convert.ToString(reader["NAME"]));//惟一值 data.VALUEFIELD = (reader["DISTANCE"] == null ? "" : Convert.ToString(reader["DISTANCE"]));//惟一值 #endregion headList.Add(data); } #region 空白项 DICModel data2 = new DICModel(); data2.KEYFIELD = "";//惟一值 data2.VALUEFIELD = "0";//惟一值 #endregion headList.Add(data2); reader.Close(); } return headList; } #endregion #region 国家 static public List GetCountryList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("select distinct c_country_code+'-'+c_country_name as CodeAndName,c_country_code CountryCode,c_country_name CountryName,c_country_ename CountryNameEn from t_sys_country_code where 1=1"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetCountryData(strSql.ToString()); } private static List SetCountryData(string sql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql)) { while (reader.Read()) { CangDanCountry data = new CangDanCountry(); #region Set DB data to Object data.CountryName = Convert.ToString(reader["CountryName"]); data.CountryNameEn = Convert.ToString(reader["CountryNameEn"]); data.CountryCode = Convert.ToString(reader["CountryCode"]); data.CodeAndName = Convert.ToString(reader["CodeAndName"]); #endregion headList.Add(data); } } return headList; } #endregion #region 逻辑信息子表操作 #region 将一个dictionary转化为用;;和::隔开的文本 public static string DicToStr(Dictionary dic) { var result = ""; foreach (var item in dic) { result += item.Key + "::" + item.Value + ";;"; } return result; } #endregion #region 将一个用;;和::隔开的文本转化为dictionary public static Dictionary StrToDic(string dicstr) { var result = new Dictionary(); var list = Regex.Split(dicstr, ";;").ToList(); foreach (var item in list) { var itemarray = Regex.Split(item, "::"); if (itemarray.Length < 2) continue; result.Add(itemarray[0], itemarray[1] == null ? "" : itemarray[1]); } return result; } #endregion public static Dictionary GetLogicInfo(string BSNO, string PROPNAME) { CommonDataContext cdc = new CommonDataContext(); var result = new Dictionary(); var infoList = cdc.OP_LOGICINFO.Where(x => x.BSNO == BSNO && x.PROPNAME == PROPNAME).ToList(); if (infoList != null && infoList.Count > 0) { result = StrToDic(infoList[0].PROPVALUE); } return result; } public static void SaveLogicInfo(string BSNO, string PROPNAME, Dictionary InfoDic) { CommonDataContext cdc = new CommonDataContext(); var result = new Dictionary(); var infoList = cdc.OP_LOGICINFO.Where(x => x.BSNO == BSNO && x.PROPNAME == PROPNAME).ToList(); if (infoList != null && infoList.Count > 0) { infoList[0].PROPVALUE = DicToStr(InfoDic); } else { var newinfo = new OP_LOGICINFO_md(); newinfo.GID = Guid.NewGuid(); newinfo.BSNO = BSNO; newinfo.PROPNAME = PROPNAME; newinfo.PROPVALUE = DicToStr(InfoDic); cdc.OP_LOGICINFO.Add(newinfo); cdc.SaveChanges(); } } #endregion #region SaveLog public static ContentResult SaveLog(List data, string USERID, string NAME, string LOGTYPE) { var headData = new Sys_Logmd();//JsonConvert.Deserialize(data); headData.GID = System.Guid.NewGuid().ToString(); headData.NAME = NAME; headData.LOGTYPE = LOGTYPE; headData.LOGTIME = System.DateTime.Now.ToString(); headData.CREATEUSER = USERID; headData.LOGCONTENT = ""; foreach (var _F in data) { headData.LOGCONTENT += string.Format("{0}:{1},", _F.FieldName, _F.FieldValue); } headData.DbOperationType = DbOperationType.DbotIns; headData.ModelUIStatus = "I"; var result = new DBResult(); var modb = new ModelObjectRepository(); result = modb.Save(headData); //刷新父窗口上的父节点 var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, //Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'") }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public static ContentResult SaveLog(T t, string USERID, string NAME, string LOGTYPE) { var _FieldList = getProperties(t); return SaveLog(_FieldList, USERID, NAME, LOGTYPE); } public static ContentResult SaveLog(List t, string USERID, string NAME, string LOGTYPE) { var _r = new ContentResult(); foreach (var item in t) { var _FieldList = getProperties(item); _r = SaveLog(_FieldList, USERID, NAME, LOGTYPE); } return _r; } public static ContentResult SaveLog(string data, string USERID, string NAME, string LOGTYPE) { var headData = new Sys_Logmd();//JsonConvert.Deserialize(data); headData.GID = System.Guid.NewGuid().ToString(); headData.NAME = NAME; headData.LOGTYPE = LOGTYPE; headData.LOGTIME = System.DateTime.Now.ToString(); headData.CREATEUSER = USERID; //headData.LOGCONTENT = ""; headData.LOGCONTENT = data; headData.DbOperationType = DbOperationType.DbotIns; headData.ModelUIStatus = "I"; var result = new DBResult(); var modb = new ModelObjectRepository(); result = modb.Save(headData); //刷新父窗口上的父节点 var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, //Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'") }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion #region 读取指定文件 然后将其写入指定表的指定字段(image字段) public static DBResult SaveFileIntoDB(FileUrlModel FileInfo, string filename) { DBResult _r = new DBResult(); _r.Success = false; var _filename = HttpContext.Current.Server.MapPath(filename); if (File.Exists(_filename)) { //var file = File.Open(filename, FileMode.Open); byte[] bytes = File.ReadAllBytes(_filename); SqlCommand cmd = new SqlCommand(string.Format("update {0} set {1} =@image where {2}='{3}'", FileInfo.TableName, FileInfo.ImgName, FileInfo.KeyName, FileInfo.KeyValue)); cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes; var _c = ExecSql(cmd); if (_c > 0) { _r.Success = true; } else { } return _r; } else { _r.Message = "不存在指定文件"; return _r; } } public static DBResult DelFileFromDB(FileUrlModel FileInfo) { DBResult _r = new DBResult(); _r.Success = false; byte[] bytes = new byte[0]; SqlCommand cmd = new SqlCommand(string.Format("update {0} set {1} =@image where {2}='{3}'", FileInfo.TableName, FileInfo.ImgName, FileInfo.KeyName, FileInfo.KeyValue)); cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes; var _c = ExecSql(cmd); if (_c > 0) { _r.Success = true; } else { } return _r; } #endregion #region 传入IDataReader 和字段名 和返回值类型 public static object getValue(IDataReader reader, string fieldname, string type) { reader.GetSchemaTable().DefaultView.RowFilter = "ColumnName= '" + fieldname + "'"; if (reader.GetSchemaTable().DefaultView.Count > 0) { var _r = reader[fieldname]; if (_r != DBNull.Value) return _r; } return null; } #endregion #region 通过USERID/或者user.showname 获取邮箱和QQ public static string GetPhoneWithUserId(string USERID, out string email, out string qq) { string sql = "select officephone,EMAIL1,QQ from user_baseinfo where (userid = '" + USERID + "' or userid in(select userid from vw_user where showname= '" + USERID + "') ) "; Database db = DatabaseFactory.CreateDatabase(); string phone = ""; email = ""; qq = ""; using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql)) { while (reader.Read()) { phone = reader["officephone"].ToString(); email = reader["EMAIL1"].ToString(); qq = reader["QQ"].ToString(); } reader.Close(); } return phone; } #endregion #region 查看reader中是否存在字段 bool public static bool ReadFieldExist(IDataReader reader, string Fieldname) { reader.GetSchemaTable().DefaultView.RowFilter = "ColumnName= '" + Fieldname + "'"; if (reader.GetSchemaTable().DefaultView.Count > 0) return true; else return false; //try //{ // var index = reader.GetOrdinal(Fieldname); // if (index > -1) // return true; // else return false; //} //catch { // return false; //} } public object getRowValue(DataColumnCollection Columns, DataRow row, string fieldname) { if (Columns.Contains(fieldname)) return row[fieldname]; else return ""; } #endregion /// /// 将Excel单表转为Datatable /// /// /// /// /// /// public static DataTable ExcelToDatatable(Stream stream, string fileType, out string strMsg, string sheetName = null) { strMsg = ""; DataTable dt = new DataTable(); ISheet sheet = null; IWorkbook workbook = null; try { #region 判断excel版本 //2007以上版本excel if (fileType == ".xlsx") { workbook = new XSSFWorkbook(stream); //workbook = WorkbookFactory.Create(stream); } //2007以下版本excel else if (fileType == ".xls") { workbook = new HSSFWorkbook(stream); } else { throw new Exception("传入的不是Excel文件!"); } #endregion if (!string.IsNullOrEmpty(sheetName)) { sheet = workbook.GetSheet(sheetName); if (sheet == null) { sheet = workbook.GetSheetAt(0); } } else { sheet = workbook.GetSheetAt(0); } if (sheet != null) { IRow firstRow = sheet.GetRow(0); int cellCount = firstRow.LastCellNum; for (int i = firstRow.FirstCellNum; i < cellCount; i++) { ICell cell = firstRow.GetCell(i); if (cell != null) { string cellValue = cell.StringCellValue.Trim(); if (!string.IsNullOrEmpty(cellValue)) { DataColumn dataColumn = new DataColumn(cellValue); dt.Columns.Add(dataColumn); } } } DataRow dataRow = null; //遍历行 for (int j = sheet.FirstRowNum + 1; j <= sheet.LastRowNum; j++) { IRow row = sheet.GetRow(j); dataRow = dt.NewRow(); if (row == null || row.FirstCellNum < 0) { continue; } //遍历列 for (int i = row.FirstCellNum; i < cellCount; i++) { ICell cellData = row.GetCell(i); if (cellData != null && cellData.ToString() != "") { //判断是否为数字型,必须加这个判断不然下面的日期判断会异常 if (cellData.CellType == CellType.Numeric) { //判断是否日期类型 if (DateUtil.IsCellDateFormatted(cellData)) { dataRow[i] = cellData.DateCellValue; } else { dataRow[i] = cellData.ToString().Trim(); } } else { dataRow[i] = cellData.ToString().Trim(); } } else { dataRow[i] = Guid.NewGuid().ToString(); } } dt.Rows.Add(dataRow); } } else { throw new Exception("没有获取到Excel中的数据表!"); } } catch (Exception ex) { workbook = new HSSFWorkbook(stream); strMsg = ex.Message; } return dt; } #region 解析BC的pdf文档 public static DataTable ExcelToDatatable_2(Stream stream, string fileType, out string strMsg, string sheetName = null) { strMsg = ""; DataTable dt = new DataTable(); ISheet sheet = null; IWorkbook workbook = null; try { #region 判断excel版本 //2007以上版本excel if (fileType == ".xlsx") { workbook = new XSSFWorkbook(stream); //workbook = WorkbookFactory.Create(stream); } //2007以下版本excel else if (fileType == ".xls") { workbook = new HSSFWorkbook(stream); } else { throw new Exception("传入的不是Excel文件!"); } #endregion if (!string.IsNullOrEmpty(sheetName)) { sheet = workbook.GetSheet(sheetName); if (sheet == null) { sheet = workbook.GetSheetAt(0); } } else { sheet = workbook.GetSheetAt(0); } if (sheet != null) { IRow firstRow = sheet.GetRow(sheet.FirstRowNum); int cellCount = firstRow.LastCellNum; for (int i = firstRow.FirstCellNum; i < cellCount; i++) { ICell cell = firstRow.GetCell(i); if (cell != null) { string cellValue = cell.StringCellValue.Trim(); if (!string.IsNullOrEmpty(cellValue)) { DataColumn dataColumn = new DataColumn(cellValue); dt.Columns.Add(dataColumn); } else { DataColumn dataColumn = new DataColumn(Guid.NewGuid().ToString()); dt.Columns.Add(dataColumn); } } } DataRow dataRow = null; //遍历行 for (int j = sheet.FirstRowNum + 1; j <= sheet.LastRowNum; j++) { IRow row = sheet.GetRow(j); dataRow = dt.NewRow(); if (row == null || row.FirstCellNum < 0) { continue; } //遍历列 for (int i = row.FirstCellNum; i < cellCount; i++) { ICell cellData = row.GetCell(i); if (cellData != null && cellData.ToString() != "") { //判断是否为数字型,必须加这个判断不然下面的日期判断会异常 if (cellData.CellType == CellType.Numeric) { //判断是否日期类型 if (DateUtil.IsCellDateFormatted(cellData)) { dataRow[i] = cellData.DateCellValue; } else { dataRow[i] = cellData.ToString().Trim(); } } else { dataRow[i] = cellData.ToString().Trim(); } } else { try { //dataRow[i] = Guid.NewGuid().ToString(); dataRow[i] = ""; } catch (Exception e) { } } } dt.Rows.Add(dataRow); } } else { throw new Exception("没有获取到Excel中的数据表!"); } } catch (Exception ex) { workbook = new HSSFWorkbook(stream); strMsg = ex.Message; } return dt; } public static string PDFTOEXCEL(string FileName) { try { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(FileName); var fullname = FileName + ".xlsx"; pdf.SaveToFile(fullname, Spire.Pdf.FileFormat.XLSX); pdf.Close(); return fullname; //return _webResponse.OK(fullname); } catch (Exception e) { //return _webResponse.Error(e.Message); SaveLog(e.Message, "", "PDF转Excel", ""); return ""; } } public class 船名航次 { public string 船名 { get; set; } public string 航次 { get; set; } public string ETD { get; set; } public string ETA { get; set; } public 船名航次() { } public 船名航次(string vessel, string voyno, string etd = "", string eta = "") { 船名 = vessel; 航次 = voyno; ETD = etd; ETD = eta; } } public class BC_ExcelInfo { protected List<船名航次> InfoList { get; set; } protected DataTable dt { get; set; } public BC_ExcelInfo() { InfoList = new List<船名航次>(); } protected string ErrorMsg { get; set; } protected FileStream fs { get; set; } public void Get_Info(string pdffile, int firstrow = 0) { var newfilename = PDFTOEXCEL(pdffile); using (fs = new FileStream(newfilename, FileMode.Open)) { int len = (int)fs.Length; byte[] buf = new byte[len]; //文件流读入图像数据 fs.Read(buf, 0, len); //创建内存流对象 //MemoryStream ms = new MemoryStream(); //图像数据由文件流写入内存流 //ms.Write(buf, 0, len); fs.Seek(0, SeekOrigin.Begin); var _ErrorMsg = ""; dt = ExcelToDatatable_2(fs, ".xlsx", out _ErrorMsg); ErrorMsg = _ErrorMsg; } } public void Set_Info() { } public string GetValue(string fieldname) { if (fieldname == "船名") { if (InfoList.Count > 0) { return InfoList[0].船名; } else { return ""; } } if (fieldname == "航次") { if (InfoList.Count > 0) { return InfoList[0].航次; } else { return ""; } } if (fieldname == "ETD") { if (InfoList.Count > 0) { return InfoList[0].ETD; } else { return ""; } } if (fieldname == "ETA") { if (InfoList.Count > 0) { return InfoList[0].ETA; } else { return ""; } } return ""; } protected bool 行存在某文本(DataRow dr, string str) { for (int i = 0; i < dt.Columns.Count; i++) { var columnvalue = dr[i].ToString(); if (columnvalue.Contains(str)) { return true; } } return false; } protected int 行序号(DataRow dr, string str) { for (int i = 0; i < dt.Columns.Count; i++) { var columnvalue = dr[i].ToString(); if (columnvalue.Contains(str)) { return i; } } return 0; } } public class 中远BC_ExcelInfo : BC_ExcelInfo { private string 船名name = "Vessel Name"; private string 航次name = "Voyage"; private string nullname = "待定"; private string 结束name = "请注意:"; private string ETDname = "ETD"; private string ETAname = "ETA"; private int 船名列 = 4; private int 航次列 = 7; private int ETD列 = 7; private int ETA列 = 7; public 中远BC_ExcelInfo(string pdffile) { Get_Info(pdffile, 19); Set_Info(); } public string BC船名 { get { if (InfoList.Count > 0) { return InfoList[0].船名; } else { return ""; } } } public string BC航次 { get { if (InfoList.Count > 0) { return InfoList[0].航次; } else { return ""; } } } public void Set_Info() { if (dt.Rows.Count > 0) { for (var line = 0; line < dt.Rows.Count; line++) { DataRow dr = dt.Rows[line]; for (int i = 0; i < dt.Columns.Count; i++) { var columnvalue = dr[i].ToString(); if (columnvalue.Contains(船名name)) { //下面一行就是产品开始行 产品行数+1 var _船名航次行数 = 1; var 船名航次行 = dt.Rows[line + _船名航次行数]; 船名列 = 行序号(dr, 船名name); 航次列 = 行序号(dr, 航次name); ETD列 = 行序号(dr, ETDname); ETA列 = 行序号(dr, ETAname); //再看它下面一行是否有备注名 如果有 那这行也是结束行 同时记录备注 //否则再下一行 同时产品行数+1 while (!行存在某文本(船名航次行, 结束name)) { //var 行文本List = new List(); var item = new 船名航次(船名航次行[船名列].ToString() , 船名航次行[航次列].ToString() , 船名航次行[ETD列].ToString() , 船名航次行[ETA列].ToString() ); if (item.船名 != nullname && !string.IsNullOrWhiteSpace(item.船名)) { InfoList.Add(item); } _船名航次行数++; 船名航次行 = dt.Rows[line + _船名航次行数]; } return; } } } } else { } } } public class 马士基BC_ExcelInfo : BC_ExcelInfo { private string 船名name = "Vessel"; private string 航次name = "Voy No."; private string nullname = ""; private string 结束name = "this booking confirmation is subject to"; private string ETDname = "ETD"; private string ETAname = "ETA"; private int 船名列 = 17; private int 航次列 = 24; private int ETD列 = 7; private int ETA列 = 7; public 马士基BC_ExcelInfo(string pdffile) { Get_Info(pdffile, 19); Set_Info(); } public void Set_Info() { try { if (dt.Rows.Count > 0) { for (var line = 0; line < dt.Rows.Count; line++) { DataRow dr = dt.Rows[line]; for (int i = 0; i < dt.Columns.Count; i++) { var columnvalue = dr[i].ToString(); if (行存在某文本(dr, 船名name) && 行存在某文本(dr, ETDname)) { try { //下面一行就是产品开始行 产品行数+1 var _船名航次行数 = 1; var 船名航次行 = dt.Rows[line + _船名航次行数]; 船名列 = 行序号(dr, 船名name); 航次列 = 行序号(dr, 航次name); ETD列 = 行序号(dr, ETDname); ETA列 = 行序号(dr, ETAname); //再看它下面一行是否有备注名 如果有 那这行也是结束行 同时记录备注 //否则再下一行 同时产品行数+1 while (!行存在某文本(船名航次行, 结束name)) { //var 行文本List = new List(); var item = new 船名航次(船名航次行[船名列].ToString() , 船名航次行[航次列].ToString() , 船名航次行[ETD列].ToString() , 船名航次行[ETA列].ToString() ); if (item.船名 != nullname && !string.IsNullOrWhiteSpace(item.船名)) { InfoList.Add(item); } _船名航次行数++; 船名航次行 = dt.Rows[line + _船名航次行数]; } } catch (Exception e) { SaveLog(e.Message, "", "BS解析", "马士基BC"); } finally { } return; } } } } else { } } catch (Exception e) { SaveLog(e.Message, "", "BS解析", "马士基BC"); } } } #endregion /// /// 接口类:分页查询语句的查询条件 /// strSql,strCondition,rangestr,sortstring,defaultsortstr,start,limit /// public class PagedQuaryParam { public string strSql { get; set; } public string strCondition { get; set; } public string rangestr { get; set; } public string sortstring { get; set; } public string defaultsortstr { get; set; } public int start { get; set; } public int limit { get; set; } } /// /// 分页查询语句 /// /// /// strSql查询语句必须以where 1=1 结尾 。 /// public static StringBuilder PagedQuaryStr(PagedQuaryParam PagedQuaryParam) { var result = new StringBuilder(); result.Append(@"SELECT * from (SELECT row_number() over ("); if (!string.IsNullOrEmpty(PagedQuaryParam.sortstring)) { result.Append(" order by " + PagedQuaryParam.sortstring); } else { result.Append(" order by " + PagedQuaryParam.defaultsortstr); } result.Append(@") as num , * from ("); result.Append(PagedQuaryParam.strSql); if (!string.IsNullOrEmpty(PagedQuaryParam.strCondition)) { result.Append(" and " + PagedQuaryParam.strCondition); } if (!string.IsNullOrEmpty(PagedQuaryParam.rangestr)) { result.Append(" and " + PagedQuaryParam.rangestr); } result.Append(@")as t )as t2 "); result.Append(string.Format(" where t2.num>{0} and t2.num<={1} ", PagedQuaryParam.start, PagedQuaryParam.start + PagedQuaryParam.limit)); // return result; } public static int PagedCount(PagedQuaryParam PagedQuaryParam) { var result = 0; StringBuilder sqlstr = new StringBuilder(); sqlstr.Append(@"SELECT count(*) _count from ( "); sqlstr.Append(PagedQuaryParam.strSql); if (!string.IsNullOrEmpty(PagedQuaryParam.strCondition)) { sqlstr.Append(" and " + PagedQuaryParam.strCondition); } if (!string.IsNullOrEmpty(PagedQuaryParam.rangestr)) { sqlstr.Append(" and " + PagedQuaryParam.rangestr); } sqlstr.Append(@") as t "); Database db = DatabaseFactory.CreateDatabase(); try { using (IDataReader reader = db.ExecuteReader(CommandType.Text, sqlstr.ToString())) { while (reader.Read()) { result = (reader["_count"] == null ? 0 : Convert.ToInt32(reader["_count"])); } //#region 空白项 //DICModel data2 = new DICModel(); //data2.KEYFIELD = "";//惟一值 //data2.VALUEFIELD = "0";//惟一值 //#endregion //headList.Add(data2); reader.Close(); } } catch { } return result; } #region 获取数据表数据的刷新时间 以供前台决定是否更新表 以及刷新mainform上面的store //此处只有第一次被读取时才读取数据库 之后都是直接返回内存数值 //setnew方法更新某个表名的刷新时间时,会同时更新内存内的刷新时间 //但是如果新增一种表名的话,需要重新启动网站服务,否则内存表内容无法添加。 public static List GetTableStatusList() { try { if (StoreModifyStatusMb.StoreModifyStatusList == null || StoreModifyStatusMb.StoreModifyStatusList.Count == 0) { ResetStoreModifyStatus(); } else { //var _result = SetStoreModifyStatus(StoreModifyStatusMb.getSql()); //StoreModifyStatusMb.setList(_result); //return getSql } return StoreModifyStatusMb.getstatus(); } catch (Exception e) { SaveLog(e.Message, "", "提前缓存表", "GetTableStatusList"); ResetStoreModifyStatus(); return StoreModifyStatusMb.getstatus(); } } public static object GetStoreModifyStatusCache() { System.Web.Caching.Cache objCache = HttpRuntime.Cache; return objCache["StoreModifyStatus"]; } public static void SetStoreModifyStatusCache(List StoreModifyStatusMb) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; //objCache.Remove("StoreModifyStatus"); objCache.Insert("StoreModifyStatus", StoreModifyStatusMb); } /// /// 更新公共store的刷新时间 /// /// /// public static DBResult PubStore_SetNew(string TABLENAME) { return StoreStatus_SetTime(TABLENAME); } public static DBResult StoreStatus_SetTime(string TABLENAME) { try { DBResult result = new DBResult(); if (StoreModifyStatusMb.StoreModifyStatusList.Exists(t => t.TABLENAME == TABLENAME)) { var modb = new ModelObjectDB(); var _tlist = StoreModifyStatusMb.StoreModifyStatusList.FindAll(t => t.TABLENAME == TABLENAME); foreach (var _t in _tlist) { _t.MODIFIEDTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); _t.DbOperationType = DbOperationType.DbotUpd; _t.ModelUIStatus = "E"; _t.PubStoreList.Clear(); result = modb.Save(_t); } return result; } else { var er = new DBResult(false, "没有该表名的配置信息", null); return er; } } catch (Exception e) { SaveLog(e.Message, "", "提前缓存表", "StoreStatus_SetTime"); BasicDataRefDAL.ResetStoreModifyStatus(); return StoreStatus_SetTime(TABLENAME); } } private static List SetStoreModifyStatus(string strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); try { using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { StoreModifyStatusMb data = new StoreModifyStatusMb(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"])); data.TABLENAME = (reader["TABLENAME"] == null ? "" : Convert.ToString(reader["TABLENAME"])); data.STORENAME = (reader["STORENAME"] == null ? "" : Convert.ToString(reader["STORENAME"])); data.DISPLAYFIELD = (reader["DISPLAYFIELD"] == null ? "" : Convert.ToString(reader["DISPLAYFIELD"])); data.VALUEFIELD = (reader["VALUEFIELD"] == null ? "" : Convert.ToString(reader["VALUEFIELD"])); data.DISPLAYFIELD2 = (reader["DISPLAYFIELD2"] == null ? "" : Convert.ToString(reader["DISPLAYFIELD2"])); data.CONDITION = (reader["CONDITION"] == null ? "" : Convert.ToString(reader["CONDITION"])); data.MODIFIEDTIME = (reader["MODIFIEDTIME"] == null ? "" : Convert.ToString(reader["MODIFIEDTIME"])); #endregion headList.Add(data); } //#region 空白项 //DICModel data2 = new DICModel(); //data2.KEYFIELD = "";//惟一值 //data2.VALUEFIELD = "0";//惟一值 //#endregion //headList.Add(data2); reader.Close(); } } catch (Exception e) { SaveLog(e.Message, "", "提前缓存表", "SetStoreModifyStatus"); } return headList; } public static void ResetStoreModifyStatus() { var _list = SetStoreModifyStatus(StoreModifyStatusMb.getSql()); SetStoreModifyStatusCache(_list); //StoreModifyStatusMb.setList(_list); } static public List getPubExtendStore(string strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); string sql = strSql.ToString(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { ////根据字段名设定同名属性值 PubStoremb data = new PubStoremb(); data.SetExtendValue(reader); headList.Add(data); } reader.Close(); } if (headList.Count > 0) { var Model = headList[0]; PubStoremb data0 = new PubStoremb(); data0.SetExtendValue_Null(Model.ExtendDic); headList.Insert(0, data0); } return headList; } #endregion #region 判断用户是否已登陆超时 /// /// 判断用户是否已登陆超时 /// /// /// public static DBResult CheckLogin(HttpSessionStateBase Session) { var result = new DBResult(); if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "") { var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" }; var _r = new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; result.SetErrorInfo("", false, _r); } else { result.setMessage(true, ""); } return result; } #endregion #region 多种业务使用的业务信息查询 static public List getVOPBSStore(int start, int limit, string OPLB, string condition, string sort = "") { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); PagedQuaryParam pp = new PagedQuaryParam(); pp.strSql = $" select * from v_op_bs where OPLB='{OPLB}' "; pp.start = start; pp.limit = limit; pp.strCondition = condition; pp.defaultsortstr = "CUSTNO"; pp.sortstring = sort; var strSql = PagedQuaryStr(pp); string sql = strSql.ToString(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ////根据字段名设定同名属性值 VOPBSmb data = new VOPBSmb(); data.SetExtendValue(reader); headList.Add(data); } reader.Close(); } return headList; } #endregion #region 返回程序目录下一个文件夹 如不存在则创建 public static string getPath(string FILEPATH) { var path = AppDomain.CurrentDomain.BaseDirectory + FILEPATH + @"\"; if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } else { } return path; } public static void ClearPath(string FILEPATH) { foreach (string f in Directory.GetFileSystemEntries(FILEPATH)) { if (File.Exists(f)) { //如果有子文件删除文件 File.Delete(f); } } } #endregion #region 下载指定URL的文件到指定路径,文件名为指定 public static string HttpDownloadFile(string remoteUrl, string FILEPATH, string FILENAME) { // 设置参数 HttpWebRequest request = WebRequest.Create(remoteUrl) as HttpWebRequest; //发送请求并获取相应回应数据 HttpWebResponse response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求 Stream responseStream = response.GetResponseStream(); var path = getPath(FILEPATH); string localPath = path + FILENAME; if (File.Exists(localPath)) { return localPath; } //创建本地文件写入流 Stream stream = new FileStream(localPath, FileMode.Create); byte[] bArr = new byte[1024]; int size = responseStream.Read(bArr, 0, (int)bArr.Length); while (size > 0) { stream.Write(bArr, 0, size); size = responseStream.Read(bArr, 0, (int)bArr.Length); } stream.Close(); responseStream.Close(); return localPath; } #endregion #region 通用excel上传解析 参数为control的 Request 返回值为一个数据表1转换成的datatable /// /// 通用excel上传解析 返回文件名 /// /// 目标文件夹名【需形如 /xxxx 】 默认【../../UploadFiles】 /// public static DBResult RequestExceltoDatatable(HttpRequestBase Request, out DataTable dt) { var result = new DBResult(false, ""); dt = new DataTable(); if (Request.Files.Count == 0) { result.Success = false; result.Message = "参数错误"; return result; } try { var excelfile = Request.Files[0]; string strMsg; string ext = Path.GetExtension(excelfile.FileName).ToLower(); if (ext != ".xls" && ext != ".xlsx") { result.Success = false; result.Message = "文件必须为EXCEL格式!"; return result; } dt = ExcelToDatatable(excelfile.InputStream, ext, out strMsg); if (!string.IsNullOrEmpty(strMsg)) { result.Success = false; result.Message = strMsg; return result; } else { result.Success = true; } } catch (Exception e) { result.SetErrorInfo(e.Message); } return result; } #endregion #region CheckAuthority public static Boolean CheckAuthority(string USERID, string MODNAME) { try { string sSQL = $" USERID = '{USERID}' AND ACTIONID in(select gid from [action] where NAME='{MODNAME}')"; int recordCount = new user_actionBLL().GetRecordCount(sSQL); if (recordCount > 0) return true; if (recordCount == 0) return false; } catch { return false; } return false; } #endregion #region MD5值 public static string GetMd5Hash(string str) { if (string.IsNullOrWhiteSpace(str)) { return null; } MD5 md5hash = MD5.Create(); byte[] data = md5hash.ComputeHash(Encoding.UTF8.GetBytes(str)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } return sBuilder.ToString(); } #endregion public static ContentResult GetContentResult(DBResult dbresult) { var jsonRespose = new JsonResponse { Success = dbresult.Success, Message = dbresult.Message, Data = null }; if (dbresult.Data != null) jsonRespose.Data = dbresult.Data; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public static DateTime ConvertLongToDateTime(long? d) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(d + "0000"); TimeSpan toNow = new TimeSpan(lTime); DateTime dtResult = dtStart.Add(toNow); return dtResult; } public static string ConvertToChineseMoney(double money) { if (money < 0) { throw new ArgumentOutOfRangeException($"参数 money 不能为负值!"); } string s = money.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A"); s = Regex.Replace(s, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9]) |(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))", "${b}${z}"); return Regex.Replace(s, ".", delegate (System.Text.RegularExpressions.Match m) { return "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟萬億兆京垓秭穰"[m.Value[0] - '-'].ToString(); }); } public static string ConvertToChineseMoney2(double money) { var result = ConvertToChineseMoney(money); var lastchar = result.Substring(result.Length - 1, 1); if (lastchar == "角" || lastchar == "分") { } else { result += "整"; } return result; } /// /// 海运出口的合规检验 http://60.209.125.238:32222/manage/file /// senderId:DongshengPlat ///senderName:东胜平台 ///senderKey:TTRQaHF2STczQ055S0lQV0duQTJaQVoydUpUOUlaMENaMUU2cFdJVnpVaEExOG4zVHMvcmQzL0RETWNjK2tsbjlKeDhRand6Uit4TForVzZiUmtCeURuS29XY1JKU0R0cU5QYzA0Z0l0UkE9 /// url:http://60.209.125.238:35210/api/RulesEngineManage/ExcuteWorkFlow /// /// /// /// public static DBResult RulesManage_OPSEAE(string BSNO) { var result = new DBResult(); var url= "http://60.209.125.238:35210/api/RulesEngineManage/ExcuteWorkFlow"; var head = MsOpSeaeDAL.GetData(" B.BSNO='"+BSNO+"'"); var sendobject = GetRuleObject("opseae", head); //var msg = JsonConvert.Serialize(sendobject); string rtn = WebRequestHelper.DoPost_Json(url, sendobject); var ruleresult = JsonConvert.Deserialize(rtn); var msg = ""; foreach (var detail in ruleresult.extra.detailList) { msg += detail.resultName+"\r\n"; } result.Data = ruleresult; result.OK("校验完成"); return result; } public static RulesEngineOrderBooking_Root GetRuleObject(string OPLBNAME, object _head) { var result = new RulesEngineOrderBooking_Root(); int GetInt(string str) { return string.IsNullOrWhiteSpace(str) ? 0 : Convert.ToInt32(Convert.ToDecimal(str)); } if (OPLBNAME == "opseae") { var head = (MsOpSeae)_head; var ams = MsOpSeaeEdiPortDAL.GetAmsData("BSNO='" + head.BSNO + "'"); var cdc = new CommonDataContext(); result.head.senderKey = "TTRQaHF2STczQ055S0lQV0duQTJaQVoydUpUOUlaMENaMUU2cFdJVnpVaEExOG4zVHMvcmQzL0RETWNjK2tsbjlKeDhRand6Uit4TForVzZiUmtCeURuS29XY1JKU0R0cU5QYzA0Z0l0UkE9"; result.head.gid = head.BSNO; result.head.messageType = "BUSI_RULE"; result.head.senderId = "DongshengPlat"; result.head.senderName = "东胜平台"; result.head.receiverId = "RulesEngine"; result.head.receiverName = "大简云规则引擎"; result.head.token = null; result.head.version = "1.0"; result.head.requestDate = DateTime.Now; result.head.requestAction = "CheckRule"; result.main.projectCode.Add("OCEAN_BOOKING"); var bi = new BusinessInfo(); bi.masterBlNo = head.MBLNO; bi.houseBlNo = head.HBLNO; bi.bookingNo = head.ORDERNO; bi.contrNo = head.CONTRACTNO; //result.main.businessInfo.servContrNo = head.CONTRACTNO; bi.shipperId = head.SHIPPERID; bi.consigneeId = head.CONSIGNEEID; bi.notifyPartyId = head.NOTIFYPARTYID; bi.shipper = head.SHIPPER; bi.consignee = head.CONSIGNEE; bi.notifyParty = head.NOTIFYPARTY; //.notifyPrt2 = head.no //bi.yardId = head.YARD; bi.yard = head.YARD; bi.vesselId = head.VESSELID; bi.vessel = head.VESSEL; bi.voyno = head.VOYNO; //bi.voynoIn=head.VOYNO内部航次号 bi.etd = head.ETD; bi.atd = head.ATD; bi.eta = head.ETA; bi.closingDate = head.CLOSINGDATE; bi.closeDocDate = head.CLOSEDOCDATE; //bi.closeVGMDate=head.clo 截VGM日期 bi.placeReceiptId = head.PLACERECEIPTID; bi.placeReceipt = head.PLACERECEIPT; bi.portLoadId = head.PORTLOADID; bi.portLoad = head.PORTLOAD; bi.portDischargeId = head.PORTDISCHARGEID; bi.portDischarge = head.PORTDISCHARGE; bi.placeDeliveryId = head.PLACEDELIVERYID; bi.placeDelivery = head.PLACEDELIVERY; bi.destinationId = head.DESTINATIONID; bi.destination = head.DESTINATION; bi.noBill = head.NOBILL; bi.copyNoBill = head.COPYNOBILL; bi.issueType = head.ISSUETYPE; var issutypeedicode = cdc.code_issutype_edi.FirstOrDefault(x => x.EDINAME == "DJY" && x.BLTYPE == head.ISSUETYPE); if (issutypeedicode != null && !string.IsNullOrWhiteSpace(issutypeedicode.EDICODE)) { bi.issueType = issutypeedicode.EDICODE; } bi.issueDate = head.ISSUEDATE; bi.issuePlaceId = head.ISSUEPLACEID; bi.issuePlace = head.ISSUEPLACE; bi.blfrt = head.BLFRT; bi.prepardAt = head.PREPARDAT; bi.payableAt = head.PAYABLEAT; bi.service = head.SERVICE; bi.marks = head.MARKS; bi.hsCode = head.HSCODE; bi.goodsDescription = head.GOODSNAME; bi.pkGs = GetInt(head.PKGS); bi.kindPKGs = head.KINDPKGS; bi.kGs = GetInt(head.KGS); bi.cbm = GetInt(head.CBM); bi.totalNO = head.TOTALNO; bi.cntrTotal = head.CNTRTOTAL; bi.carrierId = head.CARRIER; var edicode = cdc.code_cust_edi.FirstOrDefault(x => x.EDINAME == "DJY" && x.CUST==head.CARRIER); if (edicode != null && !string.IsNullOrWhiteSpace(edicode.EDICODE)) { bi.carrierId = edicode.EDICODE; } bi.carrier = head.CARRIER; bi.cargoId = head.CARGOID; bi.dClass = head.DCLASS; bi.dUnno = head.DUNNO; bi.dPage = head.DPAGE; bi.dLabel = head.DLABEL; bi.dLinkMan = head.LINKMAN; bi.tempId = head.TEMPID; bi.tempSet = head.TEMPSET; bi.reeferf = head.REEFERF; bi.humidity = head.HUMIDITY; bi.tempMin = head.TEMPMIN; bi.tempMax = head.TEMPMAX; bi.isContaSOC = head.ISCONTAINERSOC; bi.soRemark = ams.ORDERREMARK; bi.siRemark = ams.SIREMARK; //bi.yardRemark=head.yra场站备注 bi.compId = head.CORPID; bi.compName = head.SALECORP;//公司名称 bi.shipperName = head.MSHIPPER; bi.shipperAddr1 = ams.SHIPPERADDR1; bi.shipperAddr2 = ams.SHIPPERADDR2; bi.shipperAddr3 = ams.SHIPPERADDR3; bi.shipperCity = ams.SHIPPERCITY; bi.shipperProvice = ams.SHIPPERPROVINCE; bi.shipperPostCode = ams.SHIPPERPOSTCODE; bi.shipperCountry = ams.SHIPPERCOUNTRY; bi.shipperAttn = ams.SHIPPERATTN; bi.shipperTel = ams.SHIPPERTEL; bi.consigneeName = ams.CONSIGNEENAME; bi.consigneeAddr1 = ams.CONSIGNEEADDR1; bi.consigneeAddr2 = ams.CONSIGNEEADDR2; bi.consigneeAddr3 = ams.CONSIGNEEADDR3; bi.consigneeCity = ams.CONSIGNEECITY; bi.consigneeProvince = ams.CONSIGNEEPROVINCE; bi.consigneePostCode = ams.CONSIGNEEPOSTCODE; bi.consigneeCountry = ams.CONSIGNEECOUNTRY; bi.consigneeAttn = ams.CONSIGNEEATTN; bi.consigneeTel = ams.CONSIGNEETEL; bi.notifyPartyName = ams.NOTIFYPARTYNAME; bi.notifyPartyAddr1 = ams.NOTIFYPARTYADDR1; bi.notifyPartyAddr2 = ams.NOTIFYPARTYADDR2; bi.notifyPartyAddr3 = ams.NOTIFYPARTYADDR3; bi.notifyPartyCity = ams.NOTIFYPARTYCITY; bi.notifyPartyProvince = ams.NOTIFYPARTYPROVINCE; bi.notifyPartyPostCode = ams.NOTIFYPARTYPOSTCODE; bi.notifyPartyCountry = ams.NOTIFYPARTYCOUNTRY; bi.notifyPartyAttn = ams.NOTIFYPARTYATTN; bi.notifyPartyTel = ams.NOTIFYPARTYTEL; //bi.poNo= //bi.opid = head.OP; //bi.docid = head.DOC; bi.op = head.OP; bi.doc = head.DOC; //bi.saleId bi.sale = head.SALE; //bi.custserviceId bi.custservice = head.CUSTSERVICE; //bi.custserviceName bi.forwarder = head.FORWARDER; bi.shipAgency = head.SHIPAGENCY; bi.customsER = head.CUSTOMSER; bi.truckER = head.TRUCKER; bi.agentId = head.AGENTID; //bi.customerId=head.customerid //bi.forwarderId=head.forw //bi.shipAgencyId=head.SHIPAGENCY //bi.customsERId=head.customserid //bi.truckERId //bi.agentName=head.agen //bi.weiTo= bi.consigneeDoorAddr = ams.DOORADDR; //bi.shipperDoorAddr bi.scacCode = ams.SCACCODE; bi.itnCode = ams.ITNCODE; bi.prePardAtId = head.PREPARDATID; bi.payableAtId = head.PAYABLEAT; bi.custNo = head.CUSTNO; //bi.transportId = bi.transport = head.TRANSPORT; //bi.thirdPayAddr=ams.t //bi.yardContractTel = head.YARDTEL; //bi.yardContractEmail = ams.yard //bi.feeSelf=head.feeself //bi.laneCode = head.LANE;//航线代码 需确定如何取值 //bi.laneName = head.LANE; bi.freightPayer = ams.FREIGHTPAYER; //bi.shipperTaxNo = ams.shippertax bi.consigneeTaxNo = ams.CONSIGNEETAXNO; bi.notifyPartyTaxNo = ams.NOTIFYPARTYTAXNO; bi.isATDChangeIssueType = null; bi.isEngChinaLineBar = null; bi.isDoubleShipper = null; bi.isFCLAndLCLMix = null; bi.isMutipleGoods = false; //多品名 bi.isContaLCL=false;//是否拼箱 装运方式 if (string.IsNullOrWhiteSpace(head.BLTYPE)) { if(head.BLTYPE.IndexOf("整箱")>=0) bi.isContaLCL = false; if (head.BLTYPE.IndexOf("拼箱") >= 0) bi.isContaLCL = true; } if (!string.IsNullOrWhiteSpace(head.PORTDISCHARGEID)) { bi.portDischargeCountryNo = head.PORTDISCHARGEID.Substring(0, 2); var dischargecountry = cdc.code_country.FirstOrDefault(x => x.COUNTRYID == bi.portDischargeCountryNo); if (dischargecountry != null) { bi.portDischargeEN = dischargecountry.getCnName(); bi.portDischargeCN = dischargecountry.getCnName(); } } if (!string.IsNullOrWhiteSpace(head.TRANSPORT)) { bi.transportCountryNo = head.TRANSPORT.Substring(0, 2); var transportcountry = cdc.code_country.FirstOrDefault(x => x.COUNTRYID == bi.transportCountryNo); if (transportcountry != null) { bi.transportEN = transportcountry.getEnName(); bi.transportCN = transportcountry.getCnName(); } //bi.transportCountryNo //bi.transportEN //bi.transportCN } //result.main.businessInfo = bi; var OpCtnlist = MsOpSeaeDAL.GetBodyList("BSNO='" + head.BSNO + "'"); var OpCtnDetailList = MsOpSeaeDAL.GetOpCtnDetailList("[CTN_ID] in (select [CTN_ID] from op_ctn where BSNO='" + head.BSNO + "')"); //多品名 if (OpCtnDetailList != null && OpCtnDetailList.Count > 0) { bi.isMutipleGoods = true; //多品名 } if (OpCtnlist != null && OpCtnlist.Count > 0) { bi.contaList = new List(); foreach (var ctn in OpCtnlist) { var codectn = cdc.CODE_CTN.FirstOrDefault(x => x.CTN == ctn.CTNALL); var newcon = new ContaList { contaType = codectn.EDICODE, contaTypeName = ctn.CTNALL, teu = codectn.TEU.ToString(), contaNo = ctn.CNTRNO, sealNo = ctn.SEALNO, pkGs = ctn.PKGS, kindPKGs = ctn.KINDPKGS, kGs = ctn.KGS , cbm = ctn.CBM , tareWeight = ctn.TAREWEIGHT, contaStatus = ctn.CTNSTATUS, weighType = ctn.WEIGHTYPE, weighKGs =ctn.WEIGHKGS, weighAttn = ctn.WEIGHATTN, vgmConnCom = ctn.VGMCONNCOM, weighTel = ctn.WEIGHTEL, weighDate = ctn.WEIGHDATE, vgmAddr = ctn.VGMADDR, vgmEmail = ctn.VGMEMAIL, remark=ctn.REMARK, contaCategory=codectn.CTNSIZE=="20"?"small":"big" }; if (OpCtnDetailList != null && OpCtnDetailList.Count > 0) { newcon.cargoList = new List(); foreach (var detail in OpCtnDetailList) { var newdetail = new CargoList { pKGs = detail.PKGS, kindPKGs=detail.KINDPKGS, kGs = detail.KGS, cbm = detail.CBM, hsCode = detail.HSCODE, marks=detail.MARKS, description=detail.DESCRIPTION, remark=detail.REMARK }; newcon.cargoList.Add(newdetail); } } bi.contaList.Add(newcon); } } result.main.businessInfo = bi; } return result; } /// /// 毫秒型时间戳转datetime /// /// /// public static DateTime Timestamp2Datetime(long timestamp) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));//当地时区 var time = startTime.AddMilliseconds(timestamp); return time; } } }