Mini Cashiering System Using C#

Submitted by: 
Language: 
Visitors have accessed this post 880 times.

In this tutorial, I will teach you how to create a mini cashiering system using c#. This system can be used for the school project, it is simple that can be done in no time. This system has a function that can display the product in the datagridview. It also has the calculation of the total amount and change of the tender amount.

Creating an Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application in C#.
ps1

Step 2

Do the form just like shown below.
ps2

Step 3

Add another form. In order to add another form, you have to go to the solution explorer, right-click the application name, click add and select the window form.
ps7
The “Add New Item” windows dialog will be shown. After that, click add.
ps3
Design the form just like shown below
ps4

Step 4

Go back to the Form1 and double click it. After that, write the following code for setting up the properties of the textboxes, add the columns, rows and set the properties of the datagridview,

  1.  
  2. txtProduct.Enabled = false;
  3. txtID.Enabled = false;
  4. txtDesc.Enabled = false;
  5. txtPrice.Enabled = false;
  6. txtQuantity.Focus();
  7. txtTotal.Enabled = false;
  8. txtChange.Enabled = false;
  9.  
  10. DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
  11. DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
  12. DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();
  13. DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();
  14. col1.Name = "ProductID";
  15. col1.HeaderText = "ProductID";
  16. col2.Name = "ProductName";
  17. col2.HeaderText = "ProductName";
  18. col3.Name = "Description";
  19. col3.HeaderText = "Description";
  20. col4.Name = "Price";
  21. col4.HeaderText = "Price";
  22.  
  23. dataGridView1.Columns.AddRange(new DataGridViewColumn[] { col1, col2, col3, col4 });
  24.  
  25. string[] row1 = new string[] {"0001","CellPhone","Nokia 3310","900" };
  26. string[] row2 = new string[] { "0002", "CellPhone", "Vivo Y95", "10000" };
  27. string[] row3 = new string[] { "0003", "CellPhone", "Samsung j5 mini", "900" };
  28.  
  29. dataGridView1.Rows.Add(row1);
  30. dataGridView1.Rows.Add(row2);
  31. dataGridView1.Rows.Add(row3);
  32.  
  33. dataGridView1.AllowUserToAddRows = false;
  34. dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;

Step 5

Write the following code for passing the data from the datagridview to the textbox.

  1.  
  2. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  3. {
  4.  
  5. txtID.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
  6. txtProduct.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
  7. txtDesc.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
  8. txtPrice.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
  9.  
  10. txtQuantity.Focus();
  11. }

Step 6

Write the following codes for the calculation of the total amount and the change.

  1.  
  2. private void txtQuantity_TextChanged(object sender, EventArgs e)
  3. {
  4. try
  5. {
  6. double total;
  7. if(txtQuantity.Text == "")
  8. {
  9. total = 0;
  10. }
  11. else
  12. {
  13. total = double.Parse(txtPrice.Text) * double.Parse(txtQuantity.Text);
  14. }
  15.  
  16. txtTotal.Text = total.ToString();
  17. }
  18. catch
  19. {
  20.  
  21. }
  22.  
  23.  
  24.  
  25. }
  26.  
  27. private void txtTender_TextChanged(object sender, EventArgs e)
  28. {
  29. try
  30. {
  31.  
  32. double change;
  33.  
  34. if (txtTender.Text == "" || txtTotal.Text == "0")
  35. {
  36. change = 0;
  37. }
  38. else
  39. {
  40. change = double.Parse(txtTender.Text) - double.Parse(txtTotal.Text);
  41. }
  42.  
  43.  
  44. txtChange.Text = change.ToString();
  45.  
  46. }
  47. catch
  48. {
  49.  
  50. }
  51. }

Step 7

Double click the button (clear) and write the following code for clearing all the textboxes.

  1.  
  2. private void button2_Click(object sender, EventArgs e)
  3. {
  4. foreach(Control txt in groupBox2.Controls)
  5. {
  6. if(txt is TextBox || txt is RichTextBox)
  7. {
  8. txt.Text="";
  9. }
  10. }
  11. foreach (Control txt in groupBox3.Controls)
  12. {
  13. if (txt is TextBox || txt is RichTextBox)
  14. {
  15. txt.Text = "";
  16. }
  17. }
  18.  
  19. }

Step 8

Double click the button(close) again and write the following code for closing the form.

  1.  
  2. private void button3_Click(object sender, EventArgs e)
  3. {
  4. this.Close();
  5. }

Step 9

Go to the Form2 and press the F7 on the keyboard to open the code editor. Create a method for getting the data from Form1 to Form2.

  1.  
  2. private void print(string id,string product,string desc, string price,string qty,string total,string tender,string change)
  3. {
  4. lblID.Text = id;
  5. lblProduct.Text = product;
  6. lblDesc.Text = desc;
  7. lblPrice.Text = price;
  8. lblQty.Text = qty;
  9. lblTotal.Text = total;
  10. lblTenderAmount.Text = tender;
  11. lblChange.Text = change;
  12. }

Step 10

Write the following code to execute the method that you have created.

  1.  
  2. public Form2(string id,string product,string desc, string price,string qty,string total,string tender,string change)
  3. {
  4. InitializeComponent();
  5. print(id, product, desc, price, qty, total, tender, change);
  6. }

Step 11

Go back to Form1 and double click the "Print" button and write the following code to perform the print function.

  1. Form frm = new Form2(txtID.Text, txtProduct.Text,
  2. txtDesc.Text, txtPrice.Text, txtQuantity.Text, txtTotal.Text,
  3. txtTender.Text, txtChange.Text);
  4. frm.ShowDialog();

Download the complete source code and run it on your computer.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.