Beispiel #1
0
        private void OpenTab(ref TabItem tab, string title, TabContentTemplate contentContainer)
        {
            if (!Content.Items.Contains(tab))
            {
                tab = InitNewTab(tab, title);
                Content.Items.Add(tab);
                Content.SelectedItem = tab;

                tab.Content = contentContainer;
            }
            else
            {
                Content.SelectedItem = tab;
            }
        }
Beispiel #2
0
        public TabContentTemplate InitTableTabContainer(string tableName, DataTable table, int rowsQuantity)
        {
            TabContentTemplate container = null;

            if (container == null)
            {
                container = new TabContentTemplate();
                container.Container.Children.Remove(container.TimeParams);
                container.Container.Children.Remove(container.GovNumParams);
                if (!isAdmin)
                {
                    container.AddButton.Visibility   = Visibility.Collapsed;
                    container.EditButton.Visibility  = Visibility.Collapsed;
                    container.DeleteButon.Visibility = Visibility.Collapsed;
                }

                SqlDataReader reader = _carRentalDb.ExecuteTableCommand("SelectFrom" + tableName, 1, _connection);
                _carRentalDb.GetData(reader, table);
                container.DataGrid.ItemsSource = table.DefaultView;

                MouseButtonEventHandler handler = (object sender, MouseButtonEventArgs e) =>
                {
                    TextBlock button = sender as TextBlock;

                    int rowCount = _carRentalDb.TotalTableRowCount(_connection, tableName);

                    if (!rowCount.Equals(rowsQuantity))
                    {
                        AddTableTab(table.TableName);
                    }

                    PageSwitcherLogic("SelectFrom" + tableName, container, table, button);
                };

                container.PageNum1.MouseLeftButtonDown += handler;
                container.PageNum2.MouseLeftButtonDown += handler;
                container.PageNum3.MouseLeftButtonDown += handler;
                container.PageNum4.MouseLeftButtonDown += handler;
                container.PageNum5.MouseLeftButtonDown += handler;
                container.PageNum6.MouseLeftButtonDown += handler;
                container.NextPage.MouseLeftButtonDown += handler;
                container.PrevPage.MouseLeftButtonDown += handler;
            }

            return(container);
        }
Beispiel #3
0
        private void ExecutePage(string targetRequest, int pageNum, DataTable table, TabContentTemplate container)
        {
            SqlDataReader reader = null;

            if (targetRequest.Equals("RequestTimePeriod"))
            {
                reader = _carRentalDb.ExecuteTimeRequest(pageNum, _connection);
            }
            else
            {
                reader = _carRentalDb.ExecuteTableCommand(targetRequest, pageNum, _connection);
            }

            table.Clear();
            _carRentalDb.GetData(reader, table);

            container.DataGrid.ItemsSource = table.DefaultView;
        }
Beispiel #4
0
        public TabContentTemplate InitSimpleReqtTabContainer(string requestName, string rowsReqtCount, string tabTitle, DataTable table, int rowsQuantity)
        {
            TabContentTemplate container = null;

            if (container == null)
            {
                container = new TabContentTemplate();
                container.EditingBlock.Visibility = Visibility.Collapsed;
                container.TimeParams.Visibility   = Visibility.Collapsed;
                container.GovNumParams.Visibility = Visibility.Collapsed;

                SqlDataReader reader = _carRentalDb.ExecuteTableCommand(requestName, 1, _connection);
                _carRentalDb.GetData(reader, table);
                container.DataGrid.ItemsSource = table.DefaultView;

                MouseButtonEventHandler handler = (object sender, MouseButtonEventArgs e) =>
                {
                    TextBlock button = sender as TextBlock;

                    int rowCount = _carRentalDb.TotalSimpleRequestRowCount(_connection, rowsReqtCount);

                    if (!rowCount.Equals(rowsQuantity))
                    {
                        AddTableTab(tabTitle);
                    }

                    PageSwitcherLogic(requestName, container, table, button);
                };

                container.PageNum1.MouseLeftButtonDown += handler;
                container.PageNum2.MouseLeftButtonDown += handler;
                container.PageNum3.MouseLeftButtonDown += handler;
                container.PageNum4.MouseLeftButtonDown += handler;
                container.PageNum5.MouseLeftButtonDown += handler;
                container.PageNum6.MouseLeftButtonDown += handler;
                container.NextPage.MouseLeftButtonDown += handler;
                container.PrevPage.MouseLeftButtonDown += handler;
            }

            return(container);
        }
