Exemplo n.º 1
0
        public List <IEmployee> List_Employees()
        {
            List <IEmployee> lstEmployee = new List <IEmployee>();
            SqlCommand       myCommand;
            SqlConnection    myConnection = DBUtility.getConnection();

            try
            {
                using (myConnection)
                {
                    myCommand             = new SqlCommand("sp_EmployeeList", myConnection);
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myConnection.Open();
                    SqlDataReader objSqlDataReader = myCommand.ExecuteReader();

                    while (objSqlDataReader.Read())
                    {
                        int      EmployeeID  = Int32.Parse(objSqlDataReader["EmployeeID"].ToString());
                        string   Designation = (string)objSqlDataReader["Designation"];
                        string   password    = (string)objSqlDataReader["Password"];
                        bool     isHr        = (bool)objSqlDataReader["IsHR"];
                        DateTime dob         = (DateTime)objSqlDataReader["DOB"];
                        DateTime doj         = (DateTime)objSqlDataReader["DOJ"];
                        int      projid      = Int32.Parse(objSqlDataReader["ProjectID"].ToString());
                        string   gender      = (string)objSqlDataReader["Gender"];
                        string   division    = (string)objSqlDataReader["Division"];
                        float    ctc         = float.Parse(Convert.ToString(objSqlDataReader["CTC"]));
                        string   location    = (string)objSqlDataReader["Location"];
                        int      exp         = (int)objSqlDataReader["Experience"];

                        string EmployeeName = (string)objSqlDataReader["EmployeeName"];
                        int    UnitHeadID;
                        try
                        {
                            UnitHeadID = (int)objSqlDataReader["UnitHeadID"];
                        }
                        catch (Exception)
                        {
                            UnitHeadID = 0;
                        }

                        IEmployee newemployee = EmployeeFactory.Create_employee(EmployeeID, EmployeeName, UnitHeadID, projid, isHr, dob, doj, gender, division, ctc, Designation, password, location, exp);
                        lstEmployee.Add(newemployee);
                    }
                    objSqlDataReader.Close();
                }
                return(lstEmployee);
            }
            catch (Exception EE)
            {
                Console.WriteLine(EE);
                Console.Read();
                return(null);
            }
            finally
            {
                myConnection.Close();
            }
        }