private bool action(String act) { try { using (TransactionScope ts = new TransactionScope()) { ob = act == "insert" ? new Otobus() : dc.Otobus.FirstOrDefault(id => id.Id == Convert.ToInt16(lbIdValue.Text)); ob.OtobusName = tbOtobusName.Text; if (act == "insert") { dc.Otobus.InsertOnSubmit(ob); } dc.SubmitChanges(); ts.Complete(); if (act != "insert") { lbIdValue.Text = ""; lbIdValue.Visible = false; lbID.Visible = false; bCancel.Visible = false; } tbOtobusName.ResetText(); return(true); } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } }
private bool DeleteOtobus() { DialogResult dr = MessageBox.Show("Are you sure to delete this Otobus ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { try { Otobus oto = new Otobus(); oto = dc.Otobus.FirstOrDefault(x => x.Id == Convert.ToInt16(dgOtobus.CurrentRow.Cells["Id"].Value)); using (TransactionScope ts = new TransactionScope()) { if (oto != null) { dc.Otobus.DeleteOnSubmit(oto); dc.SubmitChanges(); ts.Complete(); return(true); } else { MessageBox.Show("Somthing error with delete proccess", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { return(false); } }