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.
398 lines
16 KiB
C#
398 lines
16 KiB
C#
|
|
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.MsCodeOpService;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.EntityDA;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeOpServiceDAL
|
|
{
|
|
public class MsCodeOpServiceDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<MsCodeOpService> GetDataList(string strCondition)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("OS_ID,OPField,CORPID,SERVICENAME,OPTYPE,REMARK,SORT,ENAME");
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96005 and EnumValueID=code_op_service.OPTYPE) as OPTYPESTR");
|
|
strSql.Append(" from code_op_service ");
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
|
|
strSql.Append(" order by OPTYPE,SORT,OPField");
|
|
|
|
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public MsCodeOpService GetData(string condition)
|
|
{
|
|
var list = GetDataList(condition);
|
|
if (list.Count > 0)
|
|
return list[0];
|
|
|
|
return new MsCodeOpService();
|
|
}
|
|
|
|
|
|
private static List<MsCodeOpService> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<MsCodeOpService>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsCodeOpService data = new MsCodeOpService();
|
|
#region Set DB data to Object
|
|
data.OS_ID = Convert.ToString(reader["OS_ID"]);
|
|
data.OPField = Convert.ToString(reader["OPField"]);
|
|
data.CORPID = Convert.ToString(reader["CORPID"]);
|
|
data.SERVICENAME = Convert.ToString(reader["SERVICENAME"]);
|
|
data.ENAME = Convert.ToString(reader["ENAME"]);
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
data.OPTYPESTR = Convert.ToString(reader["OPTYPESTR"]);
|
|
data.REMARK = Convert.ToString(reader["Remark"]);
|
|
if (reader["SORT"] != DBNull.Value)
|
|
data.SORT = Convert.ToInt32(reader["SORT"]);
|
|
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
|
|
static public List<MsCodeOpService> GetDataCtnList(string strCondition)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("OS_ID,OPField,CORPID,SERVICENAME,OPTYPE,REMARK,'' as OPTYPESTR,ENAME");
|
|
strSql.Append(" from code_op_service ");
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
|
|
strSql.Append(" UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR1' OS_ID,'CNTR1' OPField,'' CORPID,CNT1 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT1 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR2' OS_ID,'CNTR2' OPField,'' CORPID,CNT2 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT2 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR3' OS_ID,'CNTR3' OPField,'' CORPID,CNT3 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT3 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR4' OS_ID,'CNTR4' OPField,'' CORPID,CNT4 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT4 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR5' OS_ID,'CNTR5' OPField,'' CORPID,CNT5 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT5 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR6' OS_ID,'CNTR6' OPField,'' CORPID,CNT6 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT6 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR7' OS_ID,'CNTR7' OPField,'' CORPID,CNT7 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT7 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR9' OS_ID,'CNTR9' OPField,'' CORPID,CNT9 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT9 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR8' OS_ID,'CNTR8' OPField,'' CORPID,CNT8 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT8 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
strSql.Append("UNION SELECT TOP 1");
|
|
strSql.Append("'CNTR10' OS_ID,'CNTR10' OPField,'' CORPID,CNT10 SERVICENAME,'' OPTYPE,'' REMARK,'' as OPTYPESTR,CNT10 ENAME");
|
|
strSql.Append(" from code_ctn_disp ");
|
|
|
|
|
|
return SetCtnData(strSql);
|
|
}
|
|
|
|
private static List<MsCodeOpService> SetCtnData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<MsCodeOpService>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
if (Convert.ToString(reader["SERVICENAME"]) != "")
|
|
{
|
|
MsCodeOpService data = new MsCodeOpService();
|
|
#region Set DB data to Object
|
|
data.OS_ID = Convert.ToString(reader["OS_ID"]);
|
|
data.OPField = Convert.ToString(reader["OPField"]);
|
|
data.CORPID = Convert.ToString(reader["CORPID"]);
|
|
data.SERVICENAME = Convert.ToString(reader["SERVICENAME"]);
|
|
data.ENAME = Convert.ToString(reader["ENAME"]);
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
data.OPTYPESTR = Convert.ToString(reader["OPTYPESTR"]);
|
|
data.REMARK = Convert.ToString(reader["Remark"]);
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
|
|
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 明细表
|
|
|
|
static public List<MsCodeOpServiceDetail> GetBodyList(string strCondition)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("OS_ID,SerialNo,NAME,WORKLOAD,Remark");
|
|
strSql.Append(" from code_op_service_detail ");
|
|
if (strCondition.Trim() != String.Empty)
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
return SetBodyData(strSql);
|
|
}
|
|
|
|
private static List<MsCodeOpServiceDetail> SetBodyData(StringBuilder strSql)
|
|
{
|
|
var bodyList = new List<MsCodeOpServiceDetail>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsCodeOpServiceDetail data = new MsCodeOpServiceDetail();
|
|
#region Set DB data to Object
|
|
data.OS_ID = Convert.ToString(reader["OS_ID"]);
|
|
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
if (reader["WORKLOAD"] != DBNull.Value)
|
|
data.WORKLOAD = Convert.ToDecimal(reader["WORKLOAD"]);
|
|
data.REMARK = Convert.ToString(reader["Remark"]);
|
|
|
|
|
|
#endregion
|
|
|
|
bodyList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
return bodyList;
|
|
}
|
|
|
|
|
|
static public List<MsCodeOpServiceDetail> GetWorkList(string strCondition)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("OS_ID,SerialNo,NAME,WORKLOAD,FEENAME,Remark");
|
|
strSql.Append(" from code_op_service_work ");
|
|
if (strCondition.Trim() != String.Empty)
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
return SetworkData(strSql);
|
|
}
|
|
|
|
private static List<MsCodeOpServiceDetail> SetworkData(StringBuilder strSql)
|
|
{
|
|
var bodyList = new List<MsCodeOpServiceDetail>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsCodeOpServiceDetail data = new MsCodeOpServiceDetail();
|
|
#region Set DB data to Object
|
|
data.OS_ID = Convert.ToString(reader["OS_ID"]);
|
|
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
if (reader["WORKLOAD"] != DBNull.Value)
|
|
data.WORKLOAD = Convert.ToDecimal(reader["WORKLOAD"]);
|
|
data.REMARK = Convert.ToString(reader["Remark"]);
|
|
data.FEENAME = Convert.ToString(reader["FEENAME"]);
|
|
|
|
|
|
#endregion
|
|
|
|
bodyList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
return bodyList;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 参照部分
|
|
/*
|
|
public static string GetRangDAStr(string tb, string userid, string usercode, string orgcode)
|
|
{
|
|
string str = "";
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
|
|
strSql.Append(" from VW_User_Authority ");
|
|
strSql.Append(" where [NAME]='modTruckBulk' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
string visiblerange = "4";
|
|
string operaterange = "4";
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
break;
|
|
}
|
|
reader.Close();
|
|
}
|
|
if (visiblerange == "4")
|
|
{
|
|
str = "1=2";
|
|
}
|
|
else if (visiblerange == "3")
|
|
{
|
|
if (tb == "index")
|
|
{
|
|
str = " (UserCode='" + usercode + "' or SalesCode='" + usercode + "')";
|
|
}
|
|
else
|
|
{
|
|
str = " UPPER(OrgCode)='" + orgcode + "'";
|
|
}
|
|
}
|
|
else if (visiblerange == "2")
|
|
{
|
|
if (tb == "index")
|
|
{
|
|
var rangeDa = new RangeDA();
|
|
var companyid = rangeDa.GetCORPID(userid);
|
|
var deptname = rangeDa.GetDEPTNAME(userid);
|
|
str = " (UserCode in (select codename from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
|
|
+ " or SalesCode in (select codename 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
|
|
{
|
|
str = " UPPER(OrgCode)='" + orgcode + "'";
|
|
}
|
|
|
|
}
|
|
else if (visiblerange == "1")
|
|
{
|
|
str = " UPPER(OrgCode)='" + orgcode + "'";
|
|
}
|
|
|
|
return str;
|
|
}
|
|
*/
|
|
public static DBResult SaveDetail(MsCodeOpService headData, List<MsCodeOpServiceDetail> bodyList,List<MsCodeOpServiceDetail> workList)
|
|
{
|
|
var result = new DBResult();
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (var conn = db.CreateConnection())
|
|
{
|
|
conn.Open();
|
|
var tran = conn.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from code_op_service_detail where OS_ID='" +headData.OS_ID+ "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
var cmdDeletework = db.GetSqlStringCommand("delete from code_op_service_work where OS_ID='" + headData.OS_ID + "'");
|
|
db.ExecuteNonQuery(cmdDeletework, tran);
|
|
|
|
|
|
var cmdInsert =
|
|
db.GetSqlStringCommand(
|
|
@"insert into code_op_service_detail (OS_ID, SerialNo, NAME,WORKLOAD,REMARK)
|
|
values (@OS_ID, @SerialNo, @NAME,@WORKLOAD,@REMARK) ");
|
|
|
|
if (bodyList!=null)
|
|
{
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
cmdInsert.Parameters.Clear();
|
|
|
|
db.AddInParameter(cmdInsert, "@OS_ID", DbType.String, headData.OS_ID);
|
|
db.AddInParameter(cmdInsert, "@SerialNo", DbType.Int32, enumValue.SerialNo);
|
|
db.AddInParameter(cmdInsert, "@NAME", DbType.String, enumValue.NAME);
|
|
db.AddInParameter(cmdInsert, "@WORKLOAD", DbType.Decimal, enumValue.WORKLOAD);
|
|
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
|
|
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
}
|
|
if (workList != null)
|
|
{
|
|
|
|
var cmdInsertwork =
|
|
db.GetSqlStringCommand(
|
|
@"insert into code_op_service_work (OS_ID, SerialNo, NAME,WORKLOAD,REMARK,FEENAME)
|
|
values (@OS_ID, @SerialNo, @NAME,@WORKLOAD, @REMARK,@FEENAME) ");
|
|
|
|
foreach (var enumValue in workList)
|
|
{
|
|
cmdInsertwork.Parameters.Clear();
|
|
|
|
db.AddInParameter(cmdInsertwork, "@OS_ID",DbType.String, headData.OS_ID);
|
|
db.AddInParameter(cmdInsertwork, "@SerialNo", DbType.Int32, enumValue.SerialNo);
|
|
db.AddInParameter(cmdInsertwork, "@NAME", DbType.String, enumValue.NAME);
|
|
db.AddInParameter(cmdInsertwork, "@WORKLOAD", DbType.Decimal, enumValue.WORKLOAD);
|
|
db.AddInParameter(cmdInsertwork, "@REMARK", DbType.String, enumValue.REMARK);
|
|
db.AddInParameter(cmdInsertwork, "@FEENAME", DbType.String, enumValue.FEENAME);
|
|
|
|
db.ExecuteNonQuery(cmdInsertwork, tran);
|
|
}
|
|
}
|
|
tran.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
tran.Rollback();
|
|
|
|
result.Success = false;
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Message = "保存成功";
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|