|
|
using Estsh.Core.Dapper;
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
using Estsh.Core.Services.IServices;
|
|
|
using Estsh.Core.Util;
|
|
|
using System.Collections;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:零件关键数据
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
|
|
|
public class PartKeyDataDefineService : BaseService<SysPartKeydata>, IPartKeyDataDefineService
|
|
|
{
|
|
|
private readonly IPartKeyDataDefineRepository repository;
|
|
|
|
|
|
public PartKeyDataDefineService(IPartKeyDataDefineRepository _repository) : base(_repository)
|
|
|
{
|
|
|
repository = _repository;
|
|
|
}
|
|
|
/// 根据查询条件得出结果集
|
|
|
/// </summary>
|
|
|
/// <param name="aWhere">查询条件</param>
|
|
|
/// <returns>符合条件的结果集</returns>
|
|
|
//public ArrayList GetQuery(string aWhere, ref DataTable dt)
|
|
|
//{
|
|
|
// return repository.GetQuery(aWhere, ref dt);
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="AdjustOrderName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable GetQuery(String part_no, Pager pager, String direction, String sort, String txtProcessName, String txtKeyDataName, string cbPdline,String enabled)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
string strWhere = " 1=1 ";
|
|
|
if (!string.IsNullOrEmpty(part_no))
|
|
|
{
|
|
|
strWhere = " AND b.part_no LIKE '%" + part_no + "%' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(txtProcessName))
|
|
|
{
|
|
|
strWhere += " AND c.process_id LIKE '%" + txtProcessName + "%' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(txtKeyDataName))
|
|
|
{
|
|
|
strWhere += " AND d.keydata_id LIKE '%" + txtKeyDataName + "%' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(cbPdline))
|
|
|
{
|
|
|
strWhere += " AND e.pdline_id LIKE '%" + cbPdline + "%' ";
|
|
|
}
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.enabled = '" + enabled + "'";
|
|
|
}
|
|
|
|
|
|
|
|
|
result = repository.GetQuery(strWhere, pager.pageSize, pager.pageNo);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断数据是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="aPartID">零件ID</param>
|
|
|
/// <param name="aProcessID">制程ID</param>
|
|
|
/// <param name="aKeyDataID">关键数据ID</param>
|
|
|
/// <returns></returns>
|
|
|
public bool GetpartKeyData(string aPartID, string aProcessID, string aKeyDataID)
|
|
|
{
|
|
|
return repository.GetpartKeyData(aPartID, aProcessID, aKeyDataID);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取零件号信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> GetPartID()
|
|
|
{
|
|
|
return repository.GetPartID();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取制程信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> GetProcessID()
|
|
|
{
|
|
|
return repository.GetProcessID();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取关键数据信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> GetKeyDataID()
|
|
|
{
|
|
|
return repository.GetKeyDataID();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///更改可用状态
|
|
|
/// </summary>
|
|
|
/// <param name="status">true or false</param>
|
|
|
/// <param name="dr">当前行</param>
|
|
|
/// <returns></returns>
|
|
|
public bool ChangeDetailStatus(bool status, DataRow dr)
|
|
|
{
|
|
|
return repository.ChangeDetailStatus(status, dr);
|
|
|
|
|
|
}
|
|
|
|
|
|
public int DeleteDetail(string guid)
|
|
|
{
|
|
|
return repository.DeleteDetail(guid);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int EnableData(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.EnableData(ids);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableData(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.DisableData(ids);
|
|
|
}
|
|
|
public List<SysPartKeydata> GetRow(string aWhere)
|
|
|
{
|
|
|
return repository.GetRow(aWhere);
|
|
|
}
|
|
|
|
|
|
public int insert(string part_no, string process_id, string keydata_id, string item_count, string torque_command)
|
|
|
{
|
|
|
return repository.insert(part_no, process_id, keydata_id, item_count, torque_command);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新关键数据和零件关系
|
|
|
/// </summary>
|
|
|
/// <param name="guid">guid</param>
|
|
|
/// <param name="processid">制程编号</param>
|
|
|
/// <param name="partid">零件编号</param>
|
|
|
/// <param name="keydataid">关键数据编号</param>
|
|
|
/// <param name="itemvalue">用量</param>
|
|
|
/// <returns></returns>
|
|
|
public bool UpdateKeyData(string guid, string processid, string partNo, string keydataid, string itemvalue, string torque_command)
|
|
|
{
|
|
|
return repository.UpdateKeyData(guid, processid, partNo, keydataid, itemvalue, torque_command);
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新扭矩发送指令
|
|
|
/// </summary>
|
|
|
/// <param name="partNo">零件号</param>
|
|
|
/// <param name="processid">制程ID</param>
|
|
|
/// <param name="keydataid">关键数据编号</param>
|
|
|
/// <param name="torque_command">扭矩发送指令</param>
|
|
|
public int UpdateTorqueCommand(string partNo, string processid, string keydataid, string torque_command)
|
|
|
{
|
|
|
return repository.UpdateTorqueCommand( partNo, processid, keydataid, torque_command);
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="menuName">查询条件</param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction">排序方式</param>
|
|
|
/// <param name="sort">排序字段</param>
|
|
|
/// <returns></returns>
|
|
|
public List<PartKeyDataDefine> getTableListByPage(String part_no, String enabled_search, Pager pager, String direction, String sort, Boolean isPage)
|
|
|
{
|
|
|
List<PartKeyDataDefine> result = null;
|
|
|
int rowCount = 0;
|
|
|
string strWhere = "";
|
|
|
if (!string.IsNullOrEmpty(part_no))
|
|
|
{
|
|
|
strWhere = " AND b.part_no LIKE '%" + part_no + "%' and b.enabled = 'Y' ";
|
|
|
}
|
|
|
|
|
|
if (isPage)
|
|
|
{
|
|
|
rowCount = pager.pageSize;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
rowCount = pager.pageSize;
|
|
|
}
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(SysWebMenu).GetEntityColumnName(sort.Trim()) + " " ;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += typeof(SysWebMenu).GetEntityColumnName("MenuId") + " " ;
|
|
|
}
|
|
|
|
|
|
result = repository.getTableListByPage(rowCount, pager.pageNo, strWhere, orderBy);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取文件并更新至数据库
|
|
|
/// </summary>
|
|
|
/// <param name="inputStream">文件全路径</param>
|
|
|
/// <param name="userInfo">登录用户信息</param>
|
|
|
public Hashtable ImportExcel(List<PartKeyDataDefine> inputStream, int userId)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
Hashtable Cache = new Hashtable();
|
|
|
|
|
|
|
|
|
if (inputStream == null || inputStream.Count == 0)
|
|
|
{
|
|
|
result.Add("message", "导入数据为空,请重新导入");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
string partNo = string.Empty;
|
|
|
string processName = string.Empty;
|
|
|
string terminalName = string.Empty;
|
|
|
int qty;
|
|
|
string keydataName = string.Empty;
|
|
|
string torqueCommand = string.Empty;
|
|
|
StringBuilder ErrorMessage = new StringBuilder(1024);
|
|
|
// 验证数据
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < inputStream.Count; i++)
|
|
|
{
|
|
|
partNo = inputStream[i].PartNo.ToString().Trim();
|
|
|
|
|
|
// 跳过空行
|
|
|
if (string.IsNullOrEmpty(partNo))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//判断零件号是否存在
|
|
|
int partID = repository.GetPartID(partNo);
|
|
|
if (partID == 0)
|
|
|
{
|
|
|
ErrorMessage.Append("零件号 " + partNo + " 不存在!" + Environment.NewLine);
|
|
|
}
|
|
|
|
|
|
// 判断制程名称是否存在
|
|
|
processName = inputStream[i].ProcessName.ToString().Trim();
|
|
|
int processID = repository.GetProcessID(processName);
|
|
|
if (processID == 0)
|
|
|
{
|
|
|
ErrorMessage.Append("制程名称 " + processName + " 不存在!" + Environment.NewLine);
|
|
|
}
|
|
|
|
|
|
// 判断工位名称是否存在
|
|
|
terminalName = inputStream[i].TerminalName.ToString().Trim();
|
|
|
int terminalID = repository.GetterminalID(terminalName);
|
|
|
if (terminalID == 0)
|
|
|
{
|
|
|
ErrorMessage.Append("工位名称 " + terminalName + " 不存在!" + Environment.NewLine);
|
|
|
}
|
|
|
|
|
|
// 判断数量填写是否正确
|
|
|
try
|
|
|
{
|
|
|
qty = Int32.Parse(inputStream[i].ItemCount.ToString());
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
int rowsNo = i + 1;
|
|
|
ErrorMessage.Append("您要导入的关键数据第:[" + rowsNo + "]行,[需求数量]填写错误!" + Environment.NewLine);
|
|
|
}
|
|
|
|
|
|
// 判断关键数据名称是否存在
|
|
|
keydataName = inputStream[i].KeydataName.ToString().Trim();
|
|
|
int keydataID = repository.GetkeydataID(keydataName);
|
|
|
if (processID == 0)
|
|
|
{
|
|
|
ErrorMessage.Append("工位名称 " + terminalName + " 不存在!" + Environment.NewLine);
|
|
|
}
|
|
|
// 判断发送指令填写是否正确
|
|
|
try
|
|
|
{
|
|
|
torqueCommand = inputStream[i].TorqueCommand.ToString();
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
int rowsNo = i + 1;
|
|
|
ErrorMessage.Append("您要导入的关键数据第:[" + rowsNo + "]行,[扭矩发送指令]填写错误!" + Environment.NewLine);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
ErrorMessage.Append("数据检查失败,数据中不能有公式或宏等,或用格式刷把所有数据格式同一后再试!");
|
|
|
}
|
|
|
|
|
|
if (ErrorMessage.Length != 0)
|
|
|
{
|
|
|
result.Add("message", ErrorMessage.ToString());
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
string _rows = string.Empty;
|
|
|
string _partNo = string.Empty;
|
|
|
string _processName = string.Empty;
|
|
|
string _terminalName = string.Empty;
|
|
|
string _keyDataName = string.Empty;
|
|
|
string _torqueCommand = string.Empty;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// 处理表身数据
|
|
|
if (repository.InsertPartKeyData(inputStream))
|
|
|
{
|
|
|
result.Add("message", "导入成功");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
result.Add("message", "导入失败,请检查数据完整性!");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
} |