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/MsCodeCtnTk/MsCodeCtnTkDAL.cs

1400 lines
61 KiB
C#

using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcContainer.Models.MsCodeCtnTk;
using HcUtility.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
namespace DSWeb.MvcContainer.DAL.MsCodeCtnTk
{
public class MsCodeCtnTkDAL
{
#region Inquery DataList
static public List<CodeCtnTk> GetDataList(int start, int limit, string strCondition, string companyid, out int totel, string sort = null)
{
var rangstr = "";
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by INPUTTIME DESC");
}
strSql.Append(@") as num ,* from (");
strSql.Append("select c.GID,c.CTNNO,c.CTNPROP,c.NAMEPLATE,c.OWNERCTN,c.MADEDATE,c.MADEFACTORY,c.TANKWALLTHICK");
strSql.Append(",c.HEADTHICK,c.TANKVOLUMN,c.TAREWEIGHT,c.MAXWORKINGGPRESSURE,c.TESTINGGPRESSURE,c.DESIGNTEMPERATUREB,c.DESIGNTEMPERATUREE");
strSql.Append(",c.TRAILPEDAL,c.AIRVALVE,c.SAFETYVALVE,c.TOPVALVE,c.BOTTOMVALVE,c.EXSITSIPHONPIPE,c.EXSITPRESSUREGAUGE");
strSql.Append(",[EXSITTOPOVERFLOWBOX],[EXSITINTOOVERFLOWBOX],[EXSITBOTTONVALVEDUSTCOVER],[STEAMPIPE],c.REMARKS");
strSql.Append(",c.INPUTBY,c.INPUTTIME,c.COMPANYID,c.INSPECTION_EXPIRE_DATE,c.INSURANCE_EXPIRE_DATE,c.CTNSTATUS,c.ISSTOPUSE,c.TAKECTNDATE,c.EXPIREDATE");
strSql.Append(",(select ShowName from [user] where GID=c.INPUTBY) as INPUTBYREF");
strSql.Append(",(select TOP 1 GOODSNAME FROM op_ctnbscard WHERE CTNNO=c.CTNNO ORDER BY PORTLOAD_CNT_TIME DESC) as PREGOODNAME");
strSql.Append(",N.INSPECTDATE,I.GID INSURANCEGID,I.BSNO INSURANCENO,I.CORPSNAME INSURANCECORP,(CASE I.ISLOCK WHEN 1 THEN '锁定' else '未锁定' end) as INSURANCELOCKREF,I.BEGINDATE INBEGINDATE,I.ENDDATE INENDDATE,N.INSPECTENDDATE");
strSql.Append(",B.VDESTPORT CURPORT,B.VCURSTATOIN CURSTATOIN,c.CTNRENT,c.INSPECTLOCKSTATUS,c.INSURANCELOCKSTATUS,b.VDESTPORT+' '+b.VCURSTATOIN CURRENTPORT ");
strSql.Append(" from code_ctntk c ");
strSql.Append(" left join v_top_Code_CtnTkInspect N ON (N.LINKGID=c.GID) ");
strSql.Append(" left join v_top_Code_CtnTkInsurance I ON (I.LINKGID=c.GID) ");
strSql.Append(" left join v_top_opctnbscard B ON (B.CTNNO=c.CTNNO) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" ) v ");
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
totel = getTotalCount(strCondition);
return SetData(strSql);
}
public static int getTotalCount(string strCondition)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" from code_ctntk c where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
static public string GetDataListStr(string strCondition, string companyid, string sort = null)
{
var rangstr = "";
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT c.GID,c.CTNNO,c.CTNPROP,c.NAMEPLATE,c.OWNERCTN,c.MADEDATE,c.MADEFACTORY,c.TANKWALLTHICK");
strSql.Append(",c.HEADTHICK,c.TANKVOLUMN,c.TAREWEIGHT,c.MAXWORKINGGPRESSURE,c.TESTINGGPRESSURE,c.DESIGNTEMPERATUREB,c.DESIGNTEMPERATUREE");
strSql.Append(",c.TRAILPEDAL,c.AIRVALVE,c.SAFETYVALVE,c.TOPVALVE,c.BOTTOMVALVE,c.EXSITSIPHONPIPE,c.EXSITPRESSUREGAUGE");
strSql.Append(",[EXSITTOPOVERFLOWBOX],[EXSITINTOOVERFLOWBOX],[EXSITBOTTONVALVEDUSTCOVER],[STEAMPIPE],c.REMARKS");
strSql.Append(",c.INPUTBY,c.INPUTTIME,c.COMPANYID,c.INSPECTION_EXPIRE_DATE,c.INSURANCE_EXPIRE_DATE,c.CTNSTATUS,c.ISSTOPUSE,c.TAKECTNDATE,c.EXPIREDATE");
strSql.Append(",(select ShowName from [user] where GID=c.INPUTBY) as INPUTBYREF");
strSql.Append(",(select TOP 1 GOODSNAME FROM op_ctnbscard WHERE CTNNO=c.CTNNO ORDER BY PORTLOAD_CNT_TIME DESC) as PREGOODNAME");
strSql.Append(",N.INSPECTDATE,I.GID INSURANCEGID,I.BSNO INSURANCENO,I.CORPSNAME INSURANCECORP,(CASE I.ISLOCK WHEN 1 THEN '锁定' else '未锁定' end) as INSURANCELOCKREF,I.BEGINDATE INBEGINDATE,I.ENDDATE INENDDATE,N.INSPECTENDDATE");
strSql.Append(",B.VDESTPORT CURPORT,B.VCURSTATOIN CURSTATOIN,c.CTNRENT,c.INSPECTLOCKSTATUS,c.INSURANCELOCKSTATUS");
strSql.Append(" from code_ctntk c ");
strSql.Append(" left join v_top_Code_CtnTkInspect N ON (N.LINKGID=c.GID) ");
strSql.Append(" left join v_top_Code_CtnTkInsurance I ON (I.LINKGID=c.GID) ");
strSql.Append(" left join v_top_opctnbscard B ON (B.CTNNO=c.CTNNO) ");
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 c.INPUTTIME DESC");
}
return strSql.ToString();
}
static public List<CodeCtnTk> GetDataDateList(string strCondition, string companyid, string sort = null)
{
var rangstr = " c.COMPANYID='" + companyid + "'";
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT c.GID,c.CTNNO,c.CTNPROP,c.NAMEPLATE,c.OWNERCTN,c.MADEDATE,c.MADEFACTORY,c.TANKWALLTHICK");
strSql.Append(",c.HEADTHICK,c.TANKVOLUMN,c.TAREWEIGHT,c.MAXWORKINGGPRESSURE,c.TESTINGGPRESSURE,c.DESIGNTEMPERATUREB,c.DESIGNTEMPERATUREE");
strSql.Append(",c.TRAILPEDAL,c.AIRVALVE,c.SAFETYVALVE,c.TOPVALVE,c.BOTTOMVALVE,c.EXSITSIPHONPIPE,c.EXSITPRESSUREGAUGE");
strSql.Append(",[EXSITTOPOVERFLOWBOX],[EXSITINTOOVERFLOWBOX],[EXSITBOTTONVALVEDUSTCOVER],[STEAMPIPE],c.REMARKS");
strSql.Append(",c.INPUTBY,c.INPUTTIME,c.COMPANYID,c.INSPECTION_EXPIRE_DATE,c.INSURANCE_EXPIRE_DATE,c.CURPORT,c.CURSTATOIN,c.CTNSTATUS,c.ISSTOPUSE,c.TAKECTNDATE,c.EXPIREDATE");
strSql.Append(",(select ShowName from [user] where GID=c.INPUTBY) as INPUTBYREF");
strSql.Append(",(select TOP 1 GOODSNAME FROM op_ctnbscard WHERE CTNNO=c.CTNNO ORDER BY PORTLOAD_CNT_TIME DESC) as PREGOODNAME");
strSql.Append(",N.INSPECTDATE,I.GID INSURANCEGID,I.BSNO INSURANCENO,I.CORPSNAME INSURANCECORP,(CASE I.ISLOCK WHEN 1 THEN '锁定' else '未锁定' end) as INSURANCELOCKREF,I.BEGINDATE INBEGINDATE,I.ENDDATE INENDDATE,c.CTNRENT,N.INSPECTENDDATE,c.INSPECTLOCKSTATUS,c.INSURANCELOCKSTATUS,b.VDESTPORT+' '+b.VCURSTATOIN CURRENTPORT");
strSql.Append(" from code_ctntk c ");
strSql.Append(" left join v_top_Code_CtnTkInspect N ON (N.LINKGID=c.GID) ");
strSql.Append(" left join v_top_Code_CtnTkInsurance I ON (I.LINKGID=c.GID) ");
strSql.Append(" left join v_top_opctnbscard b on c.CTNNO=b.CTNNO ");
strSql.Append(" where (c.ISSTOPUSE is null or c.ISSTOPUSE=0) and (dateadd(yy,1,I.ENDDATE)<dateadd(day,15,GETDATE()) OR N.INSPECTENDDATE<dateadd(day,30,GETDATE())) ");
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 c.INPUTTIME DESC");
}
return SetData(strSql);
}
static public CodeCtnTk GetData(string condition, string companyid)
{
CodeCtnTk data = null;
int total = 0;
var list = GetDataList(0, 1, condition, companyid, out total);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeCtnTk();
data.COMPANYID = companyid;
}
return data;
}
private static List<CodeCtnTk> SetData(StringBuilder strSql)
{
var headList = new List<CodeCtnTk>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeCtnTk data = new CodeCtnTk();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CTNNO = Convert.ToString(reader["CTNNO"]);
data.CTNPROP = Convert.ToString(reader["CTNPROP"]);
data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]);
data.NAMEPLATE = Convert.ToString(reader["NAMEPLATE"]);
data.OWNERCTN = Convert.ToString(reader["OWNERCTN"]);
if (reader["MADEDATE"] != DBNull.Value)
data.MADEDATE = Convert.ToDateTime(reader["MADEDATE"]).ToString("yyyy-MM-dd");
data.MADEFACTORY = Convert.ToString(reader["MADEFACTORY"]);
if (reader["TANKWALLTHICK"] != DBNull.Value)
data.TANKWALLTHICK = Convert.ToDecimal(reader["TANKWALLTHICK"]);
if (reader["HEADTHICK"] != DBNull.Value)
data.HEADTHICK = Convert.ToDecimal(reader["HEADTHICK"]);
if (reader["TANKVOLUMN"] != DBNull.Value)
data.TANKVOLUMN = Convert.ToDecimal(reader["TANKVOLUMN"]);
if (reader["TAREWEIGHT"] != DBNull.Value)
data.TAREWEIGHT = Convert.ToDecimal(reader["TAREWEIGHT"]);
if (reader["MAXWORKINGGPRESSURE"] != DBNull.Value)
data.MAXWORKINGGPRESSURE = Convert.ToDecimal(reader["MAXWORKINGGPRESSURE"]);
if (reader["TESTINGGPRESSURE"] != DBNull.Value)
data.TESTINGGPRESSURE = Convert.ToDecimal(reader["TESTINGGPRESSURE"]);
if (reader["DESIGNTEMPERATUREB"] != DBNull.Value)
data.DESIGNTEMPERATUREB = Convert.ToDecimal(reader["DESIGNTEMPERATUREB"]);
if (reader["DESIGNTEMPERATUREE"] != DBNull.Value)
data.DESIGNTEMPERATUREE = Convert.ToDecimal(reader["DESIGNTEMPERATUREE"]);
data.TRAILPEDAL = Convert.ToString(reader["TRAILPEDAL"]);
data.AIRVALVE = Convert.ToString(reader["AIRVALVE"]);
data.SAFETYVALVE = Convert.ToString(reader["SAFETYVALVE"]);
data.TOPVALVE = Convert.ToString(reader["TOPVALVE"]);
data.BOTTOMVALVE = Convert.ToString(reader["BOTTOMVALVE"]);
if (reader["EXSITSIPHONPIPE"] != DBNull.Value)
data.EXSITSIPHONPIPE = Convert.ToBoolean(reader["EXSITSIPHONPIPE"]);
if (reader["EXSITPRESSUREGAUGE"] != DBNull.Value)
data.EXSITPRESSUREGAUGE = Convert.ToBoolean(reader["EXSITPRESSUREGAUGE"]);
if (reader["EXSITTOPOVERFLOWBOX"] != DBNull.Value)
data.EXSITTOPOVERFLOWBOX = Convert.ToBoolean(reader["EXSITTOPOVERFLOWBOX"]);
if (reader["EXSITINTOOVERFLOWBOX"] != DBNull.Value)
data.EXSITINTOOVERFLOWBOX = Convert.ToBoolean(reader["EXSITINTOOVERFLOWBOX"]);
if (reader["EXSITBOTTONVALVEDUSTCOVER"] != DBNull.Value)
data.EXSITBOTTONVALVEDUSTCOVER = Convert.ToBoolean(reader["EXSITBOTTONVALVEDUSTCOVER"]);
data.STEAMPIPE = Convert.ToString(reader["STEAMPIPE"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
data.CTNRENT = Convert.ToString(reader["CTNRENT"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["INSPECTION_EXPIRE_DATE"] != DBNull.Value)
data.INSPECTION_EXPIRE_DATE = Convert.ToDateTime(reader["INSPECTION_EXPIRE_DATE"]).ToString("yyyy-MM-dd");
if (reader["INSURANCE_EXPIRE_DATE"] != DBNull.Value)
data.INSURANCE_EXPIRE_DATE = Convert.ToDateTime(reader["INSURANCE_EXPIRE_DATE"]).ToString("yyyy-MM-dd");
data.CURPORT = Convert.ToString(reader["CURPORT"]);
data.CURSTATOIN = Convert.ToString(reader["CURSTATOIN"]);
data.PREGOODNAME = Convert.ToString(reader["PREGOODNAME"]);
if (reader["INSPECTDATE"] != DBNull.Value)
data.INSPECTDATE = Convert.ToDateTime(reader["INSPECTDATE"]).ToString("yyyy-MM-dd");
if (reader["INSPECTENDDATE"] != DBNull.Value)
data.INSPECTENDDATE = Convert.ToDateTime(reader["INSPECTENDDATE"]).ToString("yyyy-MM-dd");
data.INSURANCENO = Convert.ToString(reader["INSURANCENO"]);
if (reader["INBEGINDATE"] != DBNull.Value)
data.INBEGINDATE = Convert.ToDateTime(reader["INBEGINDATE"]).ToString("yyyy-MM-dd");
if (reader["INENDDATE"] != DBNull.Value)
data.INENDDATE = Convert.ToDateTime(reader["INENDDATE"]).ToString("yyyy-MM-dd");
if (reader["ISSTOPUSE"] != DBNull.Value)
data.ISSTOPUSE = Convert.ToBoolean(reader["ISSTOPUSE"]);
if (reader["INSPECTLOCKSTATUS"] != DBNull.Value)
data.INSPECTLOCKSTATUS = Convert.ToBoolean(reader["INSPECTLOCKSTATUS"]);
if (reader["INSURANCELOCKSTATUS"] != DBNull.Value)
data.INSURANCELOCKSTATUS = Convert.ToBoolean(reader["INSURANCELOCKSTATUS"]);
if (reader["CURRENTPORT"] != DBNull.Value)
data.CURRENTPORT = Convert.ToString(reader["CURRENTPORT"]);
data.INSURANCEGID = Convert.ToString(reader["INSURANCEGID"]);
data.INSURANCECORP = Convert.ToString(reader["INSURANCECORP"]);
data.INSURANCELOCKREF = Convert.ToString(reader["INSURANCELOCKREF"]);
if (reader["TAKECTNDATE"] != DBNull.Value)
data.TAKECTNDATE = Convert.ToString(reader["TAKECTNDATE"]);
if (reader["EXPIREDATE"] != DBNull.Value)
data.EXPIREDATE = Convert.ToString(reader["EXPIREDATE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteCodeCtnTk(List<CodeCtnTk> 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_ctntk 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 不能去航线
static public List<CodeCtnTkNoLaneItems> GetCodeCtnTkNoLaneItemsList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],[LANEGID],[INPUTBY],[INPUTTIME]");
strSql.Append(",(select LANE from code_lanes where GID=Code_CtnTkNoLaneItems.LANEGID) LANE");
strSql.Append(",(select ShowName from [user] where GID=Code_CtnTkNoLaneItems.INPUTBY) as INPUTBYREF");
strSql.Append(" from Code_CtnTkNoLaneItems ");
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 SetCodeCtnTkNoLaneItemsData(strSql);
}
private static List<CodeCtnTkNoLaneItems> SetCodeCtnTkNoLaneItemsData(StringBuilder strSql)
{
var headList = new List<CodeCtnTkNoLaneItems>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeCtnTkNoLaneItems data = new CodeCtnTkNoLaneItems();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
data.LANEGID = Convert.ToString(reader["LANEGID"]);
data.LANE = Convert.ToString(reader["LANE"]);
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;
}
public static DBResult SaveCodeCtnTkNoLaneItems(List<CodeCtnTkNoLaneItems> 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_CtnTkNoLaneItems (GID,LINKGID,LANEGID,INPUTBY,INPUTTIME)
values (@GID,@LINKGID,@LANEGID,@INPUTBY,@INPUTTIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update Code_CtnTkNoLaneItems set LANEGID=@LANEGID where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.LINKGID == "*" || enumValue.LINKGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@LANEGID", DbType.String, enumValue.LANEGID);
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, "@LANEGID", DbType.String, enumValue.LANEGID);
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 DeleteCodeCtnTkNoLaneItems(List<CodeCtnTkNoLaneItems> 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_CtnTkNoLaneItems 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 年检
static public List<CodeCtnTkInspect> GetCodeCtnTkInspectItemsData(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],[DEPOT],[DEPOTDATE],[INSPECTDATE],[CYCLE],[INSPECTCORP],[DEPOTAMOUNT],[DEPOTCURRENCY],[INSPECTAMOUNT],[INSPECTCURRENCY],[INPUTBY],[INPUTTIME],INSPECTENDDATE");
strSql.Append(",(select ShowName from [user] where GID=Code_CtnTkInspect.INPUTBY) as INPUTBYREF");
strSql.Append(",(select CTNNO from code_ctntk where GID=Code_CtnTkInspect.LINKGID) as CTNNO,(CASE ISLOCK WHEN 1 THEN '锁定' else '未锁定' end) as ISLOCKREF");
strSql.Append(" from Code_CtnTkInspect ");
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 INSPECTDATE DESC");
}
return SetCodeCtnTkInspectItemsData(strSql);
}
private static List<CodeCtnTkInspect> SetCodeCtnTkInspectItemsData(StringBuilder strSql)
{
var headList = new List<CodeCtnTkInspect>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeCtnTkInspect data = new CodeCtnTkInspect();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
data.CTNNO = Convert.ToString(reader["CTNNO"]);
data.DEPOT = Convert.ToString(reader["DEPOT"]);
if (reader["DEPOTDATE"] != DBNull.Value)
data.DEPOTDATE = Convert.ToDateTime(reader["DEPOTDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["INSPECTDATE"] != DBNull.Value)
data.INSPECTDATE = Convert.ToDateTime(reader["INSPECTDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["INSPECTENDDATE"] != DBNull.Value)
data.INSPECTENDDATE = Convert.ToDateTime(reader["INSPECTENDDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["CYCLE"] != DBNull.Value)
data.CYCLE = Convert.ToDecimal(reader["CYCLE"]);
data.INSPECTCORP = Convert.ToString(reader["INSPECTCORP"]);
if (reader["DEPOTAMOUNT"] != DBNull.Value)
data.DEPOTAMOUNT = Convert.ToDecimal(reader["DEPOTAMOUNT"]);
data.DEPOTCURRENCY = Convert.ToString(reader["DEPOTCURRENCY"]);
if (reader["INSPECTAMOUNT"] != DBNull.Value)
data.INSPECTAMOUNT = Convert.ToDecimal(reader["INSPECTAMOUNT"]);
data.INSPECTCURRENCY = Convert.ToString(reader["INSPECTCURRENCY"]);
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.ISLOCKREF = Convert.ToString(reader["ISLOCKREF"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveCodeCtnTkINSPECTItems(List<CodeCtnTkInspect> 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_CtnTkInspect (GID,LINKGID,DEPOT,DEPOTDATE,INSPECTDATE,CYCLE,INSPECTCORP,DEPOTAMOUNT,DEPOTCURRENCY,INSPECTAMOUNT,INSPECTCURRENCY,INPUTBY,INPUTTIME,INSPECTENDDATE)
values (@GID,@LINKGID,@DEPOT,@DEPOTDATE,@INSPECTDATE,@CYCLE,@INSPECTCORP,@DEPOTAMOUNT,@DEPOTCURRENCY,@INSPECTAMOUNT,@INSPECTCURRENCY,@INPUTBY,@INPUTTIME,@INSPECTENDDATE) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update Code_CtnTkInspect set DEPOT=@DEPOT,DEPOTDATE=@DEPOTDATE,INSPECTDATE=@INSPECTDATE,CYCLE=@CYCLE,INSPECTCORP=@INSPECTCORP,DEPOTAMOUNT=@DEPOTAMOUNT,DEPOTCURRENCY=@DEPOTCURRENCY,INSPECTAMOUNT=@INSPECTAMOUNT,INSPECTCURRENCY=@INSPECTCURRENCY,INSPECTENDDATE=@INSPECTENDDATE where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.DEPOTDATE == "") enumValue.DEPOTDATE = null;
else
{
enumValue.DEPOTDATE = Convert.ToDateTime(enumValue.DEPOTDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.INSPECTDATE == "") enumValue.INSPECTDATE = null;
else
{
enumValue.INSPECTDATE = Convert.ToDateTime(enumValue.INSPECTDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.INSPECTENDDATE == "") enumValue.INSPECTENDDATE = null;
else
{
enumValue.INSPECTENDDATE = Convert.ToDateTime(enumValue.INSPECTENDDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.LINKGID == "*" || enumValue.LINKGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@DEPOT", DbType.String, enumValue.DEPOT);
db.AddInParameter(cmdInsert, "@DEPOTDATE", DbType.String, enumValue.DEPOTDATE);
db.AddInParameter(cmdInsert, "@INSPECTDATE", DbType.String, enumValue.INSPECTDATE);
db.AddInParameter(cmdInsert, "@CYCLE", DbType.String, enumValue.CYCLE);
db.AddInParameter(cmdInsert, "@INSPECTCORP", DbType.String, enumValue.INSPECTCORP);
db.AddInParameter(cmdInsert, "@INSPECTAMOUNT", DbType.Decimal, enumValue.INSPECTAMOUNT);
db.AddInParameter(cmdInsert, "@INSPECTCURRENCY", DbType.String, enumValue.INSPECTCURRENCY);
db.AddInParameter(cmdInsert, "@DEPOTAMOUNT", DbType.Decimal, enumValue.DEPOTAMOUNT);
db.AddInParameter(cmdInsert, "@DEPOTCURRENCY", DbType.String, enumValue.DEPOTCURRENCY);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@INSPECTENDDATE", DbType.String, enumValue.INSPECTENDDATE);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@DEPOT", DbType.String, enumValue.DEPOT);
db.AddInParameter(cmdUpdate, "@DEPOTDATE", DbType.String, enumValue.DEPOTDATE);
db.AddInParameter(cmdUpdate, "@INSPECTDATE", DbType.String, enumValue.INSPECTDATE);
db.AddInParameter(cmdUpdate, "@CYCLE", DbType.String, enumValue.CYCLE);
db.AddInParameter(cmdUpdate, "@INSPECTCORP", DbType.String, enumValue.INSPECTCORP);
db.AddInParameter(cmdUpdate, "@INSPECTAMOUNT", DbType.String, enumValue.INSPECTAMOUNT);
db.AddInParameter(cmdUpdate, "@INSPECTCURRENCY", DbType.String, enumValue.INSPECTCURRENCY);
db.AddInParameter(cmdUpdate, "@DEPOTAMOUNT", DbType.Decimal, enumValue.DEPOTAMOUNT);
db.AddInParameter(cmdUpdate, "@DEPOTCURRENCY", DbType.String, enumValue.DEPOTCURRENCY);
db.AddInParameter(cmdUpdate, "@INSPECTENDDATE", DbType.String, enumValue.INSPECTENDDATE);
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 LockCodeCtnTkINSPECTItems(List<CodeCtnTkInspect> bodyList, int islock)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update Code_CtnTkInspect set ISLOCK=" + islock.ToString() + " where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
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 DeleteCodeCtnTkINSPECTItems(List<CodeCtnTkInspect> 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_CtnTkInspect 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 bool ImportCtnTkInspect(string bsno, HttpRequestBase request, DataTable table, string userid, out string msg, out List<CodeCtnTkInspect> headList)
{
var isSucess = false;
msg = "";
headList = new List<CodeCtnTkInspect>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
using (var connection = db.CreateConnection())
{
connection.Open();
var idbTran = connection.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var DEPOT = Convert.ToString(row["场站"]);
var DEPOTDATE = Convert.ToString(row["入场时间"]);
var INSPECTDATE = Convert.ToString(row["年检时间"]);
var CYCLE = Convert.ToString(row["周期"]);
var INSPECTCORP = Convert.ToString(row["年检企业"]);
var DEPOTAMOUNT = Convert.ToString(row["场站费用"]);
var DEPOTCURRENCY = Convert.ToString(row["场站币别"]);
var INSPECTAMOUNT = Convert.ToString(row["年检费用"]);
var INSPECTCURRENCY = Convert.ToString(row["年检币别"]);
var INSPECTENDDATE = Convert.ToString(row["年检结束时间"]);
if (DEPOTAMOUNT == "") DEPOTAMOUNT = "0";
if (INSPECTAMOUNT == "") INSPECTAMOUNT = "0";
if (INSPECTENDDATE == "") INSPECTENDDATE = null;
if (INSPECTDATE == "") INSPECTDATE = null;
if (DEPOT != "")
{
#region 托单数据生成
var cmdInsert =
db.GetSqlStringCommand(
@"insert into Code_CtnTkInspect (GID,LINKGID,DEPOT,DEPOTDATE,INSPECTDATE,CYCLE,INSPECTCORP,DEPOTAMOUNT,DEPOTCURRENCY,INSPECTAMOUNT,INSPECTCURRENCY,INPUTBY,INPUTTIME,INSPECTDATE)
values (@GID,@LINKGID,@DEPOT,@DEPOTDATE,@INSPECTDATE,@CYCLE,@INSPECTCORP,@DEPOTAMOUNT,@DEPOTCURRENCY,@INSPECTAMOUNT,@INSPECTCURRENCY,@INPUTBY,@INPUTTIME,@INSPECTDATE) ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@DEPOT", DbType.String, DEPOT);
db.AddInParameter(cmdInsert, "@DEPOTDATE", DbType.String, DEPOTDATE);
db.AddInParameter(cmdInsert, "@INSPECTDATE", DbType.String, INSPECTDATE);
db.AddInParameter(cmdInsert, "@CYCLE", DbType.String, CYCLE);
db.AddInParameter(cmdInsert, "@INSPECTCORP", DbType.String, INSPECTCORP);
db.AddInParameter(cmdInsert, "@INSPECTAMOUNT", DbType.Decimal, Convert.ToDecimal(INSPECTAMOUNT));
db.AddInParameter(cmdInsert, "@INSPECTCURRENCY", DbType.String, INSPECTCURRENCY);
db.AddInParameter(cmdInsert, "@DEPOTAMOUNT", DbType.Decimal, Convert.ToDecimal(DEPOTAMOUNT));
db.AddInParameter(cmdInsert, "@DEPOTCURRENCY", DbType.String, DEPOTCURRENCY);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@INSPECTENDDATE", DbType.String, INSPECTENDDATE);
db.ExecuteNonQuery(cmdInsert, idbTran);
#endregion
}
}
idbTran.Commit();
isSucess = true;
}
catch (Exception exception)
{
idbTran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
#endregion
#region 保险
static public List<CodeCtnTkInsurance> GetCodeCtnTkInsuranceItemdata(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],[BSNO],[BEGINDATE],[ENDDATE],[CORPSNAME],[INPUTBY],[INPUTTIME]");
strSql.Append(",(select ShowName from [user] where GID=Code_CtnTkInsurance.INPUTBY) as INPUTBYREF,(CASE ISLOCK WHEN 1 THEN '锁定' else '未锁定' end) as ISLOCKREF");
strSql.Append(" from Code_CtnTkInsurance ");
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 BEGINDATE DESC");
}
return SetCodeCtnTkInsuranceItemsData(strSql);
}
private static List<CodeCtnTkInsurance> SetCodeCtnTkInsuranceItemsData(StringBuilder strSql)
{
var headList = new List<CodeCtnTkInsurance>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeCtnTkInsurance data = new CodeCtnTkInsurance();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
if (reader["BEGINDATE"] != DBNull.Value)
data.BEGINDATE = Convert.ToDateTime(reader["BEGINDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["ENDDATE"] != DBNull.Value)
data.ENDDATE = Convert.ToDateTime(reader["ENDDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
data.CORPSNAME = Convert.ToString(reader["CORPSNAME"]);
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.ISLOCKREF = Convert.ToString(reader["ISLOCKREF"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveCodeCtnTkInsuranceItems(List<CodeCtnTkInsurance> 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_CtnTkInsurance (GID,LINKGID,BSNO,BEGINDATE,ENDDATE,CORPSNAME,INPUTBY,INPUTTIME)
values (@GID,@LINKGID,@BSNO,@BEGINDATE,@ENDDATE,@CORPSNAME,@INPUTBY,@INPUTTIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update Code_CtnTkInsurance set BSNO=@BSNO,BEGINDATE=@BEGINDATE,ENDDATE=@ENDDATE,CORPSNAME=@CORPSNAME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.BEGINDATE == "") enumValue.BEGINDATE = null;
else
{
enumValue.BEGINDATE = Convert.ToDateTime(enumValue.BEGINDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.ENDDATE == "") enumValue.ENDDATE = null;
else
{
enumValue.ENDDATE = Convert.ToDateTime(enumValue.ENDDATE.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.LINKGID == "*" || enumValue.LINKGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdInsert, "@BEGINDATE", DbType.String, enumValue.BEGINDATE);
db.AddInParameter(cmdInsert, "@ENDDATE", DbType.String, enumValue.ENDDATE);
db.AddInParameter(cmdInsert, "@CORPSNAME", DbType.String, enumValue.CORPSNAME);
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, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdate, "@BEGINDATE", DbType.String, enumValue.BEGINDATE);
db.AddInParameter(cmdUpdate, "@ENDDATE", DbType.String, enumValue.ENDDATE);
db.AddInParameter(cmdUpdate, "@CORPSNAME", DbType.String, enumValue.CORPSNAME);
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 LockCodeCtnTkInsuranceItems(List<CodeCtnTkInsurance> bodyList, int islock)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update Code_CtnTkInsurance set ISLOCK=" + islock.ToString() + " where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
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 LockCodeCtnTkInsurance(string data)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update Code_CtnTkInsurance set ISLOCK=1 where GID in (" + data + ") ");
cmdUpdate.Parameters.Clear();
// db.AddInParameter(cmdUpdate, "@GID", DbType.String, data);
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 DeleteCodeCtnTkInsuranceItems(List<CodeCtnTkInsurance> 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_CtnTkInsurance 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 bool ImportCtnTkInsurance(string bsno, HttpRequestBase request, DataTable table, string userid, out string msg, out List<CodeCtnTkInsurance> headList)
{
var isSucess = false;
msg = "";
headList = new List<CodeCtnTkInsurance>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
using (var connection = db.CreateConnection())
{
connection.Open();
var idbTran = connection.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var BSNO = Convert.ToString(row["保险编号"]);
var BEGINDATE = Convert.ToString(row["开始时间"]);
var ENDDATE = Convert.ToString(row["结束时间"]);
var CORPSNAME = Convert.ToString(row["保险企业"]);
if (BSNO != "")
{
#region 托单数据生成
var cmdInsert =
db.GetSqlStringCommand(
@"insert into Code_CtnTkInsurance (GID,LINKGID,BSNO,BEGINDATE,ENDDATE,CORPSNAME,INPUTBY,INPUTTIME)
values (@GID,@LINKGID,@BSNO,@BEGINDATE,@ENDDATE,@CORPSNAME,@INPUTBY,@INPUTTIME) ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, BSNO);
db.AddInParameter(cmdInsert, "@BEGINDATE", DbType.String, BEGINDATE);
db.AddInParameter(cmdInsert, "@ENDDATE", DbType.String, ENDDATE);
db.AddInParameter(cmdInsert, "@CORPSNAME", DbType.String, CORPSNAME);
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, idbTran);
#endregion
}
}
idbTran.Commit();
isSucess = true;
}
catch (Exception exception)
{
idbTran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
public static bool ImportCtnTkInsurance_List(string _bsno, HttpRequestBase request, DataTable table, string userid, out string msg, out List<CodeCtnTkInsurance> headList)
{
var isSucess = false;
msg = "";
headList = new List<CodeCtnTkInsurance>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
using (var connection = db.CreateConnection())
{
connection.Open();
var idbTran = connection.BeginTransaction();
try
{
var bsnoarray = _bsno.Split(',');
foreach (var bsno in bsnoarray)
{
foreach (DataRow row in table.Rows)
{
var BSNO = Convert.ToString(row["保险编号"]);
var BEGINDATE = Convert.ToString(row["开始时间"]);
var ENDDATE = Convert.ToString(row["结束时间"]);
var CORPSNAME = Convert.ToString(row["保险企业"]);
if (BSNO != "")
{
#region 托单数据生成
var cmdInsert =
db.GetSqlStringCommand(
@"insert into Code_CtnTkInsurance (GID,LINKGID,BSNO,BEGINDATE,ENDDATE,CORPSNAME,INPUTBY,INPUTTIME)
select @GID,@LINKGID,@BSNO,@BEGINDATE,@ENDDATE,@CORPSNAME,@INPUTBY,@INPUTTIME where not exists (select 1 from Code_CtnTkInsurance where LINKGID=@LINKGID1 and BSNO=@BSNO1 and BEGINDATE=@BEGINDATE1 and ENDDATE=@ENDDATE1) ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, BSNO);
db.AddInParameter(cmdInsert, "@BEGINDATE", DbType.String, BEGINDATE);
db.AddInParameter(cmdInsert, "@ENDDATE", DbType.String, ENDDATE);
db.AddInParameter(cmdInsert, "@CORPSNAME", DbType.String, CORPSNAME);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@LINKGID1", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@BSNO1", DbType.String, BSNO);
db.AddInParameter(cmdInsert, "@BEGINDATE1", DbType.String, BEGINDATE);
db.AddInParameter(cmdInsert, "@ENDDATE1", DbType.String, ENDDATE);
db.ExecuteNonQuery(cmdInsert, idbTran);
#endregion
}
}
}
idbTran.Commit();
isSucess = true;
}
catch (Exception exception)
{
idbTran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
#endregion
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(GID) AS CT from code_ctntk (NOLOCK) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
public static int InsertCtnInsurance(string GIDs, string SHOWNAME, DataTable dt)
{
var result = 0;
if (dt.Rows.Count > 0)
{
var gidarray = GIDs.Split(',');
foreach (var gid in gidarray)
{
foreach (DataRow row in dt.Rows)
{
var sqlstr = "";
/*
var BSNO = Convert.ToString(row["保险编号"]);
var BEGINDATE = Convert.ToString(row["开始时间"]);
var ENDDATE = Convert.ToString(row["结束时间"]);
var CORPSNAME = Convert.ToString(row["保险企业"]);
*/
var BSNO = Convert.ToString(row["保险编号"]);
var BEGINDATE = Convert.ToString(row["开始时间"]);
var ENDDATE = Convert.ToString(row["结束时间"]);
var CORPSNAME = Convert.ToString(row["保险企业"]);
sqlstr = $"insert into Code_CtnTkInsurance (GID,LINKGID,BSNO,BEGINDATE,ENDDATE,CORPSNAME,INPUTBY,INPUTTIME) select newid(), '{gid}', '{BSNO}', '{BEGINDATE}', '{ENDDATE}', '{CORPSNAME}', '{SHOWNAME}', getdate() where not exists(select 1 from Code_CtnTkInsurance where LINKGID = '{gid}' and BSNO = '{BSNO}' and BEGINDATE = '{BEGINDATE}' and ENDDATE = '{ENDDATE}') ";
result += BasicDataRefDAL.ExecSql(sqlstr);
}
}
}
return result;
}
}
}