|
|
using Dapper;
|
|
|
using Estsh.Core.Dapper;
|
|
|
using Estsh.Core.IRepositories;
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
using System.Collections;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:客户管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Repositories
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 处理菜单模块的业务数据
|
|
|
/// </summary>
|
|
|
public class CustomerRepository : BaseRepository<SysCustomer>, ICustomerRepository
|
|
|
{
|
|
|
public CustomerRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
|
|
|
{
|
|
|
}
|
|
|
#region 成员方法
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据传入条件获得菜单列表数据
|
|
|
/// </summary>
|
|
|
public List<SysCustomer> getList(string strWhere, string filedOrder)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append(" select * from dbo.sys_customer ");
|
|
|
if (strWhere != null && !strWhere.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" where " + strWhere);
|
|
|
}
|
|
|
if (filedOrder != null && !filedOrder.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" order by " + filedOrder);
|
|
|
}
|
|
|
List<SysCustomer> result = dbConn.Query<SysCustomer>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页数据列表
|
|
|
/// </summary>
|
|
|
public Hashtable getListByPage(int PageSize, int PageIndex, string strWhere, string OrderBy)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
Hashtable result = new Hashtable();
|
|
|
DynamicParameters parameters = new DynamicParameters();
|
|
|
parameters.Add("@TotalCount", 0, DbType.Int32, ParameterDirection.Output);
|
|
|
parameters.Add("@TotalPage", 0, DbType.Int32, ParameterDirection.Output);
|
|
|
parameters.Add("@Table", "dbo.sys_customer a");
|
|
|
parameters.Add("@Column", "*");
|
|
|
parameters.Add("@OrderColumn", OrderBy);
|
|
|
parameters.Add("@GroupColumn", "");
|
|
|
parameters.Add("@PageSize", PageSize);
|
|
|
parameters.Add("@CurrentPage", PageIndex);
|
|
|
parameters.Add("@Group", 0);
|
|
|
parameters.Add("@Condition", strWhere);
|
|
|
|
|
|
List<SysCustomer> depts = dbConn.Query<SysCustomer>("Com_Pagination", parameters, commandType: CommandType.StoredProcedure).ToList();
|
|
|
result.Add("dataList", depts);
|
|
|
result.Add("totalCount", parameters.Get<int>("@TotalCount"));
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 插入供应商数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveCustomer(SysCustomer htParams)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO sys_customer (customer_code ");
|
|
|
SqlStringBuilder.Append(" , customer_name ");
|
|
|
SqlStringBuilder.Append(" ,customer_tel ");
|
|
|
SqlStringBuilder.Append(" , customer_addr ");
|
|
|
SqlStringBuilder.Append(" ,factory_id ");
|
|
|
SqlStringBuilder.Append(" , factory_code ");
|
|
|
SqlStringBuilder.Append(" ,enabled ");
|
|
|
SqlStringBuilder.Append(" , create_userid ");
|
|
|
SqlStringBuilder.Append(" , create_time ");
|
|
|
SqlStringBuilder.Append(" , guid) ");
|
|
|
SqlStringBuilder.Append(" VALUES(@customerCode ");
|
|
|
SqlStringBuilder.Append(" , @customerName ");
|
|
|
SqlStringBuilder.Append(" ,@customerTel");
|
|
|
SqlStringBuilder.Append(" ,@customerAddr ");
|
|
|
SqlStringBuilder.Append(" ,@factoryId ");
|
|
|
SqlStringBuilder.Append(" ,@factoryCode ");
|
|
|
SqlStringBuilder.Append(" ,@enabled ");
|
|
|
SqlStringBuilder.Append(" ,@createUserid ");
|
|
|
SqlStringBuilder.Append(" ,CONVERT(varchar(50), GETDATE(), 21)");
|
|
|
SqlStringBuilder.Append(" ,newid()) ");
|
|
|
int result = dbConn.Execute(SqlStringBuilder.ToString(), htParams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateCustomer(SysCustomer htParams)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("update sys_customer ");
|
|
|
SqlStringBuilder.Append("SET customer_code=@customerCode ");
|
|
|
SqlStringBuilder.Append(" , customer_name=@customerName ");
|
|
|
SqlStringBuilder.Append(" , customer_tel=@customerTel ");
|
|
|
SqlStringBuilder.Append(" , customer_addr=@customerAddr ");
|
|
|
SqlStringBuilder.Append(" , factory_id=@factoryId ");
|
|
|
SqlStringBuilder.Append(" , factory_code=@factoryCode ");
|
|
|
SqlStringBuilder.Append(" , enabled=@enabled ");
|
|
|
SqlStringBuilder.Append(" , update_userid=@updateUserid ");
|
|
|
SqlStringBuilder.Append(" , update_time=CONVERT(varchar(50), GETDATE(), 21)");
|
|
|
SqlStringBuilder.Append("WHERE customer_id=@customerId ");
|
|
|
|
|
|
int result = dbConn.Execute(SqlStringBuilder.ToString(), htParams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteCustomer(String customer_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@customer_id", customer_id);
|
|
|
String delStr = "update sys_customer set Enabled='N' where customer_id = @customer_id";
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysCustomer getCustomerByExistName(string customerCode)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_customer where customer_code='" + customerCode + "'");
|
|
|
SysCustomer result = dbConn.Query<SysCustomer>(strSql.ToString()).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取下拉框菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getSelectCustomer()
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select part_id as [value] ,part_no as [key] from sys_part where part_type = '1' and enabled='Y' ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//启用
|
|
|
public int EnableCustomer(String customer_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_customer set Enabled='Y' WHERE customer_id = @customer_id";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@customer_id", customer_id);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//禁用
|
|
|
public int DisableCustomer(String customer_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_customer set Enabled='N' WHERE customer_id = @customer_id";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@customer_id", customer_id);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
public List<Customer> getExportList(String strWhere, String orderBy)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append(" select * from dbo.sys_customer where "+ strWhere+ orderBy);
|
|
|
List<Customer> result = dbConn.Query<Customer>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
#endregion 成员方法
|
|
|
}
|
|
|
}
|