Beispiel #5
0
        public TabContentTemplate InitParamReqtTabContainer(MouseButtonEventHandler handler)
        {
            TabContentTemplate container = null;

            if (container == null)
            {
                container = new TabContentTemplate();
                container.EditingBlock.Visibility = Visibility.Collapsed;

                container.PageNum1.MouseLeftButtonDown += handler;
                container.PageNum2.MouseLeftButtonDown += handler;
                container.PageNum3.MouseLeftButtonDown += handler;
                container.PageNum4.MouseLeftButtonDown += handler;
                container.PageNum5.MouseLeftButtonDown += handler;
                container.PageNum6.MouseLeftButtonDown += handler;
                container.NextPage.MouseLeftButtonDown += handler;
                container.PrevPage.MouseLeftButtonDown += handler;
            }

            return(container);
        }
Beispiel #6
0
        private void AddRequestTab(string requestId)
        {
            _concreteCarModelRowsQuantity = _carRentalDb.TotalSimpleRequestRowCount(_connection, "ConcreteCarRowCount");
            _carsManufRowsQuantity        = _carRentalDb.TotalSimpleRequestRowCount(_connection, "CarsManufBeforeCount");
            _rentDetailsRowsQuantity      = _carRentalDb.TotalSimpleRequestRowCount(_connection, "RentDetailsCount");

            int pagesQuantity;

            switch (requestId)
            {
            case "1":
                if (_rentDetailsContr == null)
                {
                    _rentDetailsContr = InitSimpleReqtTabContainer("RentDetails",
                                                                   "RentDetailsCount",
                                                                   Request1.Content.ToString(),
                                                                   _carRentalDb.RentDetailsTable,
                                                                   _rentDetailsRowsQuantity);

                    pagesQuantity = PagesCounter(_rentDetailsRowsQuantity);
                    InitPageControls(_rentDetailsContr, pagesQuantity);
                }
                else
                {
                    _rentDetailsContr = null;
                    _carRentalDb.RentDetailsTable.Clear();
                    _rentDetailsContr = InitSimpleReqtTabContainer("RentDetails",
                                                                   "RentDetailsCount",
                                                                   Request1.Content.ToString(),
                                                                   _carRentalDb.RentDetailsTable,
                                                                   _rentDetailsRowsQuantity);

                    pagesQuantity = PagesCounter(_rentDetailsRowsQuantity);
                    InitPageControls(_rentDetailsContr, pagesQuantity);

                    _request1.Content = _rentDetailsContr;
                }

                OpenTab(ref _request1, Request1.Content.ToString(), _rentDetailsContr);
                break;

            case "2":
                if (_carsManufContr == null)
                {
                    _carsManufContr = InitSimpleReqtTabContainer("CarsManufBefore",
                                                                 "CarsManufBeforeCount",
                                                                 Request2.Content.ToString(),
                                                                 _carRentalDb.CarsManufTable,
                                                                 _carsManufRowsQuantity);

                    pagesQuantity = PagesCounter(_carsManufRowsQuantity);
                    InitPageControls(_carsManufContr, pagesQuantity);
                }
                else
                {
                    _carsManufContr = null;
                    _carRentalDb.CarsManufTable.Clear();
                    _carsManufContr = InitSimpleReqtTabContainer("CarsManufBefore",
                                                                 "CarsManufBeforeCount",
                                                                 Request2.Content.ToString(),
                                                                 _carRentalDb.CarsManufTable,
                                                                 _carsManufRowsQuantity);

                    pagesQuantity = PagesCounter(_carsManufRowsQuantity);
                    InitPageControls(_carsManufContr, pagesQuantity);

                    _request2.Content = _carsManufContr;
                }

                OpenTab(ref _request2, Request2.Content.ToString(), _carsManufContr);
                break;

            case "3":
                if (_concreteCarModelReqtContr == null)
                {
                    _concreteCarModelReqtContr = InitSimpleReqtTabContainer("ConcreteModelRequest",
                                                                            "ConcreteCarRowCount",
                                                                            Request3.Content.ToString(),
                                                                            _carRentalDb.GetCarModelInfoTable,
                                                                            _concreteCarModelRowsQuantity);

                    pagesQuantity = PagesCounter(_concreteCarModelRowsQuantity);
                    InitPageControls(_concreteCarModelReqtContr, pagesQuantity);
                }
                else
                {
                    _concreteCarModelReqtContr = null;
                    _carRentalDb.GetCarModelInfoTable.Clear();
                    _concreteCarModelReqtContr = InitSimpleReqtTabContainer("ConcreteModelRequest",
                                                                            "ConcreteCarRowCount",
                                                                            Request3.Content.ToString(),
                                                                            _carRentalDb.GetCarModelInfoTable,
                                                                            _concreteCarModelRowsQuantity);

                    pagesQuantity = PagesCounter(_concreteCarModelRowsQuantity);
                    InitPageControls(_concreteCarModelReqtContr, pagesQuantity);

                    _request3.Content = _concreteCarModelReqtContr;
                }

                OpenTab(ref _request3, Request3.Content.ToString(), _concreteCarModelReqtContr);
                break;

            case "4":
                _carInfoReqtContr = new TabContentTemplate();
                _carInfoReqtContr.EditingBlock.Visibility = Visibility.Collapsed;
                _carInfoReqtContr.PagingBlock.Visibility  = Visibility.Collapsed;
                _carInfoReqtContr.TimeParams.Visibility   = Visibility.Collapsed;

                _carInfoReqtContr.GovNumB.MouseLeftButtonDown += GetGovNumHandler;

                OpenTab(ref _request4, Request4.Content.ToString(), _carInfoReqtContr);
                break;

            case "5":
                if (_timeReqtContr == null)
                {
                    _timeReqtContr = InitParamReqtTabContainer(TimeRequestPageSwitcherHandler);
                    _timeReqtContr.GovNumParams.Visibility = Visibility.Collapsed;
                    _timeReqtContr.PagingBlock.Visibility  = Visibility.Collapsed;

                    _timeReqtContr.ExecTimeRequestB.MouseLeftButtonDown += GetTimePeriodHandler;
                }

                OpenTab(ref _request5, Request5.Content.ToString(), _timeReqtContr);
                break;

            default:
                break;
            }
        }
Beispiel #7
0
        private void PageSwitcherLogic(string targetProc, TabContentTemplate container, DataTable table, TextBlock button)
        {
            int currentPage;

            switch (button.Name)
            {
            case "PrevPage":
                if (int.Parse(container.PageNum1.Text) != 1)
                {
                    container.PageNum1.Text = (int.Parse(container.PageNum1.Text) - 1).ToString();
                    container.PageNum2.Text = (int.Parse(container.PageNum2.Text) - 1).ToString();
                    container.PageNum3.Text = (int.Parse(container.PageNum3.Text) - 1).ToString();
                    ExecutePage(targetProc, int.Parse(container.PageNum1.Text), table, container);
                }
                if (int.Parse(container.PageNum1.Text) == 1)
                {
                    container.Prev.Visibility = Visibility.Hidden;
                }
                if (container.Next.Visibility == Visibility.Hidden)
                {
                    container.Next.Visibility = Visibility.Visible;
                }
                break;

            case "PageNum1":
                currentPage = int.Parse(button.Text);
                if (currentPage == 1)
                {
                    container.Prev.Visibility = Visibility.Hidden;
                }
                ExecutePage(targetProc, currentPage, table, container);
                break;

            case "PageNum2":
                currentPage = int.Parse(button.Text);
                if (container.PageButton4.Visibility == Visibility.Hidden &&
                    container.PageButton5.Visibility == Visibility.Hidden &&
                    container.PageButton6.Visibility == Visibility.Hidden)
                {
                    ExecutePage(targetProc, currentPage, table, container);
                }
                else
                {
                    if (currentPage == 2 &&
                        container.PageButton4.Visibility != Visibility.Hidden &&
                        container.PageButton5.Visibility != Visibility.Hidden &&
                        container.PageButton6.Visibility != Visibility.Hidden)
                    {
                        container.Prev.Visibility = Visibility.Visible;
                    }

                    if (int.Parse(container.PageNum3.Text) == _lastPage)
                    {
                        container.Next.Visibility = Visibility.Hidden;
                        ExecutePage(targetProc, currentPage, table, container);
                    }
                    else
                    {
                        container.PageNum1.Text = int.Parse(container.PageNum2.Text).ToString();
                        container.PageNum2.Text = int.Parse(container.PageNum3.Text).ToString();
                        container.PageNum3.Text = (int.Parse(container.PageNum3.Text) + 1).ToString();
                        ExecutePage(targetProc, currentPage, table, container);
                    }
                }
                break;

            case "PageNum3":
                currentPage = int.Parse(button.Text);
                if (_lastPage > 3)
                {
                    container.Prev.Visibility = Visibility.Visible;
                }
                if (container.PageButton4.Visibility == Visibility.Hidden &&
                    container.PageButton5.Visibility == Visibility.Hidden &&
                    container.PageButton6.Visibility == Visibility.Hidden)
                {
                    ExecutePage(targetProc, currentPage, table, container);
                }
                else
                {
                    if (currentPage == _lastPage)
                    {
                        container.Next.Visibility = Visibility.Hidden;
                        ExecutePage(targetProc, currentPage, table, container);
                    }
                    else if (currentPage != _lastPage - 1)
                    {
                        container.PageNum1.Text = int.Parse(container.PageNum3.Text).ToString();
                        container.PageNum2.Text = (int.Parse(container.PageNum2.Text) + 2).ToString();
                        container.PageNum3.Text = (int.Parse(container.PageNum1.Text) + 2).ToString();
                        ExecutePage(targetProc, currentPage, table, container);
                    }
                    else
                    {
                        container.PageNum1.Text = (int.Parse(container.PageNum1.Text) + 1).ToString();
                        container.PageNum2.Text = (int.Parse(container.PageNum2.Text) + 1).ToString();
                        container.PageNum3.Text = (int.Parse(container.PageNum3.Text) + 1).ToString();
                        ExecutePage(targetProc, currentPage, table, container);
                    }
                }
                break;

            case "PageNum4":
                currentPage = int.Parse(button.Text);
                ExecutePage(targetProc, currentPage, table, container);
                break;

            case "PageNum5":
                currentPage = int.Parse(button.Text);
                ExecutePage(targetProc, currentPage, table, container);
                break;

            case "PageNum6":
                currentPage = int.Parse(button.Text);
                ExecutePage(targetProc, currentPage, table, container);
                break;

            case "NextPage":
                if (int.Parse(container.PageNum3.Text) == _lastPage - 1)
                {
                    container.Next.Visibility = Visibility.Hidden;
                    container.PageNum1.Text   = (int.Parse(container.PageNum1.Text) + 1).ToString();
                    container.PageNum2.Text   = (int.Parse(container.PageNum2.Text) + 1).ToString();
                    container.PageNum3.Text   = (int.Parse(container.PageNum3.Text) + 1).ToString();

                    ExecutePage(targetProc, int.Parse(container.PageNum1.Text), table, container);
                    container.Prev.Visibility = Visibility.Visible;
                }
                else
                {
                    container.PageNum1.Text = int.Parse(container.PageNum2.Text).ToString();
                    container.PageNum2.Text = int.Parse(container.PageNum3.Text).ToString();
                    container.PageNum3.Text = (int.Parse(container.PageNum3.Text) + 1).ToString();
                    ExecutePage(targetProc, int.Parse(container.PageNum1.Text), table, container);
                    container.Prev.Visibility = Visibility.Visible;
                }
                break;

            default:
                break;
            }
        }
