private async void btnSubmit_Click(object sender, EventArgs e) { ticket.ChildrenCount = Convert.ToInt32(numChildrenCount.Value); ticket.AdultCount = Convert.ToInt32(numAdultCount.Value); ticket.SeniorCount = Convert.ToInt32(numSeniorCount.Value); ticket.AirplaneClassID = ((AirplaneClass)cboSeatClass.SelectedItem).ID; ticket.OrderDate = dpOrderDate.Value; ticket.Status = cboStatus.SelectedItem.ToString(); ticket.TotalCost = Convert.ToDouble(numTotalCost.Value); // Tao mot API TicketWrapper ticketWrapper = new TicketWrapper(); // Tao bien luu ket qua tra ve bool isSuccess; // Kiem tra xem dang o che do nao if (formMode == FormMode.CREATE) { // Neu dang o che do them moi (CREATE) // POST account len server isSuccess = await ticketWrapper.Post(ticket); } else { // Neu dang o che do chinh sua (EDIT) // PUT account len server isSuccess = await ticketWrapper.Put(ticket.ID.ToString(), ticket); } // 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" + ticketWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void btnDelete_Click(object sender, System.EventArgs e) { Ticket ticket = GetSelectedTicket(); // Neu hien tai khong co may bay nao duoc chon thi hien thong bao if (ticket == null) { MessageBox.Show("You must choose a ticket to delete!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (ticket.Status == "Cancelled") { MessageBox.Show("This ticket was already cancelled!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Neu co may bay dang duoc chon thi sua cot IsActive lai thanh False ticket.Status = "Cancelled"; // Gui len server de cap nhat lai cot IsActive trong CSDL TicketWrapper ticketWrapper = new TicketWrapper(); bool isSuccess = await ticketWrapper.Put(ticket.ID.ToString(), ticket); // Kiem tra ket qua tra ve if (isSuccess) { // Neu ket qua la thanh cong, hien thong bao thanh cong MessageBox.Show("Ticket successfully cancelled!", "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" + ticketWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }