using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
string _pcode, _desc, _price;
double tot = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoadRecords();
}
private void LoadRecords()
{
dataGridView2.Rows.Add("P00001", "TAPSILOG", "42.00");
dataGridView2.Rows.Add("P00002", "LONGSILOG", "34.00");
dataGridView2.Rows.Add("P00003", "CORNSILOG", "41.00");
dataGridView2.Rows.Add("P00004", "HOTSILOG", "41.00");
dataGridView2.Rows.Add("P00005", "BANGSILOG", "41.00");
}
private void txtQty_TextChanged(object sender, EventArgs e)
{
try
{
double price = double.Parse(txtPrice.Text);
double qty = double.Parse(txtQty.Text);
double subtot = price * qty;
txtSubTotal.Text = subtot.ToString("#,##0.00");
}
catch (Exception)
{
txtQty.Text = "0";
}
}
private void btnOrder_Click(object sender, EventArgs e)
{
tot += double.Parse(txtSubTotal.Text);
dataGridView3.Rows.Add(txtPcode.Text, txtDesc.Text, txtPrice.Text, txtQty.Text, txtSubTotal.Text);
lblTotal.Text= tot.ToString("#,##0.00");
}
private void btnNew_Click(object sender, EventArgs e)
{
dataGridView3.Rows.Clear();
txtDesc.Clear();
txtPcode.Clear();
txtPrice.Text = "0";
txtQty.Text = "0";
tot = 0;
lblTotal.Text = tot.ToString("#,##0.00");
}
private void dataGridView2_SelectionChanged(object sender, EventArgs e)
{
int i = dataGridView2.CurrentRow.Index;
_pcode = dataGridView2[0, i].Value.ToString();
_desc = dataGridView2[1, i].Value.ToString();
_price = dataGridView2[2, i].Value.ToString();
}
private void dataGridView2_Click(object sender, EventArgs e)
{
txtPcode.Text = _pcode;
txtDesc.Text = _desc;
txtPrice.Text = _price;
}
}
}
Programming Language: C#
IDE: Visual Studio 2010
Download Link: