コード例 #1
0
        private void LoadDataFromDatabase()
        {
            this.ReceivedProductsDataGrid.Items.Clear();
            this.StorageProductsDataGrid.Items.Clear();
            this.SoldProductsDataGrid.Items.Clear();

            var received_products = StorageDB.QueryReceivedProductRecords();
            var storage_products  = StorageDB.QueryStorageProductRecords();
            var sold_products     = StorageDB.QuerySoldProductRecords();

            foreach (var rp in received_products)
            {
                this.ReceivedProductsDataGrid.Items.Add(rp);
            }

            foreach (var sp in storage_products)
            {
                this.StorageProductsDataGrid.Items.Add(sp);
            }

            foreach (var sdp in sold_products)
            {
                this.SoldProductsDataGrid.Items.Add(sdp);
            }
        }
コード例 #2
0
 public AddRecordWindow()
 {
     InitializeComponent();
     this.ReceivedProduct = null;
     this.ProductReceivedDatePicker.Text        = DateTime.Now.ToString();
     this.ProductNameComboBox.ItemsSource       = StorageDB.QueryProductsNames();
     this.ProductNameComboBox.SelectedIndex     = 0;
     this.ProductNameTextBox.Text               = this.ProductNameComboBox.SelectedItem?.ToString();
     this.ProductNameComboBox.SelectionChanged += ProductNameComboBox_SelectionChanged;
 }
コード例 #3
0
        private void AddRecordButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.ProductReceivedDatePicker.Text == "")
            {
                MessageBox.Show("Enter date!!!");
                return;
            }
            else if (this.ProductNameTextBox.Text == "")
            {
                MessageBox.Show("Enter product name!!!");
                return;
            }
            else if (this.ProductPriceTextBox.Text == "")
            {
                MessageBox.Show("Enter product price!!!");
                return;
            }

            DateTime received_date;
            decimal  price;

            if (!DateTime.TryParse(this.ProductReceivedDatePicker.Text, out received_date))
            {
                MessageBox.Show("Date parsing failed!!!");
                return;
            }
            else if (!decimal.TryParse(this.ProductPriceTextBox.Text, out price))
            {
                MessageBox.Show("Price parsing failed!!!");
                return;
            }

            ProductRecord new_product = new ProductRecord()
            {
                Price       = price,
                ProductName = this.ProductNameTextBox.Text,
                Date        = received_date
            };


            // Add to database
            try
            {
                StorageDB.AddNewProduct(new_product);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = false;
                return;
            }

            this.ReceivedProduct = new_product;
            this.DialogResult    = true;
        }
コード例 #4
0
        private void FilterButton_Click(object sender, RoutedEventArgs e)
        {
            Status status;

            if (this.ReceivedRadioButton.IsChecked ?? false)
            {
                status = Status.RECIEVED;
            }
            else if (this.StorageRadioButton.IsChecked ?? false)
            {
                status = Status.STORAGE;
            }
            else if (this.SoldRadioButton.IsChecked ?? false)
            {
                status = Status.SOLD;
            }
            else
            {
                status = Status.ALL;
            }

            DateTime from_date;

            if (this.FromDatePicker.Text == "")
            {
                from_date = DateTime.MinValue;
            }
            else if (!DateTime.TryParse(this.FromDatePicker.Text, out from_date))
            {
                MessageBox.Show("Bad \"from date\" input!!!");
                return;
            }

            DateTime to_date;

            if (this.ToDatePicker.Text == "")
            {
                to_date = DateTime.MaxValue;
            }
            else if (!DateTime.TryParse(this.ToDatePicker.Text, out to_date))
            {
                MessageBox.Show($"Bad \"to date\" input!!!");
                return;
            }

            //MessageBox.Show($"{to_date}; {from_date};   {to_date.CompareTo(from_date)}");
            if (to_date.CompareTo(from_date) < 0)
            {
                MessageBox.Show("\"to date\" earlier than \"from date\"  input!!!");
                return;
            }

            this.ReportDataGrid.Items.Clear();
            List <ProductRecord> report_records = null;
            decimal sum = -1;

            switch (status)
            {
            case Status.ALL:
                report_records = StorageDB.QueryAllProductRecords(from_date, to_date);
                sum            = StorageDB.CountAllProductSum(from_date, to_date);
                break;

            case Status.RECIEVED:
                report_records = StorageDB.QueryReceivedProductRecords(from_date, to_date);
                sum            = StorageDB.CountReceivedProductSum(from_date, to_date);
                break;

            case Status.STORAGE:
                report_records = StorageDB.QueryStorageProductRecords(from_date, to_date);
                sum            = StorageDB.CountStorageProductSum(from_date, to_date);
                break;

            case Status.SOLD:
                report_records = StorageDB.QuerySoldProductRecords(from_date, to_date);
                sum            = StorageDB.CountSoldProductSum(from_date, to_date);
                break;
            }
            foreach (var r in report_records)
            {
                this.ReportDataGrid.Items.Add(r);
            }
            this.SumTextBlock.Text = $"Total sum: {sum}";
        }