C# Project Tutorial: Business Objects in the Food Court Project

Introduction:

In this article, we try to understand the business objects and their use in our project. In any project, data transfer is a big change because when the end-user interacts with the application and enters data, that data should be transferred from various sections, and finally, that data should be stored in the database. The transfer of data from one section to another section job will be taken care of by the business object class and its members.

Business Object Clas

To handle food court project data transfer I defined various properties to transfer data from one class to another. If the user interacts with the application and enters the data, that data will be stored in the database, so someone has to take care of this data from the front end to the back end. This data transfer job is done by our business object class.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoodCourtBusinessObject
{
    public class BusinessObject
    {
        //Common Properties for Food Court Project
        public int Quantity { get; set; }
        public double Price { get; set; }
        public string Password { get; set; }
        public int NoOfTransaction { get; set; }
        public string Date { get; set; }


        // Food Item Type Object
        public string FoodItemTypeNo { get; set; }
        public string FoodItemTypeName { get; set; }

        // Food Item Object
        public string FoodItemNo { get; set; }
        public string FoodItemName { get; set; }

        // Employee Object
        public string EmployeeID { get; set; }
        public string EmployeeName { get; set; }
        public string EmployeeAddress { get; set; }
        public string EmployeePhone { get; set; }

        // Stock Object 
        public string StockID { get; set; }

        // Bill Transaction and Bill Master Object
        public string BillMasterID { get; set; }
        public string BillID { get; set; }
        public int TotalSales { get; set; }

    }
}

I defined all the properties in a single class i.e BusinessObject class that is required for the food court project, but this is not a good practice to define all the properties in a single class while doing the projects.

For education purposes, I did this project to make you understand how the projects are built and it gives you some practical knowledge.

If in case anyone doesn't want to use all the properties in a single class, then you can segregate this above class into multiple classes.

Common Properties:

Identifying common properties in the food court project is used to transfer data through the model class we defined those properties in the common model class.


public class Common
{
	public int Quantity { get; set; }
	public double Price { get; set; }
	public string Password { get; set; }
	public int NoOfTransaction { get; set; }
	public string Date { get; set; }
}

  • Quantity: Represents the quantity of items, a fundamental aspect for managing stock and sales.
  • Price: Signifies the price of an item.
  • Password: Captures the password, essential for securing sensitive information and ensuring user authentication.
  • NoOfTransaction: Tracks the number of transactions, providing insights into the volume of operations conducted.
  • Date: Records the date associated with various transactions, contributing to effective data management.

Food Item Type Properties:

Instead of using the BusinessObject class, we can also define food item type properties, as shown below in the code snippet.


public class FoodItemType
{
	public string FoodItemTypeNo { get; set; }
	public string FoodItemTypeName { get; set; }
}

  • FoodItemTypeNo: A unique identifier for differentiating between various food item types.
  • FoodItemTypeName: Describes the name or category of a particular food item type.

Food Item Properties:

Instead of using the BusinessObjects class to manage individual food items, we can also define food item properties, as shown below in the code snippet.


public class FoodType : Common
{
	public string FoodItemNo { get; set; }
	public string FoodItemName { get; set; }
    public string FoodItemTypeNo { get; set; }
}

In the above code snippet, we also need two other properties, i.e., quantity and price, which we already created in the Common class, so they are not required to be defined; instead, we inherit the common class so we can use those properties in the food item class too.

  • FoodItemNo: A distinct identifier for individual food items.
  • FoodItemName: Specifies the name of a particular food item.

Employee Properties:

To handle employee-related information, we can define the Employee class instead of using BusinessObject class.


public class Employee
{
	public string EmployeeID { get; set; }
	public string EmployeeName { get; set; }
	public string EmployeeAddress { get; set; }
	public string EmployeePhone { get; set; }
}

  • EmployeeID: A unique identifier for each employee.
  • EmployeeName: Captures the name of an employee.
  • EmployeeAddress: Records the address of an employee.
  • EmployeePhone: Stores the contact number of an employee.

Stock Properties:

Instead of using BusinessObjects class to manage stock-related data, we can also define stock properties i.e stockid, fooditemtypeno, fooditemno, quantity and price, as shown below in the code snippet.


public class Stock : Common
{
	public string StockID { get; set; }
    public string FoodItemNo { get; set; }
    public string FoodItemTypeNo { get; set; }
}

The quantity and price properties are already defined in the common class, so we can inherit them as shown in the above code snippet.

  • StockID: A unique identifier for tracking stock-related activities.

Bill Transaction and Bill Master Properties:

For handling billing operations, we can use the bill transaction and bill master classes separately instead of using the BusinessObject class.


public class BillTransaction : Common
{
	public string BillID { get; set; }
    public string BillMasterID { get; set; }
    public string FoodItemNo { get; set; }
    
}

The above bill transaction also required quantity and price properties, which are inherited from the common class.

In the BillMaster class, I defined all the properties instead of using common properties because I can use common properties, but the names of the properties are different, which is why I defined all the properties that require transferring the data.


public class BillMaster
{
    public string BillMasterID { get; set; }
    public int TotalSales { get; set; }
    public double TotalAmount { get; set; }
    public DateTime Date { get; set; }
    public string EmployeeID { get; set; }
    
}

Download Source Code

To download the source code of the food court project with the database, we can just click on the download link.


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