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/WmsStorageAreaDA.cs

227 lines
8.1 KiB
C#

2 years ago
using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.DataAccess;
using DSWeb.Models;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class WmsStorageAreaDA
{
public WmsStorageAreaDA()
{
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(WmsStorageAreaEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into wms_storage_area(");
strSql.Append("GID,AREACODE,AREANAME,CUSTOMERNAME");
strSql.Append(") values (");
strSql.Append("@GID,@AREACODE,@AREANAME,@CUSTOMERNAME");
strSql.Append(") ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@AREACODE", SqlDbType.VarChar,50) ,
new SqlParameter("@AREANAME", SqlDbType.VarChar,100) ,
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.AREACODE;
parameters[2].Value = model.AREANAME;
parameters[3].Value = model.CUSTOMERNAME;
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(WmsStorageAreaEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update wms_storage_area set ");
strSql.Append(" GID = @GID , ");
strSql.Append(" AREACODE = @AREACODE , ");
strSql.Append(" AREANAME = @AREANAME , ");
strSql.Append(" CUSTOMERNAME = @CUSTOMERNAME ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@AREACODE", SqlDbType.VarChar,50) ,
new SqlParameter("@AREANAME", SqlDbType.VarChar,100) ,
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.AREACODE;
parameters[2].Value = model.AREANAME;
parameters[3].Value = model.CUSTOMERNAME;
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新信息表','更新操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from wms_storage_area ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
//
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters);
iResult = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
iResult = -1;//有异常,删除失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public WmsStorageAreaEntity GetModel(string GID)
{
//初始化返回变量
WmsStorageAreaEntity model = null;
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID, AREACODE, AREANAME, CUSTOMERNAME ");
strSql.Append(" from wms_storage_area ");
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
{
model = new WmsStorageAreaEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0)) { model.GID = sqlRead.GetString(0); } // 唯一编码 newid()
if (!sqlRead.IsDBNull(1)) { model.AREACODE = sqlRead.GetString(1); } //
if (!sqlRead.IsDBNull(2)) { model.AREANAME = sqlRead.GetString(2); } //
if (!sqlRead.IsDBNull(3)) { model.CUSTOMERNAME = sqlRead.GetString(3); } //
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM wms_storage_area ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
//
}
}