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/MvcShipping/DAL/MsCodeFactry/MsCodeFactryDAL.cs

132 lines
4.0 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCodeFactry;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsCodeFactry
{
public class MsCodeFactryDAL
{
#region Inquery DataList
static public List<CodeFactry> GetDataList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,CODENAME,CUSTOMERNAME,FACTRYNAME,FACTRYADDR,FACTRYATTN,FACTRYTEL,CODENAME + '-' + FACTRYNAME AS CodeAndName ");
strSql.Append(" from code_factry ");
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 CUSTOMERNAME,FACTRYNAME");
}
return SetData(strSql);
}
static public CodeFactry GetData(string condition)
{
CodeFactry data = null;
var list = GetDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeFactry();
}
return data;
}
private static List<CodeFactry> SetData(StringBuilder strSql)
{
var headList = new List<CodeFactry>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeFactry data = new CodeFactry();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CODENAME = Convert.ToString(reader["CODENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.FACTRYNAME = Convert.ToString(reader["FACTRYNAME"]);
data.FACTRYADDR = Convert.ToString(reader["FACTRYADDR"]);
data.FACTRYATTN = Convert.ToString(reader["FACTRYATTN"]);
data.FACTRYTEL = Convert.ToString(reader["FACTRYTEL"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult DeleteDetail(List<CodeFactry> 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_FACTRY 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;
}
}
}