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/TruckMng/DAL/MsCustTruckConsignee/MsCustTruckConsigneeDAL.cs

304 lines
12 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.TruckMng.Models.CodeTruckConsignee;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.DAL;
using System.Web;
namespace DSWeb.TruckMng.DAL.MsCustTruckConsignee
{
public class MsCustTruckConsigneeDAL
{
#region Inquery DataList
static public List<CodeTruckConsignee> GetDataList(string strCondition, string userid, string usercode, string orgcode, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,CONSIGNEENAME,CONSIGNEETEL,CONSIGNEEATTN,CONSIGNEEADDR,REMARK,CREATEUSER,CREATETIME,DISTPORT");
strSql.Append(",(select ShowName from [user] where GID=code_truck_consignee.CREATEUSER) as CREATEUSERREF");
strSql.Append(" from code_truck_consignee ");
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 CREATETIME DESC ");
}
return SetData(strSql);
}
static public CodeTruckConsignee GetData(string condition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,CONSIGNEENAME,CONSIGNEETEL,CONSIGNEEATTN,CONSIGNEEADDR,REMARK,CREATEUSER,CREATETIME,DISTPORT");
strSql.Append(",(select ShowName from [user] where GID=code_truck_consignee.CREATEUSER) as CREATEUSERREF");
strSql.Append(" from code_truck_consignee ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var list = SetData(strSql);
if (list.Count > 0)
{
return list[0];
}
return new CodeTruckConsignee();
}
private static List<CodeTruckConsignee> SetData(StringBuilder strSql)
{
var headList = new List<CodeTruckConsignee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeTruckConsignee data = new CodeTruckConsignee();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.DISTPORT = Convert.ToString(reader["DISTPORT"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 明细表
public static DBResult SaveDetail(List<CodeTruckConsignee> bodyList,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 code_truck_consignee (GID,CONSIGNEENAME,CONSIGNEETEL,CONSIGNEEATTN,CONSIGNEEADDR,REMARK,CREATEUSER,CREATETIME,DISTPORT)
values (@GID,@CONSIGNEENAME,@CONSIGNEETEL,@CONSIGNEEATTN,@CONSIGNEEADDR,@REMARK,@CREATEUSER,@CREATETIME,@DISTPORT) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update code_truck_consignee set CONSIGNEENAME=@CONSIGNEENAME,CONSIGNEETEL=@CONSIGNEETEL,CONSIGNEEATTN=@CONSIGNEEATTN,CONSIGNEEADDR=@CONSIGNEEADDR
,REMARK=@REMARK,DISTPORT=@DISTPORT where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@CONSIGNEENAME", DbType.String, enumValue.CONSIGNEENAME);
db.AddInParameter(cmdInsert, "@CONSIGNEETEL", DbType.String, enumValue.CONSIGNEETEL);
db.AddInParameter(cmdInsert, "@CONSIGNEEATTN", DbType.String, enumValue.CONSIGNEEATTN);
db.AddInParameter(cmdInsert, "@CONSIGNEEADDR", DbType.String, enumValue.CONSIGNEEADDR);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@DISTPORT", DbType.String, enumValue.DISTPORT);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString());
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@CONSIGNEENAME", DbType.String, enumValue.CONSIGNEENAME);
db.AddInParameter(cmdUpdate, "@CONSIGNEETEL", DbType.String, enumValue.CONSIGNEETEL);
db.AddInParameter(cmdUpdate, "@CONSIGNEEATTN", DbType.String, enumValue.CONSIGNEEATTN);
db.AddInParameter(cmdUpdate, "@CONSIGNEEADDR", DbType.String, enumValue.CONSIGNEEADDR);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@DISTPORT", DbType.String, enumValue.DISTPORT);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult DeleteDetail(CodeTruckConsignee headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmd = db.GetSqlStringCommand("delete from code_truck_consignee where GID='" + headData.GID + "'");
db.ExecuteNonQuery(cmd, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
#region 参照部分
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" Count(GID) AS CT ");
strSql.Append(" from Cust_Truck_feetemplate ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
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]='modCustTruckFeeTemplate' 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 = " CREATEUSER='" + userid + "'";
}
else
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
}
else if (visiblerange == "2")
{
if (tb == "index")
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
else
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
return str;
}
#endregion
}
}