Exemple #1
0
        //ADD ITEMS - STOCKS TO DATABASE //
        private void button3_Click(object sender, EventArgs e)
        {
            idtxt();
            ++cntr;
            dataGridView1.Visible = false;
            dataGridView4.Visible = false;
            dataGridView5.Visible = false;
            dataGridView6.Visible = false;
            dataGridView7.Visible = false;
            dataGridView8.Visible = false;
            // id.Text = null;


            switch (cntr)
            {
            case 1:
                name.Text  = null;
                type.Text  = null;
                brand.Text = null;
                price.Text = null;
                stock.Text = null;

                pictureBox1.Image   = null;
                name.Enabled        = true;
                type.Visible        = false;
                comboBox1.Visible   = true;
                brand.Visible       = false;
                brand.Enabled       = false;
                price.Enabled       = true;
                stock.Enabled       = true;
                type.Visible        = true;
                type.Enabled        = true;
                button1.Enabled     = false;
                button2.Enabled     = false;
                button4.Enabled     = true;
                pictureBox1.Visible = true;
                button3.Text        = "SAVE";
                break;

            default:


                if ((name.Text == "") || (comboBox1.Text == "") || (price.Text == "") || (stock.Text == ""))
                {
                    MessageBox.Show("Please Fill Up Informations!");
                }
                else
                {
                    String pname, ptype, pbrand, pqty, pprice,
                           pid = id.Text;
                    pname  = name.Text;
                    ptype  = comboBox1.Text;
                    pbrand = type.Text;
                    pqty   = stock.Text;
                    pprice = price.Text;



                    try
                    {
                        MemoryStream ms = new MemoryStream();
                        pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
                        byte[] img = ms.ToArray();


                        Random   rnd              = new Random();
                        int      dice             = rnd.Next(1, 7);
                        DateTime myDateTime       = DateTime.Now;
                        String   sqlFormattedDate = myDateTime.Date.ToString("yyyy-mm-dd");

                        DateTime dateTime = new DateTime();
                        dateTime = DateTime.Now;
                        DateTime newDateTime  = new DateTime();
                        TimeSpan NumberOfDays = new TimeSpan(dice, 0, 0, 0, 0);
                        newDateTime = dateTime.Add(NumberOfDays);
                        string nice = newDateTime.ToString();

                        connDB connect = new connDB();


                        int price1 = int.Parse(pqty) * int.Parse(pprice);
                        connect.additemsnew(pid, pname, ptype, pbrand, pqty, pprice, img);
                        connect.adddelivery(pid, pname, pbrand, ptype, pqty, price1.ToString(), this.dateTimePicker1.Text, nice);
                        MessageBox.Show("Product ID no: " + id.Text + " has been added");

                        name.Enabled        = false;
                        type.Enabled        = false;
                        brand.Enabled       = false;
                        price.Enabled       = false;
                        stock.Enabled       = false;
                        button1.Enabled     = true;
                        button2.Enabled     = true;
                        button3.Enabled     = true;
                        button4.Enabled     = true;
                        type.Visible        = true;
                        button4.Enabled     = false;
                        pictureBox1.Visible = false;
                        pictureBox1.Image   = null;
                        comboBox1.Visible   = false;
                        //status editor //

                        //---//
                        name.Text  = null;
                        type.Text  = null;
                        brand.Text = null;
                        price.Text = null;
                        stock.Text = null;
                        //
                        cntr = 0;
                        table1(); table2(); table3(); table4(); table5(); table6();
                        button3.Text = "Add Items";
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                break;
            } // end of switch
        }     //
Exemple #2
0
        // EDIT STOCK //
        private void button1_Click(object sender, EventArgs e)
        {
            ++cntr;

            switch (cntr)
            {
            case 1:
                name.Enabled      = true;
                type.Enabled      = true;
                comboBox1.Visible = true;
                brand.Enabled     = true;
                price.Enabled     = true;
                stock.Enabled     = true;
                type.Visible      = true;
                button2.Enabled   = false;
                button3.Enabled   = false;
                button4.Enabled   = true;
                button1.Text      = "SAVE";
                break;

            default:

                DialogResult dialogResult = MessageBox.Show("Do you Approve of this order?", "Approval ", MessageBoxButtons.YesNo);

                /*   if (int.Parse(loginfo.stock) < int.Parse(this.stock.Text))
                 * {
                 *     MessageBox.Show("you cannot lessen the current stocks");
                 * }*/

                if ((name.Text == "") || (type.Text == "") || (brand.Text == "") || (price.Text == "") || (stock.Text == ""))
                {
                    MessageBox.Show("Please Fill Up Informations!");
                }

                else if (dialogResult == DialogResult.Yes)
                {
                    String PID, PNAME, PTYPE, BRAND, PQTY, PPRICE;
                    PID    = id.Text;
                    PNAME  = name.Text;
                    PTYPE  = brand.Text;
                    BRAND  = type.Text;
                    PQTY   = stock.Text;
                    PPRICE = price.Text;


                    try
                    {
                        MemoryStream ms = new MemoryStream();
                        pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
                        byte[] img = ms.ToArray();



                        Random   rnd              = new Random();
                        int      dice             = rnd.Next(1, 7);
                        DateTime myDateTime       = DateTime.Now;
                        String   sqlFormattedDate = myDateTime.Date.ToString("yyyy-mm-dd");

                        DateTime dateTime = new DateTime();
                        dateTime = DateTime.Now;
                        DateTime newDateTime  = new DateTime();
                        TimeSpan NumberOfDays = new TimeSpan(dice, 0, 0, 0, 0);
                        newDateTime = dateTime.Add(NumberOfDays);
                        string nice   = newDateTime.ToString();
                        int    price1 = int.Parse(PQTY) * int.Parse(PPRICE);


                        connDB connect = new connDB();
                        connect.editIn(PID, PNAME, PTYPE, BRAND, PQTY, PPRICE, img);
                        connect.adddelivery(PID, PNAME, BRAND, PTYPE, PQTY, price1.ToString(), this.dateTimePicker1.Text, nice);
                        MessageBox.Show("Product ID no: " + id.Text + " has been updated");

                        name.Enabled        = false;
                        type.Enabled        = false;
                        brand.Enabled       = false;
                        price.Enabled       = false;
                        stock.Enabled       = false;
                        button2.Enabled     = true;
                        button3.Enabled     = true;
                        type.Visible        = true;
                        pictureBox1.Visible = false;
                        button4.Enabled     = false;
                        comboBox1.Visible   = false;
                        cntr = 0;
                        table1(); table2(); table3(); table4(); table5(); table6();
                        button1.Text = "UPDATE";
                    }

                    catch (System.NullReferenceException)
                    {
                        MessageBox.Show("Insert an image");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                if (dialogResult == DialogResult.No)
                {
                    String PID, PNAME, PTYPE, BRAND, PQTY, PPRICE, APPR;
                    PID          = id.Text;
                    PNAME        = name.Text;
                    PTYPE        = brand.Text;
                    BRAND        = type.Text;
                    PQTY         = stock.Text;
                    PPRICE       = price.Text;
                    APPR         = "Pending";
                    loginfo.pdid = PID;
                    int    price1  = int.Parse(PQTY) * int.Parse(PPRICE);
                    connDB connect = new connDB();
                    connect.pendingdelivery(int.Parse(PID), PNAME, PTYPE, BRAND, int.Parse(PQTY), price1, APPR);
                }

                break;
            }
        }