C# Food Court Project Database Logic | Part 2

This article is the continuation of the previous article, Food Court Project Database logic Before continuing this article, I strongly recommend reading the previous article because I started this article with how to implement database logic for food court project, which is the starting point of this article located in the previous article.

Employee Management

In any business application, employee management is a critical component. The DataBaseLogic class provides methods for creating employee accounts, updating employee details, verifying login credentials, and more.

CreateEmployeeAccount method is used to add newly joined employee records, to create an employee account we need to pass employee details like name, password, address and phone once it's inserted successfully it will generate the employee Id automatically.


#region Create Employee Account

public int CreateEmployeeAccount(BusinessObject empObj)
 {
	SqlCommand cmd = new SqlCommand("proc_InsertEmployee", con);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@ename", empObj.EmployeeName);
	cmd.Parameters.AddWithValue("@password", empObj.Password);
	cmd.Parameters.AddWithValue("@address", empObj.EmployeeAddress);
	cmd.Parameters.AddWithValue("@phone", empObj.EmployeePhone);
	con.Open();
	int i = cmd.ExecuteNonQuery();
	return i;
 }
 
#endregion   

VerifyLoginCredentials method will execute when the employee tries to login with his credentials like employee ID and password. If this credential is valid then it will return a complete employee record and bind that data into the dataset because this verify login credentials method return type is the dataset.



#region Verify Employee Login

public DataSet VerifyLoginCredientials(BusinessObject empObj)
 {                
	string query = "Select * from employee Where empid='" + empObj.EmployeeID + "' and emppwd='" + empObj.Password + "'";
	SqlCommand cmd = new SqlCommand(query, con);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	DataSet ds = new DataSet();
	da.Fill(ds);
	if(!ds.Tables[0].Rows.Count>0)
	{
		return null;
	}
	return ds;    
 }

#endregion


This GetEmployees method is used to fetch all the employee records from the employee table, bind the data into a dataset, and return the dataset as an output because this method's return type is the dataset.



#region Get Employee's Details

public DataSet GetEmployees()
 {
	SqlCommand cmd = new SqlCommand("proc_getEmployee", con);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	cmd.CommandType = CommandType.StoredProcedure;
	DataSet ds = new DataSet();
	da.Fill(ds);
	return ds;
 }

#endregion


The ResetPassword method is used to reset employee passwords who forgot their credentials. We have to pass the employee ID as a parameter whose password needs to be reset.



#region Reset Password

public int ResetPassword(BusinessObject rpObj)
 {
	SqlCommand cmd = new SqlCommand("proc_RestPassword", con);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@empid", rpObj.EmployeeID);
	con.Open();
	int i = cmd.ExecuteNonQuery();
	return i;
 }

#endregion


Employees need to change the details in the inventory then this UpdateEmployee method is used.



#region Update Employee Details

public int UpdateEmployee(BusinessObject updObj)
 {
	SqlCommand cmd = new SqlCommand("proc_UpdateEmployee", con);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@empid", updObj.EmployeeID);
	cmd.Parameters.AddWithValue("@empname", updObj.EmployeeName);
	cmd.Parameters.AddWithValue("@empaddress", updObj.EmployeeAddress);
	cmd.Parameters.AddWithValue("@empphone", updObj.EmployeePhone);
	con.Open();
	int i = cmd.ExecuteNonQuery();
    con.Close();
	return i;
 }

#endregion


DeleteEmployee method is used to delete employee records permanently from the database, we just need to pass the employee ID it will delete that employee record directly from the database.



public int DeleteEmployee(BusinessObject empObj)
 {
	SqlCommand cmd = new SqlCommand("proc_DeleteEmployee", con);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@empid", empObj.EmployeeID);
	con.Open();
	int i = cmd.ExecuteNonQuery();
	return i;
 }

Stock and Transactions Handling

Efficient stock management is vital for any business dealing with physical products. The code includes methods for updating stock data, handling bill transactions, and generating bill master data.



#region Update Stock and Food Items Quantity

public int UpdateStockData(BusinessObject usObject)
 {
	SqlCommand cmd = new SqlCommand("proc_updateStock_and_FoodItems", con);
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@sID", usObject.StockID);
	cmd.Parameters.AddWithValue("@fitemTypeNo", usObject.FoodItemTypeNo);
	cmd.Parameters.AddWithValue("@fitemNo", usObject.FoodItemNo);
	cmd.Parameters.AddWithValue("@qty", usObject.Quantity);
	cmd.Parameters.AddWithValue("@price", usObject.Price);
	con.Open();
	int i = cmd.ExecuteNonQuery();
	con.Close();
	return i;
 }

#endregion

#region Display Bill to DataGridView

public DataSet DisplayBillDataGridView(BusinessObject BGridObject)
 {
	SqlCommand cmd = new SqlCommand("proc_DisplayBill_DataGrid", con);
	cmd.CommandType = CommandType.StoredProcedure;
	SqlDataAdapter da = new SqlDataAdapter(cmd);
	cmd.Parameters.AddWithValue("@bilmasterid", BGridObject.BillMasterID);
	DataSet ds = new DataSet();
	da.Fill(ds);
	if (!ds.Tables[0].Rows.Count > 0)                 
	{
		return null;
	}
	return ds;
 }
 
#endregion

#region Insert Bill Transaction Data

public int InsertBillTransaction(BusinessObject BTnxObject)
 {
	SqlCommand cmd = new SqlCommand("proc_BillTransaction", con);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@bid", BTnxObject.BillID);
	cmd.Parameters.AddWithValue("@bmid", BTnxObject.BillMasterID);
	cmd.Parameters.AddWithValue("@fitemno", BTnxObject.FoodItemNo);
	cmd.Parameters.AddWithValue("@qty", BTnxObject.Quantity);
	cmd.Parameters.AddWithValue("@amount", BTnxObject.Price);
	cmd.Parameters.AddWithValue("@trnno", BTnxObject.NoOfTransaction);
	con.Open();
	int i = cmd.ExecuteNonQuery();
	con.Close();
	return i;
 }
 
#endregion

#region Generate Bill Master Data

public int InsertBillMaster(BusinessObject BMObject)
 {
	SqlCommand cmd = new SqlCommand("proc_GenerateBillMaster", con);
	cmd.CommandType = CommandType.StoredProcedure;
	cmd.Parameters.AddWithValue("@bmid", BMObject.BillMasterID);
	cmd.Parameters.AddWithValue("@totalSales", BMObject.TotalSales);
	cmd.Parameters.AddWithValue("@totalamount", BMObject.Price);
	cmd.Parameters.AddWithValue("@date", BMObject.Date);
	cmd.Parameters.AddWithValue("@empid", BMObject.EmployeeID);
	con.Open();
	int i = cmd.ExecuteNonQuery();
	con.Close();
	return i;
 }
 
#endregion


These functionalities ensure accurate tracking of stock levels, smooth transaction processing, and the generation of comprehensive bills.

Download Source Code

To get more information regarding blood donar project source code like Business Object, Database & Stored Procedure, Database Logic and User Interface.

Post a Comment

0 Comments