示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int intPerProductCost = Convert.ToInt16(txtPerProductCost.Text);
            int intQty            = Convert.ToInt16(txtqty.Text);
            int intDiscount       = Convert.ToInt16(txtDiscount.Text);

            clsProduct             objProduct             = new clsProduct();
            clsProductWithDiscount objProductWithDiscount = new clsProductWithDiscount();


            if (txtDiscount.Text.Length != 0)
            {
                txtTotalCost.Text = Convert.ToString(objProductWithDiscount.getTotalCost(intQty, intPerProductCost, intDiscount));
            }
            else
            {
                txtTotalCost.Text = Convert.ToString(objProduct.getTotalCost(intQty, intPerProductCost));
            }
        }
示例#2
0
        private void btnCalculateByDynamic_Click(object sender, EventArgs e)
        {
            clsProduct objProduct;

            int intPerProductCost = Convert.ToInt16(txtPerProductCost.Text);
            int intQty            = Convert.ToInt16(txtqty.Text);
            int intDiscount       = Convert.ToInt16(txtDiscount.Text);

            if (intDiscount == 0)
            {
                objProduct = new clsProduct();
                MessageBox.Show(objProduct.getTotalCost(intQty, intPerProductCost, "INR").ToString());
            }
            else
            {
                objProduct = new clsProductWithDiscount();
                MessageBox.Show(objProduct.getTotalCost(intQty, intPerProductCost, "INR").ToString());
            }
        }
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }

            int intProductQty     = 0;
            int intProductPerCost = 0;

            if (dataGridView1.Rows[e.RowIndex].Cells[1].Value != null)
            {
                intProductQty = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[2].Value != null)
            {
                intProductPerCost = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());
            }

            // Functional
            //dataGridView1.Rows[e.RowIndex].Cells[3].Value = Convert.ToString(CalculateCost(intProductPerCost,intProductQty));

            // Object oriented
            clsProduct objProduct = new clsProduct();

            clsProductWithDiscount objProduct1 = new clsProductWithDiscount();

            objProduct1.getTotalCost(20, 3);
            objProduct1.getTotalCost(20, 3, 10);



            dataGridView1.Rows[e.RowIndex].Cells[3].Value = Convert.ToString(objProduct.getTotalCost(intProductPerCost, intProductQty));
            int intDiscount = Convert.ToInt16(txtDiscount.Text);

            dataGridView1.Rows[e.RowIndex].Cells[4].Value = Convert.ToString(objProduct1.getTotalCost(intProductPerCost, intProductQty, intDiscount));
        }