private void SaveBTP_HC(LineModel chuyen, AssignmentForLineModel sanpham) { if (slkh < (lkht + txtQuantity.Value)) { MessageBox.Show("Số lương bạn nhập hiện tại đã vượt sản lượng kế hoạch. Vui lòng nhập trong phạm vi sản lượng kế hoạch", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var btpStructObj = ((PhaseModel)cbbtp_hcStruct.SelectedItem); var newObj = new PhaseDailyModel(); newObj.CommandTypeId = (int)eCommandRecive.ProductIncrease; newObj.PhaseId = btpStructObj.Id; newObj.AssignId = sanpham.STT; newObj.Quantity = (int)txtQuantity.Value; var rs = BLLBTP_HCStructure.Instance.InsertBTPDay(newObj); if (rs.IsSuccess) { Reset(); LoadAssignments(cboCommo.SelectedIndex); if (rs.DataSendKeyPad != null) { frmMainNew.listDataSendKeyPad.Add(rs.DataSendKeyPad); } if (rs.Records != null) { BLLProductivity.ResetNormsDayAndBTPInLine(frmMainNew.getBTPInLineByType, frmMainNew.calculateNormsdayType, frmMainNew.TypeOfCaculateDayNorms, chuyen.MaChuyen, false, frmMainNew.todayStr); DuAn03_HaiDang.Helper.HelperControl.ResetKeypad(chuyen.MaChuyen, false, frmMainNew); } } MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title); lbQuantitiesBTPHC.Text = newObj.Quantity.ToString(); } }
public ResponseBase InsertBTPDay(PhaseDailyModel model) { var rs = new ResponseBase(); rs.IsSuccess = true; try { using (var db = new PMSEntities()) { var now = DateTime.Now; int oldQuantities = 0; var obj = db.P_PhaseDaily.FirstOrDefault(x => x.CreatedDate.Year == now.Year && x.CreatedDate.Month == now.Month && x.CreatedDate.Day == now.Day && x.PhaseId == model.PhaseId); if (obj == null) { obj = new P_PhaseDaily(); Parse.CopyObject(model, ref obj); obj.CreatedDate = DateTime.Now; db.P_PhaseDaily.Add(obj); } else { oldQuantities = obj.Quantity; obj.Quantity = model.Quantity; } db.SaveChanges(); var total = db.P_Phase_Assign_Log.FirstOrDefault(x => x.PhaseId == model.PhaseId && x.AssignId == model.AssignId); if (total == null) { total = new P_Phase_Assign_Log() { Quantity = model.Quantity, AssignId = model.AssignId, PhaseId = model.PhaseId, CreatedDate = obj.CreatedDate }; db.P_Phase_Assign_Log.Add(total); } else { total.Quantity -= oldQuantities; total.Quantity += model.Quantity; } db.SaveChanges(); UpdateLKBTP_HC(model.AssignId, db); rs.IsSuccess = true; rs.Messages.Add(new Message() { Title = "Thông Báo", msg = "Lưu thành công." }); } } catch (Exception ex) { throw ex; } return(rs); }