Example #1
0
        private async void btnDelete_Click(object sender, EventArgs e)
        {
            // Lay may bay dang duoc chon trong bang
            Route route = GetSelectedRoute();

            // Neu hien tai khong co may bay nao duoc chon thi hien thong bao
            if (route == null)
            {
                MessageBox.Show("You must choose a route to edit!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Neu co may bay dang duoc chon thi sua cot IsActive lai thanh False
            route.IsActive = false;

            // Gui len server de cap nhat lai cot IsActive trong CSDL
            RouteWrapper routeWrapper = new RouteWrapper();
            bool         isSuccess    = await routeWrapper.Put(route.ID, route);

            // Kiem tra ket qua tra ve
            if (isSuccess)
            {
                // Neu ket qua la thanh cong, hien thong bao thanh cong
                MessageBox.Show("Airplane status 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" + routeWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ElasticRoute"/> class.
        /// </summary>
        /// <param name="url">The URL pattern.</param>
        /// <param name="routeHandler">The route handler.</param>
        /// <param name="constraints">The route constraints.</param>
        /// <param name="incomingDefaults">The incoming request default route values.</param>
        /// <param name="outgoingDefaults">The URL generation default route values.</param>
        /// <param name="projections">The route values projections.</param>
        /// <param name="dataTokens">The data tokens.</param>
        public ElasticRoute(string url, IRouteHandler routeHandler,
                            RouteValueDictionary constraints      = null,
                            RouteValueDictionary incomingDefaults = null,
                            RouteValueDictionary outgoingDefaults = null,
                            IDictionary <string, IRouteValueProjection> projections = null,
                            RouteValueDictionary dataTokens = null)
        {
            this.Url              = url;
            this.RouteHandler     = routeHandler;
            this.IncomingDefaults = incomingDefaults ?? EmptyValues();
            this.OutgoingDefaults = outgoingDefaults ?? EmptyValues();
            this.Constraints      = constraints ?? EmptyValues();
            this.Projections      = projections ?? new Dictionary <string, IRouteValueProjection>();
            this.DataTokens       = dataTokens ?? EmptyValues();

            this.routeWrapper = new RouteWrapper(this);

            foreach (var constraint in Constraints.Values.OfType <IDynamicRegexRouteConstraint>())
            {
                constraint.RegexChanged += OnRegexChanged;
            }

            var fullPathSegment = ParseSegments(url);
            var urlMatch        = BuildRegex(fullPathSegment);

            this.parsedPattern = new ParsedRoutePattern(urlMatch, fullPathSegment);

            this.RequiredParameters = new HashSet <string>(fullPathSegment.RequiredParameters.Select(p => p.Name), StringComparer.InvariantCultureIgnoreCase);
            this.AllParameters      = new HashSet <string>(fullPathSegment.Parameters, StringComparer.InvariantCultureIgnoreCase);
        }
        public void GetRouteTest()
        {
            _route = new RouteWrapper();
            AddressFinderWrapper af = new AddressFinderWrapper();

            var p0 = af.GetXY("Mestre Gomes", "613", "Vila Velha", "ES", "Gloria", "29122100");
            var p1 = af.GetXY("Orissanga", "14", "São Paulo", "SP", "Mirandopolis", "04052030");

            RouteInfo ri = _route.GetRoute(RouteWrapper.ConvertToRoutePoint(p0),
                                           RouteWrapper.ConvertToRoutePoint(p1),
                                           RouteWrapper.TipoRota.PadraoMaisCurta);

            Assert.IsTrue(ri.routeTotals.totalDistance > 0);
        }
        public void GetRouteTest()
        {
            _route = new RouteWrapper();
            AddressFinderWrapper af = new AddressFinderWrapper();

            var p0 = af.GetXY("Mestre Gomes", "613", "Vila Velha", "ES", "Gloria", "29122100");
            var p1 = af.GetXY("Orissanga", "14", "São Paulo", "SP", "Mirandopolis", "04052030");

            RouteInfo ri = _route.GetRoute(RouteWrapper.ConvertToRoutePoint(p0),
                                           RouteWrapper.ConvertToRoutePoint(p1),
                                           RouteWrapper.TipoRota.PadraoMaisCurta);

            Assert.IsTrue(ri.routeTotals.totalDistance > 0);
        }
        private async void btnSubmit_Click(object sender, System.EventArgs e)
        {
            // Lay gia tri tren form gan vao account
            route.CityAID   = (((City)cboFromCity.SelectedItem).ID);
            route.CityBID   = (((City)cboToCity.SelectedItem).ID);
            route.SkyMiles  = Convert.ToInt32(numSkyMiles.Value);
            route.BasePrice = Convert.ToDouble(numBasePrice.Value);
            route.IsActive  = rbtnActive.Checked;

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

            // 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" + routeWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #6
0
        static public RouteWrapper[] Ringify(int size) // makes a circular doubly linked list of the specified size
        {
            RouteWrapper[] Ringaround;
            Ringaround = new RouteWrapper[size];

            for (int count = 0; count < size; count++)
            {
                Ringaround[count] = new RouteWrapper();
            }

            for (int count = 1; count < size; count++)
            {
                Ringaround[count - 1].SetNext(Ringaround[count]);
                Ringaround[count].SetPrev(Ringaround[count - 1]);
                Ringaround[count].SetNum(count);
            }
            Ringaround[0].SetPrev(Ringaround[size - 1]);
            Ringaround[0].SetNum(0);
            Ringaround[size - 1].SetNext(Ringaround[0]);

            return(Ringaround);
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     _route = new RouteWrapper(); // TODO: Initialize to an appropriate value
 }
Example #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 (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 CalculoRotaData()
 {
     _address = new AddressFinderWrapper();
     _route = new RouteWrapper();
 }
        /// <summary>
        /// Only use for generate sample data of table FlightSchedule
        /// This function will generate flight schedule for all route in database,
        /// each route will have <code>maxFlightSchedulePerRoute</code> flight schedules,
        /// each flight schedule of route will apart one day, starting from today.
        /// </summary>
        private async void AutoGenerateFlightSchedule()
        {
            DateTime startTime = DateTime.Now;

            Console.WriteLine("Start at {0}", startTime);

            FlightScheduleWrapper flightScheduleWrapper = new FlightScheduleWrapper();
            AirplaneWrapper       airplaneWrapper       = new AirplaneWrapper();
            AirplaneTypeWrapper   airplaneTypeWrapper   = new AirplaneTypeWrapper();
            AirplaneInfoWrapper   airplaneInfoWrapper   = new AirplaneInfoWrapper();
            RouteWrapper          routeWrapper          = new RouteWrapper();

            List <Airplane> lstAirplane = await airplaneWrapper.List();

            List <AirplaneType> lstAirplaneType = await airplaneTypeWrapper.List();

            List <AirplaneInfo> lstAirplaneInfo = await airplaneInfoWrapper.List();

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

            int      flightScheduleOfCurrentRoute = 0;
            int      maxFlightSchedulePerRoute    = 15;
            DateTime startingDate         = DateTime.Now;
            int      currentAirplaneIndex = 0;
            int      count = 0;

            for (int routeIndex = 0, maxRouteIndex = lstRoute.Count - 1; routeIndex <= maxRouteIndex; routeIndex++)
            {
                Route currentRoute = lstRoute[routeIndex];

                do
                {
                    Airplane            currentAirplane     = lstAirplane[currentAirplaneIndex++];
                    AirplaneType        currentAirplaneType = lstAirplaneType.Find(at => at.ID == currentAirplane.TypeID);
                    List <AirplaneInfo> currentAirplaneInfo = lstAirplaneInfo.Where(ai => ai.AirplaneTypeID == currentAirplaneType.ID).ToList();
                    DateTime            departureDate       = startingDate.AddDays(flightScheduleOfCurrentRoute);

                    FlightSchedule flightSchedule = new FlightSchedule()
                    {
                        AirplaneCode      = currentAirplane.AirplaneCode,
                        RouteID           = currentRoute.ID,
                        DepartureDate     = departureDate,
                        FirstSeatAvail    = currentAirplaneInfo.Find(ai => ai.ClassID == 1).SeatCount,
                        BusinessSeatAvail = currentAirplaneInfo.Find(ai => ai.ClassID == 2).SeatCount,
                        ClubSeatAvail     = currentAirplaneInfo.Find(ai => ai.ClassID == 3).SeatCount,
                        IsActive          = true
                    };

                    if (await flightScheduleWrapper.Post(flightSchedule))
                    {
                        Console.WriteLine("Add flight schedule #{0} success!", ++count);
                    }
                    else
                    {
                        Console.WriteLine("Add flight schedule #{0} failed!", ++count);
                    }

                    if (currentAirplaneIndex >= lstAirplane.Count)
                    {
                        currentAirplaneIndex = 0;
                    }
                } while (++flightScheduleOfCurrentRoute < maxFlightSchedulePerRoute);

                flightScheduleOfCurrentRoute = 0;
            }

            DateTime endTime = DateTime.Now;

            Console.WriteLine("End at {0}", startTime);
            Console.WriteLine("Total time: {0}", (endTime - startTime).TotalSeconds);
        }
        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;
                }
            }
        }
Example #12
0
 public CalculoRotaData()
 {
     _address = new AddressFinderWrapper();
     _route   = new RouteWrapper();
 }
Example #13
0
 public void SetPrev(RouteWrapper subject)
 {
     previous = subject;
 }
Example #14
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
            }
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     _route = new RouteWrapper(); // TODO: Initialize to an appropriate value
 }
Example #16
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;
                }
            }
        }
        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;
            }
        }
Example #18
0
 public void SetNext(RouteWrapper subject)
 {
     next = subject;
 }