Exemplo n.º 1
0
        private void Button6_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
            {
                MessageBox.Show("Одно или более поле имеет пустое значение", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Dishesmenu MenuDish = new Dishesmenu();


                MenuDish.Name  = comboBox1.Text;
                MenuDish.Ves   = Convert.ToInt32(textBox2.Text);
                MenuDish.Price = Convert.ToDecimal(textBox3.Text);
                //MenuDish.idDishes = Convert.ToInt32(textBox1.Text);
                MenuDish.idDishes = Convert.ToInt32(comboBox1.SelectedValue);
                MenuDish.Category = CategoryDishesmenu.Text;
                MenuDish.idMenu   = Convert.ToInt32(textBox4.Text);

                db.Dishesmenu.Add(MenuDish);
                db.SaveChanges();

                //int n = dataGridView2.SelectedRows[0].Index;
                int u = (int)dataGridView2.SelectedCells[0].Value;
                //int u = (int)dataGridView2.Rows[0].Cells[0].Value;

                var result = from Menu in db.Menu
                             join Di in db.Dishesmenu on Menu.Id equals Di.idMenu
                             where Di.idMenu == u
                             orderby Di.Category
                             select new
                {
                    Id       = Di.Id,
                    idDishes = Di.idDishes,
                    Name     = Di.Name,
                    Ves      = Di.Ves,
                    Price    = Di.Price,
                    idMenu   = u,
                    Category = Di.Category
                };


                dataGridView3.DataSource = result.ToList();
            }
        }
Exemplo n.º 2
0
        private void удалитьToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (dataGridView3.SelectedRows.Count > 0)
            {
                int  index     = dataGridView3.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView3[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Dishesmenu menuDel = db.Dishesmenu.Find(id);
                db.Dishesmenu.Remove(menuDel);
                db.SaveChanges();
                int u = (int)dataGridView2.SelectedCells[0].Value;
                //int u = (int)dataGridView2.Rows[0].Cells[0].Value;

                var result = from Menu in db.Menu
                             join Di in db.Dishesmenu on Menu.Id equals Di.idMenu
                             where Di.idMenu == u
                             select new
                {
                    Id       = Di.Id,
                    idDishes = Di.idDishes,
                    Name     = Di.Name,
                    Ves      = Di.Ves,
                    Price    = Di.Price,
                    idMenu   = u
                };


                dataGridView3.DataSource = result.ToList();
                MessageBox.Show("Объект удален", "Блюда в меню", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Exemplo n.º 3
0
        private void button9_Click_1(object sender, EventArgs e)
        {
            var templateFileName = Path.Combine(Environment.CurrentDirectory, "меню.doc");

            if (!File.Exists(templateFileName))
            {
                throw new FileNotFoundException("File not found.", templateFileName);
            }
            Dishesmenu Du = new Dishesmenu();

            using (var application = new NetOffice.WordApi.Application {
                Visible = true
            })
            {
                using (var document = application.Documents.Add(templateFileName))
                {
                    List <HelpCategory> cats = new List <HelpCategory>();

                    for (int i = 0; i < dataGridView3.RowCount; i++)
                    {
                        HelpCategory temp = new HelpCategory();
                        temp.ves      = (int)dataGridView3.Rows[i].Cells[3].Value;
                        temp.name     = (string)dataGridView3.Rows[i].Cells[2].Value;
                        temp.price    = (decimal)dataGridView3.Rows[i].Cells[4].Value;
                        temp.category = (string)dataGridView3.Rows[i].Cells[6].Value;

                        cats.Add(temp);
                    }


                    var coordinatesTable = document.Bookmarks["Coordinates"].Range.Tables[1];


                    //

                    List <string> uniqueCategory = cats.Select(x => x.category).Distinct().ToList();



                    foreach (string strCat in uniqueCategory)
                    {
                        var tempWord = coordinatesTable.Rows.Add();

                        tempWord.Cells[2].Range.Bold = 3;
                        tempWord.Cells[2].Range.Text = strCat;


                        foreach (HelpCategory cat in cats)
                        {
                            if (cat.category == strCat)
                            {
                                var tempRow = coordinatesTable.Rows.Add();
                                tempRow.Cells[2].Range.Bold = 0;
                                tempRow.Cells[1].Range.Text = cat.ves.ToString();
                                tempRow.Cells[2].Range.Text = cat.name;
                                tempRow.Cells[3].Range.Text = cat.price.ToString("# руб");
                            }
                        }
                    }

                    coordinatesTable.Rows[2].Delete();

                    var MenuTable = document.Bookmarks["data"].Range;
                    int n         = dataGridView2.SelectedRows[0].Index;
                    MenuTable.Text = dataGridView2.Rows[n].Cells[2].Value.ToString();
                    //var MenuTable = document.Bookmarks["Menu"].Range.Text;

                    ////var coordinateRow = Menu.Add();
                }
                application.Activate();
            }
        }
Exemplo n.º 4
0
        private void button10_Click(object sender, EventArgs e)
        {
            if (dataGridView2.SelectedRows.Count > 0)
            {
                //int n = dataGridView2.SelectedRows[0].Index;
                //dataGridView3.Rows[n].Cells[1].Value = FindRecBox.Text;

                int  index     = dataGridView3.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView3[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Dishesmenu Dis = db.Dishesmenu.Find(id);

                Dis.Name     = comboBox1.Text;
                Dis.Ves      = Convert.ToInt32(textBox2.Text);
                Dis.Price    = Convert.ToDecimal(textBox3.Text);
                Dis.Category = CategoryDishesmenu.Text;

                db.SaveChanges();
                dataGridView3.Refresh(); // обновляем грид
                db.SaveChanges();

                Button6.Enabled   = true;
                button10.Enabled  = false;
                textBox2.ReadOnly = true;
                textBox3.ReadOnly = true;

                int u = (int)dataGridView2.SelectedCells[0].Value;
                //int u = (int)dataGridView2.Rows[0].Cells[0].Value;

                var result = from Di in db.Dishesmenu
                             //join Dish in db.Dishes on Di.idDishes equals Dish.Id
                             join Menu in db.Menu on Di.idMenu equals Menu.Id

                             where Di.idMenu == u
                             orderby Di.Category
                             select new
                {
                    Id       = Di.Id,
                    idDishes = Di.idDishes,
                    Name     = Di.Name,
                    Ves      = Di.Ves,
                    Price    = Di.Price,
                    idMenu   = u,
                    Category = Di.Category
                };


                dataGridView3.DataSource = result.ToList();

                MessageBox.Show("Объект обновлен");
            }
            else
            {
                MessageBox.Show("Выберите строку для редактирования.", "Ошибка.");
            }


            db.SaveChanges();
        }