Exemple #1
0
 private void checkValidDirectory()
 {
     if (!Directory.Exists(DataPath))
     {
         DialogResult result = MessageBox.Show("Путь к созданым ранее документам недоступен! Указать новый путь или использовать путь по умолчанию?", "Использовать новый путь?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         {
             fBDialogPath             = new FolderBrowserDialog();
             fBDialogPath.Description = "Выберите папку для загрузки и сохранения документов";
             fBDialogPath.ShowDialog();
             if (!Directory.Exists(fBDialogPath.SelectedPath))
             {
                 checkValidDirectory();
             }
             else
             {
                 DataPath = fBDialogPath.SelectedPath;
             }
         }
         else
         {
             DataPath = Application.StartupPath;
         }
     }
     this.WindowState = FormWindowState.Normal;
     this.Focus();
     LoggingService.AddLog("Выбран путь: " + DataPath);
 }
        private void BuildDocument()
        {
            WordWorker.Load();
            Word.Range range = WordWorker.doc.Paragraphs[WordWorker.doc.Paragraphs.Count].Range;
            double     summ  = 0;
            int        i     = 2;

            foreach (ProductDTO product in MainForm.DB.Products.GetAll())
            {
                WordWorker.doc.Tables[1].Rows.Add();
                i++;
                WordWorker.doc.Tables[1].Cell(i, 1).Range.Text = product.Name;
                WordWorker.doc.Tables[1].Cell(i, 2).Range.Text = MainForm.DB.Units.Get(product.UnitId).Name;
                WordWorker.doc.Tables[1].Cell(i, 4).Range.Text = product.Balance.ToString();
                WordWorker.doc.Tables[1].Cell(i, 3).Range.Text = product.getPrice().ToString();
                WordWorker.doc.Tables[1].Cell(i, 5).Range.Text = Math.Round(product.Sum, 2).ToString();
                summ += product.Sum;
            }
            WordWorker.doc.Tables[1].Rows.Add();
            i++;
            WordWorker.doc.Tables[1].Cell(i, 1).Range.Text = "Итого";
            WordWorker.doc.Tables[1].Cell(i, 5).Range.Text = Math.Round(summ, 2).ToString();
            DateTime now = DateTime.Now;

            WordWorker.Save(MainForm.DataPath + "\\Документы\\Остатки продуктов на " + (now.ToString("g")).Replace('.', '-').Replace(':', '-') + ".docx");
            WordWorker.Close();
            WordWorker.Open(MainForm.DataPath + "\\Документы\\Остатки продуктов на " + (now.ToString("g")).Replace('.', '-').Replace(':', '-') + ".docx");
            LoggingService.AddLog("Распечатка остатков на " + (now.ToString("g")).Replace('.', '-').Replace(':', '-') + " в файл по пути: " + MainForm.DataPath + "\\Документы\\");
        }
        private void ButDel_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить продукт " + _Product.Name + " ?", "Удаление продукта", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                MainForm.DB.Products.Delete(_Product.Id);
                MainForm.DB.Save();
                MessageBox.Show("Продукт успешно удалён");
                LoggingService.AddLog("Удаление продукта: " + _Product.Name);
                this.Close();
                main.ReloadData();
            }
        }
