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.
156 lines
5.3 KiB
C#
156 lines
5.3 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.CodeLoadPort;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeLoadPort
|
|
{
|
|
public class MsCodeLoadPortDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<CodeLoadPort> GetDataList(string strCondition, string companyid, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("PORTID,PORT,CNAME,EDICODE");
|
|
strSql.Append(" from code_loadport ");
|
|
|
|
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 PORT");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public CodeLoadPort GetData(string condition, string companyid)
|
|
{
|
|
CodeLoadPort data = null;
|
|
var list = GetDataList(condition,companyid);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new CodeLoadPort();
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<CodeLoadPort> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<CodeLoadPort>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CodeLoadPort data = new CodeLoadPort();
|
|
#region Set DB data to Object
|
|
data.PORTID = Convert.ToString(reader["PORTID"]);
|
|
data.PORT = Convert.ToString(reader["PORT"]);
|
|
data.CNAME = Convert.ToString(reader["CNAME"]);
|
|
data.EDICODE = Convert.ToString(reader["EDICODE"]);
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
public static DBResult SaveDetail(List<CodeLoadPort> 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_loadport (PORTID,PORT,CNAME,EDICODE)
|
|
values (@PORTID,@PORT,@CNAME,@EDICODE) ");
|
|
|
|
var cmdUpdate =
|
|
db.GetSqlStringCommand(
|
|
@"update code_loadport set PORT=@PORT,CNAME=@CNAME,EDICODE=@EDICODE where PORTID=@PORTID ");
|
|
|
|
if (bodyList != null)
|
|
{
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
|
|
if (enumValue.PORTID == "*" || enumValue.PORTID == "")
|
|
{
|
|
cmdInsert.Parameters.Clear();
|
|
db.AddInParameter(cmdInsert, "@PORTID", DbType.String, Guid.NewGuid().ToString());
|
|
db.AddInParameter(cmdInsert, "@PORT", DbType.String, enumValue.PORT);
|
|
db.AddInParameter(cmdInsert, "@CNAME", DbType.String, enumValue.CNAME);
|
|
db.AddInParameter(cmdInsert, "@EDICODE", DbType.String, enumValue.EDICODE);
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
db.AddInParameter(cmdUpdate, "@PORTID", DbType.String, enumValue.PORTID);
|
|
|
|
db.AddInParameter(cmdUpdate, "@PORT", DbType.String, enumValue.PORT);
|
|
db.AddInParameter(cmdUpdate, "@CNAME", DbType.String, enumValue.CNAME);
|
|
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;
|
|
}
|
|
#region 参照部分
|
|
|
|
#endregion
|
|
}
|
|
}
|