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
{
///
/// 获取区域集合
///
///
///
///
public IList 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 list = ModelConvertHelper.DataTableToModel(dt);
return list;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetRegionItems()
{
try
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("select * from View_Region_UserInfo where IsDel = '0' ");
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
return ModelConvertHelper.DataTableToModel(dt);
}
catch
{
throw new NotImplementedException();
}
}
///
/// 获取指定区域信息
///
///
///
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.ReaderToModel(dt);
}
return null;
}
catch
{
throw new NotImplementedException();
}
}
///
/// 保存区域信息
///
///
///
/// true:成功 false:失败
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();
}
}
///
/// 删除区域(逻辑删除)
///
///
///
/// true:成功 false:失败
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();
}
}
///
/// 检查是否已存在
///
///
///
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();
}
}
}
}