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/MsCrmKeyCodeSet/MsCrmKeyCodeSetDAL.cs

171 lines
6.0 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCrmKeyCodeSet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.DAL.MsCrmKeyCodeSetDAL
{
public class MsCrmKeyCodeSetDAL
{
#region 查询
static public List<MsCrmKeyCodeSet> GetDataList(string strCondition, string userid, string usercode, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * from crm_key_code where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and KEYTYPE='" + strCondition + "'");
}
else
{
strSql.Append(" and 1<0");
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by KEYVALUE");
}
return SetData(strSql);
}
static public MsCrmKeyCodeSet GetData(string strCondition, string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * from crm_key_code where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and KEYTYPE='" + strCondition + "'");
}
else
{
strSql.Append(" and 1<0");
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsCrmKeyCodeSet();
}
private static List<MsCrmKeyCodeSet> SetData(StringBuilder strSql)
{
var headList = new List<MsCrmKeyCodeSet>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCrmKeyCodeSet data = new MsCrmKeyCodeSet();
#region Set DB data to Object
data.ID = (reader["ID"] == null ? "" : Convert.ToString(reader["ID"]));//ID
data.KEYTYPE = (reader["KEYTYPE"] == null ? "" : Convert.ToString(reader["KEYTYPE"]));//上级ID
data.KEYVALUE = (reader["KEYVALUE"] == null ? "" : Convert.ToString(reader["KEYVALUE"]));//值
data.KEYVALUE2 = (reader["KEYVALUE2"] == null ? "" : Convert.ToString(reader["KEYVALUE2"]));//值
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 键值类别
static public List<MsCrmKeyCodeSet> GetCrmKeyCodeSet(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT '' as ID,KEYTYPE,'' as KEYVALUE from crm_key_code");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" group by KEYTYPE");
strSql.Append(" order by KEYTYPE");
return SetData(strSql);
}
#endregion
#region 查询 Sys_Enumeration
static public List<Sys_EnumerationMD> GetDataList2(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * from sys_Enumeration where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition + "");
}
else
{
strSql.Append(" and 1<0");
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by VALUE");
}
return SetData2(strSql);
}
static public Sys_EnumerationMD GetData2(string strCondition)
{
var list = GetDataList2(strCondition);
if (list.Count > 0)
return list[0];
return new Sys_EnumerationMD();
}
private static List<Sys_EnumerationMD> SetData2(StringBuilder strSql)
{
var headList = new List<Sys_EnumerationMD>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Sys_EnumerationMD data = new Sys_EnumerationMD();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));
data.VALUE = (reader["VALUE"] == null ? "" : Convert.ToString(reader["VALUE"]));
data.NAME = (reader["NAME"] == null ? "" : Convert.ToString(reader["NAME"]));
data.TYPE = (reader["TYPE"] == null ? "" : Convert.ToString(reader["TYPE"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region Enumeration类别
static public List<MsCrmKeyCodeSet> GetEnumerationType()
{
var strSql = new StringBuilder();
strSql.Append("SELECT distinct [type] KEYTYPE,'' ID,'' [KEYVALUE] from sys_Enumeration");
return SetData(strSql);
}
#endregion
}
}