- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace Supermarket
- {
- public partial class SellerForm : Form
- {
- public SellerForm()
- {
- InitializeComponent();
- }
- private void ProductButton_Click(object sender, EventArgs e)
- {
- this.Hide();
- ProductForm log = new ProductForm();
- log.Show();
- }
- private void SellerForm_Load(object sender, EventArgs e)
- {
- populate();
- }
- private void SellerButton_Click(object sender, EventArgs e)
- {
- this.Hide();
- SellerForm log = new SellerForm();
- log.Show();
- }
- private void CategoryButton_Click(object sender, EventArgs e)
- {
- this.Hide();
- CategoriesForm log = new CategoriesForm();
- log.Show();
- }
- SqlConnection Con = new SqlConnection(@"[Your Data Location]");
- private void AddButton1_Click(object sender, EventArgs e)
- {
- try
- {
- Con.Open();
- string query = "INSERT INTO SellerData VALUES("+SellerId.Text+", '"+SellerName.Text+"', '"+SellerAge.Text+"', '"+SellerPassword.Text+"', '"+SellerPhone.Text+"')";
- SqlCommand cmd = new SqlCommand(query, Con);
- cmd.ExecuteNonQuery();
- MessageBox.Show("New Seller Data Added Successfully");
- Con.Close();
- populate();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void EditButton1_Click(object sender, EventArgs e)
- {
- try
- {
- Con.Open();
- string query = "UPDATE SellerData SET SellerName='" + SellerName.Text + "', SellerAge='" + SellerAge.Text + "', SellerPass='" + SellerPassword.Text + "', SellerPhone='" + SellerPhone.Text+"' WHERE SellerId='" + SellerId.Text + "'";
- SqlCommand cmd = new SqlCommand(query, Con);
- cmd.ExecuteNonQuery();
- MessageBox.Show("Seller Data Updated Successfully");
- Con.Close();
- populate();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void DeleteButton1_Click(object sender, EventArgs e)
- {
- try
- {
- Con.Open();
- string query = "DELETE FROM SellerData WHERE SellerId = " + SellerId.Text + "";
- SqlCommand cmd = new SqlCommand(query, Con);
- cmd.ExecuteNonQuery();
- MessageBox.Show("Seller Data Deleted Successfully");
- Con.Close();
- populate();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void populate()
- {
- Con.Open();
- string query = "SELECT * FROM SellerData";
- SqlDataAdapter sda = new SqlDataAdapter(query, Con);
- SqlCommandBuilder builder = new SqlCommandBuilder(sda);
- var ds = new DataSet();
- sda.Fill(ds);
- SellerDataGrid.DataSource = ds.Tables[0];
- Con.Close();
- }
- private void SellerDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- SellerId.Text = SellerDataGrid.SelectedRows[0].Cells[0].Value.ToString();
- SellerName.Text = SellerDataGrid.SelectedRows[0].Cells[1].Value.ToString();
- SellerAge.Text = SellerDataGrid.SelectedRows[0].Cells[2].Value.ToString();
- SellerPassword.Text = SellerDataGrid.SelectedRows[0].Cells[3].Value.ToString();
- SellerPhone.Text = SellerDataGrid.SelectedRows[0].Cells[4].Value.ToString();
- }
- private void Logout1_Click(object sender, EventArgs e)
- {
- this.Hide();
- Login log = new Login();
- log.Show();
- }
- private void outbutton1_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- }
- }