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/WMSRate/WMSRateDAL.cs

143 lines
7.3 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.WMSRate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.DAL.WMSRateDAL
{
public class WMSRateDAL
{
#region 查询
static public List<WMSRate> GetDataList(string strCondition, string userid, string usercode, string companyid,string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("SELECT *,FEETYPENAME=(case when FEETYPE=1 then '收' else '付' end) from wms_rate where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CUSTOMERNAME,MODIFIEDTIME");
}
return SetData(strSql);
}
static public WMSRate GetData(string condition, string companyid, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
var strSql = new StringBuilder();
strSql.Append("SELECT *,FEETYPENAME=(case when FEETYPE=1 then '收' else '付' end) from wms_rate where 1=1");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new WMSRate();
}
private static List<WMSRate> SetData(StringBuilder strSql)
{
var headList = new List<WMSRate>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WMSRate data = new WMSRate();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//GID
data.FEEGRADE = (reader["FEEGRADE"] == null ? 0 : Convert.ToInt32(reader["FEEGRADE"]));//FEEGRADE
data.FEESCALE = (reader["FEESCALE"] == null ? 0 : Convert.ToInt32(reader["FEESCALE"]));//FEESCALE
data.FEEPRICE = (reader["FEEPRICE"] == null ? 0 : Convert.ToDecimal(reader["FEEPRICE"]));//FEEPRICE
data.FEEUNIT = (reader["FEEUNIT"] == null ? "" : Convert.ToString(reader["FEEUNIT"]));//FEEUNIT
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//CREATEUSER
if (reader["CREATETIME"] != null && reader["CREATETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CREATETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CREATETIME"].ToString().Trim() != "")
{
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
}
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//MODIFIEDUSER
if (reader["MODIFIEDTIME"] != null && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME"].ToString().Trim() != "")
{
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更新操作时间
}
data.REMARK = (reader["REMARK"] == null ? "" : Convert.ToString(reader["REMARK"]));//REMARK
data.BSNO = (reader["BSNO"] == null ? "" : Convert.ToString(reader["BSNO"]));//BSNO
data.CUSTOMERNAME = (reader["CUSTOMERNAME"] == null ? "" : Convert.ToString(reader["CUSTOMERNAME"]));//CUSTOMERNAME
data.FEETYPE = (reader["FEETYPE"] == null ? 0 : Convert.ToInt32(reader["FEETYPE"]));//FEETYPE
//if (reader["ENDBILLINGDATE"] != null && reader["ENDBILLINGDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["ENDBILLINGDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["ENDBILLINGDATE"].ToString().Trim() != "")
//{
// data.ENDBILLINGDATE = Convert.ToDateTime(reader["ENDBILLINGDATE"]);//ENDBILLINGDATE
//}
if (reader["ENDBILLINGDATE"] != null && reader["ENDBILLINGDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["ENDBILLINGDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["ENDBILLINGDATE"].ToString().Trim() != "")
{
data.ENDBILLINGDATE = Convert.ToDateTime(reader["ENDBILLINGDATE"]).ToString("yyyy-MM-dd");//ENDBILLINGDATE
}
else
{
data.ENDBILLINGDATE = "";//ENDBILLINGDATE
}
data.ADDPRICE = (reader["ADDPRICE"] == null ? 0 : Convert.ToDecimal(reader["ADDPRICE"]));//ADDPRICE
data.RATETYPE = (reader["RATETYPE"] == null ? 0 : Convert.ToInt32(reader["RATETYPE"]));//RATETYPE
data.FEENAME = (reader["FEENAME"] == null ? "" : Convert.ToString(reader["FEENAME"]));//FEENAME
data.ISCHANGE = (reader["ISCHANGE"] == null ? false : Convert.ToBoolean(reader["ISCHANGE"]));//ISCHANGE
data.CAPPRICE = (reader["CAPPRICE"] == null ? 0 : Convert.ToDecimal(reader["CAPPRICE"]));//CAPPRICE
data.FEETYPENAME = (reader["FEETYPENAME"] == null ? "" : Convert.ToString(reader["FEETYPENAME"]));//收费类型
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 删除
public static DBResult Delete(WMSRate head, string strUSERID)
{
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 wms_rate where GID='" + head.GID.ToString().Trim() + "'");
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
}
}