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/MvcContainer/DAL/MsOpPrice/MsOpPriceDAL.cs

828 lines
33 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcContainer.Models.MsOpPrice;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.EntityDA;
namespace DSWeb.MvcContainer.DAL.MsOpPrice
{
public class MsOpPriceDAL
{
#region Inquery DataList
static public List<OpPrice> GetDataList(string strCondition, string pricetype,string companyid, string userid,string sort = null)
{
var rangstr = GetRangDAStr(pricetype, userid, userid, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modAgentdetailView",userid);
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[PRICETYPE],[LINE],[COUNTRY],[PORTLOAD],[PORTDISCHARGE],[TRANSPORT],[CARRIER],[WEEKETD]");
strSql.Append(",[VOYAGE],[VALIDETD],[SERVICE],[GOODTYPE],[CTNSTATUS],[AGENTNAME],[DEBITCORPNAME]");
strSql.Append(",[PRICEDATE],[REMARKS],[INPUTBY],[INPUTTIME],[OP],[COMPANYID],YARD,FEETYPE,CHANGERATE");
if (isopen == true)
strSql.Append(",AGENTATTN,AGENTADDR ");
else
strSql.Append(",'' AGENTATTN,'' AGENTADDR ");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.OP) as OPREF");
strSql.Append(" from op_price b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by INPUTTIME DESC ");
}
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string pricetype, string companyid, string userid, string sort = null)
{
var rangstr = GetRangDAStr(pricetype, userid, userid, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modAgentdetailView", userid);
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[PRICETYPE],[LINE],[COUNTRY],[PORTLOAD],[PORTDISCHARGE],[TRANSPORT],[CARRIER],[WEEKETD]");
strSql.Append(",[VOYAGE],[VALIDETD],[SERVICE],[GOODTYPE],[CTNSTATUS],[AGENTNAME],[DEBITCORPNAME]");
strSql.Append(",[PRICEDATE],[REMARKS],[INPUTBY],[INPUTTIME],[OP],[COMPANYID],YARD,FEETYPE,CHANGERATE");
if (isopen == true)
strSql.Append(",AGENTATTN,AGENTADDR ");
else
strSql.Append(",'' AGENTATTN,'' AGENTADDR ");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.OP) as OPREF");
strSql.Append(" from op_price b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by INPUTTIME DESC ");
}
return strSql.ToString();
}
static public OpPrice GetData(string condition, string pricetype,string companyid,string userid)
{
OpPrice data = null;
var list = GetDataList(condition, pricetype,companyid, userid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new OpPrice();
data.COMPANYID = companyid;
}
return data;
}
static public OpPrice GetData(string condition,string userid)
{
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modAgentdetailView", userid);
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[PRICETYPE],[LINE],[COUNTRY],[PORTLOAD],[PORTDISCHARGE],[TRANSPORT],[CARRIER],[WEEKETD]");
strSql.Append(",[VOYAGE],[VALIDETD],[SERVICE],[GOODTYPE],[CTNSTATUS],[AGENTNAME],[DEBITCORPNAME]");
strSql.Append(",[PRICEDATE],[REMARKS],[INPUTBY],[INPUTTIME],[OP],[COMPANYID],YARD,FEETYPE,CHANGERATE");
if (isopen == true)
strSql.Append(",AGENTATTN,AGENTADDR ");
else
strSql.Append(",'' AGENTATTN,'' AGENTADDR ");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.OP) as OPREF");
strSql.Append(" from op_price b ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var list = SetData(strSql);
if (list.Count > 0)
return list[0];
return new OpPrice();
}
private static List<OpPrice> SetData(StringBuilder strSql)
{
var headList = new List<OpPrice>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpPrice data = new OpPrice();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PRICETYPE = Convert.ToString(reader["PRICETYPE"]);
data.LINE = Convert.ToString(reader["LINE"]);
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.TRANSPORT = Convert.ToString(reader["TRANSPORT"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.WEEKETD = Convert.ToString(reader["WEEKETD"]);
data.VOYAGE = Convert.ToString(reader["VOYAGE"]);
if (reader["VALIDETD"] != DBNull.Value)
data.VALIDETD = Convert.ToDateTime(reader["VALIDETD"]).ToString("yyyy-MM-dd");
data.SERVICE = Convert.ToString(reader["SERVICE"]);
data.GOODTYPE = Convert.ToString(reader["GOODTYPE"]);
data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]);
data.AGENTNAME = Convert.ToString(reader["AGENTNAME"]);
data.AGENTATTN = Convert.ToString(reader["AGENTATTN"]);
data.AGENTADDR = Convert.ToString(reader["AGENTADDR"]);
data.DEBITCORPNAME = Convert.ToString(reader["DEBITCORPNAME"]);
if (reader["PRICEDATE"] != DBNull.Value)
data.PRICEDATE = Convert.ToDateTime(reader["PRICEDATE"]).ToString("yyyy-MM-dd");
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
data.YARD = Convert.ToString(reader["YARD"]);
data.FEETYPE = Convert.ToString(reader["FEETYPE"]);
data.OP = Convert.ToString(reader["OP"]);
data.OPREF = Convert.ToString(reader["OPREF"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
if (reader["CHANGERATE"] != DBNull.Value)
data.CHANGERATE = Convert.ToDecimal(reader["CHANGERATE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteOpPrice(List<OpPrice> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from op_price where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#endregion
#region Price Items
static public List<OpPriceItems> GetPriceItemsList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],[ITEMSNO],[FEENAME],[UNIT],[UNITPRICE],[CURRENCY],[CHANGERATE],[GOODSNAME]");
strSql.Append(",[REMARKS],[INPUTBY],[INPUTTIME],[FEESTATUS],CTNSTATUS,[FREEDAY],[VALIDETD],[AUDITOPERATOR],[AUDITDATE],[CUSTOMERNAME]");
strSql.Append(",(select ShowName from [user] where GID=op_price_items.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=op_price_items.AUDITOPERATOR) as AUDITNAME");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=op_price_items.FeeStatus) as FEESTATUS_REF");
strSql.Append(" from op_price_items ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ITEMSNO");
}
return SetPriceItemsData(strSql);
}
private static List<OpPriceItems> SetPriceItemsData(StringBuilder strSql)
{
var headList = new List<OpPriceItems>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpPriceItems data = new OpPriceItems();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
if (reader["ITEMSNO"] != DBNull.Value)
data.ITEMSNO = Convert.ToInt16(reader["ITEMSNO"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.UNIT = Convert.ToString(reader["UNIT"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["CHANGERATE"] != DBNull.Value)
data.CHANGERATE = Convert.ToDecimal(reader["CHANGERATE"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["AUDITDATE"] != DBNull.Value)
data.AUDITDATE = Convert.ToDateTime(reader["AUDITDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["VALIDETD"] != DBNull.Value)
data.VALIDETD = Convert.ToDateTime(reader["VALIDETD"]).ToString("yyyy-MM-dd");
if (reader["FEESTATUS"] != DBNull.Value)
data.FEESTATUS = Convert.ToInt16(reader["FEESTATUS"]);
data.FEESTATUS_REF = Convert.ToString(reader["FEESTATUS_REF"]);
data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]);
if (reader["FREEDAY"] != DBNull.Value)
data.FREEDAY = Convert.ToInt16(reader["FREEDAY"]);
data.AUDITOPERATOR = Convert.ToString(reader["AUDITOPERATOR"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SavePriceItems(List<OpPriceItems> bodyList, string PID, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_price_items (GID,LINKGID,ITEMSNO,FEENAME,UNIT,UNITPRICE,CURRENCY,CHANGERATE,GOODSNAME,INPUTBY,INPUTTIME,REMARKS,
FEESTATUS,CTNSTATUS,FREEDAY,VALIDETD,CUSTOMERNAME)
values (@GID,@LINKGID,@ITEMSNO,@FEENAME,@UNIT,@UNITPRICE,@CURRENCY,@CHANGERATE,@GOODSNAME,@INPUTBY,@INPUTTIME,@REMARKS,@FEESTATUS,
@CTNSTATUS,@FREEDAY,@VALIDETD,@CUSTOMERNAME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_price_items set FEENAME=@FEENAME,UNIT=@UNIT,UNITPRICE=@UNITPRICE,CURRENCY=@CURRENCY,CHANGERATE=@CHANGERATE,GOODSNAME=@GOODSNAME,
REMARKS=@REMARKS,FEESTATUS=@FEESTATUS,CTNSTATUS=@CTNSTATUS,FREEDAY=@FREEDAY,VALIDETD=@VALIDETD,CUSTOMERNAME=@CUSTOMERNAME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.VALIDETD == "") enumValue.VALIDETD = null;
else
{
enumValue.VALIDETD = Convert.ToDateTime(enumValue.VALIDETD.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.LINKGID == "*" || enumValue.LINKGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@ITEMSNO", DbType.Int16, enumValue.ITEMSNO);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdInsert, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdInsert, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@CHANGERATE", DbType.Decimal, enumValue.CHANGERATE);
db.AddInParameter(cmdInsert, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdInsert, "@FEESTATUS", DbType.Int16, enumValue.FEESTATUS);
db.AddInParameter(cmdInsert, "@FREEDAY", DbType.Int16, enumValue.FREEDAY);
db.AddInParameter(cmdInsert, "@CTNSTATUS", DbType.String, enumValue.CTNSTATUS);
if (string.IsNullOrEmpty(enumValue.VALIDETD))
db.AddInParameter(cmdInsert, "@VALIDETD", DbType.String, null);
else
db.AddInParameter(cmdInsert, "@VALIDETD", DbType.String, enumValue.VALIDETD);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdUpdate, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdUpdate, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdUpdate, "@CHANGERATE", DbType.Decimal, enumValue.CHANGERATE);
db.AddInParameter(cmdUpdate, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdUpdate, "@FEESTATUS", DbType.Int16, enumValue.FEESTATUS);
db.AddInParameter(cmdUpdate, "@FREEDAY", DbType.Int16, enumValue.FREEDAY);
db.AddInParameter(cmdUpdate, "@CTNSTATUS", DbType.String, enumValue.CTNSTATUS);
if (string.IsNullOrEmpty(enumValue.VALIDETD))
db.AddInParameter(cmdUpdate, "@VALIDETD", DbType.String, null);
else
db.AddInParameter(cmdUpdate, "@VALIDETD", DbType.String, enumValue.VALIDETD);
db.AddInParameter(cmdUpdate, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeletePriceItems(List<OpPriceItems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from op_price_items where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult SavePiliangUpdateFee(List<OpPrice> billList, List<OpPriceItems> bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_price_items set UNITPRICE=@UNITPRICE where LINKGID=@LINKGID and FEENAME=@FEENAME and UNIT=@UNIT ");
if (billList != null)
{
foreach (var enumbillValue in billList)
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdUpdate, "@LINKGID", DbType.String, enumbillValue.GID);
db.AddInParameter(cmdUpdate, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdUpdate, "@UNIT", DbType.String, enumValue.UNIT);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "更新出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "更新成功" + result.Message;
return result;
}
public static DBResult SubmitAudit(List<OpPriceItems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("update op_price_items set FEESTATUS=2 where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult AuditFee(List<OpPriceItems> headData,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("update op_price_items set FEESTATUS=0,AUDITOPERATOR='" + userid + "',AUDITDATE='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult AuditBack(List<OpPriceItems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("update op_price_items set FEESTATUS=6,AUDITOPERATOR='',AUDITDATE=null where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#endregion
#region 权限范围
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
string modustr = "";
if (tb == "1")
{
modustr = "modPriceSeae";
}
else if (tb == "2")
{
modustr = "modPriceSeai";
}
else if (tb == "3")
{
modustr = "modPriceAgent";
}
else if (tb == "4")
{
modustr = "modPriceYard";
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='" + modustr + "' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " b.OP='" + userid + "'";
}
else if (visiblerange == "3")
{
str = " b.OP='" + userid + "'";
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select userid from user_baseinfo where DEPTNAME='" + deptname + "'");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " b.OP='" + Convert.ToString(reader["userid"]) + "' ";
}
else
{
str = str + " or b.OP='" + Convert.ToString(reader["userid"]) + "' ";
};
}
str = str + ")";
reader.Close();
}
}
else
{
str = " b.COMPANYID='" + companyid + "'";
}
}
else if (visiblerange == "1")
{
str = " b.COMPANYID='" + companyid + "'";
}
return str;
}
#endregion
#region 场站报价查询
static public List<CUSTERNAME> GetCustList(string condition, string userid, string username, string companyid)
{
var rangstr = MsOpPriceDAL.GetRangDAStr("4",userid,username,companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + rangstr;
}
else
{
condition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT distinct CUSTOMERNAME from v_yard_price b ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" WHERE " + condition);
}
strSql.Append(" order by CUSTOMERNAME ");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<CUSTERNAME>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
var i = 1;
while (reader.Read())
{
var evData = new CUSTERNAME();
evData.CUSTNAME = Convert.ToString(reader["CUSTOMERNAME"]);
evData.FIELDNAME = "Z" + i.ToString();
evList.Add(evData);
i = i + 1;
}
reader.Close();
}
return evList;
}
#endregion
}
}