// Add Combo ---------------------------------------------------------

        private void BtnConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (Checking() == false)
            {
                MessageBox.Show(error.ToString());
                error.Clear();
            }
            else
            {
                try
                {
                    CHUYENBAY newCB = new CHUYENBAY()
                    {
                        ThoiGianBay = new TimeSpan(h, m, 0),
                        GheThuong   = Normal,
                        GheVip      = VIP,
                        SBDi        = sbdi.MaSB,
                        SBDen       = sbden.MaSB,
                        IsAvailable = true,
                    };

                    FlightMngController.addNewFlight(newCB);
                    this.Visibility = Visibility.Collapsed;
                }
                catch
                {
                    MessageBox.Show("Đã tồn tại chuyến bay này rồi");
                }
            }
        }
 private void BtnDelete_Click(object sender, RoutedEventArgs e)
 {
     if (tab.SelectedIndex == 0)
     {// lịch bay
         if (dataLichBay.SelectedItem != null)
         {
             Object   item   = (Object)dataLichBay.SelectedItem;
             int      macb   = (int)item.GetType().GetProperty("MaCB").GetValue(item);
             DateTime ngaydi = (DateTime)item.GetType().GetProperty("NgayDi").GetValue(item);
             FlightMngController.deleteSheduleFor(macb, ngaydi);
             dataLichBay.ItemsSource = null;
             loadLichBayData();
         }
         else
         {
             MessageBox.Show("Bạn vẫn chưa chọn lịch bay cần xóa");
         }
     }
     else
     {// chuyển bay
         if (dataChuyenBay.SelectedItem != null)
         {
             FlightMngController.deleteFlight((CHUYENBAY)dataChuyenBay.SelectedItem);
             dataChuyenBay.ItemsSource = null;
             loadChuyenBayData();
         }
         else
         {
             MessageBox.Show("Bạn vẫn chưa chọn chuyến bay cần xóa");
         }
     }
 }
 public void loadChuyenBayData()
 {
     // Load dữ liệu cho bản chuyến bay
     FlightData = FlightMngController.LoadFlightData();
     dataChuyenBay.ItemsSource = null;
     dataChuyenBay.ItemsSource = FlightData;
     soChuyenBay = FlightMngController.getLightIDAutomatic();
     lblSo_chuyen_bay.Content = soChuyenBay;
 }
 public void loadLichBayData()
 {
     // Load dữ liệu cho bản lịch bay
     SheduleData             = FlightMngController.LoadSheduleData().ToList();
     dataLichBay.ItemsSource = null;
     dataLichBay.ItemsSource = SheduleData;
     soLichBay = SheduleData.Count();
     lblSo_lich_bay.Content = soLichBay;
 }
        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            if (Checking() == false)
            {
                MessageBox.Show(error.ToString());
                error.Clear();
            }
            else
            {
                if (IsEditing())
                {
                    FlightMngController.updateFlight(GlobalItem.selectedFlight.MaCB, new TimeSpan(h, m, 0), sbdi.MaSB, sbden.MaSB, Normal, VIP);
                }

                GlobalItem.selectedFlight = null;
                this.Visibility           = Visibility.Collapsed;
            }
        }
        // Add Combo ------------------------------------------------------------

        private void BtnAddShedule_Click(object sender, RoutedEventArgs e)
        {
            if (Checking() == false)
            {
                MessageBox.Show(error.ToString());
                error.Clear();
            }
            else
            {
                try
                {
                    LICHBAY newLB = new LICHBAY()
                    {
                        MaCB        = cmbMaCB.SelectedIndex + 1,
                        GioDi       = new TimeSpan(int.Parse(txtHrs.Text), int.Parse(txtMins.Text), 0),
                        NgayDi      = dp_ngaybay.SelectedDate.Value,
                        SoGheThuong = 0,
                        SoGheVip    = 0,
                        IsAvailable = true,
                    };

                    FlightMngController.addNewShedule(newLB);
                    try
                    {
                        FlightMngController.addListSBTG(lstSBTG, lstNote, lstStop, cmbMaCB.SelectedIndex + 1, dp_ngaybay.SelectedDate.Value);
                        this.Visibility = Visibility.Collapsed;
                    }
                    catch
                    {
                        MessageBox.Show("Sân bay trung gian bị trùng");
                    }
                }
                catch
                {
                    MessageBox.Show("Đã tồn tại lịch bay này rồi");
                }
            }
        }
        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            if (Checking() == false)
            {
                MessageBox.Show(error.ToString());
                error.Clear();
            }
            else
            {
                if (IsEditing())
                {
                    FlightMngController.updateShedule(selected.MaCB, selected.NgayDi, new TimeSpan(h, m, 0), normal, vip);
                }

                if (IsNoteUpdated)
                {
                    FlightMngController.updateSBTG(selected.MaCB, selected.NgayDi, lstSBTG, lstNote, lstStop);
                }

                GlobalItem.FlightOfSelectedShedule = -1;
                GlobalItem.DateOfSelectedShedule   = new DateTime();
                this.Visibility = Visibility.Collapsed;
            }
        }
        private void BtnSearch_Click(object sender, RoutedEventArgs e)
        {
            if (Check())
            {
                if (tab.SelectedItem == tabItemChuyenBay) // Chuyến bay
                {
                    switch (cmbSearchFilter.SelectedIndex)
                    {
                    case 0:
                    {
                        int macb = int.Parse(txtSearchBox.Text);
                        FlightMngController.SearchFlightForMACB(ref FlightData, macb);
                        dataChuyenBay.ItemsSource = FlightData;
                        break;
                    }

                    case 1:
                    {
                        StringBuilder sbdi = new StringBuilder(txtSearchBox.Text);
                        int           l    = sbdi.Length;
                        while (l < 5)
                        {
                            l++;
                            sbdi.Append(" ");
                        }
                        int length = sbdi.Length;
                        FlightMngController.SearchFlightForSBDI(ref FlightData, sbdi.ToString());
                        dataChuyenBay.ItemsSource = FlightData;
                        break;
                    }

                    case 2:
                    {
                        StringBuilder sbden = new StringBuilder(txtSearchBox.Text);
                        int           l     = sbden.Length;
                        while (l < 5)
                        {
                            l++;
                            sbden.Append(" ");
                        }
                        FlightMngController.SearchFlightForSBDI(ref FlightData, sbden.ToString());
                        dataChuyenBay.ItemsSource = FlightData;
                        break;
                    }

                    default: break;
                    }
                }
                else
                {
                    // Lịch bay
                    switch (cmbSearchFilter.SelectedIndex)
                    {
                    case 0:
                    {
                        int macb = int.Parse(txtSearchBox.Text);
                        FlightMngController.SearchForMACB(ref SheduleData, macb);
                        dataLichBay.ItemsSource = SheduleData;
                        break;
                    }

                    case 1:
                    {
                        StringBuilder sbdi = new StringBuilder(txtSearchBox.Text);
                        int           l    = sbdi.Length;
                        while (l < 5)
                        {
                            l++;
                            sbdi.Append(" ");
                        }
                        FlightMngController.SearchForSBDI(ref SheduleData, sbdi.ToString());
                        dataLichBay.ItemsSource = SheduleData;

                        break;
                    }

                    case 2:
                    {
                        StringBuilder sbden = new StringBuilder(txtSearchBox.Text);
                        int           l     = sbden.Length;
                        while (l < 5)
                        {
                            l++;
                            sbden.Append(" ");
                        }
                        FlightMngController.SearchForSBDEN(ref SheduleData, sbden.ToString());
                        dataLichBay.ItemsSource = SheduleData;

                        break;
                    }

                    case 3:
                    {
                        DateTime ngaydi = dpSearchBox.SelectedDate.Value;
                        FlightMngController.SearchForNGAYDI(ref SheduleData, ngaydi);
                        dataLichBay.ItemsSource = SheduleData;
                        break;
                    }

                    case 4:
                    {
                        TimeSpan giobay = new TimeSpan(int.Parse(hourSearchBox.Text), int.Parse(minSearchBox.Text), 0);
                        FlightMngController.SearchForGIOBAY(ref SheduleData, giobay);
                        dataLichBay.ItemsSource = SheduleData;
                        break;
                    }

                    default: break;
                    }
                }
            }
            else
            {
                // do nothing
            }
        }
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            DependencyObject ucParent = this.Parent;

            while (!(ucParent is UserControl))
            {
                ucParent = LogicalTreeHelper.GetParent(ucParent);
            }

            parentWind = (flightMng)ucParent;

            if (this.Visibility == Visibility.Visible)
            {
                lstCB = FlightMngController.LoadFlightData();
                cmbMaCB.ItemsSource        = lstCB;
                cmbSBTrungGian.ItemsSource = FlightMngController.LoadAirportData();

                if (parentWind.IsSheduleEdit == true)
                {// Xem - sữa
                    lblScheTitle.Content = "CHI TIẾT LỊCH BAY";

                    selected   = FlightMngController.getLBByID(GlobalItem.FlightOfSelectedShedule, GlobalItem.DateOfSelectedShedule);
                    selectedCB = FlightMngController.getCBByID(GlobalItem.FlightOfSelectedShedule);



                    cmbMaCB.IsEnabled    = false;
                    txtSBDi.IsEnabled    = false;
                    txtSBDen.IsEnabled   = false;
                    dp_ngaybay.IsEnabled = false;

                    txtNormalSeats.IsEnabled = false;
                    txtVIPSeats.IsEnabled    = false;

                    int index = GlobalItem.FlightOfSelectedShedule - 1;
                    cmbMaCB.SelectedItem = selectedCB;
                    txtSBDi.Text         = selectedCB.SBDi;
                    txtSBDen.Text        = selectedCB.SBDen;
                    txtDefaultHrs.Text   = selectedCB.ThoiGianBay.Value.Hours.ToString();
                    txtDefaultMins.Text  = selectedCB.ThoiGianBay.Value.Minutes.ToString();

                    txtMins.Text            = selected.GioDi.Value.Minutes.ToString();
                    txtHrs.Text             = selected.GioDi.Value.Hours.ToString();
                    dp_ngaybay.SelectedDate = selected.NgayDi;

                    txtNormalSeats.Text = selected.SoGheThuong.ToString();
                    txtVIPSeats.Text    = selected.SoGheVip.ToString();

                    FlightMngController.loadSBTGList(selected.MaCB, selected.NgayDi, ref lstSBTG, ref lstNote, ref lstStop);
                    listView_SBTG.ItemsSource = lstSBTG;

                    AddCombo.Visibility  = Visibility.Hidden;
                    EditCombo.Visibility = Visibility.Visible;
                    SeatCombo.Visibility = Visibility.Visible;
                }
                else
                {// Them mới
                    lblScheTitle.Content = "THÊM MỚI LỊCH BAY";

                    cmbMaCB.SelectedIndex = 0;
                    txtSBDen.IsEnabled    = false;
                    txtSBDi.IsEnabled     = false;
                    txtSBDi.Text          = lstCB.ElementAt(0).SBDi;
                    txtSBDen.Text         = lstCB.ElementAt(0).SBDen;
                    txtDefaultHrs.Text    = lstCB.ElementAt(0).ThoiGianBay.Value.Hours.ToString();
                    txtDefaultMins.Text   = lstCB.ElementAt(0).ThoiGianBay.Value.Minutes.ToString();

                    AddCombo.Visibility  = Visibility.Visible;
                    EditCombo.Visibility = Visibility.Hidden;
                    SeatCombo.Visibility = Visibility.Hidden;
                }
            }
            else
            {
                cmbMaCB.IsEnabled    = true;
                txtSBDi.IsEnabled    = true;
                txtSBDen.IsEnabled   = true;
                dp_ngaybay.IsEnabled = true;



                parentWind.loadLichBayData();
            }
        }
