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

604 lines
29 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsOpApplyService;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsOpApplyServiceDAL
{
public class MsOpApplyServiceDAL
{
#region Inquery DataList
static public List<MsOpApplyService> GetDataList(string strCondition, string userid, string usercode, string orgcode,string sort = null)
{
/*
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
*/
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BSNO,OPField,STATUS,OP,INPUTBY,SERVICE,STARTDATETIME,PLANENDTIME");
strSql.Append(",ENDDATETIME,ENDOP,GID,Remark");
strSql.Append(" from op_apply_service ");
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 OPField");
}
return SetData(strSql);
}
static public MsOpApplyService GetData(string condition, string userid, string usercode, string orgcode)
{
var list = GetDataList(condition,userid,usercode,orgcode);
if (list.Count > 0)
return list[0];
return new MsOpApplyService();
}
private static List<MsOpApplyService> SetData(StringBuilder strSql)
{
var headList = new List<MsOpApplyService>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpApplyService data = new MsOpApplyService();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.OPFIELD = Convert.ToString(reader["OPField"]);
data.STATUS = Convert.ToString(reader["STATUS"]);
if (reader["STARTDATETIME"] != DBNull.Value)
data.STARTDATETIME = Convert.ToString(reader["STARTDATETIME"]);
if (reader["PLANENDTIME"] != DBNull.Value)
data.PLANENDTIME = Convert.ToString(reader["PLANENDTIME"]);
if (reader["ENDDATETIME"] != DBNull.Value)
data.ENDDATETIME = Convert.ToString(reader["ENDDATETIME"]);
data.OP = Convert.ToString(reader["OP"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.SERVICE = Convert.ToString(reader["SERVICE"]);
data.ENDOP = Convert.ToString(reader["ENDOP"]);
data.GID = Convert.ToString(reader["GID"]);
// data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.REMARK = Convert.ToString(reader["Remark"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 明细表
static public List<MsOpApplyServiceDetail> GetBodyList(string strCondition,string sort)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BSNO,GID,SerialNo,OPField,STATUS,WORK,NOFINISHRESON,STARTDATETIME,PLANENDTIME");
strSql.Append(",ENDDATETIME,ENDOP,NEXTPLAN,OTADVICE,HELPOP,Remark");
strSql.Append(" from op_apply_service_detail ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by SerialNo");
}
return SetBodyData(strSql);
}
private static List<MsOpApplyServiceDetail> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsOpApplyServiceDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpApplyServiceDetail data = new MsOpApplyServiceDetail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.STATUS = Convert.ToString(reader["STATUS"]);
data.OPFIELD = Convert.ToString(reader["OPField"]);
data.WORK = Convert.ToString(reader["WORK"]);
if (reader["STARTDATETIME"] != DBNull.Value)
data.STARTDATETIME = Convert.ToString(reader["STARTDATETIME"]);
if (reader["PLANENDTIME"] != DBNull.Value)
data.PLANENDTIME = Convert.ToString(reader["PLANENDTIME"]);
if (reader["ENDDATETIME"] != DBNull.Value)
data.ENDDATETIME = Convert.ToString(reader["ENDDATETIME"]);
data.NOFINISHRESON = Convert.ToString(reader["NOFINISHRESON"]);
data.NEXTPLAN = Convert.ToString(reader["NEXTPLAN"]);
data.ENDOP = Convert.ToString(reader["ENDOP"]);
data.OTADVICE = Convert.ToString(reader["OTADVICE"]);
data.HELPOP = Convert.ToString(reader["HELPOP"]);
// data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.REMARK = Convert.ToString(reader["Remark"]);
data.GID = Convert.ToString(reader["GID"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
public static DBResult SaveDetail(MsOpApplyService headData, List<MsOpApplyServiceDetail> bodyList)
{
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_apply_service_detail (BSNO, SerialNo,OPField,STATUS,WORK,NOFINISHRESON,STARTDATETIME,PLANENDTIME,
ENDDATETIME,ENDOP,NEXTPLAN,OTADVICE,HELPOP,Remark,GID)
values (@BSNO, @SerialNo,@OPField,@STATUS,@WORK,@NOFINISHRESON,@STARTDATETIME,@PLANENDTIME,
@ENDDATETIME,@ENDOP,@NEXTPLAN,@OTADVICE,@HELPOP,@Remark,@GID) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_apply_service_detail set BSNO=@BSNO, SerialNo=@SerialNo,OPField=@OPField,STATUS=@STATUS,WORK=@WORK,
NOFINISHRESON=@NOFINISHRESON,STARTDATETIME=@STARTDATETIME,PLANENDTIME=@PLANENDTIME,ENDDATETIME=@ENDDATETIME,
ENDOP=@ENDOP,NEXTPLAN=@NEXTPLAN,OTADVICE=@OTADVICE,HELPOP=@HELPOP,Remark=@Remark WHERE GID=@GID ");
var strGID = "";
var StrGIDLIST = "('1000'";
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "")
{
strGID = Guid.NewGuid().ToString();
StrGIDLIST = StrGIDLIST + ",'" + strGID+ "'";
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, headData.BSNO);
db.AddInParameter(cmdInsert, "@SerialNo", DbType.Int32, enumValue.SerialNo);
db.AddInParameter(cmdInsert, "@OPField", DbType.String, headData.OPFIELD);
db.AddInParameter(cmdInsert, "@STATUS", DbType.String, enumValue.STATUS);
db.AddInParameter(cmdInsert, "@WORK", DbType.String, enumValue.WORK);
db.AddInParameter(cmdInsert, "@NOFINISHRESON", DbType.String, enumValue.NOFINISHRESON);
if (enumValue.STARTDATETIME == null)
{
db.AddInParameter(cmdInsert, "@STARTDATETIME", DbType.String, enumValue.STARTDATETIME);
}
else
{
if (enumValue.STARTDATETIME.ToString().IndexOf('T') > 1)
{
db.AddInParameter(cmdInsert, "@STARTDATETIME", DbType.String, enumValue.STARTDATETIME.ToString().Replace('T', ' '));
}
else
{
db.AddInParameter(cmdInsert, "@STARTDATETIME", DbType.String, enumValue.STARTDATETIME);
}
}
if (enumValue.PLANENDTIME == null)
{
db.AddInParameter(cmdInsert, "@PLANENDTIME", DbType.String, enumValue.PLANENDTIME);
}
else
{
if (enumValue.PLANENDTIME.ToString().IndexOf('T') > 1)
{
db.AddInParameter(cmdInsert, "@PLANENDTIME", DbType.String, enumValue.PLANENDTIME.ToString().Replace('T', ' '));
}
else
{
db.AddInParameter(cmdInsert, "@PLANENDTIME", DbType.String, enumValue.PLANENDTIME);
}
}
if (enumValue.ENDDATETIME == null)
{
db.AddInParameter(cmdInsert, "@ENDDATETIME", DbType.String, enumValue.ENDDATETIME);
}
else
{
if (enumValue.ENDDATETIME.ToString().IndexOf('T') > 1)
{
db.AddInParameter(cmdInsert, "@ENDDATETIME", DbType.String, enumValue.ENDDATETIME.ToString().Replace('T', ' '));
}
else
{
db.AddInParameter(cmdInsert, "@ENDDATETIME", DbType.String, enumValue.ENDDATETIME);
}
}
db.AddInParameter(cmdInsert, "@ENDOP", DbType.String, enumValue.ENDOP);
db.AddInParameter(cmdInsert, "@NEXTPLAN", DbType.String, enumValue.NEXTPLAN);
db.AddInParameter(cmdInsert, "@OTADVICE", DbType.String, enumValue.OTADVICE);
db.AddInParameter(cmdInsert, "@HELPOP", DbType.String, enumValue.HELPOP);
db.AddInParameter(cmdInsert, "@Remark", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@GID", DbType.String, strGID);
db.ExecuteNonQuery(cmdInsert, tran);
}
else {
cmdUpdate.Parameters.Clear();
StrGIDLIST = StrGIDLIST + ",'" + enumValue.GID+ "'";
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, headData.BSNO);
db.AddInParameter(cmdUpdate, "@SerialNo", DbType.Int32, enumValue.SerialNo);
db.AddInParameter(cmdUpdate, "@OPField", DbType.String, headData.OPFIELD);
db.AddInParameter(cmdUpdate, "@STATUS", DbType.String, enumValue.STATUS);
db.AddInParameter(cmdUpdate, "@WORK", DbType.String, enumValue.WORK);
db.AddInParameter(cmdUpdate, "@NOFINISHRESON", DbType.String, enumValue.NOFINISHRESON);
if (enumValue.STARTDATETIME == null)
{
db.AddInParameter(cmdUpdate, "@STARTDATETIME", DbType.String, enumValue.STARTDATETIME);
}
else
{
if (enumValue.STARTDATETIME.ToString().IndexOf('T') > 1)
{
db.AddInParameter(cmdUpdate, "@STARTDATETIME", DbType.String, enumValue.STARTDATETIME.ToString().Replace('T', ' '));
}
else
{
db.AddInParameter(cmdUpdate, "@STARTDATETIME", DbType.String, enumValue.STARTDATETIME);
}
}
if (enumValue.PLANENDTIME == null)
{
db.AddInParameter(cmdUpdate, "@PLANENDTIME", DbType.String, enumValue.PLANENDTIME);
}
else
{
if (enumValue.PLANENDTIME.ToString().IndexOf('T') > 1)
{
db.AddInParameter(cmdUpdate, "@PLANENDTIME", DbType.String, enumValue.PLANENDTIME.ToString().Replace('T', ' '));
}
else
{
db.AddInParameter(cmdUpdate, "@PLANENDTIME", DbType.String, enumValue.PLANENDTIME);
}
}
if (enumValue.ENDDATETIME == null)
{
db.AddInParameter(cmdUpdate, "@ENDDATETIME", DbType.String, enumValue.ENDDATETIME);
}
else
{
if (enumValue.ENDDATETIME.ToString().IndexOf('T') > 1)
{
db.AddInParameter(cmdUpdate, "@ENDDATETIME", DbType.String, enumValue.ENDDATETIME.ToString().Replace('T', ' '));
}
else
{
db.AddInParameter(cmdUpdate, "@ENDDATETIME", DbType.String, enumValue.ENDDATETIME);
}
}
db.AddInParameter(cmdUpdate, "@ENDOP", DbType.String, enumValue.ENDOP);
db.AddInParameter(cmdUpdate, "@NEXTPLAN", DbType.String, enumValue.NEXTPLAN);
db.AddInParameter(cmdUpdate, "@OTADVICE", DbType.String, enumValue.OTADVICE);
db.AddInParameter(cmdUpdate, "@HELPOP", DbType.String, enumValue.HELPOP);
db.AddInParameter(cmdUpdate, "@Remark", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
StrGIDLIST = StrGIDLIST + ")";
var cmdDelete = db.GetSqlStringCommand("delete from op_apply_service_detail where BSNO=@BSNO AND OPField=@OPField AND GID NOT IN " + StrGIDLIST);
db.AddInParameter(cmdDelete, "@BSNO", DbType.String, headData.BSNO);
db.AddInParameter(cmdDelete, "@OPField", DbType.String, headData.OPFIELD);
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
static public List<MsOpApplyServiceView> GetDataViewList(string strCondition, string userid, string username, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, username, companyid);
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("S.BSNO,S.OPField,S.STATUS,S.OP,S.INPUTBY,S.SERVICE,S.STARTDATETIME,S.PLANENDTIME");
strSql.Append(",S.ENDDATETIME,S.ENDOP,S.GID,S.Remark");
strSql.Append(",(SELECT SERVICENAME from code_op_service where OPField=S.OPField AND OPTYPE='5') AS SERVICETYPE ");
strSql.Append(",A.BsStatus,A.FeeStatus,A.BsDate,A.AccDate,A.Mblno,A.CustNo");
strSql.Append(",A.CustomerName,A.BsType,A.Vessel,A.VoyNo,A.ETD,A.ETA,A.PORTLOAD,A.PORTDISCHARGE");
strSql.Append(",A.INPUTBY AS AINPUTBY,A.OP AS AOP,A.SALE,A.CUSTOMSER,A.BSSOURCE,A.BSSOURCEDETAIL");
strSql.Append(",A.CORPID,A.SALEDEPT,A.PKGS,A.KGS,A.NETWEIGHT,A.CBM");
strSql.Append(",A.CUSTOMNO,A.CUSTOMDATE,A.INSPECTIONNO,A.INSPECTIONDATE,A.INVNO,A.CONTRACTNO,A.ARCOUNTRY,A.GOODSOURCE");
strSql.Append(",A.DOCNO,A.TRADETYPE,A.BOOKNO,A.BYCUSTOM,A.ENTERPID,A.ENTERP");
strSql.Append(",(CASE A.BsStatus WHEN 1 THEN '已锁定' else '未锁定' end) as bsstatusref ");
strSql.Append(",(CASE A.FeeStatus WHEN 1 THEN '已锁定' else '未锁定' end) as feestatusref ");
strSql.Append(" from op_apply_service s left join OP_APPLY A on (s.bsno=A.bsno) ");
strSql.Append(" left join op_apply_service_detail d on (d.bsno=A.bsno and d.OPField=s.OPField) ");
strSql.Append(" where d.HELPOP='" + username + "' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("UNION ");
strSql.Append("SELECT ");
strSql.Append("S.BSNO,S.OPField,S.STATUS,S.OP,S.INPUTBY,S.SERVICE,S.STARTDATETIME,S.PLANENDTIME");
strSql.Append(",S.ENDDATETIME,S.ENDOP,S.GID,S.Remark");
strSql.Append(",(SELECT SERVICENAME from code_op_service where OPField=S.OPField AND OPTYPE='5') AS SERVICETYPE ");
strSql.Append(",A.BsStatus,A.FeeStatus,A.BsDate,A.AccDate,A.Mblno,A.CustNo");
strSql.Append(",A.CustomerName,A.BsType,A.Vessel,A.VoyNo,A.ETD,A.ETA,A.PORTLOAD,A.PORTDISCHARGE");
strSql.Append(",A.INPUTBY AS AINPUTBY,A.OP AS AOP,A.SALE,A.CUSTOMSER,A.BSSOURCE,A.BSSOURCEDETAIL");
strSql.Append(",A.CORPID,A.SALEDEPT,A.PKGS,A.KGS,A.NETWEIGHT,A.CBM");
strSql.Append(",A.CUSTOMNO,A.CUSTOMDATE,A.INSPECTIONNO,A.INSPECTIONDATE,A.INVNO,A.CONTRACTNO,A.ARCOUNTRY,A.GOODSOURCE");
strSql.Append(",A.DOCNO,A.TRADETYPE,A.BOOKNO,A.BYCUSTOM,A.ENTERPID,A.ENTERP");
strSql.Append(",(CASE A.BsStatus WHEN 1 THEN '已锁定' else '未锁定' end) as bsstatusref ");
strSql.Append(",(CASE A.FeeStatus WHEN 1 THEN '已锁定' else '未锁定' end) as feestatusref ");
strSql.Append(" from op_apply_service s left join OP_APPLY A on (s.bsno=A.bsno) ");
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and A.bsno is not null ";
}
else
{
strCondition = " A.bsno is not null ";
}
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 S.OPField");
}
return SetViewData(strSql);
}
static public MsOpApplyServiceView GetViewData(string condition, string userid, string usercode, string orgcode)
{
var list = GetDataViewList(condition, userid, usercode, orgcode);
if (list.Count > 0)
return list[0];
return new MsOpApplyServiceView();
}
private static List<MsOpApplyServiceView> SetViewData(StringBuilder strSql)
{
var headList = new List<MsOpApplyServiceView>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpApplyServiceView data = new MsOpApplyServiceView();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.OPFIELD = Convert.ToString(reader["OPField"]);
data.STATUS = Convert.ToString(reader["STATUS"]);
if (reader["STARTDATETIME"] != DBNull.Value)
data.STARTDATETIME = Convert.ToString(reader["STARTDATETIME"]);
if (reader["PLANENDTIME"] != DBNull.Value)
data.PLANENDTIME = Convert.ToString(reader["PLANENDTIME"]);
if (reader["ENDDATETIME"] != DBNull.Value)
data.ENDDATETIME = Convert.ToString(reader["ENDDATETIME"]);
data.OP = Convert.ToString(reader["OP"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.SERVICE = Convert.ToString(reader["SERVICE"]);
data.ENDOP = Convert.ToString(reader["ENDOP"]);
data.GID = Convert.ToString(reader["GID"]);
data.REMARK = Convert.ToString(reader["Remark"]);
data.SERVICETYPE = Convert.ToString(reader["SERVICETYPE"]);
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
data.FEESTATUS = Convert.ToBoolean(reader["FEESTATUS"]);
data.BSSTATUSREF = Convert.ToString(reader["BSSTATUSREF"]);
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
if (reader["BSDATE"] != DBNull.Value)
data.BSDATE = Convert.ToDateTime(reader["BSDATE"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.ETA = Convert.ToString(reader["ETA"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.BSTYPE = Convert.ToString(reader["BSTYPE"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.AINPUTBY = Convert.ToString(reader["AINPUTBY"]);
data.AOP = Convert.ToString(reader["AOP"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.CUSTOMSER = Convert.ToString(reader["CUSTOMSER"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.SALEDEPT = Convert.ToString(reader["SALEDEPT"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMDATE = Convert.ToString(reader["CUSTOMDATE"]);
data.INSPECTIONNO = Convert.ToString(reader["INSPECTIONNO"]);
data.INSPECTIONDATE = Convert.ToString(reader["INSPECTIONDATE"]);
data.INVNO = Convert.ToString(reader["INVNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.ARCOUNTRY = Convert.ToString(reader["ARCOUNTRY"]);
data.GOODSOURCE = Convert.ToString(reader["GOODSOURCE"]);
data.DOCNO = Convert.ToString(reader["DOCNO"]);
data.TRADETYPE = Convert.ToString(reader["TRADETYPE"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.BOOKNO = Convert.ToString(reader["BOOKNO"]);
data.BYCUSTOM = Convert.ToString(reader["BYCUSTOM"]);
data.ENTERPID = Convert.ToString(reader["ENTERPID"]);
data.ENTERP = Convert.ToString(reader["ENTERP"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region 参照部分
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modOpApplyService' 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 = "S.OP='" + username + "'";
}
else if (visiblerange == "3")
{
str = "S.OP='" + username + "'";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " S.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))";
}
else if (visiblerange == "1")
{
str = " S.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')) ";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
return str;
}
#endregion
}
}