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.

1724 lines
72 KiB
C#

12 months ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.CustomRef;
using DSWeb.MvcShipping.Models.ModuTreeRef;
using DSWeb.MvcShipping.Models.UserBaseInfo;
using DSWeb.MvcShipping.Models.CompanyGPS;
using DSWeb.MvcShipping.Models.PortRef;
using DSWeb.MvcShipping.Models.GOODS;
using DSWeb.MvcShipping.Models.Code_StlMode;
using DSWeb.MvcShipping.Models.Sys_Bank;
using DSWeb.MvcShipping.Models.CompanyDef;
using DSWeb.MvcShipping.Models.EdiLog;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.MvcShipping.Models.CodeRptFeeGroups;
using DSWeb.MvcShipping.Models.UserQuerySetting;
using DSWeb.MvcShipping.Models.Sys_Message;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.DAL.MsBaseInfoDAL
{
public class MsBaseInfoDAL
{
#region Inquery DataList
static public List<CustomerRefModel> GetCustomerRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" GID,CODENAME AS CustCode, SHORTNAME AS CustName, CODENAME + '-' + SHORTNAME AS CodeAndName,REGISTRATIONNO,DESCRIPTION,REGISTRATIONNO + '-' + SHORTNAME AS RegAndDesc");
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 SetCustomerRefData(strSql);
}
static public CustomerRefModel GetData(string condition)
{
var list = GetCustomerRefList(condition);
if (list.Count > 0)
return list[0];
return new CustomerRefModel();
}
private static List<CustomerRefModel> SetCustomerRefData(StringBuilder strSql)
{
var headList = new List<CustomerRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CustomerRefModel data = new CustomerRefModel();
#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.REGISTRATIONNO = Convert.ToString(reader["REGISTRATIONNO"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.RegAndDesc = Convert.ToString(reader["RegAndDesc"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<CustomerRefModel> GetTRANSTYPERefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT newid() as GID, '' AS CustCode, '' AS CustName, BSTYPE AS CodeAndName,'' as REGISTRATIONNO,BSTYPE as DESCRIPTION,'' AS RegAndDesc");
strSql.Append(" from V_OP_BILL ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by CODENAME");
return SetCustomerRefData(strSql);
}
#endregion
#region Inquery Module
static public List<ModuTreeRefModel> GetModuTreeRefList(string strCondition, string strLANGUAGES)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
if (strLANGUAGES == "en-us")
{
strSql.Append(" GID,NAME,ENAME DESCRIPTION,MODULEURL,SORT,PARENTID,TYPE");
strSql.Append(",(select ENAME from sys_module where GID=m.PARENTID) AS PARENTNAME");
}
else
{
strSql.Append(" GID,NAME,DESCRIPTION,MODULEURL,SORT,PARENTID,TYPE");
strSql.Append(",(select DESCRIPTION from sys_module where GID=m.PARENTID) AS PARENTNAME");
}
strSql.Append(" from sys_module m ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by SORT");
return SetModuTreeRefData(strSql);
}
public static bool GetFeeRangDAStr(string optype, string userid)
{
bool istrue = true;
string modustr = "";
if (optype == "op_Seae")
{
modustr = " ([NAME]='modRecvFeeManagement' or [NAME]='modPayFeeManagement')";
}
else if (optype == "op_Apply")
{
modustr = " ([NAME]='modApplyRecvFeeManagement' or [NAME]='modApplyPayFeeManagement')";
}
else if (optype == "op_Seai")
{
modustr = " ([NAME]='modSeaiRecvFeeManagement' or [NAME]='modSeaiPayFeeManagement')";
}
else if (optype == "op_Aire")
{
modustr = "([NAME]='modAireRecvFeeManagement' or [NAME]='modAirePayFeeManagement')";
}
else if (optype == "op_Airi")
{
modustr = "([NAME]='modAiriRecvFeeManagement' or [NAME]='modAiriPayFeeManagement')";
}
else if (optype == "op_other" || optype == "tMsWlPcHead" || optype == "OpCtnBsCard" || optype == "op_Airn")
{
modustr = "([NAME]='modOtherRecvFeeManagement' or [NAME]='modOtherPayFeeManagement')";
}
else if (optype == "op_Bulk")
{
modustr = "([NAME]='modBulkRecvFeeManagement' or [NAME]='modBulkPayFeeManagement')";
}
else if (optype == "op_railway")
{
modustr = "([NAME]='modRailwayRecvFeeManagement' or [NAME]='modRailwayPayFeeManagement')";
}
else if (optype == "import_main")
{
modustr = "([NAME]='modImport_Fee' or [NAME]='modImport_Fee')";
}
else if (optype == "op_InternalTrade")
{
modustr = "([NAME]='modOp_InternalTradeRecvFeeManagement' or [NAME]='modOp_InternalTradePayFeeManagement')";
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where USERID='" + userid + "' and ISDELETE=0 and "+modustr);
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
if (Convert.ToString(reader["VISIBLERANGE"])!="4")
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
if (Convert.ToString(reader["OPERATERANGE"]) != "4")
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4"&&operaterange=="4")
{
istrue = false;
}
return istrue;
}
static public List<ModuTreeRefModel> GetUserModuTreeList(string strCondition, string userid, string strLANGUAGES)
{
var strSql = new StringBuilder();
if (strLANGUAGES == "en-us")
{
strSql.Append("SELECT GID,NAME,ENAME DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE,'' PARENTNAME FROM ");
strSql.Append(" sys_module WHERE PARENTID = '0' AND STATE <> 1 AND TYPE = 0 AND GID IN ");
strSql.Append(" (SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID ='" + userid + "' )");
}
else
{
strSql.Append("SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE,'' PARENTNAME FROM ");
strSql.Append(" sys_module WHERE PARENTID = '0' AND STATE <> 1 AND TYPE = 0 AND GID IN ");
strSql.Append(" (SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID ='" + userid + "' )");
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ORDER BY SORT ASC");
return SetModuTreeRefData(strSql);
}
static public List<ModuTreeRefModel> GetUserModuleEnableList(string strCondition, string userid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,NAME,ENAME DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE,'' PARENTNAME FROM ");
strSql.Append(" sys_module WHERE GID IN ");
strSql.Append(" (SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID ='" + userid + "' )");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ORDER BY SORT ASC");
return SetModuTreeRefData(strSql);
}
static public bool GetUserModuleEnable(string modulename, string userid)
{
var result = false;
var strSql = new StringBuilder();
strSql.Append("SELECT count(GID) as count FROM ");
strSql.Append(" sys_module WHERE [NAME]='" + modulename + "' AND GID IN ");
strSql.Append(" (SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID ='" + userid + "' )");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = Convert.ToInt32(reader["count"]);
if (evData > 0) { result = true; };
}
reader.Close();
}
return result;
}
static public bool GetFeeCustNoEnable(string bsno,string custno)
{
var result = false;
var strSql = new StringBuilder();
strSql.Append("SELECT count(GID) as count FROM ");
strSql.Append(" ch_fee ");
strSql.Append(" WHERE (BSNO='" + bsno + "' AND (SETTLEMENT<>0 OR INVOICE<>0 OR ORDERAMOUNT<>0 OR ORDERINVOICE<>0))");
strSql.Append(" or (WmsOutBsNo='" + custno + "')");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = Convert.ToInt32(reader["count"]);
if (evData > 0) { result = true; };
}
reader.Close();
}
return result;
}
private static List<ModuTreeRefModel> SetModuTreeRefData(StringBuilder strSql)
{
var headList = new List<ModuTreeRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ModuTreeRefModel data = new ModuTreeRefModel();
#region Set DB data to Object
data.id = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.MODULEURL = Convert.ToString(reader["MODULEURL"]);
data.PARENTID = Convert.ToString(reader["PARENTID"]);
data.PARENTNAME = Convert.ToString(reader["PARENTNAME"]);
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);
data.TYPE = Convert.ToInt16(reader["TYPE"]);
if (data.MODULEURL == "#")
{
data.leaf = false;
data.expanded = true;
}
else
{
data.leaf = true;
data.expanded = false;
};
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
static public List<PortRefModel> GetPortRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" PORTID,PORT,CNAME");
strSql.Append(" from code_disport ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by PORT");
return SetPortRefData(strSql);
}
static public List<PortRefModel> GetOurPortRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" PORTID,PORT,CNAME");
strSql.Append(" from code_loadport ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by PORT");
return SetPortRefData(strSql);
}
private static List<PortRefModel> SetPortRefData(StringBuilder strSql)
{
var headList = new List<PortRefModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
PortRefModel data = new PortRefModel();
#region Set DB data to Object
data.PORT = Convert.ToString(reader["PORT"]);
data.PORTID = Convert.ToString(reader["PORTID"]);
data.CNAME = Convert.ToString(reader["CNAME"]);
data.PORTANDNAME = Convert.ToString(reader["PORT"])+"-"+Convert.ToString(reader["CNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<GOODSModel> GetGoodsRefList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" GOODCODE,GOODNAME");
strSql.Append(" from code_goods ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by GOODCODE");
return SetGOODData(strSql);
}
private static List<GOODSModel> SetGOODData(StringBuilder strSql)
{
var headList = new List<GOODSModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
GOODSModel data = new GOODSModel();
#region Set DB data to Object
data.GOODCODE = Convert.ToString(reader["GOODCODE"]);
data.GOODNAME = Convert.ToString(reader["GOODNAME"]);
data.CODEANDNAME =Convert.ToString(reader["GOODCODE"])+"-"+ Convert.ToString(reader["GOODNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<STLMODE> GetStlModeList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" STLCODE,STLNAME");
strSql.Append(" from code_stlmode ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by STLCODE");
return SetStlModeData(strSql);
}
private static List<STLMODE> SetStlModeData(StringBuilder strSql)
{
var headList = new List<STLMODE>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
STLMODE data = new STLMODE();
#region Set DB data to Object
data.STLCODE = Convert.ToString(reader["STLCODE"]);
data.STLNAME = Convert.ToString(reader["STLNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<BANK> GetBANKList(string strCondition,string COMPANYID)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT ");
strSql.Append(" '' GID,'' CODENAME,'' CURRENCY,'' BANKNAME,'' ACCOUNT,'' ACCOUNTNAME,'' ISSTOP,'' ISDEF");
strSql.Append(" union all ");
strSql.Append(" SELECT ");
strSql.Append(" GID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,ACCOUNTNAME,ISSTOP,ISDEF");
strSql.Append(" from sys_bank WHERE LINKID='" + COMPANYID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
strSql.Append(" order by CODENAME");
return SetBANKData(strSql);
}
static public List<BANK> GetAllBANKList ( string strCondition )
{
var strSql = new StringBuilder();
//strSql.Append(" SELECT ");
//strSql.Append(" '' GID,'' CODENAME,'' CURRENCY,'' BANKNAME,'' ACCOUNT,'' ACCOUNTNAME,'' ISSTOP,'' ISDEF");
//strSql.Append(" union all ");
strSql.Append(" SELECT ");
strSql.Append(" GID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,ACCOUNTNAME,ISSTOP,ISDEF");
strSql.Append(" from sys_bank WHERE 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
strSql.Append(" order by CODENAME");
return SetBANKData(strSql);
}
private static List<BANK> SetBANKData(StringBuilder strSql)
{
var headList = new List<BANK>();
headList.Add(new BANK());
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BANK data = new BANK();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CODENAME = Convert.ToString(reader["CODENAME"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.BANKNAME = Convert.ToString(reader["BANKNAME"]);
data.ACCOUNT = Convert.ToString(reader["ACCOUNT"]);
data.ACCOUNTNAME = Convert.ToString(reader["ACCOUNTNAME"]);
data.ACCBANKNAME = Convert.ToString(reader["ACCOUNTNAME"]) + "-" + Convert.ToString(reader["BANKNAME"]);
data.ISSTOP = Convert.ToString(reader["ISSTOP"]);
data.ISDEF = Convert.ToString(reader["ISDEF"]);
data.BANKACCOUNT = Convert.ToString(reader["BANKNAME"]) + "-" + Convert.ToString(reader["ACCOUNT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region EDI发送记录
public static List<EDILOG> GetOpEdiLog(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [MFNO],[BSNO],[EDITYPE],[FILETYPE],[CARRIER],[EDISERVICE],[SENDER],[SENDDATE],[EDIFILE],EDIFILEPATH ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=op_edi_log.EDITYPE) as EDITYPEREF");
strSql.Append(",(CASE FILETYPE WHEN 'B' THEN '订舱' WHEN 'E' THEN 'SI' WHEN 'V' THEN 'VGM' ELSE FILETYPE END) FILETYPEREF ");
strSql.Append(" FROM op_edi_log ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var headList = new List<EDILOG>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDILOG data = new EDILOG();
data.MFNO = Convert.ToString(reader["MFNO"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.EDITYPE = Convert.ToString(reader["EDITYPEREF"]);
data.FILETYPE = Convert.ToString(reader["FILETYPEREF"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.EDISERVICE = Convert.ToString(reader["EDISERVICE"]);
data.SENDER = Convert.ToString(reader["SENDER"]);
data.SENDDATE = Convert.ToString(reader["SENDDATE"]);
data.EDIFILE = Convert.ToString(reader["EDIFILE"]);
data.EDIFILEPATH = Convert.ToString(reader["EDIFILEPATH"]);
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static List<OPCODE> GetOpRang(string optype, string userid)
{
var strSql = new StringBuilder();
strSql.Append(GetRangDASQLStr(optype, userid));
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<OPCODE>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new OPCODE();
evData.OPID = Convert.ToString(reader["OPCODE"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
public static List<OPCODE_Limit> GetOpRang_Limit(string optype, string userid)
{
var strSql = new StringBuilder();
strSql.Append(GetRangDASQLStr(optype, userid));
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<OPCODE_Limit>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new OPCODE_Limit();
evData.OPID = Convert.ToString(reader["OPCODE"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
public static string GetRangDASQLStr(string tb, string userid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='" + tb + "' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
break;
}
reader.Close();
}
if (operaterange == "4")
{
// str = "select '1' AS OPCODE from [user] where CODENAME='" + userid + "'";
str = "select SHOWNAME AS OPCODE from [user] where GID='" + userid + "'";
}
else if (operaterange == "3")
{
str = "select SHOWNAME AS OPCODE from [user] where GID='" + userid + "'";
}
else if (operaterange == "2")
{
var rangeDa = new RangeDA();
var deptid = rangeDa.GetDEPTGID(userid);
str = " select SHOWNAME AS OPCODE from vw_user where deptgid='" + deptid + "'";
}
else if (operaterange == "1")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
str = " select SHOWNAME AS OPCODE from [user] where GID IN (select USERID from user_company where COMPANYID='" + companyid + "')";
}
else if (operaterange == "5")
{
str = " select SHOWNAME OPCODE from VW_user where COMPANYID in (select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and OPERATERANGE=1)";
}
else if (operaterange == "6")
{
str = " select (select SHOWNAME from [user] where GID=user_authority_range_op.OPID) OPCODE from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and OPERATERANGE=1";
}
else { str = "select SHOWNAME AS OPCODE from [user] "; }
return str;
}
public static List<OPCODE> GetOpIDRang(string optype, string userid)
{
var strSql = new StringBuilder();
strSql.Append(GetRangLockIDSQLStr(optype, userid));
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<OPCODE>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new OPCODE();
evData.OPID = Convert.ToString(reader["OPCODE"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
public static bool GetCanOP(string optype, string userid, string OPID) {
var oplist = GetOpIDRang(optype, userid);
foreach (var opitem in oplist) {
if (opitem.OPID == OPID) {
return true;
}
}
return false;
}
public static string GetRangLockIDSQLStr(string tb, string userid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='" + tb + "' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (operaterange == "4")
{
str = "select '0' AS OPCODE from [user] where CODENAME='" + userid + "'";
}
else if (operaterange == "3")
{
str = "select GID AS OPCODE from [user] where GID='" + userid + "'";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
var deptname = rangeDa.GetDEPTNAME(userid);
str = " select USERID AS OPCODE from user_company where COMPANYID='" + companyid + "' and USERID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')";
}
else if (visiblerange == "1")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
str = " select USERID AS OPCODE from user_company where COMPANYID='" + companyid + "'";
}
else { str = "select GID AS OPCODE from [user] "; }
return str;
}
/// <summary>
/// 权限范围的“无”,不在默认为个人
/// </summary>
/// <param name="optype">中文名称</param>
/// <param name="userid"></param>
/// <returns></returns>
public static List<OPCODE> GetOpRang4(string optype, string userid)
{
var strSql = new StringBuilder();
strSql.Append(GetRangDASQLStr4(optype, userid));
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<OPCODE>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new OPCODE();
evData.OPID = Convert.ToString(reader["OPCODE"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
public static string GetRangDASQLStr4(string tb, string userid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='" + tb + "' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (operaterange == "4")
{
str = "select SHOWNAME AS OPCODE from [user] where 1<0";
}
else if (operaterange == "3")
{
str = "select SHOWNAME AS OPCODE from [user] where GID='" + userid + "'";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
var deptname = rangeDa.GetDEPTNAME(userid);
str = " select SHOWNAME AS OPCODE from [user] where GID IN (select USERID from user_company where COMPANYID='" + companyid + "' and USERID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))";
}
else if (visiblerange == "1")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
str = " select SHOWNAME AS OPCODE from [user] where GID IN (select USERID from user_company where COMPANYID='" + companyid + "')";
}
else { str = "select SHOWNAME AS OPCODE from [user] "; }
return str;
}
/// <summary>
/// 此编码规则是否启用
/// </summary>
/// <param name="rulename"></param>
/// <param name="ruletype"></param>
/// <returns></returns>
public static bool GetRuleUse(string rulename, string ruletype)
{
var IsUse = false;
var strSql = new StringBuilder();
strSql.Append("select ISSTARTUSING from code_rule where RULENAME='" + rulename + "' and RULETYPE='" + ruletype + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
IsUse = Convert.ToBoolean(reader["ISSTARTUSING"]);
}
reader.Close();
}
return IsUse;
}
/// <summary>
/// 是否生成之后允许编辑
/// </summary>
/// <param name="rulename"></param>
/// <param name="ruletype"></param>
/// <returns></returns>
public static bool GetRuleEdit(string rulename, string ruletype)
{
var IsEdit = true;
var strSql = new StringBuilder();
strSql.Append("select ISALLOWEDITS from code_rule where ISSTARTUSING=1 and RULENAME='" + rulename + "' and RULETYPE='" + ruletype + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
IsEdit = Convert.ToBoolean(reader["ISALLOWEDITS"]);
}
reader.Close();
}
return IsEdit;
}
static public List<UserBaseInfoModel> GetUserBaseList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,USERID,DEPTNAME,COMPANYNAME,OFFICEPHONE,MOBILE,FAX,EMAIL1");
strSql.Append(" from user_baseinfo ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetUserBaseData(strSql);
}
private static List<UserBaseInfoModel> SetUserBaseData(StringBuilder strSql)
{
var headList = new List<UserBaseInfoModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
UserBaseInfoModel data = new UserBaseInfoModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.USERID = Convert.ToString(reader["USERID"]);
data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]);
data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]);
data.OFFICEPHONE = Convert.ToString(reader["OFFICEPHONE"]);
data.MOBILE = Convert.ToString(reader["MOBILE"]);
data.FAX = Convert.ToString(reader["FAX"]);
data.EMAIL1 = Convert.ToString(reader["EMAIL1"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public CompanyGPSModel GetCompanyGps(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,GPSUser,GPSPassWord");
strSql.Append(" from company ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetCompanyGpsData(strSql);
}
private static CompanyGPSModel SetCompanyGpsData(StringBuilder strSql)
{
var headList = new List<CompanyGPSModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CompanyGPSModel data = new CompanyGPSModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.GPSUser = Convert.ToString(reader["GPSUser"]);
data.GPSPassWord = Convert.ToString(reader["GPSPassWord"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList[0];
}
static public List<OTCompanyENModel> GetOTCompanyEN(string strCondition, string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,NAME,ENNAME");
strSql.Append(" from company ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where GID<>'" + companyid + "' AND " + strCondition);
}
else {
strSql.Append(" where GID<>'" + companyid + "'" );
}
return SetCompanyENData(strSql);
}
private static List<OTCompanyENModel> SetCompanyENData(StringBuilder strSql)
{
var headList = new List<OTCompanyENModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OTCompanyENModel data = new OTCompanyENModel();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.ENNAME = Convert.ToString(reader["ENNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<OTCompanyENModel> GetCompanyEN(string strCondition, string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,NAME,ENNAME");
strSql.Append(" from company ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
else
{
}
return SetCompanyENData(strSql);
}
static public string DelPortCn(string port)
{
if (port == "" || port == null) return "";
var aport = port;
var apos=aport.LastIndexOf("-");
if (apos > 0) {
aport = aport.Substring(0, apos);
}
return aport;
}
public static List<CodeRptFeeGroup> GetCodeRptFeeGroup(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [DM_ID] ,[RPTNAME],[RPTTYPE],[INPUTBY],[INPUTDATE],[REMARKS] from code_feegroup_format");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<CodeRptFeeGroup>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeRptFeeGroup Data = new CodeRptFeeGroup();
Data.DM_ID = Convert.ToString(reader["DM_ID"]);
Data.RPTNAME = Convert.ToString(reader["RPTNAME"]);
Data.RPTTYPE = Convert.ToString(reader["RPTTYPE"]);
Data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
Data.INPUTDATE = Convert.ToString(reader["INPUTDATE"]);
Data.REMARKS = Convert.ToString(reader["REMARKS"]);
evList.Add(Data);
}
reader.Close();
}
return evList;
}
public static CompanyDef GetCompanyDef(string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,[CORPID],[PORTLOADID],[PORTLOAD],[BLFRT],[SERVICE],[KGS],[ISADVANCE],[ISCGOL],[AFRCARRIERID],[AFRAGENTID],[AFRETDTIME] from subcomp_seae_def");
strSql.Append(" Where CORPID='"+companyid+"'");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<CompanyDef>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new CompanyDef();
evData.GID = Convert.ToString(reader["GID"]);
evData.CORPID = Convert.ToString(reader["CORPID"]);
evData.PORTLOADID = Convert.ToString(reader["PORTLOADID"]);
evData.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
evData.BLFRT = Convert.ToString(reader["BLFRT"]);
evData.AFRCARRIERID = Convert.ToString(reader["AFRCARRIERID"]);
evData.AFRAGENTID = Convert.ToString(reader["AFRAGENTID"]);
evData.AFRETDTIME = Convert.ToString(reader["AFRETDTIME"]);
evList.Add(evData);
}
reader.Close();
}
if (evList.Count > 0)
return evList[0];
return new CompanyDef();
}
#region 个人查询条件设置
public static UserQuerySettingModel GetUserQuerySetting(string userid,string formname)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[USERID],[CREATETIME],[FORMNAME],[ISVISIBLE],[ISSAVEVALUE],FIELDVALUES FROM user_query_setting");
strSql.Append(" Where USERID='" + userid + "' AND FORMNAME='"+formname+"'");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<UserQuerySettingModel>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new UserQuerySettingModel();
evData.GID = Convert.ToString(reader["GID"]);
evData.USERID = Convert.ToString(reader["USERID"]);
evData.FORMNAME = Convert.ToString(reader["FORMNAME"]);
evData.ISVISIBLE = Convert.ToBoolean(reader["ISVISIBLE"]);
evData.ISSAVEVALUE = Convert.ToBoolean(reader["ISSAVEVALUE"]);
evData.FIELDVALUES = Convert.ToString(reader["FIELDVALUES"]);
evList.Add(evData);
}
reader.Close();
}
if (evList.Count > 0)
return evList[0];
return new UserQuerySettingModel();
}
public static DBResult SaveUserQuerySetting(string isvisible,string issavevalue, string userid, string formname,string fieldvalues)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into user_query_setting (GID,USERID,CREATETIME,FORMNAME,ISVISIBLE,ISSAVEVALUE,FIELDVALUES)
values (@GID,@USERID,@CREATETIME,@FORMNAME,@ISVISIBLE,@ISSAVEVALUE,@FIELDVALUES) ");
var cmdDelete =
db.GetSqlStringCommand(
@"Delete from user_query_setting where formname='" + formname + "' and userid='" + userid + "' ");
db.ExecuteNonQuery(cmdDelete, tran);
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@USERID", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@FORMNAME", DbType.String, formname);
db.AddInParameter(cmdInsert, "@ISVISIBLE", DbType.Boolean, isvisible);
db.AddInParameter(cmdInsert, "@ISSAVEVALUE", DbType.Boolean, issavevalue);
db.AddInParameter(cmdInsert, "@FIELDVALUES", DbType.String, fieldvalues);
db.ExecuteNonQuery(cmdInsert, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static List<QueryFieldModel> GetQueryFieldSetting(string formname)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[FORMNAME],[FIELDCNAME],[FIELDENAME],[FIELDTYPE],[FIELDNAME],[NESTEDSQL],SORT FROM sys_queryfield_setting");
strSql.Append(" Where FORMNAME='" + formname + "' ORDER BY SORT ");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<QueryFieldModel>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new QueryFieldModel();
evData.GID = Convert.ToString(reader["GID"]);
evData.FORMNAME = Convert.ToString(reader["FORMNAME"]);
evData.FIELDCNAME = Convert.ToString(reader["FIELDCNAME"]);
evData.FIELDENAME = Convert.ToString(reader["FIELDENAME"]);
evData.FIELDTYPE = Convert.ToString(reader["FIELDTYPE"]);
evData.FIELDNAME = Convert.ToString(reader["FIELDNAME"]);
evData.NESTEDSQL = Convert.ToString(reader["NESTEDSQL"]);
evList.Add(evData);
}
reader.Close();
}
var evData2 = new QueryFieldModel();
evData2.GID ="";
evData2.FORMNAME ="";
evData2.FIELDCNAME ="";
evData2.FIELDENAME = "";
evData2.FIELDTYPE = "";
evData2.FIELDNAME ="";
evData2.NESTEDSQL ="";
evList.Add(evData2);
return evList;
}
public static List<DsQueryListModel> GetQueryList(string userid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("CODENAME AS CustCode, SHORTNAME AS CustName,CODENAME + '-' + SHORTNAME AS CodeAndName");
strSql.Append(" from info_Client ");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<DsQueryListModel>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new DsQueryListModel();
evData.NAME = Convert.ToString(reader["CodeAndName"]);
evData.VALUE = Convert.ToString(reader["CustName"]);
evList.Add(evData);
}
reader.Close();
}
var evData2 = new DsQueryListModel();
evData2.NAME ="";
evData2.VALUE ="";
evList.Add(evData2);
return evList;
}
#endregion
public static string GetMessageStr(string userid)
{
string str = "我的消息";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" SUM(CASE WHEN ISNULL(ISREAD,0) = 1 THEN 1 ELSE 0 END) AS READTOTAL,SUM(CASE WHEN ISNULL(ISREAD,0) = 0 THEN 1 ELSE 0 END) AS UNREADTOTAL,COUNT(GID) as TOTAL ");
strSql.Append(" FROM sys_message WITH(NOLOCK) WHERE RECEIVER ='" + userid + "' AND ISNULL(ISDELETE,0) <> 1 ");
string readtotal = "0";
string unreadtotal = "0";
string total = "0";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
readtotal = Convert.ToString(reader["READTOTAL"]);
unreadtotal = Convert.ToString(reader["UNREADTOTAL"]);
total = Convert.ToString(reader["TOTAL"]);
break;
}
reader.Close();
}
str = str + "(" + unreadtotal + "/" + total + ")";
return str;
}
public static List<SysMessage> GetMessageList(string userid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" * ");
strSql.Append(" FROM sys_message WITH(NOLOCK) WHERE CREATETIME>='"+DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd") +"' and RECEIVER ='" + userid + "' AND ISNULL(ISREAD,0) <> 1 AND ISNULL(ISDELETE,0) <> 1 AND ISNULL(ISSEND,0) <> 1 ");
strSql.Append(" and NAME not in (select WORKFLOWTYPE_NAME from user_msg_set where userid='" + userid + "') order by CREATETIME ");
var evList = new List<SysMessage>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new SysMessage();
evData.GID = Convert.ToString(reader["GID"]);
evData.NAME = Convert.ToString(reader["NAME"]);
evData.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
if (reader["ISREAD"] != DBNull.Value)
evData.ISREAD = Convert.ToBoolean(reader["ISREAD"]);
if (reader["READCOUNT"] != DBNull.Value)
evData.READCOUNT = Convert.ToInt32(reader["READCOUNT"]);
evData.MESSAGECONTENT = Convert.ToString(reader["MESSAGECONTENT"]);
evData.LASTREADTIME = Convert.ToString(reader["LASTREADTIME"]);
evData.RECEIVER = Convert.ToString(reader["RECEIVER"]);
if (reader["TYPE"] != DBNull.Value)
evData.TYPE = Convert.ToInt32(reader["TYPE"]);
evData.TASKURL = Convert.ToString(reader["TASKURL"]);
evData.TASKID = Convert.ToString(reader["TASKID"]);
evData.RECVTYPE = Convert.ToString(reader["RECVTYPE"]);
if (reader["ISSEND"] != DBNull.Value)
evData.ISSEND = Convert.ToBoolean(reader["ISSEND"]);
evList.Add(evData);
}
reader.Close();
}
return evList;
}
public static DBResult MessageSend(List<SysMessage> boday)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmdupdate = db.GetSqlStringCommand("update sys_message set ISSEND=1 where GID=@GID");
foreach (var enumValue in boday)
{
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
}
result = new DBResult();
result.Success = true;
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "审核出现错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
//public static FtpSet GetCompanyFtpSet(string ediname,string companyid)
//{
// var strSql = new StringBuilder();
// strSql.Append("SELECT GID,[CORPID],[EDINAME],[SERVERIP],[FOLDERNAME],[USERNAME],[PASSWORD],SENDCODE,RECEIVECODE,SENDNAME,SENDATTN,SENDTEL,SENDEMAIL,RECEIVEOP,RECEIVESALE,RECEIVEDEPT from code_FtpSet");
// strSql.Append(" Where CORPID='" + companyid + "' and EDINAME='"+ediname+"'");
// Database db = DatabaseFactory.CreateDatabase();
// var evList = new List<FtpSet>();
// using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
// {
// while (reader.Read())
// {
// var evData = new FtpSet();
// evData.GID = Convert.ToString(reader["GID"]);
// evData.CORPID = Convert.ToString(reader["CORPID"]);
// evData.EDINAME = Convert.ToString(reader["EDINAME"]);
// evData.SERVERIP = Convert.ToString(reader["SERVERIP"]);
// evData.FOLDERNAME = Convert.ToString(reader["FOLDERNAME"]);
// evData.USERNAME = Convert.ToString(reader["USERNAME"]);
// evData.PASSWORD = Convert.ToString(reader["PASSWORD"]);
// evData.SENDCODE = Convert.ToString(reader["SENDCODE"]);
// evData.RECEIVECODE = Convert.ToString(reader["RECEIVECODE"]);
// evData.SENDNAME = Convert.ToString(reader["SENDNAME"]);
// evData.SENDATTN = Convert.ToString(reader["SENDATTN"]);
// evData.SENDTEL = Convert.ToString(reader["SENDTEL"]);
// evData.SENDEMAIL = Convert.ToString(reader["SENDEMAIL"]);
// evData.RECEIVEOP = Convert.ToString(reader["RECEIVEOP"]);
// evData.RECEIVESALE = Convert.ToString(reader["RECEIVESALE"]);
// evData.RECEIVEDEPT = Convert.ToString(reader["RECEIVEDEPT"]);
// evList.Add(evData);
// }
// reader.Close();
// }
// if (evList.Count > 0)
// return evList[0];
// return new FtpSet();
//}
#region 总账凭证号生成
public static string GetCwVOUNO(string VKNO, string strACCDATE, string strUserID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string sSQL = "SELECT top 1 * from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "'";
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
if (dsCwDesign == null)
{
//return "请先设置帐套信息!";
return "-1";
}
//
string strY = strACCDATE.Trim().Substring(0, 4);
string strM = strACCDATE.Trim().Substring(5, 2);
int day = DateTime.DaysInMonth(int.Parse(strY), int.Parse(strM));
string sDay = DateTime.Now.Day.ToString();
if (int.Parse(sDay) > day)
{
sDay = day.ToString();
}
if(sDay.Length==1)
{
sDay = "0" + sDay;
}
string strVOUDATE = strACCDATE + "-" + sDay;
string sVOUNO = "";
string strVOUNO = "SELECT top 1 convert(INT,right(VOUALLNO,4)) as VOUNO from ((select VOUALLNO from cw_vouchers_gl where STARTGID='" + strCwSTARTGID + "' and ACCYEAR='" + strY + "' and ACCMONTH='" + strM + "' and VKNO='" + VKNO + "' and (ISDELETE=0 or ISDELETE is null)) UNION (select VOUALLNO from cw_vouno_bs_gl where STARTGID='" + strCwSTARTGID + "' and VOUALLNO like '" + VKNO + strY + strM + "%')) AS a order by VOUALLNO desc";
strVOUNO = T_ALL_DA.GetStrSQL("VOUNO", strVOUNO);
if (strVOUNO.Trim() == "")
{
sVOUNO = "1";
strVOUNO = "0001";
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='凭证号' and RULETYPE=5");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim() != "")
{
strVOUNO = ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim();
}
}
}
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISFILLSERIALNO"].ToString().Trim() == "True")
{
string strFILL = "select top 1 serialno from code_fill_serialno where (ISDELETE=0 or ISDELETE is null) and STARTGID='" + strCwSTARTGID + "' and tablename='cw_vouchers_gl' and serialno like '%" + strY + strM + "%' and serialno not in (select VOUALLNO from cw_vouchers_gl where (ISDELETE=0 or ISDELETE is null) and STARTGID='" + strCwSTARTGID + "') and LEFT(serialno, LEN('" + VKNO + "'))='" + VKNO + "' and serialno not in (select VOUALLNO from cw_vouno_bs_gl where STARTGID='" + strCwSTARTGID + "') order by serialno";// and CHARINDEX('" + VKNO + "', serialno)>0
strFILL = T_ALL_DA.GetStrSQL("serialno", strFILL);
if (strFILL.Trim() != "")
{
strVOUNO = strFILL.Trim().Substring(strFILL.Length-4);
sVOUNO = int.Parse(strVOUNO).ToString();
return strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
}
}
sVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
strVOUNO = sVOUNO;
for (int i = 0; i < 4 - sVOUNO.Length; i++)
{
strVOUNO = "0" + strVOUNO;
}
}
sVOUNO = int.Parse(strVOUNO).ToString();
return strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
}
public static string GetCwISRATESET(string strUserID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string sSQL = "SELECT top 1 * from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "'";
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
if (dsCwDesign == null)
{
//return "请先设置帐套信息!";
return "-1";
}
if (dsCwDesign.Tables[0].Rows[0]["ISRATESET"].ToString().Trim() == "True")
{
return "1";
} else return "-1";
}
public static string GetCwVOUNO(string VKNO, string strACCDATE, string strUserID, string strCwSTARTGID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "SELECT top 1 * from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "'";
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
if (dsCwDesign == null)
{
//return "请先设置帐套信息!";
return "-1";
}
//
string strY = strACCDATE.Trim().Substring(0, 4);
string strM = strACCDATE.Trim().Substring(5, 2);
int day = DateTime.DaysInMonth(int.Parse(strY), int.Parse(strM));
string sDay = DateTime.Now.Day.ToString();
if (int.Parse(sDay) > day)
{
sDay = day.ToString();
}
if (sDay.Length == 1)
{
sDay = "0" + sDay;
}
string strVOUDATE = strACCDATE + "-" + sDay;
string sVOUNO = "";
string strVOUNO = "SELECT top 1 convert(INT,right(VOUALLNO,4)) as VOUNO from ((select VOUALLNO from cw_vouchers_gl where STARTGID='" + strCwSTARTGID + "' and ACCYEAR='" + strY + "' and ACCMONTH='" + strM + "' and VKNO='" + VKNO + "' and (ISDELETE=0 or ISDELETE is null)) UNION (select VOUALLNO from cw_vouno_bs_gl where STARTGID='" + strCwSTARTGID + "' and VOUALLNO like '" + VKNO + strY + strM + "%')) AS a order by VOUALLNO desc";
strVOUNO = T_ALL_DA.GetStrSQL("VOUNO", strVOUNO);
if (strVOUNO.Trim() == "")
{
sVOUNO = "1";
strVOUNO = "0001";
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='凭证号' and RULETYPE=5");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim() != "")
{
strVOUNO = ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim();
}
}
}
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISFILLSERIALNO"].ToString().Trim() == "True")
{
string strFILL = "select top 1 serialno from code_fill_serialno where (ISDELETE=0 or ISDELETE is null) and STARTGID='" + strCwSTARTGID + "' and tablename='cw_vouchers_gl' and serialno like '%" + strY + strM + "%' and serialno not in (select VOUALLNO from cw_vouchers_gl where (ISDELETE=0 or ISDELETE is null) and STARTGID='" + strCwSTARTGID + "') and LEFT(serialno, LEN('" + VKNO + "'))='" + VKNO + "' and serialno not in (select VOUALLNO from cw_vouno_bs_gl where STARTGID='" + strCwSTARTGID + "') order by serialno";// and CHARINDEX('" + VKNO + "', serialno)>0
strFILL = T_ALL_DA.GetStrSQL("serialno", strFILL);
if (strFILL.Trim() != "")
{
strVOUNO = strFILL.Trim().Substring(strFILL.Length - 4);
sVOUNO = int.Parse(strVOUNO).ToString();
return strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
}
}
sVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
strVOUNO = sVOUNO;
for (int i = 0; i < 4 - sVOUNO.Length; i++)
{
strVOUNO = "0" + strVOUNO;
}
}
sVOUNO = int.Parse(strVOUNO).ToString();
return strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
}
#endregion
#region 接口凭证号生成
public static string GetVOUNO(string VKNO, string strACCDATE)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "SELECT top 1 * from cw_design WITH(NOLOCK)";
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
if (dsCwDesign == null)
{
//return "请先设置帐套信息!";
return "-1";
}
//
string strY = strACCDATE.Trim().Substring(0, 4);
string strM = strACCDATE.Trim().Substring(5, 2);
int day = DateTime.DaysInMonth(int.Parse(strY), int.Parse(strM));
string sDay = DateTime.Now.Day.ToString();
if (int.Parse(sDay) > day)
{
sDay = day.ToString();
}
if (sDay.Length == 1)
{
sDay = "0" + sDay;
}
string strVOUDATE = strACCDATE + "-" + sDay;
string sVOUNO = "";
//string lsVOUALLNO = "select (ISNULL((select top 1 VOUNO from cw_vouchers_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ACCYEAR='" + headData.ACCYEAR.ToString() + "' and ACCMONTH='" + headData.ACCMONTH.ToString() + "' and VKNO='" + headData.VKNO.ToString() + "' order by VOUALLNO desc),0)+1) as VOUNO";
string strVOUNO = "select top 1 VOUNO from cw_vouchers where ACCYEAR='" + strY + "' and ACCMONTH='" + strM + "' and VKNO='" + VKNO + "' and (ISDELETE=0 or ISDELETE is null) and LEFT(serialno, LEN('" + VKNO + "'))='" + VKNO + "' order by convert(int,VOUNO) desc";// and CHARINDEX('" + VKNO + "', serialno)>0
strVOUNO = T_ALL_DA.GetStrSQL("VOUNO", strVOUNO);
if (strVOUNO.Trim() == "")
{
sVOUNO = "1";
strVOUNO = "0001";
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='凭证号' and RULETYPE=5");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim() != "")
{
strVOUNO = ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim();
}
}
}
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISFILLSERIALNO"].ToString().Trim() == "True")
{
string strFILL = "select top 1 serialno from code_fill_serialno where ISDELETE=0 and tablename='cw_vouchers' and serialno like '%" + strY + strM + "%' and serialno not in (select VOUALLNO from cw_vouchers where (ISDELETE=0 or ISDELETE is null)) and LEFT(serialno, LEN('" + VKNO + "'))='" + VKNO + "' order by serialno";// and CHARINDEX('" + VKNO + "', serialno)>0
strFILL = T_ALL_DA.GetStrSQL("serialno", strFILL);
if (strFILL.Trim() != "")
{
//strVOUNO = strFILL.Trim().Substring(6);
strVOUNO = strFILL.Trim().Substring(strFILL.Length - 4);
sVOUNO = int.Parse(strVOUNO).ToString();
return strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
}
}
sVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
strVOUNO = sVOUNO;
for (int i = 0; i < 4 - sVOUNO.Length; i++)
{
strVOUNO = "0" + strVOUNO;
}
}
sVOUNO = int.Parse(strVOUNO).ToString();
return strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + 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 根据条件从sys_module、user_action表中取数据
static public List<ModuTreeRefModel> GetSysModuleList(string strCondition, string userid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE,'' PARENTNAME");
strSql.Append(" FROM sys_module WHERE STATE <> 1");
strSql.Append(" AND GID IN (SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID ='" + userid + "')");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ORDER BY SORT ASC");
return SetModuTreeRefData(strSql);
}
#endregion
#region 检查reader内的值是否为null或""
public static bool CheckReader(Object readerItem) {
if (!string.IsNullOrEmpty(readerItem.ToString()))
{
return true;
}
else {
return false;
}
}
#endregion
}
}