Beispiel #10
0
        private void BtnSearch_Click(object sender, RoutedEventArgs e)
        {
            switch (cmbFilter.SelectedIndex)
            {
            case 0:
            {
                if (txtSearchBox.Text.Length > 9)
                {
                    MessageBox.Show("Mã khách hàng chỉ gồm 9 ký tự");
                }
                else
                {
                    StringBuilder makh = new StringBuilder(txtSearchBox.Text);
                    int           l    = makh.Length;
                    while (l < 9)
                    {
                        l++;
                        makh.Append(" ");
                    }
                    receiptMngController.SearchForMAKH(ref receiptData, makh.ToString());
                    dataHoaDon.ItemsSource = receiptData;
                }
                break;
            }

            case 1:
            {
                DateTime ngaydi = dpSearchBox.SelectedDate.Value;
                FlightMngController.SearchForNGAYDI(ref receiptData, ngaydi);
                dataHoaDon.ItemsSource = receiptData;
                break;
            }

            case 2:
            {
                if (txtSearchBox.Text.Length > 5)
                {
                    MessageBox.Show("Mã sân bay chỉ gồm 5 ký tự");
                }
                else
                {
                    StringBuilder sbdi = new StringBuilder(txtSearchBox.Text);
                    int           l    = sbdi.Length;
                    while (l < 5)
                    {
                        l++;
                        sbdi.Append(" ");
                    }
                    FlightMngController.SearchForSBDI(ref receiptData, sbdi.ToString());
                    dataHoaDon.ItemsSource = receiptData;
                }
                break;
            }

            case 3:
            {
                if (txtSearchBox.Text.Length > 5)
                {
                    MessageBox.Show("Mã sân bay chỉ gồm 5 ký tự");
                }
                else
                {
                    StringBuilder sbden = new StringBuilder(txtSearchBox.Text);
                    int           l     = sbden.Length;
                    while (l < 5)
                    {
                        l++;
                        sbden.Append(" ");
                    }
                    FlightMngController.SearchForSBDEN(ref receiptData, sbden.ToString());
                    dataHoaDon.ItemsSource = receiptData;
                }
                break;
            }

            default: break;
            }
        }
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Visibility == Visibility.Visible)
            {
                lstSB = FlightMngController.LoadAirportData();
                DependencyObject ucParent = this.Parent;

                while (!(ucParent is UserControl))
                {
                    ucParent = LogicalTreeHelper.GetParent(ucParent);
                }

                parentWind = (flightMng)ucParent;

                // Cập nhật dữ liệu
                cmbSBDi.ItemsSource  = lstSB;
                cmbSBDen.ItemsSource = lstSB;

                if (parentWind.IsFlightEdit == true)
                {// Xem / sữa
                    lblCBTitle.Content = "CHUYẾN BAY SỐ" + GlobalItem.selectedFlight.MaCB;

                    txtFlightID.Text      = GlobalItem.selectedFlight.MaCB.ToString();
                    txtFlightID.IsEnabled = false;
                    txtMins.Text          = GlobalItem.selectedFlight.ThoiGianBay.Value.Minutes.ToString();
                    txtHrs.Text           = GlobalItem.selectedFlight.ThoiGianBay.Value.Hours.ToString();
                    txtNormalSeats.Text   = GlobalItem.selectedFlight.GheThuong.ToString();
                    txtVIPSeats.Text      = GlobalItem.selectedFlight.GheVip.ToString();
                    cmbSBDi.SelectedItem  = lstSB.Where(x => x.MaSB == GlobalItem.selectedFlight.SBDi).SingleOrDefault();
                    cmbSBDen.SelectedItem = lstSB.Where(x => x.MaSB == GlobalItem.selectedFlight.SBDen).SingleOrDefault();

                    AddCombo.Visibility  = Visibility.Hidden;
                    EditCombo.Visibility = Visibility.Visible;
                }
                else
                {// Thêm mới
                    lblCBTitle.Content = "THÊM CHUYẾN BAY MỚI";

                    txtFlightID.Text = (parentWind.soChuyenBay + 1).ToString();
                    if (parentWind.IsFlightEdit == true)
                    {
                        GlobalItem.selectedFlight = null;
                    }
                    AddCombo.Visibility  = Visibility.Visible;
                    EditCombo.Visibility = Visibility.Hidden;
                }
            }
            else
            {
                DependencyObject ucParent = this.Parent;

                while (!(ucParent is UserControl))
                {
                    ucParent = LogicalTreeHelper.GetParent(ucParent);
                }

                flightMng parentWind = (flightMng)ucParent;

                txtFlightID.IsEnabled = true;
                parentWind.loadChuyenBayData();
            }
        }