Exemple #1
0
        public DataSet getmenu(string department)
        {
            EmployeeDao employeedao = new EmployeeDao();
            Employee employee = employeedao.getempdepartment(department);
            ConnectionDao ConnectionDao = new ConnectionDao();
            SqlDataAdapter adp = new SqlDataAdapter("select department_name,weburl from Department where Department_Name='" + employee.department + "'", ConnectionDao.getConnection());
            DataSet ds4 = new DataSet();
            adp.Fill(ds4);
            string Department = ds4.Tables[0].Rows[0]["department_name"].ToString();
            if (Department == "Sales")
            {
                ds4 = addMenu(ds4, "Email");
            }

            if (Department == "Corporate")
            {
                ds4.Tables[0].Rows.RemoveAt (0);
                ds4.AcceptChanges();

                ds4 = addMenu(ds4, "Customer");
                ds4 = addMenu(ds4, "Email");

                ds4 = addMenu(ds4, "Ticketing");
                ds4 = addMenu(ds4, "Dashboard");
                ds4 = addMenu(ds4, "Reports");

            }
            return ds4;
        }
        protected void btnsearch_Click(object sender, EventArgs e)
        {
            EmployeeDao empsearch = new EmployeeDao();

            DataSet ds = new DataSet();
            ds = empsearch.getemployeedetailsearch(txtlast.Text.Trim());
            if (ds.Tables[0].Rows.Count > 0)
            {
                grdemp.DataSource = ds;
                grdemp.DataBind();
            }
            else
            {
                grdemp.DataBind();

            }
        }
 public List<Employee> getEmployeeByLastName(string lastName)
 {
     EmployeeDao EmployeeDao = new EmployeeDao();
     return EmployeeDao.getEmployeeByLastName(lastName);
 }
 public Employee getEmployeeById(string id)
 {
     EmployeeDao EmployeeDao = new EmployeeDao();
     return EmployeeDao.getEmployeeById(id);
 }
 public Employee getEmployeeByEmail(string email)
 {
     EmployeeDao EmployeeDao = new EmployeeDao();
     return EmployeeDao.getEmployeeByEmail(email);
 }
        public string updateEmployee(Employee employee)
        {
            SqlConnection conn = null;
            SqlTransaction trans = null;
            string returnString = IdProConstants.SUCCESS;
            UserDAO userDao = new UserDAO();
            EmployeeDao EmployeeDao = new EmployeeDao();
            ConnectionDao ConnectionDao = new ConnectionDao();
            UserServices userServices = new UserServices();
            Employee employeeById = EmployeeDao.getEmployeeById(employee.EmployeeId);
            if (!(employeeById.Email.Trim().Equals(employee.Email.Trim())) && isEmployeeEmailexist(employee.Email.Trim()))
            {
                returnString = "Employee Email already Exist in the system";
            }
            else if (!(employeeById.USER.Username.Trim().ToUpper().Equals(employee.USER.Username.Trim().ToUpper())) && userServices.isUserNameExist(employee.USER.Username))
            {
                returnString = "UserName already Exit in the system";
            }
            else
            {
                try
                {
                    conn = ConnectionDao.getConnection();
                    trans = conn.BeginTransaction();
                    HttpContext.Current.Session["prevUserName"] = employeeById.USER.Username;
                    returnString = userDao.updateUser(conn, trans, employee.USER);
                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        returnString = EmployeeDao.updateEmployee(conn, trans, employee);
                    }
                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        trans.Commit();
                    }
                    else
                    {
                        trans.Rollback();
                    }
                }
                catch (Exception exception)
                {
                    trans.Rollback();
                    System.Diagnostics.Trace.WriteLine("[EmployeeServices:updateEmployee] Exception " + exception.StackTrace);

                }
                finally
                {
                    ConnectionDao.closeConnection(conn);

                }
            }

            return returnString;
        }
        public bool isEmployeeEmailexist(string email)
        {
            EmployeeDao EmployeeDao = new EmployeeDao();

            return EmployeeDao.getEmployeeByEmail(email.Trim()) != null;
        }
        public string addEmployee(Employee employee)
        {
            SqlConnection conn = null;
            SqlTransaction trans = null;

            string returnString = IdProConstants.SUCCESS;

            UserDAO userDao = new UserDAO();
            EmployeeDao EmployeeDao = new EmployeeDao();
            ConnectionDao ConnectionDao = new ConnectionDao();
            UserServices userServices = new UserServices();

            if (isEmployeeEmailexist(employee.Email.Trim()))
            {
                returnString = "Employee Email already Exist in the system";
            }
            // else if (userServices.isUserNameExist(employee.USER.Username))
            else if (userServices.isUserNameExist(employee.Username))
            {
                returnString = "UserName already Exit in the system";
            }
            else
            {

                try
                {
                    conn = ConnectionDao.getConnection();

                    trans = conn.BeginTransaction();

                    returnString = userDao.addUser(conn, trans, employee.USER);

                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        returnString = EmployeeDao.addEmployee(conn, trans, employee);

                    }

                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        trans.Commit();

                    }
                    else
                    {
                        trans.Rollback();
                    }
                }
                catch (Exception exception)
                {
                    trans.Rollback();
                    System.Diagnostics.Trace.WriteLine("[EmployeeServices:addEmployee] Exception " + exception.StackTrace);

                }
                finally
                {
                    ConnectionDao.closeConnection(conn);

                }
            }

            return returnString;
        }
        /*

        public List<EmployeeSearchResult> getEmployeeSearchResult(string lastName, string userName, string email)
        {
            List<EmployeeSearchResult> employeeSearchResultList = new List<EmployeeSearchResult>();

            EmployeeDao EmployeeDao = new EmployeeDao();

            if (userName != null && !IdProConstants.DEFAULTSTRING.Equals(userName.Trim()))
            {
                userName = userName.Trim();
                Employee employee = EmployeeDao.getEmployeeByUserName(userName);
                EmployeeSearchResult searchResult = convertEmployeeInSearchResultObject(employee);
                employeeSearchResultList.Add(searchResult);
            }

            else if (email != null && !IdProConstants.DEFAULTSTRING.Equals(email.Trim()))
            {
                email = email.Trim();
                Employee employee = EmployeeDao.getEmployeeByEmail(email);
                EmployeeSearchResult searchResult = convertEmployeeInSearchResultObject(employee);
                employeeSearchResultList.Add(searchResult);
            }

            else if (lastName != null && !IdProConstants.DEFAULTSTRING.Equals(lastName.Trim()))
            {
                lastName = lastName.Trim();
                List<Employee> employeeList = EmployeeDao.getEmployeeByLastName(lastName);
                foreach (Employee e in employeeList)
                {
                    EmployeeSearchResult searchResult = convertEmployeeInSearchResultObject(e);
                    employeeSearchResultList.Add(searchResult);
                }

            }

            return employeeSearchResultList;

        }

        public EmployeeSearchResult convertEmployeeInSearchResultObject(Employee employee)
        {
            EmployeeSearchResult result = new EmployeeSearchResult();

            if (employee != null)
            {
                result.NAME = employee.getFirstName() + " " + employee.getLastName();

                result.STATUS = employee.getEmployeeStatus();

                result.USERNAME = employee.getUser().getUserName();
            }
            return result;

        }

         *
         * */
        public Employee getEmployeeByUserName(string userName)
        {
            EmployeeDao EmployeeDao = new EmployeeDao();

            return EmployeeDao.getEmployeeByUserName(userName);
        }