Esempio n. 1
0
        private void Billingform_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.textBox2.KeyDown += new KeyEventHandler(textBox2_KeyDown);
            this.textBox3.KeyDown += new KeyEventHandler(textBox3_KeyDown);
            this.txtBoxDescription.KeyDown += new KeyEventHandler(txtBoxDescription_KeyDown);
            this.txtBoxCode.KeyDown += new KeyEventHandler(txtBoxCode_KeyDown);
            this.dataGridView1.KeyDown += new KeyEventHandler(dataGridView1_KeyDown);



            this.ActiveControl = txtBoxCode;
            //this.ActiveControl = txtBoxDescription; //focus on Description textbox
            BillGeneration bf = new BillGeneration();
            textBox1.Text = bf.BillNoGen(this).ToString(); //call to BillNoGen function


            timer1 = new Timer();
            timer1.Interval = 1000;
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Start(); //initialize timer


            label16.Text = user_name;





        }
Esempio n. 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);

            }

        }
Esempio n. 3
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);

        }
Esempio n. 4
0
        //------------------------------------------------------------------------------------------------------------------------------------------------------------------
        public void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            string keyVal = e.KeyValue.ToString();

            if (int.Parse(keyVal) == 13 && textBox3.Text != "")
            {
                decimal tot;
                decimal cash;
                Decimal.TryParse(textBox3.Text, out cash);
                Decimal.TryParse(label7.Text, out tot);
                if (cash < tot)
                {
                    MessageBox.Show("Cash value is lesser than Total Invoice amount", "Alert!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    label14.Text = (cash - tot).ToString();
                }

                //call print function
                //if (PrintClass.printfunction())
                //{
                BillGeneration bg = new BillGeneration();
                bg.billToDB(this);
                //}

            }
            else if (int.Parse(keyVal) == 110) //validate dot---------------------------------------------------------------
            {
                string dot = ".";

                textBox3.Text = textBox3.Text + dot;
                textBox3.Select(textBox3.Text.Length, 0);
            }

            else if (int.Parse(keyVal) == 8) //validate BackSpace---------------------------------------------------------------
            {
                if (textBox3.Text.Length > 0) //check is there any text in the textbox
                {
                    string text = textBox3.Text;
                    text = text.Substring(0, text.Length - 1); //remove last character from the text of the textbox
                    textBox3.Text = text;
                    textBox3.Select(textBox3.Text.Length, 0); //move cursor into the end of text in the textbox

                }
                else
                {

                    SystemSounds.Hand.Play();
                }




            }

            else if (int.Parse(keyVal) > 95 && int.Parse(keyVal) < 106)
            {
                string num = e.KeyCode.ToString();
                num = num.Substring(6, num.Length - 6);
                textBox3.Text = textBox3.Text + num;
                textBox3.Select(textBox3.Text.Length, 0);
            }
            else if (int.Parse(keyVal) == 27)
            {
                this.ActiveControl = txtBoxDescription;
                textBox3.Text = "";
            }

            else
            {
                SystemSounds.Hand.Play();
            }


        }
Esempio n. 5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------


        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                BillGeneration bf = new BillGeneration();
                label9.Text = bf.Date(this).ToString() + " "; //call to Date function
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
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);
            }
        }
        //--------------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);

            }




        }