Exemplo n.º 1
0
        public static void AddCity(string sheetName)
        {
            Logger.WriteToLogFile(Utilities.GetCurrentMethod());

            Excel.Worksheet sheet = ExcelController.GetWorkSheet(sheetName);

            Excel.Range usedRange = sheet.UsedRange;

            CityWrapper objWrap    = new CityWrapper();
            Country     objCountry = new Country();
            State       objState   = new State();

            //Do not consider row 1 as its the header
            for (int Row = 2; Row <= usedRange.Rows.Count; Row++)
            {
                City objCity = new City();

                for (int Col = 1; Col <= usedRange.Columns.Count; Col++)
                {
                    string name = (string)(usedRange.Cells[1, Col] as Excel.Range).Value2;
                    name = name.Trim();
                    string value = null;

                    if ((usedRange.Cells[Row, Col] as Excel.Range).Value2 != null)
                    {
                        value = (usedRange.Cells[Row, Col] as Excel.Range).Value2.ToString();
                    }
                    else
                    {
                        continue;
                    }

                    if (name.CompareTo(ExcelSheets.EXCELSHEET_COUNTRY) == 0)
                    {
                        objCountry.Name = value;
                        continue;
                    }
                    else
                    if (name.CompareTo(ExcelSheets.EXCELSHEET_STATE) == 0)
                    {
                        objState.Name = value;
                        continue;
                    }

                    ExcelUtilities.PopulateStructure <City>(name, value, ref objCity);
                }

                //Add the country in the Neo4j Database

                objWrap.objState   = objState;
                objWrap.objCountry = objCountry;
                objWrap.objCity    = objCity;

                DBAddinterface.CreateCityNode(objWrap);
            }
        }
Exemplo n.º 2
0
        private void ParseAsCities(Stream jsonStream)
        {
            CityWrapper myWrapper = CurrentWeatherGetter.TranslateJson <CityWrapper>(jsonStream);

            if (myWrapper == null)
            {
                return;
            }

            ObservableCollection <City> myCities = new ObservableCollection <City>();

            foreach (City c in myWrapper.RESULTS)
            {
                myCities.Add(c);
            }

            this.control.Dispatcher.BeginInvoke(delegate { control.DataContext = myCities; });
        }
Exemplo n.º 3
0
        public static City GetCityNode(CityWrapper objWrap)
        {
            Logger.WriteToLogFile(DBInteractor.Common.Utilities.GetCurrentMethod());
            Logger.WriteObjectToLogFile <City>(objWrap.objCity);

            StateWrapper objStateWrapper = new StateWrapper();

            objStateWrapper.objCountry = objWrap.objCountry;
            objStateWrapper.objState   = objWrap.objState;
            City objCity = objWrap.objCity;

            State objState = GetStateNode(objStateWrapper);

            if (objState == null)
            {
                return(null);
            }

            City retCity = null;

            var result = Neo4jController.m_graphClient.Cypher
                         .Match("(A:" + objState.getLabel() + " { id : {Stateid }})")
                         .Match("(B:" + objCity.getLabel() + " { Name : {CityName }})")
                         .Match("(A)-[r:" + Rel_State.state_city + "]->(B)")
                         .WithParams(new
            {
                Stateid  = objState.id,
                CityName = objCity.Name
            })
                         .Return(B => B.As <City>())
                         .Results;

            if (result.Count() > 0)
            {
                Logger.WriteToLogFile("City found");
                retCity = result.ElementAt(0);
            }
            else
            {
                Logger.WriteToLogFile("City not found");
            }

            return(retCity);
        }
