public EditDrugWindow(int drugID, DataGrid dataGrid) : this(dataGrid) {
            EditedDrug                     = new Drug(drugID);
            DrugID                         = drugID;
            AddButton.Content              = "Изменить";
            DrugNameTextBox.Text           = EditedDrug.Drug_name;
            DrugWholesalePriceTextBox.Text = EditedDrug.WholesalePrice.ToString();
            RetailPriceTextBox.Text        = EditedDrug.Retail_price.ToString();
            CurrentAmountTextBox.Text      = EditedDrug.Current_amount.ToString();
            WeightVolumeTextBox.Text       = EditedDrug.Weight_Volume;
            ApplicationTextBox.Document.Blocks.Add(new Paragraph(new Run(EditedDrug.Application)));
            DescriptionTextBox.Document.Blocks.Add(new Paragraph(new Run(EditedDrug.Description)));
            WarningTextBox.Document.Blocks.Add(new Paragraph(new Run(EditedDrug.Warning)));
            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = new Uri(EditedDrug.URL_photo, UriKind.Absolute);
            bitmap.EndInit();
            DrugImage.Source = bitmap;

            foreach (WholesalePriceClient wp in EditedDrug.WPricesList)
            {
                AddWPrice(wp.Price.ToString(), wp.Minimal_amount_of_product.ToString());
            }

            foreach (Manufacturer manufDrug in EditedDrug.ManufacturersList)
            {
                for (int i = 0; i < dictionaryManufacturers.Count; i++)
                {
                    if (dictionaryManufacturers[i].ManufacturerID == manufDrug.ManufacturerID)
                    {
                        (ManufacturerScrollViewer.Children[i] as CheckBox).IsChecked = true;
                    }
                }
            }

            foreach (Symptom sympDrug in EditedDrug.SymptomsList)
            {
                for (int i = 0; i < dictionarySymptoms.Count; i++)
                {
                    if (dictionarySymptoms[i].SymptomID == sympDrug.SymptomID)
                    {
                        (SymptomScrollViewer.Children[i] as CheckBox).IsChecked = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ShowContent(string filter)
        {
            content.Children.RemoveRange(0, content.Children.Count);
            List <Drug> drugsList = new List <Drug>();

            if (orderToSort != "Rating")
            {
                drugsList = Drug.GetDrugInfoList(filter,
                                                 $" Drug_name LIKE '{SearchBox.Text}%'", currentPage, pageSize, orderToSort);
            }
            else
            {
                drugsList = Drug.GetRatingSortedDrugList(filter,
                                                         $" Drug_name LIKE '{SearchBox.Text}%'", currentPage, pageSize);
            }
            numberOfDrugs = drugsList.Count;
            FillWithDrugs(drugsList);
        }
Exemplo n.º 3
0
        public static List <Drug> GetRatingSortedDrugList(string filter,
                                                          string search, int currentPage, int pageSize)
        {
            List <Drug> drugsList = new List <Drug>();

            filter = filter.Substring(filter.IndexOf(' ') + 1);
            using (MySqlConnection connection = new MySqlConnection(Logic.connectionString))
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand(
                    $"SELECT DISTINCT drugs.DrugID, drugs.Drug_name, drugs.Retail_price, drugs.URL_photo, drugs.Current_amount " +
                    $"FROM((((((drugs " +
                    $"JOIN products ON drugs.DrugID = products.DrugID) " +
                    $"JOIN treatments ON drugs.DrugID = treatments.DrugID) " +
                    $"JOIN manufacturers ON manufacturers.ManufacturerID = products.ManufacturerID) " +
                    $"JOIN symptoms ON symptoms.SymptomID = treatments.SymptomID) " +
                    $"JOIN countries ON countries.CountryID = manufacturers.CountryID) " +
                    $"LEFT JOIN historyofsales ON drugs.DrugID = historyofsales.DrugID) " +
                    $"WHERE { filter } AND { search} " +
                    $"GROUP BY drugs.DrugID " +
                    $"ORDER BY COUNT(DISTINCT historyofsales.PurchaseID) DESC " +
                    $"LIMIT {pageSize} " +
                    $"OFFSET {currentPage * pageSize};", connection);
                MySqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        Drug drug = new Drug
                        {
                            DrugID         = reader.GetInt32(0),
                            Drug_name      = reader.GetString(1),
                            Retail_price   = reader.GetString(2),
                            URL_photo      = reader.GetString(3),
                            Current_amount = reader.GetInt32(4)
                        };
                        drugsList.Add(drug);
                    }
                }
            }
            return(drugsList);
        }
Exemplo n.º 4
0
        public static List <Drug> GetAllDrugs()
        {
            List <Drug> drugs = new List <Drug>();

            using (MySqlConnection connection = new MySqlConnection(Logic.connectionString))
            {
                connection.Open();
                MySqlCommand    command = new MySqlCommand("CALL GetDrugs()", connection);
                MySqlDataReader reader  = command.ExecuteReader();
                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        int  id   = reader.GetInt32(0);
                        Drug drug = new Drug(id);
                        drugs.Add(drug);
                    }
                }
            }
            return(drugs);
        }
