Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 65

B. M. S.

COLLEGE OF ENGINEERING
Bengaluru-560019

MASTER OF COMPUTER APPLICATIONS

C#.Net AAT

BAKERY INVENTORY SYSTEM

SUBMITTED BY
Gautam Raj Kumawat
(USN-1BM19MCA16)
  Shubhra Debnath
(USN-1BF19MCA15)
COURSE CODE
18MCA5PCWP
UNDER THE GUIDANCE OF
  Dr. Ch. Ram Mohan Reddy

MCA Dept, BMSCE Page 1


B. M. S. COLLEGE OF ENGINEERING
Bengaluru-560019

MASTER OF COMPUTER APPLICATIONS

CERTIFICATE
This is to certify that, the Record is a Bonafede work carried out by Gautam
Raj Kumawat and Shubhra Debnath, students of Master of Computer
Applications Department, B. M. S. Collage of Engineering for C#.Net AAT. This
report has been submitted during the academic year 2021-22 in partial
fulfilment of the requirement of the degree of Master of Computer
Applications 5th Semester.

Signature of Supervisor: Dr. S. Uma


Name of Supervisor: HOD, Department of MCA
Dr. Ch. Ram Mohan Reddy
Date:
ACKNOWLEDGEMENT

It gives us a great sense of pleasure to present the report of the MCA


AAT Project undertaken during MCA fifth semester. This project would
never have seen the light of the day without the help and guidance that
we have received.
Our heartfelt thanks to Dr. B. V. Ravishankar, Principal of BMSCE and
Dr.S.Uma, Head of Dept of MCA for providing us with an encouraging
platform to develop this project, which helped us in shaping our
abilities towards a constructive goal. We owe a special debt of gratitude
to Dr. Ch. Ram Mohan Reddy for his constant support and guidance
throughout the course of our work. His sincerity, thoroughness and
perseverance have been a constant source of inspiration for us. He has
showered us with all his extensively experienced ideas and insightful
comments at virtually all stages.

Gautam Raj Kumawat,


Shubhra Debnath
CONTENTS

Abstract 5

Hardware and Software


6
Requirements

UML Diagrams 7-9

Modules 10

Coding 11-57

Screenshots 58-62

Conclusion 63

Bibliography 64
ABSTRACT
This Bakery Inventory System was developed using C# and MS Access
Database in .NET Framework. The system has a security feature that requires
user credentials in order for business management or the system's person in
charge can manage the data in the system. The user can manage the list of
products (bread, cake, and pastries) along with some details that are relevant
for this system. The products should have available stock in order for them to
be stock out. The system has also an error trapping feature that prevents the
user from stock out the product without sufficient stock availability. The
bakery inventory system generates printable Inventory reports for all the
products. It is easy to use and has user-friendly functionalities.
HARDWARE AND
SOFTWARE
REQUIREMENTS

Hardware Requirements:
 Processor – i3 7th gen at 3.3 Ghz or above
 RAM – 4 GB or above
 Hard Disk – 500 GB or above

Software Requirements:

 In order to run the project, you must have installed Visual


Studio (2015 or above) and MS Access (2010 or above).
 Programming Language Used – C#
 Framework - .NET, ADO.NET
 Operating System – Windows 7 or above
UML DIAGRAMS
USE CASE DIAGRAM:
ACTIVITY DIAGRAM:
CLASS DIAGRAM:
MODULES
 Secure Login and Logout - The application allows the user to login and
logout through a secure medium. It authenticates and validates every
user based on his/her user id and password. After completing work
users can logout.
 Manage List of Products – The users can manage the type of products
like cake, bread and pastries. They can add new product under these
subcategories, delete a product, view list of products.
 Stock-In - Stock-in or refill stock of a product.
 Stock-Out – Stock-out or sell a product based on its availability.
 Manage Users – The admins can manage other users. New users can be
added or users can be deleted.
 Generate Inventory Report – Report about the inventory can be
generated based on a category of product. The report shows stock-in
and sold history of the products over a day, week or month.
 Prevent Stocking Out insufficient availability – If the user wants to sell
a product which is out of stock, a proper “out of stock” message is
shown to the user.
 Categorized Product List – The products can be viewed in a categorized
manner like bread and the various bread products etc.
CODING
Form1.cs
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 BakeryInventorySystem.Properties;

namespace BakeryInventorySystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void shwfrm( Form frm)
{
frm.ShowDialog();
}

public void enable_menu()


{
tsBread.Enabled = true;
tsListofProducts.Enabled = true;
tsLogin.Text = "Logout";
tsLogin.Image = Properties.Resources.logout;
tsReport.Enabled = true;
tsStockin.Enabled = true;
tsStockout.Enabled = true;
tsUser.Enabled = true;

private void disable_menu()


{
tsBread.Enabled = false;
tsListofProducts.Enabled = false;
tsLogin.Text = "Login";
tsLogin.Image = Properties.Resources.login;
tsReport.Enabled = false;
tsStockin.Enabled = false;
tsStockout.Enabled = false;
tsUser.Enabled = false;

}
private void Form1_Load(object sender, EventArgs e)
{
disable_menu();
}

private void tsBread_Click(object sender, EventArgs e)


{
shwfrm(new frmProduct());
}

private void tsListofProducts_Click(object sender, EventArgs e)


{
shwfrm(new frmListofProducts());
}

private void tsStockin_Click(object sender, EventArgs e)


{
shwfrm(new frmStockin());
}

private void tsStockout_Click(object sender, EventArgs e)


{
shwfrm(new frmStockout());
}

private void tsUser_Click(object sender, EventArgs e)


{
shwfrm(new frmUser());
}

private void tsReport_Click(object sender, EventArgs e)


{
shwfrm(new frmInventoryReports());
}
private void tsLogin_Click(object sender, EventArgs e)
{
if(tsLogin.Text == "Login")
{
shwfrm(new frmLogin(this));
}
else
{
disable_menu();
}

}
}
}

