Asp.net Project Tutorial: Navigating the Blood Donor Project's Database Logic

Introduction:

Behind the sleek user interface of the "Blood Donor Project" lies a robust database logic that powers its functionality. In this segment, we'll dissect the intricacies of the database logic, exploring how the application manages and processes critical data related to blood donors, status updates, and blood banks.

Database Logic: Ensuring Seamless Operations

The "Blood Donor Project" relies on a well-crafted Database Logic, encapsulated within the "BloodDonarDataBaseLogic" namespace. Let's delve into the key functionalities provided by this logic:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BloodDonarObject;

namespace BloodDonarDataBaseLogic
{
   public class DatabaseLogic
    {
        // Database Connection
        //Methods 
    }
}

Insert Blood Donor Details:

The application ensures the seamless insertion of blood donor details into the database through the "InsertBloodDonarDB" method. The stored procedure "proc_insertBloodDonarDetails" is executed, capturing essential information such as the donor's username, password, contact details, and blood group.


public class DatabaseLogic
    {
        // Database Connection
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbCon"].ToString());
        string query;

        //Method
        public void InsertBloodDonarDB(BloodDonarObject.BusinessObject boObjDB)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("proc_insertBloodDonarDetails", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@donarid", boObjDB.DonarId.ToString());
                cmd.Parameters.AddWithValue("@donarusername", boObjDB.DonarUsernamer.ToString());
                cmd.Parameters.AddWithValue("@donarpassword", boObjDB.DonarPassword.ToString());
                cmd.Parameters.AddWithValue("@donarfullname", boObjDB.DonarFullName.ToString());
                cmd.Parameters.AddWithValue("@donardateofbirth", boObjDB.DonarDateOfBirth.ToString());
                cmd.Parameters.AddWithValue("@donargender", boObjDB.DonarGender.ToString());
                cmd.Parameters.AddWithValue("@donarstate",boObjDB.DonarState.ToString());
                cmd.Parameters.AddWithValue("@donarcity", boObjDB.DonarCity.ToString());
                cmd.Parameters.AddWithValue("@donaremailaddress", boObjDB.DonarEmailID.ToString());
                cmd.Parameters.AddWithValue("@donarphonenumber", boObjDB.DonarPhone.ToString());
                cmd.Parameters.AddWithValue("@donarBloodGroup", boObjDB.DonarBloodGroup);
                cmd.Parameters.AddWithValue("@donarstatus", boObjDB.Status.ToString());
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch(Exception ex)
            {
                boObjDB.ErrorMessage = ex.Message;
            }
            finally
            {
                con.Close();
            }
        }
 }

Insert Status Data:

The "InsertStatusData" method facilitates the addition of status updates to the database. Utilizing the "proc_InsertStatusData" stored procedure, it records the donor's ID, status message, timing, and the number of times the status has been edited.


public void InsertStatusData(BloodDonarObject.BusinessObject ISDObjDB)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("proc_InsertStatusData", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@donarid", ISDObjDB.DonarId);
                cmd.Parameters.AddWithValue("@statusid", ISDObjDB.StatusPostID);
                cmd.Parameters.AddWithValue("@statusmessage", ISDObjDB.StatusPostMessage);
                cmd.Parameters.AddWithValue("@poststatustime", ISDObjDB.StatusPostTiming);
                cmd.Parameters.AddWithValue("@nooftimestatusedited", ISDObjDB.NooftimeStatusedited);
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                ISDObjDB.ErrorMessage = ex.Message;
            }
            finally
            {
                con.Close();
            }
        }

Insert Blood Bank Details:

To maintain an up-to-date blood bank database, the "InsertBloodBankData" method is employed. This function executes the "proc_InsertBloodBankDetails" stored procedure, capturing details such as the blood bank's name, address, contact information, and status.


public void InsertBloodBankData(BloodDonarObject.BusinessObject bbObject)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("proc_InsertBloodBankDetails", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@bbid", bbObject.BloodBankID);
                cmd.Parameters.AddWithValue("@bbname", bbObject.BloodBankName);
                cmd.Parameters.AddWithValue("@bbaddress", bbObject.BloodBankAddress);
                cmd.Parameters.AddWithValue("@bblandmark", bbObject.BloodBankLandmark);
                cmd.Parameters.AddWithValue("@bbphone1", bbObject.BloodBankPhone1);
                cmd.Parameters.AddWithValue("@bbphone2", bbObject.BloodBankPhone2);
                cmd.Parameters.AddWithValue("@bbemail", bbObject.EmailID);
                cmd.Parameters.AddWithValue("@bbstate", bbObject.State);
                cmd.Parameters.AddWithValue("@bbcity", bbObject.City);
                cmd.Parameters.AddWithValue("@userid", bbObject.DonarId);
                cmd.Parameters.AddWithValue("@bbstatus", bbObject.Status);
                cmd.ExecuteNonQuery();
                con.Close();
            }


            catch (Exception ex)
            {
                bbObject.ErrorMessage = ex.Message;
            }
            finally
            {
                con.Close();
            }
        }

