|
|
using Dapper;
|
|
|
using Estsh.Core.Dapper;
|
|
|
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 PDLineDefineRepository : BaseRepository<SysPdline>, IPDLineDefineRepository
|
|
|
{
|
|
|
public PDLineDefineRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
|
|
|
{
|
|
|
}
|
|
|
#region 成员方法
|
|
|
/// <summary>
|
|
|
/// 获得菜单列表数据
|
|
|
/// </summary>
|
|
|
public List<SysPdline> getList(string strWhere, string filedOrder)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT * ");
|
|
|
strSql.Append("FROM sys_pdline where 1=1 ");
|
|
|
if (!strWhere.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" and " + strWhere);
|
|
|
}
|
|
|
if (filedOrder != null && !filedOrder.Trim().Equals(""))
|
|
|
{
|
|
|
strSql.Append(" order by " + filedOrder);
|
|
|
}
|
|
|
List<SysPdline> result = dbConn.Query<SysPdline>(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_pdline a ");
|
|
|
Params.Add("@Column", "*");
|
|
|
Params.Add("@PageSize", PageSize);
|
|
|
Params.Add("@CurrentPage", PageIndex);
|
|
|
Params.Add("@Condition", strWhere);
|
|
|
Params.Add("@OrderColumn", OrderBy);
|
|
|
Params.Add("@Group", 0);
|
|
|
List<SysPdline> dataList = dbConn.Query<SysPdline>("Com_Pagination", Params, commandType: CommandType.StoredProcedure).ToList();
|
|
|
result.Add("dataList", dataList);
|
|
|
result.Add("totalCount", Params.Get<int>("@TotalCount"));
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysZone> getSelectZone()
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_zone where Enabled = 'Y'");
|
|
|
List<SysZone> result = dbConn.Query<SysZone>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysLocate> getSelectLocate()
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_locate where Enabled = 'Y'");
|
|
|
List<SysLocate> result = dbConn.Query<SysLocate>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysWarehouse getSelectWarehouse(string warehouseName, int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_warehouse where warehouse_name = '" + warehouseName + "' and factory_id=" + factoryId + "");
|
|
|
SysWarehouse result = dbConn.Query<SysWarehouse>(strSql.ToString()).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysZone getSelectZone(string zoneName, int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_zone where zone_name = '" + zoneName + "' and factory_id=" + factoryId + "");
|
|
|
SysZone result = dbConn.Query<SysZone>(strSql.ToString()).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SysLocate getSelectLocate(string locateName, int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select * from sys_locate where locate_name = '" + locateName + "' and factory_id=" + factoryId + "");
|
|
|
SysLocate result = dbConn.Query<SysLocate>(strSql.ToString()).FirstOrDefault();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//线边
|
|
|
public List<KeyValueResult> getSelectSrcZone(int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select distinct a.zone_id as [value], a.zone_name as [key] from sys_zone a inner join sys_locate b on a.zone_id=b.zone_id " +
|
|
|
"and b.locate_type=40 and a.factory_Id=" + factoryId + " order by a.zone_name ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> getSelectSrcLocate(string zone_Id, int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select locate_id as [value],locate_name as [key] from sys_locate where Enabled = 'Y' and locate_type=40 and zone_id='" + zone_Id + "' and factory_Id=" + factoryId + " order by locate_name ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//成品 基础、机动、动态组合库、成品下线虚拟库位
|
|
|
public List<KeyValueResult> getSelectDestZone(int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select distinct a.zone_id as [value], a.zone_name as [key] from sys_zone a inner join sys_locate b on a.zone_id=b.zone_id " +
|
|
|
"and b.locate_type in (10,20,30,100) and a.factory_Id=" + factoryId + " order by a.zone_name ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> getSelectDestLocate(string zone_Id, int factoryId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select locate_id as [value],locate_name as [key] from sys_locate where Enabled = 'Y' and locate_type in (10,20,30,100) and zone_id='" + zone_Id + "' and factory_Id=" + factoryId + " order by locate_name ");
|
|
|
List<KeyValueResult> result = dbConn.Query<KeyValueResult>(strSql.ToString()).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 插入菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int savePdline(SysPdline htParams)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO dbo.sys_pdline( factory_id,factory_code,pdline_code ,pdline_name ,pdline_desc,src_zone_id,src_zone_name,src_locate_id,src_locate_name,dest_zone_id,dest_zone_name,dest_locate_id,dest_locate_name ,enabled , create_userid, create_time,guid,src_Warehouse_Id,src_Warehouse_Name,dest_Warehouse_Id,dest_Warehouse_name,part_prepare)VALUES ");
|
|
|
SqlStringBuilder.Append("(@factoryId,@factoryCode,@pdlineCode,@pdlineName,@pdlineDesc,@srcZoneId,@srcZoneName,@srcLocateId,@srcLocateName,@destZoneId,@destZoneName,@destLocateId,@destLocateName,@enabled, @createUserid, CONVERT(varchar(50), GETDATE(), 21),newid(),@srcWarehouseId,@srcWarehouseName,@destWarehouseId,@destWarehouseName,@partPrepare) ");
|
|
|
|
|
|
int result = dbConn.Execute(SqlStringBuilder.ToString(), htParams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updatePdline(SysPdline htParams)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("UPDATE sys_pdline SET ");
|
|
|
SqlStringBuilder.Append("pdline_code=@pdlineCode,pdline_name=@pdlineName,pdline_desc=@pdlineDesc,factory_id=@factoryId,enabled=@enabled");
|
|
|
SqlStringBuilder.Append(" ,src_zone_id=@srcZoneId,src_zone_name=@srcZoneName,src_locate_id=@srcLocateId,src_locate_name=@srcLocateName," +
|
|
|
"dest_zone_id=@destZoneId,dest_zone_name=@destZoneName,dest_locate_id=@destLocateId,dest_locate_name=@destLocateName," +
|
|
|
"dest_Warehouse_Id=@destWarehouseId,dest_Warehouse_Name=@destWarehouseName,src_Warehouse_Id=@srcWarehouseId,src_Warehouse_Name=@srcWarehouseName ");
|
|
|
SqlStringBuilder.Append(" ,update_userid = @updateUserId ");
|
|
|
SqlStringBuilder.Append(" ,update_time = CONVERT(varchar(50), GETDATE(), 21)");
|
|
|
SqlStringBuilder.Append("WHERE pdline_id=@pdlineId ");
|
|
|
|
|
|
int result = dbConn.Execute(SqlStringBuilder.ToString(), htParams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteMenu(String pdline_id)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_pdline set Enabled='N' WHERE pdline_id = @pdline_id";
|
|
|
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@pdline_id", pdline_id);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//启用
|
|
|
public int EnablePdLine(String pdlineId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_pdline set Enabled='Y' WHERE pdline_id = @pdlineId";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@pdlineId", pdlineId);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//禁用
|
|
|
public int DisablePdline(String pdlineId)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
String delStr = "update sys_pdline set Enabled='N' WHERE pdline_id = @pdlineId";
|
|
|
DynamicParameters htparams = new DynamicParameters();
|
|
|
htparams.Add("@pdlineId", pdlineId);
|
|
|
int result = dbConn.Execute(delStr, htparams);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SysPdline> ifExistsPdLine(string pdlineCode, string srcZoneName, string destZoneName, string destLocateName)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT * FROM sys_pdline (NOLOCK) WHERE pdline_code='" + pdlineCode + "' and src_zone_name='" + srcZoneName + "' and dest_Zone_name='" + destZoneName + "' and dest_locate_name='" + destLocateName + "' ";
|
|
|
List<SysPdline> result = dbConn.Query<SysPdline>(sql).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<PDLineDefine> getExportList(string strwhere, string orderBy)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
string sql = "SELECT * FROM sys_pdline a (NOLOCK) WHERE " + strwhere + orderBy;
|
|
|
List<PDLineDefine> result = dbConn.Query<PDLineDefine>(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 成员方法
|
|
|
}
|
|
|
}
|