Guest User

Untitled

a guest
May 8th, 2021
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 20.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace ETS_PosApp
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.        
  20.         public double CostOfItems()
  21.         {
  22.             Double sum = 0;
  23.             int i = 0;
  24.             for (i = 0; i < (dataGridView1.Rows.Count); i++)
  25.             {
  26.                 sum += Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
  27.             }
  28.             return sum;
  29.         }
  30.  
  31.         private void AddCost()
  32.         {
  33.             Double tax, g;
  34.             tax = 3.9;
  35.             if (dataGridView1.Rows.Count > 0)
  36.             {
  37.                 lblTax.Text = String.Format("{0:c2}", (( CostOfItems() * tax) / 100));
  38.                 lblSubTotal.Text = String.Format("{0:c2}", ( CostOfItems() ));
  39.                 g = ((CostOfItems() * tax) / 100);
  40.                 lblTotal.Text = String.Format("{0:c2}", (CostOfItems() + g));
  41.                 lblBarcode.Text = Convert.ToString(g + CostOfItems());
  42.             }
  43.         }
  44.        
  45.         private void Change()
  46.         {
  47.             Double tax, g, c;
  48.             tax = 3.9;
  49.             if (dataGridView1.Rows.Count > 0)
  50.             {
  51.                 g = ((CostOfItems() * tax) / 100) + CostOfItems();
  52.                 c = Convert.ToInt32(lblCash.Text);
  53.                 this.lblChange.Text = String.Format("{0:c2}", c - g);
  54.             }
  55.         }
  56.  
  57.         Bitmap bitmap;
  58.         private void btnPrint_Click(object sender, EventArgs e)
  59.         {
  60.             try
  61.             {
  62.                 int height = dataGridView1.Height;
  63.                 dataGridView1.Height = dataGridView1.RowCount * dataGridView1.RowTemplate.Height * 2;
  64.                 bitmap = new Bitmap(dataGridView1.Width, dataGridView1.Height);
  65.                 dataGridView1.DrawToBitmap(bitmap, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));
  66.                 printPreviewDialog1.PrintPreviewControl.Zoom = 1;
  67.                 printPreviewDialog1.ShowDialog();
  68.                 dataGridView1.Height = height;
  69.             }
  70.             catch(Exception ex)
  71.             {
  72.                 MessageBox.Show(ex.Message);
  73.             }
  74.         }
  75.  
  76.         private void button38_Click(object sender, EventArgs e)
  77.         {
  78.             try
  79.             {
  80.                 int height = dataGridView1.Height;
  81.                 dataGridView1.Height = dataGridView1.RowCount * dataGridView1.RowTemplate.Height * 2;
  82.                 bitmap = new Bitmap(dataGridView1.Width, dataGridView1.Height);
  83.                 dataGridView1.DrawToBitmap(bitmap, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));
  84.                 printPreviewDialog1.PrintPreviewControl.Zoom = 1;
  85.                 printPreviewDialog1.ShowDialog();
  86.                 dataGridView1.Height = height;
  87.             }
  88.             catch (Exception ex)
  89.             {
  90.                 MessageBox.Show(ex.Message);
  91.             }
  92.                
  93.         }
  94.  
  95.         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  96.         {
  97.             try
  98.             {
  99.                 e.Graphics.DrawImage(bitmap, 0, 0);
  100.             }
  101.             catch (Exception ex)
  102.             {
  103.                 MessageBox.Show(ex.Message);
  104.             }
  105.         }
  106.  
  107.         private void btnReset_Click(object sender, EventArgs e)
  108.         {
  109.             try
  110.             {
  111.                 lblBarcode.Text = "";
  112.                 lblCash.Text = "0";
  113.                 lblChange.Text = "";
  114.                 lblSubTotal.Text = "";
  115.                 lblTax.Text = "";
  116.                 lblTotal.Text = "";
  117.                 dataGridView1.Rows.Clear();
  118.                 dataGridView1.Refresh();
  119.                 cboPayment.Text = "";
  120.             }
  121.             catch (Exception ex)
  122.             {
  123.                 MessageBox.Show(ex.Message);
  124.             }
  125.         }
  126.  
  127.         private void Form1_Load(object sender, EventArgs e)
  128.         {
  129.             cboPayment.Items.Add("Cash");
  130.             cboPayment.Items.Add("Visa Card");
  131.             cboPayment.Items.Add("Master Card");
  132.         }
  133.  
  134.         private void NumbersOnly1(object sender, EventArgs e)
  135.         {
  136.             Button b = (Button)sender;
  137.  
  138.             if (lblCash.Text == "0")
  139.             {
  140.                 lblCash.Text = "";
  141.                 lblCash.Text = b.Text;
  142.             }
  143.             else if (b.Text == ".")
  144.             {
  145.                 if (!lblCash.Text.Contains("."))
  146.                 {
  147.                     lblCash.Text = lblCash.Text + b.Text;
  148.                 }
  149.             }
  150.             else
  151.                 lblCash.Text = lblCash.Text + b.Text;
  152.         }
  153.  
  154.         private void btnC_Click(object sender, EventArgs e)
  155.         {
  156.             lblCash.Text = "0";
  157.         }
  158.  
  159.         private void btnPay_Click(object sender, EventArgs e)
  160.         {
  161.             if (cboPayment.Text == "Cash")
  162.             {
  163.                 Change();
  164.             }
  165.             else
  166.             {
  167.                 lblChange.Text = "";
  168.                 lblCash.Text = "0";
  169.             }
  170.         }
  171.  
  172.         private void btnRemoveItem_Click(object sender, EventArgs e)
  173.         {
  174.             foreach(DataGridViewRow row in this.dataGridView1.SelectedRows)
  175.             {
  176.                 dataGridView1.Rows.Remove(row);
  177.             }
  178.             AddCost();
  179.             if (cboPayment.Text == "Cash")
  180.             {
  181.                 Change();
  182.             }
  183.             else
  184.             {
  185.                 lblChange.Text = "";
  186.                 lblCash.Text = "0";
  187.             }
  188.         }
  189.  
  190.         private void button24_Click(object sender, EventArgs e)
  191.         {
  192.             Double CostifItem = 12000;
  193.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  194.             {
  195.                 if ((bool)(row.Cells[0].Value = "button24"))
  196.                 {
  197.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  198.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  199.                 }
  200.             }
  201.             dataGridView1.Rows.Add("Bread and Ice Cream", "1", CostifItem);
  202.             AddCost();
  203.         }
  204.  
  205.         private void button23_Click(object sender, EventArgs e)
  206.         {
  207.             Double CostifItem = 25000;
  208.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  209.             {
  210.                 if ((bool)(row.Cells[0].Value = "button23"))
  211.                 {
  212.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  213.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  214.                 }
  215.             }
  216.             dataGridView1.Rows.Add("Fried Chicken", "1", CostifItem);
  217.             AddCost();
  218.         }
  219.  
  220.         private void button22_Click(object sender, EventArgs e)
  221.         {
  222.             Double CostifItem = 25000;
  223.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  224.             {
  225.                 if ((bool)(row.Cells[0].Value = "button22"))
  226.                 {
  227.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  228.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  229.                 }
  230.             }
  231.             dataGridView1.Rows.Add("Hamburger", "1", CostifItem);
  232.             AddCost();
  233.         }
  234.  
  235.         private void button36_Click(object sender, EventArgs e)
  236.         {
  237.             Double CostifItem = 15000;
  238.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  239.             {
  240.                 if ((bool)(row.Cells[0].Value = "button36"))
  241.                 {
  242.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  243.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  244.                 }
  245.             }
  246.             dataGridView1.Rows.Add("Lasagna", "1", CostifItem);
  247.             AddCost();
  248.         }
  249.  
  250.         private void button35_Click(object sender, EventArgs e)
  251.         {
  252.             Double CostifItem = 12000;
  253.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  254.             {
  255.                 if ((bool)(row.Cells[0].Value = "button35"))
  256.                 {
  257.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  258.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  259.                 }
  260.             }
  261.             dataGridView1.Rows.Add("Donuts", "1", CostifItem);
  262.             AddCost();
  263.         }
  264.  
  265.         private void button34_Click(object sender, EventArgs e)
  266.         {
  267.             Double CostifItem = 50000;
  268.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  269.             {
  270.                 if ((bool)(row.Cells[0].Value = "button34"))
  271.                 {
  272.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  273.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  274.                 }
  275.             }
  276.             dataGridView1.Rows.Add("Gnocci", "1", CostifItem);
  277.             AddCost();
  278.         }
  279.  
  280.         private void button21_Click(object sender, EventArgs e)
  281.         {
  282.             Double CostifItem = 50000;
  283.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  284.             {
  285.                 if ((bool)(row.Cells[0].Value = "button21"))
  286.                 {
  287.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  288.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  289.                 }
  290.             }
  291.             dataGridView1.Rows.Add("Birthday Cake", "1", CostifItem);
  292.             AddCost();
  293.         }
  294.  
  295.         private void button20_Click(object sender, EventArgs e)
  296.         {
  297.             Double CostifItem = 12000;
  298.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  299.             {
  300.                 if ((bool)(row.Cells[0].Value = "button20"))
  301.                 {
  302.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  303.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  304.                 }
  305.             }
  306.             dataGridView1.Rows.Add("Snacks", "1", CostifItem);
  307.             AddCost();
  308.         }
  309.  
  310.         private void button19_Click(object sender, EventArgs e)
  311.         {
  312.             Double CostifItem = 12000;
  313.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  314.             {
  315.                 if ((bool)(row.Cells[0].Value = "button19"))
  316.                 {
  317.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  318.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  319.                 }
  320.             }
  321.             dataGridView1.Rows.Add("Lemonade", "1", CostifItem);
  322.             AddCost();
  323.         }
  324.  
  325.         private void button33_Click(object sender, EventArgs e)
  326.         {
  327.             Double CostifItem = 50000;
  328.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  329.             {
  330.                 if ((bool)(row.Cells[0].Value = "button33"))
  331.                 {
  332.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  333.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  334.                 }
  335.             }
  336.             dataGridView1.Rows.Add("Ratatouille", "1", CostifItem);
  337.             AddCost();
  338.         }
  339.  
  340.         private void button32_Click(object sender, EventArgs e)
  341.         {
  342.             Double CostifItem = 25000;
  343.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  344.             {
  345.                 if ((bool)(row.Cells[0].Value = "button32"))
  346.                 {
  347.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  348.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  349.                 }
  350.             }
  351.             dataGridView1.Rows.Add("Lasagna", "1", CostifItem);
  352.             AddCost();
  353.         }
  354.  
  355.         private void button31_Click(object sender, EventArgs e)
  356.         {
  357.             Double CostifItem = 95000;
  358.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  359.             {
  360.                 if ((bool)(row.Cells[0].Value = "button31"))
  361.                 {
  362.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  363.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  364.                 }
  365.             }
  366.             dataGridView1.Rows.Add("Rainbow Cake", "1", CostifItem);
  367.             AddCost();
  368.         }
  369.  
  370.         private void button18_Click(object sender, EventArgs e)
  371.         {
  372.             Double CostifItem = 12000;
  373.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  374.             {
  375.                 if ((bool)(row.Cells[0].Value = "button18"))
  376.                 {
  377.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  378.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  379.                 }
  380.             }
  381.             dataGridView1.Rows.Add("Cheese Toast", "1", CostifItem);
  382.             AddCost();
  383.         }
  384.  
  385.         private void button17_Click(object sender, EventArgs e)
  386.         {
  387.             Double CostifItem = 15000;
  388.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  389.             {
  390.                 if ((bool)(row.Cells[0].Value = "button17"))
  391.                 {
  392.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  393.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  394.                 }
  395.             }
  396.             dataGridView1.Rows.Add("Strawberry Juice", "1", CostifItem);
  397.             AddCost();
  398.         }
  399.  
  400.         private void button16_Click(object sender, EventArgs e)
  401.         {
  402.             Double CostifItem = 25000;
  403.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  404.             {
  405.                 if ((bool)(row.Cells[0].Value = "button16"))
  406.                 {
  407.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  408.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  409.                 }
  410.             }
  411.             dataGridView1.Rows.Add("Orange Juice", "1", CostifItem);
  412.             AddCost();
  413.         }
  414.  
  415.         private void button30_Click(object sender, EventArgs e)
  416.         {
  417.             Double CostifItem = 32000;
  418.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  419.             {
  420.                 if ((bool)(row.Cells[0].Value = "button30"))
  421.                 {
  422.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  423.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  424.                 }
  425.             }
  426.             dataGridView1.Rows.Add("Pasta", "1", CostifItem);
  427.             AddCost();
  428.         }
  429.  
  430.         private void button29_Click(object sender, EventArgs e)
  431.         {
  432.             Double CostifItem = 25000;
  433.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  434.             {
  435.                 if ((bool)(row.Cells[0].Value = "button29"))
  436.                 {
  437.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  438.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  439.                 }
  440.             }
  441.             dataGridView1.Rows.Add("Mushroom Pie", "1", CostifItem);
  442.             AddCost();
  443.         }
  444.  
  445.         private void button28_Click(object sender, EventArgs e)
  446.         {
  447.             Double CostifItem = 50000;
  448.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  449.             {
  450.                 if ((bool)(row.Cells[0].Value = "button28"))
  451.                 {
  452.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  453.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  454.                 }
  455.             }
  456.             dataGridView1.Rows.Add("Pizza", "1", CostifItem);
  457.             AddCost();
  458.         }
  459.  
  460.         private void button15_Click(object sender, EventArgs e)
  461.         {
  462.             Double CostifItem = 32000;
  463.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  464.             {
  465.                 if ((bool)(row.Cells[0].Value = "button15"))
  466.                 {
  467.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  468.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  469.                 }
  470.             }
  471.             dataGridView1.Rows.Add("Soup", "1", CostifItem);
  472.             AddCost();
  473.         }
  474.  
  475.         private void button14_Click(object sender, EventArgs e)
  476.         {
  477.             Double CostifItem = 25000;
  478.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  479.             {
  480.                 if ((bool)(row.Cells[0].Value = "button14"))
  481.                 {
  482.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  483.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  484.                 }
  485.             }
  486.             dataGridView1.Rows.Add("Salad", "1", CostifItem);
  487.             AddCost();
  488.         }
  489.  
  490.         private void button13_Click(object sender, EventArgs e)
  491.         {
  492.             Double CostifItem = 15000;
  493.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  494.             {
  495.                 if ((bool)(row.Cells[0].Value = "button13"))
  496.                 {
  497.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  498.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  499.                 }
  500.             }
  501.             dataGridView1.Rows.Add("Tea", "1", CostifItem);
  502.             AddCost();
  503.         }
  504.  
  505.         private void button27_Click(object sender, EventArgs e)
  506.         {
  507.             Double CostifItem = 12000;
  508.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  509.             {
  510.                 if ((bool)(row.Cells[0].Value = "button27"))
  511.                 {
  512.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  513.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  514.                 }
  515.             }
  516.             dataGridView1.Rows.Add("Mocca Donuts", "1", CostifItem);
  517.             AddCost();
  518.         }
  519.  
  520.         private void button26_Click(object sender, EventArgs e)
  521.         {
  522.             Double CostifItem = 12000;
  523.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  524.             {
  525.                 if ((bool)(row.Cells[0].Value = "button26"))
  526.                 {
  527.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  528.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  529.                 }
  530.             }
  531.             dataGridView1.Rows.Add("Bread and Cream", "1", CostifItem);
  532.             AddCost();
  533.         }
  534.  
  535.         private void button25_Click(object sender, EventArgs e)
  536.         {
  537.             Double CostifItem = 12000;
  538.             foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
  539.             {
  540.                 if ((bool)(row.Cells[0].Value = "button25"))
  541.                 {
  542.                     row.Cells[1].Value = Double.Parse((string)row.Cells[1].Value + 1);
  543.                     row.Cells[2].Value = Double.Parse((string)row.Cells[1].Value) * CostifItem;
  544.                 }
  545.             }
  546.             dataGridView1.Rows.Add("Salty Snacks", "1", CostifItem);
  547.             AddCost();
  548.         }
  549.  
  550.         private void lblSubTotal_Click(object sender, EventArgs e)
  551.         {
  552.  
  553.         }
  554.     }
  555. }
  556.  
Advertisement
Add Comment
Please, Sign In to add comment