private void aksi(String aksinya) { sch = aksinya == "insert" ? new tbl_Schedule() : db.tbl_Schedules.FirstOrDefault(x => x.id_schedule == tbIdschedule.Text); sch.price = float.Parse(tbPrice.Text); sch.total_seat = (int)nupTotalseat.Value; sch.date = dtpDeparturedate.Value; sch.id_plane = int.Parse(tbIdplane.Text); sch.departure_origin = int.Parse(tbDepartureorigin.Text); sch.arrival_origin = int.Parse(tbArrivalorigin.Text); sch.arrival_date = dtpArrivaldate.Value; if (aksinya == "insert") { sch.id_schedule = tbIdschedule.Text; db.tbl_Schedules.InsertOnSubmit(sch); db.SubmitChanges(); } for (int i = 0; i < 3; i++) { if (!String.IsNullOrEmpty(us[i].textBox1.Text)) { schd = db.tbl_ScheduleDetails.FirstOrDefault(x => x.id_schedule == tbIdschedule.Text && x.id_route == int.Parse(us[i].textBox1.Text)); if (schd != null) { schd.id_route = int.Parse(us[i].textBox1.Text); db.SubmitChanges(); } } } db.SubmitChanges(); }
private void btnAdd_Click(object sender, EventArgs e) { String message = ""; if (va.doValidation() == false) { return; } sch = db.tbl_Schedules.FirstOrDefault(x => x.id_schedule == tbIdschedule.Text); if (sch != null) { aksi("update"); message = "Update"; } else { aksi("insert"); message = "Insert"; } MessageBox.Show(message + " data success!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); loadGrid(); va.clear("tbIdschedule", 100); }
private void action() { sch = new tbl_Schedule { id_train = int.Parse(cmbIdTrain.Text), id_route = int.Parse(cmbIdRoute.Text), id_ticket = int.Parse(cmbIdTicket.SelectedValue.ToString()), harga = float.Parse(cmbIdType.Text), departure_date = DateTime.Parse(dtpDate.Text) }; db.tbl_Schedules.InsertOnSubmit(sch); db.SubmitChanges(); }