private void CheckOutOrder_Btn_Click(object sender, EventArgs e) { using (var mdb = new MyModel()) { if (Admin_Checkbox.Checked == false) { var ct = (from item in mdb.Clients where item.Client_First_Name == Username_lbl.Text select item).FirstOrDefault(); G_Order.Client_ID = ct.Client_ID; Directory.CreateDirectory("D:/Test"); FileStream stream = new FileStream("D:/Test/MyFile.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write); StreamWriter writer = new StreamWriter(stream); writer.WriteLine("Order ID: " + G_Order.Order_ID); writer.WriteLine("Order Name: " + G_Order.Order_Name); writer.WriteLine("Order Date: " + G_Order.Order_Date); writer.WriteLine("Order Total Price: " + G_Order.Order_Price); writer.WriteLine("Client ID: " + G_Order.Client_ID); foreach (Products item in G_Order.Products) { writer.WriteLine(@" Product Made by: " + item.Product_Manufacturer + " \t" + " Product Name: " + item.Product_Name + " \t" + " Product Amount: " + item.Product_AmountToSell + " \t" + " Product Price: " + item.Product_Price); } var ppl = (from izem in mdb.Clients where izem.Client_First_Name == Username_lbl.Text select izem).FirstOrDefault(); ppl.Client_Money -= G_Order.Order_Price; G_Order.Order_Price = 0; mdb.SaveChanges(); writer.Close(); stream.Close(); } else { var at = (from item in mdb.Admins where item.Admin_First_Name == Username_lbl.Text select item).FirstOrDefault(); G_Order.Admin_ID = at.Admin_ID; Directory.CreateDirectory("D:/Test"); FileStream stream = new FileStream("D:/Test/MyFile.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write); StreamWriter writer = new StreamWriter(stream); writer.WriteLine("Order ID: " + G_Order.Order_ID); writer.WriteLine("Order Name: " + G_Order.Order_Name); writer.WriteLine("Order Date: " + G_Order.Order_Date); writer.WriteLine("Order Total Price: " + G_Order.Order_Price); writer.WriteLine("Client ID: " + G_Order.Admin_ID); foreach (Products item in G_Order.Products) { writer.Write(" Product Made by: " + item.Product_Manufacturer + " \t" + " Product Name: " + item.Product_Name + " \t" + " Product Amount: " + item.Product_AmountToSell + " \t" + " Product Price: " + item.Product_Price); } writer.WriteLine(); var ppl = (from izem in mdb.Admins where izem.Admin_First_Name == Username_lbl.Text select izem).FirstOrDefault(); ppl.Admin_Money -= G_Order.Order_Price; G_Order.Order_Price = 0; mdb.SaveChanges(); writer.Close(); stream.Close(); } } }
private void CreateProduct_Btn_Click(object sender, EventArgs e) { using (MyModel db = new MyModel()) { Products products = new Products(); products.SetProduct(ProductName_tbox.Text, ProductManuf_tbox.Text, Convert.ToDouble(ProductPrice_tbox.Text), Convert.ToInt32(ProductAmount_tbox.Text)); db.Products.Add(products); db.SaveChanges(); } }
private void CreateAdmin_Btn_Click(object sender, EventArgs e) { using (MyModel adb = new MyModel()) { string AFname = AdminFName_tbox.Text; string ALname = AdminLName_tbox.Text; string Aphone = AdminPhone_tbox.Text; string Aemail = AdminEmail_tbox.Text; string ABDate = AdminBDate_tbox.Text; string UcAlogin = AdminLogin_tbox.Text; string UcAPass = AdminPassword_tbox.Text; string Alogin = ""; string Apass = ""; if (ValidateLogin(UcAlogin, out UcAlogin) == true) { Alogin = UcAlogin; if (ValidatePassword(UcAPass, out UcAPass) == true) { Apass = UcAPass; MessageBox.Show("Admin Created!"); Close(); } else { MessageBox.Show("Error wrong password input"); } } else { MessageBox.Show("Error wrong login input"); } Admins NewAdmin = new Admins(); Login login = new Login(); NewAdmin.CreateAdmin(AFname, ALname, ABDate, Aphone, Aemail); login.SetLogin(Alogin, Apass, NewAdmin); NewAdmin.SetAdminLogin(login); adb.Logins.Add(login); adb.Admins.Add(NewAdmin); try { adb.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void CreateOrder_Btn_Click(object sender, EventArgs e) { using (var mdb = new MyModel()) { if (Admin_Checkbox.Checked == true) { var at = (from item in mdb.Admins where item.Admin_First_Name == Username_lbl.Text select item).FirstOrDefault(); Orders orders1 = new Orders(); orders1.CreateOrder(OrderName_tbox.Text, at, G_Prod); G_Order = orders1; mdb.Orders.Add(G_Order); mdb.SaveChanges(); } else { var ct = (from item in mdb.Clients where item.Client_First_Name == Username_lbl.Text select item).FirstOrDefault(); Orders orders2 = new Orders(); orders2.CreateOrder(OrderName_tbox.Text, ct, G_Prod); G_Order = orders2; mdb.Orders.Add(G_Order); mdb.SaveChanges(); } } }
private void AddProduct_Btn_Click(object sender, EventArgs e) { using (MyModel odb = new MyModel()) { Products_Dgv.CurrentCell.Selected = true; var ord = (from item in odb.Products where item.Product_ID == Products_Dgv.CurrentCell.RowIndex select item).FirstOrDefault(); if (ord != null) { ord.Product_AmountToSell = Convert.ToInt32(AddProducAmount_tbox.Text); ord.Product_Amount -= Convert.ToInt32(AddProducAmount_tbox.Text); G_Prod.Add(ord); odb.SaveChanges(); } } }
private void AddMoney_Btn_Click(object sender, EventArgs e) { using (MyModel db = new MyModel()) { var ar = (from user in db.Admins where user.Admin_First_Name == Username_lbl.Text select user).FirstOrDefault(); if (ar != null) { ar.Admin_Money += Convert.ToDouble(AddMoney_tbox.Text); } else { MessageBox.Show("Error no Data"); } db.SaveChanges(); } }
private void CreateClient_Btn_Click(object sender, EventArgs e) { using (MyModel adb = new MyModel()) { string CFname = ClientFName_tbox.Text; string CLname = ClientLName_tbox.Text; string Cphone = ClientPhone_tbox.Text; string Cemail = ClientEmail_tbox.Text; string CBDate = ClientBDate_tbox.Text; string UcClogin = ClientLogin_tbox.Text; string UcCPass = ClientPassword_tbox.Text; string Clogin = ""; string Cpass = ""; if (ValidateLogin(UcClogin, out UcClogin) == true) { Clogin = UcClogin; if (ValidatePassword(UcCPass, out UcCPass) == true) { Cpass = UcCPass; MessageBox.Show("Client Created!"); Close(); } else { MessageBox.Show("Error wrong password input"); } } else { MessageBox.Show("Error wrong login input"); } Clients NewClient = new Clients(); Login login = new Login(); NewClient.CreateClient(CFname, CLname, CBDate, Cphone, Cemail); login.SetLogin(Clogin, Cpass, NewClient); NewClient.SetClientLogin(login); adb.Logins.Add(login); adb.Clients.Add(NewClient); adb.SaveChanges(); } }
static void Main() { Database.SetInitializer(new DropCreateDatabaseAlways <MyModel>()); using (MyModel adb = new MyModel()) { Admins admins = new Admins(); Login login = new Login(); admins.CreateAdmin("Admintor", "RootAdmin", "02.03.2020", "+380555556399", "*****@*****.**"); login.SetLogin("Admin123", "pass1234", admins); admins.SetAdminLogin(login); adb.Logins.Add(login); adb.Admins.Add(admins); Clients clients = new Clients(); Login login1 = new Login(); clients.CreateClient("Client01", "Jugo", "20.02.2012", "+380223256477", "*****@*****.**"); login1.SetLogin("user1234", "pass9876", clients); clients.SetClientLogin(login1); adb.Logins.Add(login1); adb.Clients.Add(clients); Products products = new Products(); products.SetProduct("Engine", "Audi", 2500.00, 200); adb.Products.Add(products); Products products1 = new Products(); products1.SetProduct("Box", "Demo", 150.00, 500); adb.Products.Add(products1); Products products2 = new Products(); products2.SetProduct("Flames", "NOS", 500.00, 150); adb.Products.Add(products2); Orders orders = new Orders(); List <Products> Prod = new List <Products> { products, products1, products2 }; orders.CreateOrder("ForJugo", clients, Prod); adb.Orders.Add(orders); adb.SaveChanges(); Clients clients1 = new Clients(); Login login2 = new Login(); clients1.CreateClient("Client02", "Jugorasa", "20.02.2012", "+380223256477", "*****@*****.**"); login2.SetLogin("user6789", "pass6789", clients1); clients1.SetClientLogin(login2); adb.Logins.Add(login2); adb.Clients.Add(clients1); Products products3 = new Products(); products3.SetProduct("Enginesa", "Audisa", 25000.00, 300); adb.Products.Add(products3); Products products4 = new Products(); products4.SetProduct("Boxsa", "Demosa", 1500.00, 1500); adb.Products.Add(products4); Products products5 = new Products(); products5.SetProduct("Flamessa", "NOSsa", 700.00, 250); adb.Products.Add(products5); Orders orders1 = new Orders(); List <Products> Prod1 = new List <Products> { products3, products4, products5 }; orders1.CreateOrder("ForJugo2sa", clients1, Prod1); adb.Orders.Add(orders1); adb.SaveChanges(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); }