Exemple #4
0
        private void ButDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить блюдо " + _Dish.Name + " ?", "Удаление блюда", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                MainForm.DB.Dishes.Delete(_Dish.Id);
                MainForm.DB.Save();
                LoggingService.AddLog("Удаление блюда: " + _Dish.ToString());
                MessageBox.Show("Блюдо успешно удалено");
                this.Close();
                main.ReloadData();
            }
        }
 private void DGVDishesList_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 6)
     {
         AddEditDishForm addEdit = new AddEditDishForm((DishDTO)dGVDishesList.CurrentRow.Tag, this);
         addEdit.Show();
     }
     if (e.ColumnIndex == 7)
     {
         DishDTO dish = (DishDTO)dGVDishesList.CurrentRow.Tag;
         if (MessageBox.Show("Удалить " + dish.Name + " ?", "Подтверждение удаления", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             MainForm.DB.Dishes.Delete(dish.Id);
             MainForm.DB.Save();
             LoggingService.AddLog("Удаление блюда: " + dish.ToString());
             ReloadData();
         }
     }
 }
 private void DGVProductsList_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 6)
     {
         AddEditProductForm addEdit = new AddEditProductForm((ProductDTO)dGVProductsList.CurrentRow.Tag, this);
         addEdit.Show();
     }
     if (e.ColumnIndex == 7)
     {
         ProductDTO product = (ProductDTO)dGVProductsList.CurrentRow.Tag;
         if (MessageBox.Show("Удалить " + product.Name + " ?", "Подтверждение удаления", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             MainForm.DB.Products.Delete(product.Id);
             MainForm.DB.Save();
             LoggingService.AddLog("Удаление продукта: " + product.ToString());
             ReloadData();
         }
     }
 }
        private void ButSave_Click(object sender, EventArgs e)
        {
            if (tBName.Text == "")
            {
                ShowError("Не все обязательные поля заполнены!");
            }
            else
            {
                if (_Product == null)
                {
                    ProductDTO product = new ProductDTO();
                    product.Name       = tBName.Text.ToString();
                    product.PsevdoName = tBPsevdoName.Text.ToString();
                    if (tBNorm.Text != "")
                    {
                        product.Norm = float.Parse(tBNorm.Text);
                    }
                    if (tBSum.Text != "")
                    {
                        product.Sum = float.Parse(tBSum.Text);
                    }
                    if (tBBalance.Text != "")
                    {
                        product.Balance = float.Parse(tBBalance.Text);
                    }
                    if (tBCarbo.Text != "")
                    {
                        product.Carbohydrate = int.Parse(tBCarbo.Text);
                    }
                    if (tBProtein.Text != "")
                    {
                        product.Protein = int.Parse(tBProtein.Text);
                    }
                    if (tBFat.Text != "")
                    {
                        product.Fat = int.Parse(tBFat.Text);
                    }
                    if (tBVitamine.Text != "")
                    {
                        product.Vitamine_C = int.Parse(tBVitamine.Text);
                    }
                    TypeDTO type = MainForm.DB.Types.GetAll().Where(x => x.Name == cBType.SelectedValue.ToString()).First();
                    product.Type   = type;
                    product.TypeId = type.Id;
                    UnitDTO unit = MainForm.DB.Units.GetAll().Where(x => x.Name == cBUnit.SelectedValue.ToString()).First();
                    product.Unit   = unit;
                    product.UnitId = unit.Id;
                    MainForm.DB.Products.Create(product);
                    actions.Add(new ActionDescription("Характеристики продукта: " + product.Name, "Псевдоним: " + product.PsevdoName, "Ед. изм.: " + product.Unit.Name, "Тип: " + product.Type.Name, "Сумма: " + product.Sum.ToString(), "Количество: " + product.Balance.ToString(), "Норма = " + product.Norm.ToString(), "Углеводы: " + product.Carbohydrate.ToString(), "Жиры: " + product.Fat.ToString(), "Белки: " + product.Protein.ToString(), "Витамин С: " + product.Vitamine_C.ToString()));
                    logMessage.Append(product.Name);
                }
                else
                {
                    ProductDTO product = MainForm.DB.Products.Get(_Product.Id);
                    product.Name       = tBName.Text.ToString();
                    product.PsevdoName = tBPsevdoName.Text.ToString();
                    if (tBNorm.Text != "")
                    {
                        product.Norm = float.Parse(tBNorm.Text);
                    }
                    if (tBCarbo.Text != "")
                    {
                        product.Carbohydrate = int.Parse(tBCarbo.Text);
                    }
                    if (tBProtein.Text != "")
                    {
                        product.Protein = int.Parse(tBProtein.Text);
                    }
                    if (tBSum.Text != "")
                    {
                        product.Sum = float.Parse(tBSum.Text);
                    }
                    if (tBBalance.Text != "")
                    {
                        product.Balance = float.Parse(tBBalance.Text);
                    }
                    if (tBFat.Text != "")
                    {
                        product.Fat = int.Parse(tBFat.Text);
                    }
                    if (tBVitamine.Text != "")
                    {
                        product.Vitamine_C = int.Parse(tBVitamine.Text);
                    }
                    TypeDTO type = MainForm.DB.Types.GetAll().Where(x => x.Name == cBType.SelectedValue.ToString()).First();
                    product.Type   = type;
                    product.TypeId = type.Id;
                    UnitDTO unit = MainForm.DB.Units.GetAll().Where(x => x.Name == cBUnit.SelectedValue.ToString()).First();
                    product.Unit   = unit;
                    product.UnitId = unit.Id;

                    MainForm.DB.Products.Update(product);
                    actions.Add(new ActionDescription("Характеристики продукта: " + product.Name, "Псевдоним: " + product.PsevdoName, "Ед. изм.: " + product.Unit.Name, "Тип: " + product.Type.Name, "Cумма: " + product.Sum.ToString(), "Количество: " + product.Balance.ToString(), "Норма = " + product.Norm.ToString(), "Углеводы: " + product.Carbohydrate.ToString(), "Жиры: " + product.Fat.ToString(), "Белки: " + product.Protein.ToString(), "Витамин С: " + product.Vitamine_C.ToString()));
                    logMessage.Append(product.Name);
                }
                MainForm.DB.Save();
                MessageBox.Show("Продукт успешно сохранён");
                LoggingService.AddLog(logMessage.ToString(), actions.ToArray());
                this.Close();
            }
        }
