private GroupError GetGroupErrorModel() { try { GroupError error = null; try { if (string.IsNullOrEmpty(txtCode_g.Text)) { MessageBox.Show("Lỗi: Tên Nhóm lỗi không được để trống"); } else if (string.IsNullOrEmpty(txtName_g.Text)) { MessageBox.Show("Lỗi: Tên Nhóm lỗi không được để trống"); } else { error = new GroupError(); error.Id = groupErrId; error.Code = txtCode_g.Text; error.Name = txtName_g.Text; error.Description = txtDescription_g.Text; } } catch (Exception ex) { throw ex; } return(error); } catch (Exception ex) { throw ex; } }
public static ResponseBase InsertOrUpdate(GroupError obj) { var result = new ResponseBase(); try { var db = new PMSEntities(); var isOk = true; if (obj.Id == 0) { db.GroupErrors.Add(obj); } else { var error = db.GroupErrors.FirstOrDefault(x => !x.IsDeleted && x.Id == obj.Id); if (error != null) { error.Code = obj.Code; error.Name = obj.Name; error.Description = obj.Description; } else { isOk = false; result.IsSuccess = false; result.Messages.Add(new Message() { Title = "Lỗi", msg = "cập nhật thông tin thất bại" }); } } if (isOk) { db.SaveChanges(); result.IsSuccess = true; result.Messages.Add(new Message() { Title = "Thông Báo", msg = "Lưu thành công." }); } } catch (Exception ex) { throw ex; } return(result); }
private void SaveGroupError() { try { GroupError groupError = GetGroupErrorModel(); var result = BLLGroupError.InsertOrUpdate(groupError); if (result.IsSuccess) { LoadDataForGridGroupError(); ResetGroupErrorForm(); } MessageBox.Show(result.Messages[0].msg, result.Messages[0].Title); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message); } }