Exemplo n.º 1
0
        //Get the ID number in the database to register information for new employees.
        public int GetRegisterNumber()
        {
            Modules.DBModules     DB             = new Modules.DBModules();
            Models.SearchEmployee SearchEmployee = new Models.SearchEmployee();
            SqlDataReader         sqlRdr         = null;
            StringBuilder         strSql         = new StringBuilder();

            strSql.Append("SELECT EmployeeId FROM M_Employee");
            try
            {
                if (!DB.DB_Connect())
                {
                }
                if (DB.DB_SqlReader(strSql.ToString(), ref sqlRdr))
                {
                }
                while (sqlRdr.Read())
                {
                    SearchEmployee = new Models.SearchEmployee();

                    SearchEmployee.EmployeeId = int.Parse(sqlRdr["EmployeeId"].ToString());
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (sqlRdr != null)
                {
                    if (!sqlRdr.IsClosed)
                    {
                        sqlRdr.Close();
                    }
                }
                DB.DB_Close();
            }
            return(SearchEmployee.EmployeeId);
        }
Exemplo n.º 2
0
        public List <Models.SearchEmployee> SearchResult(int SelectDepartmentId, string SearchEmployeeName)
        {
            bool sqlFlag = false;

            Modules.DBModules            DB                 = new Modules.DBModules();
            Models.SearchEmployee        SearchEmployee     = new Models.SearchEmployee();
            List <Models.SearchEmployee> SearchEmployeeList = new List <Models.SearchEmployee>();
            SqlDataReader sqlRdr = null;
            StringBuilder strSql = new StringBuilder();

            strSql.Append("SELECT M_Employee.EmployeeName, M_Employee.CompanyEmployeeCode, M_Department.DepartmentName, M_Department.RegionName");
            strSql.Append(" FROM M_Department");
            strSql.Append(" INNER JOIN M_Employee ON M_Department.DepartmentId=M_Employee.DepartmentId");

            // When the user select Department in Search condition.
            if (SelectDepartmentId != 0)
            {
                strSql.Append(" WHERE");
                strSql.Append(" M_Employee.DepartmentId = ");
                strSql.AppendFormat("{0}", SelectDepartmentId);
                sqlFlag = true;
            }

            if (SearchEmployeeName != "")
            {
                if (sqlFlag == true)
                {
                    strSql.Append(" AND");
                }
                if (SelectDepartmentId == 0)
                {
                    strSql.Append(" WHERE");
                }
                strSql.Append(" M_Employee.EmployeeName = ");
                strSql.AppendFormat("'{0}'", SearchEmployeeName);
            }
            try
            {
                if (!DB.DB_Connect())
                {
                }
                if (DB.DB_SqlReader(strSql.ToString(), ref sqlRdr))
                {
                }
                while (sqlRdr.Read())
                {
                    SearchEmployee = new Models.SearchEmployee();

                    SearchEmployee.EmployeeName = sqlRdr["EmployeeName"].ToString();

                    SearchEmployee.CompanyEmployeeCode = sqlRdr["CompanyEmployeeCode"].ToString();

                    SearchEmployee.DepartmentName = sqlRdr["DepartmentName"].ToString();

                    SearchEmployee.RegionName = sqlRdr["RegionName"].ToString();

                    SearchEmployeeList.Add(SearchEmployee);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (sqlRdr != null)
                {
                    if (!sqlRdr.IsClosed)
                    {
                        sqlRdr.Close();
                    }
                }
                DB.DB_Close();
            }
            return(SearchEmployeeList);
        }