Exemplo n.º 5
0
        public static List <Drug> GetDrugInfoList(string filter, string search, int currentPage, int pageSize, string orderToSort)
        {
            List <Drug> drugsList = new List <Drug>();

            using (MySqlConnection connection = new MySqlConnection(Logic.connectionString))
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand(
                    $"SELECT DISTINCT drugs.DrugID, drugs.Drug_name, drugs.Retail_price, drugs.URL_photo, drugs.Current_amount " +
                    $"FROM drugs, manufacturers, products, symptoms, treatments, countries" +
                    $" WHERE(drugs.DrugID = products.DrugID " +
                    $"AND drugs.DrugID = treatments.DrugID " +
                    $"AND manufacturers.ManufacturerID = products.ManufacturerID " +
                    $"AND symptoms.SymptomID = treatments.SymptomID " +
                    $"AND countries.CountryID = manufacturers.CountryID) " +
                    $"{filter} AND {search}" +
                    $"ORDER BY {orderToSort} " +
                    $"LIMIT {pageSize} " +
                    $"OFFSET {currentPage * pageSize};", connection);
                MySqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        Drug drug = new Drug
                        {
                            DrugID         = reader.GetInt32(0),
                            Drug_name      = reader.GetString(1),
                            Retail_price   = reader.GetString(2),
                            URL_photo      = reader.GetString(3),
                            Current_amount = reader.GetInt32(4)
                        };
                        drugsList.Add(drug);
                    }
                }
            }

            return(drugsList);
        }
Exemplo n.º 6
0
        public PurchasesOfDrug(int drugid, DrugAnalysis drugAnalysis) : this()
        {
            List <Tuple <int, string> > list = Drug.GetSalesPerMonthByID(drugid);


            chart.ChartAreas.Add(new ChartArea("Default"));
            Series series = new Series("Series1");

            series.ChartType = SeriesChartType.Line;
            chart.Series.Add(series);
            chart.Series["Series1"].ChartArea = "Default";

            Series series1 = new Series("Series2");

            series1.ChartType = SeriesChartType.Line;
            chart.Series.Add(series1);
            chart.Series["Series1"].ChartArea = "Default";

            List <string> dates = new List <string>()
            {
                DateTime.Now.ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")) + ", " + DateTime.Now.Year,
                DateTime.Now.AddMonths(1).ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")) + ", " + DateTime.Now.AddMonths(1).Year
            };

            List <int> amounts = new List <int>()
            {
                list[list.Count - 1].Item1,
                drugAnalysis.AmountToHave
            };

            chart.Series["Series1"].Points.DataBindXY(list.Select(x => x.Item2).ToArray(), list.Select(x => x.Item1).ToArray());
            chart.Series["Series1"].IsValueShownAsLabel = true;
            chart.Series["Series2"].Points.DataBindXY(dates, amounts);
            chart.Series["Series2"].Points[1].IsValueShownAsLabel = true;
            Title title = chart.Titles.Add("Уровень продаж по месяцам");

            title.Font = new Font("Arial", 20);
            chart.AlignDataPointsByAxisLabel();
        }
