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.
169 lines
6.6 KiB
C#
169 lines
6.6 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.CodeAirPort;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeAirPort
|
|
{
|
|
public class MsCodeAirPortDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<CodeAirPort> GetDataList(string strCondition, string companyid, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("GID,PORTID,PORTENAME,PORTCNAME,CITY,COUNTRY,PORTID+'-'+PORTENAME CODEANDNAME,PORTID+'-'+PORTCNAME CODEANDCNAME,LANEGID,(SELECT LANE FROM code_lanes where GID=code_air_port.LANEGID) LANE");
|
|
strSql.Append(" from code_air_port ");
|
|
|
|
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 PORTID");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public CodeAirPort GetData(string condition, string companyid)
|
|
{
|
|
CodeAirPort data = null;
|
|
var list = GetDataList(condition,companyid);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new CodeAirPort();
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<CodeAirPort> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<CodeAirPort>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CodeAirPort data = new CodeAirPort();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.PORTID = Convert.ToString(reader["PORTID"]);
|
|
data.PORTENAME = Convert.ToString(reader["PORTENAME"]);
|
|
data.PORTCNAME = Convert.ToString(reader["PORTCNAME"]);
|
|
data.CITY = Convert.ToString(reader["CITY"]);
|
|
data.COUNTRY = Convert.ToString(reader["COUNTRY"]);
|
|
data.CODEANDNAME = Convert.ToString(reader["CODEANDNAME"]);
|
|
data.CODEANDCNAME = Convert.ToString(reader["CODEANDCNAME"]);
|
|
data.LANEGID = Convert.ToString(reader["LANEGID"]);
|
|
data.LANE = Convert.ToString(reader["LANE"]);
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
public static DBResult SaveDetail(List<CodeAirPort> 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_air_port (GID,PORTID,PORTENAME,PORTCNAME,CITY,COUNTRY,LANEGID)
|
|
values (@GID,@PORTID,@PORTENAME,@PORTCNAME,@CITY,@COUNTRY,@LANEGID) ");
|
|
|
|
var cmdUpdate =
|
|
db.GetSqlStringCommand(
|
|
@"update code_air_port set PORTID=@PORTID,PORTENAME=@PORTENAME,PORTCNAME=@PORTCNAME,CITY=@CITY,COUNTRY=@COUNTRY,LANEGID=@LANEGID 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, "@PORTID", DbType.String, enumValue.PORTID);
|
|
db.AddInParameter(cmdInsert, "@PORTENAME", DbType.String, enumValue.PORTENAME);
|
|
db.AddInParameter(cmdInsert, "@PORTCNAME", DbType.String, enumValue.PORTCNAME);
|
|
|
|
db.AddInParameter(cmdInsert, "@CITY", DbType.String, enumValue.CITY);
|
|
db.AddInParameter(cmdInsert, "@COUNTRY", DbType.String, enumValue.COUNTRY);
|
|
db.AddInParameter(cmdInsert, "@LANEGID", DbType.String, enumValue.LANEGID);
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
|
|
|
|
db.AddInParameter(cmdUpdate, "@PORTID", DbType.String, enumValue.PORTID);
|
|
db.AddInParameter(cmdUpdate, "@PORTENAME", DbType.String, enumValue.PORTENAME);
|
|
db.AddInParameter(cmdUpdate, "@PORTCNAME", DbType.String, enumValue.PORTCNAME);
|
|
db.AddInParameter(cmdUpdate, "@CITY", DbType.String, enumValue.CITY);
|
|
db.AddInParameter(cmdUpdate, "@COUNTRY", DbType.String, enumValue.COUNTRY);
|
|
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;
|
|
}
|
|
#region 参照部分
|
|
|
|
#endregion
|
|
}
|
|
}
|