frmEditProduct.cs
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 BakeryInventorySystem
{
public partial class frmEditProduct : Form
{
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string sql;
int maxrow;
frmListofProducts frm;

public frmEditProduct(string id,frmListofProducts frm)


{
InitializeComponent();

retrieveProduct(id);
this.frm = frm;
}
private void retrieveProduct(string id)
{

sql = "SELECT PROCODE,PRONAME,PRODESC,CATEGORY, PROPRICE FROM tblProductInfo


WHERE PROCODE='" + id + "'";
maxrow = config.maxrow(sql);

if(maxrow > 0)
{
foreach(DataRow r in config.dt.Rows)
{
txtPROCODE.Text = r.Field<string>(0);
TXTPRONAME.Text = r.Field<string>(1);
TXTDESC.Text = r.Field<string>(2);
cboCateg.Text = r.Field<string>(3);
TXTPRICE.Text = r.Field<decimal>(4).ToString();
}

}
private void frmEditProduct_Load(object sender, EventArgs e)
{

private void BTNSAVE_Click(object sender, EventArgs e)


{
sql = "UPDATE tblProductInfo SET PRONAME='" + TXTPRONAME.Text +
"' ,PRODESC='" + TXTDESC.Text +
"',CATEGORY='" + cboCateg.Text +
"',PROPRICE=" + TXTPRICE.Text + " WHERE PROCODE='" + txtPROCODE.Text + "'";
config.Execute_CUD(sql, "Error to update Bread.", "Bread Has Been Updated.");
}

private void btnList_Click(object sender, EventArgs e)


{
frm.refresh();
this.Close();
}
}
}
frmInventoryReports.cs
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 BakeryInventorySystem
{
public partial class frmInventoryReports : Form
{
public frmInventoryReports()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string query;
int maxrow;

private void RDOSELECT(RadioButton RDO)


{
if (RDO.Checked)
{
switch (RDO.Text)
{
case "All" :
query = "SELECT P.PROCODE AS [ProductCode], (PRONAME + ' ' + PRODESC) AS
[Product],CATEGORY AS [Category], PROPRICE AS [Price],PROQTY AS [Quantity] " +
" FROM tblProductInfo AS P WHERE CATEGORY ='" + cboCateg.Text + "' AND
PRONAME LIKE '%" + txtSearch.Text + "%'";

break;
case "Stock-In":
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product], PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE AND
CATEGORY ='" + cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
break;
case "Sold" :
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product], PROPRICE AS [Price],OUTQTY AS
[Quantity],(ROUND(OUTQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE AND
CATEGORY ='" + cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
break;
case "Today":

if( RDO.Text == "Stock-In")


{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product], PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATERECEIVED) = NOW() AND
PRODESC LIKE '%" + txtSearch.Text + "%' AND PRONAME LIKE '%" + txtSearch.Text + "%'";

}
else if (RDO.Text == "Sold")
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product],('Net/VolWt:' + PRONETWT ) AS
[Description],PROPRICE as Price,(OUTQTY + PROUNIT) AS [Quantity],(ROUND(OUTQTY * PROPRICE)) AS
[TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE AND
DATEVALUE(DATERECEIVED) = NOW() AND CATEGORY ='" + cboCateg.Text + "' AND PRONAME LIKE '%"
+ txtSearch.Text + "%'";

}
break;
case "Weekly":
if (RDO.Text == "Stock-In") {
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW())
AND DATEVALUE(DATEPART(ww,DATEOUT)) = DATEVALUE(DATEPART(ww,NOW())) AND PRODESC LIKE
'%" + txtSearch.Text + "%' AND PRONAME LIKE '%" + txtSearch.Text + "%'";

} else if (RDO.Text == "Sold") {


query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product],('Net/VolWt:' + PRONETWT ) AS
[Description],PROPRICE as Price,(OUTQTY + PROUNIT) AS [Quantity],(ROUND(OUTQTY * PROPRICE)) AS
[TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW())
AND DATEVALUE(DATEPART(ww,DATEOUT)) = DATEVALUE(DATEPART(ww,NOW())) AND CATEGORY
='" + cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
}
break;
case "Monthly":
if( RDO.Text == "Stock-In")
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW())
AND PRODESC LIKE '%" + txtSearch.Text + "%' AND PRONAME LIKE '%" + txtSearch.Text + "%'";

}
else if (RDO.Text == "Sold")
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product],('Net/VolWt:' + PRONETWT) AS
[Description],PROPRICE as Price,(OUTQTY + PROUNIT) AS [Quantity],(ROUND(OUTQTY * PROPRICE)) AS
[TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW()) AND
CATEGORY ='" + cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text + "%'";

}
break;

config.Load_DTG(query, dtglist);
}
}

private void RDOCLEAR(string ACTIONS,RadioButton rdo)


{
if (rdo.Checked)
{
switch (ACTIONS)
{
case "Product":
rdoProduct.Checked = false;
break;
case "Transaction":
rdoStockIn.Checked = false;
rdoStockOut.Checked = false;
rdoMonthly.Checked = false;
rdoWeekly.Checked = false;
rdoToday.Checked = false;
break;
}

if( rdo.Text != "Today" && rdo.Text != "21 days" && rdo.Text != "Weekly" && rdo.Text !=
"Monthly")
{
LBLLIST.Text = "List of " + rdo.Text + " (" + cboCateg.Text + ")";
}

}
}
private void RDOCLEARDATE()
{
rdoMonthly.Checked = false;
rdoWeekly.Checked = false;
rdoToday.Checked = false;
}

private void frmInventoryReports_Load(object sender, EventArgs e)


{
RDOCLEAR("Transaction", rdoProduct);
LBLLIST.Text = "List of Products (" + cboCateg.Text + ")";

RDOSELECT(rdoProduct);
}

private void rdoProduct_CheckedChanged(object sender, EventArgs e)


{
RDOCLEAR("Transaction", rdoProduct);
LBLLIST.Text = "List of Products (" + cboCateg.Text + ")";

RDOSELECT(rdoProduct);
}

private void rdoStockIn_CheckedChanged(object sender, EventArgs e)


