Example #1
0
        /// <summary>
        /// Gets a single employee
        /// </summary>
        /// <param name="Emp">Employee parameter</param>
        /// <returns>Returns a single employee</returns>
        public Employee GetEmployee(Employee Emp)
        {
            SqlConnection corpcn = new SqlConnection(Settings.Default.cnHelpDesk);

            var sb = new StringBuilder();
            sb.Append("Select EmpID, EmpFName, EmpLName, EmpUName ");
            sb.Append("From Employee ");
            sb.Append("Where EmpID = '").Append(Emp.EmpID).Append("'");

            using (corpcn)
            {
                //Needed this here to be able to use the variable towards the end. Some type of scope error.
                Employee employee = null;

                SqlCommand corpCmd = corpcn.CreateCommand();
                corpCmd.CommandType = CommandType.Text;
                corpCmd.CommandText = sb.ToString();
                corpcn.Open();
                SqlDataReader corprdr = corpCmd.ExecuteReader();

                while (corprdr.Read())
                {
                    employee = CreateEmployee(corprdr);
                }

                corprdr.Close();

                return employee;
            }
        }
Example #2
0
        /// <summary>
        /// Adds an employee
        /// </summary>
        /// <param name="emp">Employee parameter</param>
        public void InsertEmployee(Employee emp)
        {
            SqlConnection corpcn = new SqlConnection(Settings.Default.cnHelpDesk);

            var sb = new StringBuilder();
            sb.Append("Insert Into [Employee]");
            sb.Append(" ([EmpFName], [EmpLName], [EmpUName])");
            sb.Append(" Values (");
            sb.Append("'").Append(emp.EmpFName).Append("',");
            sb.Append("'").Append(emp.EmpLName).Append("',");
            sb.Append("'").Append(emp.EmpUName).Append("')");

            using (corpcn)
            {
                SqlCommand corpCmd = corpcn.CreateCommand();
                corpCmd.CommandType = CommandType.Text;
                corpCmd.CommandText = sb.ToString();
                corpcn.Open();
                corpCmd.ExecuteNonQuery();
            }
        }
Example #3
0
 /// <summary>
 /// Creates an internal employee
 /// </summary>
 /// <param name="dr">SQL Data Reader</param>
 /// <returns>Employee</returns>
 private Employee CreateEmployee(SqlDataReader dr)
 {
     var e = new Employee();
     e.EmpID = (int)dr["EmpID"];
     e.EmpFName = dr["EmpFName"].ToString();
     e.EmpLName = dr["EmpLName"].ToString();
     e.EmpUName = dr["EmpUName"].ToString();
     return e;
 }
Example #4
0
        /// <summary>
        /// Updates an existing employee
        /// </summary>
        /// <param name="emp">Employee parameter</param>
        public void UpdateEmployee(Employee emp)
        {
            SqlConnection corpcn = new SqlConnection(Settings.Default.cnHelpDesk);

            var sb = new StringBuilder();
            sb.Append("Update [Employee]");
            sb.Append(" Set ");
            sb.Append("[EmpFName]='").Append(emp.EmpFName).Append("',");
            sb.Append("[EmpLName]='").Append(emp.EmpLName).Append("',");
            sb.Append("[EmpUName]='").Append(emp.EmpUName).Append("'");
            sb.Append("Where [EmpID]='").Append(emp.EmpID).Append("';");

            using (corpcn)
            {
                SqlCommand corpCmd = corpcn.CreateCommand();
                corpCmd.CommandType = CommandType.Text;
                corpCmd.CommandText = sb.ToString();
                corpcn.Open();
                corpCmd.ExecuteNonQuery();
            }
        }
Example #5
0
 /// <summary>
 /// Gets an Employee Username by ID
 /// </summary>
 /// <param name="eID">Employee ID</param>
 /// <returns></returns>
 public string GetEmployeeByID(int eID)
 {
     Employee cluster = new Employee();
     foreach (Employee emp in empsList)
     {
         if (emp.EmpID == eID)
         {
             cluster = emp;
         }
     }
     cluster = eR.GetEmployee(cluster);
     //Tuples allow returning multiple values back to the caller of a method. http://msdn.microsoft.com/en-us/library/dd268536(v=vs.110).aspx
     return cluster.EmpUName;
 }
Example #6
0
 /// <summary>
 /// Gets a single employee
 /// </summary>
 /// <param name="eUN">Employee User Name</param>
 /// <returns>Single Employee</returns>
 public Tuple<int, string, string, string> GetEmployee(string eUN)
 {
     Employee cluster = new Employee();
     foreach (Employee emp in empsList)
     {
         if (emp.EmpUName == eUN)
         {
             cluster = emp;
         }
     }
     cluster = eR.GetEmployee(cluster);
     //Tuples allow returning multiple values back to the caller of a method. http://msdn.microsoft.com/en-us/library/dd268536(v=vs.110).aspx
     return new Tuple<int,string,string,string>(cluster.EmpID, cluster.EmpFName, cluster.EmpLName, cluster.EmpUName);
 }