private async void btnDelete_Click(object sender, EventArgs e) { // Lay may bay dang duoc chon trong bang FlightSchedule flightSchedule = GetSelectedFlightSchedule(); // Neu hien tai khong co may bay nao duoc chon thi hien thong bao if (flightSchedule == null) { MessageBox.Show("You must choose an airplane to edit!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Neu co may bay dang duoc chon thi sua cot IsActive lai thanh False flightSchedule.IsActive = false; // Gui len server de cap nhat lai cot IsActive trong CSDL FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper(); bool isSuccess = await flightScheduleWrapper.Put(flightSchedule.ID.ToString(), flightSchedule); // Kiem tra ket qua tra ve if (isSuccess) { // Neu ket qua la thanh cong, hien thong bao thanh cong MessageBox.Show("Flight Schedule was set to inactive!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); // Load lai bang LoadDataGridView(); } else { // Neu ket qua that bai, hien thong bao loi MessageBox.Show("An error has occurred!\n" + flightScheduleWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void btnSubmit_Click(object sender, System.EventArgs e) { // Lay gia tri tren form gan vao flightSchedule.AirplaneCode = ((Airplane)cboAirplane.SelectedItem).AirplaneCode; flightSchedule.RouteID = ((Route)cboRoute.SelectedItem).ID; flightSchedule.DepartureDate = dateTimePicker1.Value; flightSchedule.IsActive = rbtnActive.Checked; // Tao mot API FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper(); // Tao bien luu ket qua tra ve bool isSuccess; // Kiem tra xem dang o che do nao if (mode == FormMode.CREATE) { // Neu dang o che do them moi (CREATE) // POST account len server isSuccess = await flightScheduleWrapper.Post(flightSchedule); } else { // Neu dang o che do chinh sua (EDIT) // PUT account len server isSuccess = await flightScheduleWrapper.Put(flightSchedule.ID.ToString(), flightSchedule); } // Kiem tra ket qua tra ve if (isSuccess) { // Neu thanh cong MessageBox.Show("Operation completed successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); // Tat form CE this.Close(); } else { // Neu that bai, hien thong bao loi MessageBox.Show("An error has occurred:\n" + flightScheduleWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }