Example #1
0
 //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
         {
         }
     }
 }
Example #2
0
        //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!!!");
            }
        }
Example #3
0
        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();
            }
        }
Example #4
0
        public void buy(string n, int q)
        {
            FileStream      fs = new FileStream("products.txt", FileMode.Open);
            BinaryFormatter f  = new BinaryFormatter();
            Dictionary <string, products> list = new Dictionary <string, products>();
            products p = new products();

            while (fs.Position < fs.Length)
            {
                p = (products)f.Deserialize(fs);
                if (p.name == n)
                {
                    p.quantity  -= q;
                    list[p.name] = p;
                }
                list[p.name] = p;
            }
            fs.Close();
            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();
        }
Example #5
0
        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);
            }
        }
        public override bool check(string x)
        {
            bool v = false;
            Dictionary <string, products> list = new Dictionary <string, products>();

            if (File.Exists("products.txt"))
            {
                FileStream      fst = new FileStream("products.txt", FileMode.Open);
                BinaryFormatter f   = new BinaryFormatter();
                while (fst.Position < fst.Length)
                {
                    products c = (products)f.Deserialize(fst);
                    list[c.name] = c;
                }
                fst.Close();
                if (list.ContainsKey(x))
                {
                    v = true;
                }
                list.Clear();
            }
            else
            {
                v = false;
            }
            return(v);
        }
Example #7
0
        //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");
            }
        }
Example #8
0
        //View Catalog
        private void button4_Click(object sender, EventArgs e)
        {
            FileStream      fss  = new FileStream("products.txt", FileMode.Open);
            BinaryFormatter ff   = new BinaryFormatter();
            List <products> list = new List <products>();

            list.Clear();
            while (fss.Position < fss.Length)
            {
                products p = (products)ff.Deserialize(fss);
                list.Add(p);
            }
            fss.Close();
            dataGridView7.DataSource = list;
        }
Example #9
0
        public float return_price_order(string n, int q)
        {
            FileStream      fs = new FileStream("products.txt", FileMode.Open);
            BinaryFormatter f  = new BinaryFormatter();
            products        p  = new products();

            while (fs.Position < fs.Length)
            {
                p = (products)f.Deserialize(fs);
                if (p.name == n)
                {
                    fs.Close();
                    return(p.price * q);
                }
            }
            fs.Close();
            return(-1);
        }
Example #10
0
        //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 !!");
            }
        }
Example #11
0
 public int check_quantity(string x)
 {
     if (File.Exists("products.txt"))
     {
         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 == x)
             {
                 fs.Close();
                 return(p.quantity);
             }
         }
         fs.Close();
         return(-1);
     }
     else
     {
         return(-1);
     }
 }
Example #12
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");
            }
        }
Example #13
0
        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);
            }
        }