using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.CodeCtnEdi; using DSWeb.MvcShipping.Models.MsCodeAfrEdi; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; namespace DSWeb.MvcShipping.DAL.MsCodeCtnEdi { public class MsCodeCtnEdiDAL { #region 查询 static public List GetDataList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_ctn_edi.EDINAME) as EDINAMEREF,'' as PORTID"); strSql.Append(" from code_ctn_edi where 1=1 "); 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 EDINAME,CTN"); } return SetData(strSql); } static public List GetCustList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,CUST as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_cust_edi.EDINAME) as EDINAMEREF,'' as PORTID"); strSql.Append(" from code_cust_edi where 1=1 "); 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 EDINAME,CUST"); } return SetData(strSql); } static public List GetCarrierList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,CUST as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_carrier_edi.EDINAME) as EDINAMEREF,'' as PORTID"); strSql.Append(" from code_carrier_edi where 1=1 "); 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 EDINAME,CUST"); } return SetData(strSql); } static public List GetPkgsList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,PKGS as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_pkgs_edi.EDINAME) as EDINAMEREF,'' as PORTID"); strSql.Append(" from code_pkgs_edi where 1=1 "); 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 EDINAME,PKGS"); } return SetData(strSql); } static public List GetVesselList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,VESSEL as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_vessel_edi.EDINAME) as EDINAMEREF,'' as PORTID"); strSql.Append(" from code_vessel_edi where 1=1 "); 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 EDINAME,VESSEL"); } return SetData(strSql); } static public List GetSERVICEList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,SERVICE as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_service_edi.EDINAME) as EDINAMEREF,'' as PORTID"); strSql.Append(" from code_service_edi where 1=1 "); 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 EDINAME,SERVICE"); } return SetData(strSql); } static public List GetPORTDISCHARGEList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,PORTDISCHARGE as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_disport_edi.EDINAME) as EDINAMEREF,PORTID"); strSql.Append(" from code_disport_edi where 1=1 "); 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 EDINAME,PORTDISCHARGE"); } return SetData(strSql); } static public List GetISSUETYPEList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,BLTYPE as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_issutype_edi.EDINAME) as EDINAMEREF,'' PORTID"); strSql.Append(" from code_issutype_edi where 1=1 "); 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 EDINAME,BLTYPE"); } return SetData(strSql); } static public List GetFeeNameList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("ID as GID,FEENAME as CTN,FEEENAME EDICODE,'' EDINAME,'' REMARK"); strSql.Append(",'' as EDINAMEREF,'' PORTID"); strSql.Append(" from code_fee_edi where 1=1 "); 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 ID"); } return SetData(strSql); } static public List GetReeferfList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,REEFERF as CTN,EDICODE,EDINAME,REMARK"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97012 and EnumValueID=code_reeferf_edi.EDINAME) as EDINAMEREF,'' PORTID"); strSql.Append(" from code_reeferf_edi where 1=1 "); 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 REEFERF"); } return SetData(strSql); } static public CodeCtnEdi GetData(string condition) { CodeCtnEdi data = null; var list = GetDataList(condition); if (list.Count > 0) data = list[0]; if (data == null) { data = new CodeCtnEdi(); } return data; } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CodeCtnEdi data = new CodeCtnEdi(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CTN = Convert.ToString(reader["CTN"]); data.EDICODE = Convert.ToString(reader["EDICODE"]); data.EDINAME = Convert.ToString(reader["EDINAME"]); data.EDINAMEREF = Convert.ToString(reader["EDINAMEREF"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.PORTID = Convert.ToString(reader["PORTID"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetAFRList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT *"); strSql.Append(",(select SHORTNAME from info_client where GID=code_afr_edi.LINKGID) as CustName"); strSql.Append(" from code_afr_edi where 1=1 "); 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 MODIFIEDTIME");//CustName } return SetDataAFR(strSql); } private static List SetDataAFR(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsCodeAfrEdi data = new MsCodeAfrEdi(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//编号 data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//关联客户GID data.SHIPPERNAME = (reader["SHIPPERNAME"] == null ? "" : Convert.ToString(reader["SHIPPERNAME"]));//发货人名称 data.SHIPPERADDR1 = (reader["SHIPPERADDR1"] == null ? "" : Convert.ToString(reader["SHIPPERADDR1"]));//发货人地址1 data.SHIPPERADDR2 = (reader["SHIPPERADDR2"] == null ? "" : Convert.ToString(reader["SHIPPERADDR2"]));//发货人地址2 data.SHIPPERADDR3 = (reader["SHIPPERADDR3"] == null ? "" : Convert.ToString(reader["SHIPPERADDR3"]));//发货人地址3 data.SHIPPERCITY = (reader["SHIPPERCITY"] == null ? "" : Convert.ToString(reader["SHIPPERCITY"]));//SHIPPERCITY data.SHIPPERPROVINCE = (reader["SHIPPERPROVINCE"] == null ? "" : Convert.ToString(reader["SHIPPERPROVINCE"]));//发货人省 data.SHIPPERPOSTCODE = (reader["SHIPPERPOSTCODE"] == null ? "" : Convert.ToString(reader["SHIPPERPOSTCODE"]));//发货人邮编 data.SHIPPERCOUNTRY = (reader["SHIPPERCOUNTRY"] == null ? "" : Convert.ToString(reader["SHIPPERCOUNTRY"]));//发货人国家 data.SHIPPERATTN = (reader["SHIPPERATTN"] == null ? "" : Convert.ToString(reader["SHIPPERATTN"]));//发货人联系人 data.SHIPPERTEL = (reader["SHIPPERTEL"] == null ? "" : Convert.ToString(reader["SHIPPERTEL"]));//发货人联系方式 data.CONSIGNEENAME = (reader["CONSIGNEENAME"] == null ? "" : Convert.ToString(reader["CONSIGNEENAME"]));//收货人名称 data.CONSIGNEEADDR1 = (reader["CONSIGNEEADDR1"] == null ? "" : Convert.ToString(reader["CONSIGNEEADDR1"]));//收货人地址1 data.CONSIGNEEADDR2 = (reader["CONSIGNEEADDR2"] == null ? "" : Convert.ToString(reader["CONSIGNEEADDR2"]));//收货人地址2 data.CONSIGNEEADDR3 = (reader["CONSIGNEEADDR3"] == null ? "" : Convert.ToString(reader["CONSIGNEEADDR3"]));//收货人地址3 data.CONSIGNEECITY = (reader["CONSIGNEECITY"] == null ? "" : Convert.ToString(reader["CONSIGNEECITY"]));//收货人城市 data.CONSIGNEEPROVINCE = (reader["CONSIGNEEPROVINCE"] == null ? "" : Convert.ToString(reader["CONSIGNEEPROVINCE"]));//收货人省 data.CONSIGNEEPOSTCODE = (reader["CONSIGNEEPOSTCODE"] == null ? "" : Convert.ToString(reader["CONSIGNEEPOSTCODE"]));//收货人邮编 data.CONSIGNEECOUNTRY = (reader["CONSIGNEECOUNTRY"] == null ? "" : Convert.ToString(reader["CONSIGNEECOUNTRY"]));//收货人国家 data.CONSIGNEEATTN = (reader["CONSIGNEEATTN"] == null ? "" : Convert.ToString(reader["CONSIGNEEATTN"]));//收货人联系人 data.CONSIGNEETEL = (reader["CONSIGNEETEL"] == null ? "" : Convert.ToString(reader["CONSIGNEETEL"]));//收货人联系方式 data.NOTIFYPARTYNAME = (reader["NOTIFYPARTYNAME"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYNAME"]));//通知人名称 data.NOTIFYPARTYADDR1 = (reader["NOTIFYPARTYADDR1"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYADDR1"]));//通知人地址1 data.NOTIFYPARTYADDR2 = (reader["NOTIFYPARTYADDR2"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYADDR2"]));//通知人地址2 data.NOTIFYPARTYADDR3 = (reader["NOTIFYPARTYADDR3"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYADDR3"]));//通知人地址3 data.NOTIFYPARTYCITY = (reader["NOTIFYPARTYCITY"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYCITY"]));//通知人城市 data.NOTIFYPARTYPROVINCE = (reader["NOTIFYPARTYPROVINCE"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYPROVINCE"]));//通知人省 data.NOTIFYPARTYPOSTCODE = (reader["NOTIFYPARTYPOSTCODE"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYPOSTCODE"]));//通知人邮编 data.NOTIFYPARTYCOUNTRY = (reader["NOTIFYPARTYCOUNTRY"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYCOUNTRY"]));//通知人国家 data.NOTIFYPARTYATTN = (reader["NOTIFYPARTYATTN"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYATTN"]));//通知人联系人 data.NOTIFYPARTYTEL = (reader["NOTIFYPARTYTEL"] == null ? "" : Convert.ToString(reader["NOTIFYPARTYTEL"]));//通知人联系方式 data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//所属公司 data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人GID data.MODIFIEDTIME = (reader["MODIFIEDTIME"] == null ? DateTime.Now : Convert.ToDateTime(reader["MODIFIEDTIME"]));//更改操作时间 data.CustName = (reader["CustName"] == null ? "" : Convert.ToString(reader["CustName"])); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 删除 public static DBResult DeleteCust(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_cust_edi where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeletePkgs(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_pkgs_edi where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeleteSERVICE(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand(@"delete from code_service_edi where GID=@GID"); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeletePORTDISCHARGE(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand(@"delete from code_disport_edi where GID=@GID"); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeleteVessel(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_vessel_edi where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeleteISSUETYPE(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_issutype_edi where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeleteFeeName(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_fee_edi where ID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeleteReeferf(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_reeferf_edi where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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 DeleteCarrier(CodeCtnEdi headdata) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"delete from code_carrier_edi where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.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; } #endregion #region 保存 public static DBResult SaveDetail(List bodyList, 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_ctn_edi (GID,CTN,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_ctn_edi set CTN=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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 SaveCustDetail(List bodyList, 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_cust_edi (GID,CUST,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_cust_edi set CUST=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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 SavePkgsDetail(List bodyList, 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_pkgs_edi (GID,PKGS,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_pkgs_edi set PKGS=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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 SaveVesselDetail(List bodyList, 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_vessel_edi (GID,VESSEL,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_vessel_edi set VESSEL=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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 SaveISSUETYPEDetail(List bodyList, 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_issutype_edi (GID,BLTYPE,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_issutype_edi set BLTYPE=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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 SaveSERVICEDetail(List bodyList, 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_service_edi (GID,SERVICE,EDICODE,EDINAME,REMARK,CREATEUSER,CREATETIME) values (@GID,@SERVICE,@EDICODE,@EDINAME,@REMARK,@CREATEUSER,getdate())"); var cmdUpdate = db.GetSqlStringCommand(@"update code_service_edi set SERVICE=@SERVICE,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK,CREATEUSER=@CREATEUSER,CREATETIME=getdate() 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, "@SERVICE", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, enumValue.CREATEUSER); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@SERVICE", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdUpdate, "@CREATEUSER", DbType.String, enumValue.CREATEUSER); db.ExecuteNonQuery(cmdUpdate, tran); } } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试!"+e.Message; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DBResult SavePORTDISCHARGEDetail(List bodyList, string companyid, string sUSERID) { 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_disport_edi (GID,PORTDISCHARGE,EDICODE,EDINAME,REMARK,CREATEUSER,CREATETIME,PORTID) values (@GID,@PORTDISCHARGE,@EDICODE,@EDINAME,@REMARK,@CREATEUSER,getdate(),@PORTID)"); var cmdUpdate = db.GetSqlStringCommand(@"update code_disport_edi set PORTDISCHARGE=@PORTDISCHARGE,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK,CREATEUSER=@CREATEUSER,CREATETIME=getdate(),PORTID=@PORTID 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, "@PORTDISCHARGE", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, sUSERID); db.AddInParameter(cmdInsert, "@PORTID", DbType.String, enumValue.PORTID); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@PORTDISCHARGE", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); db.AddInParameter(cmdUpdate, "@CREATEUSER", DbType.String, sUSERID); db.AddInParameter(cmdUpdate, "@PORTID", DbType.String, enumValue.PORTID); 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 SaveFeeName(List bodyList, 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_fee_edi (FEENAME,FEEENAME) values (@CTN,@EDICODE) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_fee_edi set FEENAME=@CTN,FEEENAME=@EDICODE where ID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.GID == "*" || enumValue.GID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); 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 SaveReeferf(List bodyList, 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_reeferf_edi (GID,REEFERF,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_reeferf_edi set REEFERF=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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 SaveCarrierDetail(List bodyList, 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_carrier_edi (GID,CUST,EDICODE,EDINAME,REMARK) values (@GID,@CTN,@EDICODE,@EDINAME,@REMARK) "); var cmdUpdate = db.GetSqlStringCommand( @"update code_carrier_edi set CUST=@CTN,EDICODE=@EDICODE,EDINAME=@EDINAME,REMARK=@REMARK 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, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdInsert, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CTN", DbType.String, enumValue.CTN); db.AddInParameter(cmdUpdate, "@EDICODE", DbType.String, enumValue.EDICODE); db.AddInParameter(cmdUpdate, "@EDINAME", DbType.String, enumValue.EDINAME); db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK); 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; } #endregion } }