private async void FormTicketCE_Load(object sender, System.EventArgs e)
        {
            ProfileWrapper profileWrapper = new ProfileWrapper();
            List <Profile> lstProfile     = await profileWrapper.List();

            AirplaneClassWrapper airplaneClassWrapper = new AirplaneClassWrapper();
            List <AirplaneClass> lstAirplaneClass     = await airplaneClassWrapper.List();

            FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper();

            //List<FlightSchedule> lstFlightSchedule = await flightScheduleWrapper.List();

            cboSeatClass.DataSource    = lstAirplaneClass;
            cboSeatClass.DisplayMember = "Class";

            if (formMode == FormMode.EDIT)
            {
                ticket.AirplaneClass   = lstAirplaneClass.Find(ac => ac.ID == ticket.AirplaneClassID);
                ticket.FlightSchedules = await flightScheduleWrapper.List(ticket.ID);

                ticket.Profile = lstProfile.Find(p => p.ID == ticket.ProfileID);

                lbTicketCode.Text      = "Ticket Code: " + ticket.TicketCode;
                txtPassengerName.Text  = ticket.Profile.FirstName + " " + ticket.Profile.LastName;
                numChildrenCount.Value = ticket.ChildrenCount;
                numAdultCount.Value    = ticket.AdultCount;
                numSeniorCount.Value   = ticket.SeniorCount;

                cboSeatClass.SelectedItem = ticket.AirplaneClass;
                dpOrderDate.Value         = ticket.OrderDate;
                cboStatus.SelectedItem    = ticket.Status;
                numTotalCost.Value        = Convert.ToDecimal(ticket.TotalCost);

                LoadDataGridView(ticket.FlightSchedules.ToList());

                // If the ticket status is cancelled, not allow to edit
                if (ticket.Status == "Cancelled")
                {
                    DisableEditMode();
                }
            }
            else
            {
                ticket = new Ticket();
            }
        }
        public async void LoadDataGridView()
        {
            // Luu lai dong hien tai dang chon
            int currentRowIndex;

            // Neu hien tai khong co dong nao duoc chon thi mac dinh la dong so 0
            if (dgvAirplaneClass.SelectedRows.Count == 0)
            {
                currentRowIndex = 0;
            }
            else
            {
                currentRowIndex = dgvAirplaneClass.Rows.IndexOf(dgvAirplaneClass.SelectedRows[0]);
            }

            // Luu lai dong hien tai dang o dau` bang? trong dataGridView
            int firstRowIndex = dgvAirplaneClass.FirstDisplayedScrollingRowIndex;

            if (firstRowIndex == -1)
            {
                firstRowIndex = 0;
            }

            // Goi API lay du lieu ve
            AirplaneClassWrapper airplaneClassWrapper = new AirplaneClassWrapper();
            List <AirplaneClass> lstAirplaneClass     = await airplaneClassWrapper.List();

            // Tao bang de chua du lieu tra ve tu API
            DataTable table = new DataTable();

            table.Columns.Add("ID");
            table.Columns.Add("Class");
            table.Columns.Add("PriceRate");

            // Kiem tra xem ket qua goi API co thanh cong hay khong
            if (lstAirplaneClass != null)
            {
                // Lap qua tung "dong` du lieu"
                foreach (AirplaneClass airplaneClass in lstAirplaneClass)
                {
                    // Tao mot dong` trong bang winForm
                    DataRow row = table.NewRow();

                    // Gan du lieu len dong moi tao
                    row["ID"]        = airplaneClass.ID;
                    row["Class"]     = airplaneClass.Class;
                    row["PriceRate"] = airplaneClass.PriceRate;
                    // Gan dong moi tao vao bang
                    table.Rows.Add(row);
                }

                // Sau khi lap qua het cac dong du lieu
                // Ta co bang WinForm hoan chinh
                // Gan bang WinForm len DataGridView
                dgvAirplaneClass.DataSource = table;

                // Chon lai dong ban dau duoc chon truoc khi reload
                if (dgvAirplaneClass.Rows.Count > 0)
                {
                    dgvAirplaneClass.Rows[currentRowIndex].Selected = true;
                }

                // Cuon. toi' dong` duoc. chon.
                if (dgvAirplaneClass.Rows.Count > 0)
                {
                    dgvAirplaneClass.FirstDisplayedScrollingRowIndex = firstRowIndex;
                }
            }
        }
        public async void LoadDataGridView()
        {
            // Luu lai dong hien tai dang chon
            int currentRowIndex;

            // Neu hien tai khong co dong nao duoc chon thi mac dinh la dong so 0
            if (dgvTicket.SelectedRows.Count == 0)
            {
                currentRowIndex = 0;
            }
            else
            {
                currentRowIndex = dgvTicket.Rows.IndexOf(dgvTicket.SelectedRows[0]);
            }

            // Luu lai dong hien tai dang o dau` bang? trong dataGridView
            int firstRowIndex = dgvTicket.FirstDisplayedScrollingRowIndex;

            if (firstRowIndex == -1)
            {
                firstRowIndex = 0;
            }

            // Goi API lay du lieu ve
            ProfileWrapper profileWrapper = new ProfileWrapper();
            List <Profile> lstProfile     = await profileWrapper.List();

            TicketWrapper ticketWrapper = new TicketWrapper();
            List <Ticket> lstTicket     = await ticketWrapper.List();

            AirplaneClassWrapper airplaneClassWrapper = new AirplaneClassWrapper();
            List <AirplaneClass> lstAirplaneClass     = await airplaneClassWrapper.List();

            FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper();
            //List<FlightSchedule> lstFlightSchedule = await flightScheduleWrapper.List();

            RouteWrapper routeWrapper = new RouteWrapper();
            List <Route> lstRoute     = await routeWrapper.List();

            CityWrapper cityWrapper = new CityWrapper();
            List <City> lstCity     = await cityWrapper.List();


            // Tao bang de chua du lieu tra ve tu API
            DataTable table = new DataTable();

            table.Columns.Add("ID");
            table.Columns.Add("TicketCode");
            table.Columns.Add("ProfileID");
            table.Columns.Add("PassengerName");
            table.Columns.Add("From");
            table.Columns.Add("To");
            table.Columns.Add("Status");
            table.Columns.Add("ChildrenCount");
            table.Columns.Add("AdultCount");
            table.Columns.Add("SeniorCount");
            table.Columns.Add("AirplaneClassID");
            table.Columns.Add("AirplaneClassName");
            table.Columns.Add("OrderDate");
            table.Columns.Add("TotalCost");

            // Kiem tra xem ket qua goi API co thanh cong hay khong
            if (lstTicket != null)
            {
                // Lap qua tung "dong` du lieu"
                foreach (Ticket ticket in lstTicket)
                {
                    // Gan them du lieu len cho day du
                    ticket.AirplaneClass   = lstAirplaneClass.Find(ac => ac.ID == ticket.AirplaneClassID);
                    ticket.FlightSchedules = await flightScheduleWrapper.List(ticket.ID);

                    ticket.Profile = lstProfile.Find(p => p.ID == ticket.ProfileID);

                    foreach (FlightSchedule fs in ticket.FlightSchedules)
                    {
                        fs.Route       = lstRoute.Find(r => r.ID == fs.RouteID);
                        fs.Route.CityA = lstCity.Find(c => c.ID == fs.Route.CityAID);
                        fs.Route.CityB = lstCity.Find(c => c.ID == fs.Route.CityBID);
                    }

                    // Tao mot dong` trong bang winForm
                    DataRow row = table.NewRow();

                    // Gan du lieu len dong moi tao
                    row["ID"]                = ticket.ID;
                    row["TicketCode"]        = ticket.TicketCode;
                    row["ProfileID"]         = ticket.ProfileID;
                    row["PassengerName"]     = ticket.Profile.FirstName + " " + ticket.Profile.LastName;
                    row["From"]              = ticket.FlightSchedules.First().Route.CityA.Name;
                    row["To"]                = ticket.FlightSchedules.Last().Route.CityB.Name;
                    row["Status"]            = ticket.Status;
                    row["ChildrenCount"]     = ticket.ChildrenCount;
                    row["AdultCount"]        = ticket.AdultCount;
                    row["SeniorCount"]       = ticket.SeniorCount;
                    row["AirplaneClassID"]   = ticket.AirplaneClassID;
                    row["AirplaneClassName"] = ticket.AirplaneClass.Class;
                    row["OrderDate"]         = ticket.OrderDate;
                    row["TotalCost"]         = ticket.TotalCost;

                    // Gan dong moi tao vao bang
                    table.Rows.Add(row);
                }

                // Sau khi lap qua het cac dong du lieu
                // Ta co bang WinForm hoan chinh
                // Gan bang WinForm len DataGridView
                dgvTicket.DataSource = table;

                // An cac cot khong can thiet hien thi
                dgvTicket.Columns["ID"].Visible              = false;
                dgvTicket.Columns["ProfileID"].Visible       = false;
                dgvTicket.Columns["ChildrenCount"].Visible   = false;
                dgvTicket.Columns["AdultCount"].Visible      = false;
                dgvTicket.Columns["SeniorCount"].Visible     = false;
                dgvTicket.Columns["AirplaneClassID"].Visible = false;

                // Chon lai dong ban dau duoc chon truoc khi reload
                if (dgvTicket.Rows.Count > 0)
                {
                    dgvTicket.Rows[currentRowIndex].Selected = true;
                }

                // Cuon. toi' dong` duoc. chon.
                if (dgvTicket.Rows.Count > 0)
                {
                    dgvTicket.FirstDisplayedScrollingRowIndex = firstRowIndex;
                }
            }
        }