BOOK INVENTORY SYSTEM
Login Panel
Coding is so simple so u can design it by yourself
OPTION PANEL
Here just two Buttons u can Also Design it by your self
ADMIN PANEL
(ADD + UPDATE + DELETE + SEARCH )
Designing of Admin Panel
Create Table (itemtable) In Management Studio
1. name nvarchar(50)
2. Price nvarchar(50)
Create Two Store Procedure In Management Studio
FOR ADDING BOOK
Create procedure inventorytable
(
@name nvarchar(50),
@price nvarchar(50)
)
As
BEGIN
insert into dbo.itemtable
values (@name,@price)
END
FOR UPDATING BOOK
ALTER procedure updaterecored
(
@name nvarchar(50),
@price nvarchar(50)
)
As
begin
Update [dbo].[itemtable]
SET price = @price
where name = @name
end
Coding in visual studio
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace inventory
{
public partial class Additem : MetroForm
{
public Additem()
{
InitializeComponent();
}
private void Additem_Load(object sender, EventArgs e)
{
fillcombo();
}
private void add_Click(object sender, EventArgs e)
{
}
void fillcombo()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string Query = "select * FROM itemtable ";
SqlCommand cmd = new SqlCommand(Query, conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string books = (string)reader["name"];
comboBox1.Items.Add(books);
}
}
catch (Exception ex)
{
MessageBox.Show("error :" + ex.Message);
}
}
private void metroButton1_Click(object sender, EventArgs e)
{
}
private void Addbtn_Click(object sender, EventArgs e)
{
try
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("inventorytable", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = comboBox1.Text;
cmd.Parameters.Add("@price", SqlDbType.NVarChar, 50).Value = textBox2.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("items added");
clear();
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
clear();
comboBox1.Items.Clear();
fillcombo();
}
private void clear()
{
comboBox1.Text = "";
textBox2.Text = "";
}
private void search_Click(object sender, EventArgs e)
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("find", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("name", SqlDbType.NVarChar, 50).Value = comboBox1.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
using (reader)
{
reader.Read();
textBox2.Text = (string)reader["price"];
}
conn.Close();
}
private void metroButton5_Click(object sender, EventArgs e)
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
string data = "delete FROM itemtable WHERE name='" + this.comboBox1.Text + "'";
SqlConnection conn = new SqlConnection(connString);
using (conn)
{
SqlCommand cmd = new SqlCommand(data, conn);
conn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("del");
}
clear();
comboBox1.Items.Clear();
fillcombo();
}
private void update_Click(object sender, EventArgs e)
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
try
{
SqlCommand cmd = new SqlCommand("updaterecored", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@name", SqlDbType.NVarChar, 100).Value = comboBox1.Text;
cmd.Parameters.Add("@price", SqlDbType.NVarChar, 50).Value = textBox2.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Updated");
}
catch (Exception ex)
{
MessageBox.Show("Error :" + ex.Message);
}
clear();
}
}
}
Sales man Form
Designing of sales Man Form
Create Table (schoolnames) In Management Studio
1. school nvarchar(100)
Create store Procedure Schools
Create procedure schools
(
@school nvarchar(100)
)
As
begin
insert into dbo.schoolnames
values (@school)
end
Coding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace inventory
{
public partial class salesman : MetroForm
{
public int n;
string scl,label;
double dis,sum=0;
public string []name = new string[100];
public string[] Q = new string[100];
public string[] p = new string[100];
public salesman()
{
InitializeComponent();
}
private void salesman_Load(object sender, EventArgs e)
{
fillcombo();
fillschool();
}
private void metroScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
scl = comboBox1.Text;
}
private void add_Click(object sender, EventArgs e)
{
bool readerHasRows = false;
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string commandQuery = "SELECT school FROM schoolnames WHERE school = @school";
using (SqlCommand cmd = new SqlCommand(commandQuery, conn))
{
cmd.Parameters.AddWithValue("school", comboBox1.Text);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
using (reader)
{
readerHasRows = (reader != null && reader.HasRows);
}
conn.Close();
}
if (readerHasRows)
{
MessageBox.Show("Name already exsist");
}
else
{
try
{
SqlCommand cmd = new SqlCommand("schools", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@school", SqlDbType.NVarChar, 50).Value = comboBox1.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("items added");
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
}
}
private void label1_Click(object sender, EventArgs e)
{
}
void fillcombo()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string Query = "select * FROM itemtable ";
SqlCommand cmd = new SqlCommand(Query, conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string books = (string)reader["name"];
comboBox2.Items.Add(books);
}
}
catch (Exception ex)
{
MessageBox.Show("error :"+ ex.Message);
}
}
void fillschool()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string Query = "select * FROM schoolnames ";
SqlCommand cmd = new SqlCommand(Query, conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string books = (string)reader["school"];
comboBox1.Items.Add(books);
}
}
catch (Exception ex)
{
MessageBox.Show("error :" + ex.Message);
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
void price()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("find", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("name", SqlDbType.NVarChar, 50).Value = comboBox2.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
using (reader)
{
reader.Read();
double price = double.Parse((string)reader["price"]) * double.Parse(textBox2.Text);
dis = double.Parse(textBox3.Text);
dis = price * (dis / 100);
dis = price - dis;
dataGridView1.Rows[n].Cells[2].Value = double.Parse((string)reader["price"]) * double.Parse(textBox2.Text);
dataGridView1.Rows[n].Cells[4].Value = dis;
sum += dis;
}
conn.Close();
}
private void bill_Click(object sender, EventArgs e)
{
label = comboBox1.Text;
bills form = new bills(name,Q,p,n,label,sum);
form.ShowDialog();
}
private void gri_Click(object sender, EventArgs e)
{
n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = comboBox2.Text ;
dataGridView1.Rows[n].Cells[1].Value = textBox2.Text;
dataGridView1.Rows[n].Cells[3].Value = textBox3.Text + "%";
price();
name[n] = comboBox2.Text;
Q[n] = textBox2.Text;
p[n] = dis.ToString();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace inventory
{
public partial class salesman : MetroForm
{
public int n;
string scl,label;
double dis,sum=0;
public string []name = new string[100];
public string[] Q = new string[100];
public string[] p = new string[100];
public salesman()
{
InitializeComponent();
}
private void salesman_Load(object sender, EventArgs e)
{
fillcombo();
fillschool();
}
private void metroScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
scl = comboBox1.Text;
}
private void add_Click(object sender, EventArgs e)
{
bool readerHasRows = false;
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string commandQuery = "SELECT school FROM schoolnames WHERE school = @school";
using (SqlCommand cmd = new SqlCommand(commandQuery, conn))
{
cmd.Parameters.AddWithValue("school", comboBox1.Text);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
using (reader)
{
readerHasRows = (reader != null && reader.HasRows);
}
conn.Close();
}
if (readerHasRows)
{
MessageBox.Show("Name already exsist");
}
else
{
try
{
SqlCommand cmd = new SqlCommand("schools", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@school", SqlDbType.NVarChar, 50).Value = comboBox1.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("items added");
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
}
}
private void label1_Click(object sender, EventArgs e)
{
}
void fillcombo()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string Query = "select * FROM itemtable ";
SqlCommand cmd = new SqlCommand(Query, conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string books = (string)reader["name"];
comboBox2.Items.Add(books);
}
}
catch (Exception ex)
{
MessageBox.Show("error :"+ ex.Message);
}
}
void fillschool()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string Query = "select * FROM schoolnames ";
SqlCommand cmd = new SqlCommand(Query, conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string books = (string)reader["school"];
comboBox1.Items.Add(books);
}
}
catch (Exception ex)
{
MessageBox.Show("error :" + ex.Message);
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
void price()
{
string connString = ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("find", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("name", SqlDbType.NVarChar, 50).Value = comboBox2.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
using (reader)
{
reader.Read();
double price = double.Parse((string)reader["price"]) * double.Parse(textBox2.Text);
dis = double.Parse(textBox3.Text);
dis = price * (dis / 100);
dis = price - dis;
dataGridView1.Rows[n].Cells[2].Value = double.Parse((string)reader["price"]) * double.Parse(textBox2.Text);
dataGridView1.Rows[n].Cells[4].Value = dis;
sum += dis;
}
conn.Close();
}
private void bill_Click(object sender, EventArgs e)
{
label = comboBox1.Text;
bills form = new bills(name,Q,p,n,label,sum);
form.ShowDialog();
}
private void gri_Click(object sender, EventArgs e)
{
n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = comboBox2.Text ;
dataGridView1.Rows[n].Cells[1].Value = textBox2.Text;
dataGridView1.Rows[n].Cells[3].Value = textBox3.Text + "%";
price();
name[n] = comboBox2.Text;
Q[n] = textBox2.Text;
p[n] = dis.ToString();
}
}
}
Billing FORM
Coding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using System.Drawing.Printing;
using System.Drawing.Design;
namespace inventory
{
public partial class bills : MetroForm
{
int b;
public bills(string [] name,string[] Q,string[] p,int n,string lab,double sum)
{
InitializeComponent();
for (int a = 0; a <= n; a++)
{
b = dataGridView1.Rows.Add();
dataGridView1.Rows[b].Cells[0].Value = name[a];
dataGridView1.Rows[b].Cells[1].Value = Q[a];
dataGridView1.Rows[b].Cells[2].Value = p[a];
}
label3.Text = lab;
textBox.Text = sum.ToString();
}
public void bill_Load(object sender, EventArgs e)
{
dat.Text = DateTime.Now.ToString("dd-MM-yyyy");
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void print_Click(object sender, EventArgs e)
{
printPreviewDialog.ShowDialog();
}
int i = 0;
private void printPreviewDialog_Load(object sender,PrintPageEventArgs e)
{
}
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int height = 0;
int width = 0;
Pen pen = new Pen(Brushes.Black, 2.5f);
#region BookNamecol
e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
#endregion
#region Quantitycol
e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[1].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
#endregion
#region Pricecol
e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(200 + dataGridView1.Columns[0].Width,100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[2].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
#endregion
height = 100;
while (i < dataGridView1.Rows.Count)
{
height += dataGridView1.Rows[0].Height;
e.Graphics.DrawRectangle(pen, new Rectangle(100,height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(),dataGridView1.Font,Brushes.Black, new Rectangle(100,height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(100 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(200 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(200 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
i++;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using System.Drawing.Printing;
using System.Drawing.Design;
namespace inventory
{
public partial class bills : MetroForm
{
int b;
public bills(string [] name,string[] Q,string[] p,int n,string lab,double sum)
{
InitializeComponent();
for (int a = 0; a <= n; a++)
{
b = dataGridView1.Rows.Add();
dataGridView1.Rows[b].Cells[0].Value = name[a];
dataGridView1.Rows[b].Cells[1].Value = Q[a];
dataGridView1.Rows[b].Cells[2].Value = p[a];
}
label3.Text = lab;
textBox.Text = sum.ToString();
}
public void bill_Load(object sender, EventArgs e)
{
dat.Text = DateTime.Now.ToString("dd-MM-yyyy");
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void print_Click(object sender, EventArgs e)
{
printPreviewDialog.ShowDialog();
}
int i = 0;
private void printPreviewDialog_Load(object sender,PrintPageEventArgs e)
{
}
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int height = 0;
int width = 0;
Pen pen = new Pen(Brushes.Black, 2.5f);
#region BookNamecol
e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
#endregion
#region Quantitycol
e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[1].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
#endregion
#region Pricecol
e.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(200 + dataGridView1.Columns[0].Width,100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[2].HeaderText.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(200 + dataGridView1.Columns[0].Width, 100, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
#endregion
height = 100;
while (i < dataGridView1.Rows.Count)
{
height += dataGridView1.Rows[0].Height;
e.Graphics.DrawRectangle(pen, new Rectangle(100,height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(),dataGridView1.Font,Brushes.Black, new Rectangle(100,height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(100 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(100 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(pen, new Rectangle(200 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new Rectangle(200 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
i++;
}
}
}
}
0 comments:
Post a Comment