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.
167 lines
6.3 KiB
C#
167 lines
6.3 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.YardDataSet;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeYardDataSet
|
|
{
|
|
public class MsCodeYardDataSetDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<CodeYardDataSet> GetDataList(string strCondition, string companyid, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("GID,YARDCODE,YARD,LOGINNAME,PASSWORD,COMPANYID");
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97017 and EnumValueID=code_yarddata_set.YARDCODE) as YARDCODEREF");
|
|
strSql.Append(" from code_yarddata_set where COMPANYID='" + companyid + "'");
|
|
|
|
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 YARDCODE");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public CodeYardDataSet GetData(string condition, string companyid)
|
|
{
|
|
CodeYardDataSet data = null;
|
|
var list = GetDataList(condition,companyid);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new CodeYardDataSet();
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<CodeYardDataSet> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<CodeYardDataSet>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CodeYardDataSet data = new CodeYardDataSet();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.YARDCODE = Convert.ToString(reader["YARDCODE"]);
|
|
data.YARDCODEREF = Convert.ToString(reader["YARDCODEREF"]);
|
|
data.YARD = Convert.ToString(reader["YARD"]);
|
|
data.LOGINNAME = Convert.ToString(reader["LOGINNAME"]);
|
|
data.PASSWORD = Convert.ToString(reader["PASSWORD"]);
|
|
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
|
|
|
|
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
public static DBResult SaveDetail(List<CodeYardDataSet> 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_yarddata_set (GID,YARDCODE,YARD,LOGINNAME,PASSWORD,COMPANYID)
|
|
values (@GID,@YARDCODE,@YARD,@LOGINNAME,@PASSWORD,@COMPANYID) ");
|
|
|
|
var cmdUpdate =
|
|
db.GetSqlStringCommand(
|
|
@"update code_yarddata_set set YARDCODE=@YARDCODE,YARD=@YARD,LOGINNAME=@LOGINNAME,PASSWORD=@PASSWORD,COMPANYID=@COMPANYID 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, "@YARDCODE", DbType.String, enumValue.YARDCODE);
|
|
db.AddInParameter(cmdInsert, "@YARD", DbType.String, enumValue.YARD);
|
|
db.AddInParameter(cmdInsert, "@LOGINNAME", DbType.String, enumValue.LOGINNAME);
|
|
|
|
db.AddInParameter(cmdInsert, "@PASSWORD", DbType.String, enumValue.PASSWORD);
|
|
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
|
|
|
|
db.AddInParameter(cmdUpdate, "@YARDCODE", DbType.String, enumValue.YARDCODE);
|
|
db.AddInParameter(cmdUpdate, "@YARD", DbType.String, enumValue.YARD);
|
|
db.AddInParameter(cmdUpdate, "@LOGINNAME", DbType.String, enumValue.LOGINNAME);
|
|
db.AddInParameter(cmdUpdate, "@PASSWORD", DbType.String, enumValue.PASSWORD);
|
|
db.AddInParameter(cmdUpdate, "@COMPANYID", DbType.String, enumValue.COMPANYID);
|
|
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
|
|
}
|
|
}
|