private bool DeleteTicketType() { DialogResult dr = MessageBox.Show("Are you sure to delete this Ticket Type ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { try { tt = dc.TicketTypes.FirstOrDefault(x => x.Id == Convert.ToInt32(dgTicket.CurrentRow.Cells[0].Value)); using (TransactionScope ts = new TransactionScope()) { if (tt != null) { dc.TicketTypes.DeleteOnSubmit(tt); dc.SubmitChanges(); ts.Complete(); return(true); } else { return(false); } } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } } else { return(false); } }
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 action(string act) { try { if (tbDeparture.Text.Trim() != tbDestination.Text.Trim()) { var check = dc.Routes.Where(i => i.RouteDeparture == Convert.ToInt32(tbDeparture.Text.Trim()) && i.RouteDestination == Convert.ToInt32(tbDestination.Text.Trim())).ToList(); if (check.Count == 0) { using (TransactionScope ts = new TransactionScope()) { rt = act == "insert" ? new Route() : dc.Routes.FirstOrDefault(id => id.Id == Convert.ToInt32(lbIdValue.Text)); rt.RouteDeparture = Convert.ToInt32(tbDeparture.Text.Trim()); rt.RouteDestination = Convert.ToInt32(tbDestination.Text.Trim()); if (act == "insert") { dc.Routes.InsertOnSubmit(rt); } dc.SubmitChanges(); ts.Complete(); if (act != "insert") { lbIdValue.Text = ""; lbIdValue.Visible = false; lbID.Visible = false; bCancel.Visible = false; } tbDeparture.ResetText(); tbDepartureNameLocation.ResetText(); tbDestination.ResetText(); tbDestinationNameLocation.ResetText(); return(true); } } else { MessageBox.Show("The route is already exists", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } } else { MessageBox.Show("Departure and Destination must be different", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } } catch (Exception e) { MessageBox.Show(e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } }
private bool action(string act) { try { string busnumber = null; using (TransactionScope ts = new TransactionScope()) { string[] split = lbIdValue.Text.Split('-'); bus = act == "insert" ? new Bus() : dc.Bus.Single(id => id.Id == Convert.ToInt32(split[0])); if (act == "insert") { bus.Active = 1; } bus.IdOtobus = Convert.ToInt32(tbOtobus.Text.Trim()); bus.IdTicketType = Convert.ToInt32(tbTicketType.Text.Trim()); bus.BusModel = tbBusModel.Text.Trim(); bus.TotalSeat = Convert.ToInt32(nudSeats.Value.ToString().Trim()); if (act == "insert") { dc.Bus.InsertOnSubmit(bus); } dc.SubmitChanges(); if (act == "insert") { busnumber = bus.BusNumber; } ts.Complete(); if (act != "insert") { lbIdValue.Text = ""; lbIdValue.Visible = false; lbID.Visible = false; bCancel.Visible = false; } if (act == "insert") { MessageBox.Show("Bus Number " + busnumber + " successfully inserted.", Application.ProductName); } tbOtobus.ResetText(); tbOtobusName.ResetText(); tbTicketType.ResetText(); tbTicketTypeName.ResetText(); tbBusModel.ResetText(); nudSeats.Value = Convert.ToDecimal("0"); return(true); } } catch (Exception e) { MessageBox.Show(e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } }
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); } }