Facebook
From Mature Mockingjay, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 68
  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 CategoriesForm : Form
  13.     {
  14.         public CategoriesForm()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void ProductButton3_Click(object sender, EventArgs e)
  20.         {
  21.             this.Hide();
  22.             ProductForm log = new ProductForm();
  23.             log.Show();
  24.         }
  25.  
  26.         private void CategoryButton3_Click(object sender, EventArgs e)
  27.         {
  28.             this.Hide();
  29.             CategoriesForm log = new CategoriesForm();
  30.             log.Show();
  31.         }
  32.  
  33.         private void SellerButton3_Click(object sender, EventArgs e)
  34.         {
  35.             this.Hide();
  36.             SellerForm log = new SellerForm();
  37.             log.Show();
  38.         }
  39.  
  40.         private void populate()
  41.         {
  42.             Con.Open();
  43.             string query = "SELECT * FROM CategoryData";
  44.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  45.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  46.             var ds = new DataSet();
  47.             sda.Fill(ds);
  48.             CategoryDatagrid.DataSource = ds.Tables[0];
  49.             Con.Close();
  50.         }
  51.  
  52.         SqlConnection Con = new SqlConnection(@"[Your Data Location]");
  53.         private void AddButton3_Click(object sender, EventArgs e)
  54.         {
  55.             try
  56.             {
  57.                 Con.Open();
  58.                 string query = "INSERT INTO CategoryData VALUES(" + CategoryId.Text + ", '" + CategoryName.Text+ "', '" + CategoryDescription.Text+ "')";
  59.                 SqlCommand cmd = new SqlCommand(query, Con);
  60.                 cmd.ExecuteNonQuery();
  61.                 MessageBox.Show("Category Added Successfully");
  62.                 Con.Close();
  63.                 populate();
  64.             }
  65.             catch (Exception ex)
  66.             {
  67.                 MessageBox.Show(ex.Message);
  68.             }
  69.         }
  70.  
  71.         private void EditButton3_Click(object sender, EventArgs e)
  72.         {
  73.             try
  74.             {
  75.                 Con.Open();
  76.                 string query = "UPDATE CategoryData SET CategoryName='" + CategoryName.Text+ "', CategoryDescription='" + CategoryDescription.Text+ "' WHERE CategoryId='" + CategoryId.Text+ "'";
  77.                 SqlCommand cmd = new SqlCommand(query, Con);
  78.                 cmd.ExecuteNonQuery();
  79.                 MessageBox.Show("Category Updated Successfully");
  80.                 Con.Close();
  81.                 populate();
  82.             }
  83.             catch (Exception ex)
  84.             {
  85.                 MessageBox.Show(ex.Message);
  86.             }
  87.         }
  88.  
  89.         private void DeleteButton3_Click(object sender, EventArgs e)
  90.         {
  91.             try
  92.             {
  93.                 Con.Open();
  94.                 string query = "DELETE FROM CategoryData WHERE CategoryId = " + CategoryId.Text+ "";
  95.                 SqlCommand cmd = new SqlCommand(query, Con);
  96.                 cmd.ExecuteNonQuery();
  97.                 MessageBox.Show("Category Deleted Successfully");
  98.                 Con.Close();
  99.                 populate();
  100.             }
  101.             catch (Exception ex)
  102.             {
  103.                 MessageBox.Show(ex.Message);
  104.             }
  105.         }
  106.  
  107.         private void CategoryDatagrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
  108.         {
  109.                 CategoryId.Text = CategoryDatagrid.SelectedRows[0].Cells[0].Value.ToString();
  110.                 CategoryName.Text = CategoryDatagrid.SelectedRows[0].Cells[1].Value.ToString();
  111.                 CategoryDescription.Text = CategoryDatagrid.SelectedRows[0].Cells[2].Value.ToString();
  112.         }
  113.  
  114.         private void panel5_Paint(object sender, PaintEventArgs e)
  115.         {
  116.             populate();
  117.         }
  118.  
  119.         private void Logout3_Click(object sender, EventArgs e)
  120.         {
  121.             this.Hide();
  122.             Login log = new Login();
  123.             log.Show();
  124.         }
  125.  
  126.         private void outbutton3_Click(object sender, EventArgs e)
  127.         {
  128.             Application.Exit();
  129.         }
  130.     }
  131. }
  132.  
captcha