using Commom.Utility;
|
using Common;
|
using Model;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Text;
|
|
namespace BLL.DAL
|
{
|
public class DALRegion
|
{
|
/// <summary>
|
/// 获取区域集合
|
/// </summary>
|
/// <param name="region"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public IList<Region> GetRegionItems(QueryRegion region,ref PageInfo page)
|
{
|
try
|
{
|
StringBuilder stringBuilder = new StringBuilder();
|
stringBuilder.Append("select * from View_Region_UserInfo where IsDel = 0 ");
|
if (region.RegionCode != null && region.RegionCode != "")
|
{
|
stringBuilder.Append("and RegionCode like '%" + region.RegionCode + "%'");
|
}
|
if (region.RegionName != null && region.RegionName != "")
|
{
|
stringBuilder.Append("and RegionName like '%" + region.RegionName + "%'");
|
}
|
|
SqlParam[] para = new SqlParam[]
|
{
|
};
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(stringBuilder.ToString(), para, "CreatTime", "DESC", ref page);
|
IList<Region> list = ModelConvertHelper<Region>.DataTableToModel(dt);
|
|
return list;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
public IList<Region> GetRegionItems()
|
{
|
try
|
{
|
StringBuilder stringBuilder = new StringBuilder();
|
stringBuilder.Append("select * from View_Region_UserInfo where IsDel = '0' ");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
|
return ModelConvertHelper<Region>.DataTableToModel(dt);
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
/// <summary>
|
/// 获取指定区域信息
|
/// </summary>
|
/// <param name="RegionCode"></param>
|
/// <returns></returns>
|
public Region getRegion(string RegionCode)
|
{
|
try
|
{
|
StringBuilder stringBuilder = new StringBuilder();
|
stringBuilder.Append("select * from View_Region_UserInfo where IsDel = '0' ");
|
if (RegionCode != null && RegionCode != "")
|
{
|
stringBuilder.Append("and RegionCode like '%"+ RegionCode + "%' ");
|
|
SqlParam[] para = new SqlParam[]
|
{
|
};
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(stringBuilder, para);
|
return ModelConvertHelper<Region>.ReaderToModel(dt);
|
}
|
|
return null;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
/// <summary>
|
/// 保存区域信息
|
/// </summary>
|
/// <param name="region"></param>
|
/// <param name="loginUser"></param>
|
/// <returns>true:成功 false:失败</returns>
|
public bool SetRegions(SetRegion region,string loginUser)
|
{
|
try
|
{
|
bool bl = false;
|
int rowCount = 0;
|
Hashtable ht = new Hashtable();
|
if (region.Operation == "Add")
|
{
|
ht["RegionCode"] = region.RegionCode.AddQuotes();
|
ht["RegionName"] = region.RegionName.AddQuotes();
|
ht["Demo"] = region.Demo.AddQuotes();
|
ht["CreatTime"] = "convert(varchar(20),getdate(),120)";
|
ht["CreatUser"] = loginUser.AddQuotes();
|
ht["UpdateTime"] = "convert(varchar(20),getdate(),120)";
|
ht["UpdateUser"] = loginUser.AddQuotes();
|
|
rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("Region", ht);
|
}
|
else
|
{
|
ht["RegionName"] = region.RegionName.AddQuotes();
|
ht["Demo"] = region.Demo.AddQuotes();
|
ht["UpdateTime"] = "convert(varchar(20),getdate(),120)";
|
ht["UpdateUser"] = loginUser.AddQuotes();
|
|
rowCount = DataFactory.SqlDataBase().UpdateByHashtable("Region",
|
"RegionCode", region.RegionCode.AddQuotes(), ht);
|
}
|
|
if (rowCount > 0)
|
{
|
bl = true;
|
}
|
|
return bl;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
/// <summary>
|
/// 删除区域(逻辑删除)
|
/// </summary>
|
/// <param name="regionCodes"></param>
|
/// <param name="loginUser"></param>
|
/// <returns>true:成功 false:失败</returns>
|
public bool DelRegions(string[] regionCodes, string loginUser)
|
{
|
try
|
{
|
bool bl = false;
|
int rowCount = 0;
|
Hashtable ht = new Hashtable();
|
foreach (string regionCode in regionCodes)
|
{
|
ht["IsDel"] = 1;
|
rowCount += DataFactory.SqlDataBase().UpdateByHashtable("Region",
|
"RegionCode", regionCode.AddQuotes(), ht);
|
}
|
|
if (rowCount > 0)
|
{
|
bl = true;
|
}
|
|
return bl;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
/// <summary>
|
/// 检查是否已存在
|
/// </summary>
|
/// <param name="region"></param>
|
/// <returns></returns>
|
public bool IsExist(SetRegion region)
|
{
|
try
|
{
|
bool bl = false;
|
StringBuilder stringBuilder = new StringBuilder();
|
stringBuilder.Append("select count(*) from Region where (RegionCode = "+region.RegionCode.AddQuotes());
|
stringBuilder.Append(" or RegionName = " + region.RegionName.AddQuotes()+") and isDel = 0 ");
|
if (region.Operation == "Edit")
|
{
|
stringBuilder.Append("and RegionCode != " + region.RegionCode.AddQuotes());
|
}
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
|
if (dt.Rows[0][0].ToString() != "0")
|
{
|
bl = true;
|
}
|
|
return bl;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
}
|
}
|