private void Save_Assign() { var floor = (Floor)cbFloor2.SelectedItem; var line = (LineModel)cbLine.SelectedItem; var shift = (P_WorkingShift)lueShift.GetSelectedDataRow(); if (floor == null || floor.IdFloor == 0) { MessageBox.Show("Vui lòng chọn Lầu.", "Lỗi Thao tác"); } else if (line == null) { MessageBox.Show("Vui lòng chọn Chuyền.", "Lỗi Thao tác"); } else if (shift == null) { MessageBox.Show("Vui lòng chọn Ca làm việc.", "Lỗi Thao tác"); } else { var lineShift = new LineWorkingShiftModel(); lineShift.Id = Id; lineShift.LineId = line.MaChuyen; lineShift.LineName = line.TenChuyen; lineShift.ShiftId = shift.Id; lineShift.ShiftName = shift.Name; lineShift.ShiftOrder = (int)txtOrder.Value; var rs = BLLLineWorkingShift.InsertOrUpdate(lineShift); if (rs.IsSuccess) { ResetForm_Ass(); GetDataForLineShiftGridView(); } MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title); } }
public static ResponseBase InsertOrUpdate(LineWorkingShiftModel obj) { var result = new ResponseBase(); try { var db = new PMSEntities(); P_LineWorkingShift lineShift; lineShift = db.P_LineWorkingShift.FirstOrDefault(x => !x.IsDeleted && x.LineId == obj.LineId && x.ShiftId == obj.ShiftId && x.Id != obj.Id); if (lineShift != null) { result.IsSuccess = false; result.Messages.Add(new Message() { Title = "Trùng ca Làm Việc", msg = "Chuyển :'" + obj.LineName + "' đã có ca làm việc này rồi. Vui lòng chọn ca làm việc khác." }); } else { lineShift = db.P_LineWorkingShift.FirstOrDefault(x => !x.IsDeleted && x.LineId == obj.LineId && x.ShiftOrder == obj.ShiftOrder && x.Id != obj.Id); if (lineShift != null) { result.IsSuccess = false; result.Messages.Add(new Message() { Title = "Trùng số thứ tự Ca", msg = "Chuyển :'" + obj.LineName + "' đã có số thứ tự ca làm việc này rồi. Vui lòng chọn số thứ tự ca làm việc khác." }); } else { var check = false; if (obj.Id == 0) { lineShift = new P_LineWorkingShift(); Parse.CopyObject(obj, ref lineShift); db.P_LineWorkingShift.Add(lineShift); check = true; } else { lineShift = db.P_LineWorkingShift.FirstOrDefault(x => !x.IsDeleted && x.Id == obj.Id); if (lineShift != null) { check = true; lineShift.LineId = obj.LineId; lineShift.ShiftOrder = obj.ShiftOrder; lineShift.ShiftId = obj.ShiftId; } else { result.IsSuccess = false; result.Messages.Add(new Message() { Title = "Lỗi", msg = "Không tìm thấy thông tin." }); check = false; } } if (check) { db.SaveChanges(); result.IsSuccess = true; result.Messages.Add(new Message() { Title = "Thông Báo", msg = "Lưu thành công." }); } } } } catch (Exception) { } return(result); }