public static void AddType(string type) { if (DishModel.AddType(type)) { MessageBox.Show("Тип блюда: " + type + " успешно добавлен!", "Успех"); Form1 form1 = (Form1)Application.OpenForms["Form1"]; form1.Initialization(); FormAddType formAddType = (FormAddType)Application.OpenForms["FormAddType"]; formAddType.Close(); } else { MessageBox.Show("Ошибка! Данный тип уже добавлен.", "Error"); } }
public static int premission = 0; // 0 - usershop 1 - userCart 2 - Adminshop 3 - adminCart public static void Initialize(TabControl tabControlTypesMenu) { DishModel.InitializeDishMenu(); DishModel.InitializeTypesMenu(); tabControlTypesMenu.TabPages.Clear(); Form1.listTypePage.Clear(); TabPage myTabPage = new TabPage("Всё"); tabControlTypesMenu.TabPages.Add(myTabPage); tabControlTypesMenu.TabPages[0].UseVisualStyleBackColor = true; Form1.listTypePage.Add(new DataGridView()); Form1.listTypePage[0].Dock = DockStyle.Fill; Form1.listTypePage[0].Name = "dataGridView" + (0); tabControlTypesMenu.TabPages[0].Controls.Add(Form1.listTypePage[0]); Form1.listTypePage[0].Rows.Clear(); Form1.listTypePage[0].ColumnCount = 3; Form1.listTypePage[0].AllowUserToAddRows = false; Form1.listTypePage[0].RowHeadersVisible = false; Form1.listTypePage[0].SelectionMode = DataGridViewSelectionMode.FullRowSelect; Form1.listTypePage[0].AllowUserToResizeRows = false; Form1.listTypePage[0].ReadOnly = true; Form1.listTypePage[0].GridColor = SystemColors.ControlLightLight; Form1.listTypePage[0].BackgroundColor = SystemColors.ControlLightLight; foreach (var dish in DishModel.dishes) { Form1.listTypePage[0].Columns[1].Name = "Название"; Form1.listTypePage[0].Columns[1].Width = 316; Form1.listTypePage[0].Columns[2].Width = 40; Form1.listTypePage[0].Columns[2].Name = "Цена"; Form1.listTypePage[0].Columns[0].Name = "ID"; Form1.listTypePage[0].Columns[0].Visible = false; Form1.listTypePage[0].Rows.Add(dish.Id, dish.DishName, dish.PriceOfDIsh); } for (int i = 0; i < DishModel.AllTypeDishes.Count; i++) { myTabPage = new TabPage(DishModel.AllTypeDishes[i]); tabControlTypesMenu.TabPages.Add(myTabPage); tabControlTypesMenu.TabPages[i + 1].UseVisualStyleBackColor = true; var searchedFoodMenu = from query in DishModel.dishes where query.TypeOfDish.Contains(DishModel.AllTypeDishes[i]) select query; Form1.listTypePage.Add(new DataGridView()); Form1.listTypePage[i + 1].Name = "TypeListBox" + (i + 1); Form1.listTypePage[i + 1].Dock = DockStyle.Fill; tabControlTypesMenu.TabPages[i + 1].Controls.Add(Form1.listTypePage[i + 1]); Form1.listTypePage[i + 1].Rows.Clear(); Form1.listTypePage[i + 1].ColumnCount = 3; Form1.listTypePage[i + 1].AllowUserToAddRows = false; Form1.listTypePage[i + 1].RowHeadersVisible = false; Form1.listTypePage[i + 1].SelectionMode = DataGridViewSelectionMode.FullRowSelect; Form1.listTypePage[i + 1].AllowUserToResizeRows = false; Form1.listTypePage[i + 1].ReadOnly = true; Form1.listTypePage[i + 1].GridColor = SystemColors.ControlLightLight; Form1.listTypePage[i + 1].BackgroundColor = SystemColors.ControlLightLight; foreach (var dish in searchedFoodMenu) { Form1.listTypePage[i + 1].Columns[1].Name = "Название"; Form1.listTypePage[i + 1].Columns[1].Width = 333; Form1.listTypePage[i + 1].Columns[2].Width = 40; Form1.listTypePage[i + 1].Columns[2].Name = "Цена"; Form1.listTypePage[i + 1].Columns[0].Name = "ID"; Form1.listTypePage[i + 1].Columns[0].Visible = false; Form1.listTypePage[i + 1].Rows.Add(dish.Id, dish.DishName, dish.PriceOfDIsh); } } }