using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Model;
|
using Common;
|
using System.Data;
|
using System.Collections;
|
|
namespace BLL
|
{
|
public class DALCustomer : IDALCustomer
|
{
|
public IList<Customer> GetList()
|
{
|
try
|
{
|
IList<Customer> ls = new List<Customer>();
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("Select RoleName from Roles where IsDel !=1");
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
|
ls = ModelConvertHelper<Customer>.DataReaderToModel(dt);
|
|
return ls;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
public IList<Customer> GetList(AjaxCustomerList Json,ref PageInfo page)
|
{
|
try
|
{
|
|
IList<Customer> list = new List<Customer>();
|
StringBuilder strSql = new StringBuilder();
|
List<SqlParam> para = new List<SqlParam>();
|
strSql.Append("Select Id,CusNum,CusName,Contacts,Phone,Mobile,Fax,Email,Address,IsDel,CusType,CreatUser,CreatTime,guid,Demo,(case Enable when '1' then '启用' when '0' then '停用' end)Enable from Customer ");
|
|
if (!string.IsNullOrEmpty(Json.CusNum))
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("CusNum like '%' + @CusNum + '%' ");
|
para.Add(new SqlParam("@CusNum", Json.CusNum));
|
}
|
|
if (!string.IsNullOrEmpty(Json.CusName))
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("CusName like '%' + @CusName + '%' ");
|
para.Add(new SqlParam("@CusName", Json.CusName));
|
}
|
|
if (!string.IsNullOrEmpty(Json.CusType))
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("CusType like '%' + @CusType + '%' ");
|
para.Add(new SqlParam("@CusType", Json.CusType));
|
}
|
|
if (!string.IsNullOrEmpty(Json.Enable))
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("Enable like '%' + @Enable + '%' ");
|
para.Add(new SqlParam("@Enable", Json.Enable== "启用" ? "1":"0"));
|
}
|
|
|
if (!string.IsNullOrEmpty(Json.Address))
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("Address like '%' + @Address + '%' ");
|
para.Add(new SqlParam("@Address", Json.Address));
|
}
|
|
if (!string.IsNullOrEmpty(Json.Phone))
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("Phone like '%' + @Phone + '%' ");
|
para.Add(new SqlParam("@Phone", Json.Phone));
|
}
|
|
|
SqlParam[] param = null;
|
if (para != null)
|
param = para.ToArray();
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "id", "DESC", ref page);
|
list = ModelConvertHelper<Customer>.DataTableToModel(dt);
|
|
return list;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
|
}
|
|
|
public Customer GetModel(string CusNum)
|
{
|
try
|
{
|
Customer us = null;
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("Select CusNum,CusName,Contacts,Phone,Mobile,Fax,Email,Address,IsDel,CusType,CreatUser,CreatTime,guid,Demo,Enable from Customer where ");
|
strSql.Append("CusNum like '%' + @CusNum + '%' ");
|
strSql.Append("and IsDel != 1");
|
SqlParam[] para = new SqlParam[]
|
{
|
new SqlParam("@CusNum", CusNum),
|
};
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
|
|
us = ModelConvertHelper<Customer>.ReaderToModel(dt);
|
|
return us;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
|
public bool Add(Customer model)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
ht["CusNum"] = string.IsNullOrEmpty(model.CusNum) ? "''" : "'" + model.CusNum + "'";
|
ht["CusName"] = string.IsNullOrEmpty(model.CusNum) ? "''" : "'" + model.CusName + "'";
|
ht["Contacts"] = "'" + model.Contacts + "'";
|
ht["Phone"] = "'" + model.Phone + "'";
|
ht["Mobile"] = "'" + model.Mobile + "'";
|
ht["Fax"] = "'" + model.Fax + "'";
|
ht["Email"] = "'" + model.Email + "'";
|
ht["CusType"] = "'" + model.CusType + "'";
|
ht["Enable"] = "'" + "1"+ "'";
|
ht["Address"] = "'" + model.Address + "'";
|
ht["IsDel"] = 0;
|
ht["CreatUser"] = "'" + model.CreatUser + "'";
|
ht["CreatTime"] = "GetDate()";
|
ht["Demo"] = "'" + model.Demo + "'";
|
ht["guid"] = "NEWID()";
|
|
int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("Customer", ht);
|
|
if (_ret == 1) result = true;
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public bool Update(Customer model)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
ht["CusName"] = string.IsNullOrEmpty(model.CusName) ? "''" : "'" + model.CusName + "'";
|
ht["Contacts"] = string.IsNullOrEmpty(model.Contacts) ? "''" : "'" + model.Contacts + "'";
|
ht["Phone"] = string.IsNullOrEmpty(model.Phone) ? "''" : "'" + model.Phone + "'";
|
ht["Mobile"] = string.IsNullOrEmpty(model.Mobile) ? "''" : "'" + model.Mobile + "'";
|
ht["Fax"] = string.IsNullOrEmpty(model.Fax) ? "''" : "'" + model.Fax + "'";
|
ht["Email"] = string.IsNullOrEmpty(model.Email) ? "''" : "'" + model.Email + "'";
|
ht["CusType"] = string.IsNullOrEmpty(model.CusType) ? "''" : "'" + model.CusType + "'";
|
ht["Enable"] = string.IsNullOrEmpty(model.Enable) ? "''" : "'" + model.Enable + "'";
|
ht["Address"] = string.IsNullOrEmpty(model.Address) ? "''" : "'" + model.Address + "'";
|
ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'";
|
|
string CusNum = "'" + model.CusNum + "'";
|
|
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Customer", nameof(model.CusNum), CusNum, ht);
|
|
if (_ret == 1) result = true;
|
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
public bool IsExist(string name, string value)
|
{
|
bool result = false;
|
try
|
{
|
string[] para = new string[] { value };
|
int dt = DataFactory.SqlDataBase().IsExist("Customer", name, para);
|
if (dt > 0) result = true;
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
|
}
|
|
public DataTable GetDataTable(string[] strWhere)
|
{
|
DataTable dt = null;
|
try
|
{
|
int index = 0;
|
string str = "@RoleNum" + index;
|
SqlParam[] param = new SqlParam[strWhere.Length];
|
StringBuilder sql = new StringBuilder();
|
sql.Append("Select RoleNum as 角色编号, RoleName as 角色名,CreatUser as 创建人,CreatTime as 创建时间,UpdateUser as 更新人,UpdateTime as 更新时间,Demo as 备注 FROM View_GetRoles where RoleNum in (");
|
|
for (int i = 0; i < param.Length - 1; i++)
|
{
|
string obj2 = strWhere[i];
|
str = "@RoleNum" + index;
|
sql.Append(str).Append(",");
|
param[index] = new SqlParam(str, obj2);
|
index++;
|
}
|
str = "@RoleNum" + index;
|
sql.Append(str);
|
param[index] = new SqlParam(str, strWhere[index]);
|
sql.Append(")");
|
|
dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql, param, "");
|
|
return dt;
|
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
|
}
|
public bool BatchDelete(string[] CusNum)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("Customer", "CusNum", CusNum);
|
if (dt >= CusNum.Length)
|
{
|
int _ret = DataFactory.SqlDataBase().BatchDeleteData("Customer", "CusNum", CusNum);
|
if (_ret >= CusNum.Length) result = true;
|
}
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public bool UpdateEnable(string[] CusNum,string Enable)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("Customer", "CusNum", CusNum);
|
if (dt >= CusNum.Length)
|
{
|
Hashtable ht = new Hashtable();
|
//\
|
// string value = Enable == "启用" ? "1" : (Enable == "停用" ? "0" : "1");
|
ht["Enable"] = string.IsNullOrEmpty(Enable) ? "''" : "'" + Enable + "'"; ;
|
|
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Customer", "CusNum", CusNum,ht);
|
if (_ret >= CusNum.Length) result = true;
|
}
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
}
|
}
|