Exemple #1
0
        //DataTable dbtable;
        private void button10_Click(object sender, EventArgs e)
        {

            if ((txtBoxCode.Text == "") || (txtBoxDescription.Text == "") || (txtBoxDiscount.Text == "") || (textBox2.Text == "") || (textBox8.Text == "") || (txtBoxOther.Text == ""))
            {
                MessageBox.Show("All the fields must be Filled");
            }
            else
            {
                int textboxCode = int.Parse(txtBoxCode.Text);
                string txtboxDescription = txtBoxDescription.Text;
                decimal txtboxDiscount = decimal.Parse(txtBoxDiscount.Text);
                decimal lowestPrice = decimal.Parse(textBox2.Text);
                decimal price = decimal.Parse(textBox8.Text);
                string txtboxOther = txtBoxOther.Text;

                ItemDBConnection adminDb = new ItemDBConnection();


                adminDb.Insert(textboxCode, txtboxDescription, txtboxDiscount, lowestPrice, price, txtboxOther);
                clearItem();

            }

        }
Exemple #2
0
        private void button15_Click(object sender, EventArgs e)
        {
            if ((txtBoxCode.Text == "") || (txtBoxDescription.Text == "") || (txtBoxDiscount.Text == "") || (textBox2.Text == "") || (textBox8.Text == "") || (txtBoxOther.Text == ""))
            {
                MessageBox.Show("All the fields must be Filled");
            }
            else
            {
                int textboxCode = int.Parse(txtBoxCode.Text);

                ItemDBConnection itemdel = new ItemDBConnection();

                itemdel.Delete(textboxCode);
                clearItem();
            }
        }
Exemple #3
0
        //--------------endOfUpArrow Function---------------------------------------------------------------------------------------------------------------------------



        //--------------startOfEnter Function---------------------------------------------------------------------------------------------------------------------------
        public void enterButton(string form, string focus, object obj, object formobj = null)
        {
            DBConnection db = new DBConnection();

            try
            {
                if (form == "mb" && focus == "dgv")
                {
                    ManualBilling mb  = (ManualBilling)obj;
                    Billingform   bf  = (Billingform)formobj;
                    int           row = mb.dataGridView1.CurrentCell.RowIndex;


                    if (mb.dataGridView1.RowCount != 0)
                    {
                        int     code    = (int)mb.dataGridView1.Rows[row].Cells[0].Value;
                        string  des     = mb.dataGridView1.Rows[row].Cells[1].Value.ToString();
                        decimal price   = (decimal)mb.dataGridView1.Rows[row].Cells[4].Value;
                        decimal l_price = (decimal)mb.dataGridView1.Rows[row].Cells[5].Value;
                        decimal disc    = (decimal)mb.dataGridView1.Rows[row].Cells[6].Value;;
                        //string other = mb.dataGridView1.Rows[row].Cells[5].Value.ToString();



                        bf.txtBoxCode.Text        = code.ToString();
                        bf.txtBoxDescription.Text = des;
                        bf.textBox8.Text          = price.ToString();
                        bf.txtBoxDiscount.Text    = disc.ToString();
                        mb.Close();
                        bf.ActiveControl = bf.textBox2;
                    }
                }

                if (form == "bf" && focus == "qty")
                {
                    Billingform bf = (Billingform)obj;

                    string  code = bf.txtBoxCode.Text;
                    string  des  = bf.txtBoxDescription.Text;
                    decimal price;
                    Decimal.TryParse(bf.textBox8.Text, out price);
                    decimal disc;
                    Decimal.TryParse(bf.txtBoxDiscount.Text, out disc);
                    decimal qty;
                    Decimal.TryParse(bf.textBox2.Text, out qty);
                    decimal tot = 0.00m;

                    if (qty == 0)
                    {
                        qty = 1;
                    }

                    if (disc == 0)
                    {
                        tot = (price * qty);
                    }

                    else
                    {
                        decimal newprice;
                        newprice = (price - ((price / 100) * disc));
                        tot      = (newprice * qty);
                    }



                    Decimal.TryParse((tot.ToString().Substring(0, tot.ToString().Length)), out tot);

                    Decimal total;
                    Decimal.TryParse(bf.label7.Text, out total);

                    tot = Math.Round(tot, 2);


                    bf.dataGridView1.Rows.Add(bf.dataGridView1.RowCount + 1, code, des, qty, disc, price, tot);

                    //reduce qty
                    if (db.OpenConnection() == true)
                    {
                        int              quantity = 0;
                        string           query1   = "SELECT Quantity FROM items WHERE Item_Code=" + code + "";
                        MySqlCommand     cmd      = new MySqlCommand(query1, db.connection);
                        MySqlDataAdapter adapter  = new MySqlDataAdapter(cmd);
                        DataTable        table    = new DataTable();
                        adapter.Fill(table);
                        quantity = int.Parse(table.Rows[0].ItemArray[0].ToString());

                        if (quantity > int.Parse(qty.ToString()))
                        {
                            quantity = quantity - int.Parse(qty.ToString());

                            string       query2 = "UPDATE items SET Quantity=" + quantity + " WHERE Item_Code=" + code + "";
                            MySqlCommand cmd1   = new MySqlCommand(query2, db.connection);
                            cmd1.ExecuteNonQuery();

                            ItemDBConnection idc = new ItemDBConnection();
                            idc.reorder(code, quantity);

                            BillGeneration bg = new BillGeneration();
                            bg.total(bf);
                        }
                        else
                        {
                            MessageBox.Show("According to Database Stocks in hand is lesser than the Quantity that you going to purchuase", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            bf.dataGridView1.Rows.RemoveAt(bf.dataGridView1.RowCount - 1);

                            bf.txtBoxCode.Text        = "";
                            bf.txtBoxDescription.Text = "";
                            bf.textBox8.Text          = "";
                            bf.textBox2.Text          = "";
                            bf.txtBoxDiscount.Text    = "";
                            bf.ActiveControl          = bf.txtBoxDescription;
                        }
                    }
                }


                if (form == "bf" && focus == "des")
                {
                    Billingform bf = (Billingform)obj;
                    if (bf.dataGridView1.RowCount != 0)
                    {
                        bf.ActiveControl = bf.textBox3;
                    }
                    else
                    {
                        SystemSounds.Hand.Play();
                    }
                }


                if (form == "bf" && focus == "dgv")
                {
                    Form6 newform = new Form6(obj);

                    newform.Show();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.CloseConnection();
            }
        }