Exemplo n.º 7
0
        public BuyProductWindow(int drugID,
                                List <Tuple <Drug, int, string> > basket, string login) : this()
        {
            Login      = login;
            ShowedDrug = new Drug(drugID);
            Basket     = basket;
            NumericUpDown numericUpDown = new NumericUpDown
            {
                FontSize = 25,
                Height   = 40,
                Value    = 1,
                Name     = "numericUpDown"
            };

            Grid.SetColumn(numericUpDown, 0);
            Grid.SetRow(numericUpDown, 0);
            emptyGrid.Children.Add(numericUpDown);

            DrugNameLabel.Content   = $"{ShowedDrug.Drug_name}, {ShowedDrug.Weight_Volume}";
            PriceLabel.Content      = $"{ShowedDrug.Retail_price} грн.";
            Availability.Content    = ShowedDrug.Current_amount > 0 ? "В наличии" : "Нет в наличии";
            Availability.Foreground = ShowedDrug.Current_amount > 0 ? Brushes.Green : Brushes.Red;
            BitmapImage bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.UriSource = new Uri(ShowedDrug.URL_photo, UriKind.Absolute);
            bitmap.EndInit();
            DrugImage.Source = bitmap;


            Label label = new Label();

            label.Content += "Производители: ";
            label.FontSize = 16;
            for (int i = 0; i < ShowedDrug.ManufacturersList.Count; i++)
            {
                label.Content += ShowedDrug.ManufacturersList[i].ManufacturerName;
                if (i != ShowedDrug.ManufacturersList.Count - 1)
                {
                    label.Content += ", ";
                }
            }
            ManufacturersChar.Children.Add(label);
            ShowedDrug.ManufacturersList.Distinct(new ManufacturerComparer());
            List <Country> list = Country.GetCountries();

            Label CountryLabel = new Label
            {
                FontSize = 16
            };

            if (ShowedDrug.ManufacturersList.Count > 1)
            {
                CountryLabel.Content += "Страны-производители: ";
            }
            else
            {
                CountryLabel.Content += "Страна-производитель: ";
            }
            for (int i = 0; i < ShowedDrug.ManufacturersList.Count; i++)
            {
                string countryname = list
                                     .Where(x => x.CountryID == ShowedDrug.ManufacturersList[i].CountryID)
                                     .Select(x => x.CountryName)
                                     .First()
                                     .ToString();

                CountryLabel.Content += countryname;
                if (i != ShowedDrug.ManufacturersList.Count - 1)
                {
                    CountryLabel.Content += ", ";
                }
            }
            CountriesChar.Children.Add(CountryLabel);

            if (ShowedDrug.WPricesList.Count > 0)
            {
                ShowedDrug.WPricesList = ShowedDrug.WPricesList.OrderBy(x => x.Minimal_amount_of_product).ToList();
                foreach (WholesalePriceClient wp in ShowedDrug.WPricesList)
                {
                    TextBlock textBlock = new TextBlock
                    {
                        FontSize = 18,
                        Text     = $"При заказе от {wp.Minimal_amount_of_product} шт.\n {wp.Price} грн."
                    };
                    WholesalePrices.Children.Add(textBlock);
                }
            }

            ApplicationTextBox.Text = ShowedDrug.Application;
            WarningTextBox.Text     = ShowedDrug.Warning;
            DescriptionTextBox.Text = ShowedDrug.Description;
        }
 public CartWindow(List <Tuple <Drug, int, string> > basket, string login) : this()
 {
     Basket = basket;
     Login  = login;
     if (Basket.Count != 0)
     {
         double resultSum = 0;
         foreach (Tuple <Drug, int, string> input in Basket)
         {
             Drug       drug         = input.Item1;
             int        boughtAmount = input.Item2;
             StackPanel stackPanel   = new StackPanel
             {
                 Orientation = Orientation.Horizontal
             };
             BitmapImage bitmap = new BitmapImage();
             bitmap.BeginInit();
             bitmap.UriSource = new Uri(drug.URL_photo, UriKind.Absolute);
             bitmap.EndInit();
             Image image = new Image
             {
                 Source = bitmap,
                 Height = 150,
                 Width  = 150
             };
             TextBlock info = new TextBlock
             {
                 Text         = $"{drug.Drug_name}, {drug.Weight_Volume}\nЦена:{input.Item3}",
                 FontSize     = 18,
                 Width        = 250,
                 TextWrapping = TextWrapping.Wrap
             };
             TextBlock amount = new TextBlock
             {
                 Text         = $"Количество\n{input.Item2}",
                 FontSize     = 18,
                 Width        = 100,
                 TextWrapping = TextWrapping.Wrap
             };
             TextBlock sum = new TextBlock
             {
                 FontSize     = 18,
                 Width        = 100,
                 TextWrapping = TextWrapping.Wrap
             };
             double s = Convert.ToDouble(input.Item3.Replace('.', ','));
             resultSum += s * input.Item2;
             sum.Text   = $"Сумма \n{s*input.Item2} грн.";
             Button deleteButton = new Button();
             deleteButton.Click += Button_Click1;
             deleteButton.Name   = currentButtonName;
             Image       image1  = new Image();
             BitmapImage bitmap1 = new BitmapImage();
             bitmap1.BeginInit();
             bitmap1.UriSource = new Uri("C:\\Users\\Андрей\\Documents\\Visual Studio 2017\\Projects\\WPF_TEST\\WPF_TEST\\Icons\\minus.png", UriKind.Absolute);
             bitmap1.EndInit();
             image1.Source        = bitmap1;
             deleteButton.Content = image1;
             stackPanel.Name      = currentButtonName.Replace('a', 'b');
             currentButtonName   += "a";
             stackPanel.Children.Add(image);
             stackPanel.Children.Add(info);
             stackPanel.Children.Add(amount);
             stackPanel.Children.Add(sum);
             stackPanel.Children.Add(deleteButton);
             content.Children.Add(stackPanel);
             AddPurchase.Visibility = Visibility.Visible;
         }
         Result.Content = $"Итого: {resultSum} грн.";
     }
     else
     {
         TextBlock textBlock = new TextBlock
         {
             FontSize = 25,
             Text     = "Ваша корзина пуста"
         };
         content.Children.Add(textBlock);
     }
 }
        private void AddPurchase_Click(object sender, RoutedEventArgs e)
        {
            if (Login == String.Empty)
            {
                MessageBox.Show("Для совершения покупок необходима регистрация");
            }
            else
            {
                MessageBox.Show($"Спасибо за покупку, {Login}");
                string           chequeID = Drug.AddPurchase(Basket, Login);
                Word.Application app      = new Word.Application();
                Word.Document    doc      = app.Documents.Add(Visible: true);
                Word.Range       r        = doc.Range();
                Word.Table       t        = doc.Tables.Add(r, Basket.Count + 1, 4);

                foreach (Word.Row row in t.Rows)
                {
                    foreach (Word.Cell cell in row.Cells)
                    {
                        if (cell.RowIndex == 1)
                        {
                            switch (cell.ColumnIndex)
                            {
                            case 1:
                                cell.Range.Text = "Название, вес";
                                break;

                            case 2:
                                cell.Range.Text = "Цена";
                                break;

                            case 3:
                                cell.Range.Text = "Количество";
                                break;

                            case 4:
                                cell.Range.Text = "Сумма";
                                break;
                            }

                            cell.Range.Bold      = 1;
                            cell.Range.Font.Name = "verdana";
                            cell.Range.Font.Size = 10;

                            cell.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                            cell.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        }
                        else
                        {
                            switch (cell.ColumnIndex)
                            {
                            case 1:
                                cell.Range.Text = $"{Basket[cell.RowIndex-2].Item1.Drug_name}, " +
                                                  $"{Basket[cell.RowIndex - 2].Item1.Weight_Volume}";
                                break;

                            case 2:
                                cell.Range.Text = $"{Basket[cell.RowIndex - 2].Item3} грн.";
                                break;

                            case 3:
                                cell.Range.Text = $"{Basket[cell.RowIndex - 2].Item2} грн.";
                                break;

                            case 4:
                                cell.Range.Text = $"{Convert.ToDouble(Basket[cell.RowIndex - 2].Item3) * Basket[cell.RowIndex - 2].Item2}";
                                break;
                            }
                        }
                    }
                }
                doc.Save();
                //app.Documents.Open(@"C:\Users\Андрей\Documents\Doc1.docx");

                try
                {
                    doc.Close();
                    app.Quit();
                }
                catch (Exception ex)
                {
                }
                Basket.RemoveRange(0, Basket.Count);
            }
            Close();
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            bool   add                       = true;
            double priceOfBought             = 0;
            double retailPrice               = 0;
            int    amount                    = 0;
            double wprice                    = 0;
            int    quan                      = 0;
            string name                      = "";
            List <WholesalePriceClient> list = new List <WholesalePriceClient>();

            DrugNameTextBox.Background           = Brushes.White;
            DrugWholesalePriceTextBox.Background = Brushes.White;
            RetailPriceTextBox.Background        = Brushes.White;
            CurrentAmountTextBox.Background      = Brushes.White;
            WeightVolumeTextBox.Background       = Brushes.White;
            SymptomLabel.Background      = Brushes.White;
            ManufacturerLabel.Background = Brushes.White;
            if (DrugNameTextBox.Text == String.Empty)
            {
                DrugNameTextBox.Background = Brushes.Red;
                add = false;
            }
            else
            {
                name = DrugNameTextBox.Text;
            }
            if (!double.TryParse(DrugWholesalePriceTextBox.Text, out priceOfBought))
            {
                MakeRed(DrugWholesalePriceTextBox, out add);
            }
            if (!double.TryParse(RetailPriceTextBox.Text, out retailPrice))
            {
                MakeRed(RetailPriceTextBox, out add);
            }
            if (!int.TryParse(CurrentAmountTextBox.Text, out amount))
            {
                MakeRed(CurrentAmountTextBox, out add);
            }
            if (WeightVolumeTextBox.Text == String.Empty)
            {
                MakeRed(WeightVolumeTextBox, out add);
            }

            foreach (StackPanel s in WholesalePrices.Children)
            {
                if (!double.TryParse(((s.Children[0] as StackPanel).Children[1] as TextBox).Text, out wprice) || wprice <= 0)
                {
                    MakeRed(((s.Children[0] as StackPanel).Children[1] as TextBox), out add);
                }
                if (!Int32.TryParse(((s.Children[1] as StackPanel).Children[1] as TextBox).Text, out quan) || quan <= 0)
                {
                    MakeRed(((s.Children[1] as StackPanel).Children[1] as TextBox), out add);
                }
            }

            int i = 0;

            foreach (CheckBox c in SymptomScrollViewer.Children)
            {
                if ((bool)c.IsChecked)
                {
                    i++;
                }
            }
            if (i == 0)
            {
                MakeRed(SymptomLabel, out add);
            }

            i = 0;
            foreach (CheckBox c in ManufacturerScrollViewer.Children)
            {
                if ((bool)c.IsChecked)
                {
                    i++;
                }
            }
            if (i == 0)
            {
                MakeRed(ManufacturerLabel, out add);
            }

            Drug changedDrug = new Drug();

            if (add)
            {
                string path = (DrugImage.Source as BitmapImage).UriSource.AbsoluteUri;
                changedDrug.DrugID      = DrugID;
                changedDrug.Application = new TextRange(
                    ApplicationTextBox.Document.ContentStart,
                    ApplicationTextBox.Document.ContentEnd).Text;
                changedDrug.Current_amount = amount;
                changedDrug.Description    = new TextRange(
                    DescriptionTextBox.Document.ContentStart,
                    DescriptionTextBox.Document.ContentEnd).Text;
                changedDrug.Drug_name    = name;
                changedDrug.Retail_price = retailPrice.ToString().Replace(',', '.');
                changedDrug.URL_photo    = path;
                changedDrug.Warning      = new TextRange(
                    WarningTextBox.Document.ContentStart,
                    WarningTextBox.Document.ContentEnd).Text;
                changedDrug.Weight_Volume  = WeightVolumeTextBox.Text;
                changedDrug.WholesalePrice = priceOfBought.ToString().Replace(',', '.');

                foreach (StackPanel s in WholesalePrices.Children)
                {
                    WholesalePriceClient priceClient = new WholesalePriceClient();
                    priceClient.Price = (((s.Children[0] as StackPanel).Children[1] as TextBox).Text).Replace(',', '.');
                    priceClient.Minimal_amount_of_product = Int32.Parse(((s.Children[1] as StackPanel).Children[1] as TextBox).Text);
                    changedDrug.WPricesList.Add(priceClient);
                }

                for (int j = 0; j < SymptomScrollViewer.Children.Count; j++)
                {
                    if ((bool)(SymptomScrollViewer.Children[j] as CheckBox).IsChecked)
                    {
                        changedDrug.SymptomsList.Add(dictionarySymptoms[j]);
                    }
                }

                for (int j = 0; j < ManufacturerScrollViewer.Children.Count; j++)
                {
                    if ((bool)(ManufacturerScrollViewer.Children[j] as CheckBox).IsChecked)
                    {
                        changedDrug.ManufacturersList.Add(dictionaryManufacturers[j]);
                    }
                }

                if (AddButton.Content.ToString() == "Добавить")
                {
                    //Add

                    Drug.AddDrug(changedDrug);
                }
                else
                {
                    //Change

                    Drug.UpdateDrug(changedDrug);
                }

                Logic.ShowTable(DataGrid, "CALL GetDrugsInfo()");
                Close();
            }
        }