Display User Status Based on DonarID:

The "GetStatusPost" method retrieves status posts based on a donor's ID, enhancing the user's experience by providing personalized status information.


public DataSet GetStatusPost(BusinessObject sObject)
        {
            try
            {
                DataSet dsstatus = new DataSet();
                SqlCommand cmd = new SqlCommand("proc_getAllUserStatus", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@donarid", sObject.DonarId);
                da.Fill(dsstatus);
                return dsstatus;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }

Blood Donor Login Verification:

The "VerifyBloodDonar" method ensures secure donor authentication by verifying the provided username and password against the database. This function plays a crucial role in maintaining the security of user accounts.


public int VerifyBloodDonar(BusinessObject boObj)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("Select * from donardetails where donarusername='" + boObj.DonarUsernamer + "' and donarpassword='" + boObj.DonarPassword + "' and status='active'", con);

                //SqlCommand cmd = new SqlCommand("proc_getDonarDetails", con);
                //cmd.CommandType = CommandType.StoredProcedure;
                //cmd.Parameters.AddWithValue("@dusername", boObj.DonarUsernamer.ToString());
                //cmd.Parameters.AddWithValue("@donarpassword", boObj.DonarPassword.ToString());
                int i = Convert.ToInt32(cmd.ExecuteScalar());
                if (i > 0)
                {
                    con.Close();
                }
                return i;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }

Auto Generate ID For All:

The "GenerateID" method streamlines the process of generating unique identifiers for various components within the application, ensuring data integrity and uniqueness.


public string GenerateID(BusinessObject boObject)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(boObject.SPQuery, con);
                cmd.CommandType = CommandType.StoredProcedure;
                string ID = cmd.ExecuteScalar().ToString();
                return ID;
            }
            catch(Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }

        }

Get Donor Details for Dashboard:

The "GetBloodDonarDetails" method retrieves donor details specifically for the user's dashboard, providing a snapshot of essential information.


public DataSet GetBloodDonarDetails(BusinessObject boObj)
  {
    try
     {
       DataSet ds = new DataSet();
       SqlCommand cmd = new SqlCommand("proc_getsingledonardetails", con);
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.AddWithValue("@donarusername", boObj.DonarUsernamer);
       da.Fill(ds);
       return ds;
     }
    catch (Exception ex)
     {
      throw ex;
     }
    finally
    {
      con.Close();
    }
 }

Additional Functionalities:

The database logic encompasses various other functionalities, including retrieving all blood donor details, filtering blood donor and blood bank details based on state and city, and obtaining data for individual blood banks.


public DataSet GetAllBloodDonarDetails()
        {
            try
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand("proc_getALLDonarDetails", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }


#region Filter Blood Donar Details
        public DataSet GetBloodDonarStateCityData(BusinessObject scObject)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand("proc_FilterBloodDonarDetails", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@state", scObject.State);
                cmd.Parameters.AddWithValue("@city", scObject.City);
                cmd.Parameters.AddWithValue("@bloodgroup", scObject.DonarBloodGroup);
                //cmd.Parameters.AddWithValue("@status", scObject.Status);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Get All Blood Bank Data
        public DataSet GetALLBloodBankData()
        {
            try
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand("proc_getAllBloodBankData", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                da.Fill(ds);
                return ds;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Get Single Blood Bank Details
        public DataSet GetSingleBloodBankData(BusinessObject sBBObjec)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand("proc_singlebloodbankdetails", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@bbid", sBBObjec.BloodBankID);
            da.Fill(ds);
            return ds;
        }
        #endregion

        #region Filter Blood Bank Details Tthrough State and City
        public DataSet GetBloodBankStateCityData(BusinessObject scObj)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand("proc_getBloodbank_StateCity", con);
                SqlDataAdapter da=new SqlDataAdapter(cmd);
                cmd.CommandType=CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@bbstate",scObj.State);
                cmd.Parameters.AddWithValue("@bbcity",scObj.City);
                da.Fill(ds);
                return ds;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
        #endregion



Download Source Code

Download the complete source code for the Blood Donor Project from the provided link and explore its functionalities.


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