public bool check_sign_in(string x, string y) { bool v = false; context con = new context(new check_customer()); Dictionary <string, customer> list = new Dictionary <string, customer>(); if (con.my_function(x)) { FileStream fst = new FileStream("customer.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); customer c = new customer(); while (fst.Position < fst.Length) { c = (customer)f.Deserialize(fst); if (c.e_mail == x && c.password == y) { v = true; } } fst.Close(); } else { v = false; } return(v); }
//Add product private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView1.Rows[0].Cells[0].Value == null || dataGridView1.Rows[0].Cells[1].Value == null || dataGridView1.Rows[0].Cells[2].Value == null) { MessageBox.Show("Each field mandatory!"); } else { context con = new context(new check_product()); if (con.my_function(dataGridView1.Rows[0].Cells[0].Value.ToString())) { MessageBox.Show("This product stored !"); } else { products p = new products(dataGridView1.Rows[0].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString()), int.Parse(dataGridView1.Rows[0].Cells[2].Value.ToString())); FileStream fs = new FileStream("products.txt", FileMode.Append); BinaryFormatter f = new BinaryFormatter(); f.Serialize(fs, p); fs.Close(); MessageBox.Show("added"); dataGridView1.Rows.Clear(); } } } catch { MessageBox.Show("invalid enter!!!"); } }
//Add employee private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView4.Rows[0].Cells[0].Value == null || dataGridView4.Rows[0].Cells[1].Value == null || dataGridView4.Rows[0].Cells[2].Value == null || dataGridView4.Rows[0].Cells[3].Value == null || dataGridView4.Rows[0].Cells[4].Value == null || dataGridView4.Rows[0].Cells[5].Value == null || dataGridView4.Rows[0].Cells[6].Value == null || dataGridView4.Rows[0].Cells[7].Value == null) { MessageBox.Show("Each field mandatory!"); } else { if (dataGridView4.Rows[0].Cells[0].Value.ToString() == "delivery boy") { context con = new context(new check_boy()); if (con.my_function(dataGridView4.Rows[0].Cells[1].Value.ToString())) { MessageBox.Show("This employee is exisit !"); } else { dliveryboy d = new dliveryboy(); d.add(dataGridView4.Rows[0].Cells[2].Value.ToString(), int.Parse(dataGridView4.Rows[0].Cells[6].Value.ToString()), dataGridView4.Rows[0].Cells[4].Value.ToString(), dataGridView4.Rows[0].Cells[5].Value.ToString(), dataGridView4.Rows[0].Cells[1].Value.ToString(), double.Parse(dataGridView4.Rows[0].Cells[7].Value.ToString()), dataGridView4.Rows[0].Cells[3].Value.ToString()); MessageBox.Show("added"); dataGridView4.Rows.Clear(); } } } } catch { MessageBox.Show("invalid enter !!"); } }
//Update product private void button3_Click(object sender, EventArgs e) { if (textBox2.Text.Length == 0 || textBox3.Text.Length == 0 || comboBox1.Text.Length == 0) { MessageBox.Show("invalid enter !"); } else { products p = new products(); context c = new context(new check_product()); if (c.my_function(textBox2.Text) && int.Parse(textBox3.Text) != 0) { if (comboBox1.Text == "NOT CHANGE") { p.update_product(textBox2.Text, int.Parse(textBox3.Text), 0); MessageBox.Show("Done"); } else { p.update_product(textBox2.Text, int.Parse(textBox3.Text), int.Parse(comboBox1.Text)); MessageBox.Show("Done"); } } else { } } }
public void update_product(string n, int q, int p) { context c = new context(new check_product()); if (c.my_function(n)) { FileStream fs = new FileStream("products.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); Dictionary <string, products> list = new Dictionary <string, products>(); while (fs.Position < fs.Length) { products pr = (products)f.Deserialize(fs); list[pr.name] = pr; } fs.Close(); if (p == 0) { list[n].quantity += q; } else { list[n].price = p; list[n].quantity += q; } FileStream formatt = new FileStream("products.txt", FileMode.Truncate); formatt.Close(); FileStream file = new FileStream("products.txt", FileMode.Append); for (int i = 0; i < list.Count; i++) { f.Serialize(file, list.ElementAt(i).Value); } file.Close(); } }
public float return_price(string product) { context c = new context(new check_product()); float y = 0; if (c.my_function(product)) { FileStream fs = new FileStream("products.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); while (fs.Position < fs.Length) { products p = (products)f.Deserialize(fs); if (p.name == product) { y = p.price; } } fs.Close(); return(y); } else { return(y); } }
//Delete employee private void Delete_Emp_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (Delete_Emp.Rows[0].Cells[0].Value == null || Delete_Emp.Rows[0].Cells[1].Value == null) { MessageBox.Show("Enter employee data !"); } else { if (Delete_Emp.Rows[0].Cells[0].Value.ToString() == "delivery boy") { context con = new context(new check_boy()); if (con.my_function(Delete_Emp.Rows[0].Cells[1].Value.ToString()) == false) { MessageBox.Show("This employee not found !"); } else { dliveryboy p = new dliveryboy(); FileStream fs = new FileStream("dliveryboy.txt", FileMode.Open); BinaryFormatter formatt = new BinaryFormatter(); Dictionary <string, dliveryboy> old = new Dictionary <string, dliveryboy>(); while (fs.Position < fs.Length) { p = (dliveryboy)formatt.Deserialize(fs); old[p.id] = p; } fs.Close(); old.Remove(Delete_Emp.Rows[0].Cells[1].Value.ToString()); FileStream fille = new FileStream("dliveryboy.txt", FileMode.Truncate); fille.Close(); FileStream file = new FileStream("dliveryboy.txt", FileMode.Append); for (int i = 0; i < old.Count; i++) { formatt.Serialize(file, old.ElementAt(i).Value); } old.Clear(); file.Close(); MessageBox.Show("deleted"); Delete_Emp.Rows.Clear(); } } } } catch { MessageBox.Show("invalid enter !!"); } }
//Delete Product private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView2.Rows[0].Cells[0].Value == null) { MessageBox.Show("Enter Product Name !"); } else { context con = new context(new check_product()); if (con.my_function(dataGridView2.Rows[0].Cells[0].Value.ToString()) == false) { MessageBox.Show("This product not stored !"); } else { //products p = new products(); FileStream fs = new FileStream("products.txt", FileMode.Open); BinaryFormatter formatt = new BinaryFormatter(); Dictionary <string, products> old = new Dictionary <string, products>(); while (fs.Position < fs.Length) { products p = (products)formatt.Deserialize(fs); old[p.name] = p; } fs.Close(); old.Remove(dataGridView2.Rows[0].Cells[0].Value.ToString()); FileStream fille = new FileStream("products.txt", FileMode.Truncate); fille.Close(); FileStream file = new FileStream("products.txt", FileMode.Append); for (int i = 0; i < old.Count; i++) { formatt.Serialize(file, old.ElementAt(i).Value); } old.Clear(); file.Close(); MessageBox.Show("deleted"); dataGridView2.Rows.Clear(); } } } catch { MessageBox.Show("invalid enter"); } }
//Sign Up private void button2_Click(object sender, EventArgs e) { if (textBox4.Text.Length == 0 || textBox3.Text.Length == 0 || textBox5.Text.Length == 0 || textBox6.Text.Length == 0 || textBox7.Text.Length == 0 || comboBox1.Text.Length == 0 || comboBox2.Text.Length == 0 || comboBox3.Text.Length == 0 || comboBox4.Text.Length == 0) { MessageBox.Show("Each field is nesseccary !"); } else { context con = new context(new check_customer()); customer c = new customer(); if (con.my_function(textBox3.Text)) { MessageBox.Show("This email is already exisit !"); } else { if (comboBox4.Text == "male" || comboBox4.Text == "female") { DateTime d = new DateTime(int.Parse(comboBox1.Text), int.Parse(comboBox2.Text), int.Parse(comboBox3.Text)); DateTime to = DateTime.Today; c.age = to.Year - d.Year; c.name = textBox4.Text; c.e_mail = textBox3.Text; c.password = textBox7.Text; c.sex = comboBox4.Text; c.address = textBox5.Text; c.phone = textBox6.Text; c.add(c); t1 = c.name; MessageBox.Show(" done "); menu f = new menu(c.name, c.e_mail); this.Hide(); f.ShowDialog(); } else { MessageBox.Show("invalid sex!!"); } } } }
//Check Quantity private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView3.Rows[0].Cells[0].Value == null) { MessageBox.Show("Enter Product Name !"); } else { context con = new context(new check_product()); if (con.my_function(dataGridView3.Rows[0].Cells[0].Value.ToString()) == false) { MessageBox.Show("This product not stored !"); } else { FileStream fs = new FileStream("products.txt", FileMode.Open); BinaryFormatter formatt = new BinaryFormatter(); while (fs.Position < fs.Length) { products p = (products)formatt.Deserialize(fs); if (p.name == dataGridView3.Rows[0].Cells[0].Value.ToString()) { MessageBox.Show("Quantity = " + p.quantity); } } fs.Close(); dataGridView3.Rows.Clear(); } } } catch { MessageBox.Show("invalid enter !!"); } }