Exemple #8
0
        private void ButSave_Click(object sender, EventArgs e)
        {
            if (tBName.Text == "" || tBNorm.Text == "")
            {
                ShowError("Не все обязательные поля заполнены!");
            }
            else
            {
                if (lBSostav.Items.Count == 0)
                {
                    ShowError("Состав не может быть пустым!");
                }
                else
                {
                    if (_Dish == null)
                    {
                        DishDTO dish = new DishDTO();
                        dish.Name = tBName.Text.ToString();
                        dish.Norm = float.Parse(tBNorm.Text);
                        if (tBCarbo.Text != "")
                        {
                            dish.Carbohydrate = int.Parse(tBCarbo.Text);
                        }
                        if (tBProtein.Text != "")
                        {
                            dish.Protein = int.Parse(tBProtein.Text);
                        }
                        if (tBFat.Text != "")
                        {
                            dish.Fat = int.Parse(tBFat.Text);
                        }
                        if (tBVitamine.Text != "")
                        {
                            dish.Vitamine_C = int.Parse(tBVitamine.Text);
                        }
                        MainForm.DB.Dishes.Create(dish);
                        MainForm.DB.Save();
                        List <ActionDescription> actions = new List <ActionDescription>();
                        actions.Add(new ActionDescription("Характеристики блюда: " + dish.Name, "Норма = " + dish.Norm.ToString(), "Углеводы: " + dish.Carbohydrate.ToString(), "Жиры: " + dish.Fat.ToString(), "Белки: " + dish.Protein.ToString(), "Витамин С: " + dish.Vitamine_C.ToString()));

                        DishDTO dishNew = MainForm.DB.Dishes.GetAll().Last();
                        foreach (var item in products)
                        {
                            float temp;
                            norms.TryGetValue(item.Name, out temp);
                            MainForm.DB.ProductDishes.Create(new ProductDishDTO
                            {
                                Dish      = dishNew,
                                DishId    = dishNew.Id,
                                Product   = item,
                                ProductId = item.Id,
                                Norm      = temp
                            });
                            MainForm.DB.Save();
                            actions.Add(new ActionDescription("Добавление продукта " + item.Name, "Норма = " + temp.ToString()));
                        }
                        LoggingService.AddLog("Добавление нового блюда: " + dish.ToString(), actions.ToArray());
                    }
                    else
                    {
                        DishDTO dish = MainForm.DB.Dishes.Get(_Dish.Id);
                        dish.Name = tBName.Text.ToString();
                        dish.Norm = float.Parse(tBNorm.Text);
                        if (tBCarbo.Text != "")
                        {
                            dish.Carbohydrate = int.Parse(tBCarbo.Text);
                        }
                        if (tBProtein.Text != "")
                        {
                            dish.Protein = int.Parse(tBProtein.Text);
                        }
                        if (tBFat.Text != "")
                        {
                            dish.Fat = int.Parse(tBFat.Text);
                        }
                        if (tBVitamine.Text != "")
                        {
                            dish.Vitamine_C = int.Parse(tBVitamine.Text);
                        }

                        var list = MainForm.DB.ProductDishes.GetAll().Where(x => x.DishId == _Dish.Id);
                        foreach (var item in list)
                        {
                            MainForm.DB.ProductDishes.Delete(item.Id);
                        }
                        MainForm.DB.Save();
                        List <ActionDescription> actions = new List <ActionDescription>();
                        actions.Add(new ActionDescription("Характеристики блюда: " + dish.Name, "Норма = " + dish.Norm.ToString(), "Углеводы: " + dish.Carbohydrate.ToString(), "Жиры: " + dish.Fat.ToString(), "Белки: " + dish.Protein.ToString(), "Витамин С: " + dish.Vitamine_C.ToString()));

                        foreach (var item in products)
                        {
                            float temp;
                            norms.TryGetValue(item.Name, out temp);
                            MainForm.DB.ProductDishes.Create(new ProductDishDTO
                            {
                                Dish      = dish,
                                DishId    = dish.Id,
                                Product   = item,
                                ProductId = item.Id,
                                Norm      = temp
                            });
                            MainForm.DB.Save();
                            actions.Add(new ActionDescription("Добавление продукта " + item.Name, "Норма = " + temp.ToString()));
                        }
                        LoggingService.AddLog("Изменение блюда: " + dish.ToString(), actions.ToArray());
                    }
                    MainForm.DB.Save();
                    MessageBox.Show("Блюдо успешно сохранено");
                    this.Close();
                    main.ReloadData();
                }
            }
        }