Employee.cs

using System;

using System.Data.SqlClient;

using System.Configuration;

using System.Data;

 

namespace prjstart

{

       /// <summary>

       /// Summary description for Employee.

       /// </summary>

       public class Employee

       {

              public string FullName;   // Prepare a class employee with the following member variables

              public string Email;

              public string Password;

       }

 

       public class Employeedb

       {

              public string addemployeedetails(string fullname,string email, string password)

              {

                     // Function to add the employee details  to the employees table when the user intends to register himself.

 

                     // Exceutes the stored procedure named addempstoredproc.

                    

                     SqlConnection myconnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

                     SqlCommand myCommand = new SqlCommand("addempstoredproc",myconnection);

                     myCommand.CommandType = CommandType.StoredProcedure;

 

                     SqlParameter parameterfullname = new SqlParameter("@FullName",SqlDbType.NVarChar,50);

                     parameterfullname.Value = fullname;

                     myCommand.Parameters.Add(parameterfullname);   // Interacting with the stored procedure.

 

                     SqlParameter parameteremail = new SqlParameter("@Email",SqlDbType.NVarChar,50);

                     parameteremail.Value = email;

                     myCommand.Parameters.Add(parameteremail);

 

                     SqlParameter parameterpassword = new SqlParameter("@Password",SqlDbType.NVarChar,50);

                     parameterpassword.Value = password;

                     myCommand.Parameters.Add(parameterpassword);   // Assign the server control values to the stored procedure parameters.

 

                     SqlParameter parametercustomerid = new SqlParameter("@CustomerID",SqlDbType.NVarChar,50);

                     parametercustomerid.Direction = ParameterDirection.Output;

                     myCommand.Parameters.Add(parametercustomerid);

 

                     // Output the customer id genereated by the stored procedure.

 

                     try

                     {

                           myconnection.Open();

                           myCommand.ExecuteNonQuery(); // Executes the stored procedure.

                           myconnection.Close();

                           string customerid =(string)parametercustomerid.Value;

                           return customerid; // Returns the customerid

                     }

                     catch(Exception e){

                      return e.Message;

                    

                     }

 

 

              }

 

              public Employee getemployeedetail(int userid)

              {

                    

                     // Function to get the employee details from the employees table.

                     // Executes the stored procedure named getemployeedetail.

                     SqlConnection myconnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

                     SqlCommand myCommand = new SqlCommand("getemployeedetail",myconnection);

                     myCommand.CommandType = CommandType.StoredProcedure;

                     SqlParameter parameteruserid = new SqlParameter("@userid",SqlDbType.Int,5);

                     parameteruserid.Value = userid;                    // This stored procedure takes in the userid and in return gives you the employee details

                     myCommand.Parameters.Add(parameteruserid);

 

                     SqlParameter parameterfullname = new SqlParameter("@FullName",SqlDbType.NVarChar,50);

                     parameterfullname.Direction = ParameterDirection.Output; // Outputs the fullname

                     myCommand.Parameters.Add(parameterfullname);

 

                     SqlParameter parameteremail = new SqlParameter("@Email",SqlDbType.NVarChar,50);

                     parameteremail.Direction = ParameterDirection.Output;

                     myCommand.Parameters.Add(parameteremail); // Outputs the email id

 

                     SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);

                     parameterPassword.Direction = ParameterDirection.Output; // Outputs the password.

                     myCommand.Parameters.Add(parameterPassword);

 

                    

                           myconnection.Open();

                           myCommand.ExecuteNonQuery(); // Executes the stored procedure.

                           myconnection.Close();

                    

 

                     Employee employeedet = new Employee();

                     employeedet.FullName = (string)parameterfullname.Value;

                     employeedet.Email = (string)parameteremail.Value;

                     employeedet.Password= (string)parameterPassword.Value;

 

                     return employeedet; // Returns the employee details to the main page so that it can be used for personalization.

 

 

              }

 

      

 

              public int login(string email,string password)

              {

                     // Function to determine successful login.

                     // Exceutes the stored procedure named employeelogin

                     SqlConnection myconnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

                     SqlCommand myCommand = new SqlCommand("employeelogin",myconnection);

                     myCommand.CommandType = CommandType.StoredProcedure;

                     SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);

                     parameterEmail.Value = email;

                     myCommand.Parameters.Add(parameterEmail);

 

                     SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);

                     parameterPassword.Value = password;

                     myCommand.Parameters.Add(parameterPassword);

 

                     SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);

                     parameterCustomerID.Direction = ParameterDirection.Output;

                     myCommand.Parameters.Add(parameterCustomerID);

 

                     // Open the connection and execute the Command

                     myconnection.Open();

                     myCommand.ExecuteNonQuery();

                     myconnection.Close();

 

                     int customerId = (int)(parameterCustomerID.Value);  // Outputs the customer id

 

                     if (customerId == 0)

                     {

                           return 0;

                     }

                     else

                     {

                           return customerId;

                     }

              }

       }

}

 

 

Back to Main Page