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/MvcContainer/DAL/MsCodeMsds/MsCodeMsdsDAL.cs

515 lines
19 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcContainer.Models.MsCodeMsds;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcContainer.DAL.MsCodeMsds
{
public class MsCodeMsdsDAL
{
#region Inquery DataList
static public List<CodeMSDS> GetDataList(string strCondition, string companyid, string sort = null)
{
//var rangstr = " COMPANYID='" + companyid + "'";
//if (!string.IsNullOrEmpty(rangstr))
//{
// if (!string.IsNullOrEmpty(strCondition))
// {
// strCondition = strCondition + " and " + rangstr;
// }
// else
// {
// strCondition = rangstr;
// }
//}
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[GOODNAME],[TRADEGOODSNAME],CHEMICALGOODSNAME,CHEMICALCGOODSNAME,CASNO,[UNNO],[DCLASS],SDCLASS,PACKINGGROUP");
strSql.Append(",ISPOLLUTEOCEAN,[MELTINGPOINTB],[BOILINGPOINTB],[FLASHPOINTB],[MELTINGPOINTE],[BOILINGPOINTE],[FLASHPOINTE],ISDANGEROUS");
strSql.Append(",[DENSITY],[PH],[STABILITY],REACTIVE,[IMDG],[REMARKS],[INPUTBY],[INPUTTIME],[COMPANYID]");
strSql.Append(",(select ShowName from [user] where GID=code_msds.INPUTBY) as INPUTBYREF");
strSql.Append(",CHEMICALCGOODSNAME+ '-' + GOODNAME AS CodeAndName");
strSql.Append(" from code_msds ");
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 GOODNAME");
}
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string companyid, string sort = null)
{
var rangstr = " COMPANYID='" + companyid + "'";
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[GOODNAME],[TRADEGOODSNAME],CHEMICALGOODSNAME,CHEMICALCGOODSNAME,CASNO,[UNNO],[DCLASS],SDCLASS,PACKINGGROUP");
strSql.Append(",ISPOLLUTEOCEAN,[MELTINGPOINTB],[BOILINGPOINTB],[FLASHPOINTB],[MELTINGPOINTE],[BOILINGPOINTE],[FLASHPOINTE],ISDANGEROUS");
strSql.Append(",[DENSITY],[PH],[STABILITY],REACTIVE,[IMDG],[REMARKS],[INPUTBY],[INPUTTIME],[COMPANYID]");
strSql.Append(",(select ShowName from [user] where GID=code_msds.INPUTBY) as INPUTBYREF");
strSql.Append(",CHEMICALCGOODSNAME+ '-' + GOODNAME AS CodeAndName");
strSql.Append(" from code_msds ");
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 GOODNAME");
}
return strSql.ToString();
}
static public CodeMSDS GetData(string condition, string companyid)
{
CodeMSDS data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeMSDS();
data.COMPANYID = companyid;
}
return data;
}
private static List<CodeMSDS> SetData(StringBuilder strSql)
{
var headList = new List<CodeMSDS>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeMSDS data = new CodeMSDS();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.GOODNAME = Convert.ToString(reader["GOODNAME"]);
data.TRADEGOODSNAME = Convert.ToString(reader["TRADEGOODSNAME"]);
data.CHEMICALGOODSNAME = Convert.ToString(reader["CHEMICALGOODSNAME"]);
data.CHEMICALCGOODSNAME = Convert.ToString(reader["CHEMICALCGOODSNAME"]);
data.CASNO = Convert.ToString(reader["CASNO"]);
data.UNNO = Convert.ToString(reader["UNNO"]);
data.DCLASS = Convert.ToString(reader["DCLASS"]);
data.SDCLASS = Convert.ToString(reader["SDCLASS"]);
data.PACKINGGROUP = Convert.ToString(reader["PACKINGGROUP"]);
if (reader["ISPOLLUTEOCEAN"] != DBNull.Value)
data.ISPOLLUTEOCEAN = Convert.ToBoolean(reader["ISPOLLUTEOCEAN"]);
data.MELTINGPOINTB = Convert.ToString(reader["MELTINGPOINTB"]);
data.BOILINGPOINTB = Convert.ToString(reader["BOILINGPOINTB"]);
data.FLASHPOINTB = Convert.ToString(reader["FLASHPOINTB"]);
data.MELTINGPOINTE = Convert.ToString(reader["MELTINGPOINTE"]);
data.BOILINGPOINTE = Convert.ToString(reader["BOILINGPOINTE"]);
data.FLASHPOINTE = Convert.ToString(reader["FLASHPOINTE"]);
data.DENSITY = Convert.ToString(reader["DENSITY"]);
data.PH = Convert.ToString(reader["PH"]);
data.STABILITY = Convert.ToString(reader["STABILITY"]);
data.REACTIVE = Convert.ToString(reader["REACTIVE"]);
data.IMDG = Convert.ToString(reader["IMDG"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.GOODNAMEANDCNAME = Convert.ToString(reader["CodeAndName"]);
if (reader["ISDANGEROUS"] != DBNull.Value)
data.ISDANGEROUS = Convert.ToBoolean(reader["ISDANGEROUS"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteCodeMSDS(List<CodeMSDS> 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_msds 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;
}
#endregion
#region MSDS FACTRY
static public List<CodeMSDSFactry> GetFactryList(string strCondition,string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[MSDSID],[FACTORYNAME],[CUSTOMERNAME],[FACTORYADDR],[CONSIGNEE],[CONSIGNEEADDR]");
strSql.Append(",[REMARKS],[INPUTBY],[INPUTTIME],[LINKTEL],[SALE]");
strSql.Append(",(select ShowName from [user] where GID=code_msds_factry.INPUTBY) as INPUTBYREF");
strSql.Append(" from code_msds_factry ");
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 INPUTTIME");
}
return SetFactryData(strSql);
}
static public CodeMSDSFactry GetFactryData(string condition)
{
CodeMSDSFactry data = null;
var list = GetFactryList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeMSDSFactry();
}
return data;
}
private static List<CodeMSDSFactry> SetFactryData(StringBuilder strSql)
{
var headList = new List<CodeMSDSFactry>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeMSDSFactry data = new CodeMSDSFactry();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.MSDSID = Convert.ToString(reader["MSDSID"]);
data.FACTORYNAME = Convert.ToString(reader["FACTORYNAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.FACTORYADDR = Convert.ToString(reader["FACTORYADDR"]);
data.CONSIGNEE = Convert.ToString(reader["CONSIGNEE"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
data.LINKTEL = Convert.ToString(reader["LINKTEL"]);
data.SALE = Convert.ToString(reader["SALE"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region MSDS REJECTION
static public List<CodeMSDSRejection> GetRejectionList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[MSDSID],[REJECTID],[REMARKS],[INPUTBY],[INPUTTIME]");
strSql.Append(",(select CHEMICALCGOODSNAME+ '-' + GOODNAME from code_msds where GID=code_msds_rejection.REJECTID) GOODNAME");
strSql.Append(",(select ShowName from [user] where GID=code_msds_rejection.INPUTBY) as INPUTBYREF");
strSql.Append(" from code_msds_rejection ");
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 INPUTTIME DESC");
}
return SetRejectionData(strSql);
}
private static List<CodeMSDSRejection> SetRejectionData(StringBuilder strSql)
{
var headList = new List<CodeMSDSRejection>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeMSDSRejection data = new CodeMSDSRejection();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.MSDSID = Convert.ToString(reader["MSDSID"]);
data.REJECTID = Convert.ToString(reader["REJECTID"]);
data.GOODNAME = Convert.ToString(reader["GOODNAME"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SaveDetail(List<CodeMSDSRejection> bodyList, string PID,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_msds_rejection (GID,MSDSID,REJECTID,INPUTBY,INPUTTIME)
values (@GID,@MSDSID,@REJECTID,@INPUTBY,@INPUTTIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update code_msds_factry set REJECTID=@REJECTID 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, "@MSDSID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@REJECTID", DbType.String, enumValue.REJECTID);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String,userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@REJECTID", DbType.String, enumValue.REJECTID);
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 DeleteRejectionDetail(List<CodeMSDSRejection> 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_msds_rejection 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 DeletefactryDetail(List<CodeMSDSFactry> 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_msds_factry 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;
}
}
}