public static bool saveRec(ref bool modified, bool validated, ref bool newRec, FlexModel.FlextourEntities context, BindingSource source, string name, ErrorProvider error, Cursor curse) { return(saveRec(ref modified, validated, ref newRec, context, source, name, error, curse, true)); }
public static bool saveRec(ref bool modified, bool validated, ref bool newRec, FlexModel.FlextourEntities context, BindingSource source, string name, ErrorProvider error, Cursor curse, bool prompt) { //context = new .FlextourEntities(); try { if (modified || newRec)/////Has the record been changed? { DialogResult select = DialogResult.Yes; if (prompt) { select = DevExpress.XtraEditors.XtraMessageBox.Show("Do you want to confirm these changes?", name, MessageBoxButtons.YesNoCancel); } curse = Cursors.WaitCursor; if (select == DialogResult.Yes) ////keep changes { if (validated) ////are changes valid? { error.Clear(); context.SaveChanges(); modified = false; newRec = false; curse = Cursors.Arrow; return(true); ///Form is saved } DevExpress.XtraEditors.XtraMessageBox.Show("Please correct invalid data entries", "Could Not Save", MessageBoxButtons.OK); return(false); ///There was invalid data } if (select == DialogResult.No) ////Discard changes { error.Clear(); modified = false; if (newRec) { //MessageBox.Show("I am coming here"); source.RemoveCurrent(); context.SaveChanges(); newRec = false; curse = Cursors.Arrow; } return(true); } curse = Cursors.Arrow; return(false); ///Pressed cancel } else { return(true); ///No changes to save } /// } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.Message.Contains("Cannot insert duplicate")) { MessageBox.Show("You are attempting to enter a duplicate record please make the necessary changes."); } else { if (ex.Message.Contains("inner exception")) { MessageBox.Show(ex.InnerException.Message); } else { MessageBox.Show(ex.Message); } } return(false); } }