Ejemplo n.º 1
0
 /// <summary>
 /// 新建员工
 /// </summary>
 /// <param name="employee">员工实体对象</param>
 /// <param name="tran">中间事务对象</param>
 /// <returns>返回处理后的员工实体对象</returns>
 public Employee Add(Employee employee, ICTransaction tran)
 {
     IList<Employee> employeeList = new List<Employee>();
     employeeList.Add(employee);
     employeeList = this.Add(employeeList, tran);
     return employeeList == null ? null : employeeList[0];
 }
Ejemplo n.º 2
0
        public void AddDataTest()
        {
            #region Clear All Data

            OrgHandler.DeleteEmployee(new EmployeeSearcher());
            OrgHandler.DeletePosition(new PositionSearcher());
            OrgHandler.DeleteDepartment(new DepartmentSearcher());
            OrgHandler.DeleteCompany(new CompanySearcher());

            #endregion

            string companyName = " Com. Ltd.";
            Company company = null;
            Department department = null;
            Position position = null;
            Employee employee = null;
            int depCode = 1;
            int posCode = 1;
            int empCode = 1;
            int empCount = 30;
            Random rand = new Random(DateTime.Now.Hour);

            string[][] companyNamePool = new string[][] {
                new string[]{"ABC","10201"},
                new string[]{"DEF","10301"},
                new string[]{"GHI","10202"},
                new string[]{"JKL","10203"},
                new string[]{"MNO","10401"}
            };

            string[] departmentNamePool = new string[]{
                "GM",
                "Finance",
                "HR",
                "Sales",
                "Marketing",
                "Executive"
            };

            string[] positionNamePool = new string[] {
                "GM",
                "Specialist"
            };

            long allEmpCount = 780;

            foreach (string[] cName in companyNamePool)
            {
                company = new Company();
                company.Name = cName[0] + companyName;
                company.CompanyCode = cName[1];
                company.CreaterId = "00000000000";
                company.UpdatorId = "00000000000";
                company.RVersion = 1;
                company.Status = 1;
                OrgHandler.AddCompany(company);
                depCode = 1;
                empCode = 1;
                posCode = 1;

                foreach (string dName in departmentNamePool)
                {
                    department = new Department();
                    department.CurrCompany = company;
                    department.Name = dName;
                    department.DepartmentCode = "2" + company.CompanyCode + string.Format("{0:0000}", depCode);
                    department.CreaterId = "00000000000";
                    department.UpdatorId = "00000000000";
                    department.RVersion = 1;
                    department.Status = 1;
                    OrgHandler.AddDepartment(department);

                    foreach (string pName in positionNamePool)
                    {
                        position = new Position();
                        position.CurrCompany = company;
                        position.CurrDepartment = department;
                        position.PositionCode = "3" + company.CompanyCode + string.Format("{0:0000}", posCode);
                        position.CreaterId = "00000000000";
                        position.UpdatorId = "00000000000";
                        position.RVersion = 1;
                        position.Status = 1;

                        if (pName.Equals("GM"))
                        {
                            if (dName.Equals("GM"))
                            {
                                position.Name = pName;
                            }
                            else
                            {
                                position.Name = dName + " " + pName;
                            }

                            empCount = 1;
                        }
                        else
                        {
                            position.Name = dName + " " + pName;

                            empCount = 30;
                        }

                        OrgHandler.AddPosition(position);

                        for (int i = 1; i <= empCount; i++)
                        {
                            employee = new Employee();
                            employee.Name = "Emp" + Guid.NewGuid().ToString().ToLower().Replace("-", "").Substring(0, 5);
                            employee.EmployeeCode = "5" + company.CompanyCode + string.Format("{0:000000}", empCode);
                            employee.CurrCompany = company;
                            employee.CurrDepartment = department;
                            employee.CurrPosition = position;
                            employee.CreaterId = "00000000000";
                            employee.UpdatorId = "00000000000";
                            employee.RVersion = 1;
                            employee.Status = 1;
                            employee.Birthday = Convert.ToDateTime("19" + rand.Next(70,90).ToString() + "-" + rand.Next(1, 9).ToString() + "-" + rand.Next(1, 28).ToString());
                            employee.Sex = rand.Next(1, 2);
                            employee.StartWorkDate = Convert.ToDateTime(employee.Birthday).AddYears(20).AddMonths(rand.Next(1, 12));
                            employee.JoinDate = rand.Next(1, 10) > 6 ? employee.StartWorkDate : Convert.ToDateTime(employee.StartWorkDate).AddYears(rand.Next(1, 2)).AddMonths(rand.Next(1, 12));

                            if (dName.Equals("GM"))
                            {
                                employee.Rand = 20;
                            }
                            else if (pName.Equals("GM"))
                            {
                                employee.Rand = rand.Next(15, 19);
                            }
                            else
                            {
                                employee.Rand = rand.Next(5, 14);
                            }

                            OrgHandler.AddEmployee(employee);

                            if(QueryTest.EmployeeIdList.Count < 10 && !dName.Equals("GM") && !pName.Equals("GM"))
                            {
                                QueryTest.EmployeeIdList.Add(employee.EmployeeId);
                                QueryTest.EmployeeCodeList.Add(employee.EmployeeCode);
                            }

                            empCode++;
                        }

                        posCode++;

                        if (dName.Equals("GM"))
                        {
                            break;
                        }
                    }

                    depCode++;
                }
            }

            EmployeeSearcher empSearcher = new EmployeeSearcher();
            long newDataCount = OrgHandler.CountEmployee(empSearcher);
            Assert.AreEqual(allEmpCount, newDataCount);
        }
