Example #1
0
        //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 !!");
            }
        }
Example #2
0
        public override bool check(string x)
        {
            bool v = false;

            Dictionary <string, dliveryboy> list = new Dictionary <string, dliveryboy>();

            if (File.Exists("dliveryboy.txt"))
            {
                FileStream fst = new FileStream("dliveryboy.txt", FileMode.Open);

                BinaryFormatter f = new BinaryFormatter();

                dliveryboy c = new dliveryboy();

                while (fst.Position < fst.Length)
                {
                    c          = (dliveryboy)f.Deserialize(fst);
                    list[c.id] = c;
                }
                fst.Close();

                if (list.ContainsKey(x))
                {
                    v = true;
                }
                list.Clear();
            }
            else
            {
                v = false;
            }
            return(v);
        }
Example #3
0
        public void add_date(string n, DateTime d)
        {
            FileStream      fs = new FileStream("dliveryboy.txt", FileMode.Open);
            BinaryFormatter f  = new BinaryFormatter();
            Dictionary <string, dliveryboy> list = new Dictionary <string, dliveryboy>();

            while (fs.Position < fs.Length)
            {
                dliveryboy boy = (dliveryboy)f.Deserialize(fs);
                list[boy.name] = boy;
            }
            fs.Close();
            if (list[n].date1.Contains(d.ToString()))
            {
                list[n].date2.Add(d.ToString());
            }
            else
            {
                list[n].date1.Add(d.ToString());
            }
            FileStream formatt = new FileStream("dliveryboy.txt", FileMode.Truncate);

            formatt.Close();
            FileStream file = new FileStream("dliveryboy.txt", FileMode.Append);

            for (int i = 0; i < list.Count; i++)
            {
                f.Serialize(file, list.ElementAt(i).Value);
            }
            file.Close();
        }
Example #4
0
        public string assgin()
        {
            DateTime        da = DateTime.Now;
            FileStream      fs = new FileStream("dliveryboy.txt", FileMode.Open);
            BinaryFormatter f  = new BinaryFormatter();
            dliveryboy      d  = new dliveryboy();

            while (fs.Position < fs.Length)
            {
                d = (dliveryboy)f.Deserialize(fs);
                if (!d.date1.Contains(da.ToString()))
                {
                    fs.Close();
                    d.add_date(d.name, da);
                    return(d.name);
                }
                else if (!d.date2.Contains(da.ToString()))
                {
                    fs.Close();
                    d.add_date(d.name, da);
                    return(d.name);
                }
            }

            return(null);
        }
Example #5
0
        public override void add(string name, int age, string address, string phone, string id, double salary, string sex)
        {
            dliveryboy      d  = new dliveryboy(name, age, address, phone, id, salary, sex);
            FileStream      fs = new FileStream("dliveryboy.txt", FileMode.Append);
            BinaryFormatter f  = new BinaryFormatter();

            f.Serialize(fs, d);
            fs.Close();
        }
Example #6
0
        //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 !!");
            }
        }
Example #7
0
        //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");
            }
        }