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/MsCodeOpDef/MsCodeOpDefDAL.cs

199 lines
6.2 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCodeOpDef;
using DSWeb.MvcShipping.Models.MsCodeDuiTemplate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsCodeOpDef
{
public class MsCodeOpDefDAL
{
#region Inquery DataList
static public List<CodeOpDef> GetDataList(string strCondition, string companyid, string sort = null)
{
var rangstr = " CORPID='"+companyid+"'";
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,CORPID,BSTYPE,FIELDNAME,FIELDTYPE,DEFVALUE,REMARKS");
strSql.Append(" from CODE_OPDEF ");
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 BSTYPE,FIELDNAME");
}
return SetData(strSql);
}
/// <summary>
///
/// </summary>
/// <param name="BSTYPE">业务类型 如“海运进口”“销售订舱”这类的中文</param>
/// <param name="companyid"></param>
/// <returns></returns>
static public List<CodeOpDef> getDefList(string BSTYPE, string companyid) {
return GetDataList("BSTYPE='" + BSTYPE + "'", companyid, "");
}
static public CodeOpDef GetData(string condition, string companyid)
{
CodeOpDef data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeOpDef();
data.CORPID = companyid;
}
return data;
}
private static List<CodeOpDef> SetData(StringBuilder strSql)
{
var headList = new List<CodeOpDef>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeOpDef data = new CodeOpDef();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BSTYPE = Convert.ToString(reader["BSTYPE"]);
data.FIELDNAME = Convert.ToString(reader["FIELDNAME"]);
data.FIELDTYPE = Convert.ToString(reader["FIELDTYPE"]);
data.DEFVALUE = Convert.ToString(reader["DEFVALUE"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
if (data.FIELDTYPE == "STR") {
data.DEFVALUESTR = data.DEFVALUE;
}
if (data.FIELDTYPE == "DATE") {
data.DEFVALUESTRDATE = data.DEFVALUE;
}
if (data.FIELDTYPE == "BOOL") {
data.DEFVALUESTRBOOL=data.DEFVALUE;
}
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
static public List<CodeDuiFeeName> GetFieldList(string bstable)
{
var strSql = new StringBuilder();
strSql.Append("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='"+bstable+"'");
return SetFieldData(strSql);
}
private static List<CodeDuiFeeName> SetFieldData(StringBuilder strSql)
{
var bodyList = new List<CodeDuiFeeName>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeDuiFeeName data = new CodeDuiFeeName();
#region Set DB data to Object
data.FieldName = Convert.ToString(reader["COLUMN_NAME"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
public static DBResult DeleteDetail(List<CodeOpDef> 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_OPDEF 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;
}
}
}