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/CommMng/DAL/BasicDataRefDAL.cs

5741 lines
236 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 DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.OA.Models.WorkFlow;
using DSWeb.Common.DB;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Models.MsCtExplan;
using DSWeb.MvcShipping.Models.MsInfoClient;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.Models.MsInfoClass;
using DSWeb.SoftMng.Models.MsInfoClientItem;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using Microsoft.Practices.EnterpriseLibrary.Data;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;//使用sqlcomm
using System.IO;//用于向数据库中存取图片
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
namespace DSWeb.Areas.CommMng.DAL
{
public class BasicDataRefDAL
{
#region 费用代码
public static List<FeeTypeRefModel> GetFeeTypeRefList()
{
return GetFeeTypeRefList(String.Empty);
}
public static List<FeeTypeRefModel> GetFeeTypeRefList(string sCondition)
{
var strSql = new StringBuilder();
strSql.Append("Select FeeCode,Name,CodeAndName ");
strSql.Append(" from vMsTruckFeeType ");
if (!string.IsNullOrEmpty(sCondition))
{
strSql.Append(" where " + sCondition);
}
strSql.Append(" order by FeeCode");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<FeeTypeRefModel>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new FeeTypeRefModel();
evData.FeeCode = Convert.ToString(reader["FeeCode"]);
evData.Name = Convert.ToString(reader["Name"]);
evData.CodeAndName = Convert.ToString(reader["CodeAndName"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
public static List<FeeTypeRefModel> GetFeeGroupRefList()
{
return GetFeeGroupRefList(String.Empty);
}
public static List<FeeTypeRefModel> GetFeeGroupRefList(string sCondition)
{
var strSql = new StringBuilder();
strSql.Append("Select feegroupcode FeeCode,feegroupname Name,feegroupcode+'_'+feegroupname CodeAndName ");
strSql.Append(" from code_fee_group ");
if (!string.IsNullOrEmpty(sCondition))
{
strSql.Append(" where " + sCondition);
}
strSql.Append(" order by feegroupcode");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<FeeTypeRefModel>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new FeeTypeRefModel();
evData.FeeCode = Convert.ToString(reader["FeeCode"]);
evData.Name = Convert.ToString(reader["Name"]);
evData.CodeAndName = Convert.ToString(reader["CodeAndName"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
#endregion
#region 用户
static public List<UserRefModel> GetActionUserRefList(string strCondition,string modulename, string dbname = "")
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,UserCode,UserName,CodeAndName,CORPID,DEPTGID,DEPTNAME");
strSql.Append(" from vMsActionUser where MODULENAME='"+ modulename + "' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetUserRefData(strSql, dbname);
}
static public List<UserRefModel> GetUserRefList()
{
return GetUserRefList(string.Empty);
}
/// <summary>
/// UserCode,UserName,CodeAndName,CORPID,DEPTGID,DEPTNAME
/// </summary>
/// <param name="strCondition"></param>
/// <param name="dbname"></param>
/// <returns></returns>
static public List<UserRefModel> GetUserRefList(string strCondition, string dbname = "")
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,UserCode,UserName,CodeAndName,CORPID,DEPTGID,DEPTNAME");
strSql.Append(" from vMsTruckUser ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetUserRefData(strSql, dbname);
}
private static List<UserRefModel> SetUserRefData(StringBuilder strSql, string dbname = "")
{
var headList = new List<UserRefModel>();
Database db = DatabaseFactory.CreateDatabase();
if (dbname != "") db = DatabaseFactory.CreateDatabase(dbname);
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
UserRefModel data = new UserRefModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.UserCode = Convert.ToString(reader["UserCode"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.DEPTGID = Convert.ToString(reader["DEPTGID"]);
data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
UserRefModel adata = new UserRefModel();
#region Set DB data to Object
adata.GID = "";
adata.UserCode = "";
adata.UserName = "";
adata.CodeAndName = "";
adata.CORPID = "";
adata.DEPTGID = "";
adata.DEPTNAME = "";
#endregion
headList.Add(adata);
return headList;
}
static public List<UserLinkRefModel> GetUserLinkRefList(string strCondition, string COMPANYID)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("l.USERID GID,u.CODENAME UserCode,u.SHOWNAME UserName,u.CODENAME+'-'+u.SHOWNAME CodeAndName,");
strSql.Append("l.OFFICEPHONE Tel,l.FAX Fax,l.EMAIL1 Email,l.DEPTNAME,c.COMPANYID");
strSql.Append(" from [user] u left join user_baseinfo l on (u.gid=l.USERID) ");
strSql.Append(" left join user_company c on (u.gid=c.USERID) ");
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='OPONLYSUBCOMPANY'");
if (SeaeDefaultSort.PARAMVALUE != "" && SeaeDefaultSort.PARAMVALUE == "1")
strSql.Append(" where c.companyid='" + COMPANYID + "' ");
else
strSql.Append(" where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by u.CODENAME,u.SHOWNAME ");
return SetUserLinkRefData(strSql);
}
static public UserLinkRefModel GetUserLinkRef(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("l.USERID GID,u.USERNAME UserCode,u.SHOWNAME UserName,u.CODENAME+'-'+u.SHOWNAME CodeAndName,");
strSql.Append("l.OFFICEPHONE Tel,l.FAX Fax,l.EMAIL1 Email,l.DEPTNAME,c.COMPANYID");
strSql.Append(" from [user] u left join user_baseinfo l on (u.gid=l.USERID) ");
strSql.Append(" left join user_company c on (u.gid=c.USERID) ");
strSql.Append(" where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by u.CODENAME,u.SHOWNAME ");
var list = SetUserLinkRefData(strSql);
if (list.Count > 0)
return list[0];
return new UserLinkRefModel();
}
private static List<UserLinkRefModel> SetUserLinkRefData(StringBuilder strSql)
{
var headList = new List<UserLinkRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
UserLinkRefModel data = new UserLinkRefModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.UserCode = Convert.ToString(reader["UserCode"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.Tel = Convert.ToString(reader["Tel"]);
data.Fax = Convert.ToString(reader["Fax"]);
data.Email = Convert.ToString(reader["Email"]);
data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]);
data.CORPID = Convert.ToString(reader["COMPANYID"]);
#endregion
headList.Add(data);
}
reader.Close();
}
UserLinkRefModel adata = new UserLinkRefModel();
#region Set DB data to Object
adata.GID = "";
adata.UserCode = "";
adata.UserName = "";
adata.CodeAndName = "";
adata.Tel = "";
adata.Fax = "";
adata.Email = "";
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 配料
public static List<PluRefModel> GetPluRefList()
{
return GetPluRefList(String.Empty);
}
public static List<PluRefModel> GetPluRefList(string sCondition)
{
var strSql = new StringBuilder();
strSql.Append("Select PluCode,PluName,PluCode+'-'+PluName as CodeAndName,Unit,Spec,Price ");
strSql.Append(" from tMsTruckPlu ");
if (!string.IsNullOrEmpty(sCondition))
{
strSql.Append(" where " + sCondition);
}
strSql.Append(" order by PluCode");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<PluRefModel>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new PluRefModel();
evData.PluCode = Convert.ToString(reader["PluCode"]);
evData.PluName = Convert.ToString(reader["PluName"]);
evData.CodeAndName = Convert.ToString(reader["CodeAndName"]);
evData.Unit = Convert.ToString(reader["Unit"]);
evData.Spec = Convert.ToString(reader["Spec"]);
evData.Price = Convert.ToDecimal(reader["Price"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
#endregion
#region 客户参照对应95004(vMsTruckClient)
static public List<CustomRefModel> GetCustomRefList()
{
return GetCustomRefList(string.Empty);
}
static public List<CustomRefModel> GetCustomRefList(string strCondition, string IsEnableCustRange = "0", string userid = "", string isall = "0")
{
var strSql = GetCustomRefList_GetSqlStr(strCondition, IsEnableCustRange, userid, isall);
return SetCustomRefData(strSql);
}
public static StringBuilder GetCustomRefList_GetSqlStr(string strCondition, string IsEnableCustRange = "0", string userid = "",string isall="0")
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,CODENAME + '-' + description AS CodeAndFull,BillRises1");
strSql.Append(",UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE,OP,DOC,FEEFRT,BSSOURCE,[EMAIL],[TEL],SALECORPID ");
strSql.Append(",(select top 1 CONTRACTNO from info_client_contract WHERE LINKID=info_Client.GID order by STARTDATE desc) CONTRACTNO ");
strSql.Append(" from info_Client where 1=1 "); // BLSTATUS=0
if (isall != "1")
{
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (IsEnableCustRange == "1")
strSql.Append(" and (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range )) ");
strSql.Append(" ORDER BY CODENAME ");
return strSql;
}
static public string GetHTStorageName()
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,BillRises1");
strSql.Append(",UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE,OP,DOC,FEEFRT,BSSOURCE,[EMAIL],[TEL],SALECORPID ");
strSql.Append(",'' CONTRACTNO ");
strSql.Append(" from info_Client where 1=1 AND ISWAREHOUSE = '1' "); // BLSTATUS=0
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
strSql.Append(" ORDER BY CODENAME ");
return SetCustomRefData(strSql)[0].CustName.ToString();
}
private static List<CustomRefModel> SetCustomRefData(StringBuilder strSql)
{
var headList = new List<CustomRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomRefModel data = new CustomRefModel();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]);
data.DESCRIPTION = Convert.ToString(reader["description"]);
data.KFCodename = Convert.ToString(reader["KFCodename"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.FEEFRT = Convert.ToString(reader["FEEFRT"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.EMAIL = Convert.ToString(reader["EMAIL"]);
data.TEL = Convert.ToString(reader["TEL"]);
data.SALECORPID = Convert.ToString(reader["SALECORPID"]);
data.OP = Convert.ToString(reader["OP"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
#endregion
headList.Add(data);
}
reader.Close();
}
CustomRefModel adata = new CustomRefModel();
#region Set DB data to Object
adata.GId = "";
adata.CustCode = "";
adata.CustName = "";
adata.CodeAndName = "";
adata.BillRises1 = "";
adata.UNITPRICE = "";
adata.DESCRIPTION = "";
adata.KFCodename = "";
adata.SALE = "";
adata.FEEFRT = "";
adata.BSSOURCE = "";
#endregion
headList.Add(adata);
return headList;
}
static public List<CustomYardRefModel> GetCustomYardRefList(string strCondition, string IsEnableCustRange = "0", string userid = "")
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,ADDR");
strSql.Append(" from info_client where 1=1 ");
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
if (!string.IsNullOrEmpty(strCondition))
{
//if (IsEnableCustRange == "1")
// strSql.Append(" and SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) ");
strSql.Append(" and " + strCondition);
}
return SetCustomYardRefData(strSql);
}
public static string GetCustomerCode(string customername) {
var condition = " SHORTNAME='" + customername + "' ";
var _list = GetCustomYardRefList(condition);
if (_list != null && _list.Count > 0) {
return _list[0].CustCode;
}
return "";
}
private static List<CustomYardRefModel> SetCustomYardRefData(StringBuilder strSql)
{
var headList = new List<CustomYardRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomYardRefModel data = new CustomYardRefModel();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.ADDR = Convert.ToString(reader["ADDR"]);
#endregion
headList.Add(data);
}
reader.Close();
}
CustomYardRefModel adata = new CustomYardRefModel();
#region Set DB data to Object
adata.GId = "";
adata.CustCode = "";
adata.CustName = "";
adata.CodeAndName = "";
#endregion
headList.Add(adata);
return headList;
}
static public List<CustomInvRefModel> GetCustomInvRefList(string strCondition, string IsEnableCustRange = "0", string userid = "")
{
var strSql = GetCustomInvRefList_SqlStr(strCondition, IsEnableCustRange, userid);
return SetCustomInvRefData(strSql);
}
static public List<CustomInvRefModel> GetCustomInvRef(string strCondition, string IsEnableCustRange = "0", string userid = "")
{
var strSql = GetCustomInvRefList_SqlStr(strCondition, IsEnableCustRange, userid);
return SetCustomInvRefData(strSql,false);
}
public static StringBuilder GetCustomInvRefList_SqlStr(string strCondition, string IsEnableCustRange = "0", string userid = "")
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION]");
strSql.Append(",RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='USD' AND LINKID=info_client.GID) usdbank,usdaccount,TaxNo,Addr,Tel,EMAIL");
strSql.Append(" from info_client where 1=1 ");
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
if (IsEnableCustRange == "1")
strSql.Append(" and (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + userid + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range )) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and (" + strCondition + ")");
}
return strSql;
}
private static List<CustomInvRefModel> SetCustomInvRefData(StringBuilder strSql,bool islist=true)
{
var headList = new List<CustomInvRefModel>();
Database db = DatabaseFactory.CreateDatabase();
if (islist)
headList.Add(new CustomInvRefModel());
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomInvRefModel data = new CustomInvRefModel();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.RMBBillRises = Convert.ToString(reader["RmbBillRises"]);
data.RMBBank = Convert.ToString(reader["Rmbbank"]);
data.RMBAccount = Convert.ToString(reader["Rmbaccount"]);
data.USDBillRises = Convert.ToString(reader["usdBillRises"]);
data.USDBank = Convert.ToString(reader["usdbank"]);
data.USDAccount = Convert.ToString(reader["usdaccount"]);
data.TaxNo = Convert.ToString(reader["TaxNo"]);
data.Addr = Convert.ToString(reader["Addr"]);
data.Tel = Convert.ToString(reader["Tel"]);
data.INVADDRTEL = Convert.ToString(reader["INVADDRTEL"]);
if (data.BillRises1 == "")
data.BillRises1 = Convert.ToString(reader["DESCRIPTION"]);
if (data.RMBBillRises == "")
data.RMBBillRises = Convert.ToString(reader["DESCRIPTION"]);
if (data.USDBillRises == "")
data.USDBillRises = Convert.ToString(reader["DESCRIPTION"]);
data.EMail = Convert.ToString(reader["EMAIL"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<CustomContactRefModel> GetCustomContactRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("LinkId,CODENAME,SHOWNAME,Tel,EMAIL");
strSql.Append(" from info_client_contact ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetCustomContactRefData(strSql);
}
private static List<CustomContactRefModel> SetCustomContactRefData(StringBuilder strSql)
{
var headList = new List<CustomContactRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomContactRefModel data = new CustomContactRefModel();
#region Set DB data to Object
data.LinkId = Convert.ToString(reader["LinkId"]);
data.Code = Convert.ToString(reader["CODENAME"]);
data.Name = Convert.ToString(reader["SHOWNAME"]);
data.Tel = Convert.ToString(reader["Tel"]);
data.EMail = Convert.ToString(reader["EMAIL"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<CustomRefModel> GetAirLinesList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,BillRises1");
strSql.Append(",UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE,ISAGENTCN ");
strSql.Append(" from info_Client where 1=1 "); // BLSTATUS=0
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ORDER BY CODENAME ");
return SetAirLinesData(strSql);
}
private static List<CustomRefModel> SetAirLinesData(StringBuilder strSql)
{
var headList = new List<CustomRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomRefModel data = new CustomRefModel();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]);
data.DESCRIPTION = Convert.ToString(reader["description"]);
data.KFCodename = Convert.ToString(reader["KFCodename"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.ISAGENTCN = Convert.ToString(reader["ISAGENTCN"]);
#endregion
headList.Add(data);
}
reader.Close();
}
CustomRefModel adata = new CustomRefModel();
#region Set DB data to Object
adata.GId = "";
adata.CustCode = "";
adata.CustName = "";
adata.CodeAndName = "";
adata.BillRises1 = "";
adata.UNITPRICE = "";
adata.DESCRIPTION = "";
adata.KFCodename = "";
adata.SALE = "";
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 客户参照对应95004.内贸空运 获取vip价格
static public List<CustomVIPModel> GetCustom_SPPrice()
{
return GetCustom_SPPrice(string.Empty);
}
static public List<CustomVIPModel> GetCustom_SPPrice(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT Gid,CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName,BillRises1 ");
strSql.Append(" ,UNITPRICE,description,SHORTNAME+'_'+description KFCodename,SALE ");
strSql.Append(" ,(case when (select dbo.Get_ClientFee(SHORTNAME,'VIP单价'))>0 ");
strSql.Append(" or (select dbo.Get_ClientFee(SHORTNAME,'VIP单票'))>0 then 1 else 0 end )ISVIP ");
strSql.Append(" ,(select dbo.Get_ClientFee(SHORTNAME,'VIP单价')) VIPDJ ");
strSql.Append(" ,(select dbo.Get_ClientFee(SHORTNAME,'VIP单票')) VIPDP ");
strSql.Append(" from info_Client where 1=1 ");
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ORDER BY CODENAME ");
return SetCustom_SPPrice(strSql);
}
private static List<CustomVIPModel> SetCustom_SPPrice(StringBuilder strSql)
{
var headList = new List<CustomVIPModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomVIPModel data = new CustomVIPModel();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.UNITPRICE = Convert.ToString(reader["UNITPRICE"]);
data.DESCRIPTION = Convert.ToString(reader["description"]);
data.KFCodename = Convert.ToString(reader["KFCodename"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.ISVIP = Convert.ToString(reader["ISVIP"]);
data.VIPDJ = Convert.ToString(reader["VIPDJ"]);
data.VIPDP = Convert.ToString(reader["VIPDP"]);
#endregion
headList.Add(data);
}
reader.Close();
}
CustomVIPModel adata = new CustomVIPModel();
#region Set DB data to Object
adata.GId = "";
adata.CustCode = "";
adata.CustName = "";
adata.CodeAndName = "";
adata.BillRises1 = "";
adata.UNITPRICE = "";
adata.DESCRIPTION = "";
adata.KFCodename = "";
adata.SALE = "";
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 客户银行账户列表
static public List<MsClientAccount> GetMsClientAccount(string condition)
{
return GetMsClientAccountData(condition);
}
static public List<MsClientAccount> GetMsClientAccountData(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,BANKNAME,ACCOUNT,BANKNAME+'-'+ACCOUNT BANKNAME_ACCOUNT");
strSql.Append(" from info_client_bank ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetMsClientAccountData(strSql);
}
private static List<MsClientAccount> SetMsClientAccountData(StringBuilder strSql)
{
var headList = new List<MsClientAccount>();
MsClientAccount adata = new MsClientAccount();
#region Set DB data to Object
adata.GID = "";
adata.BANKNAME = "";
adata.ACCOUNT = "";
adata.BANKNAME_ACCOUNT = "";
#endregion
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsClientAccount data = new MsClientAccount();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BANKNAME = Convert.ToString(reader["BANKNAME"]);
data.ACCOUNT = Convert.ToString(reader["ACCOUNT"]);
data.BANKNAME_ACCOUNT = Convert.ToString(reader["BANKNAME_ACCOUNT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
headList.Add(adata);
return headList;
}
#endregion
#region 业务来源
static public List<SourceModel> GetSourceList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("SOURCEID,SOURCENAME,CORPID,SOURCECODE");
strSql.Append(" from code_source ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetSourceData(strSql);
}
static public SourceModel GetSourceData(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("SOURCEID,SOURCENAME,CORPID,SOURCECODE");
strSql.Append(" from code_source ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var list = SetSourceData(strSql, true);
if (list.Count > 0)
return list[0];
return new SourceModel();
}
private static List<SourceModel> SetSourceData(StringBuilder strSql, bool isdata = false)
{
var headList = new List<SourceModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SourceModel data = new SourceModel();
#region Set DB data to Object
data.SourceID = Convert.ToString(reader["SOURCEID"]);
data.SourceName = Convert.ToString(reader["SOURCENAME"]);
data.CorpID = Convert.ToString(reader["CORPID"]);
data.SOURCECODE = Convert.ToString(reader["SOURCECODE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
if (!isdata)
{
SourceModel adata = new SourceModel();
#region Set DB data to Object
adata.SourceID = "";
adata.SourceName = "";
adata.CorpID = "";
#endregion
headList.Add(adata);
}
return headList;
}
static public List<SourceDetailModel> GetSourceDetailList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("SOURCEDETAILID,SOURCEID,SOURCEDETAIL");
strSql.Append(" from code_source_detail ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetSourceDetailData(strSql);
}
private static List<SourceDetailModel> SetSourceDetailData(StringBuilder strSql)
{
var headList = new List<SourceDetailModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SourceDetailModel data = new SourceDetailModel();
#region Set DB data to Object
data.SourceDetailID = Convert.ToString(reader["SOURCEDETAILID"]);
data.SourceID = Convert.ToString(reader["SOURCEID"]);
data.SourceDetail = Convert.ToString(reader["SOURCEDETAIL"]);
#endregion
headList.Add(data);
}
reader.Close();
}
SourceDetailModel adata = new SourceDetailModel();
#region Set DB data to Object
adata.SourceDetailID = "";
adata.SourceID = "";
adata.SourceDetail = "";
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 部门
static public List<DeptModel> GetDeptList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,DEPTNO + '-' + DEPTNAME AS NOANDNAME");
strSql.Append(" from sys_dept ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetDeptData(strSql);
}
private static List<DeptModel> SetDeptData(StringBuilder strSql)
{
var headList = new List<DeptModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
DeptModel data = new DeptModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.Deptno = Convert.ToString(reader["DEPTNO"]);
data.DeptName = Convert.ToString(reader["DEPTNAME"]);
data.Manage1 = Convert.ToString(reader["MANAGE1"]);
data.NOANDNAME = Convert.ToString(reader["NOANDNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 船名航次参照对应95003(vMsTruckVoyInfo)
static public List<VoyRefModel> GetVoyRefList()
{
return GetVoyRefList(string.Empty);
}
static public List<VoyRefModel> GetVoyRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("VoyCode,VoyName,CodeAndName");
strSql.Append(" from vMsTruckVoyInfo ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetVoyRefData(strSql);
}
private static List<VoyRefModel> SetVoyRefData(StringBuilder strSql)
{
var headList = new List<VoyRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
VoyRefModel data = new VoyRefModel();
#region Set DB data to Object
data.VoyCode = Convert.ToString(reader["VoyCode"]);
data.VoyName = Convert.ToString(reader["VoyName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 船名
static public List<VesselModel> GetVesselList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VSID,VESSEL,CNAME,CARRIER,EDICODE,VESSEL+' '+CNAME CodeAndName");
strSql.Append(" from code_vessel ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetVesselData(strSql);
}
private static List<VesselModel> SetVesselData(StringBuilder strSql)
{
var headList = new List<VesselModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
VesselModel data = new VesselModel();
#region Set DB data to Object
data.VSID = Convert.ToString(reader["VSID"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.CNAME = Convert.ToString(reader["CNAME"]);
data.EDICODE = Convert.ToString(reader["EDICODE"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<VoyNoModel> GetVoyNoList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VOID,VSID,VOYNO,PORTLOAD,PORTDISCHARGE,ETD,CLOSINGDATE,ETA,CORPID,YARDID,ENTREPORT,VESSEL,ATD,CLOSEDOCDATE ");
strSql.Append(" from code_voyno ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetVoyNoData(strSql);
}
private static List<VoyNoModel> SetVoyNoData(StringBuilder strSql)
{
var headList = new List<VoyNoModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
VoyNoModel data = new VoyNoModel();
#region Set DB data to Object
data.VSID = Convert.ToString(reader["VSID"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");
if (reader["CLOSINGDATE"] != DBNull.Value)
data.CLOSINGDATE = Convert.ToDateTime(reader["CLOSINGDATE"]).ToString("yyyy-MM-dd");
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");
if (reader["ATD"] != DBNull.Value)
data.ATD = Convert.ToDateTime(reader["ATD"]).ToString("yyyy-MM-dd");
if (reader["CLOSEDOCDATE"] != DBNull.Value)
data.CLOSEDOCDATE = Convert.ToDateTime(reader["CLOSEDOCDATE"]).ToString("yyyy-MM-dd HH:mm");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 箱型表参照对应95005(vMsTruckCtn)
static public List<CtnRefModel> GetCtnRefList()
{
return GetCtnRefList(string.Empty);
}
static public List<CtnRefModel> GetCtnRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("CtnCode,CtnName,CodeAndName");
strSql.Append(" from vMsTruckCtn ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetCtnRefData(strSql);
}
private static List<CtnRefModel> SetCtnRefData(StringBuilder strSql)
{
var headList = new List<CtnRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CtnRefModel data = new CtnRefModel();
#region Set DB data to Object
data.CtnCode = Convert.ToString(reader["CtnCode"]);
data.CtnName = Convert.ToString(reader["CtnName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
CtnRefModel adata = new CtnRefModel();
#region Set DB data to Object
adata.CtnCode = "";
adata.CtnName = "";
adata.CodeAndName = "";
#endregion
headList.Add(adata);
return headList;
}
static public List<CtnRefModel> GetCtnDispList()
{
return GetCtnDispList(string.Empty);
}
static public List<CtnRefModel> GetCtnDispList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select CtnCode,CtnName,CodeAndName,sort from [vMsImportCtnDisp]");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by sort ");
return SetCtnRefData(strSql);
}
#endregion
#region 国家参照,(Import_country)
static public List<CountryModel> GetCountryRefList()
{
return GetCountryRefList(string.Empty);
}
static public List<CountryModel> GetCountryRefList(string strCondition)
{
var strSql = new StringBuilder();
// SELECT id,country_code,country,(country_code+'_'+country) as country_codeandname
//from import_country
strSql.Append("SELECT countryid,country,(countryid+'_'+country) as country_idandname");
strSql.Append(" from code_country ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetcountryRefData(strSql);
}
private static List<CountryModel> SetcountryRefData(StringBuilder strSql)
{
var headList = new List<CountryModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CountryModel data = new CountryModel();
#region Set DB data to Object
// data.id = Convert.ToString(reader["id"]);
data.countryid = Convert.ToString(reader["countryid"]);
data.country = Convert.ToString(reader["country"]);
data.country_idandname = Convert.ToString(reader["country_idandname"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 商品名称参照,(Import_Cargoinfo)
static public List<CargoModel> GetCargoRefList()
{
return GetCargoRefList(string.Empty);
}
static public List<CargoModel> GetCargoRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" select *,code+'_'+name codeandname from import_cargoinfo ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by code ");
return SetCargoRefData(strSql);
}
private static List<CargoModel> SetCargoRefData(StringBuilder strSql)
{
var headList = new List<CargoModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CargoModel data = new CargoModel();
#region Set DB data to Object
data.id = Convert.ToString(reader["id"]);
data.code = Convert.ToString(reader["code"]);
data.name = Convert.ToString(reader["name"]);
data.codeandname = Convert.ToString(reader["codeandname"]);
// data.tariff = Convert.ToString(reader["tariff"]);
// data.tax = Convert.ToString(reader["tax"]);
// data.tax_zz = Convert.ToString(reader["tax_zz"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 商品名称参照 含tax(Import_Cargoinfo)
static public List<CargoModel> GetCargoTax()
{
return GetCargoTax(string.Empty);
}
static public List<CargoModel> GetCargoTax(string strCondition)
{
//tariff 关税等级: 0最惠国 1普通 2零关税
var strSql = GetCargoTax_Sqlstr(strCondition);
return SetCargoTax(strSql);
}
public static StringBuilder GetCargoTax_Sqlstr(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" select ci.id,name,code+'_'+name codeandname,code, ");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 ");
strSql.Append("and EnumTypeID=9000 and EnumValueID=cc.tariff) as tariff, ");
strSql.Append("case cc.tariff when 0 then ci.tax_zhg/100 when 1 then ci.tax_pt/100 when 2 then 0 end tax, ");
strSql.Append("ci.tax_zz/100 as tax_zz,ci.tax_cl as tax_cl from code_country cc,import_cargoinfo ci ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return strSql;
}
private static List<CargoModel> SetCargoTax(StringBuilder strSql)
{
var headList = new List<CargoModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CargoModel data = new CargoModel();
#region Set DB data to Object
data.id = Convert.ToString(reader["id"]);
data.code = Convert.ToString(reader["code"]);
data.name = Convert.ToString(reader["name"]);
data.codeandname = Convert.ToString(reader["codeandname"]);
data.tariff = Convert.ToString(reader["tariff"]);
data.tax = Convert.ToString(reader["tax"]);
data.tax_zz = Convert.ToString(reader["tax_zz"]);
data.tax_cl = Convert.ToString(reader["tax_cl"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 商品ciq名称参照(Import_Cargociq)
static public List<CargociqModel> GetCargociqRefList(string strCondition = "")
{
if (strCondition.Trim().Length > 0)
if (strCondition.Trim().Substring(strCondition.Trim().Length - 1, 1) == "=")
{
return new List<CargociqModel>();
}
var strSql = GetCargociqRefList_Sqlstr(strCondition);
return SetCargociqRefData(strSql);
}
public static StringBuilder GetCargociqRefList_Sqlstr(string strCondition = "")
{
var strSql = new StringBuilder();
strSql.Append("SELECT *,ciqcode+'_'+ciqname as codeandname");
strSql.Append(" from import_cargociq ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by ciqcode ");
return strSql;
}
private static List<CargociqModel> SetCargociqRefData(StringBuilder strSql)
{
var headList = new List<CargociqModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CargociqModel data = new CargociqModel();
#region Set DB data to Object
data.id = Convert.ToString(reader["id"]);
data.ciqcode = Convert.ToString(reader["ciqcode"]);
data.ciqname = Convert.ToString(reader["ciqname"]);
data.codeandname = Convert.ToString(reader["codeandname"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 公司名称,(company)
static public List<companyModel> GetcompanyList()
{
return GetcompanyList(string.Empty);
}
static public List<companyModel> GetcompanyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT *");
strSql.Append(" from company where isdeleted=0 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetcompanyData(strSql);
}
private static List<companyModel> SetcompanyData(StringBuilder strSql)
{
var headList = new List<companyModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
companyModel data = new companyModel();
#region Set DB data to Object
data.gid = Convert.ToString(reader["gid"]);
data.code = Convert.ToString(reader["codename"]);
data.name = Convert.ToString(reader["name"]);
data.isdisable = Convert.ToString(reader["isdisable"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 币别,(currid)
static public List<currModel> GetcurrRefList()
{
return GetcurrRefList(string.Empty);
}
static public List<currModel> GetcurrRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select gid,codename,defaultrate from code_currency ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetcurrData(strSql);
}
private static List<currModel> SetcurrData(StringBuilder strSql)
{
var headList = new List<currModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
currModel data = new currModel();
#region Set DB data to Object
data.gid = Convert.ToString(reader["gid"]);
data.codename = Convert.ToString(reader["codename"]);
data.defaultrate = Convert.ToString(reader["defaultrate"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 进口贸易提醒,(import_remind)
static public List<RemindModel> GetRemindList()
{
return GetRemindList(string.Empty);
}
static public List<RemindModel> GetRemindList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select id,Remindname,Remindsql from Import_remind ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetRemindData(strSql);
}
private static List<RemindModel> SetRemindData(StringBuilder strSql)
{
var headList = new List<RemindModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
RemindModel data = new RemindModel();
#region Set DB data to Object
data.RemindName = Convert.ToString(reader["Remindname"]);
data.RemindSql = Convert.ToString(reader["Remindsql"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 贸易商/购货方combox(seller buyer info_client)
static public List<TraderModel> GetTrader()
{
return GetTrader(string.Empty);
}
static public List<TraderModel> GetTrader(string strCondition)
{
var strSql = GetTrader_Getsqlstr(strCondition);
return SetTrader(strSql);
}
public static StringBuilder GetTrader_Getsqlstr(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" select gid,shortname as name,codename code,codename+'_'+shortname codename,description,EnFullName ");
strSql.Append(" ,codename+'_'+EnFullName codeEnname,ISSTOP,RCVMode from info_client where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by codename ");
return strSql;
}
private static List<TraderModel> SetTrader(StringBuilder strSql)
{
var headList = new List<TraderModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
TraderModel data = new TraderModel();
#region Set DB data to Object
data.gid = Convert.ToString(reader["gid"]);
data.name = Convert.ToString(reader["name"]);
data.code = Convert.ToString(reader["code"]);
data.codename = Convert.ToString(reader["codename"]);
data.description = Convert.ToString(reader["description"]);
data.EnFullName = Convert.ToString(reader["EnFullName"]);
data.codeEnName = Convert.ToString(reader["codeEnName"]);
data.ISSTOP = Convert.ToString(reader["ISSTOP"]);
data.RCVMode = Convert.ToString(reader["RCVMode"]);
#endregion
headList.Add(data);
}
reader.Close();
}
//
TraderModel data1 = new TraderModel();
#region Set DB data to Object
data1.gid = "";
data1.name = "";
data1.codename = "";
data1.description = "";
#endregion
headList.Add(data1);
return headList;
}
static public List<TraderModel> GetPCTrader(string strCondition)
{
var strSql = GetPCTrader_Getsqlstr(strCondition);
return SetPCTrader(strSql);
}
public static StringBuilder GetPCTrader_Getsqlstr(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select gid,shortname as name,codename+'_'+shortname codename,description,EnFullName,codename+'_'+EnFullName codeEnname,ADDR from info_client where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
var InfoClintBlstatus = MsSysParamSetDAL.GetData("PARAMNAME='InfoClintBlstatus'");
if (InfoClintBlstatus.PARAMVALUE != "")
{
if (InfoClintBlstatus.PARAMVALUE == "1")
{
strSql.Append(" and BLSTATUS=0 ");
}
}
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by codename ");
return strSql;
}
private static List<TraderModel> SetPCTrader(StringBuilder strSql)
{
var headList = new List<TraderModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
TraderModel data = new TraderModel();
#region Set DB data to Object
data.gid = Convert.ToString(reader["gid"]);
data.name = Convert.ToString(reader["name"]);
data.codename = Convert.ToString(reader["codename"]);
data.description = Convert.ToString(reader["description"]);
data.EnFullName = Convert.ToString(reader["EnFullName"]);
data.codeEnName = Convert.ToString(reader["codeEnName"]);
data.ADDR = Convert.ToString(reader["ADDR"]);
#endregion
headList.Add(data);
}
reader.Close();
}
//
TraderModel data1 = new TraderModel();
#region Set DB data to Object
data1.gid = "";
data1.name = "";
data1.codename = "";
data1.description = "";
#endregion
headList.Add(data1);
return headList;
}
#endregion
#region 获取银行名字列表
static public List<BankModel> GetBank()
{
return GetBank(string.Empty);
}
static public List<BankModel> GetBank(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select gid, bankname,FINANCESOFTCODE,FINANCESOFTCODE+'_'+bankname codename from sys_bank ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetBank(strSql);
}
private static List<BankModel> SetBank(StringBuilder strSql)
{
var headList = new List<BankModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BankModel data = new BankModel();
#region Set DB data to Object
data.gid = Convert.ToString(reader["gid"]);
data.bankname = Convert.ToString(reader["bankname"]);
data.codename = Convert.ToString(reader["codename"]);
data.FINANCESOFTCODE = Convert.ToString(reader["FINANCESOFTCODE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 获取 其他科目代码 用于给科目列表combox提供store
static public List<AccitemsModel> GetAccitems(string strUserID)
{
return GetAccitems(string.Empty, strUserID);
}
static public List<AccitemsModel> GetAccitems(string strCondition, string strUserID)
{
string strCwACCDATE = GetCwACCDATE(strUserID);
var strSql = new StringBuilder();
strSql.Append("select GID,ACCID,ACCNAME,ACCID+'-'+ACCNAME AS ACCIDNAME,DC,ISFCY,REMARKS,DETAILED,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC from cw_accitems where ([year]=SUBSTRING('" + strCwACCDATE + "',1,4) or [year]='' or [year] is null)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by ACCID ");
return SetAccitems(strSql);
}
private static List<AccitemsModel> SetAccitems(StringBuilder strSql)
{
var headList = new List<AccitemsModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
AccitemsModel data = new AccitemsModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.ACCID = Convert.ToString(reader["ACCID"]);
data.ACCNAME = Convert.ToString(reader["ACCNAME"]);
data.ACCIDNAME = Convert.ToString(reader["ACCIDNAME"]);
data.DC = Convert.ToString(reader["DC"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.DETAILED = Convert.ToString(reader["DETAILED"]);
data.ISFCY = Convert.ToBoolean(reader["ISFCY"]);
data.ISDEPTACC = Convert.ToBoolean(reader["ISDEPTACC"]);
data.ISEMPLACC = Convert.ToBoolean(reader["ISEMPLACC"]);
data.ISCORPACC = Convert.ToBoolean(reader["ISCORPACC"]);
data.ISITEMACC = Convert.ToBoolean(reader["ISITEMACC"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<AccitemsModel> GetMngAccitems(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select GID,ACCID,ACCNAME,ACCID+'-'+ACCNAME AS ACCIDNAME,DC,ISFCY,REMARKS,DETAILED,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC from cw_accitems where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetAccitems(strSql);
}
#endregion
#region 查询用户权限
static public List<AuthorityRangemb> GetAR(string modName, string USERID)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,visiblerange,operaterange from user_authority_range where authorityid=( ");
strSql.Append(" select gid from user_authority_info where (name='" + modName + "' or DESCRIPTION='" + modName + "') and isdelete=0 ");
strSql.Append(" and userid='" + USERID + "') ");
return SetAR(strSql);
}
private static List<AuthorityRangemb> SetAR(StringBuilder strSql)
{
var bodyList = new List<AuthorityRangemb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
AuthorityRangemb data = new AuthorityRangemb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.VISIBLERANGE = Convert.ToString(reader["VISIBLERANGE"]);
data.OPERATERANGE = Convert.ToString(reader["OPERATERANGE"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
/// <summary>
/// 获得可视范围的查询子句。相关字段存储的应当都是相应ID
/// </summary>
/// <param name="modName">权限名字 user_authority_info.NAME</param>
/// <param name="USERID"></param>
/// <param name="COMPANYFIELDNAME">用于查询语句中的公司ID的字段或表达式 SQL层面的</param>
/// <param name="USERFIELD">用于查询语句中的人的ID的字段或表达式 SQL层面的</param>
/// <param name="DEPTFIELDNAME">用于查询语句中的部门的ID的字段或表达式 SQL层面的</param>
/// <returns></returns>
public static string GetVisableRange(string modName, string USERID, string COMPANYFIELDNAME, string USERFIELD = "", string DEPTFIELDNAME = "")
{
var evList = BasicDataRefDAL.GetAR(modName, USERID);
AuthorityRangemb head = null;
var result = "";
var VISIBLERANGE = "3";
if (evList.Count > 0)
head = evList[0];
if (head == null)
{
head = new AuthorityRangemb();
}
else
{
VISIBLERANGE = head.VISIBLERANGE;
}
//0 全部
if (VISIBLERANGE == "0")
{
result = "1=1";
}
else
if (VISIBLERANGE == "1")
{//1 分公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in (select companyid from vw_user where userid='" + USERID + "')";
}
else if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in (select USERID from vw_user where companyid =(select companyid from vw_user where userid='" + USERID + "'))";
}
}
else
if (VISIBLERANGE == "2")
{
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = DEPTFIELDNAME + " in (select deptgid from vw_user where userid='" + USERID + "')";
}
else if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in (select USERID from vw_user where deptgid =(select deptgid from vw_user where userid='" + USERID + "'))";
}
}
else
if (VISIBLERANGE == "3")
{
if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " ='" + USERID + "' ";
}
}
else
if (VISIBLERANGE == "4")
{
if (!string.IsNullOrEmpty(USERFIELD))
{
result = "1=2";
}
}
else
if (VISIBLERANGE == "5")
{//选择公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where userid='"
+ USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
else if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
+ USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
else
if (VISIBLERANGE == "6")
{//选择个人
if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
+ USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
if (head == null || result == "")
{
result = "1=2";
}
return result;
}
/// <summary>
/// 可操作范围查询子句
/// </summary>
/// <param name="modName"></param>
/// <param name="USERID"></param>
/// <param name="COMPANYFIELDNAME"></param>
/// <param name="USERFIELD"></param>
/// <param name="DEPTFIELDNAME"></param>
/// <returns></returns>
public static string GetOperateRange(string modName, string USERID, string COMPANYFIELDNAME, string USERFIELD = "", string DEPTFIELDNAME = "")
{
var evList = BasicDataRefDAL.GetAR(modName, USERID);
AuthorityRangemb head = null;
var result = "";
var OPERATERANGE = "3";
if (evList.Count > 0)
head = evList[0];
if (head == null)
{
head = new AuthorityRangemb();
}
else
{
OPERATERANGE = head.OPERATERANGE;
}
//0 全部
if (OPERATERANGE == "0")
{
result = "1=1";
}
else
if (OPERATERANGE == "1")
{//1 分公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "')";
}
else if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in(select USERID from vw_user where companyid =(select companyid from vw_user where userid='" + USERID + "'))";
}
}
else
if (OPERATERANGE == "2")
{
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = DEPTFIELDNAME + " in(select deptid from vw_user where userid='" + USERID + "')";
}
else if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in(select USERID from vw_user where deptid =(select deptid from vw_user where userid='" + USERID + "'))";
}
}
else
if (OPERATERANGE == "3")
{
if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " ='" + USERID + "' ";
}
}
else
if (OPERATERANGE == "4")
{
if (!string.IsNullOrEmpty(USERFIELD))
{
result = "1=2";
}
}
else
if (OPERATERANGE == "5")
{//选择公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where userid='"
+ USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
else if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
+ USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
else
if (OPERATERANGE == "6")
{//选择个人
if (!string.IsNullOrEmpty(USERFIELD))
{
result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
+ USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
if (head == null || result == "")
{
result = "1=2";
}
return result;
}
/// <summary>
/// 组织权限语句的方法 通用版(目前内贸和运价报价模块使用)
/// </summary>
/// <param name="modName"></param>
/// <param name="USERID"></param>
/// <param name="COMPANYFIELDNAME"></param>
/// <param name="USERFIELDArray"></param>
/// <param name="DEPTFIELDNAME"></param>
/// <returns></returns>
public static string GetRangeCondition(RangeType rangetype, string modName, string USERID, string COMPANYFIELDNAME, string[] USERFIELDArray, string DEPTFIELDNAME = "")
{
var RANGENAME = "";
if (rangetype == RangeType.Visable)
{
RANGENAME = "VISIBLERANGE";
}
if (rangetype == RangeType.Operate)
{
RANGENAME = "OPERATERANGE";
}
if (RANGENAME == "") return " 1=2 ";
var evList = BasicDataRefDAL.GetAR(modName, USERID);
if (evList.Count == 0) return " 1=2 ";
AuthorityRangemb head = null;
var result = "";
var RANGEVALUE = "3";
if (evList.Count > 0)
head = evList[0];
if (head == null)
{
head = new AuthorityRangemb();
}
else
{
if (rangetype == RangeType.Visable)
{
RANGEVALUE = head.VISIBLERANGE;
}
if (rangetype == RangeType.Operate)
{
RANGEVALUE = head.OPERATERANGE;
}
}
//0 全部
if (RANGEVALUE == "0")
{
result = "1=1";
}
else
if (RANGEVALUE == "1")
{//1 分公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select top 1 companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" +
" union all select SHOWNAME from vw_user where companyid in(select top 1 companyid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = "("+_S+")";
}
}
else
if (RANGEVALUE == "2")
{
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select top 1 companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')";
result += " and " + DEPTFIELDNAME + " in(select top 1 deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "' union all select top 1 deptname from vw_user where userid='" + USERID + "' or showname='" + USERID + "' ) ";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in( select USERID from vw_user where deptgid in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" +
"union all select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = "(" + _S + ")";
}
}
else
if (RANGEVALUE == "3")
{
if (USERFIELDArray.Length > 0)
{
//result = USERFIELD + " ='" + USERID + "' ";
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " ='" + USERID + "' or " + USERFIELD + " =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result ="("+ _S+")";
}
}
else
if (RANGEVALUE == "4")
{
if (USERFIELDArray.Length > 0)
{
result = "1=2";
}
}
else
if (RANGEVALUE == "5")
{//选择公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='" + modName + "' or DESCRIPTION='" + modName + "') and " + RANGENAME + " = 1)";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + " exists(select 1 from vw_user where companyid in " +
"(select companyid from user_authority_range_company where AUTHORITYID = " +
"(select GID from user_authority_info where Name = '" + modName + "' or DESCRIPTION = '" + modName + "') and " + RANGENAME + " = 1 " +
") and(userid = " + USERFIELD + " or SHOWNAME = " + USERFIELD + "))";
}
result = "(" + _S + ")";
//result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
else
if (RANGEVALUE == "6")
{//选择个人
if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" +
"or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "')" +
"and " + RANGENAME + " = 1 union all select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" +
" or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "') and " + RANGENAME + " = 1))";
}
result = "(" + _S + ")";
//result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
if (head == null || result == "")
{
result = "1=2";
}
return result;
}
public enum RangeType
{
Visable,
Operate
}
/// <summary>
/// 获得可视范围的查询子句。相关字段存储的 user或dept可以是相应ID或中文名 company必须是ID
/// var rangestr = BasicDataRefDAL.GetVisableRange("modYAXIANG", USERID, "COMPANYID", new string[]{ "CREATEUSER"}, "DEPTID");
/// </summary>
/// <param name="modName">权限名字 user_authority_info.NAME或description</param>
/// <param name="USERID"></param>
/// <param name="COMPANYFIELDNAME">用于查询语句中的公司ID的字段或表达式 SQL层面的</param>
/// <param name="USERFIELD">用于查询语句中的人的ID的字段或表达式 SQL层面的</param>
/// <param name="DEPTFIELDNAME">用于查询语句中的部门的ID的字段或表达式 SQL层面的</param>
/// <returns></returns>
public static string GetVisableRange2(string modName, string USERID, string COMPANYFIELDNAME, string[] USERFIELDArray, string DEPTFIELDNAME = "")
{
var evList = BasicDataRefDAL.GetAR(modName, USERID);
AuthorityRangemb head = null;
var result = "";
var VISIBLERANGE = "3";
if (evList.Count > 0)
head = evList[0];
if (head == null)
{
head = new AuthorityRangemb();
}
else
{
VISIBLERANGE = head.VISIBLERANGE;
}
//0 全部
if (VISIBLERANGE == "0")
{
result = "1=1";
}
else
if (VISIBLERANGE == "1")
{//1 分公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" +
" union all select SHOWNAME from vw_user where companyid in(select companyid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = _S;
}
}
else
if (VISIBLERANGE == "2")
{//限定部门 此时dept参数必须要有
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')";
result += " and " + DEPTFIELDNAME + " in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "' union all select deptname from vw_user where userid='" + USERID + "' or showname='" + USERID + "' ) ";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in( select USERID from vw_user where deptgid in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" +
"union all select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = _S;
}
}
else
if (VISIBLERANGE == "3")
{
if (USERFIELDArray.Length > 0)
{
//result = USERFIELD + " ='" + USERID + "' ";
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " ='" + USERID + "' or " + USERFIELD + " =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = _S;
}
}
else
if (VISIBLERANGE == "4")
{
if (USERFIELDArray.Length > 0)
{
result = "1=2";
}
}
else
if (VISIBLERANGE == "5")
{//选择公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='" + modName + "' or DESCRIPTION='" + modName + "') and VISIBLERANGE = 1)";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + " exists(select 1 from vw_user where companyid in " +
"(select companyid from user_authority_range_company where AUTHORITYID = " +
"(select GID from user_authority_info where Name = '" + modName + "' or DESCRIPTION = '" + modName + "') and VISIBLERANGE = 1 " +
") and(userid = " + USERFIELD + " or SHOWNAME = " + USERFIELD + "))";
}
result = _S;
//result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
else
if (VISIBLERANGE == "6")
{//选择个人
if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" +
"or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "')" +
"and VISIBLERANGE = 1 union all select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" +
" or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "') and VISIBLERANGE = 1))";
}
result = _S;
//result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
if (head == null || result == "")
{
result = "1=2";
}
return result;
}
/// <summary>
/// 可操作范围查询子句
/// </summary>
/// <param name="modName"></param>
/// <param name="USERID"></param>
/// <param name="COMPANYFIELDNAME"></param>
/// <param name="USERFIELD"></param>
/// <param name="DEPTFIELDNAME"></param>
/// <returns></returns>
public static string GetOperateRange2(string modName, string USERID, string COMPANYFIELDNAME, string[] USERFIELDArray, string DEPTFIELDNAME = "")
{
var evList = BasicDataRefDAL.GetAR(modName, USERID);
AuthorityRangemb head = null;
var result = "";
var OPERATERANGE = "3";
if (evList.Count > 0)
head = evList[0];
if (head == null)
{
head = new AuthorityRangemb();
}
else
{
OPERATERANGE = head.OPERATERANGE;
}
//0 全部
if (OPERATERANGE == "0")
{
result = "1=1";
}
else
if (OPERATERANGE == "1")
{//1 分公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" +
" union all select SHOWNAME from vw_user where companyid in(select companyid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = _S;
}
}
else
if (OPERATERANGE == "2")
{
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')";
result += " and " + DEPTFIELDNAME + " in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "' union all select deptname from vw_user where userid='" + USERID + "' or showname='" + USERID + "' ) ";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in( select USERID from vw_user where deptgid in(select deptgid from vw_user where userid='" + USERID + "' or showname='" + USERID + "')" +
"union all select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = _S;
}
}
else
if (OPERATERANGE == "3")
{
if (USERFIELDArray.Length > 0)
{
//result = USERFIELD + " ='" + USERID + "' ";
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " ='" + USERID + "' or " + USERFIELD + " =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '" + USERID + "' or showname = '" + USERID + "'))";
}
result = _S;
}
}
else
if (OPERATERANGE == "4")
{
if (USERFIELDArray.Length > 0)
{
result = "1=2";
}
}
else
if (OPERATERANGE == "5")
{//选择公司
if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='" + modName + "' or DESCRIPTION='" + modName + "') and OPERATERANGE = 1)";
}
else if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + " exists(select 1 from vw_user where companyid in " +
"(select companyid from user_authority_range_company where AUTHORITYID = " +
"(select GID from user_authority_info where Name = '" + modName + "' or DESCRIPTION = '" + modName + "') and OPERATERANGE = 1 " +
") and(userid = " + USERFIELD + " or SHOWNAME = " + USERFIELD + "))";
}
result = _S;
//result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)";
}
}
else
if (OPERATERANGE == "6")
{//选择个人
if (USERFIELDArray.Length > 0)
{
var _S = "";
foreach (var USERFIELD in USERFIELDArray)
{
if (_S != "") _S += " or ";
_S = _S + USERFIELD + " in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" +
"or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "')" +
"and OPERATERANGE = 1 union all select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '" + USERID + "'" +
" or showname = '" + USERID + "') and AUTHORITYID = (select GID from user_authority_info where name = '" + modName + "' or description = '" + modName + "') and OPERATERANGE = 1))";
}
result = _S;
//result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)";
}
}
#region 旧的单关键字段算法
//else
//if (OPERATERANGE == "1")
//{//1 分公司
// if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
// {
// result = COMPANYFIELDNAME + " in(select companyid from vw_user where userid='" + USERID + "')";
// }
// else if (!string.IsNullOrEmpty(USERFIELD))
// {
// result = USERFIELD + " in(select USERID from vw_user where companyid =(select companyid from vw_user where userid='" + USERID + "'))";
// }
//}
//else
//if (OPERATERANGE == "2")
//{
// if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
// {
// result = DEPTFIELDNAME + " in(select deptid from vw_user where userid='" + USERID + "')";
// }
// else if (!string.IsNullOrEmpty(USERFIELD))
// {
// result = USERFIELD + " in(select USERID from vw_user where deptid =(select deptid from vw_user where userid='" + USERID + "'))";
// }
//}
//else
//if (OPERATERANGE == "3")
//{
// if (!string.IsNullOrEmpty(USERFIELD))
// {
// result = USERFIELD + " ='" + USERID + "' ";
// }
//}
//else
//if (OPERATERANGE == "4")
//{
// if (!string.IsNullOrEmpty(USERFIELD))
// {
// result = "1=2";
// }
//}
//else
//if (OPERATERANGE == "5")
//{//选择公司
// if (!string.IsNullOrEmpty(COMPANYFIELDNAME))
// {
// result = COMPANYFIELDNAME + " in(select COMPANYID from user_authority_range_company where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)";
// }
// else if (!string.IsNullOrEmpty(USERFIELD))
// {
// result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)";
// }
//}
//else
//if (OPERATERANGE == "6")
//{//选择个人
// if (!string.IsNullOrEmpty(USERFIELD))
// {
// result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and OPERATERANGE=1)";
// }
//}
#endregion
if (head == null || result == "")
{
result = "1=2";
}
return result;
}
/// <summary>
/// 返回查询子句
/// 用于判断USERID是否具有对【head这条业务】的【ModName权限】的使用权
/// </summary>
/// <param name="head"></param>
/// <param name="ModName"></param>
/// <returns></returns>
public static string CanOperateStr_INVOICE(string ModName, string USERID)
{
var rangestr = BasicDataRefDAL.GetOperateRange(ModName, USERID, "COMPANYID", "OPERATOR");
return rangestr;
}
//public class USERINFO {
// public string USERID { get; set; }
// public string USERID { get; set; }
// public string USERID { get; set; }
// public string USERID { get; set; }
// public USERINFO(HttpSessionStateBase CurrSession) {
// new USERINFO(CurrSession["USERID"].ToString(), CurrSession["SHOWNAME"].ToString(), CurrSession["COMPANYID"].ToString(), CurrSession["DEPTNAME"].ToString());
// }
// public USERINFO(string USERID, string SHOWNAME, string COMPANYID, string DEPTNAME) {
// }
//}
#endregion
#region 获取本部门领取且未支取的支票号
static public List<CHEQUENUMmb> GetUnusedCHEQUENUM(string DEPTID, string BXGID)
{
var strSql = new StringBuilder();
strSql.Append(" select '外代IC卡' chequeno union all ");
strSql.Append(" select '外运IC卡' chequeno union all ");
strSql.Append(" select '挂账' chequeno union all ");
strSql.Append(" select chequeno from( ");
strSql.Append(" select cfc.chequeno,bxgid from ch_fee_cheque cfc ");
strSql.Append(" left join ch_fee on ch_fee.chequenum=cfc.chequeno ");
strSql.Append(" where cfc.billno in (select gid from OA_Jiekuan where deptid='" + DEPTID + "') ");
strSql.Append(" and cfc.chequeno is not null and cfc.chequeno<>'')t ");
strSql.Append(" where bxgid is null or bxgid='" + BXGID + "' ");
return SetUnusedCHEQUENUM(strSql);
}
private static List<CHEQUENUMmb> SetUnusedCHEQUENUM(StringBuilder strSql)
{
var bodyList = new List<CHEQUENUMmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CHEQUENUMmb data = new CHEQUENUMmb();
#region Set DB data to Object
data.CHEQUENUM = Convert.ToString(reader["CHEQUENO"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 获取工作流typeno 用于在工作流管理界面选择typeno
static public List<WorkFlowmb> GetTYPENO(string condition)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,name+'_'+description as name,typeno from workflow_type ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
return SetTYPENO(strSql);
}
private static List<WorkFlowmb> SetTYPENO(StringBuilder strSql)
{
var bodyList = new List<WorkFlowmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlowmb data = new WorkFlowmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.TYPENO = Convert.ToString(reader["TYPENO"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 通过工作流名字查找工作流编号
/*
static public List<WorkFlowmb> GetWorkFlowID(string NAME, string OrgCode)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,[Name] from workflow where ");
strSql.Append(" [type]=(select typeno from workflow_type where name= '" + NAME + "') ");
strSql.Append(" and companyid=(select gid from company where codename='" + OrgCode + "' ) ");
return SetWorkFlowID(strSql);
}
private static List<WorkFlowmb> SetWorkFlowID(StringBuilder strSql)
{
var bodyList = new List<WorkFlowmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlowmb data = new WorkFlowmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}*/
#endregion
#region 通过workflow_type.nameuserid查找workflow_step的内容
static public List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> GetWorkFlowStep(string WorkFlowName, string UserID)
{
var strSql = new StringBuilder();
strSql.Append(" select * from workflow_step where WORKFLOWID in ");
strSql.Append(" (select gid from workflow where [type]=(select [typeno] from workflow_type where [name]='" + WorkFlowName + "')) ");
strSql.Append(" and AUDITOR='" + UserID + "' order by STEPNO");
return SetWorkFlowStep(strSql);
}
private static List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> SetWorkFlowStep(StringBuilder strSql)
{
var bodyList = new List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
DSWeb.Areas.CommMng.Models.WorkFlowStepmb data = new DSWeb.Areas.CommMng.Models.WorkFlowStepmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.STEPNO = Convert.ToString(reader["STEPNO"]);
data.NEEDALLPASS = Convert.ToString(reader["NEEDALLPASS"]);
data.ISMUST = Convert.ToString(reader["ISMUST"]);
data.ISLAST = Convert.ToString(reader["ISLAST"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 获取该用户,在该工作流程的该步骤中 可以操作的业务编号列表
/*
static public List<WorkFlow_Usingmb> GetWorkFlowState(string WorkFlowID, int StepNo, string USERID)
{
var strSql = new StringBuilder();
strSql.Append(" select * from workflow_using ");
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
strSql.Append(" and stepno=( ");
strSql.Append(" select stepno from workflow_step ");
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
strSql.Append(" and auditor='" + USERID + "' ");
strSql.Append(" and stepno=" + StepNo.ToString() + ") ");
return SetWorkFlowState(strSql);
}
private static List<WorkFlow_Usingmb> SetWorkFlowState(StringBuilder strSql)
{
var bodyList = new List<WorkFlow_Usingmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlow_Usingmb data = new WorkFlow_Usingmb();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]);
data.STEPNO = Convert.ToString(reader["STEPNO"]);
data.REJECTOR_ID = Convert.ToString(reader["REJECTOR_ID"]);
data.REJECT_TIME = Convert.ToString(reader["REJECT_TIME"]);
data.FINISHED = Convert.ToString(reader["FINISHED"]);
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
*/
#endregion
#region 键值维护表 crm_key_code
static public List<CrmKeyCodeModel> GetCrmKeyCodeList(string strCondition)
{
String strSql = "SELECT ID as GID,KEYTYPE,KEYVALUE from crm_key_code ";
if (!string.IsNullOrEmpty(strCondition))
{
strSql += " where 1=1 " + strCondition;
}
return SetCrmKeyCodeData(strSql);
}
private static List<CrmKeyCodeModel> SetCrmKeyCodeData(String strSql)
{
var headList = new List<CrmKeyCodeModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CrmKeyCodeModel data = new CrmKeyCodeModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.KEYTYPE = Convert.ToString(reader["KEYTYPE"]);
data.KEYVALUE = Convert.ToString(reader["KEYVALUE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 品名
static public List<CodeGoodsModel> GetCodeMsdsGoodsList(string condition)
{
String strSql = "SELECT GID,GOODNAME GOODCODE,(CHEMICALCGOODSNAME+ '-' + GOODNAME+'-'+DCLASS) as CodeAndName,(CHEMICALCGOODSNAME+ '-' + CHEMICALCGOODSNAME) as GOODNAME,'' GoodsTypeGID,'' GoodsTypeName from code_msds ";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
strSql += " order by CodeAndName";
return SetCodeGoodsData(strSql);
}
static public List<CodeGoodsModel> GetCodeGoodsList(string condition)
{
String strSql = "SELECT GID,GOODCODE,(GOODCODE+'-'+GOODNAME) as CodeAndName,GOODNAME,GoodsTypeGID,GoodsTypeName=(select top 1 GoodsTypeName from code_goodsType where gid=code_goods.GoodsTypeGID) from code_goods ";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
strSql += " order by CodeAndName";
return SetCodeGoodsData(strSql);
}
static public List<CodeGoodsModel> GetImportCodeGoodsList(string condition)
{
String strSql = "SELECT CNNAME GID,CNNAME GOODCODE,CNNAME as CodeAndName,CNNAME GOODNAME,'' GoodsTypeGID,'' GoodsTypeName from Import_Cargoname ";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
strSql += " order by CNNAME";
return SetCodeGoodsData(strSql);
}
private static List<CodeGoodsModel> SetCodeGoodsData(String strSql)
{
var headList = new List<CodeGoodsModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeGoodsModel data = new CodeGoodsModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//货物代码
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//商品编码
data.GOODCODE = Convert.ToString(reader["GOODCODE"]);//商品编码
data.GOODNAME = Convert.ToString(reader["GOODNAME"]);//商品名称
data.GoodsTypeGID = Convert.ToString(reader["GoodsTypeGID"]);//
data.GoodsTypeName = Convert.ToString(reader["GoodsTypeName"]);//
#endregion
headList.Add(data);
}
reader.Close();
}
CodeGoodsModel adata = new CodeGoodsModel();
#region Set DB data to Object
adata.GID = "";//货物代码
adata.CodeAndName = "";//商品编码
adata.GOODCODE = "";//商品编码
adata.GOODNAME = "";//商品名称
adata.GoodsTypeGID = "";
adata.GoodsTypeName = "";
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 品名明细表
static public List<CodeGoodsDetailModel> GetCodeGoodsDetailList(string condition)
{
String strSql = "SELECT *,GOODNAME=(select top 1 GOODNAME from code_goods where gid=code_goods_detail.LINKGID) from code_goods_detail ";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
strSql += " order by GOODSDETAILNAME";
return SetCodeGoodsDetailData(strSql);
}
private static List<CodeGoodsDetailModel> SetCodeGoodsDetailData(String strSql)
{
var headList = new List<CodeGoodsDetailModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeGoodsDetailModel data = new CodeGoodsDetailModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//惟一编号
data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//品名GID
data.GOODSDETAILNAME = (reader["GOODSDETAILNAME"] == null ? "" : Convert.ToString(reader["GOODSDETAILNAME"]));//品牌名称
data.REMARK = (reader["REMARK"] == null ? "" : Convert.ToString(reader["REMARK"]));//备注
data.GOODSDETAILPKGS = (reader["GOODSDETAILPKGS"] == null ? 0 : Convert.ToDecimal(reader["GOODSDETAILPKGS"]));//规格件数
data.GOODNAME = (reader["GOODNAME"] == null ? "" : Convert.ToString(reader["GOODNAME"]));//品名
#endregion
headList.Add(data);
}
reader.Close();
}
CodeGoodsDetailModel adata = new CodeGoodsDetailModel();
#region Set DB data to Object
adata.GID = "";//惟一编号
adata.LINKGID = "";//品名GID
adata.GOODSDETAILNAME = "";//品牌名称
adata.REMARK = "";//备注
adata.GOODSDETAILPKGS = 0;//规格件数
adata.GOODNAME = "";//品名
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 新版键值维护表 tSysEnumValue
static public List<TSysEnumValueDataModel> GetTSysEnumValueList(string strCondition)
{
String strSql = "select *,CodeAndName=(EnumValueID+' | '+EnumValueName) from tSysEnumValue";//需求编号SR2017081100003
if (!string.IsNullOrEmpty(strCondition))
{
strSql += " where LangId=0 " + strCondition;
}
return SetTSysEnumValueData(strSql);
}
static public List<TSysEnumValueDataModel> GetTSysEnumValueListByTypeid(string typeid)
{
String strSql = "select *,CodeAndName=(EnumValueID+' | '+EnumValueName) from tSysEnumValue";//需求编号SR2017081100003
strSql += " where LangId=0 and enumtypeid='" + typeid + "'";
return SetTSysEnumValueData(strSql);
}
private static List<TSysEnumValueDataModel> SetTSysEnumValueData(String strSql)
{
var headList = new List<TSysEnumValueDataModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
TSysEnumValueDataModel data = new TSysEnumValueDataModel();
#region Set DB data to Object
data.EnumValueID = Convert.ToString(reader["EnumValueID"]);//需求编号SR2017081100003
data.EnumValueName = Convert.ToString(reader["EnumValueName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//需求编号SR2017081100003
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 国际港口(进口装货港、出口卸货港)
static public List<CodeDisportModel> GetCodeDisportList(string condition)
{
String strSql = GetCodeDisportList_Sqlstr(condition);
return SetCodeDisportData(strSql);
}
static public List<CodeDisportModel> GetCodeDisportbyEDICODE(string EDICODE)
{
String strSql = "SELECT *,(PORT+'-'+EDICODE) as CodeAndName,(select LANE from code_lanes where GID=Code_Disport.LANEGID) LANE from Code_Disport where EDICODE='" + EDICODE + "'";
return SetCodeDisportData(strSql);
}
static public List<CodeDisportModel> GetCodeRailwayPortList(string condition)
{
String strSql = "SELECT PORTENAME PORT,PORTCNAME CNAME,'' EDICODE,(PORTENAME+'-'+PORTCNAME) as CodeAndName,'' LANE from code_railwayport where ";
if (condition != "") strSql = strSql + condition;
strSql = strSql + " ORDER BY PORTENAME ";
return SetCodeDisportData(strSql);
}
public static string GetCodeDisportList_Sqlstr(string condition)
{
String strSql = "SELECT *,(PORT+'-'+EDICODE+'('+CNAME+')') as CodeAndName,(select LANE from code_lanes where GID=Code_Disport.LANEGID) LANE from Code_Disport where ";
if (condition != "") strSql = strSql + condition + " and ";
strSql = strSql + " EDICODE<>'' ORDER BY PORT ";
return strSql;
}
public static string GetCodeDisportList_DisplayWithCNAME_Sqlstr(string condition)
{
String strSql = "SELECT *,(PORT+'-'+EDICODE+'-'+CNAME) as CodeAndName,(select LANE from code_lanes where GID=Code_Disport.LANEGID) LANE from Code_Disport where ";
if (condition != "") strSql = strSql + condition + " and ";
strSql = strSql + " EDICODE<>'' ORDER BY PORT ";
return strSql;
}
private static List<CodeDisportModel> SetCodeDisportData(String strSql)
{
var headList = new List<CodeDisportModel>();
#region 在开头插入空值
CodeDisportModel data2 = new CodeDisportModel();
data2.PORT = "";//港口英文名称
data2.CNAME = "";//中文名称
data2.EDICODE = "";//中文名称
data2.CodeAndName = "";//中文名称
data2.LANE = "";//中文名称
headList.Add(data2);
#endregion
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeDisportModel data = new CodeDisportModel();
#region Set DB data to Object
data.PORT = Convert.ToString(reader["PORT"]);//港口英文名称
data.CNAME = Convert.ToString(reader["CNAME"]);//中文名称
data.EDICODE = Convert.ToString(reader["EDICODE"]);//中文名称
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//中文名称
data.LANE = Convert.ToString(reader["LANE"]);//航线
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 国内港口(出口装货港、进口卸货港)
static public List<CodeLoadportModel> GetCodeLoadportList(string condition)
{
String strSql = GetCodeLoadportList_Sqlstr(condition);
return SetCodeLoadportData(strSql);
}
public static string GetCodeLoadportList_Sqlstr(string condition)
{
String strSql = "SELECT *,(PORT+'-'+CNAME) as CodeAndName from Code_Loadport WHERE EDICODE<>'' ";
if (condition != "") strSql = strSql + " and " + condition;
return strSql;
}
static public List<CodeLoadportModel> GetCodeLoadportList()
{
String strSql = "SELECT *,(PORT+'-'+CNAME) as CodeAndName from Code_Loadport WHERE EDICODE<>'' ";
return SetCodeLoadportData(strSql);
}
static public List<CodeLoadportModel> GetLoadportbyEDI(string EDICODE)
{
String strSql = "SELECT *,(PORT+'-'+CNAME) as CodeAndName from Code_Loadport WHERE EDICODE='" + EDICODE + "' ";
return SetCodeLoadportData(strSql);
}
private static List<CodeLoadportModel> SetCodeLoadportData(String strSql)
{
var headList = new List<CodeLoadportModel>();
#region 在最开头插入空值
CodeLoadportModel data2 = new CodeLoadportModel();
data2.PORT = "";//港口英文名称
data2.CNAME = "";//中文名称
data2.EDICODE = "";//中文名称
data2.CodeAndName = "";//中文名称
headList.Add(data2);
#endregion
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeLoadportModel data = new CodeLoadportModel();
#region Set DB data to Object
data.PORT = Convert.ToString(reader["PORT"]);//港口英文名称
data.CNAME = Convert.ToString(reader["CNAME"]);//中文名称
data.EDICODE = Convert.ToString(reader["EDICODE"]);//中文名称
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);//中文名称
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 品名类型
static public List<sys_template> Getsys_templateList()
{
String strSql = "select GID,[TEMPLATE],[TEMPLATETYPE],[COMPANYID],[TEMPLDATE_DESC] from sys_template where TEMPLATETYPE='发票备注'";
return Setsys_templateData(strSql);
}
private static List<sys_template> Setsys_templateData(String strSql)
{
var headList = new List<sys_template>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
sys_template data = new sys_template();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//货物代码
data.TEMPLATE = Convert.ToString(reader["TEMPLATE"]);
data.TEMPLATETYPE = Convert.ToString(reader["TEMPLATETYPE"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.TEMPLDATE_DESC = Convert.ToString(reader["TEMPLDATE_DESC"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 品名类型
static public List<CodeGoodsTypeModel> GetCodeGoodsTypeList()
{
String strSql = "select *,(GoodsTypeCode+'-'+GoodsTypeName) as CodeAndName from Code_GoodsType";
return SetCodeGoodsTypeData(strSql);
}
private static List<CodeGoodsTypeModel> SetCodeGoodsTypeData(String strSql)
{
var headList = new List<CodeGoodsTypeModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeGoodsTypeModel data = new CodeGoodsTypeModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//货物代码
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
data.GoodsTypeCode = Convert.ToString(reader["GoodsTypeCode"]);
data.GoodsTypeName = Convert.ToString(reader["GoodsTypeName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 箱型
static public List<CodeCtnModel> GetCodeCtnList()
{
String strSql = "select * from [code_ctn] ORDER BY CTNID ";
return SetCodeCtnData(strSql);
}
private static List<CodeCtnModel> SetCodeCtnData(String strSql, bool isempty = true)
{
var headList = new List<CodeCtnModel>();
if (isempty)
{
CodeCtnModel data2 = new CodeCtnModel();
data2.CTN = "";
data2.DLIKGS = 0M;
headList.Add(data2);
}
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeCtnModel data = new CodeCtnModel();
#region Set DB data to Object
data.CTN = Convert.ToString(reader["CTN"]);
if (reader["DLIKGS"] != DBNull.Value)
data.DLIKGS = Convert.ToDecimal(reader["DLIKGS"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<CodeCtnModel> GetCodeCtnList(string condition, bool isempty = true)
{
String strSql = "select * from [code_ctn] ";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
strSql += " ORDER BY CTNID";
return SetCodeCtnData(strSql, isempty);
}
#endregion
#region 集装箱显示
static public CtnDispModel GetCtnDisp()
{
String strSql = "SELECT top 1 * from code_ctn_disp";
return SetCtnDispData(strSql);
}
private static CtnDispModel SetCtnDispData(String strSql)
{
var headList = new CtnDispModel();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CtnDispModel data = new CtnDispModel();
#region Set DB data to Object
data.ID = Convert.ToString(reader["ID"]);
data.CNT1 = Convert.ToString(reader["CNT1"]);
data.CNT2 = Convert.ToString(reader["CNT2"]);
data.CNT3 = Convert.ToString(reader["CNT3"]);
data.CNT4 = Convert.ToString(reader["CNT4"]);
data.CNT5 = Convert.ToString(reader["CNT5"]);
data.CNT6 = Convert.ToString(reader["CNT6"]);
data.CNT7 = Convert.ToString(reader["CNT7"]);
data.CNT8 = Convert.ToString(reader["CNT8"]);
data.CNT9 = Convert.ToString(reader["CNT9"]);
data.CNT10 = Convert.ToString(reader["CNT10"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
#endregion
headList = data;
}
reader.Close();
}
return headList;
}
#endregion
#region 航线
static public List<LaneModel> GetCodeLaneList()
{
String strSql = "select * from [code_lanes] ORDER BY LANE";
return SetCodeLaneData(strSql);
}
private static List<LaneModel> SetCodeLaneData(String strSql)
{
var headList = new List<LaneModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
LaneModel data = new LaneModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LANEID = Convert.ToString(reader["LANEID"]);
data.LANE = Convert.ToString(reader["LANE"]);
data.LANEEN = Convert.ToString(reader["LANEEN"]);
data.EDICODE = Convert.ToString(reader["EDICODE"]);
data.OP = Convert.ToString(reader["OP"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
LaneModel adata = new LaneModel();
#region Set DB data to Object
adata.GID = "";
adata.LANEID = "";
adata.LANE = "";
adata.LANEEN = "";
adata.EDICODE = "";
#endregion
headList.Add(adata);
return headList;
}
#endregion
#region 付费方式
static public List<CodeFrtModel> GetCodeFrtList()
{
String strSql = "select * from code_frt ORDER BY FRT";
return SetCodeFrtData(strSql);
}
private static List<CodeFrtModel> SetCodeFrtData(String strSql)
{
var headList = new List<CodeFrtModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeFrtModel data = new CodeFrtModel();
#region Set DB data to Object
data.FEID = Convert.ToString(reader["FEID"]);
data.FRT = Convert.ToString(reader["FRT"]);
data.FRTCNAME = Convert.ToString(reader["FRTCNAME"]);
data.EDICODE = Convert.ToString(reader["EDICODE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 签单方式
static public List<CodeBLTYPEModel> GetCodeBLTYPEList()
{
String strSql = "select * from code_issutype ORDER BY BLTYPE";
return SetCodeBLTYPEData(strSql);
}
private static List<CodeBLTYPEModel> SetCodeBLTYPEData(String strSql)
{
var headList = new List<CodeBLTYPEModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeBLTYPEModel data = new CodeBLTYPEModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BLTYPE = Convert.ToString(reader["BLTYPE"]);
data.NOBILL = Convert.ToString(reader["NOBILL"]);
data.COPYNOBILL = Convert.ToString(reader["COPYNOBILL"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 运输条款
static public List<CodeSERVICEModel> GetCodeSERVICEList()
{
String strSql = "select * from code_service ORDER BY SERVICE";
return SetCodeSERVICEData(strSql);
}
private static List<CodeSERVICEModel> SetCodeSERVICEData(String strSql)
{
var headList = new List<CodeSERVICEModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeSERVICEModel data = new CodeSERVICEModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.SERVICE = Convert.ToString(reader["SERVICE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 提单模板
static public List<CodeTemplateModel> GetCodeTemplateList()
{
String strSql = "select * from code_template ";
return SetCodeTemplateData(strSql);
}
private static List<CodeTemplateModel> SetCodeTemplateData(String strSql)
{
var headList = new List<CodeTemplateModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeTemplateModel data = new CodeTemplateModel();
#region Set DB data to Object
data.TEMPLATEID = Convert.ToString(reader["TEMPLATEID"]);
data.TEMPLATE = Convert.ToString(reader["TEMPLATE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 件数包装
static public List<CodePackageModel> GetCodePackageList()
{
String strSql = "select * from [code_package] order by PKGS";
return SetCodePackageData(strSql);
}
private static List<CodePackageModel> SetCodePackageData(String strSql)
{
var headList = new List<CodePackageModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodePackageModel data = new CodePackageModel();
#region Set DB data to Object
data.PKGS = Convert.ToString(reader["PKGS"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 币别
static public List<CodeCurrencyModel> GetCodeCurrencyList(string condition)
{
String strSql = "select * from [code_currency]";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
return SetCodeCurrencyData(strSql);
}
private static List<CodeCurrencyModel> SetCodeCurrencyData(String strSql)
{
var headList = new List<CodeCurrencyModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CodeCurrencyModel data = new CodeCurrencyModel();
#region Set DB data to Object
data.CODENAME = Convert.ToString(reader["CODENAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 委托单位_联系人
static public List<InfoClientContactModel> GetInfoClientContactList(string condition)
{
String strSql = "select * from [info_client_contact]";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
return SetInfoClientContactData(strSql);
}
private static List<InfoClientContactModel> SetInfoClientContactData(String strSql)
{
var headList = new List<InfoClientContactModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
InfoClientContactModel data = new InfoClientContactModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.SHOWNAME = Convert.ToString(reader["SHOWNAME"]);
data.EMAIL = Convert.ToString(reader["EMAIL"]);
data.TEL = Convert.ToString(reader["TEL"]);
data.FAX = Convert.ToString(reader["FAX"]);
#endregion
headList.Add(data);
}
reader.Close();
}
var _blank = new InfoClientContactModel();
headList.Add(_blank);
return headList;
}
static public List<InfoClientContactModel> GetInfoClientMailTel(string CUSTOMERNAME)
{
var ContactList = GetInfoClientContactList(" LINKID in(select GID from info_client where shortname='" + CUSTOMERNAME + "') and isnull(email,'')<>'' ");
if (!string.IsNullOrWhiteSpace(CUSTOMERNAME))
{
var infoclient = MsInfoClientDAL.GetData(" shortname='" + CUSTOMERNAME + "' ");
var _infoclient = new InfoClientContactModel();
_infoclient.SHOWNAME = infoclient.SHORTNAME;
_infoclient.TEL = infoclient.TEL;
_infoclient.EMAIL = infoclient.EMAIL;
if (!string.IsNullOrWhiteSpace(_infoclient.EMAIL))
ContactList.Add(_infoclient);
var _infoclient2 = new InfoClientContactModel();
_infoclient2.SHOWNAME = "注意:下拉选项当中带汉字名字,选中后会使用其后方的邮箱地址(不带汉字);你也可以手动输入邮箱,但这时输入的内容请不要带其他汉字,否则无法正确发送邮件。";
ContactList.Add(_infoclient2);
}
return ContactList;
}
#endregion
#region 项目
static public List<CwItemModel> GetCwItemList(string condition, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
String strSql = "SELECT *,(FINANCESOFTCODE+'-'+ITEMNAME) as CodeAndName from cw_item where [STARTGID]='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) order by ITEMCODE,ITEMNAME";
return SetCwItemData(strSql);
}
private static List<CwItemModel> SetCwItemData(String strSql)
{
var headList = new List<CwItemModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
CwItemModel data = new CwItemModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
data.ITEMCODE = (reader["ITEMCODE"] == null ? "" : Convert.ToString(reader["ITEMCODE"]));//年
data.ITEMNAME = (reader["ITEMNAME"] == null ? "" : Convert.ToString(reader["ITEMNAME"]));//月
data.FINANCESOFTCODE = (reader["FINANCESOFTCODE"] == null ? "" : Convert.ToString(reader["FINANCESOFTCODE"]));//月
data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司代码
data.ISDELETE = (reader["ISDELETE"] == null ? false : Convert.ToBoolean(reader["ISDELETE"]));//是否删除
data.DELETEUSER = (reader["DELETEUSER"] == null ? "" : Convert.ToString(reader["DELETEUSER"]));//删除人
string kjdE = reader["DELETETIME"].ToString();//删除时间
if (reader["DELETETIME"] != null && reader["DELETETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["DELETETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["DELETETIME"].ToString().Trim() != "")
{
data.DELETETIME = Convert.ToDateTime(reader["DELETETIME"]);//删除时间
}
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人gid
if (data.CREATETIME != null)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid
if (data.MODIFIEDTIME != null)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间
data.CodeAndName = (reader["CodeAndName"] == null ? "" : Convert.ToString(reader["CodeAndName"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 获得总账管理的当前账套GID
static public String GetCwSTARTGID(string strUSERID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strSTARTGID = T_ALL_DA.GetStrSQL("GID", "select top 1 GID from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "')");
return strSTARTGID;
}
#endregion
#region 获得总账管理的当前账套名称
static public String GetCwSTARTNAME(string strUSERID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strSTARTNAME = T_ALL_DA.GetStrSQL("STARTNAME", "select top 1 STARTNAME from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "')");
return strSTARTNAME;
}
#endregion
#region 获得总账管理的当前账套启用年月
static public String GetCwSTARTMONTH(string strUSERID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strSTARTMONTH = T_ALL_DA.GetStrSQL("STARTMONTH", "select top 1 STARTMONTH from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "') order by STARTMONTH desc");
return strSTARTMONTH;
}
#endregion
#region 获得总账管理的当前会计期间
static public String GetCwACCDATE(string strUSERID)
{
string strCwSTARTGID = GetCwSTARTGID(strUSERID);
string strSTARTMONTH = GetCwSTARTMONTH(strUSERID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strACCDATE = T_ALL_DA.GetStrSQL("ACCDATE", "select isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from cw_carry_over WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' ORDER by ACCDATE DESC),'" + strSTARTMONTH + "') as ACCDATE");
return strACCDATE;
}
static public String GetCwACCDATE(string strUSERID, string strCwSTARTGID)
{
string strSTARTMONTH = GetCwSTARTMONTH(strUSERID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strACCDATE = T_ALL_DA.GetStrSQL("ACCDATE", "select isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from cw_carry_over WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' ORDER by ACCDATE DESC),'" + strSTARTMONTH + "') as ACCDATE");
return strACCDATE;
}
#endregion
#region 获得出纳管理的当前账套GID
static public String GetCtSTARTGID(string strUSERID)
{
string strCwSTARTGID = GetCwSTARTGID(strUSERID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strSTARTGID = T_ALL_DA.GetStrSQL("GID", "select GID from ct_design_startusing WITH(NOLOCK) where ISENABLE=1 and (ISDELETE=0 or ISDELETE is null) and STARTGID='" + strCwSTARTGID + "'");
return strSTARTGID;
}
#endregion
#region 获得出纳管理的当前会计期间
static public String GetCtACCDATE(string strUSERID)
{
string sCtSTARTGID = GetCtSTARTGID(strUSERID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strACCDATE = T_ALL_DA.GetStrSQL("ACCDATE", "select isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from ct_carry_over WITH(NOLOCK) where STARTGID='" + sCtSTARTGID + "' and ISCARRY=1 ORDER by STARTGID,ACCDATE DESC),ISNULL((select top 1 STARTMONTH from ct_design_startusing WITH(NOLOCK) where STARTGID='" + sCtSTARTGID + "' and ISENABLE=1 and (ISDELETE=0 or ISDELETE is null) order by STARTMONTH desc),'')) as ACCDATE");
return strACCDATE;
}
#endregion
#region 科目币别表查询
static public List<CwAccitemsCurrencyModel> GetCwAccitemsCurrencyList(string strCondition, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
var strSql = new StringBuilder();
strSql.Append("SELECT CURRENCY from cw_accitems_currency where LINKGID in (SELECT GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "')");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" group by CURRENCY");
strSql.Append(" order by CURRENCY");
return SetMsCwAccitemsCurrencyData(strSql);
}
private static List<CwAccitemsCurrencyModel> SetMsCwAccitemsCurrencyData(StringBuilder strSql)
{
var headList = new List<CwAccitemsCurrencyModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
int k = 0;
while (reader.Read())
{
k++;
CwAccitemsCurrencyModel data = new CwAccitemsCurrencyModel();
#region Set DB data to Object
data.CURRENCY = (reader["CURRENCY"] == null ? "" : Convert.ToString(reader["CURRENCY"]).Trim());//币别
#endregion
headList.Add(data);
}
//
if (k == 0)
{
CwAccitemsCurrencyModel data = new CwAccitemsCurrencyModel();
#region Set DB data to Object
data.LINKGID = "";//科目GID
data.CURRENCY = "RMB";//币别
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 业务类型
static public List<OPLBModel> GetOPLBList(string condition)
{
String strSql = "SELECT OPLB,OPLBNAME from [v_op_bs]";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
strSql += " GROUP by OPLB,OPLBNAME ORDER BY OPLBNAME";
return SetOPLBData(strSql);
}
private static List<OPLBModel> SetOPLBData(String strSql)
{
var headList = new List<OPLBModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
OPLBModel data = new OPLBModel();
#region Set DB data to Object
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 获取 总账科目信息
static public List<CwAccitemsGlModel> GetCwAccitemsGl(string strCondition, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = GetCwACCDATE(strUserID);
var strSql = new StringBuilder();
strSql.Append("select *,ACCID+'-'+ACCNAME AS ACCIDNAME from cw_accitems_gl where [year]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'");
// strSql.Append("select *,ACCID+'-'+ACCNAME+'('+[YEAR]+')' AS ACCIDNAME from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
// strSql.Append(" ORDER BY [YEAR] DESC ");
return SetCwAccitemsGl(strSql);
}
private static List<CwAccitemsGlModel> SetCwAccitemsGl(StringBuilder strSql)
{
var headList = new List<CwAccitemsGlModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CwAccitemsGlModel data = new CwAccitemsGlModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码
data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称
data.ACCIDNAME = Convert.ToString(reader["ACCIDNAME"]);
data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志)
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目
data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注
data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年
data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月
data.PACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码
data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益)
data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用
data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim());
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 获取 总账科目信息(包含上级科目)
static public List<CwAccitemsGlModel> GetCwAccitemsGlAll(string strCondition, string strUserID, string CwSTARTGID = "", string CwACCDATE = "")
{
string strCwSTARTGID = CwSTARTGID;
if (strCwSTARTGID == "")
{
strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
}
string strCwACCDATE = CwACCDATE;
if (strCwACCDATE == "")
{
strCwACCDATE = GetCwACCDATE(strUserID, strCwSTARTGID);
}
var pacclist = GetCwAccitemsGlPAll(strCwSTARTGID, strCwACCDATE);
var strSql = new StringBuilder();
strSql.Append("select *,ACCID+ACCNAME AS ACCIDNAME from cw_accitems_gl where [year]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetCwAccitemsGlAll(strSql, pacclist);
}
static public CwAccitemsGlModel GetCwAccitems(string accid, List<CwAccitemsGlModel> accitemsGlAll)
{
var accitems = accitemsGlAll.Find(t => t.ACCID == accid);
if (accitems == null) accitems = new CwAccitemsGlModel();
return accitems;
}
private static List<CwAccitemsGlModel> SetCwAccitemsGlAll(StringBuilder strSql, List<CwAccitemsGlModel> pacclist)
{
var headList = new List<CwAccitemsGlModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CwAccitemsGlModel data = new CwAccitemsGlModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码
data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志)
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目
data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注
data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年
data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月
data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益)
data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用
data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim());
//data.ACCIDNAME = (reader["ACCIDNAME"] == null ? "" : Convert.ToString(reader["ACCIDNAME"]).Trim());//科目名称
//
string sPACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码
string sACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码
string sACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称
data.ACCLNAME = sACCNAME;
data.PACCGID = sPACCGID;//父级科目代码
data.ACCID = sACCID;//科目代码
data.ACCNAME = setCAGA(sPACCGID, sACCNAME, pacclist);//科目名称
data.ACCIDNAME = sACCID + "-" + data.ACCNAME;//科目名称
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<CwAccitemsGlModel> GetCwAccitemsGlPAll(string strCwSTARTGID, string strCwACCDATE)
{
var strSql = new StringBuilder();
strSql.Append("select *,ACCID+ACCNAME AS ACCIDNAME from cw_accitems_gl where [year]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' AND ISENABLE=1 AND DETAILED<>1");
return SetCwAccitemsGlPAll(strSql);
}
private static List<CwAccitemsGlModel> SetCwAccitemsGlPAll(StringBuilder strSql)
{
var headList = new List<CwAccitemsGlModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CwAccitemsGlModel data = new CwAccitemsGlModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码
data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志)
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目
data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注
data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年
data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月
data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益)
data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用
data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim());
//data.ACCIDNAME = (reader["ACCIDNAME"] == null ? "" : Convert.ToString(reader["ACCIDNAME"]).Trim());//科目名称
//
string sPACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码
string sACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码
string sACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称
data.PACCGID = sPACCGID;//父级科目代码
data.ACCID = sACCID;//科目代码
data.ACCNAME = sACCNAME;//科目名称
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public String setCAGA(string sPACCGID, string sACCNAME)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "select *,(ACCNAME+'_" + sACCNAME + "') AS ACCIDNAME from cw_accitems_gl where gid='" + sPACCGID + "'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
sPACCGID = ds.Tables[0].Rows[0]["PACCGID"].ToString();
sACCNAME = ds.Tables[0].Rows[0]["ACCIDNAME"].ToString();
if (sPACCGID.Length > 20)
{
sACCNAME = setCAGA(sPACCGID, sACCNAME);
}
}
}
return sACCNAME;
}
static public String setCAGA(string sPACCGID, string sACCNAME, List<CwAccitemsGlModel> pacclist)
{
pacclist.ForEach(i =>
{
if (i.GID == sPACCGID)
{
sPACCGID = i.PACCGID;
sACCNAME = i.ACCNAME + "_" + sACCNAME;
if (sPACCGID.Length > 26)
{
sACCNAME = setCAGA(sPACCGID, sACCNAME, pacclist);
}
}
});
return sACCNAME;
}
#endregion
#region 获取 接口科目信息
static public List<CwAccitemsGlModel> GetCwAccitems(string strCondition)
{
var strSql = new StringBuilder();
//strSql.Append("SELECT [GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS],ACCID+'_'+ACCNAME AS ACCIDNAME FROM ((SELECT [GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS] FROM cw_accitems where ACCID is not null and ACCID<>'') UNION (SELECT [GID],FINANCESOFTCODE as [ACCID],BANKNAME as [ACCNAME],1 as [DETAILED],'借' as [DC],0 as [ISFCY],0 as [ISDEPTACC],0 as [ISEMPLACC],0 as [ISCORPACC],0 as [ISITEMACC],'' as [REMARKS] FROM sys_bank where FINANCESOFTCODE is not null and FINANCESOFTCODE<>'')) as a where 1=1");
strSql.Append("SELECT [GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS],ACCID+'_'+ACCNAME AS ACCIDNAME FROM cw_accitems where ACCID is not null and ACCID<>''");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by ACCID");
return SetCwAccitems(strSql);
}
private static List<CwAccitemsGlModel> SetCwAccitems(StringBuilder strSql)
{
var headList = new List<CwAccitemsGlModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CwAccitemsGlModel data = new CwAccitemsGlModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());
data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称
data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志)
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目
data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注
data.ACCIDNAME = (reader["ACCIDNAME"] == null ? "" : Convert.ToString(reader["ACCIDNAME"]).Trim());
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
//
#region 获取指定表内,符合条件的列的数量,主要用于防止删除主表
static public int GetExist(string tablename, string condition)
{
var strSql = new StringBuilder();
strSql.Append("Select count(*) _count from " + tablename);
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
_count = Convert.ToInt16(reader["_count"]);
}
reader.Close();
}
return _count;
}
//fieldname相同 fieldname2不相同(通常用于判断 某单据号相同而GID号不同 以防止不同业务同单据号)
static public int GetExist(string tablename, string fieldname, string value, string fieldname2, string value2)
{
var strSql = new StringBuilder();
var tvalue = value.Trim();
var condition = new StringBuilder();
if (tvalue == "null" || tvalue == "Null" || tvalue == "NULL")
{
condition.Append(" is null ");
}
else
{
condition.Append(fieldname + "='" + tvalue + "'");
}
condition.Append(string.Format(" and {0}<>'{1}' ", fieldname2.Trim(), value2.Trim()));
strSql.Append("Select count(*) _count from " + tablename);
strSql.Append(" where " + condition.ToString());
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
_count = Convert.ToInt16(reader["_count"]);
}
reader.Close();
}
return _count;
}
//返回 某表中 某字段=某值的列 的数量
static public int GetExist(string tablename, string fieldname, string value)
{
var strSql = new StringBuilder();
var tvalue = value.Trim();
var condition = new StringBuilder();
if (tvalue == "null" || tvalue == "Null" || tvalue == "NULL")
{
condition.Append(" is null ");
}
else
{
condition.Append(fieldname + "='" + tvalue + "'");
}
strSql.Append("Select count(*) _count from " + tablename);
strSql.Append(" where " + condition.ToString());
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
_count = Convert.ToInt16(reader["_count"]);
}
reader.Close();
}
return _count;
}
//返回 某表中 某字段=某值 且 某字段=某值... 的列 的数量
static public int GetExist(string tablename, string keyname, string keyvalue, List<string> fieldnamelist, List<string> valuelist)
{
var strSql = new StringBuilder();
if (fieldnamelist.Count != valuelist.Count) return 999;
var condition = new StringBuilder();
var _listcount = 0;
foreach (var fieldname in fieldnamelist)
{
var value = valuelist[_listcount];
var tvalue = value.Trim();
if (condition.ToString() != "") condition.Append(" and ");
if (tvalue == "null" || tvalue == "Null" || tvalue == "NULL")
{
condition.Append(fieldname + " is null ");
}
else
{
condition.Append(fieldname + "='" + tvalue + "'");
}
_listcount++;
}
strSql.Append("Select count(*) _count from " + tablename);
strSql.Append(" where " + keyname + "<>'" + keyvalue + "' and " + condition.ToString());
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
_count = Convert.ToInt16(reader["_count"]);
}
reader.Close();
}
return _count;
}
static public bool HaveExist(string tablename, string fieldname, string value)
{
var _count = GetExist(tablename, fieldname, value);
bool r = false;
if (_count > 0)
{
r = true;
}
return r;
}
static public bool HaveExist(string tablename, string fieldname, string value, string fieldname2, decimal value2)
{
return HaveExist(tablename, fieldname, value, fieldname2, value2.ToString());
}
/// <summary>
/// fieldname相同 fieldname2不相同
/// </summary>
/// <param name="tablename"></param>
/// <param name="fieldname"></param>
/// <param name="value"></param>
/// <param name="fieldname2"></param>
/// <param name="value2"></param>
/// <returns></returns>
static public bool HaveExist(string tablename, string fieldname, string value, string fieldname2, string value2)
{
var _count = GetExist(tablename, fieldname, value, fieldname2, value2);
bool r = false;
if (_count > 0)
{
r = true;
}
return r;
}
static public bool HaveExist(string tablename, string condition)
{
var _count = GetExist(tablename, condition);
bool r = false;
if (_count > 0)
{
r = true;
}
return r;
}
#endregion
#region 获取 出纳摘要信息
static public List<MsCtExplanDetail> GetEXPLAN(string strCondition, string strUserID)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(strUserID);
var strSql = new StringBuilder();
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_explan_detail.MODIFIEDUSER) from ct_explan_detail where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and LINKGID in (select GID from ct_explan where STARTGID='" + strCtSTARTGID + "' and " + strCondition + ")");
}
strSql.Append(" order by EXPLAN");
return SetEXPLAN(strSql);
}
private static List<MsCtExplanDetail> SetEXPLAN(StringBuilder strSql)
{
var headList = new List<MsCtExplanDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCtExplanDetail data = new MsCtExplanDetail();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//摘要GID
data.EXPLAN = (reader["EXPLAN"] == null ? "" : Convert.ToString(reader["EXPLAN"]));//内容
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid
if (data.MODIFIEDTIME != null)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//更改人
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 通用查询方法 参数是查询语句必须把GID和值as成GID和GValue
static public List<GeneralModel> GeneralSelect(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(strCondition);
return SetGeneralSelect(strSql);
}
static public List<GeneralModel> GeneralSelect(string tablename, string keyname, string valuename, string condition)
{//keyname=GVALUE一般用于displayname
var strSql = new StringBuilder();
strSql.Append(string.Format("select {1} as GID,{2} as GVALUE from {0}", tablename, keyname, valuename));
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
return SetGeneralSelect(strSql);
}
static public List<GeneralModel> GeneralSelect2(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(strCondition);
return SetGeneralSelect3(strSql);
}
#region 将GVALUE的值集合成逗号隔开的
static public List<GeneralModel> GeneralSelect_commaList(string tablename, string valuename, string condition)
{
var strSql = new StringBuilder();
strSql.Append(string.Format("select distinct {1} as GVALUE from {0}", tablename, valuename));
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
return SetGeneralSelect2(strSql);
}
#endregion
#region 获取指定表中符合条件的字段值返回一个用逗号隔开各个字段的string
/// <summary>
/// 获取指定表中符合条件的字段值返回一个用逗号隔开各个字段的string
/// </summary>
/// <param name="tablename"></param>
/// <param name="valuename"></param>
/// <param name="condition"></param>
/// <returns></returns>
static public string GeneralSelect_commaString(string tablename, string valuename, string condition)
{
var itemlist = GeneralSelect_commaList(tablename, valuename, condition);
var result = "";
if (itemlist.Count > 0)
{
foreach (var item in itemlist)
{
if (result != "")
{
result += ",";
}
result += "'" + item.GVALUE + "'";
}
return result;
}
else return "";
}
#endregion
public static List<GeneralModel> GeneralGet(string tablename, string condition = "")
{
var _condition = condition;
if (tablename == "company" || tablename == "sys_company")
{
if (!string.IsNullOrEmpty(_condition))
{
_condition += " and ISDELETED=0 ";
}
else
{
_condition += " ISDELETED=0 ";
}
return GeneralSelect("company", "GID", "NAME", _condition);
}
else if (tablename == "client")
{
return GeneralSelect("info_client", "GID", "SHORTNAME", _condition);
}
else if (tablename == "client_airline")
{
return GeneralSelect("info_client", "CODENAME", "SHORTNAME", " ISAIRLINES=1 ");
}
return new List<GeneralModel>();
}
public static string GeneralGet_String(string tablename, string condition = "")
{
var idlist = BasicDataRefDAL.GeneralGet(tablename, condition);
var result = "";
if (idlist.Count > 0)
{
result = idlist[0].GVALUE.ToString();
}
return result;
}
private static List<GeneralModel> SetGeneralSelect(StringBuilder strSql)
{
var headList = new List<GeneralModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
GeneralModel data = new GeneralModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));
data.GVALUE = (reader["GVALUE"] == null ? "" : Convert.ToString(reader["GVALUE"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
private static List<GeneralModel> SetGeneralSelect2(StringBuilder strSql)
{
var headList = new List<GeneralModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
GeneralModel data = new GeneralModel();
#region Set DB data to Object
data.GVALUE = (reader["GVALUE"] == null ? "" : Convert.ToString(reader["GVALUE"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
private static List<GeneralModel> SetGeneralSelect3(StringBuilder strSql)
{
var headList = new List<GeneralModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
GeneralModel data = new GeneralModel();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));
data.GVALUE = (reader["GVALUE"] == null ? "" : Convert.ToString(reader["GVALUE"]));
data.GVALUE2 = (reader["GVALUE2"] == null ? "" : Convert.ToString(reader["GVALUE2"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region 获取指定表内的某列数据前50行指定查询条件和排序方式 主要用于提供“近期数据”内容的combox
public static List<GeneralModel> GeneralSelect_Top(string TABLENAME, string FIELDNAME, string condition, string topnum = "50")
{
var result = new List<GeneralModel>();
var sqlstr = "select TOP " + topnum + " " + FIELDNAME + " as GID," + FIELDNAME + " as GVALUE from " + TABLENAME + " where " + condition;
result = GeneralSelect(sqlstr);
return result;
}
#endregion
#region 获取指定表内的指定查询条件的某字段distinct值
public static List<GeneralModel> GeneralSelect_Distinct(string TABLENAME, string FIELDNAME, string condition)
{
var result = new List<GeneralModel>();
var sqlstr = "select distinct " + FIELDNAME + " as GID," + FIELDNAME + " as GVALUE from " + TABLENAME + " where " + condition;
result = GeneralSelect(sqlstr);
return result;
}
#endregion
#endregion
#region 将带逗号的内容拆成单个,并将出现频率最高的放置在最前。参数为(表名 列名 查询条件)
/// <summary>
/// 将带逗号的内容拆成单个,并将出现频率最高的放置在最前。参数为(表名 列名 查询条件)
/// </summary>
/// <param name="tablename"></param>
/// <param name="columnname"></param>
/// <param name="condition"></param>
/// <returns></returns>
static public List<DICModel> GetCommaWord(string tablename, string columnname, string condition)
{
var strSql = new StringBuilder();
var column = " case isnull(" + columnname + ",'') when '' then '' else " + columnname + "+',' end ";
strSql.Append(" WITH TB_2 AS ( ");
strSql.Append(" SELECT " + column + " as " + columnname + " ,CHARINDEX(','," + column + ") STA,CHARINDEX(','," + column + ")-1 LENS FROM " + tablename + " where 1=1 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" UNION ALL ");
strSql.Append(" SELECT " + columnname + " ,CHARINDEX(','," + columnname + ",STA+1) STA,CHARINDEX(','," + columnname + ",STA+1)-STA-1 LENS FROM TB_2 WHERE STA<>0) ");
strSql.Append(" SELECT distinct SUBSTRING(" + columnname + ",STA-LENS,LENS) VALUE,count(SUBSTRING(" + columnname + ",STA-LENS,LENS)) count FROM TB_2 ");
strSql.Append(" WHERE STA<>0 ");
strSql.Append(" group by SUBSTRING(" + columnname + ",STA-LENS,LENS) ");
strSql.Append(" order by count(SUBSTRING(" + columnname + ",STA-LENS,LENS)) DESC ");
return SetCommaWord(strSql);
}
private static List<DICModel> SetCommaWord(StringBuilder strSql)
{
var headList = new List<DICModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
DICModel data = new DICModel();
#region Set DB data to Object
data.KEYFIELD = (reader["VALUE"] == null ? "" : Convert.ToString(reader["VALUE"]));//惟一值
data.VALUEFIELD = (reader["count"] == null ? "" : Convert.ToString(reader["count"]));//惟一值
#endregion
headList.Add(data);
}
#region 空白项
DICModel data2 = new DICModel();
data2.KEYFIELD = "";//惟一值
data2.VALUEFIELD = "0";//惟一值
#endregion
headList.Add(data2);
reader.Close();
}
return headList;
}
//符合条件的表、字段中,实际已存在的用逗号隔开的部分,是否包含指定文字;
/// <summary>
/// 符合条件的表、字段中,实际已存在的用逗号隔开的部分,是否包含指定文字;
/// </summary>
/// <param name="tablename"></param>
/// <param name="columnname"></param>
/// <param name="ExistValue"></param>
/// <param name="condition"></param>
/// <returns></returns>
static public bool GetCommaWordExist(string tablename, string columnname, string ExistValue, string condition)
{
var _list = GetCommaWord(tablename, columnname, condition);
if (_list.Count() == 0)
{
return false;
}
else
{
foreach (var item in _list)
{
if (item.KEYFIELD == ExistValue.Trim())
{
return true;
}
}
return false;
}
}
#endregion
#region 将逗号隔开的字符串 转化成1 string[]2用于sql的带单引号string3一个stringList 并按字母顺序排序
public static string[] getStringArray(string str, char splitword = ',')
{
var stringlist = str.Split(splitword);
return stringlist;
}
public static string getSqlString(string str, char splitword = ',')
{
var stringlist = str.Split(splitword);
var result = "";
foreach (var item in stringlist)
{
if (result != "") result += ",";
result += "'" + item + "'";
}
return result;
}
public static List<string> getStrListfromCommaStr(string str, char splitword = ',')
{
var stringlist = str.Split(splitword).ToList<string>();
stringlist.OrderBy(o => o.ToString());
return stringlist;
}
#endregion
#region 判断字符串中是否包含中文
/// <summary>
/// 判断字符串中是否包含中文
/// </summary>
/// <param name="str">需要判断的字符串</param>
/// <returns>判断结果</returns>
public static bool isHasChinese(string str)
{
return System.Text.RegularExpressions.Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
}
#endregion
#region 直接DelCtnDetailList执行sql命令小心使用
static public int ExecSql(string StrSql)
{
Database db = DatabaseFactory.CreateDatabase();
var _count = -1;
try
{
_count = db.ExecuteNonQuery(CommandType.Text, StrSql);
}
catch
{
return _count;
}
return _count;
}
static public int ExecSql_DB(string StrSql, string DBNAME = "")
{
Database db = DatabaseFactory.CreateDatabase(DBNAME);
var _count = db.ExecuteNonQuery(CommandType.Text, StrSql);
return _count;
}
static public int ExecSql(SqlCommand StrSqlComm)
{
Database db = DatabaseFactory.CreateDatabase();
var _count = db.ExecuteNonQuery(StrSqlComm);
return _count;
}
#endregion
#region 返回实体类的属性名与列表
public static List<FieldModel> getProperties<T>(T t)
{
var tStr = new List<FieldModel>();
if (t == null)
{
return tStr;
}
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
if (properties.Length <= 0)
{
return tStr;
}
foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name;
object value = item.GetValue(t, null);
if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
{
var _sl = new FieldModel();
_sl.FieldName = name;
if (value != null)
{
_sl.FieldValue = value.ToString();
}
tStr.Add(_sl);
//tStr += string.Format("{0}:{1},", name, value);
}
else
{
//getProperties(value);
}
}
return tStr;
}
#endregion
#region 获取 InfoClass管理分类表
static public List<MsInfoClassEntity> GetMsInfoClass(string strCondition, string strUserID)
{
var strSql = new StringBuilder();
strSql.Append("select * from InfoClass where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by sortID");
return SetMsInfoClass(strSql);
}
private static List<MsInfoClassEntity> SetMsInfoClass(StringBuilder strSql)
{
var headList = new List<MsInfoClassEntity>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsInfoClassEntity data = new MsInfoClassEntity();
#region Set DB data to Object
data.ID = (reader["ID"] == null ? 0 : Convert.ToInt32(reader["ID"]));
data.PARENTID = (reader["PARENTID"] == null ? "" : Convert.ToString(reader["PARENTID"]));
data.CLASSID = (reader["CLASSID"] == null ? "" : Convert.ToString(reader["CLASSID"]));
data.CLASSNAMEENG = (reader["CLASSNAMEENG"] == null ? "" : Convert.ToString(reader["CLASSNAMEENG"]));
data.CLASSNAME = (reader["CLASSNAME"] == null ? "" : Convert.ToString(reader["CLASSNAME"]));
data.CLASSICON = (reader["CLASSICON"] == null ? "" : Convert.ToString(reader["CLASSICON"]));
data.CLASSKEY = (reader["CLASSKEY"] == null ? "" : Convert.ToString(reader["CLASSKEY"]));
data.CLASSLOCATION = (reader["CLASSLOCATION"] == null ? 0 : Convert.ToInt32(reader["CLASSLOCATION"]));
data.CLASSATTRIB = (reader["CLASSATTRIB"] == null ? 0 : Convert.ToInt32(reader["CLASSATTRIB"]));
data.HASCHILD = (reader["HASCHILD"] == null ? false : Convert.ToBoolean(reader["HASCHILD"]));
data.ISUSED = (reader["ISUSED"] == null ? false : Convert.ToBoolean(reader["ISUSED"]));
data.ISSORT = (reader["ISSORT"] == null ? false : Convert.ToBoolean(reader["ISSORT"]));
data.SORTATTRIB = (reader["SORTATTRIB"] == null ? false : Convert.ToBoolean(reader["SORTATTRIB"]));
data.SORTID = (reader["SORTID"] == null ? 0 : Convert.ToInt32(reader["SORTID"]));
data.AUTHOR = (reader["AUTHOR"] == null ? "" : Convert.ToString(reader["AUTHOR"]));
data.CREATEDATE = Convert.ToDateTime(reader["CREATEDATE"]);
data.LASTMODIFYDATE = Convert.ToDateTime(reader["LASTMODIFYDATE"]);
data.DEL_SIGN = (reader["DEL_SIGN"] == null ? false : Convert.ToBoolean(reader["DEL_SIGN"]));
#endregion
headList.Add(data);
}
#region 空白项
MsInfoClassEntity data2 = new MsInfoClassEntity();
data2.ID = 0;
data2.PARENTID = "";
data2.CLASSID = "";
data2.CLASSNAMEENG = "";
data2.CLASSNAME = "";
data2.CLASSICON = "";
data2.CLASSKEY = "";
data2.CLASSLOCATION = 0;
data2.CLASSATTRIB = 0;
data2.HASCHILD = false;
data2.ISUSED = false;
data2.ISSORT = false;
data2.SORTATTRIB = false;
data2.SORTID = 0;
data2.AUTHOR = "";
data2.CREATEDATE = DateTime.Now;
data2.LASTMODIFYDATE = DateTime.Now;
data2.DEL_SIGN = false;
#endregion
headList.Add(data2);
reader.Close();
}
return headList;
}
#endregion
#region 获取 客户子项目
static public List<MsInfoClientItemEntity> GetMsInfoClientItem(string strCondition, string strUserID)
{
var strSql = new StringBuilder();
strSql.Append("select * from info_client_item where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetMsInfoClientItem(strSql);
}
private static List<MsInfoClientItemEntity> SetMsInfoClientItem(StringBuilder strSql)
{
var headList = new List<MsInfoClientItemEntity>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsInfoClientItemEntity data = new MsInfoClientItemEntity();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//惟一值
data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//客户GID
data.ITEMNAME = (reader["ITEMNAME"] == null ? "" : Convert.ToString(reader["ITEMNAME"]));//项目名称
data.STARTTIME = Convert.ToDateTime(reader["STARTTIME"]);//起始时间
data.ENDTIME = Convert.ToDateTime(reader["ENDTIME"]);//结束时间
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人gid
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更改时间
#endregion
headList.Add(data);
}
#region 空白项
MsInfoClientItemEntity data2 = new MsInfoClientItemEntity();
data2.GID = "";//惟一值
data2.LINKGID = "";//客户GID
data2.ITEMNAME = "";//项目名称
data2.STARTTIME = DateTime.Now;//起始时间
data2.ENDTIME = DateTime.Now;//结束时间
data2.CREATEUSER = "";//创建人gid
data2.CREATETIME = DateTime.Now;//创建时间
data2.MODIFIEDUSER = "";//更改操作人gid
data2.MODIFIEDTIME = DateTime.Now;//最后一次更改时间
#endregion
headList.Add(data2);
reader.Close();
}
return headList;
}
#endregion
#region 良通捷运 目的地列表
static public List<DICModel> GetDetiNation_LTJY(string strCondition, string strUserID)
{
var strSql = new StringBuilder();
strSql.Append("select DISTINCT NAME,DISTANCE from PC_LTJY_Distance where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetDetiNation_LTJY(strSql);
}
private static List<DICModel> SetDetiNation_LTJY(StringBuilder strSql)
{
var headList = new List<DICModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
DICModel data = new DICModel();
#region Set DB data to Object
data.KEYFIELD = (reader["NAME"] == null ? "" : Convert.ToString(reader["NAME"]));//惟一值
data.VALUEFIELD = (reader["DISTANCE"] == null ? "" : Convert.ToString(reader["DISTANCE"]));//惟一值
#endregion
headList.Add(data);
}
#region 空白项
DICModel data2 = new DICModel();
data2.KEYFIELD = "";//惟一值
data2.VALUEFIELD = "0";//惟一值
#endregion
headList.Add(data2);
reader.Close();
}
return headList;
}
#endregion
#region 国家
static public List<CangDanCountry> GetCountryList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("select distinct c_country_code+'-'+c_country_name as CodeAndName,c_country_code CountryCode,c_country_name CountryName,c_country_ename CountryNameEn from t_sys_country_code where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetCountryData(strSql.ToString());
}
private static List<CangDanCountry> SetCountryData(string sql)
{
var headList = new List<CangDanCountry>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
CangDanCountry data = new CangDanCountry();
#region Set DB data to Object
data.CountryName = Convert.ToString(reader["CountryName"]);
data.CountryNameEn = Convert.ToString(reader["CountryNameEn"]);
data.CountryCode = Convert.ToString(reader["CountryCode"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
headList.Add(data);
}
}
return headList;
}
#endregion
#region 逻辑信息子表操作
#region 将一个dictionary转化为用;;和::隔开的文本
public static string DicToStr(Dictionary<string,string> dic) {
var result = "";
foreach (var item in dic) {
result += item.Key + "::" + item.Value + ";;";
}
return result;
}
#endregion
#region 将一个用;;和::隔开的文本转化为dictionary
public static Dictionary<string, string> StrToDic(string dicstr) {
var result = new Dictionary<string, string>();
var list = Regex.Split(dicstr, ";;").ToList();
foreach (var item in list) {
var itemarray= Regex.Split(item, "::");
if (itemarray.Length < 2) continue;
result.Add(itemarray[0], itemarray[1]==null?"": itemarray[1]);
}
return result;
}
#endregion
public static Dictionary<string, string> GetLogicInfo(string BSNO, string PROPNAME) {
CommonDataContext cdc = new CommonDataContext();
var result = new Dictionary<string, string>();
var infoList = cdc.OP_LOGICINFO.Where(x => x.BSNO == BSNO && x.PROPNAME == PROPNAME).ToList();
if (infoList != null && infoList.Count > 0)
{
result= StrToDic(infoList[0].PROPVALUE);
}
return result;
}
public static void SaveLogicInfo(string BSNO, string PROPNAME,Dictionary<string,string> InfoDic)
{
CommonDataContext cdc = new CommonDataContext();
var result = new Dictionary<string, string>();
var infoList = cdc.OP_LOGICINFO.Where(x => x.BSNO == BSNO && x.PROPNAME == PROPNAME).ToList();
if (infoList != null && infoList.Count > 0)
{
infoList[0].PROPVALUE = DicToStr(InfoDic);
}
else {
var newinfo = new OP_LOGICINFO_md();
newinfo.GID = Guid.NewGuid();
newinfo.BSNO = BSNO;
newinfo.PROPNAME = PROPNAME;
newinfo.PROPVALUE = DicToStr(InfoDic);
cdc.OP_LOGICINFO.Add(newinfo);
cdc.SaveChanges();
}
}
#endregion
#region SaveLog
public static ContentResult SaveLog(List<FieldModel> data, string USERID, string NAME, string LOGTYPE)
{
var headData = new Sys_Logmd();//JsonConvert.Deserialize<WorkLogmb>(data);
headData.GID = System.Guid.NewGuid().ToString();
headData.NAME = NAME;
headData.LOGTYPE = LOGTYPE;
headData.LOGTIME = System.DateTime.Now.ToString();
headData.CREATEUSER = USERID;
headData.LOGCONTENT = "";
foreach (var _F in data)
{
headData.LOGCONTENT += string.Format("{0}:{1},", _F.FieldName, _F.FieldValue);
}
headData.DbOperationType = DbOperationType.DbotIns;
headData.ModelUIStatus = "I";
var result = new DBResult();
var modb = new ModelObjectRepository();
result = modb.Save(headData);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public static ContentResult SaveLog<T>(T t, string USERID, string NAME, string LOGTYPE)
{
var _FieldList = getProperties(t);
return SaveLog(_FieldList, USERID, NAME, LOGTYPE);
}
public static ContentResult SaveLog<T>(List<T> t, string USERID, string NAME, string LOGTYPE)
{
var _r = new ContentResult();
foreach (var item in t) {
var _FieldList = getProperties(item);
_r = SaveLog(_FieldList, USERID, NAME, LOGTYPE);
}
return _r;
}
public static ContentResult SaveLog(string data, string USERID, string NAME, string LOGTYPE)
{
var headData = new Sys_Logmd();//JsonConvert.Deserialize<WorkLogmb>(data);
headData.GID = System.Guid.NewGuid().ToString();
headData.NAME = NAME;
headData.LOGTYPE = LOGTYPE;
headData.LOGTIME = System.DateTime.Now.ToString();
headData.CREATEUSER = USERID;
//headData.LOGCONTENT = "";
headData.LOGCONTENT = data;
headData.DbOperationType = DbOperationType.DbotIns;
headData.ModelUIStatus = "I";
var result = new DBResult();
var modb = new ModelObjectRepository();
result = modb.Save(headData);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 读取指定文件 然后将其写入指定表的指定字段image字段
public static DBResult SaveFileIntoDB(FileUrlModel FileInfo, string filename)
{
DBResult _r = new DBResult();
_r.Success = false;
var _filename = HttpContext.Current.Server.MapPath(filename);
if (File.Exists(_filename))
{
//var file = File.Open(filename, FileMode.Open);
byte[] bytes = File.ReadAllBytes(_filename);
SqlCommand cmd = new SqlCommand(string.Format("update {0} set {1} =@image where {2}='{3}'", FileInfo.TableName, FileInfo.ImgName, FileInfo.KeyName, FileInfo.KeyValue));
cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;
var _c = ExecSql(cmd);
if (_c > 0)
{
_r.Success = true;
}
else
{
}
return _r;
}
else
{
_r.Message = "不存在指定文件";
return _r;
}
}
public static DBResult DelFileFromDB(FileUrlModel FileInfo)
{
DBResult _r = new DBResult();
_r.Success = false;
byte[] bytes = new byte[0];
SqlCommand cmd = new SqlCommand(string.Format("update {0} set {1} =@image where {2}='{3}'", FileInfo.TableName, FileInfo.ImgName, FileInfo.KeyName, FileInfo.KeyValue));
cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;
var _c = ExecSql(cmd);
if (_c > 0)
{
_r.Success = true;
}
else
{
}
return _r;
}
#endregion
#region 传入IDataReader 和字段名 和返回值类型
public static object getValue(IDataReader reader, string fieldname, string type)
{
reader.GetSchemaTable().DefaultView.RowFilter = "ColumnName= '" + fieldname + "'";
if (reader.GetSchemaTable().DefaultView.Count > 0)
{
var _r = reader[fieldname];
if (_r != DBNull.Value) return _r;
}
return null;
}
#endregion
#region 通过USERID/或者user.showname 获取邮箱和QQ
public static string GetPhoneWithUserId(string USERID, out string email, out string qq)
{
string sql = "select officephone,EMAIL1,QQ from user_baseinfo where (userid = '" + USERID + "' or userid in(select userid from vw_user where showname= '" + USERID + "') ) ";
Database db = DatabaseFactory.CreateDatabase();
string phone = "";
email = "";
qq = "";
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
phone = reader["officephone"].ToString();
email = reader["EMAIL1"].ToString();
qq = reader["QQ"].ToString();
}
reader.Close();
}
return phone;
}
#endregion
#region 查看reader中是否存在字段 bool
public static bool ReadFieldExist(IDataReader reader, string Fieldname)
{
reader.GetSchemaTable().DefaultView.RowFilter = "ColumnName= '" + Fieldname + "'";
if (reader.GetSchemaTable().DefaultView.Count > 0)
return true;
else return false;
//try
//{
// var index = reader.GetOrdinal(Fieldname);
// if (index > -1)
// return true;
// else return false;
//}
//catch {
// return false;
//}
}
public object getRowValue(DataColumnCollection Columns, DataRow row, string fieldname)
{
if (Columns.Contains(fieldname)) return row[fieldname];
else return "";
}
#endregion
/// <summary>
/// 将Excel单表转为Datatable
/// </summary>
/// <param name="stream"></param>
/// <param name="fileType"></param>
/// <param name="strMsg"></param>
/// <param name="sheetName"></param>
/// <returns></returns>
public static DataTable ExcelToDatatable(Stream stream, string fileType, out string strMsg, string sheetName = null)
{
strMsg = "";
DataTable dt = new DataTable();
ISheet sheet = null;
IWorkbook workbook = null;
try
{
#region 判断excel版本
//2007以上版本excel
if (fileType == ".xlsx")
{
workbook = new XSSFWorkbook(stream);
//workbook = WorkbookFactory.Create(stream);
}
//2007以下版本excel
else if (fileType == ".xls")
{
workbook = new HSSFWorkbook(stream);
}
else
{
throw new Exception("传入的不是Excel文件");
}
#endregion
if (!string.IsNullOrEmpty(sheetName))
{
sheet = workbook.GetSheet(sheetName);
if (sheet == null)
{
sheet = workbook.GetSheetAt(0);
}
}
else
{
sheet = workbook.GetSheetAt(0);
}
if (sheet != null)
{
IRow firstRow = sheet.GetRow(0);
int cellCount = firstRow.LastCellNum;
for (int i = firstRow.FirstCellNum; i < cellCount; i++)
{
ICell cell = firstRow.GetCell(i);
if (cell != null)
{
string cellValue = cell.StringCellValue.Trim();
if (!string.IsNullOrEmpty(cellValue))
{
DataColumn dataColumn = new DataColumn(cellValue);
dt.Columns.Add(dataColumn);
}
}
}
DataRow dataRow = null;
//遍历行
for (int j = sheet.FirstRowNum + 1; j <= sheet.LastRowNum; j++)
{
IRow row = sheet.GetRow(j);
dataRow = dt.NewRow();
if (row == null || row.FirstCellNum < 0)
{
continue;
}
//遍历列
for (int i = row.FirstCellNum; i < cellCount; i++)
{
ICell cellData = row.GetCell(i);
if (cellData != null && cellData.ToString() != "")
{
//判断是否为数字型,必须加这个判断不然下面的日期判断会异常
if (cellData.CellType == CellType.Numeric)
{
//判断是否日期类型
if (DateUtil.IsCellDateFormatted(cellData))
{
dataRow[i] = cellData.DateCellValue;
}
else
{
dataRow[i] = cellData.ToString().Trim();
}
}
else
{
dataRow[i] = cellData.ToString().Trim();
}
}
else
{
dataRow[i] = Guid.NewGuid().ToString();
}
}
dt.Rows.Add(dataRow);
}
}
else
{
throw new Exception("没有获取到Excel中的数据表");
}
}
catch (Exception ex)
{
workbook = new HSSFWorkbook(stream);
strMsg = ex.Message;
}
return dt;
}
/// <summary>
/// 接口类:分页查询语句的查询条件
/// strSql,strCondition,rangestr,sortstring,defaultsortstr,start,limit
/// </summary>
public class PagedQuaryParam
{
public string strSql { get; set; }
public string strCondition { get; set; }
public string rangestr { get; set; }
public string sortstring { get; set; }
public string defaultsortstr { get; set; }
public int start { get; set; }
public int limit { get; set; }
}
/// <summary>
/// 分页查询语句
/// </summary>
/// <param name="PagedQuaryParam"></param>
/// strSql查询语句必须以where 1=1 结尾 。
/// <returns></returns>
public static StringBuilder PagedQuaryStr(PagedQuaryParam PagedQuaryParam)
{
var result = new StringBuilder();
result.Append(@"SELECT * from (SELECT row_number() over (");
if (!string.IsNullOrEmpty(PagedQuaryParam.sortstring))
{
result.Append(" order by " + PagedQuaryParam.sortstring);
}
else
{
result.Append(" order by " + PagedQuaryParam.defaultsortstr);
}
result.Append(@") as num , * from (");
result.Append(PagedQuaryParam.strSql);
if (!string.IsNullOrEmpty(PagedQuaryParam.strCondition))
{
result.Append(" and " + PagedQuaryParam.strCondition);
}
if (!string.IsNullOrEmpty(PagedQuaryParam.rangestr))
{
result.Append(" and " + PagedQuaryParam.rangestr);
}
result.Append(@")as t )as t2 ");
result.Append(string.Format(" where t2.num>{0} and t2.num<={1} ", PagedQuaryParam.start, PagedQuaryParam.start + PagedQuaryParam.limit)); //
return result;
}
public static int PagedCount(PagedQuaryParam PagedQuaryParam)
{
var result = 0;
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append(@"SELECT count(*) _count from ( ");
sqlstr.Append(PagedQuaryParam.strSql);
if (!string.IsNullOrEmpty(PagedQuaryParam.strCondition))
{
sqlstr.Append(" and " + PagedQuaryParam.strCondition);
}
if (!string.IsNullOrEmpty(PagedQuaryParam.rangestr))
{
sqlstr.Append(" and " + PagedQuaryParam.rangestr);
}
sqlstr.Append(@") as t ");
Database db = DatabaseFactory.CreateDatabase();
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sqlstr.ToString()))
{
while (reader.Read())
{
result = (reader["_count"] == null ? 0 : Convert.ToInt32(reader["_count"]));
}
//#region 空白项
//DICModel data2 = new DICModel();
//data2.KEYFIELD = "";//惟一值
//data2.VALUEFIELD = "0";//惟一值
//#endregion
//headList.Add(data2);
reader.Close();
}
}
catch { }
return result;
}
#region 获取数据表数据的刷新时间 以供前台决定是否更新表 以及刷新mainform上面的store
//此处只有第一次被读取时才读取数据库 之后都是直接返回内存数值
//setnew方法更新某个表名的刷新时间时会同时更新内存内的刷新时间
//但是如果新增一种表名的话,需要重新启动网站服务,否则内存表内容无法添加。
public static List<StoreModifyResultStatus> GetTableStatusList()
{
try
{
if (StoreModifyStatusMb.StoreModifyStatusList == null || StoreModifyStatusMb.StoreModifyStatusList.Count == 0)
{
ResetStoreModifyStatus();
}
else
{
//var _result = SetStoreModifyStatus(StoreModifyStatusMb.getSql());
//StoreModifyStatusMb.setList(_result);
//return getSql
}
return StoreModifyStatusMb.getstatus();
}
catch (Exception e)
{
SaveLog(e.Message, "", "提前缓存表", "GetTableStatusList");
ResetStoreModifyStatus();
return StoreModifyStatusMb.getstatus();
}
}
public static object GetStoreModifyStatusCache()
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache["StoreModifyStatus"];
}
public static void SetStoreModifyStatusCache(List<StoreModifyStatusMb> StoreModifyStatusMb)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
//objCache.Remove("StoreModifyStatus");
objCache.Insert("StoreModifyStatus", StoreModifyStatusMb);
}
/// <summary>
/// 更新公共store的刷新时间
/// </summary>
/// <param name="STORENAME"></param>
/// <returns></returns>
public static DBResult PubStore_SetNew(string TABLENAME)
{
return StoreStatus_SetTime(TABLENAME);
}
public static DBResult StoreStatus_SetTime(string TABLENAME)
{
try
{
DBResult result = new DBResult();
if (StoreModifyStatusMb.StoreModifyStatusList.Exists(t => t.TABLENAME == TABLENAME))
{
var modb = new ModelObjectDB();
var _tlist = StoreModifyStatusMb.StoreModifyStatusList.FindAll(t => t.TABLENAME == TABLENAME);
foreach (var _t in _tlist)
{
_t.MODIFIEDTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
_t.DbOperationType = DbOperationType.DbotUpd;
_t.ModelUIStatus = "E";
_t.PubStoreList.Clear();
result = modb.Save(_t);
}
return result;
}
else
{
var er = new DBResult(false, "没有该表名的配置信息", null);
return er;
}
}
catch (Exception e)
{
SaveLog(e.Message, "", "提前缓存表", "StoreStatus_SetTime");
BasicDataRefDAL.ResetStoreModifyStatus();
return StoreStatus_SetTime(TABLENAME);
}
}
private static List<StoreModifyStatusMb> SetStoreModifyStatus(string strSql)
{
var headList = new List<StoreModifyStatusMb>();
Database db = DatabaseFactory.CreateDatabase();
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
StoreModifyStatusMb data = new StoreModifyStatusMb();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));
data.TABLENAME = (reader["TABLENAME"] == null ? "" : Convert.ToString(reader["TABLENAME"]));
data.STORENAME = (reader["STORENAME"] == null ? "" : Convert.ToString(reader["STORENAME"]));
data.DISPLAYFIELD = (reader["DISPLAYFIELD"] == null ? "" : Convert.ToString(reader["DISPLAYFIELD"]));
data.VALUEFIELD = (reader["VALUEFIELD"] == null ? "" : Convert.ToString(reader["VALUEFIELD"]));
data.DISPLAYFIELD2 = (reader["DISPLAYFIELD2"] == null ? "" : Convert.ToString(reader["DISPLAYFIELD2"]));
data.CONDITION = (reader["CONDITION"] == null ? "" : Convert.ToString(reader["CONDITION"]));
data.MODIFIEDTIME = (reader["MODIFIEDTIME"] == null ? "" : Convert.ToString(reader["MODIFIEDTIME"]));
#endregion
headList.Add(data);
}
//#region 空白项
//DICModel data2 = new DICModel();
//data2.KEYFIELD = "";//惟一值
//data2.VALUEFIELD = "0";//惟一值
//#endregion
//headList.Add(data2);
reader.Close();
}
}
catch (Exception e)
{
SaveLog(e.Message, "", "提前缓存表", "SetStoreModifyStatus");
}
return headList;
}
public static void ResetStoreModifyStatus()
{
var _list = SetStoreModifyStatus(StoreModifyStatusMb.getSql());
SetStoreModifyStatusCache(_list);
//StoreModifyStatusMb.setList(_list);
}
static public List<PubStoremb> getPubExtendStore(string strSql)
{
var headList = new List<PubStoremb>();
Database db = DatabaseFactory.CreateDatabase();
string sql = strSql.ToString();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
////根据字段名设定同名属性值
PubStoremb data = new PubStoremb();
data.SetExtendValue(reader);
headList.Add(data);
}
reader.Close();
}
if (headList.Count > 0)
{
var Model = headList[0];
PubStoremb data0 = new PubStoremb();
data0.SetExtendValue_Null(Model.ExtendDic);
headList.Insert(0, data0);
}
return headList;
}
#endregion
#region 判断用户是否已登陆超时
/// <summary>
/// 判断用户是否已登陆超时
/// </summary>
/// <param name="Session"></param>
/// <returns></returns>
public static DBResult CheckLogin(HttpSessionStateBase Session)
{
var result = new DBResult();
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
var _r = new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
result.SetErrorInfo("", false, _r);
}
else
{
result.setMessage(true, "");
}
return result;
}
#endregion
#region 多种业务使用的业务信息查询
static public List<VOPBSmb> getVOPBSStore(int start, int limit, string OPLB, string condition, string sort = "")
{
var headList = new List<VOPBSmb>();
Database db = DatabaseFactory.CreateDatabase();
PagedQuaryParam pp = new PagedQuaryParam();
pp.strSql = $" select * from v_op_bs where OPLB='{OPLB}' ";
pp.start = start;
pp.limit = limit;
pp.strCondition = condition;
pp.defaultsortstr = "CUSTNO";
pp.sortstring = sort;
var strSql = PagedQuaryStr(pp);
string sql = strSql.ToString();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
////根据字段名设定同名属性值
VOPBSmb data = new VOPBSmb();
data.SetExtendValue(reader);
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 返回程序目录下一个文件夹 如不存在则创建
public static string getPath(string FILEPATH)
{
var path = AppDomain.CurrentDomain.BaseDirectory + FILEPATH + @"\";
if (Directory.Exists(path) == false)
{
Directory.CreateDirectory(path);
}
else
{
}
return path;
}
public static void ClearPath(string FILEPATH)
{
foreach (string f in Directory.GetFileSystemEntries(FILEPATH))
{
if (File.Exists(f))
{
//如果有子文件删除文件
File.Delete(f);
}
}
}
#endregion
#region 下载指定URL的文件到指定路径文件名为指定
public static string HttpDownloadFile(string remoteUrl, string FILEPATH, string FILENAME)
{
// 设置参数
HttpWebRequest request = WebRequest.Create(remoteUrl) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
var path = getPath(FILEPATH);
string localPath = path + FILENAME;
if (File.Exists(localPath))
{
return localPath;
}
//创建本地文件写入流
Stream stream = new FileStream(localPath, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
return localPath;
}
#endregion
#region 通用excel上传解析 参数为control的 Request 返回值为一个数据表1转换成的datatable
/// <summary>
/// 通用excel上传解析 返回文件名
/// </summary>
/// <param name="filepath">目标文件夹名【需形如 /xxxx 】 默认【../../UploadFiles】</param>
/// <returns></returns>
public static DBResult RequestExceltoDatatable(HttpRequestBase Request, out DataTable dt)
{
var result = new DBResult(false, "");
dt = new DataTable();
if (Request.Files.Count == 0)
{
result.Success = false;
result.Message = "参数错误";
return result;
}
try
{
var excelfile = Request.Files[0];
string strMsg;
string ext = Path.GetExtension(excelfile.FileName).ToLower();
if (ext != ".xls" && ext != ".xlsx")
{
result.Success = false;
result.Message = "文件必须为EXCEL格式";
return result;
}
dt = ExcelToDatatable(excelfile.InputStream, ext, out strMsg);
if (!string.IsNullOrEmpty(strMsg))
{
result.Success = false;
result.Message = strMsg;
return result;
}
else
{
result.Success = true;
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
#endregion
#region
public static Boolean CheckAuthority(string USERID, string MODNAME)
{
try
{
string sSQL = $" USERID = '{USERID}' AND ACTIONID in(select gid from [action] where NAME='{MODNAME}')";
int recordCount = new user_actionBLL().GetRecordCount(sSQL);
if (recordCount > 0) return true;
if (recordCount == 0) return false;
}
catch
{
return false;
}
return false;
}
#endregion
}
}