using System.Collections; using Estsh.Core.Util; using Estsh.Core.Repository.IRepositories; using Estsh.Core.Services.IServices; using Estsh.Core.Models; using Estsh.Core.Model.Result; using Estsh.Core.Dapper; using Estsh.Core.Model.ExcelModel; using Dapper; using System.Text; namespace Estsh.Core.Services { public class CarrierDateService : BaseService, ICarrierDateService { private readonly ICarrierDateRepository repository; public CarrierDateService(ICarrierDateRepository _repository) : base(_repository) { repository = _repository; } /// /// 根据分页条件获取分页菜单数据 /// /// /// /// /// /// public Hashtable getCarrierListByPage(string rackNo, string cartonNo, string partNo, string partSpec, string enabled, int factoryId, Pager pager, String direction, String sort) { Hashtable result = new Hashtable(); String strWhere = " 1=1 "; if (rackNo != null && !rackNo.Trim().Equals("")) { strWhere += "and a.rack_no like '%" + rackNo.Trim() + "%'"; } if (cartonNo != null && !cartonNo.Trim().Equals("")) { strWhere += "and b.carton_no like '%" + cartonNo + "%'"; } if (partNo != null && !partNo.Trim().Equals("")) { strWhere += "and b.part_no like '%" + partNo + "%'"; } if (partSpec != null && !partSpec.Trim().Equals("")) { strWhere += "and b.part_spec like '%" + partSpec + "%'"; } //if (enabled != null && !enabled.Trim().Equals("")) //{ // strWhere += "and a.enabled like '%" + enabled + "%'"; //} strWhere += " and b.factory_id = " + factoryId + " and a.factory_id=" + factoryId + " and a.enabled='Y' and b.enabled='Y' and c.enum_type='sys_stock_status' "; String orderBy = ""; if (sort != null && !"".Equals(sort.Trim())) { orderBy += typeof(WmsRack).GetEntityColumnName(sort.Trim()) + " " + direction; } else { //orderBy += typeof(WmsRack).GetEntityColumnName("ruid") + " " + direction; } result = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy); return result; } /// /// 保存菜单数据 /// /// /// public int saveCarrier(WmsRack htParams) { return repository.saveCarrier(htParams); } /// /// 更新菜单数据 /// /// /// public int updateCarrier(WmsRack htParams) { return repository.updateCarrier(htParams); } /// /// 导入零件免检 /// public Hashtable ImportExcel(List inputStream, int factoryId, string factoryCode, int empId) { try { Hashtable result = new Hashtable(); List SqlStrings = new List(); List Parameters = new List(); DynamicParameters Params = new DynamicParameters(); //判断EXCEL是否存在数据 if (inputStream == null || inputStream.Count == 0) { result.Add("message", "导入数据为空,请重新导入!"); result.Add("flag", "error"); return result; } //判断零件号是否存在 for (int i = 0; i < inputStream.Count; i++) { string rackNo = inputStream[i].RackNo.ToString(); List sysExemptions = repository.ifCarrierManage(rackNo); if (sysExemptions.Count <= 0) { StringBuilder querySen = new StringBuilder(1024); querySen.AppendLine("INSERT INTO dbo.wms_rack "); querySen.AppendLine(" ( rack_no , "); querySen.AppendLine(" rack_type , "); querySen.AppendLine(" enabled , "); querySen.AppendLine(" factory_id , "); querySen.AppendLine(" factory_code , "); querySen.AppendLine(" create_userid , "); querySen.AppendLine(" create_time "); querySen.AppendLine(" ) "); querySen.AppendLine("VALUES ( @rackNo ,"); querySen.AppendLine(" @rackType,"); querySen.AppendLine(" @enabled,"); querySen.AppendLine(" @factoryId ,"); querySen.AppendLine(" @factoryCode ,"); querySen.AppendLine(" @createUserid,"); querySen.AppendLine(" @createTime"); querySen.AppendLine(" ) "); Params = new DynamicParameters(); Params.Add("@rackNo", rackNo); Params.Add("@rackType", "1"); Params.Add("@enabled", "Y"); Params.Add("@factoryId", factoryId); Params.Add("@factoryCode", factoryCode); Params.Add("@createUserid", empId); Params.Add("@createTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); SqlStrings.Add(querySen.ToString()); Parameters.Add(Params); } } if (repository.InsertData(SqlStrings, Parameters)) { result.Add("message", "导入成功"); result.Add("flag", "OK"); } else { result.Add("message", "导入失败"); result.Add("flag", "error"); } return result; } catch (Exception ex) { Hashtable result = new Hashtable(); result.Add("message", "导入失败"); result.Add("flag", "error"); return result; } } /// /// 查看菜单详情 /// /// /// public Hashtable getCarrierDetail(String ruid) { ruid = " ruid = " + ruid; List dt = repository.getList(ruid, ""); Hashtable result = new Hashtable(); result.Add("ruid", dt[0].Ruid); result.Add("rackNo", dt[0].RackNo); result.Add("rackType", dt[0].RackType); result.Add("factoryId", dt[0].FactoryId); result.Add("enabled", dt[0].Enabled); return result; } public List getExportList(string rackNo, string enabled, string factoryId) { String strWhere = " 1=1 "; string orderBy = ""; if (rackNo != null && !rackNo.Trim().Equals("")) { strWhere += "and rack_no like '%" + rackNo.Trim() + "%'"; } if (enabled != null && !enabled.Trim().Equals("")) { strWhere += "and enabled like '%" + enabled + "%'"; } strWhere += " and factory_id = " + factoryId + " "; orderBy = " order by rack_no "; return repository.getExportList(strWhere, orderBy); } /// /// 启用 /// /// /// public int EnableCarrier(String ids) { String[] idArray = ids.Split(','); int count = 0; foreach (String id in idArray) { if (!"".Equals(id)) { count += this.repository.EnableCarrier(id); } } return count; } /// /// 禁用 /// /// /// public int DisableCarrier(String ids) { String[] idArray = ids.Split(','); int count = 0; foreach (String id in idArray) { if (!"".Equals(id)) { count += this.repository.DisableCarrier(id); } } return count; } } }