Beispiel #8
0
        private void InitPageControls(TabContentTemplate container, int pagesQuantity)
        {
            container.Prev.Visibility = Visibility.Hidden;

            container.PageButton1.Visibility = Visibility.Visible;
            container.PageButton2.Visibility = Visibility.Visible;
            container.PageButton3.Visibility = Visibility.Visible;
            container.Splitter.Visibility    = Visibility.Visible;
            container.PageButton4.Visibility = Visibility.Visible;
            container.PageButton5.Visibility = Visibility.Visible;
            container.PageButton6.Visibility = Visibility.Visible;

            container.PageNum1.Text = 1.ToString();
            container.PageNum2.Text = 2.ToString();
            container.PageNum3.Text = 3.ToString();

            container.Next.Visibility = Visibility.Visible;

            if (pagesQuantity > 6)
            {
                container.PageNum4.Text = (pagesQuantity - 2).ToString();
                container.PageNum5.Text = (pagesQuantity - 1).ToString();
                container.PageNum6.Text = (pagesQuantity).ToString();

                _lastPage = int.Parse(container.PageNum6.Text);
            }
            else if (pagesQuantity == 6)
            {
                container.Next.Visibility = Visibility.Hidden;
                container.Prev.Visibility = Visibility.Hidden;
                container.PageNum4.Text   = (pagesQuantity - 2).ToString();
                container.PageNum5.Text   = (pagesQuantity - 1).ToString();
                container.PageNum6.Text   = (pagesQuantity).ToString();

                _lastPage = int.Parse(container.PageNum6.Text);
            }
            else if (pagesQuantity == 5)
            {
                container.Prev.Visibility        = Visibility.Hidden;
                container.PageButton6.Visibility = Visibility.Hidden;
                container.PageNum4.Text          = (pagesQuantity - 1).ToString();
                container.PageNum5.Text          = (pagesQuantity).ToString();

                _lastPage = int.Parse(container.PageNum5.Text);
            }
            else if (pagesQuantity == 4)
            {
                container.Prev.Visibility        = Visibility.Hidden;
                container.PageButton6.Visibility = Visibility.Hidden;
                container.PageButton5.Visibility = Visibility.Hidden;
                container.PageNum4.Text          = (pagesQuantity).ToString();

                _lastPage = int.Parse(container.PageNum4.Text);
            }
            else if (pagesQuantity == 3)
            {
                container.Next.Visibility        = Visibility.Hidden;
                container.Prev.Visibility        = Visibility.Hidden;
                container.PageButton6.Visibility = Visibility.Hidden;
                container.PageButton5.Visibility = Visibility.Hidden;
                container.PageButton4.Visibility = Visibility.Hidden;
                container.Splitter.Visibility    = Visibility.Hidden;
            }
            else if (pagesQuantity == 2)
            {
                container.Next.Visibility        = Visibility.Hidden;
                container.Prev.Visibility        = Visibility.Hidden;
                container.PageButton6.Visibility = Visibility.Hidden;
                container.PageButton5.Visibility = Visibility.Hidden;
                container.PageButton4.Visibility = Visibility.Hidden;
                container.PageButton3.Visibility = Visibility.Hidden;
                container.Splitter.Visibility    = Visibility.Hidden;
            }
            else if (pagesQuantity <= 1)
            {
                container.PagingBlock.Visibility = Visibility.Hidden;
            }
        }