{
RDOCLEAR("Product", rdoStockIn);
RDOCLEARDATE();
RDOSELECT(rdoStockIn);
}

private void rdoStockOut_CheckedChanged(object sender, EventArgs e)


{
RDOCLEAR("Product", rdoStockOut);
RDOCLEARDATE();
RDOSELECT(rdoStockOut);
}

private void rdoToday_CheckedChanged(object sender, EventArgs e)


{

if(rdoStockIn.Checked)
{
RDOCLEAR("Product", rdoStockIn);
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATERECEIVED) = DATEVALUE(NOW())
AND PRODESC LIKE '%" + txtSearch.Text + "%' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
config.Load_DTG(query, dtglist);
}
else if (rdoStockOut.Checked)
{
RDOCLEAR("Product", rdoStockOut);
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS [TransactionDate],
(PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],OUTQTY AS [Quantity],(ROUND(OUTQTY
* PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE AND
DATEVALUE(DATEOUT) =DATEVALUE(NOW()) AND CATEGORY ='" + cboCateg.Text + "' AND PRONAME
LIKE '%" + txtSearch.Text + "%'";
config.Load_DTG(query, dtglist);
}
}

private void rdoWeekly_CheckedChanged(object sender, EventArgs e)


{

if (rdoStockIn.Checked)
{
RDOCLEAR("Product", rdoStockIn);
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW()) AND
PRODESC LIKE '%" + txtSearch.Text + "%' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
config.Load_DTG(query, dtglist);
}
else if (rdoStockOut.Checked)
{
RDOCLEAR("Product", rdoStockOut);
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS [TransactionDate],
(PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],OUTQTY AS [Quantity],(ROUND(OUTQTY
* PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATEOUT) = MONTH(NOW()) AND
DatePart('ww',DATEVALUE(DATEOUT))= DatePart('ww',DATEVALUE(NOW())) AND CATEGORY ='" +
cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text + "%'";

config.Load_DTG(query, dtglist);
}

private void rdoMonthly_CheckedChanged(object sender, EventArgs e)


{

if (rdoStockIn.Checked)
{
RDOCLEAR("Product", rdoStockIn);
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW()) AND
PRODESC LIKE '%" + txtSearch.Text + "%' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
config.Load_DTG(query, dtglist);
}
else if (rdoStockOut.Checked)
{
RDOCLEAR("Product", rdoStockOut);
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS [TransactionDate],
(PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],OUTQTY AS [Quantity],(ROUND(OUTQTY
* PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATEOUT) = MONTH(NOW()) AND CATEGORY
='" + cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text + "%'";
config.Load_DTG(query, dtglist);
}
}

private void btnSearch_Click(object sender, EventArgs e)


{
if( rdoProduct.Checked)
{
rdoStockOut.Checked = true;
}

DateTime dfrom = DateTime.Parse(dtpFrom.Text);


DateTime dto = DateTime.Parse(dtpTo.Text);

if( rdoStockIn.Checked)
{
LBLLIST.Text = "Stock of " + cboCateg.Text + " from " + dfrom + " to " + dto;
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATERECEIVED) BETWEEN #" + dfrom +
"# AND #" + dto + "# AND PRODESC LIKE '%" + txtSearch.Text + "%' AND PRONAME LIKE '%" +
txtSearch.Text + "%'";
config.Load_DTG(query, dtglist);
}
else if (rdoStockOut.Checked)
{
LBLLIST.Text = "Sold " + cboCateg.Text + " from " + dfrom + " to " + dto;
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS [TransactionDate],
(PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],OUTQTY AS [Quantity],(ROUND(OUTQTY
* PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATEOUT) BETWEEN #" + dfrom + "#
AND #" + dto + "# AND CATEGORY ='" + cboCateg.Text + "' AND PRONAME LIKE '%" + txtSearch.Text +
"%'";
config.Load_DTG(query, dtglist);
}

private void BTNSEARCHGRID_Click(object sender, EventArgs e)


{
RDOCLEAR("Transaction", rdoProduct);

LBLLIST.Text = "List of Products (" + cboCateg.Text + ")";

RDOSELECT(rdoProduct);
}

private void btnClose_Click(object sender, EventArgs e)


{
this.Close();
}

private void btnpreview_Click(object sender, EventArgs e)


{
Form frm = new frmPrint(LBLLIST.Text, cboCateg.Text, dtpFrom.Text, dtpTo.Text, txtSearch.Text
, rdoToday, rdoWeekly, rdoMonthly, rdoStockIn, rdoStockOut, rdoProduct);
frm.Show();

}
}
}

frmListofProducts.cs
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 BakeryInventorySystem
{
public partial class frmListofProducts : Form
{
public frmListofProducts()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string sql;
int maxrow;
private void btnNew_Click(object sender, EventArgs e)
{
Form frm = new frmProduct();
frm.ShowDialog();
}

public void refresh()


{
sql = "SELECT PROCODE as [ProductCode], (PRONAME + ' ' + PRODESC) AS [Product],CATEGORY
AS [Category], (PROPRICE) AS [Price],PROQTY AS [Quantity] FROM tblProductInfo";
config.Load_DTG(sql, DTGLIST);
}

private void btnRefresh_Click(object sender, EventArgs e)


{
sql = "SELECT PROCODE as [ProductCode], (PRONAME + ' ' + PRODESC) AS [Product],CATEGORY
AS [Category], (PROPRICE) AS [Price],PROQTY AS [Quantity] FROM tblProductInfo";
config.Load_DTG(sql, DTGLIST);
}

private void Button1_Click(object sender, EventArgs e)


{
this.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
sql = "DELETE * FROM tblStockIn WHERE PROCODE = '" + DTGLIST.CurrentRow.Cells[0].Value +
"'";
config.Execute_Query(sql);

sql = "DELETE * FROM tblStockOut WHERE PROCODE = '" + DTGLIST.CurrentRow.Cells[0].Value +


"'";
config.Execute_Query(sql);

sql = "DELETE * FROM tblProductInfo WHERE PROCODE = '" + DTGLIST.CurrentRow.Cells[0].Value


+ "'";
config.Execute_CUD(sql, "Failed to delete", "Product has been deleted.");
}

private void btnEdit_Click(object sender, EventArgs e)


{
Form frm = new frmEditProduct(DTGLIST.CurrentRow.Cells[0].Value.ToString(),this);
frm.ShowDialog();
}

private void frmListofProducts_Load(object sender, EventArgs e)


{
btnRefresh_Click(sender, e);
}

private void TXTSEARCH_TextChanged(object sender, EventArgs e)


{

DTGLIST.Columns.Clear();

sql = "SELECT PROCODE as [ProductCode], (PRONAME + ' ' + PRODESC) AS [Product],CATEGORY


AS [Category], (PROPRICE) AS [Price],PROQTY AS [Quantity] FROM tblProductInfo WHERE (PROCODE +
' ' + PRONAME + ' ' + PRODESC + ' ' + CATEGORY) LIKE '%" + TXTSEARCH.Text + "%'";
config.Load_DTG(sql, DTGLIST);

}
}
}
frmListStockin.cs
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 BakeryInventorySystem
{
public partial class frmListStockin : Form
{
public frmListStockin()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string sql;
int maxrow;
private void btnNew_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnRefresh_Click(object sender, EventArgs e)


{
sql = "SELECT TRANSNUM AS [Transaction#], P.PROCODE as [ProductCode],PRONAME AS
[Product], PROPRICE as Price, (PRODESC + ' [' + CATEGORY + ']') AS [Description],DATERECEIVED AS
[TransactionDate],RECEIVEDQTY AS [Quantity], RECEIVEDTOTPRICE AS [TotalPrice] FROM tblStockIn as
S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE";
config.Load_DTG(sql, DTGLIST);
}

private void frmListStockin_Load(object sender, EventArgs e)


{
btnRefresh_Click(sender, e);
}

private void btnDelete_Click(object sender, EventArgs e)


{
string numtrans = DTGLIST.CurrentRow.Cells[0].Value.ToString();
int transnum = int.Parse(numtrans);
sql = "UPDATE tblProductInfo AS P, tblStockIn AS S SET PROQTY = PROQTY - RECEIVEDQTY
WHERE P.PROCODE=S.PROCODE AND TRANSNUM =" + transnum ;
config.Execute_Query(sql);

sql = "DELETE * FROM tblStockIn WHERE TRANSNUM = " + transnum ;


config.Execute_CUD(sql,"error to execute the query.","Transaction has been deleted.");

btnRefresh_Click(sender, e);
}

private void TXTSEARCH_TextChanged(object sender, EventArgs e)


{
sql = "SELECT TRANSNUM AS [Transaction#], P.PROCODE as [ProductCode], PRONAME AS
[Product],(PRODESC + ' [' + CATEGORY + ']') AS [Description],PROPRICE as [Price],DATERECEIVED AS
[TransactionDate],RECEIVEDQTY AS [Quantity], RECEIVEDTOTPRICE AS [TotalPrice] FROM tblStockIn as
S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE AND " +
" (P.PROCODE + ' ' + PRONAME + ' ' + PRODESC + ' ' + CATEGORY ) LIKE '%" +
TXTSEARCH.Text + "%'";
config.Load_DTG(sql, DTGLIST);
}

private void Button1_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

frmListStockout.cs
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 BakeryInventorySystem
{
public partial class frmListStockout : Form
{
public frmListStockout()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string query;
int maxrow;

private void btnRefresh_Click(object sender, EventArgs e)


{
query = " SELECT TRANSNUM AS [Transaction#],P.PROCODE as [ProductCode], PRONAME AS
[Product], CATEGORY AS [Category],DATEOUT AS [TransactionDate],OUTQTY AS
[Quantity],OUTTOTPRICE AS [Price] " +
" FROM tblStockOut as O, tblProductInfo AS P " +
" WHERE P.PROCODE=O.PROCODE AND (PRONAME + ' ' + PRODESC + ' ' + CATEGORY) LIKE '%"
+ TXTSEARCH.Text + "%'";
config.Load_DTG(query, DTGLIST);
}

private void TXTSEARCH_TextChanged(object sender, EventArgs e)


{
btnRefresh_Click(sender, e);
}

private void btnNew_Click(object sender, EventArgs e)


{
this.Close();
}

private void Button1_Click(object sender, EventArgs e)


{
this.Close();
}

private void btnDelete_Click(object sender, EventArgs e)


{
query = "UPDATE tblProductInfo AS P, tblStockOut AS S SET PROQTY = PROQTY + OUTQTY
WHERE P.PROCODE=S.PROCODE AND TRANSNUM = " + DTGLIST.CurrentRow.Cells[0].Value;
config.Execute_Query(query);

query = "DELETE * FROM tblStockOut WHERE TRANSNUM = " +


DTGLIST.CurrentRow.Cells[0].Value;
config.Execute_Query(query);

MessageBox.Show("Transaction has been deleted.");


btnRefresh_Click(sender, e);
}

private void frmListStockout_Load(object sender, EventArgs e)


{
btnRefresh_Click(sender, e);
}
}
}

frmLogin.cs
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 BakeryInventorySystem
{
public partial class frmLogin : Form
{
Form1 frm;
public frmLogin(Form1 frm)
{
InitializeComponent();
this.frm = frm;
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string query;
int maxrow;

private void frmLogin_Load(object sender, EventArgs e)


{

}
private void OK_Click(object sender, EventArgs e)
{
query = "SELECT * FROM tblUser WHERE U_UNAME ='" + UsernameTextBox.Text + "' AND
U_PASS = '" + PasswordTextBox.Text + "'";
maxrow = config.maxrow(query);

if(maxrow > 0)
{
MessageBox.Show("User successfully logged in");
frm.enable_menu();
this.Close();
}
else
{
MessageBox.Show("Account does not
exist!","Invalid",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}

private void Cancel_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

frmPrint.cs
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 BakeryInventorySystem
{
public partial class frmPrint : Form
{
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string query;
int maxrow;

private void reports(string sql, string rptname)


{

try
{

config.loadReports(sql);

string reportname = rptname;

CrystalDecisions.CrystalReports.Engine.ReportDocument reportdoc = new


CrystalDecisions.CrystalReports.Engine.ReportDocument(); ;

string strReportPath = Application.StartupPath + "\\reports\\" + reportname + ".rpt";

reportdoc.Load(strReportPath);
reportdoc.SetDataSource(config.dt);

crystalReportViewer1.ReportSource = reportdoc;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "No crystal reports installed. Pls. contact administrator.");
}

public frmPrint (string lbllist, string category,string dtpFrom,string dtpTo,string txtsearch,


RadioButton rdoToday,RadioButton rdoWeekly,RadioButton rdoMonthly,RadioButton
rdoStockIn,
RadioButton rdoStockOut,RadioButton rdoProduct)
{
InitializeComponent();
DateTime dfrom = DateTime.Parse(dtpFrom);
DateTime dto = DateTime.Parse(dtpTo);

if (lbllist == "Stock of " + category + " from " + dfrom + " to " + dto)
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],(PROPRICE) AS [Price],RECEIVEDQTY AS
[Quantity],((ROUND(RECEIVEDQTY * PROPRICE)) ) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATERECEIVED) BETWEEN #" + dfrom + "#
AND #" + dto + "# AND PRODESC LIKE '%" + txtsearch + "%' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "stockinasof");

}
else if (lbllist == "Sold " + category + " from " + dfrom + " to " + dto)
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS [TransactionDate],
(PRONAME + ' ' + PRODESC) AS [Product],(PROPRICE) AS [Price],OUTQTY AS [Quantity],
((ROUND(OUTQTY * PROPRICE))) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATEOUT) BETWEEN #" + dfrom + "#
AND #" + dto + "# AND CATEGORY ='" + category + "' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "stockoutasof");
}
else
{

if (rdoToday.Checked)
{
if(rdoStockIn.Checked)
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],(PROPRICE) AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND DATEVALUE(DATERECEIVED) =
DATEVALUE(NOW()) AND PRODESC LIKE '%" + txtsearch + "%' AND PRONAME LIKE '%" + txtsearch +
"%'";
reports(query, "dailystockin");
}
else
{
query = "SELECT TRANSNUM, P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product], (OUTQTY) AS [Quantity],PROPRICE as
[Price], (ROUND(OUTQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE
AND DATEVALUE(DATEOUT) = DATEVALUE(NOW()) AND CATEGORY ='" + category + "' AND PRONAME
LIKE '%" + txtsearch + "%'";
reports(query, "dailystockout");
}

}
else if (rdoWeekly.Checked)
{
if (rdoStockIn.Checked)
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE AS [Price],RECEIVEDQTY AS
[Quantity],(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW())
AND DATEPART('ww',DATEVALUE(DATERECEIVED)) = DATEPART('ww',DATEVALUE(NOW())) AND
PRODESC LIKE '%" + txtsearch + "%' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "weeklystockins");
}
else
{
query = "SELECT TRANSNUM, P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product], OUTQTY AS [Quantity],PROPRICE as
[Price], (ROUND(OUTQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATEOUT) = MONTH(NOW()) AND
DATEPART('ww',DATEVALUE(DATEOUT)) = DATEPART('ww',DATEVALUE(NOW())) AND CATEGORY ='" +
category + "' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "weeklystockout");
}
}
else if (rdoMonthly.Checked)
{
if (rdoStockIn.Checked)
{
query = "SELECT P.PROCODE AS [ProductCode],DATEVALUE(DATERECEIVED) AS
[ReceivedDate], (PRONAME + ' ' + PRODESC) AS [Product],PROPRICE,RECEIVEDQTY AS [Quantity],
(ROUND(RECEIVEDQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockIn AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATERECEIVED) = MONTH(NOW())
AND PRODESC LIKE '%" + txtsearch + "%' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "monthlystockin");
}
else
{
query = "SELECT TRANSNUM, P.PROCODE AS [ProductCode],DATEVALUE(DATEOUT) AS
[TransactionDate], (PRONAME + ' ' + PRODESC) AS [Product], (OUTQTY) AS [Quantity],PROPRICE as
[Price], (ROUND(OUTQTY * PROPRICE)) AS [TotalPrice] " +
" FROM tblStockOut AS S, tblProductInfo AS P " +
" WHERE S.PROCODE=P.PROCODE AND MONTH(DATEOUT) = MONTH(NOW()) AND
CATEGORY ='" + category + "' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "monthlystockout");
}
}
else
{
if( rdoProduct.Checked)
{
query = "SELECT * " +
" FROM tblProductInfo WHERE CATEGORY ='" + category + "' AND PRONAME LIKE
'%" + txtsearch + "%'";
reports(query, "listofproducts");
}
else if (rdoStockIn.Checked)
{
query = "SELECT * " +
" FROM tblStockIn AS S, tblProductInfo AS P WHERE S.PROCODE=P.PROCODE AND
CATEGORY ='" + category +
"' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "stockinCMD");
}
else if (rdoStockOut.Checked)
{
query = "SELECT * FROM tblStockOut AS S, tblProductInfo AS P WHERE
S.PROCODE=P.PROCODE AND CATEGORY ='" + category +
"' AND PRONAME LIKE '%" + txtsearch + "%'";
reports(query, "stockoutCMD");
}

}
}

private void frmPrint_Load(object sender, EventArgs e)


{

}
}
}

frmProduct.cs
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 BakeryInventorySystem
{
public partial class frmProduct : Form
{
public frmProduct()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string sql;
int maxrow;

private void Button1_Click(object sender, EventArgs e)


{
func.clearTxt(this);
cboCateg.Text = "Select";
config.autonumber(2, txtPROCODE);
}

private void frmProduct_Load(object sender, EventArgs e)


{
Button1_Click(sender, e);
}

private void Button2_Click(object sender, EventArgs e)


{
this.Close();
}

private void BTNSAVE_Click(object sender, EventArgs e)


{

if (TXTPRONAME.Text == "" || TXTDESC.Text == "" || cboCateg.Text == "Select" || TXTPRICE.Text


== "")
{
func.messagerequired();
}

sql = "SELECT * FROM tblProductInfo WHERE PROCODE='" + txtPROCODE.Text + "'";


maxrow = config.maxrow(sql);

if (maxrow > 0)
{
sql = "UPDATE tblProductInfo SET PRONAME='" + TXTPRONAME.Text +
"' ,PRODESC='" + TXTDESC.Text +
"',CATEGORY='" + cboCateg.Text +
"',PROPRICE=" + TXTPRICE.Text + " WHERE PROCODE='" + txtPROCODE.Text + "'";
config.Execute_CUD(sql, "Error to update Bread", "Bread Has Been Updated.");
}
else
{
sql = "INSERT INTO tblProductInfo
(PROCODE,PRONAME,PRODESC,CATEGORY,PROPRICE,PROQTY)"
+ " VALUES ( '" + txtPROCODE.Text + "', '" + TXTPRONAME.Text + "','" + TXTDESC.Text + "','"
+ cboCateg.Text + "','" + TXTPRICE.Text + "',0)";
config.Execute_CUD(sql, "Error to save Product.", "New Bread Has Been Saved.");

config.update_Autonumber(2);
}

Button1_Click(sender, e);

}
}
}
frmStockin.cs
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 BakeryInventorySystem
{
public partial class frmStockin : Form
{
public frmStockin()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string sql;
int maxrow;
private void frmStockin_Load(object sender, EventArgs e)
{
BTNNEW_Click(sender, e);
}

private void BTNNEW_Click(object sender, EventArgs e)


{
func.clearTxt(GroupBox1);
func.clearTxt(GroupBox3);
CBOUNIT.Text = "";
LBLMSG.Text = "";
LBLUNIT.Text = "";
LBLMSG.BackColor = Color.Transparent;

config.autonumber_transaction(1, LBLTRANSNUM);

config.autocomplete("SELECT PROCODE FROM tblProductInfo", txtPROCODE);


}

private void BTNCLOSE_Click(object sender, EventArgs e)


{
this.Close();
}

private void BTNADD_Click(object sender, EventArgs e)


{
if(TXTDESC.Text != "" && TXTQTY.Text != "")
{
int qty = int.Parse(TXTQTY.Text);
int transnum = int.Parse(LBLTRANSNUM.Text);

sql = "INSERT INTO tblStockIn


(TRANSNUM,PROCODE,DATERECEIVED,RECEIVEDQTY,RECEIVEDTOTPRICE) " +
" VALUES (" + transnum + ",'" + txtPROCODE.Text + "','" + DTPTRANSDATE.Value + "'," + qty + "
,'" + TXTTOT.Text + "')";
config.Execute_Query(sql);

// 'ADDING THE QTY OF THE STOCK


sql = "UPDATE tblProductInfo SET PROQTY = PROQTY + '" + TXTQTY.Text + "' WHERE PROCODE
= '" + txtPROCODE.Text + "'";
config.Execute_Query(sql);

LBLMSG.Text = "The " + TXTPRODUCT.Text + " has been added into the inventory.";
LBLMSG.BackColor = Color.Aquamarine;
LBLMSG.ForeColor = Color.Black;

config.update_Autonumber(1);

BTNNEW_Click(sender, e);
}
else
{
LBLMSG.Text = "Fill up the correct product in the empty fields inorder to save.";
LBLMSG.BackColor = Color.Red;
LBLMSG.ForeColor = Color.White;
}

private void txtPROCODE_TextChanged(object sender, EventArgs e)


{
sql = "SELECT * FROM tblProductInfo WHERE PROCODE ='" + txtPROCODE.Text + "'";
maxrow = config.maxrow(sql);

if(maxrow > 0)
{
foreach(DataRow r in config.dt.Rows)
{
TXTPRODUCT.Text = r.Field<string>("PRONAME");
TXTDESC.Text = r.Field<string>("PRODESC") + " [" + r.Field<string>("CATEGORY") + "]";
TXTPRICE.Text = r.Field<decimal>("PROPRICE").ToString();
}

}
else
{
TXTPRODUCT.Clear();
TXTDESC.Clear();
TXTPRICE.Clear();
TXTQTY.Clear();
TXTTOT.Clear();
}
}

private void TXTQTY_TextChanged(object sender, EventArgs e)


{
double total;
if( TXTQTY.Text == "")
{
TXTTOT.Text ="0";
}
else
{
total = Double.Parse(TXTPRICE.Text) * Double.Parse(TXTQTY.Text);
TXTTOT.Text = total.ToString();
}
}

private void btnList_Click(object sender, EventArgs e)


{
Form frm = new frmListStockin();
frm.ShowDialog();
}
}
}
frmStockout.cs
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 BakeryInventorySystem
{
public partial class frmStockout : Form
{
public frmStockout()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string query;
int maxrow;
private void BTNNEW_Click(object sender, EventArgs e)
{
func.clearTxt(GroupBox1);
func.clearTxt(GroupBox2);
LBLMSG.Text = "";
LBLMSG.BackColor = Color.Transparent;

query = "SELECT PROCODE FROM tblProductInfo";


config.autocomplete(query, txtPROCODE);

config.autonumber_transaction(1, LBLTRANSNUM);

private void frmStockout_Load(object sender, EventArgs e)


{
BTNNEW_Click(sender, e);
}
private void txtPROCODE_TextChanged(object sender, EventArgs e)
{
query = "SELECT * FROM tblProductInfo WHERE PROCODE ='" + txtPROCODE.Text + "'";
maxrow = config.maxrow(query);

if (maxrow > 0)
{
foreach (DataRow r in config.dt.Rows)
{
TXTPRODUCT.Text = r.Field<string>("PRONAME");
TXTDESC.Text = r.Field<string>("PRODESC") + " [" + r.Field<string>("CATEGORY") + "]";
TXTPRICE.Text = r.Field<decimal>("PROPRICE").ToString();
TXTAVAILQTY.Text = r.Field<int>("PROQTY").ToString();
}

}
else
{
TXTPRODUCT.Clear();
TXTDESC.Clear();
TXTPRICE.Clear();
TXTQTY.Clear();
TXTTOT.Clear();
TXTAVAILQTY.Clear();
}
}

private void TXTQTY_TextChanged(object sender, EventArgs e)


{
double remainqty, totalamount;
if(TXTQTY.Text == "")
{
TXTTOT.Text = "0";
TXTREMAINQTY.Text = TXTAVAILQTY.Text;
}
else
{
remainqty= Double.Parse(TXTAVAILQTY.Text) - Double.Parse(TXTQTY.Text);
TXTREMAINQTY.Text = remainqty.ToString();
totalamount = Double.Parse(TXTPRICE.Text) * Double.Parse(TXTQTY.Text);
TXTTOT.Text = totalamount.ToString();
}
}
private void BTNCLOSE_Click(object sender, EventArgs e)
{
this.Close();
}

private void BTNSAVE_Click(object sender, EventArgs e)


{
if( TXTDESC.Text != "" && TXTQTY.Text != "")
{
double Rqty = Double.Parse(TXTAVAILQTY.Text);
double qty = Double.Parse(TXTQTY.Text);

if ( Rqty < qty)


{
LBLMSG.Text = "Not valid. The entered quantity is greater than the available quantity!";
LBLMSG.BackColor = Color.Red;
LBLMSG.ForeColor = Color.White;
}
else
{
query = "INSERT INTO tblStockOut
(TRANSNUM,PROCODE,DATEOUT,OUTQTY,OUTUNIT,OUTTOTPRICE ) " +
" VALUES ('" + LBLTRANSNUM.Text + "','" + txtPROCODE.Text + "','" +
DTPTRANSDATE.Value + "','" + TXTQTY.Text + "','" + LBLUNIT.Text + "','" + TXTTOT.Text + "')";
config.Execute_Query(query);

query = "UPDATE tblProductInfo SET PROQTY = PROQTY - " + TXTQTY.Text + " WHERE
PROCODE = '" + txtPROCODE.Text + "'";
config.Execute_Query(query);

LBLMSG.Text = "The " + TXTPRODUCT.Text + " has been deducted into the inventory.";
LBLMSG.BackColor = Color.Aquamarine;
LBLMSG.ForeColor = Color.Black;
;
config.update_Autonumber(1);

BTNNEW_Click(sender, e);

}
}
else
{
LBLMSG.Text = "Fill up the correct product in the empty fields inorder to save.";
LBLMSG.BackColor = Color.Red;
LBLMSG.ForeColor = Color.White;
}

private void btnList_Click(object sender, EventArgs e)


{
Form frm = new frmListStockout();
frm.ShowDialog();
}
}
}

frmUser.cs
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 BakeryInventorySystem
{
public partial class frmUser : Form
{
public frmUser()
{
InitializeComponent();
}
SQLConfig config = new SQLConfig();
usableFunction func = new usableFunction();
string query;
int maxrow;

private void btnnew_Click(object sender, EventArgs e)


{
func.clearTxt(Panel2);
cbotype.Text = "";
LBLUSERID.Text = "USERID";

query = "SELECT USERID , U_NAME AS [Name],U_UNAME AS [Username] ,U_TYPE AS [Role]


FROM tblUser WHERE ( U_NAME + ' ' + U_UNAME + ' ' + U_TYPE) LIKE '%" + txtsearch.Text + "%'";
config.Load_DTG(query, dtglist);
}

private void frmUser_Load(object sender, EventArgs e)


{
btnnew_Click(sender, e);
}

private void txtsearch_TextChanged(object sender, EventArgs e)


{
btnnew_Click(sender, e);
}

private void btnclose_Click(object sender, EventArgs e)


{
this.Close();
}

private void btnsave_Click(object sender, EventArgs e)


{
if( txtname.Text != "" && txtusername.Text != "" && txtpass.Text != "" && cbotype.Text != "" )
{
if (LBLUSERID.Text == "USERID")
{
query = "INSERT INTO tblUser ( U_NAME,U_UNAME,U_PASS,U_TYPE) VALUES ('" +
txtname.Text + "','" + txtusername.Text
+ "','" + txtpass.Text + "','" + cbotype.Text + "')";
config.Execute_CUD(query, "User not saved.", "New user has been saved.");
}
else
{
query = "UPDATE tblUser SET U_NAME='" + txtname.Text + "',U_UNAME='" +
txtusername.Text
+ "',U_PASS='" + txtpass.Text + "',U_TYPE='" + cbotype.Text + "' WHERE USERID=" +
LBLUSERID.Text;
config.Execute_CUD(query, "User is not updated.", "User has been updated.");
}
btnnew_Click(sender, e);
}
else
{
MessageBox.Show("Fields are required!", "Invalid", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}

private void btndelete_Click(object sender, EventArgs e)


{
query = "DELETE * FROM tblUser WHERE USERID = " + dtglist.CurrentRow.Cells[0].Value;
config.Execute_CUD(query, "User is not deleted.", "User has been deleted.");

btnnew_Click(sender, e);
}

private void dtglist_CellClick(object sender, DataGridViewCellEventArgs e)


{
LBLUSERID.Text = dtglist.CurrentRow.Cells[0].Value.ToString();
query = "SELECT * FROM tblUser WHERE USERID=" + LBLUSERID.Text;
maxrow = config.maxrow(query);
if(maxrow > 0)
{
foreach(DataRow r in config.dt.Rows)
{
txtname.Text = r.Field<string>(1);
txtusername.Text = r.Field<string>(2);
txtpass.Text = r.Field<string>(3);
cbotype.Text = r.Field<string>(4);
}

}
}
}

SQLConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using MySql.Data.MySqlClient;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;

namespace BakeryInventorySystem
{
class SQLConfig
{

private OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source="
+ Application.StartupPath + "\\dbBakeshop.accdb; JET OLEDB:Database Password =
admin1234");
private OleDbCommand cmd;
private OleDbDataAdapter da;
public DataTable dt;
int result;
usableFunction funct = new usableFunction();
public void Execute_CUD(string sql, string msg_false, string msg_true)
{
try
{
con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();

if(result > 0)
{
MessageBox.Show(msg_true);
}
else
{
MessageBox.Show(msg_false);
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
public void Execute_Query(string sql)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}
//con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
public void Load_DTG(string sql,DataGridView dtg)
{
try
{
//con.Open();
if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);
dtg.DataSource = dt;

funct.ResponsiveDtg(dtg);
dtg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dtg.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}

}
public void fiil_CBO(string sql, ComboBox cbo)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}

cmd = new OleDbCommand();


da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

cbo.DataSource = dt;
cbo.ValueMember = dt.Columns[0].ColumnName;
cbo.DisplayMember = dt.Columns[1].ColumnName;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}

}
public void combo(string sql, ComboBox cbo)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}

cmd = new OleDbCommand();


da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

cbo.Items.Clear();
cbo.Text = "Select";
foreach(DataRow r in dt.Rows)
{
cbo.Items.Add(r.Field<string>(0));
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}

}
public void singleResult(string sql)

{
try
{
con.Open();
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}
}

public int maxrow(string sql)

{
int maxrow = 0;

try
{
con.Open();
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

maxrow = dt.Rows.Count;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
con.Close();
}

return maxrow;

public void loadReports(string sql)

{
try
{
con.Open();
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();
cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}

public void autocomplete(string sql,TextBox txt)


{
try
{
con.Open();
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.Fill(dt);
txt.AutoCompleteCustomSource.Clear();
txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
foreach (DataRow r in dt.Rows)
{
txt.AutoCompleteCustomSource.Add(r.Field<string>(0));
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}

public void autonumber(int ID, TextBox txt)


{
try
{

if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = "SELECT (STARTNUM + INCNUM) FROM tblAutoNumber WHERE ID=" +
ID;
da.SelectCommand = cmd;
da.Fill(dt);

txt.Text = DateTime.Now.ToString("yyyy") + dt.Rows[0].Field<string>(0);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}
public void autonumber_transaction(int ID, Label txt)
{
try
{

if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new OleDbCommand();
da = new OleDbDataAdapter();
dt = new DataTable();

cmd.Connection = con;
cmd.CommandText = "SELECT (STARTNUM + INCNUM) FROM tblAutoNumber WHERE ID=" +
ID;
da.SelectCommand = cmd;
da.Fill(dt);

txt.Text = dt.Rows[0].Field<string>(0);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
da.Dispose();
}
}
public void update_Autonumber(int id)
{
Execute_Query("UPDATE tblAutoNumber SET INCNUM=INCNUM + 1 WHERE ID=" + id);
}
}
}

usableFunction.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BakeryInventorySystem
{
class usableFunction
{
public void clearTxt(Control container)
{
try
{
//'for each txt as control in this(object).control
foreach (Control txt in container.Controls)
{
//conditioning the txt as control by getting it's type.
//the type of txt as control must be textbox.
if (txt is TextBox)
{
//if the object(textbox) is present. The result is, the textbox will be cleared.
txt.Text = "";
}
if (txt is RichTextBox)
{
txt.Text = "";
}
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public string checkOption(CheckBox chk)
{
string yesno;

if (chk.Checked)
{
yesno = "Yes";
}
else
{
yesno = "No";
}
return yesno;
}

// Public Sub checkOption(ByVal chk As CheckBox, ByRef yesno As String)


// If chk.CheckState = CheckState.Checked Then
// yesno = "Yes"
// Else
// yesno = "No"
// End If
//End Sub

//initialize the validating method


static Regex Valid_Name = StringOnly();
static Regex Valid_Contact = NumbersOnly();
static Regex Valid_Password = ValidPassword();
static Regex Valid_Email = Email_Address();

//Method for validating email address


private static Regex Email_Address()
{
string Email_Pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";

return new Regex(Email_Pattern, RegexOptions.IgnoreCase);


}
//Method for string validation only
private static Regex StringOnly()
{
string StringAndNumber_Pattern = "^[a-zA-Z]";

return new Regex(StringAndNumber_Pattern, RegexOptions.IgnoreCase);


}
//Method for numbers validation only
private static Regex NumbersOnly()
{
string StringAndNumber_Pattern = "^[0-9]*$";

return new Regex(StringAndNumber_Pattern, RegexOptions.IgnoreCase);


}
//Method for password validation only
private static Regex ValidPassword()
{
string Password_Pattern = "(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,15})$";

return new Regex(Password_Pattern, RegexOptions.IgnoreCase);


}
public void ResponsiveDtg(DataGridView dtg)
{
dtg.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
}

public void messagerequired()


{
MessageBox.Show("All field are requireds.", "Invalid", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BakeryInventorySystem
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
SCREENSHOTS
CONCLUSION

This project has helped us in getting a clearer understanding of real-world


application development in .NET framework. It has provided us a deeper
insight into connecting users to the front end by coding at backend. The
entire learning outcome of this project has proved to be immensely
beneficial for our future application development with C# and ADO.NET.

Here, in this application we have been able to gain a deep insight into
how to work with windows forms application along with ADO.NET to
integrate the application with databases. The windows application
provides an easy user interface which will help a user to automate his
bakery inventory system. The user can manage all the tasks related to a
bakery inventory with ease and in an efficient manner. This project helped
us to deal with the real-life GUI-based windows application development
and how to fulfill a client’s requirements with respect to a specific
business scenario. It also helped us to develop the skill to think as per the
user perspective and application developer’s perspective.
BIBLIOGRAPHY
 https://www.sourcecodester.com/c/13369/bakery-inventory-
system-using-c-and-ms-access-database.html
 https://www.youtube.com/watch?v=pMl2yukTG74

You might also like