//Bills private void button1_Click_1(object sender, EventArgs e) { if (File.Exists("bills.txt")) { FileStream fs = new FileStream("bills.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); List <orders> list = new List <orders>(); while (fs.Position < fs.Length) { orders o = (orders)f.Deserialize(fs); list.Add(o); } fs.Close(); dataGridView5.DataSource = list; } }
public int return_id() { if (File.Exists("bills.txt")) { List <orders> list = new List <orders>(); FileStream fs = new FileStream("bills.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); while (fs.Position < fs.Length) { orders o = (orders)f.Deserialize(fs); list.Add(o); } fs.Close(); return(list.Count); } else { return(0); } }
//My Bills private void button3_Click(object sender, EventArgs e) { if (File.Exists("bills.txt")) { FileStream fs = new FileStream("bills.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); List <orders> list = new List <orders>(); List <string> l = new List <string>(); while (fs.Position < fs.Length) { orders o = (orders)f.Deserialize(fs); if (o.e_mail == sign_in.t1) { list.Add(o); } } DataTable p_table = new DataTable(); p_table.Columns.Add("Bill ID"); p_table.Columns.Add("Prouduct Name"); p_table.Columns.Add("Quantity"); DataRow pp; for (int ss = 0; ss < list.Count; ss++) { for (int cc = 0; cc < list[ss].products.Count; cc++) { pp = p_table.NewRow(); pp["Bill ID"] = list[ss].id; pp["Prouduct Name"] = list[ss].products.ElementAt(cc).Key; pp["Quantity"] = list[ss].products.ElementAt(cc).Value; p_table.Rows.Add(pp); } } dataGridView3.DataSource = p_table; fs.Close(); dataGridView2.DataSource = list; } }
//Make Order btn private void button2_Click(object sender, EventArgs e) { try { if (dataGridView1.Rows[0].Cells[0].Value == null || dataGridView1.Rows[0].Cells[1].Value == null) { MessageBox.Show("error !!"); } else { dliveryboy boy = new dliveryboy(); products p = new products(); List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >(); float total = 0; DateTime t = DateTime.Now; bool flag = false; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (p.check(dataGridView1.Rows[i].Cells[0].Value.ToString()) && int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) <= p.check_quantity(dataGridView1.Rows[i].Cells[0].Value.ToString())) { flag = true; } else { flag = false; } } if (boy.assgin() == null) { MessageBox.Show("Please wait few minutes to make order"); } else { bool ff = true; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) <= 0) { MessageBox.Show("falid quantity in row " + ++i); ff = false; } } if (ff) { for (int j = 0; j < dataGridView1.Rows.Count - 1; j++) { if (flag) { p.buy(dataGridView1.Rows[j].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[j].Cells[1].Value.ToString())); total += p.return_price_order(dataGridView1.Rows[j].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[j].Cells[1].Value.ToString())); list.Add(new KeyValuePair <string, int>(dataGridView1.Rows[j].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[j].Cells[1].Value.ToString()))); MessageBox.Show("done & total= " + total); } else { MessageBox.Show("invalid name or quantity !!"); } } if (flag) { total += 5; orders order = new orders(sign_in.t1, t, list, total, boy.assgin()); order.bill(order); } } } } } catch { MessageBox.Show("invalid enter"); } }
public string return_product(int bill_id, string product, int quantity) { string return_message; if (File.Exists("bills.txt")) { FileStream fs = new FileStream("bills.txt", FileMode.Open); BinaryFormatter f = new BinaryFormatter(); Dictionary <int, orders> list = new Dictionary <int, orders>(); KeyValuePair <string, int> li = new KeyValuePair <string, int>(); // bool falg = false; DateTime n = DateTime.Now; while (fs.Position < fs.Length) { orders o = (orders)f.Deserialize(fs); list[o.id] = o; } fs.Close(); if (list.ContainsKey(bill_id)) { if (list[bill_id].date.Day - n.Day <= 14) { for (int i = 0; i < list[bill_id].products.Count; i++) { if (list[bill_id].products.ElementAt(i).Key == product) { if (list[bill_id].products.ElementAt(i).Value >= quantity && quantity != 0) { if (list[bill_id].products.ElementAt(i).Value == quantity) { li = new KeyValuePair <string, int>(product, quantity); list[bill_id].products.Remove(li); products p = new products(); list[bill_id].total -= p.return_price(product) * quantity; if (list[bill_id].products.Count == 0) { list.Remove(bill_id); } FileStream format = new FileStream("bills.txt", FileMode.Truncate); format.Close(); FileStream file = new FileStream("bills.txt", FileMode.Append); for (int j = 0; j < list.Count; j++) { f.Serialize(file, list.ElementAt(j).Value); } file.Close(); list.Clear(); p.update_product(product, quantity, 0); return_message = "done"; list.Clear(); return(return_message); } else { int x = 0; x = list[bill_id].products.ElementAt(i).Value - quantity; li = new KeyValuePair <string, int>(product, list[bill_id].products.ElementAt(i).Value); list[bill_id].products.Remove(li); li = new KeyValuePair <string, int>(product, x); list[bill_id].products.Add(li); products p = new products(); list[bill_id].total -= p.return_price(product) * quantity; if (list[bill_id].products.Count == 0) { list.Remove(bill_id); } FileStream format = new FileStream("bills.txt", FileMode.Truncate); format.Close(); FileStream file = new FileStream("bills.txt", FileMode.Append); for (int j = 0; j < list.Count; j++) { f.Serialize(file, list.ElementAt(j).Value); } file.Close(); list.Clear(); return_message = "done"; p.update_product(product, quantity, 0); list.Clear(); return(return_message); } } else { return_message = "invalid quantity"; return(return_message); } } } return_message = "product not found"; return(return_message); } else { return_message = "over 14 day"; return(return_message); } } else { return_message = "invalid bill"; return(return_message); } } else { return_message = "invalid bill"; return(return_message); } }