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 DeleteBus() { DialogResult dr = MessageBox.Show("Are you sure to delete this Bus ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { try { bus = dc.Bus.Single(x => x.Id == Convert.ToInt32(dgBus.CurrentRow.Cells[0].Value)); using (TransactionScope ts = new TransactionScope()) { if (bus != null) { using (BMTDataContext proc = new BMTDataContext()) { proc.DeleteBus(Convert.ToInt32(dgBus.CurrentRow.Cells[0].Value)); 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 void attach_Bus(Bus entity) { this.SendPropertyChanging(); entity.TicketType = this; }
private void detach_Bus(Bus entity) { this.SendPropertyChanging(); entity.TicketType = null; }
partial void DeleteBus(Bus instance);
partial void UpdateBus(Bus instance);
partial void InsertBus(Bus instance);
private void detach_Bus(Bus entity) { this.SendPropertyChanging(); entity.Otobus = null; }
private void attach_Bus(Bus entity) { this.SendPropertyChanging(); entity.Otobus = this; }