Splash Page Code
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;
namespace Book_Shop_Management_System
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
int StartPoint = 0;
private void Timer1_Tick(object sender, EventArgs e)
{
StartPoint += 1;
ProgressBar1.Value = StartPoint;
lblPercent.Text = StartPoint + "%";
if(ProgressBar1.Value == 100)
{
ProgressBar1.Value = 0;
Timer1.Stop();
User_Login Obj = new User_Login();
Obj.Show();
this.Hide();
}
}
private void Form1_Load(object sender, EventArgs e)
{
Timer1.Start();
}
}
}
Admin Login Page Code
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;
namespace Book_Shop_Management_System
{
public partial class Admin_Login : Form
{
public Admin_Login()
{
InitializeComponent();
}
private void lblUser_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
User_Login Obj = new User_Login();
Obj.Show();
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUsername.Text == "Admin" || txtPassword.Text == "Password")
{
Books Obj = new Books();
Obj.Show();
this.Hide();
}else
{
MessageBox.Show("Wrong Username & Password");
}
}
}
}
User Login Page Code
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 Book_Shop_Management_System
{
public partial class User_Login : Form
{
public User_Login()
{
InitializeComponent();
}
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Documents\BookShopDatabase.mdf;Integrated Security=True;Connect Timeout=30″);
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void lblAdmin_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Admin_Login Obj = new Admin_Login();
Obj.Show();
this.Hide();
}
public static string Username = "";
private void btnLogin_Click(object sender, EventArgs e)
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from UsersTbl where Username = '" + txtUsername.Text + "' and UserPassword = '" + txtPassword.Text + "'", Con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
Username = txtUsername.Text;
Billing Obj = new Billing();
Obj.Show();
this.Hide();
Con.Close();
}
else
{
MessageBox.Show("Wrong Username and Password");
}
Con.Close();
}
}
}
Books Page Code
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 Book_Shop_Management_System
{
public partial class Books : Form
{
public Books()
{
InitializeComponent();
}
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Documents\BookShopDatabase.mdf;Integrated Security=True;Connect Timeout=30″);
private void btnUsers_Click(object sender, EventArgs e)
{
Users Obj = new Users();
Obj.Show();
this.Hide();
}
private void btnDashboard_Click(object sender, EventArgs e)
{
Dashboard Obj = new Dashboard();
Obj.Show();
this.Hide();
}
private void btnLogout_Click(object sender, EventArgs e)
{
User_Login Obj = new User_Login();
Obj.Show();
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void DisplayBooks()
{
Con.Open();
string query = "select * from BooksTbl";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new DataSet();
sda.Fill(ds);
DGVBooks.DataSource = ds.Tables[0];
Con.Close();
}
private void Reset()
{
txtBookTitle.Text = "";
txtAuthorName.Text = "";
CbSelectCategory.SelectedIndex = -1;
txtQuantity.Text = "";
txtPrice.Text = "";
}
private void FilterByCategory()
{
Con.Open();
string query = "select * from BooksTbl where Category = '"+CbFilterByCategory.SelectedItem.ToString()+"'";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new DataSet();
sda.Fill(ds);
DGVBooks.DataSource = ds.Tables[0];
Con.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (txtBookTitle.Text == "" || txtAuthorName.Text == "" || CbSelectCategory.SelectedIndex == -1 || txtQuantity.Text == "" || txtPrice.Text == "")
{
MessageBox.Show("Missing Information");
}
else
{
try
{
Con.Open();
string query = "insert into BooksTbl values('" + txtBookTitle.Text + "','" + txtAuthorName.Text + "','" + CbSelectCategory.SelectedItem.ToString() + "'," + txtQuantity.Text + "," + txtPrice.Text + ")";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Book Added Successfully");
Con.Close();
DisplayBooks();
Reset();
}catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void Books_Load(object sender, EventArgs e)
{
DisplayBooks();
}
int Key = 0;
private void DGVBooks_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtBookTitle.Text = DGVBooks.SelectedRows[0].Cells[1].Value.ToString();
txtAuthorName.Text = DGVBooks.SelectedRows[0].Cells[2].Value.ToString();
CbSelectCategory.SelectedItem = DGVBooks.SelectedRows[0].Cells[3].Value.ToString();
txtQuantity.Text = DGVBooks.SelectedRows[0].Cells[4].Value.ToString();
txtPrice.Text = DGVBooks.SelectedRows[0].Cells[5].Value.ToString();
if(txtBookTitle.Text == "")
{
Key = 0;
}else
{
Key = Convert.ToInt32(DGVBooks.SelectedRows[0].Cells[0].Value.ToString());
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (txtBookTitle.Text == "" || txtAuthorName.Text == "" || CbSelectCategory.SelectedIndex == -1 || txtQuantity.Text == "" || txtPrice.Text == "")
{
MessageBox.Show("Missing Information");
}
else
{
try
{
Con.Open();
string query = "update BooksTbl set Title ='" + txtBookTitle.Text + "',Author = '" + txtAuthorName.Text + "',Category = '" + CbSelectCategory.SelectedItem.ToString() + "',Quantity = " + txtQuantity.Text + ",Price = " + txtPrice.Text + " where BookId = "+Key+";";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Book Updated Successfully");
Con.Close();
DisplayBooks();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (Key ==0)
{
MessageBox.Show("Missing Information");
}
else
{
try
{
Con.Open();
string query = "delete from BooksTbl where BookId = " + Key + ";";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Book Deleted Successfully");
Con.Close();
DisplayBooks();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void btnReset_Click(object sender, EventArgs e)
{
Reset();
}
private void btnRefresh_Click(object sender, EventArgs e)
{
DisplayBooks();
CbFilterByCategory.SelectedIndex = -1;
}
private void CbFilterByCategory_SelectionChangeCommitted(object sender, EventArgs e)
{
FilterByCategory();
}
}
}
User Page Code
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 Book_Shop_Management_System
{
public partial class Users : Form
{
public Users()
{
InitializeComponent();
}
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Documents\BookShopDatabase.mdf;Integrated Security=True;Connect Timeout=30″);
private void DisplayUsers()
{
Con.Open();
string query = "select * from UsersTbl";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
var ds = new DataSet();
sda.Fill(ds);
DGVUsers.DataSource = ds.Tables[0];
Con.Close();
}
private void Reset()
{
txtUsername.Text = "";
txtPhone.Text = "";
txtAddress.Text = "";
txtPassword.Text = "";
}
private void btnBooks_Click(object sender, EventArgs e)
{
Books Obj = new Books();
Obj.Show();
this.Hide();
}
private void btnDashboard_Click(object sender, EventArgs e)
{
Dashboard Obj = new Dashboard();
Obj.Show();
this.Hide();
}
private void btnLogout_Click(object sender, EventArgs e)
{
User_Login Obj = new User_Login();
Obj.Show();
this.Hide();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (txtUsername.Text == "" || txtPhone.Text == "" || txtAddress.Text == "" || txtPassword.Text == "")
{
MessageBox.Show("Missing Information");
}
else
{
try
{
Con.Open();
string query = "insert into UsersTbl values('" + txtUsername.Text + "','" + txtPhone.Text + "','" + txtAddress.Text + "','" + txtPassword.Text + "')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("User Added Successfully");
Con.Close();
DisplayUsers();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void Users_Load(object sender, EventArgs e)
{
DisplayUsers();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (txtUsername.Text == "" || txtPhone.Text == "" || txtAddress.Text == "" || txtPassword.Text == "")
{
MessageBox.Show("Missing Information");
}
else
{
try
{
Con.Open();
string query = "update UsersTbl set Username = '" + txtUsername.Text + "',UserPhone = '" + txtPhone.Text + "',UserAddress = '" + txtAddress.Text + "',UserPassword = '" + txtPassword.Text + "' where UserId = "+Key+";";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("User Updated Successfully");
Con.Close();
DisplayUsers();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
int Key = 0;
private void DGVUsers_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtUsername.Text = DGVUsers.SelectedRows[0].Cells[1].Value.ToString();
txtPhone.Text = DGVUsers.SelectedRows[0].Cells[2].Value.ToString();
txtAddress.Text = DGVUsers.SelectedRows[0].Cells[3].Value.ToString();
txtPassword.Text = DGVUsers.SelectedRows[0].Cells[4].Value.ToString();
if (txtUsername.Text == "")
{
Key = 0;
}
else
{
Key = Convert.ToInt32(DGVUsers.SelectedRows[0].Cells[0].Value.ToString());
}
}
private void btnReset_Click(object sender, EventArgs e)
{
Reset();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (Key == 0)
{
MessageBox.Show("Missing Information");
}
else
{
try
{
Con.Open();
string query = "delete from UsersTbl where UserId = " + Key + ";";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("User Deleted Successfully");
Con.Close();
DisplayUsers();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
}
}
Dashboard Page Code
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 Book_Shop_Management_System
{
public partial class Dashboard : Form
{
public Dashboard()
{
InitializeComponent();
}
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Documents\BookShopDatabase.mdf;Integrated Security=True;Connect Timeout=30″);
private void btnBooks_Click(object sender, EventArgs e)
{
Books Obj = new Books();
Obj.Show();
this.Hide();
}
private void btnUsers_Click(object sender, EventArgs e)
{
Users Obj = new Users();
Obj.Show();
this.Hide();
}
private void btnLogout_Click(object sender, EventArgs e)
{
User_Login Obj = new User_Login();
Obj.Show();
this.Hide();
}
private void TotalBooks()
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select sum(Quantity) from BooksTbl", Con);
DataTable dt = new DataTable();
sda.Fill(dt);
lblTotalBooks.Text = dt.Rows[0][0].ToString();
Con.Close();
}
private void TotalUsers()
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select count(Username) from UsersTbl", Con);
DataTable dt = new DataTable();
sda.Fill(dt);
lblTotalUsers.Text = dt.Rows[0][0].ToString();
Con.Close();
}
private void TotalAmount()
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select sum(Amount) from BillsTbl", Con);
DataTable dt = new DataTable();
sda.Fill(dt);
lblTotalAmount.Text = dt.Rows[0][0].ToString();
Con.Close();
}
private void Dashboard_Load(object sender, EventArgs e)
{
TotalBooks();
TotalUsers();
TotalAmount();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}