|
|
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
|
|
|
{
|
|
|
public class LocatePartDefineRepository : BaseRepository<SysLocatePart>, ILocatePartDefineRepository
|
|
|
{
|
|
|
public LocatePartDefineRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
|
|
|
{
|
|
|
}
|
|
|
#region 成员方法
|
|
|
/// <summary>
|
|
|
/// 获得菜单列表数据
|
|
|
/// </summary>
|
|
|
public List<SysLocatePart> getList(string strWhere, string filedOrder)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append(" select a.locate_id,a.locate_name,a.part_id,a.part_no,a.max_qty,a.min_qty,a.safety_qty,a.wip_min_qty,a.factory_id,a.factory_code,a.enabled,a.guid from sys_locate_part a ");
|
|
|
if (!string.IsNullOrEmpty(strWhere))
|
|
|
{
|
|
|
strSql.Append(" where " + strWhere);
|
|
|
}
|
|
|
if (filedOrder != null && !filedOrder.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" order by " + filedOrder);
|
|
|
}
|
|
|
List<SysLocatePart> result = dbConn.Query<SysLocatePart>(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 Params = new DynamicParameters();
|
|
|
Params.Add("@TotalCount", 0, DbType.Int32, ParameterDirection.Output);
|
|
|
Params.Add("@TotalPage", 0, DbType.Int32, ParameterDirection.Output);
|
|
|
Params.Add("@GroupColumn", "");
|
|
|
Params.Add("@Table", " sys_locate_part a left join sys_locate b on a.locate_id=b.locate_id left join sys_part c on a.part_id=c.part_id ");
|
|
|
Params.Add("@Column", " a.locate_id,a.locate_name,b.locate_desc ,a.part_id,a.part_no,c.part_spec,c.part_spec2,a.max_qty,a.min_qty,a.safety_qty,a.wip_min_qty,a.factory_id,a.factory_code,a.enabled,a.guid,a.safety_pull_order,case a.is_safety_pull when 1 then '否' else '是' end is_safety_pull ");
|
|
|
Params.Add("@PageSize", PageSize);
|
|
|
Params.Add("@CurrentPage", PageIndex);
|
|
|
Params.Add("@Condition", strWhere);
|
|
|
Params.Add("@OrderColumn", OrderBy);
|
|
|
Params.Add("@Group", 0);
|
|
|
List<SysLocatePart> dataList = dbConn.Query<SysLocatePart>("Com_Pagination", Params, commandType: CommandType.StoredProcedure).ToList();
|
|
|
result.Add("dataList", dataList);
|
|
|
result.Add("totalCount", Params.Get<int>("@TotalCount"));
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取下拉框菜单数据 这里显示的是待添加的厂区信息,厂区名称
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getSelectWarehouse(string factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select warehouse_id as [value],warehouse_desc as [key] from sys_warehouse where Enabled = 'Y' and factory_Id='" + factoryId + "'");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> getSelectZone(string warehouseId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select zone_id as [value],zone_name as [key] from sys_zone where Enabled = 'Y' and warehouse_Id='" + warehouseId + "'");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysWarehouse> getSelectWarehouseInfo(string warehouseId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_warehouse where warehouse_id='" + warehouseId + "' and Enabled = 'Y'");
|
|
|
List<SysWarehouse> result = dbConn.Query<SysWarehouse>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysZone> getSelectZoneInfo(string zone_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_zone where zone_id='" + zone_id + "' and Enabled = 'Y'");
|
|
|
List<SysZone> result = dbConn.Query<SysZone>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysLocate> getSelectLocateInfo(string strWhere)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("select * from sys_locate a");
|
|
|
if (!string.IsNullOrEmpty(strWhere))
|
|
|
{
|
|
|
strSql.Append(" where " + strWhere);
|
|
|
}
|
|
|
List<SysLocate> result = dbConn.Query<SysLocate>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
public List<SysLocatePart> getSelectLocatePartInfo(string strWhere)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("select * from sys_locate_part a");
|
|
|
if (!string.IsNullOrEmpty(strWhere))
|
|
|
{
|
|
|
strSql.Append(" where " + strWhere);
|
|
|
}
|
|
|
List<SysLocatePart> result = dbConn.Query<SysLocatePart>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 插入菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveLocatePart(SysLocatePart ht)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
StringBuilder SqlStringBuilder1 = new StringBuilder(1024);
|
|
|
SqlStringBuilder1.Append(" insert into sys_locate_part([locate_id],locate_name,[part_id],part_no,max_qty,min_qty,safety_qty,wip_min_qty,factory_id,factory_code,enabled,guid, create_userid, create_time) values ");
|
|
|
SqlStringBuilder1.Append(" (@locateId, @locateName, @PartId, @PartNo, @maxQty, @minQty, @safetyQty, @wipMinQty, @factoryId, @factoryCode, 'Y', newId(), @createUserid, CONVERT(VARCHAR(10), GETDATE(), 21)) ");
|
|
|
|
|
|
return dbConn.Execute(SqlStringBuilder1.ToString(), ht);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateLocatePart(SysLocatePart ht)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder1 = new StringBuilder(1024);
|
|
|
SqlStringBuilder1.Append(" UPDATE sys_locate_part set locate_name = @locateName, part_id = @partId, part_no = @partNo, ");
|
|
|
SqlStringBuilder1.Append(" max_qty = @maxQty, min_qty = @minQty, safety_qty = @safetyQty, wip_min_qty = @wipMinQty, factory_id = @factoryId, factory_code = @factoryCode, enabled = @enabled ,");
|
|
|
SqlStringBuilder1.Append(" update_userid = @updateUserid,update_time = CONVERT(varchar(50), GETDATE(), 21) where guid = @guid ");
|
|
|
|
|
|
return dbConn.Execute(SqlStringBuilder1.ToString(), ht);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteLocatePart(String guid)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_locate_part set Enabled='N' where guid = @guid";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@guid", guid);
|
|
|
return dbConn.Execute(delStr, htparams);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获得零件信息
|
|
|
/// </summary>
|
|
|
/// <param name="type">零件类型</param>
|
|
|
/// <returns></returns>
|
|
|
public List<SysPart> GetPartInfo(string part_no)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT part_id,part_no,part_spec,default_box_qty FROM sys_part (NOLOCK) WHERE enabled='Y' AND part_no LIKE '" + part_no + "%' ORDER BY part_no";
|
|
|
List<SysPart> result = dbConn.Query<SysPart>(sql).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysLocate> GetLocateInfo(string locateName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT locate_id,locate_name,locate_desc FROM sys_locate (NOLOCK) WHERE enabled='Y' AND locate_name LIKE '" + locateName + "%' ORDER BY locate_name";
|
|
|
List<SysLocate> result = dbConn.Query<SysLocate>(sql).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysLocate GetLocateInfoByName(string locateName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT locate_id,locate_name,locate_desc FROM sys_locate (NOLOCK) WHERE locate_name LIKE '" + locateName + "%'";
|
|
|
SysLocate result = dbConn.Query<SysLocate>(sql).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> GetLocateType()
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select enum_value [value],enum_desc as [key] from sys_enum where enum_type = 'sys_locate_type' and enabled='Y' ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> GetpartInfo()
|
|
|
{
|
|
|
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 = 0 and enabled='Y' ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//启用
|
|
|
public int EnableLocatePart(String guid)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_locate_part set Enabled='Y' WHERE guid = @guid";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@guid", guid);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//禁用
|
|
|
public int DisableLocatePart(String guid)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_locate_part set Enabled='N' WHERE guid = @guid";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@guid", guid);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
public SysLocate ifExistsLocatePart(string locateName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT b.* FROM sys_locate_part a left join sys_locate b on a.locate_id=b.locate_id WHERE a.locate_name = '" + locateName + "'";
|
|
|
SysLocate result = dbConn.Query<SysLocate>(sql).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysLocatePart ifExistsLocatePartByPartNo(string locateName, string partNo)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT * FROM sys_locate_part WHERE locate_name = '" + locateName + "' and part_no='"+partNo+"'";
|
|
|
SysLocatePart result = dbConn.Query<SysLocatePart>(sql).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysPart GetPartInfoByPartNo(string partNo)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT * FROM sys_part (NOLOCK) WHERE part_no = '" + partNo + "'";
|
|
|
SysPart result = dbConn.Query<SysPart>(sql).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<LocatePart> getExportList(string strwhere, string orderBy)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = @"SELECT a.locate_id,a.locate_name,b.locate_desc ,a.part_id,a.part_no,c.part_spec,c.part_spec2,isnull(a.max_qty,0.00000000) max_qty,
|
|
|
isnull(a.min_qty,0.00000000) min_qty,isnull(a.safety_qty,0.00000000) safety_qty,isnull(a.wip_min_qty,0.00000000) wip_min_qty,a.factory_id,a.factory_code,a.enabled,a.guid
|
|
|
FROM sys_locate_part a left join sys_locate b on a.locate_id=b.locate_id
|
|
|
left join sys_part c on a.part_id=c.part_id WHERE " + strwhere + orderBy;
|
|
|
List<LocatePart> result = dbConn.Query<LocatePart>(sql).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//事务批量执行添加、修改
|
|
|
public bool InsertData(List<string> sqlStrings, List<DynamicParameters> parameterList)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
if (dbConn.State == ConnectionState.Closed)
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
}
|
|
|
//执行事务
|
|
|
IDbTransaction transaction = dbConn.BeginTransaction();
|
|
|
if (parameterList == null || parameterList.Count == 0)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < sqlStrings.Count; i++)
|
|
|
{
|
|
|
dbConn.Execute(sqlStrings[i], null, transaction);
|
|
|
}
|
|
|
transaction.Commit();
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
transaction.Rollback();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < sqlStrings.Count; i++)
|
|
|
{
|
|
|
dbConn.Execute(sqlStrings[i], parameterList[i], transaction);
|
|
|
}
|
|
|
transaction.Commit();
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
transaction.Rollback();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion 成员方法
|
|
|
}
|
|
|
}
|