Exemplo n.º 4
0
        public static void CreateCityNode(CityWrapper objWrap)
        {
            Logger.WriteToLogFile(DBInteractor.Common.Utilities.GetCurrentMethod());
            Logger.WriteObjectToLogFile <City>(objWrap.objCity);


            City  objCity  = objWrap.objCity;
            State objState = objWrap.objState;

            if (objState == null)
            {
                Logger.WriteToLogFile("Unable to find State...No creating city");
                throw new Exception("State is null");
            }

            var result = Neo4jController.
                         m_graphClient.Cypher
                         .Match("(A:" + objState.getLabel() + " { id : {Stateid }})")
                         .Merge("(A)-[R:" + Rel_State.state_city + "]->(B:" + objCity.getLabel() + "{ Name : {cityName} })")
                         .OnCreate()
                         .Set("B = { objCity}")
                         .WithParams(new
            {
                Stateid  = objState.id,
                objCity  = objCity,
                cityName = objCity.Name
            })
                         .Return((B, R) => new
            {
                StateCount    = B.Count(),
                RelationCount = R.Count()
            })
                         .Results
                         .Single();

            if (result.StateCount == 1)
            {
                Logger.WriteToLogFile("Successfully created City");
            }
            else
            {
                Logger.WriteToLogFile("Unable to create City");
            }
        }
        private async void FormRouteCE_Load(object sender, System.EventArgs e)
        {
            // Goi API lay danh sach cac Loai may bay ve
            CityWrapper cityWrapper = new CityWrapper();
            List <City> lstCityA    = await cityWrapper.List();

            List <City> lstCityB = new List <City>(lstCityA);

            // Dua danh sach loai may bay len Combobox
            cboFromCity.DataSource    = lstCityA;
            cboFromCity.DisplayMember = "Name";

            cboToCity.DataSource    = lstCityB;
            cboToCity.DisplayMember = "Name";
            // Neu la che do chinh sua (Edit) thi hien thi thong tin cua may bay len form
            if (mode == FormMode.EDIT)
            {
                // Chon thanh pho tuong ung
                cboFromCity.SelectedItem = lstCityA.Where(at => at.ID == route.CityAID).Single();
                cboToCity.SelectedItem   = lstCityB.Where(at => at.ID == route.CityBID).Single();

                if (route.IsActive)
                {
                    // Neu may bay nay dang active thi check vao radio button Active
                    rbtnActive.Checked = true;
                }
                else
                {
                    rbtnInActive.Checked = true;
                }

                numSkyMiles.Value  = route.SkyMiles;
                numBasePrice.Value = Convert.ToDecimal(route.BasePrice);
            }
            else
            {
                // Neu dang o che do them moi
                // Tao moi mot may bay
                route = new Route();

                // Nhung gia tri khac se duoc gan vao may bay khi nguoi dung bam nut Submit
            }
        }
        private async void btnSubmit_Click(object sender, EventArgs e)
        {
            // Lay gia tri tren form gan vao account
            city.Code = txtCode.Text;
            city.Name = txtName.Text;

            // Tao mot API
            CityWrapper cityWrapper = new CityWrapper();
            // 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 cityWrapper.Post(city);
            }
            else
            {
                // Neu dang o che do chinh sua (EDIT)
                // PUT city len server
                isSuccess = await cityWrapper.Put(city.ID, city);
            }

            // 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" + cityWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private async void LoadDataGridView(List <FlightSchedule> lstFlightSchedule)
        {
            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();

            // Hien thi len label FromTo
            lbFromTo.Text = String.Format("From {0} - to {1}",
                                          lstCity.Find(c => c.ID == lstRoute.Find(r => r.ID == lstFlightSchedule.First().RouteID).CityAID).Name,
                                          lstCity.Find(c => c.ID == lstRoute.Find(r => r.ID == lstFlightSchedule.Last().RouteID).CityBID).Name
                                          );

            // 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;
                    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;
                dgvFlightSchedule.Columns["IsActive"].Visible = false;
            }
        }
Exemplo n.º 8
0
        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 (dgvCity.SelectedRows.Count == 0)
            {
                currentRowIndex = 0;
            }
            else
            {
                currentRowIndex = dgvCity.Rows.IndexOf(dgvCity.SelectedRows[0]);
            }

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

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

            // Goi API lay du lieu ve
            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("Code");
            table.Columns.Add("Name");

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

                    // Gan du lieu len dong moi tao
                    row["ID"]   = city.ID;
                    row["Code"] = city.Code;
                    row["Name"] = city.Name;
                    // 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
                dgvCity.DataSource = table;

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

                // Cuon. toi' dong` duoc. chon.
                if (dgvCity.Rows.Count > 0)
                {
                    dgvCity.FirstDisplayedScrollingRowIndex = firstRowIndex;
                }
            }
        }
Exemplo n.º 9
0
        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;
                }
            }
        }
        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;
                }
            }
        }
Exemplo n.º 11
0
        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
            }
        }
Exemplo n.º 12
0
        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 (dgvRoute.SelectedRows.Count == 0)
            {
                currentRowIndex = 0;
            }
            else
            {
                currentRowIndex = dgvRoute.Rows.IndexOf(dgvRoute.SelectedRows[0]);
            }

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

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

            // Goi API lay du lieu ve
            RouteWrapper routeWrapper = new RouteWrapper();
            List <Route> lstRoute     = await routeWrapper.List();

            // Khai bao API de lay du lieu cua Loai may bay (AirplaneType)
            // va Thong tin ve` so luong cua tung loai ghe (AirplaneInfo)
            CityWrapper cityWrapper = new CityWrapper();

            // Goi API lay du lieu ve
            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 may bay
            table.Columns.Add("CityAID");   // ID cua thanh pho A
            table.Columns.Add("CityBID");   // ID cua thanh pho B
            table.Columns.Add("CityAName"); // Thanh pho A
            table.Columns.Add("CityBName"); // Thanh pho B
            table.Columns.Add("SkyMiles");  // Khoang cach giua hai noi
            table.Columns.Add("BasePrice"); // Gia ban dau
            table.Columns.Add("IsActive");

            // Kiem tra xem ket qua goi API co thanh cong hay khong
            if (lstRoute != null)
            {
                // Lap qua tung "dong` du lieu"
                foreach (Route route in lstRoute)
                {
                    // Goi API de lay du lieu cua thanh pho (ten thanh pho)
                    City cityA = lstCity.Where(at => at.ID == route.CityAID).Single();
                    City cityB = lstCity.Where(at => at.ID == route.CityBID).Single();

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

                    // Gan du lieu len dong moi tao
                    row["ID"]        = route.ID;
                    row["CityAID"]   = route.CityAID;
                    row["CityBID"]   = route.CityBID;
                    row["SkyMiles"]  = route.SkyMiles;
                    row["BasePrice"] = route.BasePrice;
                    row["CityAName"] = lstCity.Where(at => at.ID == route.CityAID).Single().Name;
                    row["CityBName"] = lstCity.Where(at => at.ID == route.CityBID).Single().Name;
                    row["IsActive"]  = route.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
                dgvRoute.DataSource = table;

                // An cot CityAID va CityBID, khong hien cot nay
                dgvRoute.Columns["CityAID"].Visible = false;
                dgvRoute.Columns["CityBID"].Visible = false;

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

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