Example #1
0
        private void button15_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);

            if (dataGridView1.RowCount == 0)
            {
                ActiveControl = txtBoxDescription; // focus on Description textbox
                dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control
                txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control
                txtBoxDescription.Select(txtBoxDescription.Text.Length, 0);   //move cursor into the end of text in the textbox
            }
            else
            {

                dataGridView1.Rows[0].Selected = true;
                dataGridView1.CurrentCell = dataGridView1[0, 0];
                ActiveControl = txtBoxDescription; // focus on Description textbox
                dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control
                txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control
                txtBoxDescription.Select(txtBoxDescription.Text.Length, 0);   //move cursor into the end of text in the textbox
            }
            BillGeneration bg = new BillGeneration();
            bg.total(this);

        }
Example #2
0
        //------------------------------------------------------------------------------------------------------------------------------------------------------------------
        public void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {

                string keyVal;


                keyVal = e.KeyValue.ToString();


                if (int.Parse(keyVal) == 40)
                {
                    if (dataGridView1.RowCount != 0 || dataGridView1.RowCount != 1)
                    {
                        KeyPressEvent kpe = new KeyPressEvent();
                        kpe.downArrow("bf", "dgv", this); //mb=ManualBilling, dgv=DataGridView

                    }

                }
                else if (int.Parse(keyVal) == 38)
                {
                    KeyPressEvent kpe = new KeyPressEvent();

                    kpe.upArrow("bf", "dgv", this);
                }
                else if (int.Parse(keyVal) == 13)
                {
                    KeyPressEvent kpe = new KeyPressEvent();
                    kpe.enterButton("bf", "dgv", this);

                }
                else if (int.Parse(keyVal) == 27)
                {
                    dataGridView1.Rows[0].Selected = true;
                    dataGridView1.CurrentCell = dataGridView1[0, 0];
                    ActiveControl = txtBoxDescription; // focus on Description textbox
                    dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control
                    txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control
                    txtBoxDescription.Select(txtBoxDescription.Text.Length, 0);   //move cursor into the end of text in the textbox

                }
                else if (int.Parse(keyVal) == 46)
                {
                    dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);

                    if (dataGridView1.RowCount == 0)
                    {
                        ActiveControl = txtBoxDescription; // focus on Description textbox
                        dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control
                        txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control
                        txtBoxDescription.Select(txtBoxDescription.Text.Length, 0);   //move cursor into the end of text in the textbox
                    }
                    else
                    {

                        dataGridView1.Rows[0].Selected = true;
                        dataGridView1.CurrentCell = dataGridView1[0, 0];
                        ActiveControl = txtBoxDescription; // focus on Description textbox
                        dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control
                        txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control
                        txtBoxDescription.Select(txtBoxDescription.Text.Length, 0);   //move cursor into the end of text in the textbox
                    }
                    BillGeneration bg = new BillGeneration();
                    bg.total(this);
                }
                else
                {
                    if (int.Parse(keyVal) < 65 && int.Parse(keyVal) > 105 && int.Parse(keyVal) != 32)
                    {

                        SystemSounds.Hand.Play();
                    }

                }
            }

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

            }

        }
Example #3
0
        //--------------endOfUpArrow Function---------------------------------------------------------------------------------------------------------------------------



        //--------------startOfEnter Function---------------------------------------------------------------------------------------------------------------------------
        public void enterButton(string form, string focus, object obj, object formobj = null)
        {
            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[2].Value;
                        decimal l_price = (decimal)mb.dataGridView1.Rows[row].Cells[3].Value;
                        decimal disc    = (decimal)mb.dataGridView1.Rows[row].Cells[4].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);

                    BillGeneration bg = new BillGeneration();
                    bg.total(bf);
                }


                if (form == "bf" && focus == "des")
                {
                    Billingform bf = (Billingform)obj;
                    if (bf.dataGridView1.RowCount != 0)
                    {
                        bf.ActiveControl = bf.textBox3;
                    }
                    else
                    {
                        SystemSounds.Hand.Play();
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
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();
            }
        }
        //--------------endOfUpArrow Function---------------------------------------------------------------------------------------------------------------------------










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

            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[2].Value;
                        decimal l_price = (decimal)mb.dataGridView1.Rows[row].Cells[3].Value;
                        decimal disc = (decimal)mb.dataGridView1.Rows[row].Cells[4].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);

                    BillGeneration bg = new BillGeneration();
                    bg.total(bf);


                }


                if (form == "bf" && focus == "des")
                {
                    Billingform bf = (Billingform)obj;
                    if (bf.dataGridView1.RowCount != 0)
                    {

                        bf.ActiveControl = bf.textBox3;
                    }
                    else
                    {
                        SystemSounds.Hand.Play();
                    }

                }




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

            }




        }