document.write('
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 SellerForm : Form
  15.     {
  16.         public SellerForm()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\LENOVO\\Documents\\smarketdb.mdf;Integrated Security=True;Connect Timeout=30");
  22.         private void populate()
  23.         {
  24.             Con.Open();
  25.             string query = "select * from SellerTbl";
  26.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  27.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  28.             var ds = new DataSet();
  29.             sda.Fill(ds);
  30.             SellerDGV.DataSource = ds.Tables[0];
  31.             Con.Close();
  32.         }
  33.         private void button5_Click(object sender, EventArgs e)
  34.         {
  35.             Application.Exit();
  36.         }
  37.  
  38.         private void SellerAddBtn_Click(object sender, EventArgs e)
  39.         {
  40.             try
  41.             {
  42.                 Con.Open();
  43.                 string query = "Insert into SellerTbl values (" + Sid.Text + ",\'" + Sname.Text + "\', " + Sage.Text + ", \'" + Sphone.Text + "\', \'" + Spass.Text + "\')";
  44.                 SqlCommand cmd = new SqlCommand(query, Con);
  45.                 cmd.ExecuteNonQuery();
  46.                 MessageBox.Show("Seller Added Successfully");
  47.                 Con.Close();
  48.                 populate();
  49.                 Sid.Text = "";
  50.                 Sname.Text = "";
  51.                 Sphone.Text = "";
  52.                 Spass.Text = "";
  53.                 Sage.Text = "";
  54.             }
  55.             catch (Exception ex)
  56.             {
  57.                 MessageBox.Show(ex.Message);
  58.             }
  59.             finally
  60.             {
  61.                 Con.Close();
  62.             }
  63.         }
  64.  
  65.         private void SellerEditBtn_Click(object sender, EventArgs e)
  66.         {
  67.             try
  68.             {
  69.                 if (Sname.Text == "" || Sid.Text == "" || Sage.Text == "" || Sphone.Text == "" || Spass.Text == "")
  70.                 {
  71.                     MessageBox.Show("Missing Information");
  72.                 }
  73.                 else
  74.                 {
  75.                     Con.Open();
  76.                     string query = "update SellerTbl set SellerName = \'" + Sname.Text + "\', SellerAge = " + Sage.Text + ", SellerPhone = \'" + Sphone.Text + "\', SellerPass =  \'" + Spass.Text + "\' where SellerId = " + Sid.Text + ";";
  77.                     SqlCommand cmd = new SqlCommand(query, Con);
  78.                     cmd.ExecuteNonQuery();
  79.                     MessageBox.Show("Seller data successfully updated");
  80.                     Con.Close();
  81.                     populate();
  82.                 }
  83.             }
  84.             catch (Exception ex)
  85.             {
  86.                 MessageBox.Show(ex.Message);
  87.             }
  88.             finally
  89.             {
  90.                 Con.Close();
  91.             }
  92.         }
  93.  
  94.         private void SellerDelBtn_Click(object sender, EventArgs e)
  95.         {
  96.             try
  97.             {
  98.                 if (Sid.Text == "")
  99.                 {
  100.                     MessageBox.Show("Select the seller to delete");
  101.                 }
  102.                 else
  103.                 {
  104.                     Con.Open();
  105.                     string query = "delete from SellerTbl where SellerId = " + Sid.Text + "";
  106.                     SqlCommand cmd = new SqlCommand(query, Con);
  107.                     cmd.ExecuteNonQuery();
  108.                     MessageBox.Show("Seller deleted successfully");
  109.                     Con.Close();
  110.                     populate();
  111.                     Sid.Text = "";
  112.                     Sname.Text = "";
  113.                     Sphone.Text = "";
  114.                     Spass.Text = "";
  115.                     Sage.Text = "";
  116.                 }
  117.             }
  118.             catch (Exception ex)
  119.             {
  120.                 MessageBox.Show(ex.Message);
  121.             }
  122.             finally
  123.             {
  124.                 Con.Close();
  125.             }
  126.         }
  127.  
  128.         private void SellerDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  129.         {
  130.             Sid.Text = SellerDGV.SelectedRows[0].Cells[0].Value.ToString();
  131.             Sname.Text = SellerDGV.SelectedRows[0].Cells[1].Value.ToString();
  132.             Sage.Text = SellerDGV.SelectedRows[0].Cells[2].Value.ToString();
  133.             Sphone.Text = SellerDGV.SelectedRows[0].Cells[3].Value.ToString();
  134.             Spass.Text = SellerDGV.SelectedRows[0].Cells[4].Value.ToString();
  135.         }
  136.  
  137.         private void SellerForm_Load(object sender, EventArgs e)
  138.         {
  139.             populate();
  140.         }
  141.  
  142.         private void ProductPage_Click(object sender, EventArgs e)
  143.         {
  144.             ProductForm cat = new ProductForm();
  145.             cat.Show();
  146.             this.Hide();
  147.         }
  148.  
  149.         private void CategoriesPage_Click(object sender, EventArgs e)
  150.         {
  151.             CategoryForm cat = new CategoryForm();
  152.             cat.Show();
  153.             this.Hide();
  154.         }
  155.  
  156.         private void SellingPage_Click(object sender, EventArgs e)
  157.         {
  158.  
  159.         }
  160.  
  161.         private void label7_Click(object sender, EventArgs e)
  162.         {
  163.             this.Hide();
  164.             Form1 login = new Form1();
  165.             login.Show();
  166.         }
  167.     }
  168. }
');