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 (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; } } }
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 (dgvFlightSchedule.SelectedRows.Count == 0) { currentRowIndex = 0; } else { currentRowIndex = dgvFlightSchedule.Rows.IndexOf(dgvFlightSchedule.SelectedRows[0]); } // Luu lai dong hien tai dang o dau` bang? trong dataGridView int firstRowIndex = dgvFlightSchedule.FirstDisplayedScrollingRowIndex; if (firstRowIndex == -1) { firstRowIndex = 0; } // Goi API lay du lieu ve FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper(); List <FlightSchedule> lstFlightSchedule = await flightScheduleWrapper.List(); // Khai bao API de lay du lieu cua bang City (City) // va Thong tin ve` so luong cua tung loai ghe (AirplaneInfo) AirplaneWrapper airplaneWrapper = new AirplaneWrapper(); AirplaneTypeWrapper airplaneTypeWrapper = new AirplaneTypeWrapper(); RouteWrapper routeWrapper = new RouteWrapper(); CityWrapper cityWrapper = new CityWrapper(); // Goi API lay du lieu ve List <Airplane> lstAirplane = await airplaneWrapper.List(); List <AirplaneType> lstAirplaneType = await airplaneTypeWrapper.List(); List <Route> lstRoute = await routeWrapper.List(); List <City> lstCity = await cityWrapper.List(); // Tao bang de chua du lieu tra ve tu API DataTable table = new DataTable(); table.Columns.Add("ID"); // Ma chuyen bay table.Columns.Add("AirplaneCode"); // ID cua may bay table.Columns.Add("AirplaneTypeName"); // ID cua may bay table.Columns.Add("RouteID"); // ID cua chuyen bay table.Columns.Add("CityAName"); // ID cua may bay table.Columns.Add("CityBName"); // ID cua may bay table.Columns.Add("DepartureDate"); // Ngay cat canh table.Columns.Add("FirstSeatAvail"); // So luong ghe hang Nhat con table.Columns.Add("BusinessSeatAvail"); // So luong ghe hang Thuong gia con table.Columns.Add("ClubSeatAvail"); // So luong ghe hang Pho Thong con table.Columns.Add("IsActive"); // Trang thai cua chuyen bay // Kiem tra xem ket qua goi API co thanh cong hay khong if (lstFlightSchedule != null) { // Lap qua tung "dong` du lieu" foreach (FlightSchedule flightSchedule in lstFlightSchedule) { // Goi API de lay So luong cua moi Loai ghe tren may bay nay Airplane airplane = lstAirplane.Find(a => a.AirplaneCode == flightSchedule.AirplaneCode); AirplaneType airplaneType = lstAirplaneType.Find(at => at.ID == airplane.TypeID); // Goi API de lay ID cua chuyen bay (Route) Route route = lstRoute.Find(r => r.ID == flightSchedule.RouteID); City cityA = lstCity.Find(c => c.ID == route.CityAID); City cityB = lstCity.Find(c => c.ID == route.CityBID); // Tao mot dong` trong bang winForm DataRow row = table.NewRow(); // Gan du lieu len dong moi tao row["ID"] = flightSchedule.ID; row["AirplaneCode"] = airplane.AirplaneCode; row["AirplaneTypeName"] = airplaneType.Name; row["RouteID"] = flightSchedule.RouteID; row["CityAName"] = cityA.Name; row["CityBName"] = cityB.Name; row["DepartureDate"] = flightSchedule.DepartureDate.ToString("dd/MM/yyyy"); row["FirstSeatAvail"] = flightSchedule.FirstSeatAvail; row["BusinessSeatAvail"] = flightSchedule.BusinessSeatAvail; row["ClubSeatAvail"] = flightSchedule.ClubSeatAvail; row["IsActive"] = flightSchedule.IsActive; // 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 dgvFlightSchedule.DataSource = table; // An? cot AirplaneTypeID di, khong hien cot nay dgvFlightSchedule.Columns["RouteID"].Visible = false; // Chon lai dong ban dau duoc chon truoc khi reload if (dgvFlightSchedule.Rows.Count > 0) { dgvFlightSchedule.Rows[currentRowIndex].Selected = true; } // Cuon. toi' dong` duoc. chon. if (dgvFlightSchedule.Rows.Count > 0) { dgvFlightSchedule.FirstDisplayedScrollingRowIndex = firstRowIndex; } } }
private async void FormFlightScheduleCE_Load(object sender, System.EventArgs e) { // Lay danh sach cac may bay ve AirplaneWrapper airplaneWrapper = new AirplaneWrapper(); List <Airplane> lstAirplane = await airplaneWrapper.List(); // Goi API lay danh sach cac Loai may bay ve AirplaneTypeWrapper airplaneTypeWrapper = new AirplaneTypeWrapper(); List <AirplaneType> lstAirplaneType = await airplaneTypeWrapper.List(); // Goi API lay danh sach cac Lich bay ve FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper(); List <FlightSchedule> lstFlightSchedule = await flightScheduleWrapper.List(); // Goi API lay danh sach Route ve RouteWrapper routeWrapper = new RouteWrapper(); List <Route> lstRoute = await routeWrapper.List(); // Goi API lay danh sach City ve CityWrapper cityWrapper = new CityWrapper(); List <City> lstCity = await cityWrapper.List(); // Gan loai may bay vao danh sach may bay foreach (Airplane airplane in lstAirplane) { airplane.AirplaneType = lstAirplaneType.Where(at => at.ID == airplane.TypeID).Single(); } // Gan city vao Route foreach (Route route in lstRoute) { route.CityA = lstCity.Where(c => c.ID == route.CityAID).Single(); route.CityB = lstCity.Where(c => c.ID == route.CityBID).Single(); } // Dua danh sach loai may bay len Combobox cboAirplane.DataSource = lstAirplane; cboAirplane.DisplayMember = "AirplaneCode"; // Dua danh sach Route len Combobox cboRoute.DataSource = lstRoute; cboRoute.DisplayMember = "CityAID"; // Neu la che do chinh sua (Edit) thi hien thi thong tin cua may bay len form if (mode == FormMode.EDIT) { // Dua airplane code len cboAirplane.SelectedItem = lstAirplane.Where(a => a.AirplaneCode == flightSchedule.AirplaneCode).Single(); // Chon loai may bay (AirplaneType) tuong ung voi may bay nay cboRoute.SelectedItem = lstRoute.Where(r => r.ID == flightSchedule.RouteID).Single(); // Chon ngay khoi hanh dateTimePicker1.Value = flightSchedule.DepartureDate; if (flightSchedule.IsActive) { // Neu may bay nay dang active thi check vao radio button Active rbtnActive.Checked = true; } else { rbtnInActive.Checked = true; } } else { // Neu dang o che do them moi // Tao moi mot may bay flightSchedule = new FlightSchedule(); // Set lich bay la ngay hien tai dateTimePicker1.Value = DateTime.Now; // Nhung gia tri khac se duoc gan vao may bay khi nguoi dung bam nut Submit } }