|
|
using Dapper;
|
|
|
using Estsh.Core.Dapper;
|
|
|
using Estsh.Core.IRepositories;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
using Estsh.Core.Util;
|
|
|
using System.Collections;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Repositories
|
|
|
{
|
|
|
public class DefectReasonRepository : BaseRepository<SysReason>, IDefectReasonRepository
|
|
|
{
|
|
|
public DefectReasonRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
|
|
|
{
|
|
|
}
|
|
|
string TABLE_NAME = "sys_reason";
|
|
|
string PK_NAME = "reason_id";
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据用户选择的条件查找不良原因
|
|
|
/// </summary>
|
|
|
/// <param name="wheres">筛选条件</param>
|
|
|
/// <returns>盘点数据</returns>
|
|
|
public Hashtable GetDefectReasonWhere(string wheres, Pager pager)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
Hashtable result = new Hashtable();
|
|
|
wheres += " and enabled='Y' ";
|
|
|
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_reason ");
|
|
|
parameters.Add( "@Column", " * ");
|
|
|
parameters.Add( "@OrderColumn", "reason_id");
|
|
|
parameters.Add( "@GroupColumn", "");
|
|
|
parameters.Add( "@PageSize", pager.pageSize);
|
|
|
parameters.Add( "@CurrentPage", pager.pageNo);
|
|
|
parameters.Add( "@Group", 0);
|
|
|
parameters.Add( "@Condition", wheres);
|
|
|
|
|
|
List<SysReason> defects = dbConn.Query<SysReason>("Com_Pagination", parameters, commandType: CommandType.StoredProcedure).ToList();
|
|
|
result.Add("dataList", defects);
|
|
|
result.Add("totalCount", parameters.Get<int>("@TotalCount"));
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public bool AddDefectReason(SysReason htParames)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO sys_reason (reason_code ");
|
|
|
SqlStringBuilder.Append(" , reason_level ");
|
|
|
SqlStringBuilder.Append(" , reason_desc ");
|
|
|
SqlStringBuilder.Append(" , reason_type ");
|
|
|
SqlStringBuilder.Append(" , enabled ");
|
|
|
SqlStringBuilder.Append(" , create_userid ");
|
|
|
SqlStringBuilder.Append(" , create_time ");
|
|
|
SqlStringBuilder.Append(" ) ");
|
|
|
SqlStringBuilder.Append(" VALUES(@reasonCode ");
|
|
|
SqlStringBuilder.Append(" , @reasonLevel ");
|
|
|
SqlStringBuilder.Append(" , @reasonDesc ");
|
|
|
SqlStringBuilder.Append(" , @reasonType ");
|
|
|
SqlStringBuilder.Append(" , @enabled ");
|
|
|
SqlStringBuilder.Append(" , @createUserid ");
|
|
|
SqlStringBuilder.Append(" , CONVERT(varchar(50), GETDATE(), 21) ");
|
|
|
SqlStringBuilder.Append(" )");
|
|
|
int row = dbConn.Execute(SqlStringBuilder.ToString(), htParames);
|
|
|
|
|
|
if (row > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public bool UpdateReason(SysReason htParames)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
|
|
|
SqlStringBuilder.Append("update sys_reason ");
|
|
|
SqlStringBuilder.Append("SET reason_code=@reasonCode ");
|
|
|
SqlStringBuilder.Append(", reason_level=@reasonLevel ");
|
|
|
SqlStringBuilder.Append(", reason_desc=@reasonDesc ");
|
|
|
SqlStringBuilder.Append(", reason_type=@reasonType ");
|
|
|
SqlStringBuilder.Append(",update_userid = @updateUserId ");
|
|
|
SqlStringBuilder.Append(",update_time = CONVERT(varchar(50), GETDATE(), 21)");
|
|
|
SqlStringBuilder.Append(", enabled=@enabled ");
|
|
|
SqlStringBuilder.Append("WHERE reason_id=@reasonId ");
|
|
|
int row = dbConn.Execute(SqlStringBuilder.ToString(), htParames);
|
|
|
|
|
|
if (row > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public bool DeleteReasonById(int reason_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sqlStr = string.Format("update {0} set Enabled='N' WHERE reason_id = {1} ", this.TABLE_NAME, reason_id);
|
|
|
int row = dbConn.Execute(sqlStr);
|
|
|
if (row > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//启用
|
|
|
public int EnableData(String ids)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_reason set Enabled='Y' WHERE reason_id in (" + ids + ")";
|
|
|
int result = dbConn.Execute(delStr);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//禁用
|
|
|
public int DisableData(String ids)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_reason set Enabled='N' WHERE reason_id in (" + ids + ")";
|
|
|
int result = dbConn.Execute(delStr);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|