|
|
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 LocateDefineRepository : BaseRepository<SysLocate>, ILocateDefineRepository
|
|
|
{
|
|
|
public LocateDefineRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
|
|
|
{
|
|
|
}
|
|
|
#region 成员方法
|
|
|
/// <summary>
|
|
|
/// 获得菜单列表数据
|
|
|
/// </summary>
|
|
|
public List<SysLocate> 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,sp.part_no ,a.enabled,a.locate_type,a.locate_desc,a.locate_capacity, a.warehouse_name,a.warehouse_id,a.zone_id,a.zone_name,lp.part_no from sys_locate a left join sys_locate_part ab on a.locate_id=ab.locate_id left join sys_part sp on sp.part_id=ab.part_id left join sys_locate_part lp on a.locate_name=lp.locate_name where a.enabled='Y' ");
|
|
|
if (!strWhere.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" and " + strWhere);
|
|
|
}
|
|
|
if (filedOrder != null && !filedOrder.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" order by " + filedOrder);
|
|
|
}
|
|
|
List<SysLocate> result = dbConn.Query<SysLocate>(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 a left join sys_zone b on a.zone_id=b.zone_id left join sys_warehouse c on a.warehouse_id=c.warehouse_id left join sys_enum m on a.locate_type=m.enum_value and enum_type = 'sys_locate_type' left join sys_locate_part lp on a.locate_name=lp.locate_name ");
|
|
|
Params.Add("@Column", "a.locate_id,a.locate_name,a.enabled,a.locate_type,a.locate_desc,a.locate_capacity,a.locate_empty, a.warehouse_name,a.warehouse_id,a.zone_id,a.zone_name,b.zone_desc,c.warehouse_desc,m.enum_desc as locate_typeDesc,lp.part_no ");
|
|
|
Params.Add("@PageSize", PageSize);
|
|
|
Params.Add("@CurrentPage", PageIndex);
|
|
|
Params.Add("@Condition", strWhere);
|
|
|
Params.Add("@OrderColumn", OrderBy);
|
|
|
Params.Add("@Group", 0);
|
|
|
List<SysLocate> dataList = dbConn.Query<SysLocate>("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(int 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 + "' order by zone_name");
|
|
|
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 SysWarehouse getSelectWarehouseInfoByName(string warehouseName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_warehouse where warehouse_name='" + warehouseName + "'");
|
|
|
SysWarehouse result = dbConn.Query<SysWarehouse>(strSql.ToString()).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
public SysLocate getlocateByExistName(string locateName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_locate where locate_name='" + locateName + "' and Enabled = 'Y'");
|
|
|
SysLocate result = dbConn.Query<SysLocate>(strSql.ToString()).FirstOrDefault();
|
|
|
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 SysZone getSelectZoneInfoByName(string zone_name)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_zone where zone_name='" + zone_name + "'");
|
|
|
SysZone result = dbConn.Query<SysZone>(strSql.ToString()).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 插入菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveLocate(SysLocate htParams, bool flag, SysLocatePart ht)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO dbo.sys_locate(locate_name ,locate_desc,locate_capacity,warehouse_id,warehouse_name,zone_id,zone_name ,enabled,factory_id,factory_code,guid,create_userid,create_time,locate_type)VALUES ");
|
|
|
SqlStringBuilder.Append("(@locateName,@locateDesc,@LocateCapacity,@warehouseId,@warehouseName,@zoneId,@zoneName,@enabled, @factoryId, @factoryCode,newid(),@createUserid,CONVERT(varchar(50), GETDATE(), 21),@locateType) ");
|
|
|
dbConn.Execute(SqlStringBuilder.ToString(), htParams);
|
|
|
if (flag)
|
|
|
{
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_locate_part where locate_name='" + htParams.LocateName + "' and Enabled = 'Y'");
|
|
|
List<SysLocatePart> locateList = dbConn.Query<SysLocatePart>(strSql.ToString()).ToList();
|
|
|
if (locateList.Count > 0)
|
|
|
{
|
|
|
SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("UPDATE dbo.sys_locate_part ");
|
|
|
SqlStringBuilder.Append(" SET locate_id = (select locate_id from sys_locate where locate_name = @LocateName) ");
|
|
|
SqlStringBuilder.Append(" ,locate_name = @locateName,part_id = @PartId ");
|
|
|
SqlStringBuilder.Append(" ,part_no = @PartNo,factory_id = @factoryId ");
|
|
|
SqlStringBuilder.Append(" ,factory_code = @factoryCode,enabled = 'Y' ");
|
|
|
SqlStringBuilder.Append(" ,update_userid = @createUserid ");
|
|
|
SqlStringBuilder.Append(" ,update_time = CONVERT(varchar(50), GETDATE(), 21) ");
|
|
|
SqlStringBuilder.Append(" WHERE locate_name=@locateName ");
|
|
|
dbConn.Execute(SqlStringBuilder.ToString(), ht);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder1 = new StringBuilder(1024);
|
|
|
SqlStringBuilder1.Append(" insert into sys_locate_part([locate_id],locate_name,[part_id],part_no,[enabled],factory_id,factory_code,guid, create_userid, create_time) values((select locate_id from sys_locate where locate_name = @LocateName),@locateName,@PartId,@PartNo,'Y', @factoryId, @factoryCode, newid(),@createUserid, CONVERT(varchar(50), GETDATE(), 21)) ");
|
|
|
dbConn.Execute(SqlStringBuilder1.ToString(), ht);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateLocate(SysLocate htParams, bool flag, SysLocatePart ht)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("UPDATE sys_locate SET ");
|
|
|
SqlStringBuilder.Append("locate_name=@locateName,locate_desc=@locateDesc,locate_type=@locateType,locate_capacity=@LocateCapacity,warehouse_id=@warehouseId,warehouse_Name=@warehouseName,zone_id=@zoneId,zone_name=@zoneName,enabled=@enabled, factory_id = @factoryId, factory_code = @factoryCode,update_userid=@updateUserid,update_time=CONVERT(varchar(50), GETDATE(), 21) ");
|
|
|
SqlStringBuilder.Append("WHERE locate_id=@locateId ");
|
|
|
|
|
|
dbConn.Execute(SqlStringBuilder.ToString(), htParams);
|
|
|
if (flag)
|
|
|
{
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_locate_part where locate_id='" + htParams.LocateId + "'");
|
|
|
List<SysLocatePart> locateList = dbConn.Query<SysLocatePart>(strSql.ToString()).ToList();
|
|
|
if (locateList.Count>0)
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder1 = new StringBuilder(1024);
|
|
|
SqlStringBuilder1.Append(" UPDATE sys_locate_part set locate_name=@locateName,part_id=@partId,part_no=@partNo, factory_id = @factoryId, factory_code = @factoryCode,update_userid=@updateUserid,update_time=CONVERT(varchar(50), GETDATE(), 21) where locate_id=@locateId ");
|
|
|
dbConn.Execute(SqlStringBuilder1.ToString(), ht);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder1 = new StringBuilder(1024);
|
|
|
SqlStringBuilder1.Append(" insert into sys_locate_part([locate_id],locate_name,[part_id],part_no,[enabled],factory_id,factory_code,guid, create_userid, create_time) values((select locate_id from sys_locate where locate_name = @LocateName),@locateName,@PartId,@PartNo,'Y', @factoryId, @factoryCode, newid(),@createUserid, CONVERT(varchar(50), GETDATE(), 21)) ");
|
|
|
dbConn.Execute(SqlStringBuilder1.ToString(), ht);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder2 = new StringBuilder(1024);
|
|
|
SqlStringBuilder2.Append(" delete from sys_locate_part where locate_id='" + htParams.LocateId + "' ");
|
|
|
dbConn.Execute(SqlStringBuilder2.ToString(), ht);
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteLocate(String locate_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_locate set Enabled='N' where locate_id = @locateId";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@locateId", locate_id);
|
|
|
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<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' order by enum_seq");
|
|
|
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 EnableLocate(String locate_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_locate set Enabled='Y' WHERE locate_id = @locateId";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@locateId", locate_id);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//禁用
|
|
|
public int DisableLocate(String locate_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_locate set Enabled='N' WHERE locate_id = @locateId";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@locateId", locate_id);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
public SysLocate ifExistsLocate(string locateName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT * FROM sys_locate (NOLOCK) WHERE locate_name = '" + locateName + "'";
|
|
|
SysLocate result = dbConn.Query<SysLocate>(sql).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
public List<LocateDefine> getExportList(string strwhere, string orderBy)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("SELECT a.locate_name,a.locate_desc,b.enum_name as locate_type,a.locate_capacity,a.max_locate_qty,a.warehouse_name,a.zone_name ");
|
|
|
SqlStringBuilder.Append("FROM sys_locate a left join sys_enum b on enum_type like '%sys_locate_type%' and a.locate_type=b.enum_value WHERE " + strwhere + orderBy);
|
|
|
List<LocateDefine> result = dbConn.Query<LocateDefine>(SqlStringBuilder.ToString()).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 成员方法
|
|
|
}
|
|
|
}
|