private bool action(String act) { try { using (TransactionScope ts = new TransactionScope()) { vn = act == "insert" ? new Venue() : dc.Venues.Single(id => id.Id == Convert.ToInt16(lbIdValue.Text)); vn.VenueName = tbBusStation.Text.Trim(); vn.VenueLocation = tbLocation.Text.Trim(); if (act == "insert") dc.Venues.InsertOnSubmit(vn); dc.SubmitChanges(); ts.Complete(); if (act != "insert") { lbIdValue.Text = ""; lbIdValue.Visible = false; lbID.Visible = false; bCancel.Visible = false; } tbBusStation.ResetText(); tbLocation.ResetText(); this.tbSearch.CustomButton.Enabled = true; this.cbLoadItem.Enabled = true; return true; } } catch(Exception e) { MessageBox.Show(e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return false; } }
private bool DeleteBusStation() { DialogResult dr = MessageBox.Show("Are you sure to delete this Bus Station ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { try { vn = dc.Venues.Single(i => i.Id == Convert.ToInt16(this.dgBusStation.CurrentRow.Cells[0].Value)); using (TransactionScope ts = new TransactionScope()) { if (vn != null) { dc.Venues.DeleteOnSubmit(vn); 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); return false; } } else { return false; } }
partial void UpdateVenue(Venue instance);
partial void DeleteVenue(Venue instance);
partial void InsertVenue(Venue instance);