private void butLogin_Click(object sender, EventArgs e) { if (!textBoxLog.Text.Equals("") || !textBoxPass.Text.Equals("")) { User toUpdateUser = new User { nick = textBoxLog.Text, pass = textBoxPass.Text }; try { var result = (from user in data.Users where user.nick == textBoxLog.Text select new { user }).FirstOrDefault(); if (result == null) { labelMsg.Text = "User not found"; labelMsg.Visible = true; } else if (PasswordHash.checkPassword(textBoxPass.Text, result.user.pass)) { labelMsg.Text = "Zalogowano !!!"; labelMsg.Visible = true; FormMain formMain = new FormMain(form11); formMain.Show(); form11.Hide(); if (result.user.role.Equals("admin")) { formMain.Admin = true; } formMain.Loggedin = true; formMain.loadBox(); this.Close(); } else { labelMsg.Text = "Zly login lub haslo !!!"; labelMsg.Visible = true; } } catch (System.Data.SqlClient.SqlException ex) { MessageBox.Show("Connection lost"); this.Close(); }catch (Exception ex) { labelMsg.Text = "Zly login lub haslo !!!"; labelMsg.Visible = true; } } else { MessageBox.Show("Enter login and password"); } }
private void butDelete_Click(object sender, EventArgs e) { try { int idx = getSelectedIdx(dataGridKind, "Id"); var result = (from kind in data.Kinds where kind.Id == idx select kind).First(); data.Kinds.DeleteOnSubmit(result); try{ data.SubmitChanges(); }catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); } refresh(); form1.loadBox(); errorHide(); }catch (Exception ex) { Console.WriteLine(ex); form1.lostConnection(); errorShow("You can not delete while it is somewhere used"); } }
private void butBack_Click(object sender, EventArgs e) { formHandler.loadBox(); this.Close(); }
private void butAdd_Click(object sender, EventArgs e) { DateTime myDateTime = DateTime.Now; Description desc = new Description(); try { desc.decription = textBoxOrderDesc.Text; }catch (Exception ex) { Console.WriteLine(ex); desc.decription = "Null"; } data.Descriptions.InsertOnSubmit(desc); try{ data.SubmitChanges(); }catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); } Order order = new Order(); order.Description = desc; order.startDateTime = myDateTime; order.idKind = (byte)comboBoxKind.SelectedValue; order.idStatus = 1; data.Orders.InsertOnSubmit(order); try{ data.SubmitChanges(); }catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); } foreach (var item in myItems) { try { if (item.type.Equals("Dish")) { var result = (from dishDetail in data.DishDetails where dishDetail.Id == item.id select dishDetail).First(); OrderDish orderDish = new OrderDish(); orderDish.idOrder = order.Id; orderDish.idDishDetail = result.Id; data.OrderDishes.InsertOnSubmit(orderDish); try{ data.SubmitChanges(); }catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); } } else { var result = (from drinkDetail in data.DrinkDetails where drinkDetail.Id == item.id select drinkDetail).First(); OrderDrink orderDrink = new OrderDrink(); orderDrink.idOrder = order.Id; orderDrink.idDrinkDetail = result.Id; data.OrderDrinks.InsertOnSubmit(orderDrink); try{ data.SubmitChanges(); }catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); } } }catch (Exception ex) { form1.lostConnection(); } } this.Close(); form1.clearAll(); form1.loadBox(); }
private void button1_Click(object sender, EventArgs e) { data.ExecuteCommand("DROP TABLE [dbo].[OrderDish]"); data.ExecuteCommand("DROP TABLE [dbo].[OrderDrink]"); data.ExecuteCommand("DROP TABLE [dbo].[DishDetail]"); data.ExecuteCommand("DROP TABLE [dbo].[DrinkDetail]"); data.ExecuteCommand("DROP TABLE [dbo].[Order]"); data.ExecuteCommand("DROP TABLE [dbo].[Status]"); data.ExecuteCommand("DROP TABLE [dbo].[Kind]"); data.ExecuteCommand("DROP TABLE [dbo].[Size]"); data.ExecuteCommand("DROP TABLE [dbo].[Profit]"); data.ExecuteCommand("DROP TABLE [dbo].[Drink]"); data.ExecuteCommand("DROP TABLE [dbo].[Dish]"); data.ExecuteCommand("DROP TABLE [dbo].[Description]"); data.ExecuteCommand("CREATE TABLE [dbo].[Description] ([Id] INT IDENTITY(1, 1) NOT NULL,[decription] VARCHAR(200) NULL,PRIMARY KEY CLUSTERED([Id] ASC)); "); data.ExecuteCommand("CREATE TABLE [dbo].[Kind] ([Id] TINYINT NOT NULL,[text] VARCHAR(50) NULL,PRIMARY KEY CLUSTERED([Id] ASC)); "); data.ExecuteCommand("CREATE TABLE [dbo].[Size] ([Id] TINYINT NOT NULL,[text] VARCHAR(50) NULL, [value] INT NULL,PRIMARY KEY CLUSTERED([Id] ASC)); "); data.ExecuteCommand("CREATE TABLE [dbo].[Status] ([Id] TINYINT NOT NULL,[text] VARCHAR(50) NULL,PRIMARY KEY CLUSTERED([Id] ASC)); "); data.ExecuteCommand("CREATE TABLE [dbo].[Profit] ([Id] INT IDENTITY(1, 1) NOT NULL,[date] DATE NULL,[inCash] MONEY NULL,[onHand] MONEY NULL,[tax] MONEY NULL,PRIMARY KEY CLUSTERED([Id] ASC)); "); data.ExecuteCommand("CREATE TABLE [dbo].[Drink] ([Id] INT IDENTITY(1, 1) NOT NULL,[name] VARCHAR(100) NULL,[adults] BIT NULL,[idDescription] INT NULL, PRIMARY KEY CLUSTERED([Id] ASC),FOREIGN KEY([idDescription]) REFERENCES[dbo].[Description]([Id])); "); data.ExecuteCommand("CREATE TABLE [dbo].[Dish] ( [Id] INT IDENTITY(1, 1) NOT NULL,[name] VARCHAR(100) NULL,[idDescription] INT NULL, PRIMARY KEY CLUSTERED([Id] ASC),FOREIGN KEY([idDescription]) REFERENCES[dbo].[Description]([Id])); "); data.ExecuteCommand("CREATE TABLE [dbo].[DishDetail] ([Id] INT IDENTITY(1, 1) NOT NULL,[availability] BIT NULL,[idSize] TINYINT NULL, [idKind] TINYINT NULL,[price] MONEY NULL,[tax] INT NULL,[idDish] INT NOT NULL,PRIMARY KEY CLUSTERED([Id] ASC),FOREIGN KEY([idSize]) REFERENCES[dbo].[Size]([Id]),FOREIGN KEY([idKind]) REFERENCES[dbo].[Kind]([Id]),FOREIGN KEY([idDish]) REFERENCES[dbo].[Dish]([Id])); "); data.ExecuteCommand("CREATE TABLE [dbo].[DrinkDetail] ([Id] INT IDENTITY(1, 1) NOT NULL,[availability] BIT NULL,[idSize] TINYINT NULL,[idKind] TINYINT NULL, [price] MONEY NULL,[tax] INT NULL,[idDrink] INT NOT NULL,PRIMARY KEY CLUSTERED([Id] ASC),FOREIGN KEY([idSize]) REFERENCES[dbo].[Size]([Id]),FOREIGN KEY([idKind]) REFERENCES[dbo].[Kind]([Id]), FOREIGN KEY([idDrink]) REFERENCES[dbo].[Drink]([Id])); "); data.ExecuteCommand("CREATE TABLE [dbo].[Order] ([Id] INT IDENTITY(1, 1) NOT NULL,[idStatus] TINYINT NULL,[idKind] TINYINT NULL,[startDateTime] DATETIME NULL,[endDateTime] DATETIME NULL,[idDescription] INT NULL,PRIMARY KEY CLUSTERED([Id] ASC), FOREIGN KEY([idDescription]) REFERENCES[dbo].[Description]([Id]),FOREIGN KEY([idKind]) REFERENCES[dbo].[Kind]([Id]),FOREIGN KEY([idStatus]) REFERENCES[dbo].[Status]([Id])); "); data.ExecuteCommand("CREATE TABLE [dbo].[OrderDish] ([Id] INT IDENTITY(1, 1) NOT NULL,[idOrder] INT NOT NULL,[idDishDetail] INT NOT NULL,PRIMARY KEY CLUSTERED([Id] ASC),FOREIGN KEY([idDishDetail]) REFERENCES[dbo].[DishDetail]([Id]),FOREIGN KEY([idOrder]) REFERENCES[dbo].[Order]([Id])); "); data.ExecuteCommand("CREATE TABLE [dbo].[OrderDrink] ([Id] INT IDENTITY(1, 1) NOT NULL,[idOrder] INT NOT NULL,[idDrinkDetail] INT NOT NULL,PRIMARY KEY CLUSTERED([Id] ASC),FOREIGN KEY([idDrinkDetail]) REFERENCES[dbo].[DrinkDetail]([Id]),FOREIGN KEY([idOrder]) REFERENCES[dbo].[Order]([Id])); "); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (1, N'Thin')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (2, N'Thick')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (3, N'Italian')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (11, N'Beer')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (12, N'Vodka')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (13, N'Wine')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (14, N'Ice Tea')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (15, N'Fizzy')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (16, N'Coffee')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (51, N'in Restaurant')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (52, N'Takeaway')"); data.ExecuteCommand("INSERT INTO [dbo].[Kind] ([Id], [text]) VALUES (53, N'Delivery')"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (1, N'Small', 26)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (2, N'Medium', 35)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (3, N'Large', 46)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (4, N'XLarge', 54)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (11, N'Tiny', 330)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (12, N'Small', 500)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (13, N'Medium', 750)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (14, N'Large', 1000)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (15, N'Big', 1500)"); data.ExecuteCommand("INSERT INTO [dbo].[Size] ([Id], [text], [value]) VALUES (16, N'XBig', 2000)"); data.ExecuteCommand("INSERT INTO [dbo].[Status] ([Id], [text]) VALUES (1, N'Open')"); data.ExecuteCommand("INSERT INTO [dbo].[Status] ([Id], [text]) VALUES (2, N'Close')"); data.ExecuteCommand("INSERT INTO [dbo].[Status] ([Id], [text]) VALUES (3, N'Canceled')"); data.ExecuteCommand("INSERT INTO [dbo].[Description] ([decription]) VALUES (N'Sos pomidorowy, Ser')"); data.ExecuteCommand("INSERT INTO [dbo].[Dish] ([name], [idDescription]) VALUES (N'Margarita', 1)"); data.ExecuteCommand("INSERT INTO [dbo].[DishDetail] ([availability], [idSize], [idKind], [price], [tax], [idDish]) VALUES (1,1,1,10,8,1)"); data.ExecuteCommand("INSERT INTO [dbo].[Description] ([decription]) VALUES (N'Sos pomidorowy, Ser, Ananas, Szynka')"); data.ExecuteCommand("INSERT INTO [dbo].[Dish] ([name], [idDescription]) VALUES (N'Neapoli', 2)"); data.ExecuteCommand("INSERT INTO [dbo].[DishDetail] ([availability], [idSize], [idKind], [price], [tax], [idDish]) VALUES (1,1,1,12,8,2)"); data.ExecuteCommand("INSERT INTO [dbo].[Description] ([decription]) VALUES (N'Prawie jak Cocacola')"); data.ExecuteCommand("INSERT INTO [dbo].[Drink] ([name], [idDescription]) VALUES (N'Pepsi', 3)"); data.ExecuteCommand("INSERT INTO [dbo].[DrinkDetail] ([availability], [idSize], [idKind], [price], [tax], [idDrink]) VALUES (1,11,15,5,26,1)"); data.ExecuteCommand("INSERT INTO [dbo].[Description] ([decription]) VALUES (N'Ty jestes pragnienie')"); data.ExecuteCommand("INSERT INTO [dbo].[Drink] ([name], [idDescription]) VALUES (N'Sprite', 4)"); data.ExecuteCommand("INSERT INTO [dbo].[DrinkDetail] ([availability], [idSize], [idKind], [price], [tax], [idDrink]) VALUES (1,11,15,6,26,2)"); formHandler.Refresh(); formHandler.loadBox(); this.Close(); }