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/EntityDA/wmsfeeCodeDA.cs

394 lines
16 KiB
C#

2 years ago
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
/// <summary>
/// 数据访问类:wmsfeeCodeDA
/// </summary>
public class WmsFeeCodeDA
{
public WmsFeeCodeDA()
{}
#region Method
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(string GID)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from wms_feeCode");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
try
{
return bool.Parse(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters).ToString());
}
catch
{
return false;
}
}
}
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(WmsFeeCodeEntity model)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into wms_feeCode(");
strSql.Append("GID,FEETYPE,FEENAME,BSNO,UNIT,CURRENCY,UNITPRICE,EXCHANGERATE,CREATEUSER,CREATETIME,REMARK)");
strSql.Append(" values (");
strSql.Append("@GID,@FEETYPE,@FEENAME,@BSNO,@UNIT,@CURRENCY,@UNITPRICE,@EXCHANGERATE,@CREATEUSER,getdate(),@REMARK)");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36),
new SqlParameter("@FEETYPE", SqlDbType.Int,4),
new SqlParameter("@FEENAME", SqlDbType.VarChar,100),
new SqlParameter("@BSNO", SqlDbType.VarChar,100),
new SqlParameter("@UNIT", SqlDbType.VarChar,20),
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20),
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9),
new SqlParameter("@EXCHANGERATE", SqlDbType.Decimal,9),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36),
//new SqlParameter("@CREATETIME", SqlDbType.DateTime),
new SqlParameter("@REMARK", SqlDbType.VarChar,200)};
parameters[0].Value = model.GID;
parameters[1].Value = model.FEETYPE;
parameters[2].Value = model.FEENAME;
parameters[3].Value = model.BSNO;
parameters[4].Value = model.UNIT;
parameters[5].Value = model.CURRENCY;
parameters[6].Value = model.UNITPRICE;
parameters[7].Value = model.EXCHANGERATE;
parameters[8].Value = model.CREATEUSER;
//parameters[10].Value = model.CREATETIME;
parameters[9].Value = model.REMARK;
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(WmsFeeCodeEntity model)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update wms_feeCode set MODIFIEDTIME=getdate(),");
strSql.Append("FEETYPE=@FEETYPE,");
strSql.Append("FEENAME=@FEENAME,");
strSql.Append("BSNO=@BSNO,");
strSql.Append("UNIT=@UNIT,");
strSql.Append("CURRENCY=@CURRENCY,");
strSql.Append("UNITPRICE=@UNITPRICE,");
strSql.Append("EXCHANGERATE=@EXCHANGERATE,");
strSql.Append("MODIFIEDUSER=@MODIFIEDUSER,");
strSql.Append("REMARK=@REMARK");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36),
new SqlParameter("@FEETYPE", SqlDbType.Int,4),
new SqlParameter("@FEENAME", SqlDbType.VarChar,100),
new SqlParameter("@BSNO", SqlDbType.VarChar,100),
new SqlParameter("@UNIT", SqlDbType.VarChar,20),
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20),
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9),
new SqlParameter("@EXCHANGERATE", SqlDbType.Decimal,9),
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36),
new SqlParameter("@REMARK", SqlDbType.VarChar,200)};
parameters[0].Value = model.GID;
parameters[1].Value = model.FEETYPE;
parameters[2].Value = model.FEENAME;
parameters[3].Value = model.BSNO;
parameters[4].Value = model.UNIT;
parameters[5].Value = model.CURRENCY;
parameters[6].Value = model.UNITPRICE;
parameters[7].Value = model.EXCHANGERATE;
parameters[8].Value = model.MODIFIEDUSER;
parameters[9].Value = model.REMARK;
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(string GID)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from wms_feeCode ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 批量删除数据
/// </summary>
public bool DeleteList(string GIDlist)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from wms_feeCode ");
strSql.Append(" where GID in (" + GIDlist + ") ");
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public WmsFeeCodeEntity GetModel(string GID)
{
WmsFeeCodeEntity model = new WmsFeeCodeEntity();
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 GID,FEETYPE,FEENAME,BSNO,CLIENT,UNIT,CURRENCY,UNITPRICE,EXCHANGERATE,CREATEUSER,CREATETIME,REMARK from wms_feeCode ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
using(SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters))
{
try
{
while (sqlRead.Read())
{
if (sqlRead["GID"] != null && sqlRead["GID"].ToString() != "")
{
model.GID = sqlRead["GID"].ToString();
}
if (sqlRead["FEETYPE"] != null && sqlRead["FEETYPE"].ToString() != "")
{
model.FEETYPE = int.Parse(sqlRead["FEETYPE"].ToString());
}
if (sqlRead["FEENAME"] != null && sqlRead["FEENAME"].ToString() != "")
{
model.FEENAME = sqlRead["FEENAME"].ToString();
}
if (sqlRead["BSNO"] != null && sqlRead["BSNO"].ToString() != "")
{
model.BSNO = sqlRead["BSNO"].ToString();
}
if (sqlRead["CLIENT"] != null && sqlRead["CLIENT"].ToString() != "")
{
model.CLIENT = int.Parse(sqlRead["CLIENT"].ToString());
}
if (sqlRead["UNIT"] != null && sqlRead["UNIT"].ToString() != "")
{
model.UNIT = sqlRead["UNIT"].ToString();
}
if (sqlRead["CURRENCY"] != null && sqlRead["CURRENCY"].ToString() != "")
{
model.CURRENCY = sqlRead["CURRENCY"].ToString();
}
if (sqlRead["UNITPRICE"] != null && sqlRead["UNITPRICE"].ToString() != "")
{
model.UNITPRICE = decimal.Parse(sqlRead["UNITPRICE"].ToString());
}
if (sqlRead["EXCHANGERATE"] != null && sqlRead["EXCHANGERATE"].ToString() != "")
{
model.EXCHANGERATE = decimal.Parse(sqlRead["EXCHANGERATE"].ToString());
}
if (sqlRead["CREATEUSER"] != null && sqlRead["CREATEUSER"].ToString() != "")
{
model.CREATEUSER = sqlRead["CREATEUSER"].ToString();
}
if (sqlRead["CREATETIME"] != null && sqlRead["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(sqlRead["CREATETIME"].ToString());
}
if (sqlRead["REMARK"] != null && sqlRead["REMARK"].ToString() != "")
{
model.REMARK = sqlRead["REMARK"].ToString();
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID,FEETYPE,FEENAME,BSNO,CLIENT,UNIT,CURRENCY,UNITPRICE,EXCHANGERATE,CREATEUSER,CREATETIME,REMARK ");
strSql.Append(" FROM wms_feeCode ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" GID,FEETYPE,FEENAME,BSNO,CLIENT,UNIT,CURRENCY,UNITPRICE,EXCHANGERATE,CREATEUSER,CREATETIME,REMARK ");
strSql.Append(" FROM wms_feeCode ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获取记录总数
/// </summary>
public int GetRecordCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) FROM wms_feeCode ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
object obj = SqlHelper.GetSingle(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby);
}
else
{
strSql.Append("order by T.GID desc");
}
strSql.Append(")AS Row, T.* from wms_feeCode T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/*
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetList(int PageSize,int PageIndex,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = "wms_feeCode";
parameters[1].Value = "GID";
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = 0;
parameters[5].Value = 0;
parameters[6].Value = strWhere;
return SqlHelper.RunProcedure(SqlHelper.ConnectionStringLocalTransaction.ToString(), "UP_GetRecordByPage", parameters, "ds");
}*/
#region 根据SQL语句查询仓储费率数据集
/// <summary>
/// 根据SQL语句查询仓储费率数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetRateListByCondition(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
#endregion Method
}
}