Ejemplo n.º 3
0
        public void TransactionRollBackTest()
        {
            ICTransaction tran = DalManager.DalFactory.BeginTransaction();

            Employee existEmployee = OrgHandler.FindEmployeeById(QueryTest.EmployeeIdList[2]);
            Position newPosition = new Position();
            newPosition.CurrCompany = existEmployee.CurrCompany;
            newPosition.CurrDepartment = existEmployee.CurrDepartment;
            newPosition.PositionCode = "3" + existEmployee.CurrCompany.CompanyCode + string.Format("{0:0000}", "13");
            newPosition.CreaterId = "00000000000";
            newPosition.UpdatorId = "00000000000";
            newPosition.RVersion = 1;
            newPosition.Status = 1;
            OrgHandler.AddPosition(newPosition, tran);

            Employee newEmployee = new Employee();
            newEmployee.Name = "Emp" + Guid.NewGuid().ToString().ToLower().Replace("-", "").Substring(0, 5);
            newEmployee.EmployeeCode = "5" + existEmployee.CurrCompany.CompanyCode + string.Format("{0:000000}", "159");
            newEmployee.CurrCompany = existEmployee.CurrCompany;
            newEmployee.CurrDepartment = existEmployee.CurrDepartment;
            newEmployee.CurrPosition = newPosition;
            newEmployee.CreaterId = "00000000000";
            newEmployee.UpdatorId = "00000000000";
            newEmployee.RVersion = 1;
            newEmployee.Status = 1;
            newEmployee.Birthday = Convert.ToDateTime("1981-11-27");
            newEmployee.Sex = 1;
            newEmployee.StartWorkDate = Convert.ToDateTime("2005-4-1");
            newEmployee.JoinDate = Convert.ToDateTime("2005-4-1");
            newEmployee.Rand = 10;
            OrgHandler.AddEmployee(newEmployee, tran);

            newEmployee = new Employee();
            newEmployee.Name = "Emp" + Guid.NewGuid().ToString().ToLower().Replace("-", "").Substring(0, 5);
            newEmployee.EmployeeCode = "5" + existEmployee.CurrCompany.CompanyCode + string.Format("{0:000000}", "160");
            newEmployee.CurrCompany = existEmployee.CurrCompany;
            newEmployee.CurrDepartment = existEmployee.CurrDepartment;
            newEmployee.CurrPosition = newPosition;
            newEmployee.CreaterId = "00000000000";
            newEmployee.UpdatorId = "00000000000";
            newEmployee.RVersion = 1;
            newEmployee.Status = 1;
            newEmployee.Birthday = Convert.ToDateTime("1981-12-02");
            newEmployee.Sex = 1;
            newEmployee.StartWorkDate = Convert.ToDateTime("2005-4-3");
            newEmployee.JoinDate = Convert.ToDateTime("2005-4-3");
            newEmployee.Rand = 11;
            OrgHandler.AddEmployee(newEmployee, tran);

            ((HibernateTransaction)tran).CurrentTransaction.Rollback();

            long allCountPosEx = 56;
            long allCountPos = OrgHandler.CountPosition(new PositionSearcher());
            Assert.AreEqual(allCountPosEx, allCountPos);
            long allCountEmpEx = 782;
            long allCountEmp = OrgHandler.CountEmployee(new EmployeeSearcher());
            Assert.AreEqual(allCountEmpEx, allCountEmp);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新员工数据
        /// </summary>
        /// <param name="employee">员工实体对象</param>
        /// <param name="tran">中间事务对象</param>
        public void Update(Employee employee, ICTransaction tran)
        {
            Employee oldEmployee = this.FindSingle(employee.EmployeeId, tran);
            int updateColCount = 0;

            if (employee == null)
            {
                throw new ArgumentException("employee");
            }

            if (oldEmployee == null)
            {
                throw new ResponseException((int)ResultCode.NoDataExists, employee.EmployeeCode);
            }

            if (employee.RVersion != oldEmployee.RVersion)
            {
                throw new ResponseException((int)ResultCode.VersionChanged, oldEmployee.RVersion.ToString());
            }

            StringBuilder query = new StringBuilder();
            query.AppendLine(@"UPDATE ");
            query.AppendLine(@"   `Employee`");
            query.AppendLine(@"SET ");
            query.AppendLine(@"   `EmployeeId` = @EmployeeId ");

            if ((!string.IsNullOrEmpty(employee.EmployeeCode) && !employee.EmployeeCode.Equals(oldEmployee.EmployeeCode))
                || (!string.IsNullOrEmpty(oldEmployee.EmployeeCode) && !oldEmployee.EmployeeCode.Equals(employee.EmployeeCode)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`EmployeeCode` = @EmployeeCode ");
            }

            if ((!string.IsNullOrEmpty(employee.Name) && !employee.Name.Equals(oldEmployee.Name))
                || (!string.IsNullOrEmpty(oldEmployee.Name) && !oldEmployee.Name.Equals(employee.Name)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`Name` = @Name ");
            }

            if (((DateTime)oldEmployee.Birthday).CompareTo(employee.Birthday) != 0 && employee.Birthday != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,`Birthday` = @Birthday ");
            }

            if (employee.Sex != oldEmployee.Sex)
            {
                updateColCount++;
                query.AppendLine(@"  ,`Sex` = @Sex ");
            }

            if ((!string.IsNullOrEmpty(employee.CompanyId) && !employee.CompanyId.Equals(oldEmployee.CompanyId))
                || (!string.IsNullOrEmpty(oldEmployee.CompanyId) && !oldEmployee.CompanyId.Equals(employee.CompanyId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`CompanyId` = @CompanyId ");
            }

            if ((!string.IsNullOrEmpty(employee.DepartmentId) && !employee.DepartmentId.Equals(oldEmployee.DepartmentId))
                || (!string.IsNullOrEmpty(oldEmployee.DepartmentId) && !oldEmployee.DepartmentId.Equals(employee.DepartmentId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`DepartmentId` = @DepartmentId ");
            }

            if ((!string.IsNullOrEmpty(employee.PositionId) && !employee.PositionId.Equals(oldEmployee.PositionId))
                || (!string.IsNullOrEmpty(oldEmployee.PositionId) && !oldEmployee.PositionId.Equals(employee.PositionId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`PositionId` = @PositionId ");
            }

            if (employee.Rand != oldEmployee.Rand)
            {
                updateColCount++;
                query.AppendLine(@"  ,`Rand` = @Rand ");
            }

            if (employee.Status != oldEmployee.Status)
            {
                updateColCount++;
                query.AppendLine(@"  ,`Status` = @Status ");
            }

            if ((!string.IsNullOrEmpty(employee.UpdatorId) && !employee.UpdatorId.Equals(oldEmployee.UpdatorId))
                || (!string.IsNullOrEmpty(oldEmployee.UpdatorId) && !oldEmployee.UpdatorId.Equals(employee.UpdatorId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`UpdatorId` = @UpdatorId ");
            }

            if (oldEmployee.UpdateTime.CompareTo(employee.UpdateTime) != 0 && employee.UpdateTime != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,`UpdateTime` = @UpdateTime ");
            }

            if (((DateTime)oldEmployee.StartWorkDate).CompareTo(employee.StartWorkDate) != 0 && employee.StartWorkDate != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,`StartWorkDate` = @StartWorkDate ");
            }

            if (((DateTime)oldEmployee.JoinDate).CompareTo(employee.JoinDate) != 0 && employee.JoinDate != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,`JoinDate` = @JoinDate ");
            }

            query.AppendLine(@"  ,`RVersion` = @RVersion ");
            query.AppendLine(@"WHERE ");
            query.AppendLine(@"   `EmployeeId` = @EmployeeId ");

            if (updateColCount == 0)
            {
                return;
            }

            employee.UpdateTime = DateTime.Now;
            MySqlParameter[] paramCollection = new MySqlParameter[15];
            paramCollection[0] = new MySqlParameter("@EmployeeId", MySqlDbType.String, 40);
            paramCollection[1] = new MySqlParameter("@EmployeeCode", MySqlDbType.String, 15);
            paramCollection[2] = new MySqlParameter("@Name", MySqlDbType.String, 50);
            paramCollection[3] = new MySqlParameter("@Birthday", MySqlDbType.DateTime);
            paramCollection[4] = new MySqlParameter("@Sex", MySqlDbType.Int32);
            paramCollection[5] = new MySqlParameter("@CompanyId", MySqlDbType.String, 40);
            paramCollection[6] = new MySqlParameter("@DepartmentId", MySqlDbType.String, 40);
            paramCollection[7] = new MySqlParameter("@PositionId", MySqlDbType.String, 40);
            paramCollection[8] = new MySqlParameter("@Rand", MySqlDbType.Int32);
            paramCollection[9] = new MySqlParameter("@RVersion", MySqlDbType.Int32);
            paramCollection[10] = new MySqlParameter("@Status", MySqlDbType.Int32);
            paramCollection[11] = new MySqlParameter("@UpdatorId", MySqlDbType.String, 40);
            paramCollection[12] = new MySqlParameter("@UpdateTime", MySqlDbType.DateTime);
            paramCollection[13] = new MySqlParameter("@StartWorkDate", MySqlDbType.DateTime);
            paramCollection[14] = new MySqlParameter("@JoinDate", MySqlDbType.DateTime);

            paramCollection[0].Value = employee.EmployeeId;
            paramCollection[1].Value = employee.EmployeeCode;
            paramCollection[2].Value = employee.Name;
            paramCollection[3].Value = employee.Birthday;
            paramCollection[4].Value = employee.Sex;
            paramCollection[5].Value = employee.CompanyId;
            paramCollection[6].Value = employee.DepartmentId;
            paramCollection[7].Value = employee.PositionId;
            paramCollection[8].Value = employee.Rand;
            paramCollection[9].Value = employee.RVersion;
            paramCollection[10].Value = employee.Status;
            paramCollection[11].Value = employee.UpdatorId;
            paramCollection[12].Value = employee.UpdateTime;
            paramCollection[13].Value = employee.StartWorkDate;
            paramCollection[14].Value = employee.JoinDate;

            try
            {
                int effectCount = 0;

                if (employee != null)
                {
                    if (tran != null)
                    {
                        effectCount = MySqlHelper.ExecuteNonQuery((MySqlConnection)tran.Connection, query.ToString(), paramCollection);
                    }
                    else
                    {
                        effectCount = MySqlHelper.ExecuteNonQuery(this.CurrentConnectionString, query.ToString(), paramCollection);
                    }
                }

                // 抛出一个异常
                if (effectCount == 0)
                {
                    throw new ResponseException((int)ResultCode.NoDataUpdate, employee.EmployeeCode);
                }
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 更新员工数据
 /// </summary>
 /// <param name="employee">员工实体对象</param>
 public void Update(Employee employee)
 {
     this.Update(employee, null);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 查找指定条件的员工分页集合
        /// </summary>
        /// <param name="employeeSearcher">员工查询对象</param>
        /// <param name="pager">分页对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回查找到的分页集合,包括按条件可查询到的所有记录数和当前分页的对象集合</returns>
        public PageList<Employee> FindList(EmployeeSearcher employeeSearcher, Pager pager, ICTransaction tran)
        {
            PageList<Employee> resultList = new PageList<Employee>();
            PageDataTable pageDataTable = this.FindDataTable(employeeSearcher, pager, tran);
            Employee ele = null;

            if (pageDataTable != null)
            {
                resultList = new PageList<Employee>();
                resultList.PageIndex = pageDataTable.PageIndex;
                resultList.TotalCount = pageDataTable.TotalCount;

                if (pageDataTable.RecordList != null && pageDataTable.RecordList.Rows.Count > 0)
                {
                    foreach (DataRow aRow in pageDataTable.RecordList.Rows)
                    {
                        ele = new Employee();

                        if (!(aRow["EmployeeId"] is DBNull))
                        {
                            ele.EmployeeId = aRow["EmployeeId"].ToString();
                        }

                        if (!(aRow["CompanyId"] is DBNull))
                        {
                            ele.CompanyId = aRow["CompanyId"].ToString();
                        }

                        if (!(aRow["DepartmentId"] is DBNull))
                        {
                            ele.DepartmentId = aRow["DepartmentId"].ToString();
                        }

                        if (!(aRow["PositionId"] is DBNull))
                        {
                            ele.PositionId = aRow["PositionId"].ToString();
                        }

                        if (!(aRow["EmployeeCode"] is DBNull))
                        {
                            ele.EmployeeCode = aRow["EmployeeCode"].ToString();
                        }

                        if (!(aRow["CreaterId"] is DBNull))
                        {
                            ele.CreaterId = aRow["CreaterId"].ToString();
                        }

                        if (!(aRow["CreateTime"] is DBNull))
                        {
                            ele.CreateTime = Convert.ToDateTime(aRow["CreateTime"]);
                        }

                        if (!(aRow["Name"] is DBNull))
                        {
                            ele.Name = aRow["Name"].ToString();
                        }

                        if (!(aRow["RVersion"] is DBNull))
                        {
                            ele.RVersion = Convert.ToInt32(aRow["RVersion"]);
                        }

                        if (!(aRow["Status"] is DBNull))
                        {
                            ele.Status = Convert.ToInt32(aRow["Status"]);
                        }

                        if (!(aRow["UpdateTime"] is DBNull))
                        {
                            ele.UpdateTime = Convert.ToDateTime(aRow["UpdateTime"]);
                        }

                        if (!(aRow["UpdatorId"] is DBNull))
                        {
                            ele.UpdatorId = aRow["UpdatorId"].ToString();
                        }

                        if (!(aRow["Birthday"] is DBNull))
                        {
                            ele.Birthday = Convert.ToDateTime(aRow["Birthday"]);
                        }

                        if (!(aRow["JoinDate"] is DBNull))
                        {
                            ele.JoinDate = Convert.ToDateTime(aRow["JoinDate"]);
                        }

                        if (!(aRow["Rand"] is DBNull))
                        {
                            ele.Rand = Convert.ToInt32(aRow["Rand"]);
                        }

                        if (!(aRow["Sex"] is DBNull))
                        {
                            ele.Sex = Convert.ToInt32(aRow["Sex"]);
                        }

                        if (!(aRow["StartWorkDate"] is DBNull))
                        {
                            ele.StartWorkDate = Convert.ToDateTime(aRow["StartWorkDate"]);
                        }

                        resultList.RecordList.Add(ele);
                    }
                }
            }

            return resultList;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 新建员工
        /// </summary>
        /// <param name="employee">员工实体对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回处理后的员工实体对象</returns>
        public Employee Add(Employee employee, ICTransaction tran)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee");
            }

            employee.EmployeeId = KeyGenerator.GenNewGuidKey();
            StringBuilder query = new StringBuilder();
            query.AppendLine(@"INSERT INTO ");
            query.AppendLine(@"  `Employee` ( ");
            query.AppendLine(@"     `EmployeeId` ");
            query.AppendLine(@"    ,`EmployeeCode` ");
            query.AppendLine(@"    ,`Name` ");
            query.AppendLine(@"    ,`Birthday` ");
            query.AppendLine(@"    ,`Sex` ");
            query.AppendLine(@"    ,`CompanyId` ");
            query.AppendLine(@"    ,`DepartmentId` ");
            query.AppendLine(@"    ,`PositionId` ");
            query.AppendLine(@"    ,`Rand` ");
            query.AppendLine(@"    ,`RVersion` ");
            query.AppendLine(@"    ,`Status` ");
            query.AppendLine(@"    ,`CreaterId` ");
            query.AppendLine(@"    ,`CreateTime` ");
            query.AppendLine(@"    ,`UpdatorId` ");
            query.AppendLine(@"    ,`UpdateTime` ");
            query.AppendLine(@"    ,`StartWorkDate` ");
            query.AppendLine(@"    ,`JoinDate` ");
            query.AppendLine(@"  ) ");
            query.AppendLine(@"VALUES (");
            query.AppendLine(@"     @EmployeeId ");
            query.AppendLine(@"    ,@EmployeeCode ");
            query.AppendLine(@"    ,@Name ");
            query.AppendLine(@"    ,@Birthday ");
            query.AppendLine(@"    ,@Sex ");
            query.AppendLine(@"    ,@CompanyId ");
            query.AppendLine(@"    ,@DepartmentId ");
            query.AppendLine(@"    ,@PositionId ");
            query.AppendLine(@"    ,@Rand ");
            query.AppendLine(@"    ,@RVersion ");
            query.AppendLine(@"    ,@Status ");
            query.AppendLine(@"    ,@CreaterId ");
            query.AppendLine(@"    ,@CreateTime ");
            query.AppendLine(@"    ,@UpdatorId ");
            query.AppendLine(@"    ,@UpdateTime ");
            query.AppendLine(@"    ,@StartWorkDate ");
            query.AppendLine(@"    ,@JoinDate ");
            query.AppendLine(@"); ");

            MySqlParameter[] paramCollection = new MySqlParameter[17];
            paramCollection[0] = new MySqlParameter("@EmployeeId", MySqlDbType.String, 40);
            paramCollection[1] = new MySqlParameter("@EmployeeCode", MySqlDbType.String, 15);
            paramCollection[2] = new MySqlParameter("@Name", MySqlDbType.String, 50);
            paramCollection[3] = new MySqlParameter("@Birthday", MySqlDbType.DateTime);
            paramCollection[4] = new MySqlParameter("@Sex", MySqlDbType.Int32);
            paramCollection[5] = new MySqlParameter("@CompanyId", MySqlDbType.String, 40);
            paramCollection[6] = new MySqlParameter("@DepartmentId", MySqlDbType.String, 40);
            paramCollection[7] = new MySqlParameter("@PositionId", MySqlDbType.String, 40);
            paramCollection[8] = new MySqlParameter("@Rand", MySqlDbType.Int32);
            paramCollection[9] = new MySqlParameter("@RVersion", MySqlDbType.Int32);
            paramCollection[10] = new MySqlParameter("@Status", MySqlDbType.Int32);
            paramCollection[11] = new MySqlParameter("@CreaterId", MySqlDbType.String, 40);
            paramCollection[12] = new MySqlParameter("@CreateTime", MySqlDbType.DateTime);
            paramCollection[13] = new MySqlParameter("@UpdatorId", MySqlDbType.String, 40);
            paramCollection[14] = new MySqlParameter("@UpdateTime", MySqlDbType.DateTime);
            paramCollection[15] = new MySqlParameter("@StartWorkDate", MySqlDbType.DateTime);
            paramCollection[16] = new MySqlParameter("@JoinDate", MySqlDbType.DateTime);

            paramCollection[0].Value = employee.EmployeeId;
            paramCollection[1].Value = employee.EmployeeCode;
            paramCollection[2].Value = employee.Name;
            paramCollection[3].Value = employee.Birthday;
            paramCollection[4].Value = employee.Sex;
            paramCollection[5].Value = employee.CompanyId;
            paramCollection[6].Value = employee.DepartmentId;
            paramCollection[7].Value = employee.PositionId;
            paramCollection[8].Value = employee.Rand;
            paramCollection[9].Value = employee.RVersion;
            paramCollection[10].Value = employee.Status;
            paramCollection[11].Value = employee.CreaterId;
            paramCollection[12].Value = employee.CreateTime;
            paramCollection[13].Value = employee.UpdatorId;
            paramCollection[14].Value = employee.UpdateTime;
            paramCollection[15].Value = employee.StartWorkDate;
            paramCollection[16].Value = employee.JoinDate;

            try
            {
                int effectCount = 0;

                if (tran != null)
                {
                    effectCount = MySqlHelper.ExecuteNonQuery((MySqlConnection)tran.Connection, query.ToString(), paramCollection);
                }
                else
                {
                    effectCount = MySqlHelper.ExecuteNonQuery(this.CurrentConnectionString, query.ToString(), paramCollection);
                }

                if (effectCount == 0)
                {
                    employee.EmployeeId = string.Empty;
                    throw new ResponseException((int)ResultCode.NoDataInsert, employee.EmployeeCode);
                }
            }
            catch(Exception ex)
            {
                employee.EmployeeId = string.Empty;
                throw new Exception(ex.Message, ex);
            }

            return employee;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 新建员工
 /// </summary>
 /// <param name="employee">员工实体对象</param>
 /// <returns>返回处理后的员工实体对象</returns>
 public Employee Add(Employee employee)
 {
     return this.Add(employee, null);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 更新员工数据
        /// </summary>
        /// <param name="employee">员工实体对象</param>
        /// <param name="tran">中间事务对象</param>
        public void Update(Employee employee, ICTransaction tran)
        {
            Employee oldEmployee = this.FindSingle(employee.EmployeeId, tran);
            int updateColCount = 0;

            if (employee == null)
            {
                throw new ArgumentException("employee");
            }

            if (oldEmployee == null)
            {
                throw new ResponseException((int)ResultCode.NoDataExists, employee.EmployeeCode);
            }

            if (employee.RVersion != oldEmployee.RVersion)
            {
                throw new ResponseException((int)ResultCode.VersionChanged, oldEmployee.RVersion.ToString());
            }

            StringBuilder query = new StringBuilder();
            query.AppendLine(@"UPDATE ");
            query.AppendLine(@"   [Employee]");
            query.AppendLine(@"SET ");
            query.AppendLine(@"   [EmployeeId] = @EmployeeId ");

            if ((!string.IsNullOrEmpty(employee.EmployeeCode) && !employee.EmployeeCode.Equals(oldEmployee.EmployeeCode))
                || (!string.IsNullOrEmpty(oldEmployee.EmployeeCode) && !oldEmployee.EmployeeCode.Equals(employee.EmployeeCode)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[EmployeeCode] = @EmployeeCode ");
            }

            if ((!string.IsNullOrEmpty(employee.Name) && !employee.Name.Equals(oldEmployee.Name))
                || (!string.IsNullOrEmpty(oldEmployee.Name) && !oldEmployee.Name.Equals(employee.Name)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[Name] = @Name ");
            }

            if (((DateTime)oldEmployee.Birthday).CompareTo(employee.Birthday) != 0 && employee.Birthday != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,[Birthday] = @Birthday ");
            }

            if (employee.Sex != oldEmployee.Sex)
            {
                updateColCount++;
                query.AppendLine(@"  ,[Sex] = @Sex ");
            }

            if ((!string.IsNullOrEmpty(employee.CompanyId) && !employee.CompanyId.Equals(oldEmployee.CompanyId))
                || (!string.IsNullOrEmpty(oldEmployee.CompanyId) && !oldEmployee.CompanyId.Equals(employee.CompanyId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[CompanyId] = @CompanyId ");
            }

            if ((!string.IsNullOrEmpty(employee.DepartmentId) && !employee.DepartmentId.Equals(oldEmployee.DepartmentId))
                || (!string.IsNullOrEmpty(oldEmployee.DepartmentId) && !oldEmployee.DepartmentId.Equals(employee.DepartmentId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[DepartmentId] = @DepartmentId ");
            }

            if ((!string.IsNullOrEmpty(employee.PositionId) && !employee.PositionId.Equals(oldEmployee.PositionId))
                || (!string.IsNullOrEmpty(oldEmployee.PositionId) && !oldEmployee.PositionId.Equals(employee.PositionId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[PositionId] = @PositionId ");
            }

            if (employee.Rand != oldEmployee.Rand)
            {
                updateColCount++;
                query.AppendLine(@"  ,[Rand] = @Rand ");
            }

            if (employee.Status != oldEmployee.Status)
            {
                updateColCount++;
                query.AppendLine(@"  ,[Status] = @Status ");
            }

            if ((!string.IsNullOrEmpty(employee.CreaterId) && !employee.CreaterId.Equals(oldEmployee.CreaterId))
                || (!string.IsNullOrEmpty(oldEmployee.CreaterId) && !oldEmployee.CreaterId.Equals(employee.CreaterId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[CreaterId] = @CreaterId ");
            }

            if (oldEmployee.CreateTime.CompareTo(employee.CreateTime) != 0 && employee.CreateTime != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,[CreateTime] = @CreateTime ");
            }

            if ((!string.IsNullOrEmpty(employee.UpdatorId) && !employee.UpdatorId.Equals(oldEmployee.UpdatorId))
                || (!string.IsNullOrEmpty(oldEmployee.UpdatorId) && !oldEmployee.UpdatorId.Equals(employee.UpdatorId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[UpdatorId] = @UpdatorId ");
            }

            if (oldEmployee.UpdateTime.CompareTo(employee.UpdateTime) != 0 && employee.UpdateTime != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,[UpdateTime] = @UpdateTime ");
            }

            if (((DateTime)oldEmployee.StartWorkDate).CompareTo(employee.StartWorkDate) != 0 && employee.StartWorkDate != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,[StartWorkDate] = @StartWorkDate ");
            }

            if (((DateTime)oldEmployee.JoinDate).CompareTo(employee.JoinDate) != 0 && employee.JoinDate != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,[JoinDate] = @JoinDate ");
            }

            query.AppendLine(@"  ,[RVersion] = @RVersion ");
            query.AppendLine(@"WHERE ");
            query.AppendLine(@"   [EmployeeId] = @EmployeeId ");

            if (updateColCount == 0)
            {
                return;
            }

            employee.UpdateTime = DateTime.Now;
            DBParamCollection<DBParam> paramCollection = new DBParamCollection<DBParam>();
            paramCollection.Add(new DBParam("@EmployeeId", employee.EmployeeId, DbType.String, 40));
            paramCollection.Add(new DBParam("@EmployeeCode", employee.EmployeeCode, DbType.String, 15));
            paramCollection.Add(new DBParam("@Name", employee.Name, DbType.String, 50));
            paramCollection.Add(new DBParam("@Birthday", employee.Birthday, DbType.DateTime));
            paramCollection.Add(new DBParam("@Sex", employee.Sex, DbType.Int32));
            paramCollection.Add(new DBParam("@CompanyId", employee.CompanyId, DbType.String, 40));
            paramCollection.Add(new DBParam("@DepartmentId", employee.DepartmentId, DbType.String, 40));
            paramCollection.Add(new DBParam("@PositionId", employee.PositionId, DbType.String, 40));
            paramCollection.Add(new DBParam("@Rand", employee.Rand, DbType.Int32));
            paramCollection.Add(new DBParam("@RVersion", employee.RVersion, DbType.Int32));
            paramCollection.Add(new DBParam("@Status", employee.Status, DbType.Int32));
            paramCollection.Add(new DBParam("@CreaterId", employee.CreaterId, DbType.String, 40));
            paramCollection.Add(new DBParam("@CreateTime", employee.CreateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@UpdatorId", employee.UpdatorId, DbType.String, 40));
            paramCollection.Add(new DBParam("@UpdateTime", employee.UpdateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@StartWorkDate", employee.StartWorkDate, DbType.DateTime));
            paramCollection.Add(new DBParam("@JoinDate", employee.JoinDate, DbType.DateTime));

            try
            {
                int effectCount = 0;

                if (employee != null)
                {
                    if (tran != null)
                    {
                        DbTransaction dbTran = ((MssqlTransaction)tran).CurrentTransaction;
                        effectCount = MssqlHelper.ExecuteNonQuery(dbTran, CommandType.Text, query.ToString(), paramCollection);
                    }
                    else
                    {
                        effectCount = MssqlHelper.ExecuteNonQuery(this.CurrentConnectionString, CommandType.Text, query.ToString(), paramCollection);
                    }
                }

                // 抛出一个异常
                if (effectCount == 0)
                {
                    throw new ResponseException((int)ResultCode.NoDataUpdate, employee.EmployeeCode);
                }
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 新建员工
        /// </summary>
        /// <param name="employee">员工实体对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回处理后的员工实体对象</returns>
        public Employee Add(Employee employee, ICTransaction tran)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee");
            }

            employee.EmployeeId = KeyGenerator.GenNewGuidKey();
            StringBuilder query = new StringBuilder();
            query.AppendLine(@"INSERT INTO ");
            query.AppendLine(@"  [Employee] ( ");
            query.AppendLine(@"     [EmployeeId] ");
            query.AppendLine(@"    ,[EmployeeCode] ");
            query.AppendLine(@"    ,[Name] ");
            query.AppendLine(@"    ,[Birthday] ");
            query.AppendLine(@"    ,[Sex] ");
            query.AppendLine(@"    ,[CompanyId] ");
            query.AppendLine(@"    ,[DepartmentId] ");
            query.AppendLine(@"    ,[PositionId] ");
            query.AppendLine(@"    ,[Rand] ");
            query.AppendLine(@"    ,[RVersion] ");
            query.AppendLine(@"    ,[Status] ");
            query.AppendLine(@"    ,[CreaterId] ");
            query.AppendLine(@"    ,[CreateTime] ");
            query.AppendLine(@"    ,[UpdatorId] ");
            query.AppendLine(@"    ,[UpdateTime] ");
            query.AppendLine(@"    ,[StartWorkDate] ");
            query.AppendLine(@"    ,[JoinDate] ");
            query.AppendLine(@"  ) ");
            query.AppendLine(@"VALUES (");
            query.AppendLine(@"     @EmployeeId ");
            query.AppendLine(@"    ,@EmployeeCode ");
            query.AppendLine(@"    ,@Name ");
            query.AppendLine(@"    ,@Birthday ");
            query.AppendLine(@"    ,@Sex ");
            query.AppendLine(@"    ,@CompanyId ");
            query.AppendLine(@"    ,@DepartmentId ");
            query.AppendLine(@"    ,@PositionId ");
            query.AppendLine(@"    ,@Rand ");
            query.AppendLine(@"    ,@RVersion ");
            query.AppendLine(@"    ,@Status ");
            query.AppendLine(@"    ,@CreaterId ");
            query.AppendLine(@"    ,@CreateTime ");
            query.AppendLine(@"    ,@UpdatorId ");
            query.AppendLine(@"    ,@UpdateTime ");
            query.AppendLine(@"    ,@StartWorkDate ");
            query.AppendLine(@"    ,@JoinDate ");
            query.AppendLine(@"); ");

            DBParamCollection<DBParam> paramCollection = new DBParamCollection<DBParam>();
            paramCollection.Add(new DBParam("@EmployeeId", employee.EmployeeId, DbType.String, 40));
            paramCollection.Add(new DBParam("@EmployeeCode", employee.EmployeeCode, DbType.String, 15));
            paramCollection.Add(new DBParam("@Name", employee.Name, DbType.String, 50));
            paramCollection.Add(new DBParam("@Birthday", employee.Birthday, DbType.DateTime));
            paramCollection.Add(new DBParam("@Sex", employee.Sex, DbType.Int32));
            paramCollection.Add(new DBParam("@CompanyId", employee.CompanyId, DbType.String, 40));
            paramCollection.Add(new DBParam("@DepartmentId", employee.DepartmentId, DbType.String, 40));
            paramCollection.Add(new DBParam("@PositionId", employee.PositionId, DbType.String, 40));
            paramCollection.Add(new DBParam("@Rand", employee.Rand, DbType.Int32));
            paramCollection.Add(new DBParam("@RVersion", employee.RVersion, DbType.Int32));
            paramCollection.Add(new DBParam("@Status", employee.Status, DbType.Int32));
            paramCollection.Add(new DBParam("@CreaterId", employee.CreaterId, DbType.String, 40));
            paramCollection.Add(new DBParam("@CreateTime", employee.CreateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@UpdatorId", employee.UpdatorId, DbType.String, 40));
            paramCollection.Add(new DBParam("@UpdateTime", employee.UpdateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@StartWorkDate", employee.StartWorkDate, DbType.DateTime));
            paramCollection.Add(new DBParam("@JoinDate", employee.JoinDate, DbType.DateTime));

            try
            {
                int effectCount = 0;

                if (tran != null)
                {
                    DbTransaction dbTran = ((MssqlTransaction)tran).CurrentTransaction;
                    effectCount = MssqlHelper.ExecuteNonQuery(dbTran, CommandType.Text, query.ToString(), paramCollection);
                }
                else
                {
                    effectCount = MssqlHelper.ExecuteNonQuery(this.CurrentConnectionString, CommandType.Text, query.ToString(), paramCollection);
                }

                if (effectCount == 0)
                {
                    employee.EmployeeId = string.Empty;
                    throw new ResponseException((int)ResultCode.NoDataInsert, employee.EmployeeCode);
                }
            }
            catch(Exception ex)
            {
                employee.EmployeeId = string.Empty;
                throw new Exception(ex.Message, ex);
            }

            return employee;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 更新员工数据
 /// </summary>
 /// <param name="employee">员工实体对象</param>
 /// <param name="tran">中间事务对象</param>
 public void Update(Employee employee, ICTransaction tran)
 {
     IList<Employee> employeeList = new List<Employee>();
     employeeList.Add(employee);
     this.Update(employeeList, tran);
 }