This paste brought to you by Pastebin. View Raw

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.SqlClient;
  9.  
  10. namespace Supermarket
  11. {
  12.     public partial class SellingForm : Form
  13.     {
  14.         public SellingForm()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         SqlConnection Con = new SqlConnection(@"[Your Data Location]");
  20.        
  21.         private void populate()
  22.         {
  23.             Con.Open();
  24.             string query = "SELECT ProductName, ProductQuantity FROM ProductData";
  25.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  26.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  27.             var ds = new DataSet();
  28.             sda.Fill(ds);
  29.  
  30.             SellinglistproductDatagrid.DataSource = ds.Tables[0];
  31.             Con.Close();
  32.         }
  33.  
  34.         private void SellingForm_Load(object sender, EventArgs e)
  35.         {
  36.             populate();
  37.             SellingDate.Text = DateTime.Today.Day.ToString() + "/" + DateTime.Today.Month.ToString() + "/" + DateTime.Today.Year.ToString();
  38.             populatebill();
  39.             SellingSellername.Text = Login.Sellername;
  40.         }
  41.  
  42.         private void Logout1_Click(object sender, EventArgs e)
  43.         {
  44.             this.Hide();
  45.             Login log = new Login();
  46.             log.Show();
  47.         }
  48.  
  49.         private void SellinglistproductDatagrid_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
  50.         {
  51.             SellingProductname.Text = SellinglistproductDatagrid.SelectedRows[0].Cells[0].Value.ToString();
  52.             SellingPrice.Text = "12000";
  53.         }
  54.  
  55.         int Grdtotal = 0;
  56.         int n = 0;
  57.         private void SellingAddproduct_Click_1(object sender, EventArgs e)
  58.         {
  59.                 int total = Convert.ToInt32(SellingPrice.Text) * Convert.ToInt32(SellingQuantity.Text);
  60.  
  61.                 DataGridViewRow data = new DataGridViewRow();
  62.                 data.CreateCells(SellingproductDatagrid);
  63.                 data.Cells[0].Value = n + 1;
  64.                 data.Cells[1].Value = SellingProductname.Text;
  65.                 data.Cells[2].Value = SellingQuantity.Text;
  66.                 data.Cells[3].Value = Convert.ToInt32(SellingPrice.Text) * Convert.ToInt32(SellingQuantity.Text);
  67.                 SellingproductDatagrid.Rows.Add(data);
  68.                 Grdtotal = Grdtotal + total;
  69.                 SellingAmount.Text = " "+ Grdtotal;
  70.                 label6.Text = "Total Amount : " + "Rp ";
  71.                 n++;
  72.        }
  73.  
  74.         private void populatebill()
  75.         {
  76.             Con.Open();
  77.             string query = "SELECT * FROM BillData";
  78.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  79.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  80.             var ds = new DataSet();
  81.             sda.Fill(ds);
  82.  
  83.             SellingselllistDatagrid.DataSource = ds.Tables[0];
  84.             Con.Close();
  85.         }
  86.  
  87.         private void ListaddButton_Click(object sender, EventArgs e)
  88.         {
  89.             try
  90.             {
  91.                 Con.Open();
  92.                 string query = "INSERT INTO BillData VALUES("+SellingBillId.Text+",'"+SellingSellername.Text+"','"+SellingDate.Text+"','"+SellingAmount.Text+"')";
  93.                 SqlCommand cmd = new SqlCommand(query, Con);
  94.                 cmd.ExecuteNonQuery();
  95.                 MessageBox.Show("Bill Data Added Successfully");
  96.                 Con.Close();
  97.                 populatebill();
  98.             }
  99.             catch (Exception ex)
  100.             {
  101.                 MessageBox.Show(ex.Message);
  102.             }
  103.         }
  104.  
  105.         private void ListdeleteButton_Click(object sender, EventArgs e)
  106.         {
  107.             try
  108.             {
  109.                 Con.Open();
  110.                 string query = "DELETE FROM BillData WHERE BillId = " + SellingselllistDatagrid.SelectedRows[0].Cells[0].Value+"";
  111.                 SqlCommand cmd = new SqlCommand(query, Con);
  112.                 cmd.ExecuteNonQuery();
  113.                 MessageBox.Show("Bill Deleted Successfully");
  114.                 Con.Close();
  115.                 populatebill();
  116.             }
  117.             catch (Exception ex)
  118.             {
  119.                 MessageBox.Show(ex.Message);
  120.             }
  121.         }
  122.  
  123.         private void outbutton4_Click(object sender, EventArgs e)
  124.         {
  125.             Application.Exit();
  126.         }
  127.     }
  128. }
  129.