private bool ServiceDepartment_atSaveClick(object source, SaveClickEventArgs e) { try { if (NewRecord) { GetSeqNo(); s_Department = new ServiceDepartment(); } s_Department.LocationID = GlobalFunctions.LoginLocationID; s_Department.LoginUserID = GlobalFunctions.LoginUserID; s_Department.DepartmentCode = txtCode.Text; s_Department.DepartmentName = txtName.Text; if (NewRecord) { db.ServiceDepartments.AddObject(s_Department); } if (!NewRecord) { db.ObjectStateManager.ChangeObjectState(s_Department, System.Data.EntityState.Modified); } db.SaveChanges(); PopulateServiceDepartment(); return(true); } catch (UpdateException updEx) { db.DetachAllEntities(); if (updEx.InnerException.Message.Contains("UC_ServiceDepartmentCode")) { if (FirstSaveClick == true && atMessageBox.Show(MessageKeys.MsgCodeAlreadyExistsDoYouWantToFollowTheSeriesBasedOnPreviousSequence, MessageBoxButtons.YesNo) == DialogResult.No) { txtCode.Focus(); return(false); } FirstSaveClick = false; return(ServiceDepartment_atSaveClick(source, e)); } else if (updEx.InnerException != null) { if (updEx.InnerException.Message.Contains("UC_ServiceDepartmentName")) { atMessageBox.Show(MessageKeys.MsgAnother + MessageKeys.MsgService + " (" + txtName.Text + ") " + MessageKeys.MsgWithSameNameAlreadyExistsPleaseEnterDifferentName); txtName.Focus(); return(false); } } ExceptionManager.Publish(updEx); atMessageBox.Show(updEx, ENOperation.Save); return(false); } catch (Exception ex) { db.DetachAllEntities(); ExceptionManager.Publish(ex); atMessageBox.Show(ex, ENOperation.Save); return(false); } }
private bool FrmServiceInsuranceView_atSaveClick(object source, SaveClickEventArgs e) { try { if (NewRecord) { GetSeqNo(); m_ServiceInsurance = new ServiceInsurance(); } m_ServiceInsurance.LocationID = GlobalFunctions.LoginLocationID; m_ServiceInsurance.LoginUserID = GlobalFunctions.LoginUserID; m_ServiceInsurance.InsuranceCode = txtInsuranceCode.Text.ToString(); m_ServiceInsurance.InsuranceName = txtInsuranceName.Text.ToString(); m_ServiceInsurance.Description = txtDescription.Text.ToString(); m_ServiceInsurance.CompanyName = cmbCompany.Text.ToString(); if (NewRecord) { db.ServiceInsurances.AddObject(m_ServiceInsurance); } else { db.ObjectStateManager.ChangeObjectState(m_ServiceInsurance, EntityState.Modified); } db.SaveChanges(); return(true); } catch (UpdateException updEx) { db.DetachAllEntities(); ExceptionManager.Publish(updEx); atMessageBox.Show(MessageKeys.MsgExceptionOccurredWhileSaving); return(false); } catch (Exception ex) { db.DetachAllEntities(); ExceptionManager.Publish(ex); atMessageBox.Show(MessageKeys.MsgExceptionOccurredWhileSaving); return(false); } }