Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  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. using System.Data.SqlClient;
  11.  
  12. namespace Supermarket
  13. {
  14.     public partial class SellingForm : Form
  15.     {
  16.         public SellingForm()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         SqlConnection connect = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\USERS\ASUS\DOCUMENTS\SUPERMARKETDB.mdf;Integrated Security=True;Connect Timeout=30");
  21.  
  22.         private void populate()
  23.         {
  24.             connect.Open();
  25.             string query = "select NamaProduk,QuantProduk,PriceProduk from Produk";
  26.             SqlDataAdapter sda = new SqlDataAdapter(query, connect);
  27.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  28.             var dataset = new DataSet();
  29.             sda.Fill(dataset);
  30.             ProdukGDV1.DataSource = dataset.Tables[0];
  31.             connect.Close();
  32.         }
  33.         private void populatebills()
  34.         {
  35.             connect.Open();
  36.             string query = "select * from Transaksi";
  37.             SqlDataAdapter sda = new SqlDataAdapter(query, connect);
  38.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  39.             var dataset = new DataSet();
  40.             sda.Fill(dataset);
  41.             BillsGDV.DataSource = dataset.Tables[0];
  42.             connect.Close();
  43.         }
  44.         private void SellingForm_Load(object sender, EventArgs e)
  45.         {
  46.             populate();
  47.             populatebills();
  48.             SellerNamelbl.Text = Form1.NamaSeller;
  49.         }
  50.        
  51.         private void button5_Click(object sender, EventArgs e)
  52.         {
  53.  
  54.         }
  55.  
  56.         private void button1_Click(object sender, EventArgs e)
  57.         {
  58.  
  59.         }
  60.  
  61.         private void bunifuMaterialTextbox1_OnValueChanged(object sender, EventArgs e)
  62.         {
  63.  
  64.         }
  65.  
  66.         private void ProdukGDV1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  67.         {
  68.             NamaProduk.Text = ProdukGDV1.SelectedRows[0].Cells[0].Value.ToString();
  69.             PriceProduk.Text = ProdukGDV1.SelectedRows[0].Cells[2].Value.ToString();
  70.  
  71.         }
  72.         int Grdtotal = 0, n = 0;
  73.         private void button3_Click(object sender, EventArgs e)
  74.         {
  75.             if(NamaProduk.Text == "" || QuantProduk.Text == "")
  76.             {
  77.                 MessageBox.Show("Missing Data");
  78.             }
  79.             else
  80.             {
  81.                 int total = Convert.ToInt32(PriceProduk.Text) * Convert.ToInt32(QuantProduk.Text);
  82.                 DataGridViewRow newRow = new DataGridViewRow();
  83.                 newRow.CreateCells(OrderGDV);
  84.                 newRow.Cells[0].Value = n + 1;
  85.                 newRow.Cells[1].Value = NamaProduk.Text;
  86.                 newRow.Cells[2].Value = PriceProduk.Text;
  87.                 newRow.Cells[3].Value = QuantProduk.Text;
  88.                 newRow.Cells[4].Value = Convert.ToInt32(PriceProduk.Text) * Convert.ToInt32(QuantProduk.Text);
  89.                 OrderGDV.Rows.Add(newRow);
  90.                 n++;
  91.                 Grdtotal = Grdtotal + total;
  92.                 Amountlbl.Text = "" + Grdtotal;
  93.             }
  94.            
  95.         }
  96.  
  97.         private void button10_Click(object sender, EventArgs e)
  98.         {
  99.             if(IDBill.Text == "")
  100.             {
  101.                 MessageBox.Show("Missing Bill ID");
  102.             }
  103.             else
  104.             {
  105.                 try
  106.                 {
  107.                     connect.Open();
  108.                     string query = "insert into Transaksi values (" + IDBill.Text + ",'" + SellerNamelbl.Text + "', '" + Datelabel.Text + "'," + Amountlbl.Text + ")";
  109.                     SqlCommand cmd = new SqlCommand(query, connect);
  110.                     cmd.ExecuteNonQuery();
  111.                     MessageBox.Show("Order Added Successfully");
  112.                     connect.Close();
  113.                     populatebills();
  114.                 }
  115.                 catch (Exception ex)
  116.                 {
  117.                     MessageBox.Show(ex.Message);
  118.                 }
  119.             }
  120.            
  121.         }
  122.  
  123.         private void Amountlbl_Click(object sender, EventArgs e)
  124.         {
  125.  
  126.         }
  127.  
  128.         private void NamaProduk_OnValueChanged(object sender, EventArgs e)
  129.         {
  130.  
  131.         }
  132.  
  133.         private void button12_Click(object sender, EventArgs e)
  134.         {
  135.             if(printPreviewDialog1.ShowDialog() == DialogResult.OK)
  136.             {
  137.                 printDocument1.Print();
  138.             }
  139.         }
  140.  
  141.         private void BillsGDV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  142.         {
  143.            
  144.         }
  145.  
  146.         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  147.         {
  148.             e.Graphics.DrawString("Supermarket", new Font("Century Gothic", 25, FontStyle.Bold), Brushes.Teal, new Point(300));
  149.             e.Graphics.DrawString("Bill ID : " +BillsGDV.SelectedRows[0].Cells[0].Value.ToString(), new Font("Century Gothic", 20, FontStyle.Bold), Brushes.Teal, new Point(100, 70));
  150.             e.Graphics.DrawString("Seller Name : " + BillsGDV.SelectedRows[0].Cells[1].Value.ToString(), new Font("Century Gothic", 20, FontStyle.Bold), Brushes.Teal, new Point(100, 100));
  151.             e.Graphics.DrawString("Date : " + BillsGDV.SelectedRows[0].Cells[2].Value.ToString(), new Font("Century Gothic", 20, FontStyle.Bold), Brushes.Teal, new Point(100, 130));
  152.             e.Graphics.DrawString("Total Amount : " + BillsGDV.SelectedRows[0].Cells[3].Value.ToString(), new Font("Century Gothic", 20, FontStyle.Bold), Brushes.Teal, new Point(100, 160));
  153.             //e.Graphics.DrawString("CodeSpace", new Font("Century Gothic", 25, FontStyle.Bold), Brushes.Teal, new Point(300));
  154.         }
  155.  
  156.         private void logout_Click(object sender, EventArgs e)
  157.         {
  158.             this.Hide();
  159.             Form1 login = new Form1();
  160.             login.Show();
  161.         }
  162.  
  163.         private void label5_Click(object sender, EventArgs e)
  164.         {
  165.             Application.Exit();
  166.         }
  167.  
  168.         private void button4_Click(object sender, EventArgs e)
  169.         {
  170.  
  171.         }
  172.  
  173.         private void OrderGDV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  174.         {
  175.  
  176.         }
  177.     }
  178. }
  179.