You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/DAL/MsInfoClient/MsInfoClientDAL.cs

4648 lines
207 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsInfoClient;
using DSWeb.MvcShipping.Models.MsInfoClientContact;
using DSWeb.MvcShipping.Models.MsInfoContract;
using DSWeb.MvcShipping.Models.MsInfoShipper;
using DSWeb.MvcShipping.Models.MsCompanysDept;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.EntityDA;
using DSWeb.Areas.TruckMng.Models;
using System.Web;
using System.Data.SqlClient;
using System.IO;
using WebSqlHelper;
using DSWeb.Areas.CommMng.DAL;
using System.Text.RegularExpressions;
using System.Linq;
using System.Data.Common;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.Common.DB;
using DSWeb.MvcShipping.Helper;
using DSWeb.SoftMng.Model;
using DSWeb.SysMng.DAL.SysRoleTaskQuery;
using javax.xml.crypto;
using System.Web.UI.WebControls;
using com.sun.org.apache.xml.@internal.resolver.helpers;
using MimeKit;
using DSWeb.MvcShipping.Models.WMSNew;
using NPOI.SS.Formula.Functions;
using System.Data.Entity.Migrations;
using DSWeb.MvcShipping.Models.MsChFee;
using NPOI.OpenXmlFormats.Dml;
using DSWeb.Areas.OA.Models.ChfeeList;
using DSWeb.Areas.MvcShipping.Helper;
using Quartz.Util;
using DSWeb.Areas.Account.Models.Chfee_Settlement;
using DSWeb.Areas.Account.Models.BillChfeeDetail;
using DSWeb.Areas.Account.Models.ChfeeDetail;
using DSWeb.Areas.Account.Models.Chfee_do_detail;
using DSWeb.Areas.Account.Models.Chfee_Invoice;
using DSWeb.Areas.MvcShipping.DAL.MsOp_BLISSUE;
using DSWeb.Areas.MvcShipping.DB;
namespace DSWeb.MvcShipping.DAL.MsInfoClient
{
public class MsInfoClientDAL: IGetTotalCount
{
#region BillNoSet
static public List<MsClient> GetDataList(int start, int limit, string strCondition, string userid, string username, string companyid, string sort = null)
{
SysRoleTaskQueryDAL.SaveQuery(userid, "modExchangesUnit", "formInfoClientIndex", strCondition);
var rangstr = GetRangDAStr("index", userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("ACCREMARK", " (SELECT TOP 1 REMARK FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID order by BGNDATE DESC) ");
sortstring = sortstring.Replace("ACCTYPE", " (SELECT TOP 1 ACCTYPE FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ");
sortstring = sortstring.Replace("ACCMONTH", " (SELECT TOP 1 ACCMONTH FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ");
sortstring = sortstring.Replace("ALLOWAMOUNT", " (SELECT TOP 1 ALLOWAMOUNT FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ");
sortstring = sortstring.Replace("BLSTATUSREF", " BLSTATUS ");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CODENAME desc");
}
strSql.Append(@") as num , ");
strSql.Append("[GID],[CODENAME],[SHORTNAME],[DESCRIPTION],[EnFullName],[STATUS],[ADDR],[EMAIL],[WEB]");
strSql.Append(",(SELECT TOP 1 ACCTYPE FROM Info_Client_ACCDATE WHERE ENDDATE>=GETDATE() AND LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCTYPE,(SELECT TOP 1 ACCDAYS FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCDAYS");
strSql.Append(",[TEL],[FAX],[CHIEF],[SALE],[OP],[DOC],[ISCARRIER],[ISBOOKING],[ISYARD],[ISTRUCK],[ISCONTROLLER]");
strSql.Append(",[ISCUSTOM],[ISAGENT],[ISAGENTCN],[ISEXPRESS],[ISAIRLINES],[ISSHIPPER],[ISCONSIGNEE],[ISNOTIFYPARTY]");
strSql.Append(",[ISWAREHOUSE],[COUNTRY],[PROVINCE],[CITY],[CORPID],[BLCONTENT],[ISSTOP],[BillRises1],[BillRises2],INVBANK,INVADDRTEL");
strSql.Append(",[USDBillRises],[RMBBillRises],[USDMaxAmountCredit],[RMBMaxAmountCredit],[MaxAmountCredit],[STLNAME]");
strSql.Append(",[OPNAME],[OPTIME],[REMARK],[USDExchangeRate],[STLDATE],[STLFIRSTHALFDATE],[STLMIDDLEDATE],[STLDATEPJ]");
strSql.Append(",[LEVEL],[LOGINNAME],[LOGINPASSWORD],[QQ],[MSN],[MODIFIEDUSER],[MODIFIEDTIME],[ISWHARF],[ISSHIPPINGAGENT]");
strSql.Append(",[FARCODE],[FAPCODE],[ISINSURE],[ISLEASING],[ISTRADINGAGENCY],[ISOTHER],[OTHERS],[UNITPRICE],[REGISTRATIONNO]");
strSql.Append(",[ORDERNO],[ISENTERP],[TAXNO],[EDICODE],[EDICODE2],[EDICODE3],[ORGANIZATIONCODE],CODENAME + '-' + SHORTNAME AS CodeAndName");
strSql.Append(",PCORPNAME,InspectionNo,[ISSHIPAGENCY],ISSP,FEEFRT,BSSOURCE,BLSTATUS,SALECORPID,TICHENG,FENCHENG,TICHENGCANYU");
strSql.Append(",(select EnumValueName from tSysEnumValue where enumtypeid=99024 and enumvalueid=blstatus) BLSTATUSREF");
strSql.Append(",RCVMode,[CUSTTYPE],[CUSTGUIMO],[CUSTCLASS],[QUALIFICATION],[REGDATE],[CARGOL],[PRODUCT],[EXPREGION],[CARRIERLIST],[CTNTYPE],[CUSTNUM],[NATURE]");
strSql.Append(",(SELECT TOP 1 REMARK FROM Info_Client_ACCDATE WHERE ENDDATE>=GETDATE() AND LINKGID=info_client.GID order by BGNDATE DESC) ACCREMARK");
strSql.Append(",(SELECT TOP 1 ACCMONTH FROM Info_Client_ACCDATE WHERE ENDDATE>=GETDATE() AND LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCMONTH");
strSql.Append(",(SELECT TOP 1 ALLOWAMOUNT FROM Info_Client_ACCDATE WHERE ENDDATE>=GETDATE() AND LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ALLOWAMOUNT");
strSql.Append(",case WHEN BLSTATUS=0 THEN '合作客户' else '潜在客户' end CUSTPROP");
strSql.Append(",(select showname from [user] where gid=info_client.MODIFIEDUSER) MODIFIEDUSERREF ");
strSql.Append(",RANGETYPE ");
strSql.Append(" from info_client WITH (NOLOCK) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
return SetData(strSql, userid);
}
static public List<MsClient> GetDataListAll(string strCondition, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[CODENAME],[SHORTNAME],[DESCRIPTION],[EnFullName],[STATUS],[ADDR],[EMAIL],[WEB],(SELECT TOP 1 ACCTYPE FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCTYPE,(SELECT TOP 1 ACCDAYS FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCDAYS");
strSql.Append(",[TEL],[FAX],[CHIEF],[SALE],[OP],[DOC],[ISCARRIER],[ISBOOKING],[ISYARD],[ISTRUCK],[ISCONTROLLER]");
strSql.Append(",[ISCUSTOM],[ISAGENT],[ISAGENTCN],[ISEXPRESS],[ISAIRLINES],[ISSHIPPER],[ISCONSIGNEE],[ISNOTIFYPARTY]");
strSql.Append(",[ISWAREHOUSE],[COUNTRY],[PROVINCE],[CITY],[CORPID],[BLCONTENT],[ISSTOP],[BillRises1],[BillRises2],INVBANK,INVADDRTEL");
strSql.Append(",[USDBillRises],[RMBBillRises],[USDMaxAmountCredit],[RMBMaxAmountCredit],[MaxAmountCredit],[STLNAME]");
strSql.Append(",[OPNAME],[OPTIME],[REMARK],[USDExchangeRate],[STLDATE],[STLFIRSTHALFDATE],[STLMIDDLEDATE],[STLDATEPJ]");
strSql.Append(",[LEVEL],[LOGINNAME],[LOGINPASSWORD],[QQ],[MSN],[MODIFIEDUSER],[MODIFIEDTIME],[ISWHARF],[ISSHIPPINGAGENT]");
strSql.Append(",[FARCODE],[FAPCODE],[ISINSURE],[ISLEASING],[ISTRADINGAGENCY],[ISOTHER],[OTHERS],[UNITPRICE],[REGISTRATIONNO]");
strSql.Append(",[ORDERNO],[ISENTERP],[TAXNO],[EDICODE],[EDICODE2],[EDICODE3],[ORGANIZATIONCODE],CODENAME + '-' + SHORTNAME AS CodeAndName");
strSql.Append(",PCORPNAME,InspectionNo,[ISSHIPAGENCY],ISSP,FEEFRT,BSSOURCE,BLSTATUS,SALECORPID,TICHENG,FENCHENG,TICHENGCANYU");
strSql.Append(",(select EnumValueName from tSysEnumValue where enumtypeid=99024 and enumvalueid=blstatus) BLSTATUSREF");
strSql.Append(",RCVMode,[CUSTTYPE],[CUSTGUIMO],[CUSTCLASS],[QUALIFICATION],[REGDATE],[CARGOL],[PRODUCT],[EXPREGION],[CARRIERLIST],[CTNTYPE],[CUSTNUM],[NATURE]");
strSql.Append(",(SELECT TOP 1 REMARK FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID order by BGNDATE DESC) ACCREMARK");
strSql.Append(",(SELECT TOP 1 ACCMONTH FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCMONTH");
strSql.Append(",(SELECT TOP 1 ALLOWAMOUNT FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ALLOWAMOUNT");
strSql.Append(",case WHEN BLSTATUS=0 THEN '合作客户' else '潜在客户' end CUSTPROP");
strSql.Append(",(select showname from [user] where gid=info_client.MODIFIEDUSER) MODIFIEDUSERREF ");
strSql.Append(",RANGETYPE ");
strSql.Append(" from info_client where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CODENAME desc");
}
return SetData(strSql);
}
public static int getTotalCount(string strCondition, string userid, string usercode, string companyid)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" from info_client WITH (NOLOCK) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
public int GetTotalCount(string strCondition, string userid, string usercode, string companyid)
{
try
{
return getTotalCount(strCondition, userid, usercode, companyid);
}
catch (Exception e) {
return 0;
}
}
static public string GetDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[CODENAME],[SHORTNAME],[DESCRIPTION],[EnFullName],[STATUS],[ADDR],[EMAIL],[WEB],(SELECT TOP 1 ACCTYPE FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCTYPE,(SELECT TOP 1 ACCDAYS FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCDAYS");
strSql.Append(",[TEL],[FAX],[CHIEF],[SALE],[OP],[DOC],[ISCARRIER],[ISBOOKING],[ISYARD],[ISTRUCK],[ISCONTROLLER]");
strSql.Append(",[ISCUSTOM],[ISAGENT],[ISAGENTCN],[ISEXPRESS],[ISAIRLINES],[ISSHIPPER],[ISCONSIGNEE],[ISNOTIFYPARTY]");
strSql.Append(",[ISWAREHOUSE],[COUNTRY],[PROVINCE],[CITY],[CORPID],[BLCONTENT],[ISSTOP],[BillRises1],[BillRises2],INVBANK,INVADDRTEL");
strSql.Append(",[USDBillRises],[RMBBillRises],[USDMaxAmountCredit],[RMBMaxAmountCredit],[MaxAmountCredit],[STLNAME]");
strSql.Append(",[OPNAME],[OPTIME],[REMARK],[USDExchangeRate],[STLDATE],[STLFIRSTHALFDATE],[STLMIDDLEDATE],[STLDATEPJ]");
strSql.Append(",[LEVEL],[LOGINNAME],[LOGINPASSWORD],[QQ],[MSN],[MODIFIEDUSER],[MODIFIEDTIME],[ISWHARF],[ISSHIPPINGAGENT]");
strSql.Append(",[FARCODE],[FAPCODE],[ISINSURE],[ISLEASING],[ISTRADINGAGENCY],[ISOTHER],[OTHERS],[UNITPRICE],[REGISTRATIONNO]");
strSql.Append(",[ORDERNO],[ISENTERP],[TAXNO],[EDICODE],[EDICODE2],[EDICODE3],[ORGANIZATIONCODE],CODENAME + '-' + SHORTNAME AS CodeAndName");
strSql.Append(",PCORPNAME,InspectionNo,[ISSHIPAGENCY],ISSP,FEEFRT,BSSOURCE,BLSTATUS,SALECORPID,TICHENG,FENCHENG,TICHENGCANYU");
strSql.Append(",(select EnumValueName from tSysEnumValue where enumtypeid=99024 and enumvalueid=blstatus) BLSTATUSREF");
strSql.Append(",RCVMode,[CUSTTYPE],[CUSTGUIMO],[CUSTCLASS],[QUALIFICATION],[REGDATE],[CARGOL],[PRODUCT],[EXPREGION],[CARRIERLIST],[CTNTYPE],[CUSTNUM],[NATURE]");
strSql.Append(",(SELECT TOP 1 REMARK FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID order by BGNDATE DESC) ACCREMARK");
strSql.Append(",(SELECT TOP 1 ACCMONTH FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ACCMONTH");
strSql.Append(",(SELECT TOP 1 ALLOWAMOUNT FROM Info_Client_ACCDATE WHERE LINKGID=info_client.GID ORDER BY MODIFIEDTIME DESC) ALLOWAMOUNT");
strSql.Append(",case WHEN BLSTATUS=0 THEN '合作客户' else '潜在客户' end CUSTPROP");
strSql.Append(",(select showname from [user] where gid=info_client.MODIFIEDUSER) MODIFIEDUSERREF ");
strSql.Append(",RANGETYPE,''CONTRACTDATE, '' CONTRACTSTATUS");
strSql.Append(" from info_client where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CODENAME ");
}
return strSql.ToString();
}
static public MsClient GetData(string condition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[CODENAME],[SHORTNAME],[DESCRIPTION],[EnFullName],[STATUS],[ADDR],[EMAIL],[WEB]");
strSql.Append(",[TEL],[FAX],[CHIEF],[SALE],[OP],[DOC],[ISCARRIER],[ISBOOKING],[ISYARD],[ISTRUCK],[ISCONTROLLER]");
strSql.Append(",[ISCUSTOM],[ISAGENT],[ISAGENTCN],[ISEXPRESS],[ISAIRLINES],[ISSHIPPER],[ISCONSIGNEE],[ISNOTIFYPARTY]");
strSql.Append(",[ISWAREHOUSE],[COUNTRY],[PROVINCE],[CITY],[CORPID],[BLCONTENT],[ISSTOP],[BillRises1],[BillRises2],INVBANK,INVADDRTEL");
strSql.Append(",[USDBillRises],[RMBBillRises],[USDMaxAmountCredit],[RMBMaxAmountCredit],[MaxAmountCredit],[STLNAME]");
strSql.Append(",[OPNAME],[OPTIME],[REMARK],[USDExchangeRate],[STLDATE],[STLFIRSTHALFDATE],[STLMIDDLEDATE],[STLDATEPJ]");
strSql.Append(",[LEVEL],[LOGINNAME],[LOGINPASSWORD],[QQ],[MSN],[MODIFIEDUSER],[MODIFIEDTIME],[ISWHARF],[ISSHIPPINGAGENT]");
strSql.Append(",[FARCODE],[FAPCODE],[ISINSURE],[ISLEASING],[ISTRADINGAGENCY],[ISOTHER],[OTHERS],[UNITPRICE],[REGISTRATIONNO]");
strSql.Append(",[ORDERNO],[ISENTERP],[TAXNO],[EDICODE],[EDICODE2],[EDICODE3],[ORGANIZATIONCODE],CODENAME + '-' + SHORTNAME AS CodeAndName");
strSql.Append(",PCORPNAME,InspectionNo,ISSHIPAGENCY,ISSP,FEEFRT,BSSOURCE,BLSTATUS,SALECORPID,TICHENG,FENCHENG,TICHENGCANYU");
strSql.Append(",(select EnumValueName from tSysEnumValue where enumtypeid=99024 and enumvalueid=blstatus) BLSTATUSREF");
strSql.Append(",RCVMode,'' ACCREMARK,'' ACCMONTH,'' ALLOWAMOUNT");
strSql.Append(",[CUSTTYPE],[CUSTGUIMO],[CUSTCLASS],[QUALIFICATION],[REGDATE],[CARGOL],[PRODUCT],[EXPREGION],[CARRIERLIST],[CTNTYPE],[CUSTNUM],[NATURE]");
strSql.Append(",case WHEN BLSTATUS=0 THEN '合作客户' else '潜在客户' end CUSTPROP");
strSql.Append(",(select showname from [user] where gid=info_client.MODIFIEDUSER) MODIFIEDUSERREF ");
strSql.Append(",RANGETYPE ");
strSql.Append(" from info_client where 1=1 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list = SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsClient();
}
private static List<MsClient> SetData(StringBuilder strSql,string USERID="")
{
var headList = new List<MsClient>();
Database db = DatabaseFactory.CreateDatabase();
var contractrangstr = "";
var ContractList = GetContractDataList("", null, USERID);
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsClient data = new MsClient();
#region Set DB data to Object
reader.GetSchemaTable().DefaultView.RowFilter = "ColumnName= 'ACCTYPE'";
if (reader.GetSchemaTable().DefaultView.Count > 0)
{
data.ACCTYPE = Convert.ToString(reader["ACCTYPE"]);
data.ACCDAYS = Convert.ToString(reader["ACCDAYS"]);
data.ACCMONTH = Convert.ToString(reader["ACCMONTH"]);
if (data.ACCTYPE == "") data.ACCTYPE = "现结买单";
data.ALLOWAMOUNT = Convert.ToString(reader["ALLOWAMOUNT"]);
}
data.GID = Convert.ToString(reader["GID"]);
data.PCORPNAME = Convert.ToString(reader["PCORPNAME"]);
data.CODENAME = Convert.ToString(reader["CODENAME"]);
data.SHORTNAME = Convert.ToString(reader["SHORTNAME"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.ENFULLNAME = Convert.ToString(reader["ENFULLNAME"]);
data.STATUS = Convert.ToInt16(reader["STATUS"]);
data.ADDR = Convert.ToString(reader["ADDR"]);
data.EMAIL = Convert.ToString(reader["EMAIL"]);
data.WEB = Convert.ToString(reader["WEB"]);
data.TEL = Convert.ToString(reader["TEL"]);
data.FAX = Convert.ToString(reader["FAX"]);
data.CHIEF = Convert.ToString(reader["CHIEF"]);
data.OP = Convert.ToString(reader["OP"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.OPNAME = Convert.ToString(reader["OPNAME"]);
data.OPTIME = Convert.ToString(reader["OPTIME"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.SALECORPID = Convert.ToString(reader["SALECORPID"]);
data.OTHERS = Convert.ToString(reader["OTHERS"]);
if (reader["STATUS"] != DBNull.Value)
data.STATUS = Convert.ToInt16(reader["STATUS"]);//状态1
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
data.PROVINCE = Convert.ToString(reader["PROVINCE"]);
data.CITY = Convert.ToString(reader["CITY"]);
data.BLCONTENT = Convert.ToString(reader["BLCONTENT"]);
data.BILLRISES1 = Convert.ToString(reader["BILLRISES1"]);
data.BILLRISES2 = Convert.ToString(reader["BILLRISES2"]);
data.INVBANK = Convert.ToString(reader["INVBANK"]);
data.INVADDRTEL = Convert.ToString(reader["INVADDRTEL"]);
data.RMBBILLRISES = Convert.ToString(reader["RMBBILLRISES"]);
data.USDBILLRISES = Convert.ToString(reader["USDBILLRISES"]);
if (reader["USDMAXAMOUNTCREDIT"] != DBNull.Value)
data.USDMAXAMOUNTCREDIT = Convert.ToDecimal(reader["USDMAXAMOUNTCREDIT"]);//状态1
if (reader["RMBMAXAMOUNTCREDIT"] != DBNull.Value)
data.RMBMAXAMOUNTCREDIT = Convert.ToDecimal(reader["RMBMAXAMOUNTCREDIT"]);//状态1
if (reader["MAXAMOUNTCREDIT"] != DBNull.Value)
data.MAXAMOUNTCREDIT = Convert.ToDecimal(reader["MAXAMOUNTCREDIT"]);//状态1
data.STLNAME = Convert.ToString(reader["STLNAME"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.ACCREMARK = Convert.ToString(reader["ACCREMARK"]);
data.STLDATE = Convert.ToString(reader["STLDATE"]);
if (reader["USDEXCHANGERATE"] != DBNull.Value)
data.USDEXCHANGERATE = Convert.ToDecimal(reader["USDEXCHANGERATE"]);//状态1
data.STLFIRSTHALFDATE = Convert.ToString(reader["STLFIRSTHALFDATE"]);
data.STLMIDDLEDATE = Convert.ToString(reader["STLMIDDLEDATE"]);
data.STLDATEPJ = Convert.ToString(reader["STLDATEPJ"]);
data.LEVEL = Convert.ToString(reader["LEVEL"]);
data.LOGINNAME = Convert.ToString(reader["LOGINNAME"]);
data.LOGINPASSWORD = Convert.ToString(reader["LOGINPASSWORD"]);
data.QQ = Convert.ToString(reader["QQ"]);
data.MSN = Convert.ToString(reader["MSN"]);
data.FARCODE = Convert.ToString(reader["FARCODE"]);
data.FAPCODE = Convert.ToString(reader["FAPCODE"]);
data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]);
data.REGISTRATIONNO = Convert.ToString(reader["REGISTRATIONNO"]);
data.TAXNO = Convert.ToString(reader["TAXNO"]);
data.InspectionNo = Convert.ToString(reader["InspectionNo"]);
data.EDICODE = Convert.ToString(reader["EDICODE"]);
data.EDICODE2 = Convert.ToString(reader["EDICODE2"]);
data.EDICODE3 = Convert.ToString(reader["EDICODE3"]);
data.ORGANIZATIONCODE = Convert.ToString(reader["ORGANIZATIONCODE"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
if (reader["ISCARRIER"] != DBNull.Value)
data.ISCARRIER = Convert.ToBoolean(reader["ISCARRIER"]);//状态
if (reader["ISBOOKING"] != DBNull.Value)
data.ISBOOKING = Convert.ToBoolean(reader["ISBOOKING"]);//状态
if (reader["ISYARD"] != DBNull.Value)
data.ISYARD = Convert.ToBoolean(reader["ISYARD"]);//状态
if (reader["ISTRUCK"] != DBNull.Value)
data.ISTRUCK = Convert.ToBoolean(reader["ISTRUCK"]);//状态
if (reader["ISCONTROLLER"] != DBNull.Value)
data.ISCONTROLLER = Convert.ToBoolean(reader["ISCONTROLLER"]);//状态
if (reader["ISCUSTOM"] != DBNull.Value)
data.ISCUSTOM = Convert.ToBoolean(reader["ISCUSTOM"]);//状态
if (reader["ISAGENT"] != DBNull.Value)
data.ISAGENT = Convert.ToBoolean(reader["ISAGENT"]);//状态
if (reader["ISAGENTCN"] != DBNull.Value)
data.ISAGENTCN = Convert.ToBoolean(reader["ISAGENTCN"]);//状态
if (reader["ISEXPRESS"] != DBNull.Value)
data.ISEXPRESS = Convert.ToBoolean(reader["ISEXPRESS"]);//状态
if (reader["ISAIRLINES"] != DBNull.Value)
data.ISAIRLINES = Convert.ToBoolean(reader["ISAIRLINES"]);//状态
if (reader["ISSHIPPER"] != DBNull.Value)
data.ISSHIPPER = Convert.ToBoolean(reader["ISSHIPPER"]);//状态
if (reader["ISCONSIGNEE"] != DBNull.Value)
data.ISCONSIGNEE = Convert.ToBoolean(reader["ISCONSIGNEE"]);//状态
if (reader["ISNOTIFYPARTY"] != DBNull.Value)
data.ISNOTIFYPARTY = Convert.ToBoolean(reader["ISNOTIFYPARTY"]);//状态
if (reader["ISWAREHOUSE"] != DBNull.Value)
data.ISWAREHOUSE = Convert.ToBoolean(reader["ISWAREHOUSE"]);//状态
if (reader["ISINSURE"] != DBNull.Value)
data.ISINSURE = Convert.ToBoolean(reader["ISINSURE"]);//状态
if (reader["ISLEASING"] != DBNull.Value)
data.ISLEASING = Convert.ToBoolean(reader["ISLEASING"]);//状态
if (reader["ISTRADINGAGENCY"] != DBNull.Value)
data.ISTRADINGAGENCY = Convert.ToBoolean(reader["ISTRADINGAGENCY"]);//状
if (reader["ISOTHER"] != DBNull.Value)
data.ISOTHER = Convert.ToBoolean(reader["ISOTHER"]);//状
if (reader["ISENTERP"] != DBNull.Value)
data.ISENTERP = Convert.ToBoolean(reader["ISENTERP"]);//状
if (reader["ISSTOP"] != DBNull.Value)
data.ISSTOP = Convert.ToBoolean(reader["ISSTOP"]);//状态1
if (reader["ISSHIPAGENCY"] != DBNull.Value)
data.ISSHIPAGENCY = Convert.ToBoolean(reader["ISSHIPAGENCY"]);//状
data.BLSTATUSREF = Convert.ToString(reader["BLSTATUSREF"]);
if (reader["ISSP"] != DBNull.Value)
data.ISSP = Convert.ToBoolean(reader["ISSP"]);//状
data.FEEFRT = Convert.ToString(reader["FEEFRT"]);
data.RCVMode = Convert.ToString(reader["RCVMode"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
if (reader["TICHENG"] != DBNull.Value)
data.TICHENG = Convert.ToString(reader["TICHENG"]);//提成
if (reader["FENCHENG"] != DBNull.Value)
data.FENCHENG = Convert.ToString(reader["FENCHENG"]);//分成
data.TICHENGCANYU = Convert.ToString(reader["TICHENGCANYU"]);//分成
data.CUSTTYPE = Convert.ToString(reader["CUSTTYPE"]);//分成
data.CUSTGUIMO = Convert.ToString(reader["CUSTGUIMO"]);//分成
data.CUSTCLASS = Convert.ToString(reader["CUSTCLASS"]);//分成
data.QUALIFICATION = Convert.ToString(reader["QUALIFICATION"]);//分成
data.REGDATE = Convert.ToString(reader["REGDATE"]);//分成
data.CARGOL = Convert.ToString(reader["CARGOL"]);//分成
data.PRODUCT = Convert.ToString(reader["PRODUCT"]);//分成
data.EXPREGION = Convert.ToString(reader["EXPREGION"]);//分成
data.CARRIERLIST = Convert.ToString(reader["CARRIERLIST"]);//分成
data.CTNTYPE = Convert.ToString(reader["CTNTYPE"]);//分成
data.CUSTNUM = Convert.ToString(reader["CUSTNUM"]);//分成
data.NATURE = Convert.ToString(reader["NATURE"]);//分成
data.CUSTPROP = Convert.ToString(reader["CUSTPROP"]);//客户属性
data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.RANGETYPE = Convert.ToString(reader["RANGETYPE"]);
#endregion
data.SetContractStatus(ContractList);
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 联系人
static public List<MsClientContact> GetContactDataList(string strCondition,string sort = null,string USERID="1")
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKID],[CODENAME],[SHOWNAME],[ADDR],[EMAIL],[TEL],QQ,[FAX],[MOBILE]");
strSql.Append(",[ISFINANCIALSTAFF],[ISOPERATOR],[ISSALEMAN],[ISOTHER],[ISINSURANCE],[CREATEUSER],[CREATETIME]");
strSql.Append(" ,[ISSTOP],[ISDELETED],[REMARK],[ANNIVERSARY2],[AREMARK2],[BIRTHDAY],[ANNIVERSARY1] ");
strSql.Append(" ,[AREMARK1],[ISBIRTHDAY],[ISANNIVERSARY1],[ISANNIVERSARY2],[BIRTHDAYDAY],[ANNIVERSARYDAY1]");
strSql.Append(" ,[ANNIVERSARYDAY2],[JOB],[SEX],[AGE],[MARRY],[CHILDREN],[HOBBIES],ISDUI");
strSql.Append(",(select filename from info_files where pid=info_client_contact.gid) PICURL");
strSql.Append(" from info_client_contact where 1=1 ");
var rangstr = "";
if (USERID == "1") rangstr = "1=2";
else
{
rangstr=BasicDataRefDAL.GetVisableRange("modInfoClient_info", USERID, "", "CREATEUSER");
}
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CODENAME");
}
return SetContactData(strSql);
}
static public MsClientContact GetContactData(string condition,string userid)
{
MsClientContact data = null;
var list = GetContactDataList(condition,"", userid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsClientContact();
}
return data;
}
private static List<MsClientContact> SetContactData(StringBuilder strSql)
{
var headList = new List<MsClientContact>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsClientContact data = new MsClientContact();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKID = Convert.ToString(reader["LINKID"]);
data.CODENAME = Convert.ToString(reader["CODENAME"]);
data.SHOWNAME = Convert.ToString(reader["SHOWNAME"]);
data.ADDR = Convert.ToString(reader["ADDR"]);
data.EMAIL = Convert.ToString(reader["EMAIL"]);
data.MOBILE = Convert.ToString(reader["MOBILE"]);
data.TEL = Convert.ToString(reader["TEL"]);
data.QQ = Convert.ToString(reader["QQ"]);
data.FAX = Convert.ToString(reader["FAX"]);
data.JOB = Convert.ToString(reader["JOB"]);
data.SEX = Convert.ToString(reader["SEX"]);
data.AGE = Convert.ToString(reader["AGE"]);
data.MARRY = Convert.ToString(reader["MARRY"]);
data.CHILDREN = Convert.ToString(reader["CHILDREN"]);
data.HOBBIES = Convert.ToString(reader["HOBBIES"]);
if (reader["ISFINANCIALSTAFF"] != DBNull.Value)
data.ISFINANCIALSTAFF = Convert.ToBoolean(reader["ISFINANCIALSTAFF"]);//状态1
if (reader["ISOPERATOR"] != DBNull.Value)
data.ISOPERATOR = Convert.ToBoolean(reader["ISOPERATOR"]);//状态1
if (reader["ISSALEMAN"] != DBNull.Value)
data.ISSALEMAN = Convert.ToBoolean(reader["ISSALEMAN"]);//状态1
if (reader["ISSTOP"] != DBNull.Value)
data.ISSTOP = Convert.ToBoolean(reader["ISSTOP"]);//状态1
if (reader["ISINSURANCE"] != DBNull.Value)
data.ISINSURANCE = Convert.ToBoolean(reader["ISINSURANCE"]);//状态1
if (reader["ISDUI"] != DBNull.Value)
data.ISDUI = Convert.ToBoolean(reader["ISDUI"]);//状态1
data.REMARK = Convert.ToString(reader["REMARK"]);
data.BIRTHDAY = Convert.ToString(reader["BIRTHDAY"]);
if (reader["ISBIRTHDAY"] != DBNull.Value)
data.ISBIRTHDAY = Convert.ToBoolean(reader["ISBIRTHDAY"]);//状态1
if (reader["BIRTHDAYDAY"] != DBNull.Value)
data.BIRTHDAYDAY = Convert.ToInt16(reader["BIRTHDAYDAY"]);//状态1
data.ANNIVERSARY1 = Convert.ToString(reader["ANNIVERSARY1"]);
if (reader["ISANNIVERSARY1"] != DBNull.Value)
data.ISANNIVERSARY1 = Convert.ToBoolean(reader["ISANNIVERSARY1"]);//状态1
if (reader["ANNIVERSARYDAY1"] != DBNull.Value)
data.ANNIVERSARYDAY1 = Convert.ToInt16(reader["ANNIVERSARYDAY1"]);//状态1
data.ANNIVERSARY2 = Convert.ToString(reader["ANNIVERSARY2"]);
if (reader["ISANNIVERSARY2"] != DBNull.Value)
data.ISANNIVERSARY2 = Convert.ToBoolean(reader["ISANNIVERSARY2"]);//状态1
if (reader["ANNIVERSARYDAY2"] != DBNull.Value)
data.ANNIVERSARYDAY2 = Convert.ToInt16(reader["ANNIVERSARYDAY2"]);//状态1
data.PICURL = Convert.ToString(reader["PICURL"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveContactDetail(string linkid,List<MsClientContact> bodyList, string userid,string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_client_contact ([GID],[LINKID],[CODENAME],[SHOWNAME],[ADDR],[EMAIL],[TEL],QQ,[FAX],[MOBILE]
,[ISFINANCIALSTAFF],[ISOPERATOR],[ISSALEMAN],[ISOTHER],[CREATEUSER],[CREATETIME],[ISSTOP],[REMARK],[ANNIVERSARY2],
[AREMARK2],[BIRTHDAY],[ANNIVERSARY1],[AREMARK1],[ISBIRTHDAY],[ISANNIVERSARY1],[ISANNIVERSARY2],[BIRTHDAYDAY],[ANNIVERSARYDAY1]
,[ANNIVERSARYDAY2],[JOB],[SEX],[AGE],[MARRY],[CHILDREN],[HOBBIES])
values (@GID,@LINKID,@CODENAME,@SHOWNAME,@ADDR,@EMAIL,@TEL,@QQ,@FAX,@MOBILE
,@ISFINANCIALSTAFF,@ISOPERATOR,@ISSALEMAN,@ISOTHER,@CREATEUSER,@CREATETIME,@ISSTOP,@REMARK,@ANNIVERSARY2,
@AREMARK2,@BIRTHDAY,@ANNIVERSARY1,@AREMARK1,@ISBIRTHDAY,@ISANNIVERSARY1,@ISANNIVERSARY2,@BIRTHDAYDAY,@ANNIVERSARYDAY1
,@ANNIVERSARYDAY2,@JOB,@SEX,@AGE,@MARRY,@CHILDREN,@HOBBIES) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update info_client_contact set LINKID=@LINKID,CODENAME=@CODENAME,SHOWNAME=@SHOWNAME,ADDR=@ADDR,EMAIL=@EMAIL,TEL=@TEL,QQ=@QQ,FAX=@FAX,MOBILE=@MOBILE
,ISFINANCIALSTAFF=@ISFINANCIALSTAFF,ISOPERATOR=@ISOPERATOR,ISSALEMAN=@ISSALEMAN,ISOTHER=@ISOTHER,CREATEUSER=@CREATEUSER,CREATETIME=@CREATETIME
,ISSTOP@ISSTOP,REMARK=@REMARK,ANNIVERSARY2=@ANNIVERSARY2,AREMARK2=@AREMARK2,BIRTHDAY=@BIRTHDAY,ANNIVERSARY1=@ANNIVERSARY1
,AREMARK1=@AREMARK1,ISBIRTHDAY=@ISBIRTHDAY,ISANNIVERSARY1=@ISANNIVERSARY1,ISANNIVERSARY2=@ISANNIVERSARY2,BIRTHDAYDAY=@BIRTHDAYDAY,
ANNIVERSARYDAY1=@ANNIVERSARYDAY1,ANNIVERSARYDAY2=@ANNIVERSARYDAY2,JOB=@JOB,SEX=@SEX,AGE=@AGE,MARRY=@MARRY,CHILDREN=@CHILDREN,HOBBIES=@HOBBIES
where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKID", DbType.String, linkid);
db.AddInParameter(cmdInsert, "@CODENAME", DbType.String, enumValue.CODENAME);
db.AddInParameter(cmdInsert, "@SHOWNAME", DbType.String, enumValue.SHOWNAME);
db.AddInParameter(cmdInsert, "@ADDR", DbType.String, enumValue.ADDR);
db.AddInParameter(cmdInsert, "@EMAIL", DbType.String, enumValue.EMAIL);
db.AddInParameter(cmdInsert, "@TEL", DbType.String, enumValue.TEL);
db.AddInParameter(cmdInsert, "@QQ", DbType.String, enumValue.QQ);
db.AddInParameter(cmdInsert, "@FAX", DbType.String, enumValue.FAX);
db.AddInParameter(cmdInsert, "@MOBILE", DbType.String, enumValue.MOBILE);
db.AddInParameter(cmdInsert, "@ISFINANCIALSTAFF", DbType.Boolean, enumValue.ISFINANCIALSTAFF);
db.AddInParameter(cmdInsert, "@ISOPERATOR", DbType.Boolean, enumValue.ISOPERATOR);
db.AddInParameter(cmdInsert, "@ISSALEMAN", DbType.Boolean, enumValue.ISSALEMAN);
db.AddInParameter(cmdInsert, "@ISOTHER", DbType.Boolean, enumValue.ISOTHER);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdInsert, "@ISSTOP", DbType.Boolean, enumValue.ISSTOP);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@ANNIVERSARY2", DbType.String, enumValue.ANNIVERSARY2);
db.AddInParameter(cmdInsert, "@AREMARK2", DbType.String, enumValue.AREMARK2);
db.AddInParameter(cmdInsert, "@BIRTHDAY", DbType.String, enumValue.BIRTHDAY);
db.AddInParameter(cmdInsert, "@ANNIVERSARY1", DbType.String, enumValue.ANNIVERSARY1);
db.AddInParameter(cmdInsert, "@AREMARK1", DbType.String, enumValue.AREMARK1);
db.AddInParameter(cmdInsert, "@ISBIRTHDAY", DbType.Boolean, enumValue.ISBIRTHDAY);
db.AddInParameter(cmdInsert, "@ISANNIVERSARY1", DbType.Boolean, enumValue.ISANNIVERSARY1);
db.AddInParameter(cmdInsert, "@ISANNIVERSARY2", DbType.Boolean, enumValue.ISANNIVERSARY2);
db.AddInParameter(cmdInsert, "@BIRTHDAYDAY", DbType.Int16, enumValue.BIRTHDAYDAY);
db.AddInParameter(cmdInsert, "@ANNIVERSARYDAY1", DbType.Int16, enumValue.ANNIVERSARYDAY1);
db.AddInParameter(cmdInsert, "@ANNIVERSARYDAY2", DbType.Int16, enumValue.ANNIVERSARYDAY2);
db.AddInParameter(cmdInsert, "@JOB", DbType.String, enumValue.JOB);
db.AddInParameter(cmdInsert, "@SEX", DbType.String, enumValue.SEX);
db.AddInParameter(cmdInsert, "@AGE", DbType.String, enumValue.AGE);
db.AddInParameter(cmdInsert, "@MARRY", DbType.String, enumValue.MARRY);
db.AddInParameter(cmdInsert, "@CHILDREN", DbType.String, enumValue.CHILDREN);
db.AddInParameter(cmdInsert, "@HOBBIES", DbType.String, enumValue.HOBBIES);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@LINKID", DbType.String, enumValue.LINKID);
db.AddInParameter(cmdUpdate, "@CODENAME", DbType.String, enumValue.CODENAME);
db.AddInParameter(cmdUpdate, "@SHOWNAME", DbType.String, enumValue.SHOWNAME);
db.AddInParameter(cmdUpdate, "@ADDR", DbType.String, enumValue.ADDR);
db.AddInParameter(cmdUpdate, "@EMAIL", DbType.String, enumValue.EMAIL);
db.AddInParameter(cmdUpdate, "@TEL", DbType.String, enumValue.TEL);
db.AddInParameter(cmdUpdate, "@QQ", DbType.String, enumValue.QQ);
db.AddInParameter(cmdUpdate, "@FAX", DbType.String, enumValue.FAX);
db.AddInParameter(cmdUpdate, "@MOBILE", DbType.String, enumValue.MOBILE);
db.AddInParameter(cmdUpdate, "@ISFINANCIALSTAFF", DbType.Boolean, enumValue.ISFINANCIALSTAFF);
db.AddInParameter(cmdUpdate, "@ISOPERATOR", DbType.Boolean, enumValue.ISOPERATOR);
db.AddInParameter(cmdUpdate, "@ISSALEMAN", DbType.Boolean, enumValue.ISSALEMAN);
db.AddInParameter(cmdUpdate, "@ISOTHER", DbType.Boolean, enumValue.ISOTHER);
db.AddInParameter(cmdUpdate, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdUpdate, "@ISSTOP", DbType.Boolean, enumValue.ISSTOP);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@ANNIVERSARY2", DbType.String, enumValue.ANNIVERSARY2);
db.AddInParameter(cmdUpdate, "@AREMARK2", DbType.String, enumValue.AREMARK2);
db.AddInParameter(cmdUpdate, "@BIRTHDAY", DbType.String, enumValue.BIRTHDAY);
db.AddInParameter(cmdUpdate, "@ANNIVERSARY1", DbType.String, enumValue.ANNIVERSARY1);
db.AddInParameter(cmdUpdate, "@AREMARK1", DbType.String, enumValue.AREMARK1);
db.AddInParameter(cmdUpdate, "@ISBIRTHDAY", DbType.Boolean, enumValue.ISBIRTHDAY);
db.AddInParameter(cmdUpdate, "@ISANNIVERSARY1", DbType.Boolean, enumValue.ISANNIVERSARY1);
db.AddInParameter(cmdUpdate, "@ISANNIVERSARY2", DbType.Boolean, enumValue.ISANNIVERSARY2);
db.AddInParameter(cmdUpdate, "@BIRTHDAYDAY", DbType.Int16, enumValue.BIRTHDAYDAY);
db.AddInParameter(cmdUpdate, "@ANNIVERSARYDAY1", DbType.Int16, enumValue.ANNIVERSARYDAY1);
db.AddInParameter(cmdUpdate, "@ANNIVERSARYDAY2", DbType.Int16, enumValue.ANNIVERSARYDAY2);
db.AddInParameter(cmdUpdate, "@JOB", DbType.String, enumValue.JOB);
db.AddInParameter(cmdUpdate, "@SEX", DbType.String, enumValue.SEX);
db.AddInParameter(cmdUpdate, "@AGE", DbType.String, enumValue.AGE);
db.AddInParameter(cmdUpdate, "@MARRY", DbType.String, enumValue.MARRY);
db.AddInParameter(cmdUpdate, "@CHILDREN", DbType.String, enumValue.HOBBIES);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 合同
static public List<MsInfoContract> GetContractDataList(string strCondition, string sort = null,string USERID="1")
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],LINKID,[CONTRACTNO],CONTRACTNAME,[SIGNINGDATE],[STARTDATE],");
strSql.Append("[CANCELDATE],[CHIEF],[REMARK],[CORPID],[CREATEUSER],[CREATETIME],[DEPTGID]");
strSql.Append(",(select ShowName from [user] where GID=info_client_contract.CREATEUSER) as CREATEUSERREF");
strSql.Append(",(select SHORTNAME from info_client where GID=info_client_contract.LINKID) as CUSTNAME");
strSql.Append(" from info_client_contract where 1=1 ");
var rangstr = "";
if (USERID == "1") rangstr = "1=2";
else
{
rangstr = BasicDataRefDAL.GetVisableRange("modInfoClient_info", USERID, "", "CREATEUSER","DEPTGID");
}
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by SIGNINGDATE DESC");
}
return SetContractData(strSql);
}
static public MsInfoContract GetContractData(string condition,string userid)
{
MsInfoContract data = null;
var list = GetContractDataList(condition,"",userid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsInfoContract();
}
return data;
}
private static List<MsInfoContract> SetContractData(StringBuilder strSql)
{
var headList = new List<MsInfoContract>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsInfoContract data = new MsInfoContract();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKID = Convert.ToString(reader["LINKID"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CONTRACTNAME = Convert.ToString(reader["CONTRACTNAME"]);
data.CUSTNAME = Convert.ToString(reader["CUSTNAME"]);
if (reader["SIGNINGDATE"] != DBNull.Value)
data.SIGNINGDATE = Convert.ToDateTime(reader["SIGNINGDATE"]).ToString("yyyy-MM-dd");//预抵日期
if (reader["STARTDATE"] != DBNull.Value)
data.STARTDATE = Convert.ToDateTime(reader["STARTDATE"]).ToString("yyyy-MM-dd");//预抵日期
if (reader["CANCELDATE"] != DBNull.Value)
data.CANCELDATE = Convert.ToDateTime(reader["CANCELDATE"]).ToString("yyyy-MM-dd");//预抵日期
data.CHIEF = Convert.ToString(reader["CHIEF"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.DEPTGID = Convert.ToString(reader["DEPTGID"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SaveCustFee(MsClient headData, List<Info_Client_GDFYWHmb> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from cust_fee_templatedetail where CUSTOMERNAME='" + headData.SHORTNAME + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdInsert =
db.GetSqlStringCommand(
@"insert into cust_fee_templatedetail (GID,FEENAME,CUSTOMERNAME,UNIT,CURRENCY,UNITPRICE,REMARK,CREATEUSER,CREATETIME,EXCHANGERATE,ISCTN,ISINVOICE,ISADVANCEDPAY,FEEFRT,TAXRATE,TAX)
values (@GID,@FEENAME,@CUSTOMERNAME,@UNIT,@CURRENCY,@UNITPRICE,@REMARK,@CREATEUSER,@CREATETIME,@EXCHANGERATE,@ISCTN,@ISINVOICE,@ISADVANCEDPAY,@FEEFRT,@TAXRATE,@TAX) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, headData.SHORTNAME);
db.AddInParameter(cmdInsert, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString());
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.EXCHANGERATE);
db.AddInParameter(cmdInsert, "@ISCTN", DbType.Boolean, enumValue.ISCTN);
db.AddInParameter(cmdInsert, "@ISINVOICE", DbType.Boolean, enumValue.ISINVOICE);
db.AddInParameter(cmdInsert, "@ISADVANCEDPAY", DbType.Boolean, enumValue.ISADVANCEDPAY);
db.AddInParameter(cmdInsert, "@FEEFRT", DbType.String, enumValue.FEEFRT);
db.AddInParameter(cmdInsert, "@TAXRATE", DbType.Decimal, enumValue.TAXRATE);
db.AddInParameter(cmdInsert, "@TAX", DbType.Decimal, enumValue.TAX);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
static public DBResult CreateHangXinCust(string filename)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
var cmdDelete = db.GetSqlStringCommand("delete from tmp_hangxincust ");
db.ExecuteNonQuery(cmdDelete, tran);
try
{
FileStream fs = new FileStream(filename, FileMode.Open);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"));
string line;
int linecount = 0;
while ((line = sr.ReadLine()) != null)
{
if (linecount < 3)
{
linecount++;
continue;
}
linecount++;
string[] custlist = Regex.Split(line, "~~", RegexOptions.IgnoreCase);
if (custlist.Length > 5)
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into tmp_hangxincust (NO,CUSTNAME,TAXNO,ADDRTEL,BANK,SORT)
values (@NO,@CUSTNAME,@TAXNO,@ADDRTEL,@BANK,@SORT) ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@NO", DbType.String, custlist[0]);
db.AddInParameter(cmdInsert, "@CUSTNAME", DbType.String, custlist[1]);
db.AddInParameter(cmdInsert, "@TAXNO", DbType.String, custlist[3]);
db.AddInParameter(cmdInsert, "@ADDRTEL", DbType.String, custlist[4]);
db.AddInParameter(cmdInsert, "@BANK", DbType.String, custlist[5]);
db.AddInParameter(cmdInsert, "@SORT", DbType.Int32, linecount);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员"+e.Message;
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult SaveHangXinCust(List<MsHangXinCust> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update tmp_hangxincust set SHORTNAME=@SHORTNAME WHERE GID=@GID ");
foreach (var enumValue in boday)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@SHORTNAME", DbType.String, enumValue.SHORTNAME);
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "设置完成";
return result;
}
public static DBResult UpdateHangXinCust(List<MsHangXinCust> boday, String USERID)
{
var result = new DBResult();
var errostr = "";
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
var shortname = "";
try
{
if (boday != null)
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update info_client set BILLRISES1=@BILLRISES1,INVADDRTEL=@INVADDRTEL,TAXNO=@TAXNO WHERE SHORTNAME=@SHORTNAME ");
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_client_bank (GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,[REMARK],FINANCESOFTCODE,CREATEUSER,CREATETIME,ACCOUNTNAME)
SELECT NEWID(),GID,'','RMB',@BANKNAME,@ACCOUNT,'','',@CREATEUSER,GETDATE(),@ACCOUNTNAME FROM INFO_CLIENT WHERE SHORTNAME=@SHORTNAME ");
foreach (var enumValue in boday)
{
if (enumValue.SHORTNAME != "")
{
shortname = enumValue.SHORTNAME;
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BILLRISES1", DbType.String, enumValue.CUSTNAME);
db.AddInParameter(cmdUpdate, "@INVADDRTEL", DbType.String, enumValue.ADDRTEL);
db.AddInParameter(cmdUpdate, "@TAXNO", DbType.String, enumValue.TAXNO);
db.AddInParameter(cmdUpdate, "@SHORTNAME", DbType.String, enumValue.SHORTNAME);
db.ExecuteNonQuery(cmdUpdate, tran);
var BANKSTR = enumValue.BANK;
if (BANKSTR != "") {
BANKSTR = BANKSTR.Replace(" ", "");
BANKSTR = BANKSTR.Replace("-", "");
Regex r = new Regex(@"\d+");
try
{
var ms = r.Matches(BANKSTR);
var bankaccount = ms.OfType<System.Text.RegularExpressions.Match>().Last().ToString();
var bankname = BANKSTR.Replace(bankaccount, "").Trim();
var banklist = GetBankList(" LINKID in (select GID FROM INFO_CLIENT WHERE SHORTNAME='" + enumValue.SHORTNAME + "') and BANKNAME='" + bankname + "' and ACCOUNT='" + bankaccount + "'", "1", "BANKNAME", tran);
if (banklist.Count == 0)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@BANKNAME", DbType.String, bankname);
db.AddInParameter(cmdInsert, "@ACCOUNT", DbType.String, bankaccount);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, USERID);
db.AddInParameter(cmdInsert, "@ACCOUNTNAME", DbType.String, enumValue.CUSTNAME);
db.AddInParameter(cmdInsert, "@SHORTNAME", DbType.String, enumValue.SHORTNAME);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
catch (Exception e)
{
errostr = errostr + e.Message;
}
}
}
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员 "+ shortname + e.Message;
return result;
}
}
result.Success = true;
result.Message = "设置完成"+ errostr;
return result;
}
public static string GetBankNo(string str)
{
string resultstr = "";
str = str.Replace(" ", "");
str = str.Replace("-", "");
Regex r = new Regex(@"\d+");
var ms = r.Matches(str);
resultstr = ms.OfType<System.Text.RegularExpressions.Match>().Last().ToString();
return resultstr;
}
#region 客户部门
static public List<MsCompanysDept> GetDeptList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * from info_client_dept where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by DEPTNO,MODIFIEDTIME");
}
return SetDeptData(strSql);
}
static public MsCompanysDept GetDeptData(string condition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * from info_client_dept where 1=1");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list = SetDeptData(strSql);
if (list.Count > 0)
return list[0];
return new MsCompanysDept();
}
private static List<MsCompanysDept> SetDeptData(StringBuilder strSql)
{
var headList = new List<MsCompanysDept>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCompanysDept data = new MsCompanysDept();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//惟一编号
data.LINKID = (reader["LINKID"] == null ? "" : Convert.ToString(reader["LINKID"]));//公司关联id
data.DEPTNO = (reader["DEPTNO"] == null ? "" : Convert.ToString(reader["DEPTNO"]));//代码
data.DEPTNAME = (reader["DEPTNAME"] == null ? "" : Convert.ToString(reader["DEPTNAME"]));//名称
data.FINANCESOFTCODE = (reader["FINANCESOFTCODE"] == null ? "" : Convert.ToString(reader["FINANCESOFTCODE"]));//FINANCESOFTCODE
data.MANAGE1 = (reader["MANAGE1"] == null ? "" : Convert.ToString(reader["MANAGE1"]));//经理
data.MANAGE2 = (reader["MANAGE2"] == null ? "" : Convert.ToString(reader["MANAGE2"]));//副经理
data.REMARK = (reader["REMARK"] == null ? "" : Convert.ToString(reader["REMARK"]));//备注
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//CREATEUSER
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"]);//更改操作时间
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 银行信息
static public List<MsClientAccount> GetBankList(string strCondition,string isedit="0", string sort = null,DbTransaction tran=null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * ,(SELECT SHORTNAME FROM info_client where GID=info_client_bank.LINKID) CUSTNAME");
strSql.Append(",BANKNAME + '-' + ACCOUNTNAME AS ACCOUNTNAMEREF");
strSql.Append(",BANKNAME + ' ' + ACCOUNT AS BANKACCOUNT");
strSql.Append(",(select country from code_country where countryid=info_client_bank.countryid) country");
strSql.Append(",ISINVDEF,(CASE WHEN ISINVDEF='1' THEN '是' ELSE '否' END) ISINVDEFREF");
strSql.Append(" from info_client_bank where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CODENAME");
}
return SetBankData(strSql,isedit, tran);
}
static public MsClientAccount GetBankData(string condition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * ,(SELECT SHORTNAME FROM info_client where GID=info_client_bank.LINKID) CUSTNAME");
strSql.Append(",BANKNAME + '-' + ACCOUNTNAME AS ACCOUNTNAMEREF");
strSql.Append(",BANKNAME + ' ' + ACCOUNT AS BANKACCOUNT");
strSql.Append(",(select country from code_country where countryid=info_client_bank.countryid) country");
strSql.Append(",ISINVDEF,(CASE WHEN ISINVDEF='1' THEN '是' ELSE '否' END) ISINVDEFREF");
//strSql.Append(",(select country from code_country where countryid=info_client_bank.countryid),0,(charindex('(',(select country from code_country where countryid=info_client_bank.countryid))) ) country");
strSql.Append(" from info_client_bank where 1=1");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list = SetBankData(strSql,"1");
if (list.Count > 0)
return list[0];
return new MsClientAccount();
}
private static List<MsClientAccount> SetBankData(StringBuilder strSql,string isedit, DbTransaction tran = null)
{
var headList = new List<MsClientAccount>();
Database db = DatabaseFactory.CreateDatabase();
if (tran == null)
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsClientAccount data = new MsClientAccount();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//GID
data.LINKID = (reader["LINKID"] == null ? "" : Convert.ToString(reader["LINKID"]));//公司关联id
data.CODENAME = (reader["CODENAME"] == null ? "" : Convert.ToString(reader["CODENAME"]));//CODENAME
data.CURRENCY = (reader["CURRENCY"] == null ? "" : Convert.ToString(reader["CURRENCY"]));//CURRENCY
data.BANKNAME = (reader["BANKNAME"] == null ? "" : Convert.ToString(reader["BANKNAME"]));//BANKNAME
data.ACCOUNT = (reader["ACCOUNT"] == null ? "" : Convert.ToString(reader["ACCOUNT"]));//ACCOUNT
data.ACCOUNTNAME = (reader["ACCOUNTNAME"] == null ? "" : Convert.ToString(reader["ACCOUNTNAME"]));//ACCOUNT
data.SUBJECTCODE = (reader["SUBJECTCODE"] == null ? "" : Convert.ToString(reader["SUBJECTCODE"]));//银行账户
data.REMARK = (reader["REMARK"] == null ? "" : Convert.ToString(reader["REMARK"]));//REMARK
data.FINANCESOFTCODE = (reader["FINANCESOFTCODE"] == null ? "" : Convert.ToString(reader["FINANCESOFTCODE"]));//FINANCESOFTCODE
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//CREATEUSER
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);//创建时间
data.CUSTNAME = Convert.ToString(reader["CUSTNAME"]);//创建时间
data.ACCOUNTNAMEREF = Convert.ToString(reader["ACCOUNTNAMEREF"]);//创建时间
data.SWIFT = Convert.ToString(reader["SWIFT"]);
data.BANKAGENTNAME = Convert.ToString(reader["BANKAGENTNAME"]);
data.BANKADDR = Convert.ToString(reader["BANKADDR"]);
data.BANKACNO = Convert.ToString(reader["BANKACNO"]);
data.COUNTRYID = Convert.ToString(reader["COUNTRYID"]);
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
data.BANKNAME_ACCOUNT = Convert.ToString(reader["BANKACCOUNT"]);
data.ISINVDEF = Convert.ToString(reader["ISINVDEF"]);
data.ISINVDEFREF = Convert.ToString(reader["ISINVDEFREF"]);
#endregion
headList.Add(data);
}
reader.Close();
}
}
else {
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsClientAccount data = new MsClientAccount();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//GID
data.LINKID = (reader["LINKID"] == null ? "" : Convert.ToString(reader["LINKID"]));//公司关联id
data.CODENAME = (reader["CODENAME"] == null ? "" : Convert.ToString(reader["CODENAME"]));//CODENAME
data.CURRENCY = (reader["CURRENCY"] == null ? "" : Convert.ToString(reader["CURRENCY"]));//CURRENCY
data.BANKNAME = (reader["BANKNAME"] == null ? "" : Convert.ToString(reader["BANKNAME"]));//BANKNAME
data.ACCOUNT = (reader["ACCOUNT"] == null ? "" : Convert.ToString(reader["ACCOUNT"]));//ACCOUNT
data.ACCOUNTNAME = (reader["ACCOUNTNAME"] == null ? "" : Convert.ToString(reader["ACCOUNTNAME"]));//ACCOUNT
data.SUBJECTCODE = (reader["SUBJECTCODE"] == null ? "" : Convert.ToString(reader["SUBJECTCODE"]));//银行账户
data.REMARK = (reader["REMARK"] == null ? "" : Convert.ToString(reader["REMARK"]));//REMARK
data.FINANCESOFTCODE = (reader["FINANCESOFTCODE"] == null ? "" : Convert.ToString(reader["FINANCESOFTCODE"]));//FINANCESOFTCODE
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//CREATEUSER
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);//创建时间
data.CUSTNAME = Convert.ToString(reader["CUSTNAME"]);//创建时间
data.ACCOUNTNAMEREF = Convert.ToString(reader["ACCOUNTNAMEREF"]);//创建时间
data.SWIFT = Convert.ToString(reader["SWIFT"]);
data.BANKAGENTNAME = Convert.ToString(reader["BANKAGENTNAME"]);
data.BANKADDR = Convert.ToString(reader["BANKADDR"]);
data.BANKACNO = Convert.ToString(reader["BANKACNO"]);
data.COUNTRYID = Convert.ToString(reader["COUNTRYID"]);
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
data.BANKNAME_ACCOUNT = Convert.ToString(reader["BANKACCOUNT"]);
data.ISINVDEF = Convert.ToString(reader["ISINVDEF"]);
data.ISINVDEFREF = Convert.ToString(reader["ISINVDEFREF"]);
#endregion
headList.Add(data);
}
reader.Close();
}
}
if (isedit != "1")
{
MsClientAccount adata = new MsClientAccount();
#region Set DB data to Object
adata.GID = "";//GID
adata.LINKID = "";//公司关联id
adata.CODENAME = "";//CODENAME
adata.CURRENCY = "";//CURRENCY
adata.BANKNAME = "";//BANKNAME
adata.ACCOUNT = "";//ACCOUNT
adata.ACCOUNTNAME = "";//ACCOUNT
adata.SUBJECTCODE = "";//银行账户
adata.REMARK = "";//REMARK
adata.FINANCESOFTCODE = "";//FINANCESOFTCODE
adata.CREATEUSER = "";//CREATEUSER
adata.CUSTNAME = "";//创建时间
adata.ACCOUNTNAMEREF = "";//创建时间
adata.BANKNAME_ACCOUNT = "";
adata.ISINVDEF ="0";
adata.ISINVDEFREF ="否";
#endregion
headList.Add(adata);
}
return headList;
}
public static DBResult SaveBank(string GID, List<MsClientAccount> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_client_bank (GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,[REMARK],FINANCESOFTCODE,CREATEUSER,CREATETIME,ACCOUNTNAME,ISINVDEF)
values (@GID,@LINKID,@CODENAME,@CURRENCY,@BANKNAME,@ACCOUNT,@REMARK,@FINANCESOFTCODE,@CREATEUSER,@CREATETIME,@ACCOUNTNAME,@ISINVDEF) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update info_client_bank set CODENAME=@CODENAME,CURRENCY=@CURRENCY,BANKNAME=@BANKNAME,ACCOUNT=@ACCOUNT,REMARK=@REMARK,FINANCESOFTCODE=@FINANCESOFTCODE
,ACCOUNTNAME=@ACCOUNTNAME,ISINVDEF=@ISINVDEF where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.LINKID == "*" || enumValue.LINKID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdInsert, "@LINKID", DbType.String,GID);
db.AddInParameter(cmdInsert, "@CODENAME", DbType.String, enumValue.CODENAME);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@BANKNAME", DbType.String, enumValue.BANKNAME);
db.AddInParameter(cmdInsert, "@ACCOUNT", DbType.String, enumValue.ACCOUNT);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@FINANCESOFTCODE", DbType.String, enumValue.FINANCESOFTCODE);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString());
db.AddInParameter(cmdInsert, "@ACCOUNTNAME", DbType.String, enumValue.ACCOUNTNAME);
db.AddInParameter(cmdInsert, "@ISINVDEF", DbType.String, enumValue.ISINVDEF);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@CODENAME", DbType.String, enumValue.CODENAME);
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdUpdate, "@BANKNAME", DbType.String, enumValue.BANKNAME);
db.AddInParameter(cmdUpdate, "@ACCOUNT", DbType.String, enumValue.ACCOUNT);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@FINANCESOFTCODE", DbType.String, enumValue.FINANCESOFTCODE);
db.AddInParameter(cmdUpdate, "@ACCOUNTNAME", DbType.String, enumValue.ACCOUNTNAME);
db.AddInParameter(cmdUpdate, "@ISINVDEF", DbType.String, enumValue.ISINVDEF);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 收发货人信息
static public List<MsInfoShipper> GetShipperDataList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT shipperID,[codename],[SHORTNAME],[shipperdetail]");
strSql.Append(",[shippertype],[LOADADDRESS],[DELIVERADDRESS] ,[ISPUBLIC],SERVICECONTRACTNO,COUNTRY,ATTN,TEL,EMAIL,CORPID ");
strSql.Append(",(select SHORTNAME from info_client where CODENAME=info_shipper.codename) AS CUSTOMERNAME ");
strSql.Append(" from info_shipper where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by shipperID");
return SetShipperData(strSql);
}
static public MsInfoShipper GetShipperData(string condition)
{
MsInfoShipper data = null;
var list = GetShipperDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsInfoShipper();
}
return data;
}
private static List<MsInfoShipper> SetShipperData(StringBuilder strSql)
{
var headList = new List<MsInfoShipper>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsInfoShipper data = new MsInfoShipper();
#region Set DB data to Object
data.SHIPPERID = Convert.ToString(reader["SHIPPERID"]);
data.CODENAME = Convert.ToString(reader["CODENAME"]);
data.SHORTNAME = Convert.ToString(reader["SHORTNAME"]);
data.SHIPPERDETAIL = Convert.ToString(reader["SHIPPERDETAIL"]);
if (reader["SHIPPERTYPE"] != DBNull.Value)
data.SHIPPERTYPE = Convert.ToInt16(reader["SHIPPERTYPE"]);
if (reader["ISPUBLIC"] != DBNull.Value)
data.ISPUBLIC = Convert.ToBoolean(reader["ISPUBLIC"]);
data.SHIPPERDETAIL = Convert.ToString(reader["SHIPPERDETAIL"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["SERVICECONTRACTNO"] != DBNull.Value)
data.SERVICECONTRACTNO = Convert.ToString(reader["SERVICECONTRACTNO"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
data.ATTN = Convert.ToString(reader["ATTN"]);
data.TEL = Convert.ToString(reader["TEL"]);
data.EMAIL = Convert.ToString(reader["EMAIL"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 权限范围
/// <summary>
/// 该算法改为只限制销售
///
/// </summary>
/// <param name="tb"></param>
/// <param name="userid"></param>
/// <param name="username"></param>
/// <param name="companyid"></param>
/// <returns></returns>
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";// ISNULL(BLSTATUS,1)=0 and RANGETYPE='集团'
var cdc = new CommonDataContext();
var userinfo = cdc.VW_user_all.FirstOrDefault(x => x.USERID == userid);
if (userinfo == null) return (" 1=2 ");
if (userinfo != null && userinfo.ISSALEMAN== "true") {
//是销售 看不到录入人 不是自己且不为空的 Rangetype=个人 的往来单位
//str = $" (RANGETYPE='集团' or (RANGETYPE='个人' and (OPNAME='{username}' or SALE='{username}')))";//or isnull(OPNAME,'')=''
//20220901 又改成 如果查询者是销售 则受用户权限控制
//strSql.Append($" and ((RANGETYPE='个人' and (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' )) ) or RANGETYPE='集团' ) ");
//str = $" (RANGETYPE='集团' or (RANGETYPE='个人' and (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ))))";
str = $" ((RANGETYPE = '个人' and exists(select 1 from info_client_range where info_client_range.SHORTNAME = info_Client.SHORTNAME and USERID = '" + userid + $"')) or (SALE='{username}') or (OPNAME='{username}' or OPNAME in(select SHOWNAME from [user] where codename='{username}')) or RANGETYPE = '集团' )";
}
return str;
/*
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modExchangesUnit' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
str = " OPNAME='" + username + "' or SALE='" + username + "' or DOC='" + username + "'or OP='" + username + "' ";
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " OPNAME='" + Convert.ToString(reader["SHOWNAME"]) + "' or SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' or DOC='" + Convert.ToString(reader["SHOWNAME"]) + "' or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
}
else
{
str = str + " or OPNAME='" + Convert.ToString(reader["SHOWNAME"]) + "' or SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' or DOC='" + Convert.ToString(reader["SHOWNAME"]) + "' or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
};
}
reader.Close();
}
}
else
{
str = " UPPER(Corpid)='" + companyid + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(Corpid)='" + companyid + "'";
}
//20220823 增加对 info_client.TANGETYPE 的查询支持
//info_client.TANGETYPE='集团' 则都可以查看
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
var modCrmClientVisible = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modCrmClientVisible", userid);
if (modCrmClientVisible)
{
}
else
{
if (str != "") str += (" and ");
str += (" (OPNAME='" + username + "' or (ISNULL(BLSTATUS,1)=0)) ");
}
}
}
if (str != "")
{
str = "((" + str + ") or RANGETYPE='集团')";
}
return str;
*/
}
#endregion
#region 客户权限范围
/// <summary>
/// 2个人 1部门 0分公司
/// </summary>
/// <param name="bodyList"></param>
/// <param name="op"></param>
/// <param name="seltype"></param>
/// <param name="userid"></param>
/// <returns></returns>
public static DBResult InsertClientRange(List<MsClient> bodyList, string op,string seltype,string userid)
{
var result = new DBResult();
if (bodyList != null)
{
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in bodyList)
{
if (seltype == "2")
{//个人
var cmddeletefeedo = db.GetSqlStringCommand("insert into info_client_range select newid(),'" + enumValue.SHORTNAME + "',u.userid,'" + userid + "',GETDATE() from VW_user u where USERID IN (" + op + ") AND USERID NOT IN (SELECT USERID FROM info_client_range WHERE SHORTNAME='" + enumValue.SHORTNAME + "') ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
else if (seltype == "1")
{//部门
var cmddeletefeedo = db.GetSqlStringCommand("insert into info_client_range select newid(),'" + enumValue.SHORTNAME + "',u.userid,'" + userid + "',GETDATE() from VW_user u where deptgid IN (" + op + ") AND USERID NOT IN (SELECT USERID FROM info_client_range WHERE SHORTNAME='" + enumValue.SHORTNAME + "') ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
else if (seltype == "0")
{//分公司
var cmddeletefeedo = db.GetSqlStringCommand("insert into info_client_range select newid(),'" + enumValue.SHORTNAME + "',u.userid,'" + userid + "',GETDATE() from VW_user u where COMPANYID IN (" + op + ") AND USERID NOT IN (SELECT USERID FROM info_client_range WHERE SHORTNAME='" + enumValue.SHORTNAME + "') ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
}
return result;
}
/// <summary>
/// 删除人员、公司权限
/// seltype= 2:op是userid列表3全部1按部门0按公司
/// </summary>
/// <param name="bodyList"></param>
/// <param name="op"></param>
/// <param name="seltype"></param>
/// <param name="userid"></param>
/// <returns></returns>
public static DBResult DelClientRange(List<MsClient> bodyList, string op, string seltype, string userid)
{
var result = new DBResult();
if (bodyList != null)
{
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in bodyList)
{
if (seltype == "2")
{
var cmddeletefeedo = db.GetSqlStringCommand("delete from info_client_range where USERID IN (" + op + ") and SHORTNAME='"+enumValue.SHORTNAME+"' ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
else if (seltype == "1")
{
var cmddeletefeedo = db.GetSqlStringCommand("delete from info_client_range where userid in (select userid from VW_user where deptgid IN (" + op + ")) and SHORTNAME='" + enumValue.SHORTNAME + "' ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
else if (seltype == "0")
{
var cmddeletefeedo = db.GetSqlStringCommand("delete from info_client_range where userid in (select userid from VW_user where companyid IN (" + op + ")) and SHORTNAME='" + enumValue.SHORTNAME + "' ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
else if (seltype == "3")
{
var cmddeletefeedo = db.GetSqlStringCommand("delete from info_client_range where SHORTNAME='" + enumValue.SHORTNAME + "' ");
db.ExecuteNonQuery(cmddeletefeedo, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
}
return result;
}
#endregion
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(GID) AS CT from info_client (NOLOCK) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
static public string GetMaxNum()
{
var strSql = new StringBuilder();
strSql.Append("select ISNULL(max(cast(CUSTNUM as int)),0) as maxxh from info_client(NOLOCK) ");
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt32(reader["maxxh"]);
}
reader.Close();
}
ct = ct + 1;
var custnum = ct.ToString();
if (custnum.Length < 7) {
while (custnum.Length < 7) {
custnum = "0" + custnum;
}
}
return custnum;
}
static public int GetShipperRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(info_shipper) AS CT from info_shipper (NOLOCK) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
static public int GetFeeTemplateCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(GID) AS CT from Cust_Truck_feetemplate (NOLOCK) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
static public bool ISCUSTUSE(string CUSTNAME)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(CUSTNAME) AS CT from v_all_client (NOLOCK) where CUSTNAME='" + CUSTNAME + "'");
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
if (ct > 0)
return true;
else
return false;
}
public static DBResult UpdateEmail(string userid, string email)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase("SHIPPINGBOX");
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@" Update UserInfo set email=@Email where mobile=@Mobile ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@Email", DbType.String, email);
db.AddInParameter(cmdUpdate, "@Mobile", DbType.String, userid);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult UpdateCust(string gid, string shortname,string codename)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@" Update info_client set CODENAME=@CODENAME,SHORTNAME=@SHORTNAME where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@CODENAME", DbType.String, codename);
db.AddInParameter(cmdUpdate, "@SHORTNAME", DbType.String, shortname);
db.AddInParameter(cmdUpdate, "@GID", DbType.String, gid);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#region BillNoSet
static public List<MsInfoClentGroup> GetClientGroupList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [CODENAME],[SHORTNAME],CODENAME + '-' + SHORTNAME AS CodeAndName,PCORPNAME");
strSql.Append(" from info_client where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetClientGroupData(strSql);
}
static public MsInfoClentGroup GetClientGroupData(string condition)
{
MsInfoClentGroup data = null;
var list = GetClientGroupList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsInfoClentGroup();
}
return data;
}
private static List<MsInfoClentGroup> SetClientGroupData(StringBuilder strSql)
{
var headList = new List<MsInfoClentGroup>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsInfoClentGroup data = new MsInfoClentGroup();
#region Set DB data to Object
data.PCORPNAME = Convert.ToString(reader["PCORPNAME"]);
data.CODENAME = Convert.ToString(reader["CODENAME"]);
data.SHORTNAME = Convert.ToString(reader["SHORTNAME"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 账期列表
public static DBResult SaveAccDateDetail(MsInfoContract headData, List<Info_Client_ACCDATEmb> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into Info_Client_ACCDATE (GID,LINKGID,CONTRACTGID,BGNDATE,ENDDATE,OPLBNAME,SALE,ACCTYPE,ACCSTARTDATE,ACCMONTH,ACCDAYS,ALLOWAMOUNT,REMARK,MODIFIEDUSER,MODIFIEDTIME,BSSOURCE,COMMISSIONRATE)
values (@GID,@LINKGID,@CONTRACTGID,@BGNDATE,@ENDDATE,@OPLBNAME,@SALE,@ACCTYPE,@ACCSTARTDATE,@ACCMONTH,@ACCDAYS,@ALLOWAMOUNT,@REMARK,@MODIFIEDUSER,@MODIFIEDTIME,@BSSOURCE,@COMMISSIONRATE) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update Info_Client_ACCDATE set BGNDATE=@BGNDATE,ENDDATE=@ENDDATE,OPLBNAME=@OPLBNAME,SALE=@SALE,ACCTYPE=@ACCTYPE,ACCSTARTDATE=@ACCSTARTDATE,ACCMONTH=@ACCMONTH,ACCDAYS=@ACCDAYS,ALLOWAMOUNT=@ALLOWAMOUNT,REMARK=@REMARK,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME,BSSOURCE=@BSSOURCE,COMMISSIONRATE=@COMMISSIONRATE where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.COMMISSIONRATE == "" || enumValue.COMMISSIONRATE == null) enumValue.COMMISSIONRATE = "0";
if (enumValue.CONTRACTGID == "*" || enumValue.CONTRACTGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@CONTRACTGID", DbType.String, headData.GID);
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, headData.LINKID);
db.AddInParameter(cmdInsert, "@BGNDATE", DbType.String, enumValue.BGNDATE);
db.AddInParameter(cmdInsert, "@ENDDATE", DbType.String, enumValue.ENDDATE);
db.AddInParameter(cmdInsert, "@OPLBNAME", DbType.String, enumValue.OPLBNAME);
db.AddInParameter(cmdInsert, "@SALE", DbType.String, enumValue.SALE);
db.AddInParameter(cmdInsert, "@BSSOURCE", DbType.String, enumValue.BSSOURCE);
db.AddInParameter(cmdInsert, "@COMMISSIONRATE", DbType.Decimal,Convert.ToDecimal(enumValue.COMMISSIONRATE));
db.AddInParameter(cmdInsert, "@ACCTYPE", DbType.String, enumValue.ACCTYPE);
db.AddInParameter(cmdInsert, "@ACCSTARTDATE", DbType.String, enumValue.ACCSTARTDATE);
db.AddInParameter(cmdInsert, "@ACCMONTH", DbType.String, enumValue.ACCMONTH);
db.AddInParameter(cmdInsert, "@ACCDAYS", DbType.String, enumValue.ACCDAYS);
db.AddInParameter(cmdInsert, "@ALLOWAMOUNT", DbType.String, enumValue.ALLOWAMOUNT);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString());
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, headData.LINKID);
db.AddInParameter(cmdUpdate, "@BGNDATE", DbType.String, enumValue.BGNDATE);
db.AddInParameter(cmdUpdate, "@ENDDATE", DbType.String, enumValue.ENDDATE);
db.AddInParameter(cmdUpdate, "@OPLBNAME", DbType.String, enumValue.OPLBNAME);
db.AddInParameter(cmdUpdate, "@SALE", DbType.String, enumValue.SALE);
db.AddInParameter(cmdUpdate, "@BSSOURCE", DbType.String, enumValue.BSSOURCE);
db.AddInParameter(cmdUpdate, "@COMMISSIONRATE", DbType.Decimal, Convert.ToDecimal(enumValue.COMMISSIONRATE));
db.AddInParameter(cmdUpdate, "@ACCTYPE", DbType.String, enumValue.ACCTYPE);
db.AddInParameter(cmdUpdate, "@ACCSTARTDATE", DbType.String, enumValue.ACCSTARTDATE);
db.AddInParameter(cmdUpdate, "@ACCMONTH", DbType.String, enumValue.ACCMONTH);
db.AddInParameter(cmdUpdate, "@ACCDAYS", DbType.String, enumValue.ACCDAYS);
db.AddInParameter(cmdUpdate, "@ALLOWAMOUNT", DbType.String, enumValue.ALLOWAMOUNT);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString());
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
static public List<Info_Client_ACCDATEmb> GetACCDATEList ( string strCondition )
{
var strSql = new StringBuilder();
strSql.Append(" SELECT GID,LINKGID,dbo.trimdate(BGNDATE) BGNDATE,dbo.trimdate(ENDDATE) ENDDATE,OPLBNAME ");
strSql.Append(" ,SALE,ACCTYPE,ACCSTARTDATE,ACCMONTH,ACCDAYS,ALLOWAMOUNT,MODIFIEDUSER,MODIFIEDUSER,dbo.GetUSER(MODIFIEDUSER) MODIFIEDUSERREF,MODIFIEDTIME,REMARK,CONTRACTGID,BSSOURCE,COMMISSIONRATE ");
strSql.Append(" from Info_Client_ACCDATE ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetACCDATEData(strSql);
}
private static List<Info_Client_ACCDATEmb> SetACCDATEData ( StringBuilder strSql )
{
var headList = new List<Info_Client_ACCDATEmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Info_Client_ACCDATEmb data = new Info_Client_ACCDATEmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
data.CONTRACTGID = Convert.ToString(reader["CONTRACTGID"]);
data.BGNDATE = Convert.ToString(reader["BGNDATE"]);
data.ENDDATE = Convert.ToString(reader["ENDDATE"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
if (reader["COMMISSIONRATE"] != DBNull.Value)
data.COMMISSIONRATE = Convert.ToString(reader["COMMISSIONRATE"]);//状态1
data.ACCTYPE = Convert.ToString(reader["ACCTYPE"]);
data.ACCSTARTDATE = Convert.ToString(reader["ACCSTARTDATE"]);
data.ACCMONTH = Convert.ToString(reader["ACCMONTH"]);
data.ACCDAYS = Convert.ToString(reader["ACCDAYS"]);
data.ALLOWAMOUNT = Convert.ToString(reader["ALLOWAMOUNT"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 固定费用维护
static public List<Info_Client_GDFYWHmb> GetGDFYWHList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,FEENAME,CUSTOMERNAME,UNIT");
strSql.Append(",CURRENCY,UNITPRICE,REMARK,CREATEUSER,CREATETIME,EXCHANGERATE,ISCTN,TAXRATE,TAX");
strSql.Append(",(case ISCTN when 1 then '是' else '否' end) as ISCTNREF,ISINVOICE,ISADVANCEDPAY,FEEFRT ");
strSql.Append(" from cust_fee_templatedetail ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
return SetBodyData(strSql);
}
private static List<Info_Client_GDFYWHmb> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<Info_Client_GDFYWHmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Info_Client_GDFYWHmb data = new Info_Client_GDFYWHmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]);
if (reader["EXCHANGERATE"] != DBNull.Value)
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
if (reader["TAXRATE"] != DBNull.Value)
data.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]);
if (reader["TAX"] != DBNull.Value)
data.TAX = Convert.ToDecimal(reader["TAX"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.UNIT = Convert.ToString(reader["UNIT"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.FEEFRT = Convert.ToString(reader["FEEFRT"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
if (reader["ISCTN"] != DBNull.Value)
data.ISCTN = Convert.ToBoolean(reader["ISCTN"]);
data.ISCTNREF = Convert.ToString(reader["ISCTNREF"]);
if (reader["ISINVOICE"] != DBNull.Value)
data.ISINVOICE = Convert.ToBoolean(reader["ISINVOICE"]);
if (reader["ISADVANCEDPAY"] != DBNull.Value)
data.ISADVANCEDPAY = Convert.ToBoolean(reader["ISADVANCEDPAY"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 获得结算日期
static public STLDATEmb GetSTLDATE ( string CUSTOMERNAME,string OPLBNAME,string BUSDATE,string SALE )
{
var strcondition=new StringBuilder();
strcondition.Append(" LINKGID=(SELECT GID from info_client where Shortname='" + CUSTOMERNAME
+ "') and Convert(datetime,'" + BUSDATE + "') between BGNDATE and ENDDATE and (OPLBNAME='" + OPLBNAME + "' or ISNULL(OPLBNAME,'')='') ");
if (!string.IsNullOrEmpty(SALE))
{
strcondition.Append(" and (isnull(SALE,'')='" + SALE + "' or isnull(SALE,'')='') ");
}
else {
strcondition.Append(" and isnull(SALE,'')='' ");
}
strcondition.Append(" order by SALE desc,BGNDATE ASC ");
var ClientACCDATEList = GetACCDATEList(strcondition.ToString());
if (ClientACCDATEList.Count==0){
var _r=new STLDATEmb();
_r.STLDATE=BUSDATE;
_r.STLNAME = "";
_r.BSSOURCE = "";
return _r;
}else{
var CA = ClientACCDATEList[0];
var _r = new STLDATEmb();
_r.STLNAME = CA.ACCTYPE;
_r.BSSOURCE = CA.BSSOURCE;
if (CA.ACCTYPE == "月结") {
//延迟月份 指定日
var Date_0=Convert.ToDateTime(BUSDATE);
var year_0 =Date_0.Year;
var month_0=Date_0.Month;
var day_0 = Date_0.Day;
var month = Convert.ToInt32(CA.ACCMONTH);
if (month<=0) month=1;
//var tmonth = Convert.ToInt32((Math.Ceiling(Convert.ToDecimal(month_0 / month)) + 1) * month );
//if (tmonth > 12) {
// var years = Convert.ToDouble(tmonth / 12);
// tmonth = tmonth % 12;
// year_0=year_0+Convert.ToInt32( Math.Floor(years));
//}
var day = Convert.ToInt32(CA.ACCDAYS);
//var d = new DateTime();
var d = Date_0.AddMonths(month);
if (day > 28) {
d = new DateTime(d.Year, d.Month, 1).AddMonths(1).AddDays(-1);
// d = Convert.ToDateTime(d).AddMonths(1).AddDays(-1);
}else{
if (day == 0) {
d = Date_0.AddMonths(month);
}else
d = new DateTime(d.Year, d.Month, day);
}
_r.STLDATE = d.ToShortDateString();
return _r;
}else
if (CA.ACCTYPE == "约定天数")// CA.ACCTYPE == "固定期限"||
{
var month = Convert.ToInt32(CA.ACCMONTH);
var Date = Convert.ToDateTime(BUSDATE);//.AddMonths(month);
Date = Date.AddDays(Convert.ToInt32(CA.ACCDAYS));
_r.STLDATE = Date.ToShortDateString();
return _r;
}
else
if (CA.ACCTYPE == "旬结")// CA.ACCTYPE == "固定期限"||
{
var month = Convert.ToInt32(CA.ACCMONTH);
var Date = Convert.ToDateTime(BUSDATE);//.AddMonths(month);
Date = Date.AddDays(Convert.ToInt32(10));
_r.STLDATE = Date.ToShortDateString();
return _r;
}
else
if (CA.ACCTYPE == "半月结")
{
var _busdate = Convert.ToDateTime(BUSDATE);
var Date = Convert.ToDateTime(BUSDATE);
if (_busdate.Day < 16)
{
var TMPDAYS =Convert.ToInt32(CA.ACCDAYS);
if (Convert.ToInt32(CA.ACCDAYS) > 28) {
var tmpdate= new DateTime(_busdate.Year, _busdate.Month,1);
tmpdate = tmpdate.AddMonths(1).AddDays(-1);
if (tmpdate.Day < Convert.ToInt32(CA.ACCDAYS)) TMPDAYS = tmpdate.Day;
}
Date = new DateTime(_busdate.Year, _busdate.Month, TMPDAYS);
}
else
{
var TMPDAYS = Convert.ToInt32(CA.ACCMONTH);
if (Convert.ToInt32(CA.ACCDAYS) > 28)
{
var tmpdate = new DateTime(_busdate.Year, _busdate.Month, 1);
tmpdate = tmpdate.AddMonths(2).AddDays(-1);
if (tmpdate.Day < Convert.ToInt32(CA.ACCMONTH)) TMPDAYS = tmpdate.Day;
}
Date = new DateTime(_busdate.Year, _busdate.Month, TMPDAYS);
Date = Date.AddMonths(1);
}
_r.STLDATE = Date.ToShortDateString();
return _r;
}
else
if (CA.ACCTYPE == "季结")
{
var _busdate = Convert.ToDateTime(BUSDATE);
var Date = _busdate.AddDays(Convert.ToInt32(Convert.ToInt16(CA.ACCMONTH)*90));
_r.STLDATE = Date.ToShortDateString();
return _r;
}
else
{
_r.STLDATE = BUSDATE;
return _r;
}
/*if (CA.ACCTYPE == "约定天数")
{
}*/
}
}
#endregion
#region 获得账期天数
static public STLDATEmb GetSTLDAYS ( string CUSTOMERNAME, string OPLBNAME, string BUSDATE, string SALE )
{
var strcondition = new StringBuilder();
strcondition.Append(" LINKGID=(SELECT GID from info_client where Shortname='" + CUSTOMERNAME
+ "') and Convert(datetime,(dbo.trimdate(BGNDATE)+' 00:00:00'))<=Convert(datetime,'" + BUSDATE + "') "
+ " and Convert(datetime,(dbo.trimdate(ENDDATE)+' 23:59:59'))>=Convert(datetime,'" + BUSDATE + "') and OPLBNAME='" + OPLBNAME + "' ");
if (!string.IsNullOrEmpty(SALE))
{
strcondition.Append(" and SALE='" + SALE + "' ");
}
strcondition.Append(" order by BGNDATE ");
var ClientACCDATEList = GetACCDATEList(strcondition.ToString());
if (ClientACCDATEList.Count == 0)
{
var _r = new STLDATEmb();
_r.STLDATE = BUSDATE;
_r.STLNAME = "";
return _r;
}
else
{
var CA = ClientACCDATEList[0];
var _r = new STLDATEmb();
_r.STLNAME = CA.ACCTYPE;
if (CA.ACCTYPE == "月结")
{
//延迟月份 指定日
var Date_0 = Convert.ToDateTime(BUSDATE);
var year_0 = Date_0.Year;
var month_0 = Date_0.Month;
var month = Convert.ToInt32(CA.ACCMONTH);
if (month <= 0) month = 1;
var tmonth = Convert.ToInt32((Math.Ceiling(Convert.ToDecimal(month_0 / month)) + 1) * month);
if (tmonth > 12)
{
tmonth = tmonth % 12;
var years = Convert.ToDouble(year_0 / 12);
year_0 = year_0 + Convert.ToInt32(Math.Floor(years));
}
var day = Convert.ToInt32(CA.ACCDAYS);
var d = new DateTime();
if (day > 28)
{
var Date = new DateTime(year_0, tmonth, 1);
d = Convert.ToDateTime(Date).AddMonths(1).AddDays(-1);
}
else
{
d = new DateTime(year_0, tmonth, day);
}
DateTime d1 = Convert.ToDateTime(BUSDATE);
DateTime d2 = Convert.ToDateTime(d.ToShortDateString());
TimeSpan d3 = d2.Subtract(d1);
_r.STLDAYS = d3.Days.ToString();
return _r;
}
else
if (CA.ACCTYPE == "约定天数")// CA.ACCTYPE == "固定期限"||
{
var month = Convert.ToInt32(CA.ACCMONTH);
var Date = Convert.ToDateTime(BUSDATE);//.AddMonths(month);
Date = Date.AddDays(Convert.ToInt32(CA.ACCDAYS));
_r.STLDATE = Date.ToShortDateString();
DateTime d1 = Convert.ToDateTime(BUSDATE);
DateTime d2 = Convert.ToDateTime(Date.ToShortDateString());
TimeSpan d3 = d2.Subtract(d1);
_r.STLDAYS = d3.Days.ToString();
return _r;
}
else
if (CA.ACCTYPE == "半月结")
{
var _busdate = Convert.ToDateTime(BUSDATE);
var Date = Convert.ToDateTime(BUSDATE);
if (_busdate.Day < 16)
{
Date = new DateTime(_busdate.Year, _busdate.Month, Convert.ToInt32(CA.ACCDAYS));
}
else
{
Date = new DateTime(_busdate.Year, _busdate.Month, Convert.ToInt32(CA.ACCMONTH));
Date = Date.AddMonths(1);
}
_r.STLDATE = Date.ToShortDateString();
DateTime d1 = Convert.ToDateTime(BUSDATE);
DateTime d2 = Convert.ToDateTime(Date.ToShortDateString());
TimeSpan d3 = d2.Subtract(d1);
_r.STLDAYS = d3.Days.ToString();
return _r;
}
else
{
_r.STLDATE = BUSDATE;
return _r;
}
/*if (CA.ACCTYPE == "约定天数")
{
}*/
}
}
#endregion
#region 根据业务BSNO判断该客户该业务当前属于何种账期类型。如无账期信息或者有但是没有找到则返回一条acctype=票结 的查询结果
/// <summary>
/// 根据业务BSNO判断该客户该业务当前属于何种账期类型(日期用ETD)。如无账期信息或者有但是没有找到则返回一条acctype=票结 的查询结果
/// 如果实际上有多条满足条件,则会返回其中的某一条
/// </summary>
/// <param name="BSNO"></param>
/// <returns></returns>
public static Info_Client_ACCDATE_mb GetCustAccdate(string BSNO)
{
var result = new Info_Client_ACCDATE_mb();
result.ACCTYPE = "票结";
var cdc = new CommonDataContext();
var bs = cdc.v_op_bs.FirstOrDefault(x => x.BSNO == BSNO);
if (bs == null || string.IsNullOrWhiteSpace(bs.CUSTOMERNAME))
{
return result;
}
var cust = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == bs.CUSTOMERNAME);
var accdatainfoList = cdc.Info_Client_ACCDATE.Where(x => x.LINKGID == cust.GID).ToList();
if (accdatainfoList == null || accdatainfoList.Count == 0)
{
return result;
}
else
{
//账期信息有三个维度 sale oplbname 有效期
//优先找全部符合的 如无则寻找有销售无oplbname的
//如无则寻找有oplbname无销售的
//如无则寻找没有销售没有业务类型只有有效期的
//
//1首先按 sale oplbname 有效期 找
foreach (var item in accdatainfoList)
{
try
{
//1首先按 sale oplbname 有效期 找
if (item.OPLBNAME != bs.OPLBNAME || item.SALE != bs.SALE) continue;
var settledate = Convert.ToDateTime(bs.ETD);
var startdate = Convert.ToDateTime(item.BGNDATE);
var enddate = Convert.ToDateTime(item.ENDDATE);
if (startdate <= settledate && enddate >= settledate)
{
result = item;
return result;
}
}
catch (Exception ex)
{
return result;
}
}
////2按sale找
foreach (var item in accdatainfoList)
{
try
{
//2按sale找
if (item.SALE != bs.SALE) continue;
var settledate = Convert.ToDateTime(bs.ETD);
var startdate = Convert.ToDateTime(item.BGNDATE);
var enddate = Convert.ToDateTime(item.ENDDATE);
if (startdate <= settledate && enddate >= settledate)
{
result = item;
return result;
}
}
catch (Exception ex)
{
return result;
}
}
//3按业务类型找
foreach (var item in accdatainfoList)
{
try
{
//3按业务类型找
if (item.OPLBNAME != bs.OPLBNAME) continue;
var settledate = Convert.ToDateTime(bs.ETD);
var startdate = Convert.ToDateTime(item.BGNDATE);
var enddate = Convert.ToDateTime(item.ENDDATE);
if (startdate <= settledate && enddate >= settledate)
{
result = item;
return result;
}
}
catch (Exception ex)
{
return result;
}
}
//4按指定业务类型和销售没找到 找业务类型空白的
foreach (var item in accdatainfoList)
{
try
{
//找业务类型空白的
if (!string.IsNullOrWhiteSpace(item.OPLBNAME))
continue;
var settledate = Convert.ToDateTime(bs.ETD);
var startdate = Convert.ToDateTime(item.BGNDATE);
var enddate = Convert.ToDateTime(item.ENDDATE);
if (startdate <= settledate && enddate >= settledate)
{
result = item;
return result;
}
}
catch (Exception ex)
{
return result;
}
}
if (result.ACCTYPE == "") result.ACCTYPE = "票结";
}
return result;
}
public static string GetCustAcctype(string BSNO) {
var accdate = GetCustAccdate(BSNO);
return accdate.ACCTYPE;
}
#endregion
#region 往来单位审核
public static DBResult IC_Start ( List<MsClient> _List, string USERID ) //申请签入
{
var WorkFlowName = "MsInfoClient_Audit";
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var _bill in _List)
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, _bill.GID, USERID,_bill.SHORTNAME, _bill.GID,"");
if (WorkResult.Success == true)
{
if (WorkResult.islast != true)
{
var cmdupdate = db.GetSqlStringCommand("update Info_client set BLSTATUS=2 where GID=@GID and BLSTATUS in(1,6) ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, _bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
else {
var cmdupdate = db.GetSqlStringCommand("update Info_client set BLSTATUS=0 where GID=@GID and BLSTATUS in(1,6) ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, _bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
}
else
{
result.Success = false;
result.Message = $"提交错误![{WorkResult.Message}]";
tran.Rollback();
return result;
}
}
var r2 = MsInfoClientDAL.SetRange(_List, USERID);
result = new DBResult();
result.Success = true;
result.Message = "提交成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
//return result;
}
}
return result;
}
public static DBResult IC_back ( List<MsClient> _List, string USERID ) //申请签入_撤回
{
var WorkFlowName = "MsInfoClient_Audit";
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var _bill in _List)
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, _bill.GID, USERID);
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update Info_Client set BLSTATUS=1 where GID=@GID and BLSTATUS=2 ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, _bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
result.Success = false;
result.Message = "提交错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "提交成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
//return result;
}
}
return result;
}
public static DBResult IC_Auditback ( List<MsClient> _List, string USERID ) //申请签入_驳回
{
var WorkFlowName = "MsInfoClient_Audit";
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var _bill in _List)
{
Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo(WorkFlowName, _bill.GID, USERID, "");
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update Info_client set BLSTATUS=6 where GID=@GID and BLSTATUS in (2,0) ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, _bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
result.Success = false;
result.Message = "提交错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "提交成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
//return result;
}
}
return result;
}
public static DBResult IC_Audit ( List<MsClient> _List, string USERID ) //申请签入_驳回
{
var WorkFlowName = "MsInfoClient_Audit";
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var _bill in _List)
{
Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo(WorkFlowName, _bill.GID, USERID,_bill.SHORTNAME);
if (WorkResult.Success == true)
{
if (WorkResult.islast == true)
{
var cmdupdate = db.GetSqlStringCommand("update Info_Client set BLSTATUS=0 where GID=@GID and BLSTATUS =2 ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, _bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
}
}
else
{
result.Success = false;
result.Message = "提交错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "提交成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
//return result;
}
}
return result;
}
#endregion
#region 往来单位图片
static public List<MsInfoClientImgmb> GetImgList(string strCondition, string sort = null,string USERID="1")
{
var strSql = new StringBuilder();
var rangstr = "";
if (USERID == "1") rangstr = "1=2";
else
{
rangstr = BasicDataRefDAL.GetVisableRange("modInfoClient_info", USERID, "", "CREATEUSER");
}
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by NAME ");
}
return SetImgData(strSql);
}
private static List<MsInfoClientImgmb> SetImgData(StringBuilder strSql)//, List<HcUtility.Core.Fieldmb> fieldlist
{
var headList = new List<MsInfoClientImgmb>();
Database db = DatabaseFactory.CreateDatabase();
string sql = MsInfoClientImgmb.getSQL() + strSql;
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
////根据字段名设定同名属性值
MsInfoClientImgmb data = new MsInfoClientImgmb();
data.SetExtendValue(reader);
data.SetValue("INDATABASE_OLD", data.GetValue("INDATABASE"));
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 独立版本功能 设定往来单位权限
public static DBResult SetRange(string RANGETYPE, string data,string USERID)
{
//1集团 2分公司 3个人
//1集团 即清空所有往来单位人员权限
//2分公司 效果为选中所有该往来单位录入人的本公司人员
//3个人 效果为选中录入人本人 和他所在公司的操作部、财务
var dataList = JsonConvert.Deserialize<List<MsClient>>(data);
var result = new DBResult();
//op为一串用逗号隔开的带单引号userid 形如 'aaaaa','bbbbb'
var op = "";
var seltype = "2";
var cdc = new CommonDataContext();
if (RANGETYPE == "1")
{
result = MsInfoClientDAL.DelClientRange(dataList, op, "3", USERID);
/// //1集团 2分公司 3个人
DoSetRangeType(dataList, "集团");
}
if (RANGETYPE == "2")
{
result = MsInfoClientDAL.DelClientRange(dataList, op, "3", USERID);
//获取本公司的所有人gid
var = new List<VW_user_all_md>();
foreach (var item in dataList)
{
= cdc.VW_user_all.Where(x => x.COMPANYID == item.CORPID).ToList();
op = GetUseridStr();
var templist = dataList.Where(x => x.GID == item.GID).ToList();
result = MsInfoClientDAL.InsertClientRange(templist, op, seltype, USERID);
if (!result.Success) return result;
}
DoSetRangeType(dataList, "分公司");
//SetInfoclientLogic_range(dataList, RANGETYPE);
}
if (RANGETYPE == "3")
{
//20230823 改为不删除当前人员权限
//result = MsInfoClientDAL.DelClientRange(dataList, op, "3", USERID);
//获取本公司非销售人员
//user_userattribute.userid属于本公司 且attri 3C91140E-6FB6-4B5A-B5AB-30E59E3CBBED
//var 本公司人员 = new List<VW_user_md>();
foreach (var item in dataList)
{
//本公司人员 = cdc.VW_user_all.Where(x => x.COMPANYID == item.CORPID).ToList();
//改为所有公司的所有销售人员
var = cdc.VW_user_all.FirstOrDefault(x => x.SHOWNAME == item.OPNAME);
var = cdc.VW_user_all.FirstOrDefault(x => x.SHOWNAME == item.SALE);
var = cdc.VW_user_all.Where(x => x.USERID!= .USERID).ToList();
op = str();
if (op != "") op += ",";
op += $"'{本人.USERID}'";
if (!string.IsNullOrWhiteSpace(.USERID))
{
op += $",'{往来单位销售.USERID}'";
}
//20230823 改为不删除当前人员权限
result = MsInfoClientDAL.DelClientRange(dataList, op, "2", USERID);
//2个人1部门0分公司
result = MsInfoClientDAL.InsertClientRange(dataList, op, seltype, USERID);
if (!result.Success) return result;
}
DoSetRangeType(dataList, "个人");
//SetInfoclientLogic_range(dataList, RANGETYPE);
}
return result;
}
public static DBResult SetRange(string data, string USERID)
{
//1集团 2分公司 3个人
//1集团 即清空所有往来单位人员权限
//2分公司 效果为选中所有该往来单位录入人的本公司人员
//3个人 效果为选中录入人本人 和他所在公司的操作部、财务
var dataList = JsonConvert.Deserialize<List<MsClient>>(data);
var result = SetRange(dataList, USERID);
//var result = new DBResult();
////op为一串用逗号隔开的带单引号userid 形如 'aaaaa','bbbbb'
//var op = "";
//var seltype = "2";
//var cdc = new CommonDataContext();
//var 集团List = new List<MsClient>();
//var 个人List = new List<MsClient>();
//foreach (var item in dataList)
//{
// if (item.RANGETYPE == "集团")
// {
// 集团List.Add(item);
// }
// if (item.RANGETYPE == "个人")
// {
// 个人List.Add(item);
// }
//}
//if (集团List != null && 集团List.Count > 0)
//{
// result = MsInfoClientDAL.DelClientRange(集团List, op, "3", USERID);
// /// //1集团 2分公司 3个人
// //DoSetRangeType(dataList, "集团");
//}
//if (个人List != null && 个人List.Count > 0)
//{
// {
// result = MsInfoClientDAL.DelClientRange(个人List, op, "3", USERID);
// //获取本公司非销售人员
// //user_userattribute.userid属于本公司 且attri 3C91140E-6FB6-4B5A-B5AB-30E59E3CBBED
// //var 本公司人员 = new List<VW_user_md>();
// foreach (var item in 个人List)
// {
// //本公司人员 = cdc.VW_user_all.Where(x => x.COMPANYID == item.CORPID).ToList();
// //改为所有公司的所有销售人员
// var 本人 = cdc.VW_user_all.FirstOrDefault(x => x.SHOWNAME == item.OPNAME);
// var 全部人员 = cdc.VW_user_all.Where(x => x.USERID != 本人.USERID).ToList();
// op = 获取非销售人员str(全部人员);
// if (op != "") op += ",";
// op += $"'{本人.USERID}'";
// result = MsInfoClientDAL.InsertClientRange(个人List, op, "2", USERID);
// if (!result.Success) return result;
// }
// //DoSetRangeType(dataList, "个人");
// //SetInfoclientLogic_range(dataList, RANGETYPE);
// }
//}
return result;
}
public static DBResult SetRange(List<MsClient> dataList, string USERID)
{
//1集团 2分公司 3个人
//1集团 即清空所有往来单位人员权限
//2分公司 效果为选中所有该往来单位录入人的本公司人员
//3个人 效果为选中录入人本人 和他所在公司的操作部、财务
//var dataList = JsonConvert.Deserialize<List<MsClient>>(data);
var result = new DBResult();
//op为一串用逗号隔开的带单引号userid 形如 'aaaaa','bbbbb'
var op = "";
var seltype = "2";
var cdc = new CommonDataContext();
var List = new List<MsClient>();
var List = new List<MsClient>();
foreach (var item in dataList)
{
if (item.RANGETYPE == "集团")
{
List.Add(item);
}
if (item.RANGETYPE == "个人")
{
List.Add(item);
}
}
if (List != null && List.Count > 0)
{
result = MsInfoClientDAL.DelClientRange(List, op, "3", USERID);
/// //1集团 2分公司 3个人
//DoSetRangeType(dataList, "集团");
}
if (List != null && List.Count > 0)
{
{
//获取本公司非销售人员
//user_userattribute.userid属于本公司 且attri 3C91140E-6FB6-4B5A-B5AB-30E59E3CBBED
//var 本公司人员 = new List<VW_user_md>();
foreach (var item in List)
{
//本公司人员 = cdc.VW_user_all.Where(x => x.COMPANYID == item.CORPID).ToList();
//改为所有公司的所有销售人员
var = cdc.VW_user_all.FirstOrDefault(x => x.SHOWNAME == item.OPNAME);
var = cdc.VW_user_all.FirstOrDefault(x => x.SHOWNAME == item.SALE);
var = cdc.VW_user_all.Where(x => x.USERID != .USERID).ToList();
op = str();
if (op != "") op += ",";
op += $"'{本人.USERID}'";
if (!string.IsNullOrWhiteSpace(.USERID))
{
op += $",'{往来单位销售.USERID}'";
}
result = MsInfoClientDAL.DelClientRange(List, op, "2", USERID);
result = MsInfoClientDAL.InsertClientRange(List, op, "2", USERID);
if (!result.Success) return result;
}
//DoSetRangeType(dataList, "个人");
//SetInfoclientLogic_range(dataList, RANGETYPE);
}
}
return result;
}
private static void DoSetRangeType(List<MsClient> dataList,string RANGETYPE) {
var GIDList = dataList.Select(s => s.GID).ToList();
var GIDListStr = "";
foreach (var gid in GIDList)
{
if (GIDListStr != "") GIDListStr += ",";
GIDListStr += "'" + gid + "'";
}
var _r = BasicDataRefDAL.ExecSql(" UPDATE info_client set RANGETYPE='"+ RANGETYPE + "' where GID in(" + GIDListStr + ")");
}
private static string GetUseridStr(List<VW_user_all_md> vwuserlist)
{
var result = "";
foreach (var user in vwuserlist)
{
if (result != "") result += ",";
result += $"'{user.USERID}'";
}
return result;
}
private static string str(List<VW_user_all_md> vwuserlist)
{
var cdc = new CommonDataContext();
var useridlist = vwuserlist.Select(s => s.USERID).ToList();
var List = cdc.user_userattribute.Where(x => useridlist.Contains(x.USERID) && x.ATTRIBUTEID == "3C91140E-6FB6-4B5A-B5AB-30E59E3CBBED" && x.VALUE == "false").ToList();
var UseridList = List.Select(s => s.USERID).ToList();
var result = "";
foreach (var userid in UseridList)
{
if (result != "") result += ",";
result += $"'{userid}'";
}
return result;
}
private static void SetInfoclientLogic_range(List<MsClient> MsClients, string RANGETYPE) {
foreach (var client in MsClients) {
var logicinfo= new Dictionary<string, string>();
logicinfo.Add("权限范围", RANGETYPE);
BasicDataRefDAL.SaveLogicInfo(client.GID, "权限范围", logicinfo);
}
}
#endregion
#region 参照部分
#region FileList
static public List<MsUpLoadFile> GetUpLoadFileList ( string strCondition )
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,PID,FILENAME,FILETYPE,IMGFILE,UPLOADEMPLY,UPLOADDATE,FILEPATH");
strSql.Append(" from info_files ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetUpLoadFileData(strSql);
}
private static List<MsUpLoadFile> SetUpLoadFileData ( StringBuilder strSql )
{
var headList = new List<MsUpLoadFile>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsUpLoadFile data = new MsUpLoadFile();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PID = Convert.ToString(reader["PID"]);
data.UPLOADEMPLY = Convert.ToString(reader["UPLOADEMPLY"]);
data.UPLOADDATE = Convert.ToString(reader["UPLOADDATE"]);
data.FILETYPE = Convert.ToString(reader["FILETYPE"]);
data.FILENAME = Convert.ToString(reader["FILENAME"]);
data.FILEPATH = Convert.ToString(reader["FILEPATH"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static bool UpdateFileData ( HttpRequestBase request, string filename,string Path, string GID, out string msg )
{
var isSucess = false;
msg = "";
Stream stream = new FileStream(filename, FileMode.Open);
byte[] data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
stream.Close();
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
const string insertSql = @" delete from info_files where PID=@PID0 "+
" insert info_files (GID,PID,UPLOADEMPLY,UPLOADDATE,FILENAME,FILETYPE,IMGFILE) "+
" VALUES(@GID,@PID,@UPLOADEMPLY,@UPLOADDATE,@FILENAME,@FILETYPE,@Image) ";
SqlParameter[] insertParms = new SqlParameter[] {
new SqlParameter("@GID",SqlDbType.VarChar),
new SqlParameter("@PID",SqlDbType.VarChar),
new SqlParameter("@UPLOADEMPLY",SqlDbType.VarChar),
new SqlParameter("@UPLOADDATE",SqlDbType.VarChar),
new SqlParameter("@FILENAME",SqlDbType.VarChar),
new SqlParameter("@FILETYPE",SqlDbType.VarChar),
new SqlParameter("@PID0",SqlDbType.VarChar),
new SqlParameter("@Image",SqlDbType.Image)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = GID;
insertParms[2].Value = CookieConfig.GetCookie_UserName(request);
insertParms[3].Value = DateTime.Now.ToString();
insertParms[4].Value = Path;
insertParms[5].Value = "结算单位联系人签名";
insertParms[6].Value = GID;
insertParms[7].Value = data;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, insertSql, insertParms);
sqlTran.Commit();
isSucess = true;//状态为1表示插入成功
}
catch (Exception execError)
{
isSucess = false;//有异常,插入失败
sqlTran.Rollback();
msg = execError.Message;
}
finally
{
SqlHelper.CloseConnection();
}
}
return isSucess;
}
static public int SaveFileList ( IList<MsUpLoadFile> tempFileEntities, string tempBSNO )
{
int iResult = 0;
const string SQL_INSERT = @"insert info_files (GID,PID,UPLOADEMPLY,UPLOADDATE,FILENAME,FILETYPE) VALUES(@GID,@PID,@UPLOADEMPLY,@UPLOADDATE,@FILENAME,@FILETYPE) ";
const string SQL_UPDATE = @"update info_files SET FILENAME=@FILENAME where GID=@GID";
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
foreach (MsUpLoadFile fileEntity in tempFileEntities)
{
if (fileEntity.PID == "*" || fileEntity.PID == "")
{
SqlParameter[] insertParms = new SqlParameter[] {
new SqlParameter("@GID",SqlDbType.VarChar),
new SqlParameter("@PID",SqlDbType.VarChar),
new SqlParameter("@UPLOADEMPLY",SqlDbType.VarChar),
new SqlParameter("@UPLOADDATE",SqlDbType.VarChar),
new SqlParameter("@FILENAME",SqlDbType.VarChar),
new SqlParameter("@FILETYPE",SqlDbType.VarChar)
};
insertParms[0].Value = fileEntity.GID;
insertParms[1].Value = tempBSNO;
insertParms[2].Value = fileEntity.UPLOADEMPLY;
insertParms[3].Value = fileEntity.UPLOADDATE;
insertParms[4].Value = fileEntity.FILENAME;
insertParms[5].Value = fileEntity.FILETYPE;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT, insertParms);
}
else
{
SqlParameter[] updateParms = new SqlParameter[] {
new SqlParameter("@FILENAME",SqlDbType.VarChar)
};
updateParms[0].Value = fileEntity.GID;
updateParms[1].Value = tempBSNO;
updateParms[2].Value = fileEntity.UPLOADEMPLY;
updateParms[3].Value = fileEntity.UPLOADDATE;
updateParms[4].Value = fileEntity.FILENAME;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE, updateParms);
}
}
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
static public int DeleteUploadFile ( string tempGId )
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
var strSql = new StringBuilder();
strSql.Append("Delete from info_files where ");
strSql.Append(" GId in (" + tempGId + ")");
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString());
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
}
public class InfoClientLimitDAL
{
public static DBResult DoSave(string InfoClientId,string data)
{
var headList = JsonConvert.Deserialize<List<Info_Client_Limit_md>>(data);
var result = new DBResult();
try
{
var cdc = new CommonDataContext();
if (headList == null || headList.Count == 0)
{
DoSet(InfoClientId);
}
else
{
var currHeadList = cdc.Info_Client_Limit.Where(x => x.InfoClientId == InfoClientId).ToList();
foreach (var head in headList)
{
var _count = BasicDataRefDAL.GetExist("info_client_limit_change", " pid='" + head.GID + "' ");
var currHead = currHeadList.FirstOrDefault(x => x.GID == head.GID);
if (currHead.TOTALLIMIT == head.TOTALLIMIT)
{
continue;
}
if (_count == 0)
{
//无原有变动日志 直接修改
currHead.TOTALLIMIT = head.TOTALLIMIT;
currHead.REMAINLIMIT = head.TOTALLIMIT;
cdc.Info_Client_Limit.AddOrUpdate(currHead);
}
else {
//需判断原有值,计算差值,并反应到所有日志记录
var addLimit = head.TOTALLIMIT - currHead.TOTALLIMIT;
var currbodyList = cdc.Info_Client_Limit_Change.Where(x => x.Pid == head.GID).ToList();
currHead.TOTALLIMIT = head.TOTALLIMIT;
currHead.REMAINLIMIT = currHead.REMAINLIMIT+ addLimit;
cdc.Info_Client_Limit.AddOrUpdate(currHead);
foreach (var body in currbodyList) {
body.AMOUNT2 += addLimit;
body.AMOUNT3 += addLimit;
}
}
cdc.SaveChanges();
}
}
result.OK();
}
catch (Exception ex)
{
result.SetErrorInfo(ex.Message);
}
return result;
}
public static DBResult DoSet(string GID) {
var result = new DBResult();
var cdc = new CommonDataContext();
var _list = cdc.info_client.Where(x => x.GID == GID).ToList();
if (_list == null || _list.Count == 0)
{
}
else {
var companyList = cdc.company.Where(x => 1 == 1).ToList();
//var currHeadList = cdc.Info_Client_Limit.Where(x => x.InfoClientId == GID).ToList();
foreach (var company in companyList)
{
DoSet(GID, company.GID);
}
}
return result;
}
private static DBResult DoSet(string InfoClientId,string SALECORPID)
{
var result = new DBResult();
try
{
var cdc = new CommonDataContext();
var _list = cdc.Info_Client_Limit.Where(x => x.InfoClientId == InfoClientId && x.SALECORPID== SALECORPID).ToList();
if (_list == null || _list.Count == 0)
{
var infoclient = cdc.info_client.First(x => x.GID == InfoClientId);
var newhead = new Info_Client_Limit_md();
newhead.GID = Guid.NewGuid().ToString();
newhead.SALECORPID = SALECORPID;
newhead.InfoClientId = InfoClientId;
newhead.CUSTOMERNAME = infoclient.SHORTNAME;
newhead.PCORPNAME = "";
newhead.TOTALLIMIT = 0;
newhead.CURRENTDEBT = 0;
newhead.REMAINLIMIT = 0;
cdc.Info_Client_Limit.Add(newhead);
cdc.SaveChanges();
}
//else
//{
// //已有更新
// var head = _list[0];
// head.PCORPNAME = PCORPNAME;
// head.TOTALLIMIT = TOTALLIMIT;
// cdc.Info_Client_Limit.AddOrUpdate(head);
// cdc.SaveChanges();
//}
result.OK();
}
catch (Exception ex)
{
result.SetErrorInfo(ex.Message);
}
return result;
}
public static DBResult GetHeadList(string GID)
{
var result = new DBResult();
try
{
var cdc = new CommonDataContext();
var head = new Info_Client_Limit_md();
var _list = cdc.Info_Client_Limit.Where(x => x.InfoClientId == GID).ToList();
if (_list == null || _list.Count == 0)
{
DoSet(GID);
return GetHeadList(GID);
}
else
{
}
result.OK("", _list);
result.totalCount= _list.Count;
}
catch (Exception ex)
{
result.SetErrorInfo(ex.Message);
}
return result;
}
public static DBResult GetBodyList(int start, int limit, string GID,string condition)
{
var result = new DBResult();
try
{
var cdc = new CommonDataContext();
Dictionary<string, string> dictionary = JsonConvert.Deserialize<Dictionary<string, string>>(condition);
var data = new List<Info_Client_Limit_Change_md>();
var alldata = 0;
QueryCollection queries = new QueryCollection();
if (dictionary != null && dictionary.Count>0)
{
if (dictionary.ContainsKey("CUSTNO") && !string.IsNullOrWhiteSpace(dictionary["CUSTNO"]))
{
queries.Add(new Query { Name = "CUSTNO", Operator = Query.Operators.Contains, Value = dictionary["CUSTNO"] });
}
if (dictionary.ContainsKey("BILLNO") && !string.IsNullOrWhiteSpace(dictionary["BILLNO"]))
{
queries.Add(new Query { Name = "BILLNO", Operator = Query.Operators.Contains, Value = dictionary["BILLNO"] });
}
}
else {
queries.Add(new Query { Name = "Id", Operator = Query.Operators.GreaterThan, Value = 0 });
}
//alldata = cdc.Info_Client_Limit_Change.Where(x => x.Pid == GID ).Count();
//data = cdc.Info_Client_Limit_Change
// .Where(x => x.Pid == GID)
// .OrderBy(o => o.Id)
// .Skip(start).Take(limit).ToList();
alldata = cdc.Info_Client_Limit_Change
.Where(x => x.Pid == GID)
.Where(queries.AsExpression<Info_Client_Limit_Change_md>())
.Count();
data = cdc.Info_Client_Limit_Change
.Where(x => x.Pid == GID)
.Where(queries.AsExpression<Info_Client_Limit_Change_md>())
.OrderByDescending(o => o.Id)
.Skip(start).Take(limit).ToList();
result.OK("", data);
result.totalCount = alldata;
}
catch (Exception ex)
{
result.SetErrorInfo(ex.Message);
}
return result;
}
}
/// <summary>
/// 用于查询和使用往来单位的欠费
/// </summary>
public class InfoClientLimitHelper
{
public Info_Client_Limit_md Head { get; set; }
//private Info_Client_Limit_Change_md lastchange { get; set; }
public v_op_bill_mb Bill { get; set; }
private string CHANGEUSER { get; set; }
private info_client_md customer { get; set; }
private List<Info_Client_Limit_Change_md> ChangeDetail { get; set; }
public InfoClientLimitHelper() { }
public bool canuse() {
if (Head != null && Head.GID != null && Head.GID != "")
{
return true;
}
else {
return false;
}
}
private CommonDataContext cdc { get; set; } = new CommonDataContext();
/// <summary>
/// 传入往来单位GID或往来单位shortname
/// </summary>
/// <param name="GID"></param>
public InfoClientLimitHelper(string SALECORPID, string InfoClientId, string USERNAME)
{
//cdc = new CommonDataContext();
Head = cdc.Info_Client_Limit.FirstOrDefault(x => x.SALECORPID == SALECORPID && (x.GID == InfoClientId || x.CUSTOMERNAME == InfoClientId));
CHANGEUSER = USERNAME;
NewChange = new List<Info_Client_Limit_Change_md>();
//if (canuse()) {
// ChangeDetail = cdc.Info_Client_Limit_Change.Where(x=>x.Pid== Head.GID).OrderBy(x=>x.Id).ToList();
//}
}
/// <summary>
/// bsno是v_op_bill的业务编号USERNAME用于记录此次变动的执行人如果是用于查询目的可传空白
///
/// </summary>
/// <param name="BSNO"></param>
/// <param name="USERNAME"></param>
public InfoClientLimitHelper(string BSNO, string USERNAME)
{
CHANGEUSER = USERNAME;
//cdc = new CommonDataContext();
Bill = cdc.v_op_bill.FirstOrDefault(x => x.BSNO == BSNO);
customer = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == Bill.CUSTOMERNAME);
if (customer != null)
{
Head = cdc.Info_Client_Limit.FirstOrDefault(x => x.SALECORPID == Bill.SALECORPID && (x.InfoClientId == customer.GID));
}
NewChange = new List<Info_Client_Limit_Change_md>();
//if (canuse()) {
// ChangeDetail = cdc.Info_Client_Limit_Change.Where(x=>x.Pid== Head.GID).OrderBy(x=>x.Id).ToList();
//}
}
public static void (List<string> FEEIDList, string USERNAME)
{
if (FEEIDList == null || FEEIDList.Count == 0) return;
var BSNOList = new List<string>();
var cdc = new CommonDataContext();
var _user = cdc.VW_user_all.FirstOrDefault(x => x.USERID == USERNAME);
if (!string.IsNullOrWhiteSpace(_user.SHOWNAME))
{
USERNAME = _user.SHOWNAME;
}
var chfeeList = cdc.ch_fee.Where(x => FEEIDList.Contains(x.GID) && x.FEETYPE == 1).ToList();
BSNOList = chfeeList.Select(s => s.BSNO).Distinct().ToList();
var = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO)).Distinct().ToList();
foreach (var billitem in )
{
var = MsOp_BLISSUEDAL.(billitem.PARENTID);
if (!.Success)
{
chfeeList.RemoveAll(x => x.BSNO == billitem.BSNO);
}
}
BSNOList = chfeeList.Select(s => s.BSNO).Distinct().ToList();
var feehead = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO)).ToList();
foreach (var bsno in BSNOList)
{
var hp = new InfoClientLimitHelper(bsno, USERNAME);
hp.DO_(chfeeList.Where(x => x.BSNO == bsno).ToList(), USERNAME);
}
}
public static void (List<string> FEEIDList, string USERNAME)
{
if (FEEIDList == null || FEEIDList.Count == 0) return;
var BSNOList = new List<string>();
var cdc = new CommonDataContext();
var _user = cdc.VW_user_all.FirstOrDefault(x => x.USERID == USERNAME);
if (!string.IsNullOrWhiteSpace(_user.SHOWNAME))
{
USERNAME = _user.SHOWNAME;
}
var chfeeList = cdc.ch_fee.Where(x => FEEIDList.Contains(x.GID) && x.FEETYPE == 1).ToList();
BSNOList = chfeeList.Select(s => s.BSNO).Distinct().ToList();
var = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO)).Distinct().ToList();
foreach (var billitem in )
{
var = MsOp_BLISSUEDAL.(billitem.PARENTID);
if (!.Success)
{
chfeeList.RemoveAll(x => x.BSNO == billitem.BSNO);
}
}
BSNOList = chfeeList.Select(s => s.BSNO).Distinct().ToList();
var feehead = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO)).ToList();
foreach (var bsno in BSNOList)
{
var hp = new InfoClientLimitHelper(bsno, USERNAME);
hp.DO_(chfeeList.Where(x => x.BSNO == bsno).ToList(), USERNAME);
}
}
public static void (List<string> BSNOList, string USERNAME)
{
if (BSNOList == null || BSNOList.Count == 0) return;
//var BSNOList = new List<string>();
var cdc = new CommonDataContext();
var _user = cdc.VW_user_all.FirstOrDefault(x => x.USERID == USERNAME);
if (!string.IsNullOrWhiteSpace(_user.SHOWNAME))
{
USERNAME = _user.SHOWNAME;
}
var chfeeList = cdc.ch_fee.Where(x => BSNOList.Contains(x.BSNO) && x.FEETYPE == 1).ToList();
BSNOList = chfeeList.Select(s => s.BSNO).Distinct().ToList();
foreach (var bsno in BSNOList)
{
var = MsOp_BLISSUEDAL.(bsno);
if (!.Success)
{
chfeeList.RemoveAll(x => x.BSNO == bsno);
}
}
BSNOList = chfeeList.Select(s => s.BSNO).Distinct().ToList();
var feehead = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO)).ToList();
foreach (var bsno in BSNOList)
{
var hp = new InfoClientLimitHelper(bsno, USERNAME);
hp.DO_(chfeeList.Where(x => x.BSNO == bsno).ToList(), USERNAME);
}
}
public DBResult CanCheckOut() {
var result = new DBResult();
if (Bill == null || string.IsNullOrWhiteSpace(Bill.BSNO)) {
result.SetErrorInfo("没有找到业务");
return result;
}
var billfee = cdc.ch_fee.Where(x => x.BSNO == Bill.BSNO && x.CUSTOMERNAME== Bill.CUSTOMERNAME && x.FEETYPE == 1).ToList();
if (billfee == null || billfee.Count == 0) {
result.OK();
return result;
}
var = billfee.Sum(s => ((s.AMOUNT - s.SETTLEMENT) * s.EXCHANGERATE));
if ( > Head.REMAINLIMIT)
{
var _ = Math.Round((decimal), 2);
result.SetErrorInfo($"本业务有未收款共[{_欠费}RMB],委托单位[{Head.CUSTOMERNAME}]的欠费放单额度 {Head.TOTALLIMIT},目前剩余 {Head.REMAINLIMIT},不能放货.");
return result;
}
else {
result.OK();
return result;
}
}
private void RefrashHead()
{
Head = cdc.Info_Client_Limit.FirstOrDefault(x => x.GID == Head.GID);
}
private void GetDetail(bool getnow = false) {
if (canuse())
{
if (getnow == false)
{
if (ChangeDetail == null || ChangeDetail.Count == 0)
ChangeDetail = cdc.Info_Client_Limit_Change.Where(x => x.Pid == Head.GID).OrderBy(x => x.Id).ToList();
}
else {
ChangeDetail = cdc.Info_Client_Limit_Change.Where(x => x.Pid == Head.GID).OrderBy(x => x.Id).ToList();
}
}
}
private Info_Client_Limit_Change_md GetLastDetail(bool getnow = false)
{
var result = new Info_Client_Limit_Change_md();
if (canuse())
{
try
{
var lastlist = cdc.Info_Client_Limit_Change.Where(x => x.Pid == Head.GID).OrderByDescending(x => x.Id).Skip(0).Take(1).ToList();
result = lastlist[0];
}
catch (Exception e) {
}
}
return result;
}
//类行为: 外部行为 1查询额度 2查询变动日志 2添加变动记录
public Info_Client_Limit_md GetLimit() {
return Head;
}
public List<Info_Client_Limit_Change_md> GetLimitChange()
{
GetDetail(true);
return ChangeDetail;
}
/// <summary>
///
/// </summary>
/// <param name="CUSTOMERNAME"></param>
/// <param name="CHANGETYPE">1扣除 2加</param>
/// <param name="CHANGEOPLBNAME"></param>
/// <param name="CHANGEUSER"></param>
/// <param name="FEEID"></param>
/// <param name="FEEDOID"></param>
/// <param name="BSNO"></param>
/// <param name="BILLNO"></param>
/// <param name="CUSTNO"></param>
/// <param name="CHANGEAMOUNT"></param>
/// <returns></returns>
private Info_Client_Limit_Change_md GetNewChange(string SALECORPID, string CUSTOMERNAME, int CHANGETYPE, string CHANGEOPLBNAME, string CHANGEUSER
, string FEEID, string FEEDOID, string BSNO, string BILLNO, string CUSTNO, decimal CHANGEAMOUNT)
{
var result = new Info_Client_Limit_Change_md();
result.Pid = Head.GID;
result.SALECORPID = SALECORPID;
result.PCORPNAME = Head.PCORPNAME;
result.CUSTOMERNAME = CUSTOMERNAME;
result.CHANGETYPE = CHANGETYPE;
result.CHANGEOPLBNAME = CHANGEOPLBNAME;
result.CHANGEUSER = CHANGEUSER;
result.CREATEDATE = DateTime.Now;
result.FEEID = FEEID;
result.FEEDOID = FEEDOID;
result.BSNO = BSNO;
result.BILLNO = BILLNO;
result.CUSTNO = CUSTNO;
result.CHANGEAMOUNT = CHANGEAMOUNT;
return result;
}
private List<Info_Client_Limit_Change_md> NewChange { get; set; }
private void DoSave() {
cdc.Info_Client_Limit.AddOrUpdate(Head);
if (NewChange != null && NewChange.Count > 0) {
cdc.Info_Client_Limit_Change.AddRange(NewChange);
}
cdc.SaveChanges();
NewChange.Clear();
}
//private static void AddChange(InfoClientLimitHelper hp, Info_Client_Limit_Change_md changeitem)
//{
// //GetDetail(true);
// var lastchange = hp.GetLastDetail();
// hp.RefrashHead();
// if (lastchange == null || lastchange.AMOUNT3 == null)
// {
// lastchange.AMOUNT3 = hp.Head.TOTALLIMIT;
// }
// changeitem.AMOUNT2 = lastchange.AMOUNT3;
// if (changeitem.CHANGETYPE == 1)
// {
// //扣减额度
// changeitem.AMOUNT3 = changeitem.AMOUNT2 - changeitem.CHANGEAMOUNT;
// hp.Head.CURRENTDEBT += changeitem.CHANGEAMOUNT;
// hp.Head.REMAINLIMIT -= changeitem.CHANGEAMOUNT;
// }
// if (changeitem.CHANGETYPE == 2)
// {
// //恢复额度
// changeitem.AMOUNT3 = changeitem.AMOUNT2 + changeitem.CHANGEAMOUNT;
// hp.Head.CURRENTDEBT -= changeitem.CHANGEAMOUNT;
// hp.Head.REMAINLIMIT += changeitem.CHANGEAMOUNT;
// }
// hp.NewChange.Add(changeitem);
//}
private void AddChange(Info_Client_Limit_Change_md changeitem)
{
//GetDetail(true);
RefrashHead();
var lastchange = GetLastDetail();
if (lastchange == null || lastchange.AMOUNT3 == null)
{
lastchange.AMOUNT3 = Head.TOTALLIMIT;
}
changeitem.AMOUNT2 = lastchange.AMOUNT3;
//if (changeitem.CHANGETYPE == 1)
//{
// //扣减额度
// changeitem.AMOUNT3 = changeitem.AMOUNT2 - changeitem.CHANGEAMOUNT;
// Head.CURRENTDEBT += changeitem.CHANGEAMOUNT;
// Head.REMAINLIMIT -= changeitem.CHANGEAMOUNT;
//}
//if (changeitem.CHANGETYPE == 2)
//{
// //恢复额度
// changeitem.AMOUNT3 = changeitem.AMOUNT2 + changeitem.CHANGEAMOUNT;
// Head.CURRENTDEBT -= changeitem.CHANGEAMOUNT;
// Head.REMAINLIMIT += changeitem.CHANGEAMOUNT;
//}
changeitem.AMOUNT3 = changeitem.AMOUNT2 + changeitem.CHANGEAMOUNT;
Head.CURRENTDEBT -= changeitem.CHANGEAMOUNT;
Head.REMAINLIMIT += changeitem.CHANGEAMOUNT;
NewChange.Add(changeitem);
DoSave();
}
public void (string BSNO)
{
("直接放单_票结", BSNO);
}
public void (string BSNO)
{
("直接放单_月结", BSNO);
}
public void (string BSNO)
{
("特放申请放单", BSNO);
}
public void (string BSNO)
{
("直接放单", BSNO);
}
//1直接放单票结有欠款ATD不是最晚《未超额度》
//月结,有欠款,欠费不超期,《未超额度》
//通过特殊放单 )扣额度
//2收费结算 加额度
//3取消放单 加额度1的逆运算同样插入一条加额度的变动
//4取消结算 扣额度3的逆运算同样插入一条扣额度的变动
/// <summary>
///
/// </summary>
public void (string CHANGEOPLBNAME, string BSNO)
{
var CHANGETYPE = 1;
var BSNOList = new List<string> { BSNO };
var amend = cdc.op_amend.Where(x => x.PARENTID == BSNO).ToList();
if (amend != null && amend.Count > 0) {
BSNOList.AddRange(amend.Select(s => s.BSNO));
}
var feehead = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO)||BSNOList.Contains(x.PARENTID)).ToList();
var headbsnoList = feehead.Select(x => x.BSNO).Distinct().ToList();
var FeeList = new List<ch_fee_md>();
foreach (var head in feehead) {
var temp_FeeList = cdc.ch_fee.Where(x => head.BSNO==x.BSNO && head.CUSTOMERNAME==x.CUSTOMERNAME && x.FEETYPE == 1 && x.FEESTATUS!=1 && x.FEESTATUS != 2 && x.FEESTATUS != 6 && ((x.AMOUNT>0 && x.SETTLEMENT < x.AMOUNT) || (x.AMOUNT < 0 && x.SETTLEMENT > x.AMOUNT))).ToList();
if (temp_FeeList != null) {
FeeList.AddRange(temp_FeeList);
}
}
if (FeeList == null || FeeList.Count == 0) return;
foreach (var item in FeeList)
{
var bill = feehead.FirstOrDefault(x => x.BSNO == item.BSNO);
var changeamount = (item.AMOUNT - item.SETTLEMENT) * item.EXCHANGERATE;
var change = GetNewChange(bill.SALECORPID, item.CUSTOMERNAME, CHANGETYPE, CHANGEOPLBNAME, CHANGEUSER
, item.GID, "", item.BSNO, "", bill.CUSTNO, -(decimal)changeamount);
AddChange(change);
}
//DoSave();
}
public void (string BSNO)
{
var CHANGEOPLBNAME = "取消放单通知";
var CHANGETYPE = 2;
var BSNOList = new List<string> { BSNO };
var amend = cdc.op_amend.Where(x => x.PARENTID == BSNO).ToList();
if (amend != null && amend.Count > 0)
{
BSNOList.AddRange(amend.Select(s => s.BSNO));
}
var feehead = cdc.v_op_bill.Where(x => BSNOList.Contains(x.BSNO) || BSNOList.Contains(x.PARENTID)).ToList();
var headbsnoList = feehead.Select(x => x.BSNO).Distinct().ToList();
var FeeList = new List<ch_fee_md>();
foreach (var head in feehead)
{
var temp_FeeList = cdc.ch_fee.Where(x => head.BSNO == x.BSNO && head.CUSTOMERNAME == x.CUSTOMERNAME && x.FEETYPE == 1 && x.FEESTATUS != 1 && x.FEESTATUS != 2 && x.FEESTATUS != 6 && ((x.AMOUNT > 0 && x.SETTLEMENT < x.AMOUNT) || (x.AMOUNT < 0 && x.SETTLEMENT > x.AMOUNT))).ToList();
if (temp_FeeList != null)
{
FeeList.AddRange(temp_FeeList);
}
}
if (FeeList == null || FeeList.Count == 0) return;
var feeidList = FeeList.Select(s => s.GID).ToList();
var = cdc.Info_Client_Limit_Change.Where(x => feeidList.Contains(x.FEEID)).ToList();
foreach (var item in FeeList)
{
if (!.Exists(x => x.FEEID == item.GID)) {
continue;
}
var bill = feehead.FirstOrDefault(x => x.BSNO == item.BSNO);
var changeamount = (item.AMOUNT - item.SETTLEMENT) * item.EXCHANGERATE;
var change = GetNewChange(bill.SALECORPID, item.CUSTOMERNAME, CHANGETYPE, CHANGEOPLBNAME, CHANGEUSER
, item.GID, "", item.BSNO, "", bill.CUSTNO, (decimal)changeamount);
AddChange(change);
}
//DoSave();
}
public void DO_(List<ch_fee_md> chfeeList, string USERNAME)
{
if (chfeeList == null || chfeeList.Count == 0) return;
var CHANGETYPE = 1;
var CHANGEOPLBNAME = "特放业务应收费用审核通过";
var feehead = cdc.v_op_bill.Where(x => x.BSNO== Bill.BSNO || x.PARENTID== Bill.BSNO).ToList();
foreach (var item in chfeeList)
{
if (item.CUSTOMERNAME != feehead.First(x => x.BSNO == item.BSNO).CUSTOMERNAME)
{
continue;
}
var bill = feehead.FirstOrDefault(x => x.BSNO == item.BSNO);
var changeamount = (item.AMOUNT - item.SETTLEMENT) * item.EXCHANGERATE;
var change = GetNewChange(bill.SALECORPID, item.CUSTOMERNAME, CHANGETYPE, CHANGEOPLBNAME, CHANGEUSER
, item.GID, "", item.BSNO, "", bill.CUSTNO, -(decimal)changeamount);
AddChange(change);
}
//DoSave();
}
private void DO_(List<ch_fee_md> chfeeList, string USERNAME)
{
if (chfeeList == null || chfeeList.Count == 0) return;
var CHANGETYPE = 2;
var CHANGEOPLBNAME = "特放业务应收费用审核驳回";
var feehead = cdc.v_op_bill.Where(x => x.BSNO == Bill.BSNO || x.PARENTID == Bill.BSNO).ToList();
foreach (var item in chfeeList)
{
if (item.CUSTOMERNAME != feehead.First(x => x.BSNO == item.BSNO).CUSTOMERNAME)
{
continue;
}
var bill = feehead.FirstOrDefault(x => x.BSNO == item.BSNO);
var changeamount = (item.AMOUNT - item.SETTLEMENT) * item.EXCHANGERATE;
var change = GetNewChange(bill.SALECORPID, item.CUSTOMERNAME, CHANGETYPE, CHANGEOPLBNAME, CHANGEUSER
, item.GID, "", item.BSNO, "", bill.CUSTNO, (decimal)changeamount);
AddChange(change);
}
//DoSave();
}
/// <summary>
/// 收费结算
/// </summary>
/// <param name="chfeedo"></param>
public void (List<ch_fee_do_md> chfeedoList,List<v_op_bill_mb> BillList,List<ch_fee_md> feeList) {
var feeidList = chfeedoList.Select(s => s.FEEID).ToList();
var = cdc.Info_Client_Limit_Change.Where(x => feeidList.Contains(x.FEEID)).ToList();
var bsnoList = chfeedoList.Select(s => s.BSNO).ToList();
var feeheadList = cdc.v_op_bill.Where(x => bsnoList.Contains(x.BSNO) || bsnoList.Contains(x.PARENTID)).ToList();
RefrashHead();
foreach (var chfeedo in chfeedoList)
{
if (!.Exists(x => x.FEEID == chfeedo.FEEID))
continue;
var _bill = BillList.First(x => x.BSNO == chfeedo.BSNO);
var _fee = feeList.First(x => x.GID == chfeedo.FEEID);
var _feehead = feeheadList.First(x => x.BSNO == chfeedo.BSNO);
var changeamount = chfeedo.AMOUNT;
if (!string.IsNullOrWhiteSpace(chfeedo.CURRENCY) && chfeedo.CURRENCY != "RMB") {
changeamount = chfeedo.AMOUNT * _fee.EXCHANGERATE;
}
var change = GetNewChange(_feehead.SALECORPID, _fee.CUSTOMERNAME,2, "收费结算", CHANGEUSER
, chfeedo.FEEID, chfeedo.GID, chfeedo.BSNO, chfeedo.BILLNO, _bill.CUSTNO, (decimal)changeamount);
AddChange(change);
}
//DoSave();
}
public void (List<ch_fee_do_md> chfeedoList, List<v_op_bill_mb> BillList, List<ch_fee_md> feeList)
{
var feeidList = chfeedoList.Select(s => s.FEEID).ToList();
var = cdc.Info_Client_Limit_Change.Where(x => feeidList.Contains(x.FEEID)).ToList();
var bsnoList = chfeedoList.Select(s => s.BSNO).ToList();
var feeheadList = cdc.v_op_bill.Where(x => bsnoList.Contains(x.BSNO) || bsnoList.Contains(x.PARENTID)).ToList();
foreach (var chfeedo in chfeedoList)
{
if (!.Exists(x => x.FEEID == chfeedo.FEEID))
continue;
var _bill = BillList.First(x => x.BSNO == chfeedo.BSNO);
var _fee = feeList.First(x => x.GID == chfeedo.FEEID);
var _feehead = feeheadList.First(x => x.BSNO == chfeedo.BSNO);
var changeamount = chfeedo.AMOUNT;
if (chfeedo.CURRENCY != "RMB")
{
changeamount = chfeedo.AMOUNT * _fee.EXCHANGERATE;
}
var change = GetNewChange(_feehead.SALECORPID, _fee.CUSTOMERNAME, 1, "取消收费结算", CHANGEUSER
, chfeedo.FEEID, chfeedo.GID, chfeedo.BSNO, chfeedo.BILLNO, _bill.CUSTNO, -(decimal)changeamount);
AddChange(change);
}
//DoSave();
}
private class {
public string SALECORPID { get; set; }
public string CUSTOMERNAME { get; set; }
public () { }
public (string a, string b) {
SALECORPID = a;
CUSTOMERNAME = b;
}
}
public static void _(string BILLNO, List<BillChfeeDetail> feelist, string USERNAME) {
var cdc = new CommonDataContext();
var feeidlist = feelist.Select(s => s.CH_ID).ToList();
var feedolist = cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO && feeidlist.Contains(x.FEEID)).ToList();
("结算", feedolist, USERNAME);
}
public static void _(string BILLNO, List<ChInvoice> invoicelist, string USERNAME)
{
var cdc = new CommonDataContext();
var billnoList = invoicelist.Select(s => s.BILLNO).ToList();
var feedolist = cdc.ch_fee_do.Where(x => billnoList.Contains(x.BILLNO)).ToList();
("结算", feedolist, USERNAME);
}
public static void _(string BILLNO, List<ChFeeDetail> feelist, string USERNAME)
{
var cdc = new CommonDataContext();
var feeidlist = feelist.Select(s => s.CH_ID).ToList();
var feedolist = cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO && feeidlist.Contains(x.FEEID)).ToList();
("结算", feedolist, USERNAME);
}
/// <summary>
/// CHANGETYPE2收费结算1取消收费结算
/// </summary>
/// <param name="BILLNO"></param>
/// <param name="BILLTYPE"></param>
/// <param name="USERNAME"></param>
/// <param name="CHANGETYPE">2收费结算1取消收费结算</param>
public static void (string BILLNO, int BILLTYPE,string USERNAME,int CHANGETYPE)
{
if (BILLTYPE == 2) return;
var _cdc = new CommonDataContext();
//查找收费结算的ch_fee_do
var feedoList = _cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO).ToList();
if (feedoList == null || feedoList.Count == 0) return;
var bsnoList = feedoList.Select(s => s.BSNO).ToList();
var billList = _cdc.v_op_bill.Where(x => bsnoList.Contains(x.BSNO)).ToList();
var feeidList = feedoList.Select(s => s.FEEID).ToList();
var feeList = _cdc.ch_fee.Where(x => feeidList.Contains(x.GID)).ToList();
var billinfoList = new List<>();
void addbillinfo(string SALECORPID, string CUSTOMERNAME)
{
if (billinfoList == null) billinfoList = new List<>();
if (billinfoList.Exists(x => x.SALECORPID == SALECORPID && x.CUSTOMERNAME == CUSTOMERNAME))
{
}
else
{
billinfoList.Add(new (SALECORPID, CUSTOMERNAME));
}
}
foreach (var bill in billList) {
addbillinfo(bill.SALECORPID, bill.CUSTOMERNAME);
}
foreach (var billinfo in billinfoList) {
var helper = new InfoClientLimitHelper(billinfo.SALECORPID,billinfo.CUSTOMERNAME, USERNAME);
var _billList = billList.Where(x => x.SALECORPID == billinfo.SALECORPID && x.CUSTOMERNAME== billinfo.CUSTOMERNAME).ToList();
var dolist = feedoList.Where(x => _billList.Select(s => s.BSNO).Contains(x.BSNO)).ToList();
if (CHANGETYPE == 2)
helper.(dolist, _billList, feeList);
if (CHANGETYPE == 1)
helper.(dolist, _billList, feeList);
}
}
public static void (string CHANGETYPE, List<ch_fee_do_md> feedoList, string USERNAME)
{
var _cdc = new CommonDataContext();
//查找收费结算的ch_fee_do
//var feedoList = _cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO).ToList();
if (feedoList == null || feedoList.Count == 0) return;
var bsnoList = feedoList.Select(s => s.BSNO).ToList();
var billList = _cdc.v_op_bill.Where(x => bsnoList.Contains(x.BSNO)).ToList();
var feeidList = feedoList.Select(s => s.FEEID).ToList();
var feeList = _cdc.ch_fee.Where(x => feeidList.Contains(x.GID)).ToList();
var billinfoList = new List<>();
void addbillinfo(string SALECORPID, string CUSTOMERNAME)
{
if (billinfoList == null) billinfoList = new List<>();
if (billinfoList.Exists(x => x.SALECORPID == SALECORPID && x.CUSTOMERNAME == CUSTOMERNAME))
{
}
else
{
billinfoList.Add(new (SALECORPID, CUSTOMERNAME));
}
}
foreach (var bill in billList)
{
addbillinfo(bill.SALECORPID, bill.CUSTOMERNAME);
}
foreach (var billinfo in billinfoList)
{
var helper = new InfoClientLimitHelper(billinfo.SALECORPID, billinfo.CUSTOMERNAME, USERNAME);
var _billList = billList.Where(x => x.SALECORPID == billinfo.SALECORPID && x.CUSTOMERNAME == billinfo.CUSTOMERNAME).ToList();
var dolist = feedoList.Where(x => _billList.Select(s => s.BSNO).Contains(x.BSNO)).ToList();
if (CHANGETYPE == "结算")
helper.(dolist, _billList, feeList);
if (CHANGETYPE == "取消结算")
helper.(dolist, _billList, feeList);
}
}
public static void _(string BILLNO, List<Chfee_do_detail> feelist, string USERNAME)
{
var cdc = new CommonDataContext();
var feeidlist = feelist.Select(s => s.FEEID).ToList();
var feedolist = cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO && feeidlist.Contains(x.FEEID)).ToList();
("取消结算", feedolist, USERNAME);
}
public static void _(string BILLNO, List<ChPaySettlement> bodyList, string USERNAME)
{
var _cdc = new CommonDataContext();
//查找收费结算的ch_fee_do
//var feedoList = _cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO).ToList();
//if (feedoList == null || feedoList.Count == 0) return;
//var bsnoList = bodyList.Select(s => s.BSNO).ToList();
//var billList = _cdc.v_op_bill.Where(x => bsnoList.Contains(x.BSNO)).ToList();
//var feeidList = feedoList.Select(s => s.FEEID).ToList();
//var feeList = _cdc.ch_fee.Where(x => feeidList.Contains(x.GID)).ToList();
var billinfoList = new List<>();
void addbillinfo(string SALECORPID, string CUSTOMERNAME)
{
if (billinfoList == null) billinfoList = new List<>();
if (billinfoList.Exists(x => x.SALECORPID == SALECORPID && x.CUSTOMERNAME == CUSTOMERNAME))
{
}
else
{
billinfoList.Add(new (SALECORPID, CUSTOMERNAME));
}
}
//foreach (var bill in billList)
//{
// addbillinfo(bill.SALECORPID, bill.CUSTOMERNAME);
//}
//foreach (var billinfo in billinfoList)
//{
// var helper = new InfoClientLimitHelper(billinfo.SALECORPID, billinfo.CUSTOMERNAME, USERNAME);
// var _billList = billList.Where(x => x.SALECORPID == billinfo.SALECORPID && x.CUSTOMERNAME == billinfo.CUSTOMERNAME).ToList();
// var dolist = feedoList.Where(x => _billList.Select(s => s.BSNO).Contains(x.BSNO)).ToList();
// if (CHANGETYPE == 2)
// helper.收费结算(dolist, _billList, feeList);
// if (CHANGETYPE == 1)
// helper.取消收费结算(dolist, _billList, feeList);
//}
}
//public static void 取消结算单扣除欠款额度(string BILLNO, string USERNAME)
//{
// //if (BILLTYPE == 2) return;
// var _cdc = new CommonDataContext();
// //查找收费结算的ch_fee_do
// var feedoList = _cdc.ch_fee_do.Where(x => x.BILLNO == BILLNO).ToList();
// if (feedoList == null || feedoList.Count == 0) return;
// var bsnoList = feedoList.Select(s => s.BSNO).ToList();
// var billList = _cdc.v_op_bill.Where(x => bsnoList.Contains(x.BSNO)).ToList();
// var feeidList = feedoList.Select(s => s.FEEID).ToList();
// var feeList = _cdc.ch_fee.Where(x => feeidList.Contains(x.GID)).ToList();
// var 委托单位简称List = billList.Select(s => s.CUSTOMERNAME).Distinct().ToList();
// var 委托单位List = _cdc.info_client.Where(x => 委托单位简称List.Contains(x.SHORTNAME)).ToList();
// foreach (var 委托单位 in 委托单位List)
// {
// var helper = new InfoClientLimitHelper(委托单位.SHORTNAME, USERNAME);
// var _billList = billList.Where(x => x.CUSTOMERNAME == 委托单位.SHORTNAME).ToList();
// var dolist = feedoList.Where(x => _billList.Select(s => s.BSNO).Contains(x.BSNO)).ToList();
// helper.取消收费结算(dolist, 委托单位, _billList, feeList);
// }
//}
}
}