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.

304 lines
12 KiB
C#

11 months ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcContainer.Models.MsCodeCtnTkFitings;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcContainer.DAL.MsCodeCtnTkFitings
{
public class MsCodeCtnTkFitingsDAL
{
#region Inquery DataList
static public List<CodeCtnTkFitings> GetDataList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,FITINGCODE,FITINGNAME,MODEL,ISXHP,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql.Append(",(select ShowName from [user] where GID=code_ctntkFiting.CREATEUSER) as CREATEUSERREF");
strSql.Append(",(select ShowName from [user] where GID=code_ctntkFiting.MODIFIEDUSER) as MODIFIEDUSERREF");
10 months ago
strSql.Append(",(FITINGCODE+'-'+FITINGNAME+'-'+MODEL) as FITINGFULL,ISLOCK,LOCKUSER");
11 months ago
strSql.Append(" from code_ctntkFiting ");
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 MODIFIEDTIME,FITINGCODE");
}
return SetData(strSql);
}
static public CodeCtnTkFitings GetData(string condition, string companyid)
{
CodeCtnTkFitings data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeCtnTkFitings();
}
return data;
}
private static List<CodeCtnTkFitings> SetData(StringBuilder strSql)
{
var headList = new List<CodeCtnTkFitings>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeCtnTkFitings data = new CodeCtnTkFitings();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.FITINGCODE = Convert.ToString(reader["FITINGCODE"]);
data.FITINGNAME = Convert.ToString(reader["FITINGNAME"]);
data.FITINGFULL = Convert.ToString(reader["FITINGFULL"]);
data.MODEL = Convert.ToString(reader["MODEL"]);
if (reader["ISXHP"] != DBNull.Value)
data.ISXHP = Convert.ToString(reader["ISXHP"]);
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");
data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd hh:mm:ss");
if (reader["ISLOCK"] != DBNull.Value)
data.ISLOCK = Convert.ToBoolean(reader["ISLOCK"]);
data.LOCKUSER = Convert.ToString(reader["LOCKUSER"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SaveDetail(List<CodeCtnTkFitings> bodyList, string userid, string companyid)
{
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_ctntkFiting (GID,FITINGCODE,FITINGNAME,MODEL,ISXHP,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME)
values (@GID,@FITINGCODE,@FITINGNAME,@MODEL,@ISXHP,@REMARK,@CREATEUSER,@CREATETIME,@MODIFIEDUSER,@MODIFIEDTIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update code_ctntkFiting set FITINGCODE=@FITINGCODE,FITINGNAME=@FITINGNAME,MODEL=@MODEL,ISXHP=@ISXHP,REMARK=@REMARK,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME 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, "@FITINGCODE", DbType.String, enumValue.FITINGCODE);
db.AddInParameter(cmdInsert, "@FITINGNAME", DbType.String, enumValue.FITINGNAME);
db.AddInParameter(cmdInsert, "@MODEL", DbType.String, enumValue.MODEL);
db.AddInParameter(cmdInsert, "@ISXHP", DbType.String, enumValue.ISXHP);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String,DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
if (!enumValue.ISLOCK)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@FITINGCODE", DbType.String, enumValue.FITINGCODE);
db.AddInParameter(cmdUpdate, "@FITINGNAME", DbType.String, enumValue.FITINGNAME);
db.AddInParameter(cmdUpdate, "@MODEL", DbType.String, enumValue.MODEL);
db.AddInParameter(cmdUpdate, "@ISXHP", DbType.String, enumValue.ISXHP);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeleteDetail(List<CodeCtnTkFitings> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from code_ctntkFiting where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult SetLock(List<CodeCtnTkFitings> billList, string userid, bool isstop)
{
var result = new DBResult();
var i = 0;
var mblno = "";
result.Success = true;
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var bill in billList)
{
if (isstop)
{
var cmdupdate = db.GetSqlStringCommand("update code_ctntkFiting set ISLOCK=1,LOCKUSER='" + userid + "' where GID=@GID");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@GID", DbType.String, bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
else {
var cmdupdate = db.GetSqlStringCommand("update code_ctntkFiting set ISLOCK=0,LOCKUSER='' where GID=@GID");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@GID", DbType.String, bill.GID);
db.ExecuteNonQuery(cmdupdate, tran);
}
}
if (result.Success == true)
{
result = new DBResult();
result.Success = true;
result.Message = "提交成功";
tran.Commit();
}
else
{
result.Success = true;
result.Message = "完成,其中" + i.ToString() + "票驳回错误,错误信息" + result.Message;
tran.Commit();
}
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
return result;
}
}
}