public static void Set(User user) { //if (user == null) //{ // throw new TechnicalException("User can't be null."); //} securityContext.Value = user; }
public void RecordKanbanTransaction(KanbanCard card, User transUser, DateTime transDate, KBTransType transType) { if (card != null && transUser != null) { KanbanTransaction trans = new KanbanTransaction(); trans.CardNo = card.CardNo; trans.TransactionType = transType; trans.TransactionDate = transDate; trans.CreateUserId = transUser.Id; trans.CreateUserName = transUser.Name; this.genericMgr.Create(trans); } }
public ActionResult Edit(User user) { if (ModelState.IsValid) { this.GeneMgr.Update(user); SaveSuccessMessage(Resources.ACC.User.User_Updated); } return new RedirectToRouteResult(new RouteValueDictionary { { "action", "Index" }, { "controller", "UserFavorite" }, { "id", user.Id } }); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { user.LastPasswordModifyDate = genericMgr.FindById<User>(user.Id).LastPasswordModifyDate; this.genericMgr.Update(user); SaveSuccessMessage(Resources.ACC.User.User_Updated); } return new RedirectToRouteResult(new RouteValueDictionary { { "action", "Index" }, { "controller", "UserFavorite" }, { "id", user.Id } }); }
//public void CreateKanbanScan(KanbanCard card, FlowDetail matchDetail, User scanUser, DateTime? scanTime) //{ // if (card != null && matchDetail != null && scanUser != null) // { // KanbanScan scan = Mapper.Map<KanbanCard, KanbanScan>(card); // scan.ScanUserId = scanUser.Id; // scan.ScanUserName = scanUser.Name; // scan.ScanTime = scanTime; // //FlowDetail fd = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Id = ? ", card.FlowDetailId).SingleOrDefault(); // scan.ScanQty = matchDetail.UnitCount; // scan.IsOrdered = false; // this.genericMgr.Create(scan); // } //} public void CreateKanbanScan(KanbanCard card, decimal qty, User scanUser, DateTime? scanTime) { if (card != null && scanUser != null) { KanbanScan scan = Mapper.Map<KanbanCard, KanbanScan>(card); scan.ScanUserId = scanUser.Id; scan.ScanUserName = scanUser.Name; scan.ScanTime = scanTime; scan.ReferenceItemCode = card.ReferenceItemCode; //用物流中心记工位 scan.LogisticCenterCode = card.OpRef; //FlowDetail fd = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Id = ? ", card.FlowDetailId).SingleOrDefault(); scan.ScanQty = qty; scan.IsOrdered = false; this.genericMgr.Create(scan); card.ScanId = scan.Id; } }
public KanbanScan CreateKanbanScan(KanbanCard card, FlowDetail matchDetail, User scanUser, DateTime? scanTime) { KanbanScan scan = new KanbanScan(); if (card != null && matchDetail != null && scanUser != null) { scan = Mapper.Map<KanbanCard, KanbanScan>(card); scan.ScanUserId = scanUser.Id; scan.ScanUserName = scanUser.Name; scan.ScanTime = scanTime; scan.ReferenceItemCode = card.ReferenceItemCode; //用物流中心记工位 scan.LogisticCenterCode = matchDetail.BinTo; //FlowDetail fd = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Id = ? ", card.FlowDetailId).SingleOrDefault(); scan.ScanQty = matchDetail.MinUnitCount; scan.IsOrdered = false; this.genericMgr.Create(scan); card.ScanId = scan.Id; return scan; } return scan; }
public User GetMonitorUser() { if(monitorUser == null) { monitorUser = queryMgr.FindById<User>(BusinessConstants.SYSTEM_USER_MONITOR); } return monitorUser; }
public void ImportKanBanCard(Stream inputStream, com.Sconit.CodeMaster.OrderType type, User currUser) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 10); #region 列定义 // FlowMaster int colCode = 1; // 路线代码 int colItem = 2; // 物料号 int colRefItemCode = 3; // 旧图号 int colItemDesc = 4; // 零件名称 int colOpRef = 5; // 工位代码 int colOpUseQty = 6; // 工位用量 int colItemType = 7; // 零件类型 int colOpRefSeq = 8; // 看板编号 int colUC = 9; // 单包装 int colUCDesc = 10; // 包装描述 int colContainerDesc = 11; // 容器描述 int colDock = 12; // 配送路径 int colCardQty = 13; // 看板卡数量 int colIsActive = 14; // 是否生效 //int colShelf = 13; // 架位 #endregion var errorMessage = new BusinessException(); //IList<Item> ItemsList = new List<Item>(); //IList<FlowMaster> exactFlowList = new List<FlowMaster>(); IList<FlowDetail> exactFlowDetailList = new List<FlowDetail>(); //IList<FlowDetail> deleteFlowDetailList = new List<FlowDetail>(); int colCount = 0; #region 取所有的路线和路线明细 //var totalFlowMasterList = genericMgr.FindAll<FlowMaster>("from FlowMaster f where f.Type = ? and f.FlowStrategy = ?", new object[] { (int)type, (int)CodeMaster.FlowStrategy.ANDON }); var totalFlowDetailList = genericMgr.FindEntityWithNativeSql<FlowDetail>("select d.* from scm_FlowDet d inner join scm_FlowMstr f on f.Code = d.Flow and f.Type = ? and exists(select 1 from SCM_FlowStrategy as fs where fs.Flow=f.Code and fs.Strategy=?)", new object[] { (int)type, (int)CodeMaster.FlowStrategy.ANDON }); //var totalFlowStrategyList = genericMgr.FindEntityWithNativeSql<FlowStrategy>("select g.* from scm_FlowStrategy g inner join scm_FlowMstr f on f.Code = g.Flow and f.Type = ? and f.FlowStrategy = ?", new object[] { (int)type, (int)CodeMaster.FlowStrategy.ANDON }); //var totalSupplierList = genericMgr.FindAll<Supplier>(); //var totalRegionList = genericMgr.FindAll<Region>(); //var totalLocationList = genericMgr.FindAll<Location>(); //var totalItemList = genericMgr.FindAll<Item>("from Item where IsActive = ?", true); #endregion while (rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 14)) { break;//边界 } colCount++; var rowErrors = new List<Message>(); string code = string.Empty; string item = string.Empty; string refItemCode = string.Empty; string itemDesc = string.Empty; string opRef = string.Empty; string opUseQty = string.Empty; string itemType = string.Empty; string opRefSeq = string.Empty; string uc = string.Empty; string ucDesc = string.Empty; string dock = string.Empty; string containerDesc = string.Empty; string cardQty = string.Empty; string isActive = string.Empty; #region 读取数据 code = ImportHelper.GetCellStringValue(row.GetCell(colCode)); if (code == null || code.Trim() == string.Empty) { rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowMaster.FlowMaster_Code)); } opRef = ImportHelper.GetCellStringValue(row.GetCell(colOpRef)); if (opRef == null || opRef.Trim() == string.Empty) { rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), "工位")); } cardQty = ImportHelper.GetCellStringValue(row.GetCell(colCardQty)); decimal qtyVar = 0; if (cardQty == null || cardQty.Trim() == string.Empty || !decimal.TryParse(cardQty,out qtyVar)) { rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), "看板张数")); } item = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (item == null || item.Trim() == string.Empty) { rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowDetail.FlowDetail_Item)); } #endregion #region 检查路线明细是否都在数据库中 var flowDet = totalFlowDetailList.FirstOrDefault(f => f.Flow.ToUpper() == code.ToUpper() && f.Item.ToUpper() == item.ToUpper() && f.BinTo.ToUpper() == opRef.ToUpper()); if (flowDet == null) { rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, "导入的数据的第{0}行路线明细不存在", colCount.ToString())); } else { flowDet.OrderQty = qtyVar; exactFlowDetailList.Add(flowDet); } #endregion errorMessage.AddMessages(rowErrors); } if (errorMessage.HasMessage) { throw errorMessage; } if (exactFlowDetailList.Count > 0) { var flowCodes = exactFlowDetailList.Select(f => f.Flow).Distinct(); foreach (var flow in flowCodes) { this.AddManuallyByKanbanFlow(flow, exactFlowDetailList.Where(f => f.Flow == flow).ToList(), DateTime.Now, currUser, true); } } }
public void CreateUser(User user) { if (this.genericMgr.FindAll<long>("select count(*) from User as u where u.Code = ?", new object[] { user.Code })[0] > 0) { throw new BusinessException(Resources.ACC.User.Errors_Existing_User, user.Code); } else { if (CheckePassword(user.ConfirmPassword)) { user.Password = EncryptHelper.Md5(user.ConfirmPassword); this.genericMgr.Create(user); UserUpdatePasswordLog upLog = new UserUpdatePasswordLog { UserCode = user.Code, UserName = user.Name, UpdateTime = DateTime.Now, NewPassword = EncryptHelper.Md5(user.Password), }; this.genericMgr.Create(upLog); this.genericMgr.UpdateWithNativeQuery("exec USP_Busi_ChangePassword ?,?", new object[] { user.Id, user.ConfirmPassword }, new IType[] { NHibernateUtil.String, NHibernateUtil.String }); } } }
public ActionResult _Edit(User user) { if (ModelState.IsValid) { user.LastPasswordModifyDate = genericMgr.FindById<User>(user.Id).LastPasswordModifyDate; genericMgr.UpdateWithTrim(user); SaveSuccessMessage(Resources.ACC.User.User_Updated); } return PartialView(user); }
private void CreateSapProcOrder(OrderMaster orderMaster, User user) { //IList<ErrorMessage> errorMessageList = new List<ErrorMessage>(); //SecurityContextHolder.Set(user); //try //{ // MI_CRSL_LESService service = new MI_CRSL_LESService(); // service.Credentials = this.Credentials; // service.Timeout = this.TimeOut; // service.Url = "http://10.86.128.63:8000/XISOAPAdapter/MessageServlet?channel=:LES01:CC_SOAP7&version=3.0&Sender.Service=LES01&Interface=http%3A%2F%2Fwww.sih.cq.cn%2Fsap%2Fmm%2F07%5EMI_CRSL_LES"; // #region 循环创建计划协议明细 // foreach (OrderDetail orderDetail in orderMaster.OrderDetails) // { // //根据来源目的库位+零件号查找 // //来源目的库位明细上没有取头上的 // log.Debug(string.Format("开始连接Web服务创建计划协议,路线代码{0},零件{1},数量{2},开始时间{3},窗口时间{4}", // orderMaster.Flow, orderDetail.Item, orderDetail.OrderedQty, orderMaster.StartTime, orderMaster.WindowTime)); // ZLSCHE_IN ZLSCHE_IN = new ZLSCHE_IN(); // ZLSCHE_IN.EBELN = orderDetail.EBELN; // ZLSCHE_IN.EBELP = orderDetail.EBELP; // ZLSCHE_IN.MENGE = orderDetail.OrderedQty; //订单单位的数量 // ZLSCHE_IN.MENGESpecified = true; // ZLSCHE_IN.EINDT = orderMaster.WindowTime.ToString("yyyyMMdd"); // ZLSCHE_OUT ZLSCHE_OUT = service.MI_CRSL_LES(ZLSCHE_IN); // log.Debug("连接Web服务创建计划协议完成。"); // if (ZLSCHE_OUT.STATUS == "S") // { // orderMaster.ExternalOrderNo = ZLSCHE_OUT.EBELN; //计划协议号 // orderDetail.ExternalSequence = ZLSCHE_OUT.EBELP; //计划协议行号 // orderDetail.ExternalOrderNo = orderMaster.ExternalOrderNo; // this.CreateOrder(orderMaster); // } // else // { // string logMessage = "创建计划协议失败。错误信息:" + ZLSCHE_OUT.MESSAGE; // log.Error(logMessage); // string mailTo = this.systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.ExceptionMailTo); // string emailBody = @"订单号:" + orderMaster.ExternalOrderNo + ",计划协议号:" + ZLSCHE_OUT.EBELN + ",计划协议行号:" + ZLSCHE_OUT.EBELP; // EmailService.EmailService emailService = new EmailService.EmailService(); // emailService.AsyncSend(logMessage, emailBody, mailTo, EmailService.MailPriority.High); // } // } // #endregion //} //catch (Exception ex) //{ // string logMessage = "连接Web服务创建计划协议失败。"; // log.Error(logMessage, ex); // string mailTo = this.systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.ExceptionMailTo); // string emailBody = @"订单号:" + orderMaster.ExternalOrderNo; // EmailService.EmailService emailService = new EmailService.EmailService(); // emailService.AsyncSend(logMessage, emailBody, mailTo, EmailService.MailPriority.High); //} }
public void RunRccp(DateTime planVersion, DateTime snapTime, CodeMaster.TimeUnit dateType, string dateIndex, User user) { lock(RunRccpLock) { planVersion = DateTime.Parse(planVersion.ToString("yyyy-MM-dd HH:mm:ss")); SecurityContextHolder.Set(user); log.Info(string.Format("---**------ SnapTime:{0} PlanVersion:{1} - 开始执行预测计划 ---", snapTime, planVersion)); BusinessException businessException = new BusinessException(); int rccpPlanVersion = 0; try { #region 获取RccpPlan log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始获取RccpPlan ---", snapTime, planVersion)); var rccpPlans = this.genericMgr.FindAll<RccpPlan> (@"from RccpPlan as m where m.DateIndex >= ? and DateType=? ", new object[] { dateIndex, dateType }); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束获取RccpPlan ---", snapTime, planVersion)); rccpPlanVersion = rccpPlans.Max(p => p.PlanVersion); #endregion #region 获取路线 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始获取路线 ---", snapTime, planVersion)); var mrpFlowDetailList = this.genericMgr.FindAll<MrpFlowDetail> (@"from MrpFlowDetail as m where m.SnapTime = ?", new object[] { snapTime }); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束获取路线 ---", snapTime, planVersion)); #endregion #region 分解BOM log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始分解Bom ---", snapTime, planVersion)); var rccpTransList = GetRccpTrans(planVersion, rccpPlans, businessException); var rccpTransGroupList = (from r in rccpTransList group r by new { Item = r.Item, DateIndex = r.DateIndex, IsLastLevel = r.IsLastLevel, DateType = r.DateType } into g select new RccpTransGroup { PlanVersion = planVersion, DateType = g.Key.DateType, Item = g.Key.Item, DateIndex = g.Key.DateIndex, IsLastLevel = g.Key.IsLastLevel, Qty = g.Sum(r => r.Qty), ScrapPercentage = g.Sum(s => s.Qty) > 0 ? g.Sum(r => r.ScrapPercentage * (r.Qty / g.Sum(s => s.Qty))) : 0 }).ToList(); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束分解Bom ---", snapTime, planVersion)); #endregion #region 后加工 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始执行后加工计划 ---", snapTime, planVersion)); GenFiRccp(planVersion, dateType, mrpFlowDetailList, rccpTransList, businessException); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束执行后加工计划 ---", snapTime, planVersion)); #endregion 后加工 #region 炼胶 委外 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始执行炼胶计划 ---", snapTime, planVersion)); GenMiRccp(planVersion, dateType, dateIndex, mrpFlowDetailList, rccpTransGroupList, businessException); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束执行炼胶计划 ---", snapTime, planVersion)); #endregion 炼胶 #region 采购/委外等 log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始执行采购/委外计划 ---", snapTime, planVersion)); GenPurchaseRccp(planVersion, dateType, businessException, mrpFlowDetailList, rccpTransGroupList, snapTime, user); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束执行采购/委外计划 ---", snapTime, planVersion)); #endregion 采购/委外等 #region Create RccpTransGroup log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 开始记录RccpTrans/Group ---", snapTime, planVersion)); this.genericMgr.BulkInsert<RccpTransGroup>(rccpTransGroupList); log.Info(string.Format("--- SnapTime:{0} PlanVersion:{1} - 结束记录RccpTrans/Group ---", snapTime, planVersion)); #endregion } catch(Exception ex) { businessException.AddMessage(new Message(CodeMaster.MessageType.Error, ex.StackTrace)); log.Error(ex); } List<RccpLog> rccpLogs = new List<RccpLog>(); CodeMaster.MessageType status = CodeMaster.MessageType.Info; if(businessException.HasMessage) { var messages = businessException.GetMessages().GroupBy(p => new { Message = p.GetMessageString(), MessageType = p.MessageType }, (k, g) => new { k.Message, k.MessageType }); foreach(var message in messages) { RccpLog rccpLog = new RccpLog(); rccpLog.ErrorLevel = message.MessageType.ToString(); rccpLog.Message = message.Message; rccpLog.Logger = "RunRccp"; rccpLog.PlanVersion = planVersion; rccpLogs.Add(rccpLog); //this.genericMgr.Create(rccpLog); if(message.MessageType == CodeMaster.MessageType.Warning) { log.Warn(rccpLog.Message); } else if(message.MessageType == CodeMaster.MessageType.Error) { log.Error(rccpLog.Message); } else { log.Info(rccpLog.Message); } } if(messages.Count(f => f.MessageType == CodeMaster.MessageType.Error) > 0) { status = CodeMaster.MessageType.Error; } else if(messages.Count(f => f.MessageType == CodeMaster.MessageType.Warning) > 0) { status = CodeMaster.MessageType.Warning; } } #region 记录RccpPlanMaster RccpPlanMaster rccpPlanMaster = new RccpPlanMaster(); rccpPlanMaster.DateType = dateType; rccpPlanMaster.SnapTime = snapTime; rccpPlanMaster.PlanVersion = planVersion; rccpPlanMaster.Status = status; rccpPlanMaster.RccpPlanVersion = rccpPlanVersion; rccpPlanMaster.CreateUserId = user.Id; rccpPlanMaster.CreateUserName = user.FullName; rccpPlanMaster.CreateDate = DateTime.Now; rccpPlanMaster.LastModifyUserId = user.Id; rccpPlanMaster.LastModifyUserName = user.FullName; rccpPlanMaster.LastModifyDate = DateTime.Now; this.genericMgr.Create(rccpPlanMaster); #endregion double timetick = 1001 - (rccpPlanMaster.CreateDate - planVersion).TotalMilliseconds; timetick = timetick > 0 ? timetick : 0; Thread.Sleep((int)timetick); string infoMessage = string.Format("完成预测计划时间:{0},时间总计:{1}秒", DateTime.Now.ToLocalTime(), (DateTime.Now - planVersion).TotalSeconds); log.Info(infoMessage); RccpLog infoLog = new RccpLog(); infoLog.ErrorLevel = CodeMaster.MessageType.Info.ToString(); infoLog.Message = infoMessage; infoLog.Logger = "RunRccp"; infoLog.PlanVersion = planVersion; rccpLogs.Add(infoLog); this.genericMgr.BulkInsert<RccpLog>(rccpLogs); } }
public ActionResult Subscibe(string code, string userIdStr, string emailStr, string smsStr) { if (!string.IsNullOrWhiteSpace(code) && !string.IsNullOrWhiteSpace(userIdStr) && (!string.IsNullOrWhiteSpace(emailStr) || !string.IsNullOrWhiteSpace(smsStr))) { ViewBag.Code = code; IList<string> userIdList = (userIdStr.Split(',')).ToList<string>(); IList<string> emailList = (emailStr.Split(',')).ToList<string>(); IList<string> smsList = (smsStr.Split(',')).ToList<string>(); if (userIdList != null && (emailList != null || smsList != null)) { for (int i = 0; i < userIdList.Count; i++) { IssueTypeToUserDetail issueTypeToUserDetail = new IssueTypeToUserDetail(); IssueTypeToMaster issueTypeToMaster =new IssueTypeToMaster(); issueTypeToMaster.Code = code; issueTypeToUserDetail.IssueTypeTo = issueTypeToMaster; User user = new User(); user.Id = Int32.Parse(userIdList[i]); issueTypeToUserDetail.User = user; if (!string.IsNullOrWhiteSpace(emailList[i]) && bool.Parse(emailList[i]) == true) { issueTypeToUserDetail.IsEmail = true; } else { issueTypeToUserDetail.IsEmail = false; } if (!string.IsNullOrWhiteSpace(smsList[i]) && bool.Parse(smsList[i]) == true) { issueTypeToUserDetail.IsSMS = true; } else { issueTypeToUserDetail.IsSMS = false; } genericMgr.CreateWithTrim(issueTypeToUserDetail); } SaveSuccessMessage(Resources.ISS.IssueTypeToUserDetail.User_Subscibed); } } return this.RedirectToAction("ChooseUser/" + code); }
public IList<KanbanScan> OrderCard(string region, string supplier, string lccode, string orderTime, string scanIds, User orderUser, ref string orderNos) { DateTime dt = DateTime.Now; IList<KanbanScan> result = new List<KanbanScan>(); string hql = "from KanbanScan where IsOrdered = ? and Id in (" + scanIds + ")"; IList<object> paraList = new List<object>(); paraList.Add(false); IList<KanbanScan> scans = null; scans = this.genericMgr.FindAll<KanbanScan>(hql, paraList.ToArray()); if (scans != null) { IDictionary<string, IList<KanbanScan>> flowScanDict = new Dictionary<string, IList<KanbanScan>>(); //flow-item-qty IDictionary<string, IDictionary<string, decimal>> flowItemQty = new Dictionary<string, IDictionary<string, decimal>>(); // 把同一个flow的kanbanscan放到一起 IDictionary<string, KanbanScan> flowItemPONo = new Dictionary<string, KanbanScan>(); //flow-item-iskit IDictionary<string, HashSet<string>> flowNonKitItems = new Dictionary<string, HashSet<string>>(); IDictionary<string, HashSet<string>> flowKitItems = new Dictionary<string, HashSet<string>>(); foreach (KanbanScan scan in scans) { if (flowScanDict.ContainsKey(scan.Flow)) { flowScanDict[scan.Flow].Add(scan); } else { IList<KanbanScan> scanSameFlow = new List<KanbanScan>(); scanSameFlow.Add(scan); flowScanDict.Add(scan.Flow, scanSameFlow); } if (scan.IsKit) { if (flowKitItems.ContainsKey(scan.Flow)) { flowKitItems[scan.Flow].Add(scan.Item); } else { HashSet<string> kitItems = new HashSet<string>(); kitItems.Add(scan.Item); flowKitItems.Add(scan.Flow, kitItems); } } else { if (flowNonKitItems.ContainsKey(scan.Flow)) { flowNonKitItems[scan.Flow].Add(scan.Item); } else { HashSet<string> nonKitItems = new HashSet<string>(); nonKitItems.Add(scan.Item); flowNonKitItems.Add(scan.Flow, nonKitItems); } } if (!string.IsNullOrEmpty(scan.PONo) && !string.IsNullOrEmpty(scan.POLineNo) && !flowItemPONo.ContainsKey(scan.Flow + scan.Item)) { flowItemPONo.Add(scan.Flow + scan.Item, scan); } if (flowItemQty.ContainsKey(scan.Flow)) { if (flowItemQty[scan.Flow].ContainsKey(scan.Item)) { flowItemQty[scan.Flow][scan.Item] += scan.ScanQty; } else { flowItemQty[scan.Flow].Add(scan.Item, scan.ScanQty); } } else { IDictionary<string, decimal> itemQty = new Dictionary<string, decimal>(); itemQty.Add(scan.Item, scan.ScanQty); flowItemQty.Add(scan.Flow, itemQty); } } //IDictionary<string, WorkingCalendar> regionWcCache = new Dictionary<string, WorkingCalendar>(); foreach (KeyValuePair<string, IList<KanbanScan>> k in flowScanDict) { IList<KanbanScan> sameFlow = k.Value; FlowMaster fm = this.genericMgr.FindAll<FlowMaster>("from FlowMaster where Code = ? ", k.Key).SingleOrDefault(); if (fm == null) { KanbanScan res = new KanbanScan(); res.Flow = k.Key; res.Ret = KBProcessCode.NoFlowMaster; res.Msg = Resources.KB.KanbanCard.Process_NoFlowMaster; result.Add(res); } else { //考虑跨天,fm.partyto等于kanbanscan上的region //WorkingCalendar currentWorkcalendar = null; //if (regionWcCache.ContainsKey(fm.PartyTo)) //{ // currentWorkcalendar = regionWcCache[fm.PartyTo]; //} //else //{ // currentWorkcalendar = workingCalendarMgr.GetWorkingCalendarByDatetimeAndRegion(dt, fm.PartyTo); // if (currentWorkcalendar == null) // { // KanbanScan res = new KanbanScan(); // res.Region = region; // res.Ret = KBProcessCode.NoWorkingCalendar; // res.Msg = Resources.KB.KanbanCard.Process_NoWorkingCalendar + ":Region=" + fm.PartyTo + " Date=" + dt; // result.Add(res); // continue; // } // else { // regionWcCache.Add(fm.PartyTo, currentWorkcalendar); // } //} //交货时段开始和结束时间 //考虑跨天 //StartEndTime seTime = ForwardCalculateNextDeliveryForSpecificWorkCalendar(currentWorkcalendar, dt, fm, this.flowMgr.GetFlowStrategy(fm.Code)); //if (KanbanUtility.IsMinAndMaxDateTime(seTime.StartTime, seTime.EndTime)) //{ // KanbanScan res = new KanbanScan(); // res.Flow = k.Key; // res.Ret = KBProcessCode.NoFlowShiftDetail; // res.Msg = Resources.KB.KanbanCard.Process_NoFlowShiftDetail + ":WorkDate-" + currentWorkcalendar.WorkingDate.Date; // result.Add(res); //} //else //{ //IList<string> items = flowItemQty[k.Key].Keys.ToList<string>(); OrderMaster newOrder = null; if (flowNonKitItems.ContainsKey(k.Key)) { IList<string> items = flowNonKitItems[k.Key].ToList<string>(); newOrder = orderMgr.TransferFlow2Order(fm, items, dt, true); } else if (flowKitItems.ContainsKey(k.Key)) { newOrder = orderMgr.TransferFlow2Order(fm, null, dt, false); } if (newOrder != null) { string[] setimestring = orderTime.Split('~'); newOrder.IsAutoRelease = true; newOrder.StartTime = DateTime.Parse(setimestring[0]); newOrder.WindowTime = DateTime.Parse(setimestring[1]); //non kit items if (newOrder.OrderDetails != null) { for (int i = 0; i < newOrder.OrderDetails.Count; i++) { newOrder.OrderDetails[i].RequiredQty = flowItemQty[k.Key][newOrder.OrderDetails[i].Item]; newOrder.OrderDetails[i].OrderedQty = flowItemQty[k.Key][newOrder.OrderDetails[i].Item]; //if (flowItemPONo.ContainsKey(k.Key + newOrder.OrderDetails[i].Item)) //{ // newOrder.OrderDetails[i].PONo = flowItemPONo[k.Key + newOrder.OrderDetails[i].Item].PONo; // newOrder.OrderDetails[i].POLineNo = flowItemPONo[k.Key + newOrder.OrderDetails[i].Item].POLineNo; //} } } //kit items if (flowKitItems.ContainsKey(k.Key)) { IList<string> kitItems = flowKitItems[k.Key].ToList<string>(); foreach (string kitItem in kitItems) { decimal kitQty = flowItemQty[k.Key][kitItem]; IList<ItemKit> itemKits = itemMgr.GetKitItemChildren(kitItem); if (itemKits != null && itemKits.Count > 0) { foreach (ItemKit ik in itemKits) { OrderDetail od = new OrderDetail(); od.Item = ik.ChildItem.Code; Item itemkkk = this.genericMgr.FindById<Item>(od.Item); od.ItemDescription = itemkkk.Description; od.Uom = itemkkk.Uom; od.BillAddress = newOrder.BillAddress; od.BillAddressDescription = newOrder.BillAddressDescription; //od.TraceCode = kitItem; od.RequiredQty = kitQty * ik.Qty; od.OrderedQty = kitQty * ik.Qty; //if (flowItemPONo.ContainsKey(k.Key + kitItem)) //{ // od.PONo = flowItemPONo[k.Key + kitItem].PONo; // od.POLineNo = flowItemPONo[k.Key + kitItem].POLineNo; //} newOrder.AddOrderDetail(od); } } } } try { orderMgr.CreateOrder(newOrder); orderNos = orderNos + newOrder.OrderNo + ";"; for (int j = 0; j < sameFlow.Count; j++) { //设置kanbanscan上的结转数量,日期等 sameFlow[j].IsOrdered = true; sameFlow[j].OrderQty = sameFlow[j].ScanQty; sameFlow[j].OrderUserId = orderUser.Id; sameFlow[j].OrderUserName = orderUser.Name; sameFlow[j].OrderTime = dt; sameFlow[j].OrderNo = newOrder.OrderNo; this.genericMgr.Update(sameFlow[j]); //设置看板卡状态到Ordered KanbanCard card = this.kanbanCardMgr.GetByCardNo(sameFlow[j].CardNo); card.Status = KBStatus.Ordered; this.genericMgr.Update(card); //如果看板卡是多轨,结转时累加多轨循环量,在扫描的时候处理 //if (this.multiSupplyGroupMgr.IsKanbanCardMultiSupplyGroupEnabled(card)) //{ // this.multiSupplyGroupMgr.KBAccumulateCycleAmount(card, sameFlow[j].OrderQty); //} //记录看板order事务 this.kanbanTransactionMgr.RecordKanbanTransaction(card, orderUser, dt, KBTransType.Order); sameFlow[j].Ret = KBProcessCode.Ok; sameFlow[j].Msg = Resources.KB.KanbanCard.Process_Ok; result.Add(sameFlow[j]); } } catch (BusinessException be) { KanbanScan res = new KanbanScan(); res.Flow = k.Key; res.Ret = KBProcessCode.CreateOrderFailed; res.Msg = Resources.KB.KanbanCard.Process_CreateOrderFailed + ":" + be.GetMessages()[0].GetMessageString(); result.Add(res); } } else { KanbanScan res = new KanbanScan(); res.Flow = k.Key; res.Ret = KBProcessCode.OrderTransferError; res.Msg = Resources.KB.KanbanCard.Process_OrderTransferError; result.Add(res); } //} } } } return result; }
public void ModifyScanQty(KanbanScan scan, decimal newQty, string tempKanbanCard, User modifyUser) { DateTime dt = DateTime.Now; scan.ScanQty = newQty; scan.TempKanbanCard = tempKanbanCard; this.genericMgr.Update(scan); KanbanCard card = this.kanbanCardMgr.GetByCardNo(scan.CardNo); this.kanbanTransactionMgr.RecordKanbanTransaction(card, modifyUser, dt, KBTransType.ModifyScan); }
public KanbanScan Scan(string cardNo, User scanUser, Boolean isScanBySD) { KanbanScan kbscan = new KanbanScan(); KanbanCard card = this.kanbanCardMgr.GetByCardNo(cardNo); //是否有效(未冻结) if (this.kanbanCardMgr.IsEffectiveCard(card)) { if (this.kanbanCardMgr.IsFrozenCard(card)) { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.Frozen, Resources.KB.KanbanCard.Process_Frozen); } else { FlowDetail fd = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Id = ? ", card.FlowDetailId).SingleOrDefault(); DateTime dt = DateTime.Now; //if (!string.IsNullOrEmpty(card.MultiSupplyGroup)) //{ // CreateKanbanScan(card, card.Qty, scanUser, dt); //} //else //{ kbscan = CreateKanbanScan(card, fd, scanUser, dt); //} card.Status = KBStatus.Scanned; card.LastUseDate = dt; card.OpTime = dt; this.genericMgr.Update(card); this.kanbanTransactionMgr.RecordKanbanTransaction(card, scanUser, dt, KBTransType.Scan); } } else { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.NotEffective, Resources.KB.KanbanCard.Process_NotEffective); } return kbscan; }
public KanbanCard Scan(string cardNo, User scanUser) { KanbanCard card = this.kanbanCardMgr.GetByCardNo(cardNo); //是否存在 if (card == null) { #region 处理遗失 IList<KanbanLost> kanbanLostList = genericMgr.FindAll<KanbanLost>(); var q = kanbanLostList.Where(k => k.CardNo == cardNo); if (q != null && q.Count() > 0) { KanbanLost kanbanLost = q.First(); genericMgr.Delete(kanbanLost); } #endregion card = new KanbanCard(); card.CardNo = cardNo; card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.NonExistingCard, Resources.KB.KanbanCard.Process_NonExistingCard); } else { //是否有效(未冻结) if (this.kanbanCardMgr.IsEffectiveCard(card)) { if (this.kanbanCardMgr.IsFrozenCard(card)) { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.Frozen, Resources.KB.KanbanCard.Process_Frozen); } else { //是否已经扫描过 if (this.kanbanCardMgr.IsScanned(card)) { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.AlreadyScanned, Resources.KB.KanbanCard.Process_AlreadyScanned); } else { //多轨,是否超循环量,这个时间计算多轨 decimal oldQty = card.Qty; decimal scanQty = card.Qty; //if (!multiSupplyGroupMgr.ScanMultiSupplyGroup(card)) //{ // #region 获取下一个双轨厂商零件,新华说现在看板都是双轨,直接取另一个厂商好了 // MultiSupplyItem multiSupplyItem = genericMgr.FindAll<MultiSupplyItem>("from MultiSupplyItem where GroupNo = ? and Supplier != ? ", new object[] { card.MultiSupplyGroup, card.Supplier }).FirstOrDefault(); // #endregion // if (multiSupplyItem != null) // { // SetCardRetMsg(card, KBProcessCode.ExceedCycleAmount, "当前生效的多轨厂商不是" + card.Supplier + "请扫描厂商:" + multiSupplyItem.Supplier + "件号:" + multiSupplyItem.Item); // } // else // { // SetCardRetMsg(card, KBProcessCode.ExceedCycleAmount, "当前生效的多轨厂商不是" + card.Supplier); // } //} //else //{ //if (oldQty != card.Qty) //{ // SetCardRetMsg(card, KBProcessCode.ExceedCycleAmount, "扫描量超过剩余量,请制作临时看板卡,数量" + card.Qty); // scanQty = card.Qty; // card.Qty = oldQty; //} FlowDetail fd = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Id = ? ", card.FlowDetailId).SingleOrDefault(); if (fd == null) { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.NoFlowDetail, Resources.KB.KanbanCard.Process_NoFlowDetail); } else { //判断kanbancard相关字段与item,fd及supplier等其他表字段是否有变化 string validText = kanbanCardMgr.ValidateKanbanCardFields(card); if (!String.IsNullOrEmpty(validText)) { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.InvalidFields, Resources.KB.KanbanCard.Process_InvalidFields + ":" + validText); } else { // 可以扫描,创建扫描记录,kb事务记录,设置卡片状态到scanned,不知道为什么会有0的情况 if (scanQty > 0) { DateTime dt = DateTime.Now; if (!string.IsNullOrEmpty(card.MultiSupplyGroup)) { CreateKanbanScan(card, scanQty, scanUser, dt); } else { CreateKanbanScan(card, fd, scanUser, dt); } card.Status = KBStatus.Scanned; card.LastUseDate = dt; card.OpTime = dt; this.genericMgr.Update(card); this.kanbanTransactionMgr.RecordKanbanTransaction(card, scanUser, dt, KBTransType.Scan); if (oldQty == scanQty) { SetCardRetMsg(card, KBProcessCode.Ok, Resources.KB.KanbanCard.Process_Ok); } } } } } //} } } else { card.OpTime = DateTime.Now; SetCardRetMsg(card, KBProcessCode.NotEffective, Resources.KB.KanbanCard.Process_NotEffective); } } return card; }
public void DeleteKanbanScan(KanbanScan scan, User deleteUser) { if (scan.IsOrdered) { throw new BusinessException("扫描记录已结转,不能删除"); } KanbanCard card = this.kanbanCardMgr.GetByCardNo(scan.CardNo); if (card != null) { card.Status = KBStatus.Loop; this.genericMgr.Update(card); this.kanbanTransactionMgr.RecordKanbanTransaction(card, deleteUser, DateTime.Now, KBTransType.UnScan); #region 记到双轨溢出量 //if (!string.IsNullOrEmpty(card.MultiSupplyGroup)) //{ // MultiSupplyGroup msg = genericMgr.FindAll<MultiSupplyGroup>("from MultiSupplyGroup m where m.GroupNo = ?", card.MultiSupplyGroup).FirstOrDefault(); // if (msg != null) // { // if (msg.KBEffSupplier == card.Supplier && msg.KBAccumulateQty >= scan.ScanQty) // { // msg.KBAccumulateQty -= scan.ScanQty; // genericMgr.Update(msg); // } // else // { // MultiSupplySupplier mss = genericMgr.FindAll<MultiSupplySupplier>("from MultiSupplySupplier s where s.GroupNo = ? and s.Supplier = ?", new object[] { card.MultiSupplyGroup, card.Supplier }).FirstOrDefault(); // mss.KanbanSpillQty -= Convert.ToInt32(scan.ScanQty); // genericMgr.Update(mss); // } // } //} #endregion } this.genericMgr.Delete(scan); this.kanbanTransactionMgr.RecordKanbanTransaction(card, deleteUser, DateTime.Now, KBTransType.DeleteScan); }
public static string GetBatchNo(string multiregion, string region, string location, DateTime startDate, DateTime endDate, int kbCalc, User calcUser) { if (String.IsNullOrEmpty(multiregion)) { return region + location + startDate.ToString("yyMMdd") + endDate.ToString("yyMMdd") + kbCalc; } else { return multiregion + startDate.ToString("yyMMdd") + endDate.ToString("yyMMdd") + kbCalc; } }
public string AutoGenAnDonOrder(User user) { try { var orderNos = this.genericMgr.FindAllWithNativeSql<string>("USP_Busi_GenAnDonOrder ?,?", new object[] { user.Id, user.FullName }); if (orderNos != null && orderNos.Count > 0) { string hqlOrderMaster = string.Empty; string hqlOrderDetail = string.Empty; object[] paras = new object[orderNos.Count]; for (int i = 0; i < orderNos.Count; i++) { if (i == 0) { hqlOrderMaster = "from OrderMaster om where om.OrderNo in(?"; hqlOrderDetail = "from OrderDetail od where od.OrderNo in(?"; } else { hqlOrderMaster += ",?"; hqlOrderDetail += ",?"; } paras[i] = orderNos[i]; } hqlOrderMaster += ")"; hqlOrderDetail += ")"; var orderMasterList = this.genericMgr.FindAll<OrderMaster>(hqlOrderMaster, paras); var orderDetailList = this.genericMgr.FindAll<OrderDetail>(hqlOrderDetail, paras); foreach (var orderMaster in orderMasterList) { orderMaster.OrderDetails = orderDetailList.Where(o => o.OrderNo == orderMaster.OrderNo).ToList(); #region 发送打印 this.AsyncSendPrintData(orderMaster); #endregion } } return string.Empty; } catch(Exception ex) { string errorMessage = string.Empty; if (ex.InnerException != null) { if (ex.InnerException.InnerException != null) { errorMessage = ex.InnerException.InnerException.Message; } else { errorMessage = ex.InnerException.Message; } } else { errorMessage = ex.Message; } log.Error(errorMessage); IList<ErrorMessage> errorMessageList = new List<ErrorMessage>(); errorMessageList.Add(new ErrorMessage { Template = NVelocityTemplateRepository.TemplateEnum.GenAnDonOrderFail, Message = errorMessage, }); SendErrorMessage(errorMessageList); return errorMessage; } }
private void GenPurchaseRccp(DateTime planVersion, CodeMaster.TimeUnit dateType, BusinessException businessException, IList<MrpFlowDetail> mrpFlowDetailList, IEnumerable<RccpTransGroup> rccpTransGroupList, DateTime snapTime, User user) { if(businessException.GetMessages().Where(p => p.MessageType == CodeMaster.MessageType.Error).Count() > 0) { //如果有错误,退出,不产生采购物料需求 return; } var flowDetails = mrpFlowDetailList .Where(p => p.Type == CodeMaster.OrderType.Procurement || p.Type == CodeMaster.OrderType.CustomerGoods || p.Type == CodeMaster.OrderType.SubContract || p.Type == CodeMaster.OrderType.ScheduleLine); var purchasePlanList = new List<PurchasePlan>(); var rccpTransGroupByIndexList = (from p in rccpTransGroupList group p by p.DateIndex into g select new { DateIndex = g.Key, List = g }).OrderBy(p => p.DateIndex).ToList(); foreach(var rccpTransGroupByIndex in rccpTransGroupByIndexList) { DateTime windowTime = DateTime.Now; if(dateType == CodeMaster.TimeUnit.Week) { windowTime = DateTimeHelper.GetWeekIndexDateFrom(rccpTransGroupByIndex.DateIndex); } else if(dateType == CodeMaster.TimeUnit.Month) { windowTime = DateTime.Parse(rccpTransGroupByIndex.DateIndex + "-01"); } var mrpFlowDetailDic = flowDetails.Where(p => p.StartDate <= windowTime && p.EndDate > windowTime) .GroupBy(p => p.Item, (k, g) => new { k, g }) .ToDictionary(d => d.k, d => d.g); foreach(var groupRccpTrans in rccpTransGroupByIndex.List) { var mrpFlowDetails = mrpFlowDetailDic.ValueOrDefault(groupRccpTrans.Item); if(mrpFlowDetails != null) { foreach(var mrpFlowDetail in mrpFlowDetails) { var purchasePlan = new PurchasePlan(); purchasePlan.Item = groupRccpTrans.Item; //purchasePlan.Sequence = mrpFlowDetail.Sequence; purchasePlan.Flow = mrpFlowDetail.Flow; purchasePlan.LocationTo = mrpFlowDetail.LocationTo; purchasePlan.OrderType = mrpFlowDetail.Type; purchasePlan.WindowTime = windowTime; var leadDay = Utility.DateTimeHelper.TimeTranfer((decimal)mrpFlowDetail.LeadTime, CodeMaster.TimeUnit.Hour, CodeMaster.TimeUnit.Day); if(dateType == CodeMaster.TimeUnit.Week) { purchasePlan.StartTime = purchasePlan.WindowTime.AddDays(3).AddDays(-leadDay); purchasePlan.StartTime = Utility.DateTimeHelper.GetWeekStart(purchasePlan.StartTime); } else { purchasePlan.StartTime = purchasePlan.WindowTime.AddDays(15).AddDays(-leadDay); purchasePlan.StartTime = Utility.DateTimeHelper.GetStartTime(CodeMaster.TimeUnit.Month, purchasePlan.StartTime); } purchasePlan.Qty = (mrpFlowDetail.MrpWeight / mrpFlowDetails.Sum(p => p.MrpWeight)) * groupRccpTrans.Qty; purchasePlan.PlanQty = purchasePlan.Qty; purchasePlan.DateType = dateType; purchasePlan.PlanVersion = planVersion; purchasePlanList.Add(purchasePlan); } } else { if(groupRccpTrans.IsLastLevel) { businessException.AddMessage(new Message(CodeMaster.MessageType.Warning, "没有找到物料{0}的采购路线", groupRccpTrans.Item)); } } } } string hql = string.Empty; if(dateType == CodeMaster.TimeUnit.Week) { hql = "from FlowStrategy where IsCheckMrpWeeklyPlan =? and Flow in(?"; } else if(dateType == CodeMaster.TimeUnit.Month) { hql = "from FlowStrategy where IsCheckMrpMonthlyPlan =? and Flow in(?"; } var flowStategys = this.genericMgr.FindAllIn<FlowStrategy> (hql, purchasePlanList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct(), new object[] { true }); var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster> ("from FlowMaster where Code in(?", flowStategys.Select(p => p.Flow).Distinct()) .GroupBy(p => p.Code, (k, g) => new { k, g.First().Description }) .ToDictionary(d => d.k, d => d.Description); foreach(var flowStategy in flowStategys) { PurchasePlanMaster purchasePlanMaster = new PurchasePlanMaster(); purchasePlanMaster.DateType = dateType; purchasePlanMaster.Flow = flowStategy.Flow; purchasePlanMaster.FlowDescription = flowMasterDic[flowStategy.Flow]; purchasePlanMaster.PlanVersion = planVersion; purchasePlanMaster.SnapTime = snapTime; purchasePlanMaster.SourcePlanVersion = snapTime; purchasePlanMaster.CreateUserId = user.Id; purchasePlanMaster.CreateUserName = user.FullName; purchasePlanMaster.CreateDate = DateTime.Now; purchasePlanMaster.LastModifyUserId = user.Id; purchasePlanMaster.LastModifyUserName = user.FullName; purchasePlanMaster.LastModifyDate = DateTime.Now; this.genericMgr.Create(purchasePlanMaster); } purchasePlanList = purchasePlanList.Where(p => flowStategys.Select(q => q.Flow).Contains(p.Flow)).ToList(); this.genericMgr.BulkInsert<PurchasePlan>(purchasePlanList); }
private void SendMailAndSMS(IssueMaster issue, double hours, DateTime date, IList<IssueLevel> issueLevels, User user) { int count = issueLevels.Count; foreach (IssueLevel issueLevel in issueLevels) { if (date.AddHours(count * hours) < DateTime.Now) { //是否发送过 if (!this.IsSended(issue, issueLevel)) { IList<IssueDetail> issueDetailList = this.genericMgr.FindAll<IssueDetail>("select det from IssueDetail where IssueCode = ? and IssueLevel = ? ", new object[] { issue.Code, issueLevel.Code }); SendMailAndSMS(issue, issueLevel, issueDetailList); } break; } count--; } }
public ActionResult _Edit(User user) { if (ModelState.IsValid) { genericMgr.Update(user); SaveSuccessMessage(Resources.ACC.User.User_Updated); } return PartialView(user); }
public bool HavePermission(string issueCode, User user, com.Sconit.CodeMaster.IssueStatus status) { string hql = "select count(*) from IssueDetail where IsActive =true and IssueCode =? and UserId = ? "; if (status == com.Sconit.CodeMaster.IssueStatus.InProcess) { hql += "and IsDefault != true"; } IList<long> count = this.genericMgr.FindAll<long>(hql, new object[] { issueCode, user.Id }); if (count != null && count.Count > 0 && count[0] > 0) { return true; } return false; }
public ActionResult New(User user) { if (ModelState.IsValid) { //判断用户名不能重复 if (this.genericMgr.FindAll<long>(userNameDuiplicateVerifyStatement, new object[] { user.Code })[0] > 0) { base.SaveErrorMessage(Resources.ACC.User.Errors_Existing_User, user.Code); } else { user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(user.ConfirmPassword, "MD5"); user.LastPasswordModifyDate = DateTime.Now; genericMgr.CreateWithTrim(user); SaveSuccessMessage(Resources.ACC.User.User_Added); return RedirectToAction("Edit/" + user.Id); } } return View(user); }
public void ImportKanbanCalc2(Stream inputStream, string batchno, User currentUser) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } BusinessException businessException = new BusinessException(); HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); IDictionary<string, KanbanCalc> importedKanbanCalcs = new Dictionary<string, KanbanCalc>(); ImportHelper.JumpRows(rows, 1); #region 列定义 int colFlowDet = 0;//路线明细 int colKanbanDeltaNum = 26;//变化张数 #endregion int i = 1; while (rows.MoveNext()) { i++; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 26)) { break;//边界 } int flowDetId = 0; int kanbanDeltaNum = 0; #region 路线明细Id try { try { flowDetId = Convert.ToInt32(row.GetCell(colFlowDet).NumericCellValue); } catch (Exception) { flowDetId = Convert.ToInt32(row.GetCell(colFlowDet).ToString()); } } catch { businessException.AddMessage("无法获取导入数据的路线ID,第{0}行。\t", i.ToString()); continue; } #endregion #region 变化张数 try { try { kanbanDeltaNum = Convert.ToInt32(row.GetCell(colKanbanDeltaNum).NumericCellValue); } catch (Exception) { kanbanDeltaNum = Convert.ToInt32(row.GetCell(colKanbanDeltaNum).ToString()); } } catch { businessException.AddMessage("无法获取导入数据差异,第{0}行。\t", i.ToString()); continue; } #endregion if (importedKanbanCalcs.ContainsKey(flowDetId.ToString())) { businessException.AddMessage("Import.Stream.DuplicateRow, id为{0}", flowDetId.ToString()); } else { KanbanCalc calc = new KanbanCalc(); calc.BatchNo = batchno; calc.FlowDetailId = flowDetId; calc.KanbanDeltaNum = kanbanDeltaNum; importedKanbanCalcs.Add(flowDetId.ToString(), calc); } } if (businessException.HasMessage) { throw businessException; } this.UpdateBatch(batchno, currentUser, importedKanbanCalcs); }
private IList<UserPermissionView> GetUserPermission(User user) { if (user.Code.Trim().ToLower() == "su") { //超级用户,给予所有权限 DetachedCriteria criteria = DetachedCriteria.For<Permission>(); IList<Permission> permissionList = genericMgr.FindAll<Permission>(criteria); criteria = DetachedCriteria.For<PermissionCategory>(); IList<PermissionCategory> categoryList = genericMgr.FindAll<PermissionCategory>(criteria); return (from p in permissionList join c in categoryList on p.PermissionCategory equals c.Code select new UserPermissionView { UserId = user.Id, PermissionCode = p.Code, PermissionCategory = p.PermissionCategory, PermissionCategoryType = c.Type }).ToList(); } else { DetachedCriteria criteria = DetachedCriteria.For<UserPermissionView>(); criteria.Add(Expression.Eq("UserId", user.Id)); return genericMgr.FindAll<UserPermissionView>(criteria); } }
//[Transaction(TransactionMode.Requires)] public void DoAnDon(List<AnDonInput> anDonInputList,User scanUser) { if (anDonInputList != null && anDonInputList.Count > 0) { List<string> flowCodeList = anDonInputList.Select(a => a.Flow).Distinct().ToList(); #region 以前的代码 //foreach (var flowCode in flowCodeList) //{ // //string flowCode = anDonInputList.Select(a => a.Flow).Distinct().Single(); // Entity.SCM.FlowMaster flowMaster = this.genericMgr.FindById<Entity.SCM.FlowMaster>(flowCode); // Entity.ORD.OrderMaster orderMaster = orderMgr.TransferFlow2Order(flowMaster, anDonInputList.Select(a => a.Item).Distinct().ToList()); // orderMaster.StartTime = DateTime.Now; // FlowStrategy flowStrategy = genericMgr.FindById<FlowStrategy>(flowCode); // orderMaster.WindowTime = orderMaster.StartTime.AddHours((double)flowStrategy.LeadTime); // orderMaster.IsAutoRelease = true; // foreach (AnDonInput anDonInput in anDonInputList) // { // Entity.ORD.OrderDetail orderDetail = orderMaster.OrderDetails != null ? // orderMaster.OrderDetails.Where(f => f.BinTo == anDonInput.OpRef // && f.Item == anDonInput.Item).FirstOrDefault() : null; // if (orderDetail != null) // { // orderDetail.RequiredQty += anDonInput.UnitCount; // orderDetail.OrderedQty += anDonInput.UnitCount; // } // else // { // if (anDonInput.Flow == orderMaster.Flow) // { // orderDetail = new Entity.ORD.OrderDetail(); // orderDetail.OrderType = orderMaster.Type; // orderDetail.OrderSubType = orderMaster.SubType; // //orderDetail.Sequence = ; // Entity.MD.Item item = this.genericMgr.FindById<Entity.MD.Item>(anDonInput.Item); // orderDetail.Item = item.Code; // orderDetail.ItemDescription = item.Description; // orderDetail.ReferenceItemCode = item.ReferenceCode; // orderDetail.BaseUom = item.Uom; // orderDetail.Uom = anDonInput.Uom; // //orderDetail.PartyFrom= // orderDetail.UnitCount = anDonInput.UnitCount; // //orderDetail.UnitCountDescription= // //orderDetail.MinUnitCount= // orderDetail.QualityType = CodeMaster.QualityType.Qualified; // orderDetail.ManufactureParty = anDonInput.Supplier; // orderDetail.RequiredQty += anDonInput.UnitCount; // orderDetail.OrderedQty += anDonInput.UnitCount; // //orderDetail.ShippedQty = ; // //orderDetail.ReceivedQty = ; // //orderDetail.RejectedQty = ; // //orderDetail.ScrapQty = ; // //orderDetail.PickedQty = ; // if (orderDetail.BaseUom != orderDetail.Uom) // { // orderDetail.UnitQty = this.itemMgr.ConvertItemUomQty(orderDetail.Item, orderDetail.BaseUom, 1, orderDetail.Uom); // } // else // { // orderDetail.UnitQty = 1; // } // //public string LocationFrom { get; set; } // //public string LocationFromName { get; set; } // Entity.MD.Location locationTo = this.genericMgr.FindById<Entity.MD.Location>(anDonInput.LocationTo); // orderDetail.LocationTo = locationTo.Code; // orderDetail.LocationToName = locationTo.Name; // orderDetail.IsInspect = false; // //public string Container { get; set; } // //public string ContainerDescription { get; set; } // //public Boolean IsScanHu { get; set; } // orderDetail.BinTo = anDonInput.OpRef; // orderMaster.AddOrderDetail(orderDetail); // } // } // } // this.orderMgr.CreateOrder(orderMaster); //} #endregion #region 新的看板代码 string hqlFlowMaster = string.Empty; string hqlFlowStra = string.Empty; List<object> para = new List<object>(); foreach (var flowCode in flowCodeList) { if (string.IsNullOrEmpty(hqlFlowMaster)) { hqlFlowMaster = "from FlowMaster fm where fm.Code in(?"; hqlFlowStra = "from FlowStrategy fs where fs.Flow in(?"; } else { hqlFlowMaster += ",?"; hqlFlowStra += ",?"; } para.Add(flowCode); } hqlFlowMaster += ")"; hqlFlowStra += ")"; IList<FlowMaster> flowList = this.genericMgr.FindAll<FlowMaster>(hqlFlowMaster, para.ToArray()); IList<FlowStrategy> flowStrategyList = this.genericMgr.FindAll<FlowStrategy>(hqlFlowStra, para.ToArray()); List<Entity.KB.KanbanScan> kbScanOrderNowList = new List<Entity.KB.KanbanScan>(); List<Entity.KB.KanbanScan> kbScanList = new List<Entity.KB.KanbanScan>(); foreach (var anDonInput in anDonInputList) { var scan = kanbanScanMgr.Scan(anDonInput.CardNo, scanUser, true); var flowStrategy = flowStrategyList.FirstOrDefault(f => f.Flow == anDonInput.Flow); if (!string.IsNullOrEmpty(scan.CardNo)) { if (flowStrategy.IsOrderNow) { kbScanOrderNowList.Add(scan); } else { kbScanList.Add(scan); } } } if (kbScanOrderNowList.Count > 0) { kanbanScanOrderMgr.OrderCard(kbScanOrderNowList, flowList, DateTime.Now); } #endregion } else { throw new BusinessException("请刷入看板卡。"); } }
public void DeleteKanbanCard(KanbanCard card, User user) { this.genericMgr.Delete(card); this.kanbanTransactionMgr.RecordKanbanTransaction(card, user, DateTime.Now, KBTransType.Scan); this.genericMgr.Update("Update KanbanCard Set TotalCount = ? where FlowDetailId = ? ", new object[] { card.TotalCount - 1, card.FlowDetailId }); this.genericMgr.Update("Update FlowDetail Set CycloidAmount = ? where Id = ? ", new object[] { card.TotalCount - 1, card.FlowDetailId }); }
public void TryCalculate(string multiregion, DateTime startDate, DateTime endDate, int kbCalc, User calcUser) { #region 删除同批号的,按照区域,开始日期,结束日期 string batchno = KanbanUtility.GetBatchNo(multiregion, null, null, startDate, endDate, kbCalc, calcUser); this.genericMgr.Delete("from KanbanCalc where BatchNo = ?", batchno, NHibernate.NHibernateUtil.String); genericMgr.FlushSession(); genericMgr.CleanSession(); #endregion List<KanbanCalc> kanbanCalcList = new List<KanbanCalc>(); IList<KanbanCalc> lerror = new List<KanbanCalc>(); IList<Region> calcRegions = new List<Region>(); DateTime dateTimeNow = DateTime.Now; #region 检查区域的标准和特殊代码有没有设置 string[] regions = multiregion.Split(','); for (int ir = 0; ir < regions.Length; ir++) { Region r = this.genericMgr.FindAll<Region>("from Region where Code = ? ", regions[ir]).FirstOrDefault(); //if (String.IsNullOrEmpty(r.KbStandardCode) || String.IsNullOrEmpty(r.KbAlternativeCode)) //{ // throw new BusinessException("没找到区域" + r.Code + "的看板代码和异常代码!"); //} calcRegions.Add(r); } #endregion if (calcRegions.Count() > 0) { IList<ShiftMaster> shiftMasterList = genericMgr.FindAll<ShiftMaster>(); //先这样吧,全部的班次,反正也不多 foreach (Region calcRegion in calcRegions) { #region 把生效时间未到和待冻结的都删掉 genericMgr.FindAllWithNativeSql<KanbanCard>("Delete from KB_KanbanCard where Region = ? and KBCalc = ? and (EffDate > ? or FreezeDate < ?) ", new object[] { calcRegion.Code, kbCalc, dateTimeNow, dateTimeNow }); genericMgr.FindAllWithNativeSql<KanbanCard>("Update KB_KanbanCard set TotalCount = k.TotalCount from (select FlowDetId, max(Number) as TotalCount from KB_KanbanCard where Region = ? and KBCalc = ? group by FlowDetId ) k where k.FlowDetId = KB_KanbanCard.FlowDetId and KB_KanbanCard.Region = ? and KB_KanbanCard.KBCalc = ?", new object[] { calcRegion.Code, kbCalc, calcRegion.Code, kbCalc }); genericMgr.FindAllWithNativeSql<FlowDetail>("Update SCM_FlowDet set CycloidAmount = c.TotalCount from KB_KanbanCard c where c.FlowDetId = SCM_FlowDet.Id"); genericMgr.FindAllWithNativeSql<FlowDetail>("Update SCM_FlowDet set CycloidAmount = 0 where not exists (select 1 from KB_KanbanCard c where c.FlowDetId = SCM_FlowDet.Id) and CycloidAmount>0"); genericMgr.FlushSession(); genericMgr.CleanSession(); #endregion #region 取此区域下所有的路线 //WorkingCalendar nSub1 = workingCalendarMgr.GetLastWorkingCalendar(startDate, region, 7); IList<FlowMaster> flowList = genericMgr.FindEntityWithNativeSql<FlowMaster>(@"select c.* from scm_flowmstr c inner join scm_flowstrategy as g on c.Code = g.Flow where c.IsActive = ? and c.PartyTo = ? and g.Strategy = ? and g.KBCalc = ?", new object[] { true, calcRegion.Code, (int)com.Sconit.CodeMaster.FlowStrategy.KB, kbCalc }); List<ItemDailyConsume> itemDailyConsumeList = new List<ItemDailyConsume>(); IList<WorkingCalendar> workingCalendatList = genericMgr.FindAll<WorkingCalendar>(" from WorkingCalendar w where w.FlowStrategy = ? and w.Region = ? and w.WorkingDate >= ? and w.WorkingDate <= ?", new object[] { (int)com.Sconit.CodeMaster.FlowStrategy.KB, calcRegion.Code, startDate, endDate }); IList<Party> partyList = genericMgr.FindAll<Party>(); IList<LocationBinItem> locationBinItemList = genericMgr.FindEntityWithNativeSql<LocationBinItem>(@"select l.* from md_locationbinitem l inner join md_location d on l.Location = d.Code where d.Region = ?", calcRegion.Code); //IList<Item> kitItemList = genericMgr.FindAll<Item>(" from Item i where i.IsKit = ?",true); IList<ItemTrace> itemTraceList = genericMgr.FindAll<ItemTrace>(); IList<Item> itemList = genericMgr.FindEntityWithNativeSql<Item>(@"select i.* from md_item i inner join scm_flowdet d on i.code = d.item inner join scm_flowmstr c on d.flow = c.code inner join scm_flowstrategy as g on c.Code = g.Flow where c.IsActive = ? and c.PartyTo = ? and g.Strategy = ? and g.KBCalc = ?", new object[] { true, calcRegion.Code, (int)com.Sconit.CodeMaster.FlowStrategy.KB, kbCalc }); IList<Supplier> supplierList = genericMgr.FindAll<Supplier>(); IList<ItemKit> itemKitList = genericMgr.FindAll<ItemKit>(); #endregion if (flowList != null && flowList.Count() > 0) { #region 获取站别日用量 if (kbCalc == (int)com.Sconit.CodeMaster.KBCalculation.Normal) { //采购的 IList<ItemDailyConsume> procurementItemDailyConsumeList = this.genericMgr.FindEntityWithNativeSql<ItemDailyConsume>(@"select max(ic.id) as id,ic.item,max(ic.itemdesc) as itemdesc, ic.location,max(qty) as qty,max(ic.consumedate) as consumedate,max(ic.substitutegroup) as substitutegroup,max(ic.multisupplygroup) as multisupplygroup,max(ic.createdate) as createdate,max(ic.originalqty) as originalqty from cust_itemdailyconsume ic inner join scm_flowdet fd on ic.item = fd.item inner join scm_flowmstr fm on fd.flow = fm.code inner join scm_flowstrategy fg on fm.code = fg.flow inner join prd_workingcalendar pw on ic.ConsumeDate = pw.workingdate where fm.isactive = ? and ic.Location = fm.LocTo and fm.Type = ? and fm.FlowStrategy = ? and fg.kbcalc = ? and ic.ConsumeDate >= ? and ic.ConsumeDate <= ? and fm.PartyTo = ? and pw.type = ? and pw.flowstrategy = ? and pw.region = fm.PartyTo and ic.qty > 0 group by ic.location,ic.item,pw.shift", new object[] { true, (int)com.Sconit.CodeMaster.OrderType.Procurement, (int)com.Sconit.CodeMaster.FlowStrategy.KB, kbCalc, startDate, endDate, calcRegion.Code, (int)com.Sconit.CodeMaster.WorkingCalendarType.Work, (int)com.Sconit.CodeMaster.FlowStrategy.KB }); //移库的,有些是用来源库位来算的,如KD件,有些使用目的库位来算的,如闭口订单,真变态 IList<ItemDailyConsume> transferItemDailyConsumeList = this.genericMgr.FindEntityWithNativeSql<ItemDailyConsume>(@"select max(ic.id) as id,ic.item,max(ic.itemdesc) as itemdesc, ic.location,max(qty) as qty,max(ic.consumedate) as consumedate,max(ic.substitutegroup) as substitutegroup,max(ic.multisupplygroup) as multisupplygroup,max(ic.createdate) as createdate,max(ic.originalqty) as originalqty from cust_itemdailyconsume ic inner join scm_flowdet fd on ic.item = fd.item inner join scm_flowmstr fm on fd.flow = fm.code inner join scm_flowstrategy fg on fm.code = fg.flow inner join prd_workingcalendar pw on ic.ConsumeDate = pw.workingdate where fm.isactive = ? and (ic.Location = fm.LocTo or ic.Location = fm.LocFrom) and fm.Type = ? and fm.FlowStrategy = ? and fg.kbcalc = ? and ic.ConsumeDate >= ? and ic.ConsumeDate <= ? and fm.PartyTo = ? and pw.type = ? and pw.flowstrategy = ? and pw.region = fm.PartyTo and ic.qty > 0 group by ic.location,ic.item,pw.shift", new object[] { true, (int)com.Sconit.CodeMaster.OrderType.Transfer, (int)com.Sconit.CodeMaster.FlowStrategy.KB, kbCalc, startDate, endDate, calcRegion.Code, (int)com.Sconit.CodeMaster.WorkingCalendarType.Work, (int)com.Sconit.CodeMaster.FlowStrategy.KB }); if (procurementItemDailyConsumeList != null && procurementItemDailyConsumeList.Count > 0) { itemDailyConsumeList.AddRange(procurementItemDailyConsumeList); } if (transferItemDailyConsumeList != null && transferItemDailyConsumeList.Count > 0) { itemDailyConsumeList.AddRange(transferItemDailyConsumeList); } } else if (kbCalc == (int)com.Sconit.CodeMaster.KBCalculation.CatItem) { //生产,因为冲压送焊装的部分站别日用量在焊装,不是冲压,不考虑库位,按照生产线明细匹配 IList<ItemDailyConsume> productionItemDailyConsumeList = this.genericMgr.FindEntityWithNativeSql<ItemDailyConsume>(@"select ic.* from cust_itemdailyconsume ic inner join scm_flowdet fd on ic.item = fd.item inner join scm_flowmstr fm on fd.flow = fm.code inner join scm_flowstrategy fg on fm.code = fg.flow where fm.isactive = ? and fm.FlowStrategy = ? and fg.kbcalc = ? and ic.ConsumeDate >= ? and ic.ConsumeDate <= ? and fm.PartyTo = ? and ic.Qty > 0", new object[] { true, (int)com.Sconit.CodeMaster.FlowStrategy.KB, kbCalc, startDate, endDate, calcRegion.Code }); if (productionItemDailyConsumeList != null && productionItemDailyConsumeList.Count > 0) { itemDailyConsumeList.AddRange(productionItemDailyConsumeList); } } #endregion } foreach (FlowMaster flow in flowList) { #region 物流 if (kbCalc == (int)com.Sconit.CodeMaster.KBCalculation.Normal) { IList<FlowShiftDetail> flowShiftDetailList = genericMgr.FindAll<FlowShiftDetail>(" from FlowShiftDetail f where f.Flow = ?", flow.Code); IList<FlowDetail> flowDetailList = genericMgr.FindAll<FlowDetail>(" from FlowDetail d where d.Flow = ? and d.IsRejectInspect = ?", new object[] { flow.Code, false }); com.Sconit.Entity.SCM.FlowStrategy flowStrategy = genericMgr.FindById<com.Sconit.Entity.SCM.FlowStrategy>(flow.Code); #region 冻结日期和投出日期时间,冻结取计算时段第一个时段不能交进来,投出取计算前一个工作日的倒数4个时段作为交货时段,先做倒数第4个时段好了,平均分配太麻烦 DateTime freezeDate = DateTime.Parse("2999-1-1 00:00:00"); DateTime effDate = DateTime.Parse("1900-1-1 00:00:00"); #endregion #region 按路线明细计算看板 // string matchLocation = flow.Type == com.Sconit.CodeMaster.OrderType.Procurement ? flow.LocationTo : flow.LocationFrom; foreach (FlowDetail flowDetail in flowDetailList) { IList<ItemDailyConsume> flowDetailItemDailyConsumeList = itemDailyConsumeList.Where(p => p.Item == flowDetail.Item && (p.Location == flow.LocationFrom || p.Location == flow.LocationTo)).ToList(); //IList<KanbanCard> existKanbanCardList = genericMgr.FindAll<KanbanCard>("from KanbanCard c where c.FlowDetailId = ?", flowDetail.Id); int existKanbanNum = flowDetail.CycloidAmount; decimal calculatedKanbanNum = 0; DateTime? calcDate = null; Decimal calcQty = 0; string groupNo = string.Empty; int tiao = 0; IList<string> shiftList = workingCalendatList.Select(i => i.Shift).Distinct().ToList(); #region 计算 if (flowDetailItemDailyConsumeList != null && flowDetailItemDailyConsumeList.Count > 0) { foreach (ItemDailyConsume idc in flowDetailItemDailyConsumeList) { WorkingCalendar wc = workingCalendatList.Where(w => w.Region == flow.PartyTo && w.WorkingDate == idc.ConsumeDate).ToList().FirstOrDefault(); if (wc != null && wc.Type == (int)com.Sconit.CodeMaster.WorkingCalendarType.Work) { int qtbM = flowShiftDetailList.Where(f => f.Shift == wc.Shift).Count(); int workTimeNum = shiftMasterList.Where(s => s.Code == wc.Shift).FirstOrDefault().ShiftCount; if (qtbM > 0 && workTimeNum > 0 && flowDetail.UnitCount > 0) { decimal dailyKanbanNum = Convert.ToDecimal((idc.Qty * ((1 + flowStrategy.LeadTime) * workTimeNum + (flowDetail.SafeStock == null ? 0 : flowDetail.SafeStock.Value) * qtbM)) / (qtbM * workTimeNum * flowDetail.UnitCount)); if (dailyKanbanNum > calculatedKanbanNum) { calculatedKanbanNum = dailyKanbanNum; calcQty = idc.Qty; calcDate = idc.ConsumeDate; groupNo = idc.MultiSupplyGroup; tiao = qtbM; } } else { break; } } } } else { #region 本次无日用量的,应该所有的都冻结 #endregion } #endregion #region 记录计算结果 KanbanCalc kanbanCalc = new KanbanCalc(); kanbanCalc.Flow = flow.Code; kanbanCalc.KBCalc = (com.Sconit.CodeMaster.KBCalculation)kbCalc; kanbanCalc.CalcConsumeDate = calcDate; kanbanCalc.CalcConsumeQty = calcQty; kanbanCalc.CalcKanbanNum = calculatedKanbanNum; kanbanCalc.Flow = flow.Code; kanbanCalc.FlowDetailId = flowDetail.Id; kanbanCalc.Item = flowDetail.Item; Item item = itemList.Where(k => k.Code == kanbanCalc.Item).FirstOrDefault(); kanbanCalc.ItemDescription = item.Description; // kanbanCalc.Container = item.UnitCountDescription; if (item.IsKit) { kanbanCalc.IsKit = item.IsKit; kanbanCalc.KitCount = itemKitList.Where(p => p.KitItem == item.Code).Count(); } ItemTrace itemTrace = itemTraceList.Where(t => t.Item == flowDetail.Item).FirstOrDefault(); if (itemTrace != null) { kanbanCalc.IsTrace = true; } Supplier supplier = supplierList.Where(s => s.Code == flow.PartyFrom).FirstOrDefault(); //if (supplier != null) //{ // kanbanCalc.LogisticCenterCode = supplier.LogisticsCentre; // kanbanCalc.LogisticCenterName = supplier.LogisticsCentreName; //} //kanbanCalc.GroupNo = flowDetail.GroupNo; //kanbanCalc.GroupDesc = flowDetail.GroupDesc; kanbanCalc.KanbanNum = existKanbanNum; kanbanCalc.Qty = flowDetail.UnitCount; kanbanCalc.KanbanDeltaNum = (int)Math.Ceiling(kanbanCalc.CalcKanbanNum < 1 ? 1 : kanbanCalc.CalcKanbanNum) - existKanbanNum; kanbanCalc.MultiSupplyGroup = groupNo; kanbanCalc.Region = calcRegion.Code; kanbanCalc.RegionName = calcRegion.Name; kanbanCalc.Supplier = flow.PartyFrom; var sup = partyList.Where(p => p.Code == flow.PartyFrom).FirstOrDefault(); kanbanCalc.SupplierName = sup.Name; if (sup is Supplier) { Supplier su = sup as Supplier; kanbanCalc.SupplierName = string.IsNullOrEmpty(su.ShortCode) ? su.Name.Substring(0, 4) : su.ShortCode; } // kanbanCalc.QiTiaoBian = flowStrategy.QiTiaoBian; kanbanCalc.OpRef = flowDetail.BinTo; kanbanCalc.Location = flow.LocationTo; //if (tiao == 0) //{ // string[] tiaoArray = flowStrategy.QiTiaoBian.Split('-'); // if (tiaoArray.Count() == 3) // { // tiao = Convert.ToInt32(tiaoArray[1]); // } //} kanbanCalc.Tiao = tiao; kanbanCalc.Bian = Convert.ToInt32(flowStrategy.LeadTime); LocationBinItem locationBinItem = locationBinItemList.Where(l => l.Location == flow.LocationTo && l.Item == flowDetail.Item).FirstOrDefault(); if (locationBinItem != null) { kanbanCalc.LocBin = locationBinItem.Bin; } // kanbanCalc.Shelf = flowDetail.Shelf; kanbanCalc.LastUseDate = DateTime.Parse("1900-1-1 00:00:00"); //if (!calcRegion.IsAutoExportKanBanCard) //{ // if (freezeDate == DateTime.Parse("2999-1-1 00:00:00") && kanbanCalc.KanbanDeltaNum < 0) // { // freezeDate = GetFreezeDate(startDate, flow, Convert.ToInt32(flowStrategy.LeadTime)); // } // // kanbanCalc.FreezeDate = freezeDate; // if (effDate == DateTime.Parse("1900-1-1 00:00:00") && kanbanCalc.KanbanDeltaNum > 0) // { // effDate = GetEffDate(startDate, flow, Convert.ToInt32(flowStrategy.LeadTime)); // } //} //else //{ if (freezeDate == DateTime.Parse("2999-1-1 00:00:00") && kanbanCalc.KanbanDeltaNum <= 0) { freezeDate = dateTimeNow; } if (effDate == DateTime.Parse("1900-1-1 00:00:00") && kanbanCalc.KanbanDeltaNum >= 0) { effDate = dateTimeNow; } //} kanbanCalc.FreezeDate = freezeDate; kanbanCalc.EffectiveDate = effDate; kanbanCalc.OpTime = DateTime.Parse("1900-1-1 00:00:00"); kanbanCalc.BatchNo = batchno; #region 处理双轨 if (!string.IsNullOrEmpty(groupNo)) { IList<KanbanCalc> kCalcList = kanbanCalcList.Where(k => k.MultiSupplyGroup == groupNo & k.Region == calcRegion.Code).ToList(); if (kCalcList != null && kCalcList.Count > 0) { decimal gKanbanNum = kCalcList.Max(k => k.CalcKanbanNum); if (gKanbanNum > calculatedKanbanNum) { kanbanCalc.CalcKanbanNum = gKanbanNum; kanbanCalc.KanbanDeltaNum = (int)Math.Ceiling(gKanbanNum) - existKanbanNum; } else { foreach (KanbanCalc k in kCalcList) { k.CalcKanbanNum = calculatedKanbanNum; k.KanbanDeltaNum = (int)Math.Ceiling(calculatedKanbanNum) - existKanbanNum; } } } } kanbanCalcList.Add(kanbanCalc); #endregion #endregion #region 记录路线明细上的日产量,交货趟次 flowDetail.MaxStock = kanbanCalc.CalcConsumeQty; flowDetail.MrpWeight = kanbanCalc.Tiao; genericMgr.Update(flowDetail); #endregion } #endregion } #endregion #region 生产 if (kbCalc == (int)com.Sconit.CodeMaster.KBCalculation.CatItem) { IList<FlowDetail> flowDetailList = genericMgr.FindAll<FlowDetail>(" from FlowDetail d where d.Flow = ?", flow.Code); com.Sconit.Entity.SCM.FlowStrategy flowStrategy = genericMgr.FindById<com.Sconit.Entity.SCM.FlowStrategy>(flow.Code); DateTime freezeDate = DateTime.Parse("2999-1-1 00:00:00"); DateTime effDate = DateTime.Parse("1900-1-1 00:00:00"); foreach (FlowDetail flowDetail in flowDetailList) { IList<ItemDailyConsume> flowDetailItemDailyConsumeList = itemDailyConsumeList.Where(p => p.Item == flowDetail.Item).ToList(); // IList<KanbanCard> existKanbanCardList = genericMgr.FindAll<KanbanCard>("from KanbanCard c where c.FlowDetailId = ?", flowDetail.Id); int existKanbanNum = flowDetail.CycloidAmount; decimal calculatedKanbanNum = 0; Decimal calcQty = 0; decimal batchSizeKanbanNum = 0; decimal safeStockKanbanNum = 0; if (flowDetailItemDailyConsumeList != null && flowDetailItemDailyConsumeList.Count > 0) { if (flowDetail.UnitCount != 0) { decimal maxQty = flowDetailItemDailyConsumeList.Max(f => f.Qty); decimal batchsizeQty = flowDetail.BatchSize.HasValue ? flowDetail.BatchSize.Value : 0; #region 正常零件 //if (string.IsNullOrEmpty(flowDetail.GroupNo)) //{ calcQty = maxQty; //} #endregion #region 种别件 //else //{ // IList<FlowDetail> gFlowDetailList = flowDetailList.Where(f => f.GroupNo == flowDetail.GroupNo).ToList(); // decimal groupQty = 0; // foreach (FlowDetail g in gFlowDetailList) // { // IList<ItemDailyConsume> l = itemDailyConsumeList.Where(p => p.Item == g.Item).ToList(); // if (l != null && l.Count > 0) // { // groupQty += l.Max(f => f.Qty); // } // } // batchsizeQty = batchsizeQty * maxQty / groupQty; //} #endregion #region 计算 decimal safeStock = flowDetail.SafeStock == null ? 0 : flowDetail.SafeStock.Value; // decimal shiftType = string.IsNullOrEmpty(flowDetail.Shift) ? 1 : Convert.ToInt32(flowDetail.Shift); decimal shiftType = 1; //安全张数, 需求数*安全时数/(8*焊装班次) if (flowDetail.UnitCount < 2 * maxQty) { int safeQty = (int)Math.Round(maxQty * safeStock / (8 * shiftType), 0, MidpointRounding.AwayFromZero); safeStockKanbanNum = (int)Math.Round(safeQty / flowDetail.UnitCount, 0, MidpointRounding.AwayFromZero); } //批量张数 batchSizeKanbanNum = (int)Math.Ceiling(batchsizeQty / flowDetail.UnitCount); calculatedKanbanNum = batchSizeKanbanNum + safeStockKanbanNum; calcQty = maxQty; #endregion } } else { #region 本次无日用量的,应该所有的都冻结 #endregion } #region 记录计算结果 KanbanCalc kanbanCalc = new KanbanCalc(); kanbanCalc.Flow = flow.Code; kanbanCalc.KBCalc = (com.Sconit.CodeMaster.KBCalculation)kbCalc; kanbanCalc.CalcConsumeQty = calcQty; kanbanCalc.CalcKanbanNum = calculatedKanbanNum; kanbanCalc.Flow = flow.Code; kanbanCalc.FlowDetailId = flowDetail.Id; kanbanCalc.Item = flowDetail.Item; Item item = itemList.Where(k => k.Code == kanbanCalc.Item).FirstOrDefault(); kanbanCalc.ItemDescription = item.Description; kanbanCalc.Container = item.Description; if (item.IsKit) { kanbanCalc.IsKit = item.IsKit; kanbanCalc.KitCount = itemKitList.Where(p => p.KitItem == item.Code).Count(); } ItemTrace itemTrace = itemTraceList.Where(t => t.Item == flowDetail.Item).FirstOrDefault(); if (itemTrace != null) { kanbanCalc.IsTrace = true; } //kanbanCalc.GroupNo = flowDetail.GroupNo; //kanbanCalc.GroupDesc = flowDetail.GroupDesc; kanbanCalc.KanbanNum = existKanbanNum; kanbanCalc.Qty = flowDetail.UnitCount; kanbanCalc.KanbanDeltaNum = (int)Math.Ceiling(calculatedKanbanNum) - existKanbanNum; kanbanCalc.Region = calcRegion.Code; kanbanCalc.RegionName = calcRegion.Name; kanbanCalc.Supplier = flow.PartyFrom; var sup = partyList.Where(p => p.Code == flow.PartyFrom).FirstOrDefault(); kanbanCalc.SupplierName = sup.Name; if (sup is Supplier) { Supplier su = sup as Supplier; kanbanCalc.SupplierName = string.IsNullOrEmpty(su.ShortCode) ? su.Name.Substring(0, 4) : su.ShortCode; } kanbanCalc.LastUseDate = DateTime.Parse("1900-1-1 00:00:00"); LocationBinItem locationBinItem = locationBinItemList.Where(l => l.Location == flow.LocationTo && l.Item == flowDetail.Item).FirstOrDefault(); if (locationBinItem != null) { kanbanCalc.LocBin = locationBinItem.Bin; } kanbanCalc.BatchNo = batchno; kanbanCalc.BatchKanbanNum = batchSizeKanbanNum; kanbanCalc.SafeKanbanNum = safeStockKanbanNum; kanbanCalc.Location = flow.LocationTo; if (kanbanCalc.KanbanDeltaNum > 0) { effDate = DateTime.Now; } if (kanbanCalc.KanbanDeltaNum < 0) { freezeDate = DateTime.Now; } kanbanCalc.EffectiveDate = effDate; kanbanCalc.FreezeDate = freezeDate; kanbanCalcList.Add(kanbanCalc); #endregion } } #endregion } } } #region 生成结果 // kanbanCalcList.AddRange(lerror); if (kanbanCalcList.Count > 0) { foreach (KanbanCalc kc in kanbanCalcList) { this.genericMgr.Create(kc); } } #endregion }