private void btnSave_Click(object sender, EventArgs e) { tour.StartLocation = tbxStartLocation.Text.ToUpper(); tour.Destination = tbxDestination.Text.ToUpper(); tour.StartDate = dtpStartDate.Text.ToString(); tour.EndDate = dtpEndDate.Text.ToString(); tour.TotalSeat = int.Parse(tbxTotalSeat.Text); tour.EmptySeat = int.Parse(tbxEmptySeat.Text); tour.Price = int.Parse(Utils.eraiseComma(tbxPrice.Text)); if (selectedFunction == 0) { try { if (tourModel.insertTour(tour)) { DataRow insertedRow = listTour.NewRow(); insertedRow[0] = tour.TourId = tourModel.getInsertedId(); insertedRow[1] = tour.StartLocation; insertedRow[2] = tour.Destination; insertedRow[3] = tour.StartDate; insertedRow[4] = tour.EndDate; insertedRow[5] = tour.TotalSeat; insertedRow[6] = tour.EmptySeat; insertedRow[7] = tour.Price; listTour.Rows.InsertAt(insertedRow, 0); dtgListTour.DataSource = listTour; selectedFunction = 1; } } catch { Utils.showError(Constants.strFailedInsert); } } else { if (Utils.showConfirm(Constants.strConfirmUpdate) == DialogResult.Yes) { try { if (tourModel.updateTour(tour)) { dtgListTour.Rows[rowIndex].Cells[1].Value = tour.StartLocation; dtgListTour.Rows[rowIndex].Cells[2].Value = tour.Destination; dtgListTour.Rows[rowIndex].Cells[3].Value = tour.StartDate; dtgListTour.Rows[rowIndex].Cells[4].Value = tour.EndDate; dtgListTour.Rows[rowIndex].Cells[5].Value = tour.TotalSeat; dtgListTour.Rows[rowIndex].Cells[6].Value = tour.EmptySeat; dtgListTour.Rows[rowIndex].Cells[7].Value = tour.Price; } } catch { Utils.showError(Constants.strFailedUpdate); } } } }