using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Supermarket
{
public partial class SellerForm : Form
{
public SellerForm()
{
InitializeComponent();
}
SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\LENOVO\\Documents\\smarketdb.mdf;Integrated Security=True;Connect Timeout=30");
private void populate()
{
Con.Open();
string query = "select * from SellerTbl";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new DataSet();
sda.Fill(ds);
SellerDGV.DataSource = ds.Tables[0];
Con.Close();
}
private void button5_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void SellerAddBtn_Click(object sender, EventArgs e)
{
try
{
Con.Open();
string query = "Insert into SellerTbl values (" + Sid.Text + ",\'" + Sname.Text + "\', " + Sage.Text + ", \'" + Sphone.Text + "\', \'" + Spass.Text + "\')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Seller Added Successfully");
Con.Close();
populate();
Sid.Text = "";
Sname.Text = "";
Sphone.Text = "";
Spass.Text = "";
Sage.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Con.Close();
}
}
private void SellerEditBtn_Click(object sender, EventArgs e)
{
try
{
if (Sname.Text == "" || Sid.Text == "" || Sage.Text == "" || Sphone.Text == "" || Spass.Text == "")
{
MessageBox.Show("Missing Information");
}
else
{
Con.Open();
string query = "update SellerTbl set SellerName = \'" + Sname.Text + "\', SellerAge = " + Sage.Text + ", SellerPhone = \'" + Sphone.Text + "\', SellerPass = \'" + Spass.Text + "\' where SellerId = " + Sid.Text + ";";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Seller data successfully updated");
Con.Close();
populate();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Con.Close();
}
}
private void SellerDelBtn_Click(object sender, EventArgs e)
{
try
{
if (Sid.Text == "")
{
MessageBox.Show("Select the seller to delete");
}
else
{
Con.Open();
string query = "delete from SellerTbl where SellerId = " + Sid.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Seller deleted successfully");
Con.Close();
populate();
Sid.Text = "";
Sname.Text = "";
Sphone.Text = "";
Spass.Text = "";
Sage.Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Con.Close();
}
}
private void SellerDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
Sid.Text = SellerDGV.SelectedRows[0].Cells[0].Value.ToString();
Sname.Text = SellerDGV.SelectedRows[0].Cells[1].Value.ToString();
Sage.Text = SellerDGV.SelectedRows[0].Cells[2].Value.ToString();
Sphone.Text = SellerDGV.SelectedRows[0].Cells[3].Value.ToString();
Spass.Text = SellerDGV.SelectedRows[0].Cells[4].Value.ToString();
}
private void SellerForm_Load(object sender, EventArgs e)
{
populate();
}
private void ProductPage_Click(object sender, EventArgs e)
{
ProductForm cat = new ProductForm();
cat.Show();
this.Hide();
}
private void CategoriesPage_Click(object sender, EventArgs e)
{
CategoryForm cat = new CategoryForm();
cat.Show();
this.Hide();
}
private void SellingPage_Click(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
this.Hide();
Form1 login = new Form1();
login.Show();
}
}
}