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 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 PartSNRuleDefineService : BaseService, IPartSNRuleDefineService { private readonly IPartSNRuleDefineRepository repository; public PartSNRuleDefineService(IPartSNRuleDefineRepository _repository) : base(_repository) { repository = _repository; } /// /// 根据分页条件获取分页菜单数据 /// /// /// /// /// /// public Hashtable getPartSNRuleListByPage(String partNo_search, String type_test, Pager pager, String direction, String sort, String enabled) { String strWhere = " 1=1 "; if (!String.IsNullOrEmpty(partNo_search)) { strWhere += " and b.part_no like '%" + partNo_search.Trim() + "%'"; } if (!String.IsNullOrEmpty(type_test)) { strWhere += " and a.type like '%" + type_test.Trim() + "%'"; } if (!String.IsNullOrEmpty(enabled)) { strWhere += " and a.enabled = '" + enabled.Trim() + "'"; } String orderBy = ""; if (sort != null && !"".Equals(sort.Trim())) { orderBy += typeof(SysPartSnRule).GetEntityColumnName(sort.Trim()) + " " + direction; } else { orderBy += typeof(SysPartSnRule).GetEntityColumnName("Ruid") + " " + direction; } Hashtable dt = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy); return dt; } /// /// 保存菜单数据 /// /// /// public int savePartSNRule(SysPartSnRule htParams) { return repository.savePartSNRule(htParams); } /// /// 更新菜单数据 /// /// /// public int updatePartSNRule(SysPartSnRule htParams) { return repository.updatePartSNRule(htParams); } /// /// 查看菜单详情 /// /// /// public Hashtable getPartSNRuleDetail(String ruid) { ruid = " ruid = " + ruid; List dt = repository.getList(ruid, ""); Hashtable result = new Hashtable(); result.Add("ruid", dt[0].Ruid); result.Add("type", dt[0].Type); result.Add("lenght", dt[0].Lenght); result.Add("from1", dt[0].From1); result.Add("partNo", dt[0].PartNo); result.Add("to1", dt[0].To1); result.Add("fix1", dt[0].Fix1); result.Add("from2", dt[0].From2); result.Add("to2", dt[0].To2); result.Add("fix2", dt[0].Fix2); result.Add("partId", dt[0].PartId); //result.Add("ext_rule", dt[0]["ext_rule"]); result.Add("enabled", dt[0].Enabled); result.Add("isValidateUnique", dt[0].IsValidateUnique); result.Add("isValidateLength", dt[0].IsValidateLength); return result; } /// /// 删除菜单 /// /// /// public int deletePartSNRule(String ids) { String[] idArray = ids.Split(','); int count = 0; foreach (String id in idArray) { if (!"".Equals(id)) { count += this.repository.deletePartSNRule(id); } } return count; } /// /// 启用 /// /// /// public int EnableData(String ids) { ids = ids.Substring(0, ids.Length - 1); return this.repository.EnableData(ids); } /// /// 禁用 /// /// /// public int DisableData(String ids) { ids = ids.Substring(0, ids.Length - 1); return this.repository.DisableData(ids); } /// /// 获取 类型 信息 /// BY NOAH /// /// public List getTypeData() { return repository.getTypeData(); } /// /// 判断是否存在 用户输入的零件号 /// BY NOAH /// /// /// public String isExsitPart_no(String part_no) { return this.repository.isExsitPart_no(part_no); } /// /// 根据分页条件获取分页菜单数据 /// /// 查询条件 /// /// 排序方式 /// 排序字段 /// public Hashtable getTableListByPage(String partNo_search, String type_test, String enabled, Pager pager, String direction, String sort, Boolean isPage) { int rowCount = 0; String strWhere = " 1=1 "; if (!String.IsNullOrEmpty(partNo_search)) { strWhere += " and b.part_no like '%" + partNo_search.Trim() + "%'"; } if (!String.IsNullOrEmpty(type_test)) { strWhere += " and a.type like '%" + type_test.Trim() + "%'"; } if (!String.IsNullOrEmpty(enabled)) { strWhere += " and a.enabled = '" + enabled.Trim() + "'"; } if (isPage) { rowCount = pager.pageSize; } else { rowCount = pager.pageSize; } String orderBy = ""; if (sort != null && !"".Equals(sort.Trim())) { orderBy += typeof(SysPartSnRule).GetEntityColumnName(sort.Trim()) + " " + direction; } else { orderBy += typeof(SysPartSnRule).GetEntityColumnName("Ruid") + " " + direction; } Hashtable result = repository.getTableListByPage(rowCount, pager.pageNo, strWhere, orderBy); return result; } /// /// 读取文件并更新至数据库 /// /// 文件全路径 /// 登录用户信息 public Hashtable ImportExcel(List 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; StringBuilder ErrorMessage = new StringBuilder(1024); // 验证数据 for (int i = 0; i < inputStream.Count; i++) { partNo = inputStream[i].PartNo.ToString(); // 判断零件号是否存在 int partID = repository.GetPartID(partNo); if (partID == 0) { ErrorMessage.Append("零件号 " + partNo + " 不存在!" + '\r' + '\n' + Environment.NewLine); } } if (ErrorMessage.Length != 0) { result.Add("message", ErrorMessage.ToString()); result.Add("flag", "error"); return result; } // 处理表身数据 if (repository.InsertData(inputStream, userId.ToString())) { result.Add("message", "导入成功"); result.Add("flag", "error"); return result; } else { result.Add("message", "导入失败"); result.Add("flag", "error"); return result; } } } }