Beispiel #9
0
        private void AddTableTab(string title)
        {
            _carsRowsQuantity      = _carRentalDb.TotalTableRowCount(_carRentalDb.Connection, "Cars");
            _customersRowsQuantity = _carRentalDb.TotalTableRowCount(_carRentalDb.Connection, "Customers");
            _rentRowsQuantity      = _carRentalDb.TotalTableRowCount(_carRentalDb.Connection, "Rent");

            int pagesQuantity;

            switch (title)
            {
            case "Автомобили":

                if (_carsContainer == null)
                {
                    _carsContainer = InitTableTabContainer("Cars", _carRentalDb.Cars, _carsRowsQuantity);

                    InitCarsEditBtnsHandlers();
                    pagesQuantity = PagesCounter(_carsRowsQuantity);
                    InitPageControls(_carsContainer, pagesQuantity);
                }
                else
                {
                    _carsContainer = null;
                    _carRentalDb.Cars.Clear();
                    _carsContainer = InitTableTabContainer("Cars", _carRentalDb.Cars, _carsRowsQuantity);

                    InitCarsEditBtnsHandlers();
                    pagesQuantity = PagesCounter(_carsRowsQuantity);
                    InitPageControls(_carsContainer, pagesQuantity);
                    _cars.Content = _carsContainer;
                }

                OpenTab(ref _cars, title, _carsContainer);
                break;

            case "Клиенты":
                if (_customersContainer == null)
                {
                    _customersContainer = InitTableTabContainer("Customers", _carRentalDb.Customers, _customersRowsQuantity);

                    InitCustomerEditBtnsHandlers();
                    pagesQuantity = PagesCounter(_customersRowsQuantity);
                    InitPageControls(_customersContainer, pagesQuantity);
                }
                else
                {
                    _customersContainer = null;
                    _carRentalDb.Customers.Clear();
                    _customersContainer = InitTableTabContainer("Customers", _carRentalDb.Customers, _customersRowsQuantity);

                    InitCustomerEditBtnsHandlers();
                    pagesQuantity = PagesCounter(_customersRowsQuantity);
                    InitPageControls(_customersContainer, pagesQuantity);

                    _customers.Content = _customersContainer;
                }

                OpenTab(ref _customers, title, _customersContainer);
                break;

            case "Прокат":
                if (_rentContainer == null)
                {
                    _rentContainer = InitTableTabContainer("Rent", _carRentalDb.Rent, _rentRowsQuantity);

                    InitRentBtnsHandlers();
                    pagesQuantity = PagesCounter(_rentRowsQuantity);
                    InitPageControls(_rentContainer, pagesQuantity);
                }
                else
                {
                    _rentContainer = null;
                    _carRentalDb.Rent.Clear();
                    _rentContainer = InitTableTabContainer("Rent", _carRentalDb.Rent, _rentRowsQuantity);

                    InitRentBtnsHandlers();
                    pagesQuantity = PagesCounter(_rentRowsQuantity);
                    InitPageControls(_rentContainer, pagesQuantity);

                    _rent.Content = _rentContainer;
                }

                OpenTab(ref _rent, title, _rentContainer);
                break;

            default:
                break;
            }
        }