Exemple #1
0
 /// <summary>
 /// 新建部门
 /// </summary>
 /// <param name="department">部门实体对象</param>
 /// <param name="tran">事务对象</param>
 /// <returns>返回处理后的部门实体对象</returns>
 public Department Add(Department department, ICTransaction tran)
 {
     IList<Department> departmentList = new List<Department>();
     departmentList.Add(department);
     departmentList = this.Add(departmentList, tran);
     return departmentList == null ? null : departmentList[0];
 }
Exemple #2
0
        /// <summary>
        /// 更新部门数据
        /// </summary>
        /// <param name="department">部门实体对象</param>
        /// <param name="tran">中间事务对象</param>
        public void Update(Department department, ICTransaction tran)
        {
            Department oldDepartment = this.FindSingle(department.DepartmentId, tran);
            int updateColCount = 0;

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

            if (oldDepartment == null)
            {
                throw new ResponseException((int)ResultCode.NoDataExists, department.DepartmentCode);
            }

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

            StringBuilder query = new StringBuilder();
            query.AppendLine(@"UPDATE ");
            query.AppendLine(@"   [Department]");
            query.AppendLine(@"SET ");
            query.AppendLine(@"   [DepartmentId] = @DepartmentId ");

            if ((!string.IsNullOrEmpty(department.DepartmentCode) && !department.DepartmentCode.Equals(oldDepartment.DepartmentCode))
                || (!string.IsNullOrEmpty(oldDepartment.DepartmentCode) && !oldDepartment.DepartmentCode.Equals(department.DepartmentCode)))
            {
                updateColCount++;
                query.AppendLine(@"  ,[DepartmentCode] = @DepartmentCode ");
            }

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

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

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

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

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

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

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

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

            if (updateColCount == 0)
            {
                return;
            }

            department.UpdateTime = DateTime.Now;
            DBParamCollection<DBParam> paramCollection = new DBParamCollection<DBParam>();
            paramCollection.Add(new DBParam("@DepartmentId", department.DepartmentId, DbType.String, 40));
            paramCollection.Add(new DBParam("@DepartmentCode", department.DepartmentCode, DbType.String, 10));
            paramCollection.Add(new DBParam("@CompanyId", department.CompanyId, DbType.String, 40));
            paramCollection.Add(new DBParam("@Name", department.Name, DbType.String, 100));
            paramCollection.Add(new DBParam("@RVersion", department.RVersion, DbType.Int32));
            paramCollection.Add(new DBParam("@Status", department.Status, DbType.Int32));
            paramCollection.Add(new DBParam("@CreaterId", department.CreaterId, DbType.String, 40));
            paramCollection.Add(new DBParam("@CreateTime", department.CreateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@UpdatorId", department.UpdatorId, DbType.String, 40));
            paramCollection.Add(new DBParam("@UpdateTime", department.UpdateTime, DbType.DateTime));

            try
            {
                int effectCount = 0;

                if (department != 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, department.DepartmentCode);
                }
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Exemple #3
0
 /// <summary>
 /// 更新部门数据
 /// </summary>
 /// <param name="department">部门实体对象</param>
 public void Update(Department department)
 {
     this.Update(department, null);
 }
Exemple #4
0
        /// <summary>
        /// 查找指定条件的部门分页集合
        /// </summary>
        /// <param name="departmentSearcher">部门查询对象</param>
        /// <param name="pager">分页对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回查找到的分页集合,包括按条件可查询到的所有记录数和当前分页的对象集合</returns>
        public PageList<Department> FindList(DepartmentSearcher departmentSearcher, Pager pager, ICTransaction tran)
        {
            PageList<Department> resultList = new PageList<Department>();
            PageDataTable pageDataTable = this.FindDataTable(departmentSearcher, pager, tran);
            Department ele = null;

            if (pageDataTable != null)
            {
                resultList = new PageList<Department>();
                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 Department();

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

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

                        if (!(aRow["DepartmentCode"] is DBNull))
                        {
                            ele.DepartmentCode = aRow["DepartmentCode"].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();
                        }

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

            return resultList;
        }
Exemple #5
0
        /// <summary>
        /// 新建部门
        /// </summary>
        /// <param name="department">部门实体对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回处理后的部门实体对象</returns>
        public Department Add(Department department, ICTransaction tran)
        {
            if (department == null)
            {
                throw new ArgumentNullException("department");
            }

            department.DepartmentId = KeyGenerator.GenNewGuidKey();
            StringBuilder query = new StringBuilder();
            query.AppendLine(@"INSERT INTO ");
            query.AppendLine(@"  [Department] ( ");
            query.AppendLine(@"     [DepartmentId] ");
            query.AppendLine(@"    ,[DepartmentCode] ");
            query.AppendLine(@"    ,[CompanyId]  ");
            query.AppendLine(@"    ,[Name] ");
            query.AppendLine(@"    ,[RVersion] ");
            query.AppendLine(@"    ,[Status] ");
            query.AppendLine(@"    ,[CreaterId] ");
            query.AppendLine(@"    ,[CreateTime] ");
            query.AppendLine(@"    ,[UpdatorId] ");
            query.AppendLine(@"    ,[UpdateTime] ");
            query.AppendLine(@"   )");
            query.AppendLine(@"VALUES (");
            query.AppendLine(@"     @DepartmentId ");
            query.AppendLine(@"    ,@DepartmentCode ");
            query.AppendLine(@"    ,@CompanyId ");
            query.AppendLine(@"    ,@Name ");
            query.AppendLine(@"    ,@RVersion ");
            query.AppendLine(@"    ,@Status ");
            query.AppendLine(@"    ,@CreaterId ");
            query.AppendLine(@"    ,@CreateTime ");
            query.AppendLine(@"    ,@UpdatorId ");
            query.AppendLine(@"    ,@UpdateTime ");
            query.AppendLine(@"); ");

            DBParamCollection<DBParam> paramCollection = new DBParamCollection<DBParam>();
            paramCollection.Add(new DBParam("@DepartmentId", department.DepartmentId, DbType.String, 40));
            paramCollection.Add(new DBParam("@DepartmentCode", department.DepartmentCode, DbType.String, 10));
            paramCollection.Add(new DBParam("@CompanyId", department.CompanyId, DbType.String, 40));
            paramCollection.Add(new DBParam("@Name", department.Name, DbType.String, 100));
            paramCollection.Add(new DBParam("@RVersion", department.RVersion, DbType.Int32));
            paramCollection.Add(new DBParam("@Status", department.Status, DbType.Int32));
            paramCollection.Add(new DBParam("@CreaterId", department.CreaterId, DbType.String, 40));
            paramCollection.Add(new DBParam("@CreateTime", department.CreateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@UpdatorId", department.UpdatorId, DbType.String, 40));
            paramCollection.Add(new DBParam("@UpdateTime", department.UpdateTime, 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)
                {
                    department.DepartmentId = string.Empty;
                    throw new ResponseException((int)ResultCode.NoDataInsert, department.DepartmentCode);
                }
            }
            catch(Exception ex)
            {
                department.DepartmentId = string.Empty;
                throw new Exception(ex.Message, ex);
            }

            return department;
        }
Exemple #6
0
 /// <summary>
 /// 新建部门
 /// </summary>
 /// <param name="department">部门实体对象</param>
 /// <returns>返回处理后的部门实体对象</returns>
 public Department Add(Department department)
 {
     return this.Add(department, null);
 }
Exemple #7
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);
        }
Exemple #8
0
 /// <summary>
 /// 更新部门数据
 /// </summary>
 /// <param name="department">部门实体对象</param>
 /// <param name="tran">中间事务对象</param>
 public void Update(Department department, ICTransaction tran)
 {
     IList<Department> departmentList = new List<Department>();
     departmentList.Add(department);
     this.Update(departmentList, tran);
 }
Exemple #9
0
        /// <summary>
        /// 更新部门数据
        /// </summary>
        /// <param name="department">部门实体对象</param>
        /// <param name="tran">中间事务对象</param>
        public void Update(Department department, ICTransaction tran)
        {
            Department oldDepartment = this.FindSingle(department.DepartmentId, tran);
            int updateColCount = 0;

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

            if (oldDepartment == null)
            {
                throw new ResponseException((int)ResultCode.NoDataExists, department.DepartmentCode);
            }

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

            StringBuilder query = new StringBuilder();
            query.AppendLine(@"UPDATE ");
            query.AppendLine(@"   `Department`");
            query.AppendLine(@"SET ");
            query.AppendLine(@"   `DepartmentId` = @DepartmentId ");

            if ((!string.IsNullOrEmpty(department.DepartmentCode) && !department.DepartmentCode.Equals(oldDepartment.DepartmentCode))
                || (!string.IsNullOrEmpty(oldDepartment.DepartmentCode) && !oldDepartment.DepartmentCode.Equals(department.DepartmentCode)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`DepartmentCode` = @DepartmentCode ");
            }

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

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

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

            if ((!string.IsNullOrEmpty(department.CreaterId) && !department.CreaterId.Equals(oldDepartment.CreaterId))
                || (!string.IsNullOrEmpty(oldDepartment.CreaterId) && !oldDepartment.CreaterId.Equals(department.CreaterId)))
            {
                updateColCount++;
                query.AppendLine(@"  ,`CreaterId` = @CreaterId ");
            }

            if (oldDepartment.CreateTime.CompareTo(department.CreateTime) != 0 && department.CreateTime != DateTime.MinValue)
            {
                updateColCount++;
                query.AppendLine(@"  ,`CreateTime` = @CreateTime ");
            }

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

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

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

            if (updateColCount == 0)
            {
                return;
            }

            department.UpdateTime = DateTime.Now;
            MySqlParameter[] paramCollection = new MySqlParameter[8];
            paramCollection[0] = new MySqlParameter("@DepartmentId", MySqlDbType.String, 40);
            paramCollection[1] = new MySqlParameter("@DepartmentCode", MySqlDbType.String, 10);
            paramCollection[2] = new MySqlParameter("@CompanyId", MySqlDbType.String, 40);
            paramCollection[3] = new MySqlParameter("@Name", MySqlDbType.String, 100);
            paramCollection[4] = new MySqlParameter("@RVersion", MySqlDbType.Int32);
            paramCollection[5] = new MySqlParameter("@Status", MySqlDbType.Int32);
            paramCollection[8] = new MySqlParameter("@UpdatorId", MySqlDbType.String, 40);
            paramCollection[9] = new MySqlParameter("@UpdateTime", MySqlDbType.DateTime);

            paramCollection[0].Value = department.DepartmentId;
            paramCollection[1].Value = department.DepartmentCode;
            paramCollection[2].Value = department.CompanyId;
            paramCollection[3].Value = department.Name;
            paramCollection[4].Value = department.RVersion;
            paramCollection[5].Value = department.Status;
            paramCollection[6].Value = department.UpdatorId;
            paramCollection[7].Value = department.UpdateTime;

            try
            {
                int effectCount = 0;

                if (department != 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, department.DepartmentCode);
                }
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Exemple #10
0
        /// <summary>
        /// 新建部门
        /// </summary>
        /// <param name="department">部门实体对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回处理后的部门实体对象</returns>
        public Department Add(Department department, ICTransaction tran)
        {
            if (department == null)
            {
                throw new ArgumentNullException("department");
            }

            department.DepartmentId = KeyGenerator.GenNewGuidKey();
            StringBuilder query = new StringBuilder();
            query.AppendLine(@"INSERT INTO ");
            query.AppendLine(@"  `Department` ( ");
            query.AppendLine(@"     `DepartmentId` ");
            query.AppendLine(@"    ,`DepartmentCode` ");
            query.AppendLine(@"    ,`CompanyId` ");
            query.AppendLine(@"    ,`Name` ");
            query.AppendLine(@"    ,`RVersion` ");
            query.AppendLine(@"    ,`Status` ");
            query.AppendLine(@"    ,`CreaterId` ");
            query.AppendLine(@"    ,`CreateTime` ");
            query.AppendLine(@"    ,`UpdatorId` ");
            query.AppendLine(@"    ,`UpdateTime` ");
            query.AppendLine(@"   )");
            query.AppendLine(@"VALUES (");
            query.AppendLine(@"     @DepartmentId ");
            query.AppendLine(@"    ,@DepartmentCode ");
            query.AppendLine(@"    ,@CompanyId ");
            query.AppendLine(@"    ,@Name ");
            query.AppendLine(@"    ,@RVersion ");
            query.AppendLine(@"    ,@Status ");
            query.AppendLine(@"    ,@CreaterId ");
            query.AppendLine(@"    ,@CreateTime ");
            query.AppendLine(@"    ,@UpdatorId ");
            query.AppendLine(@"    ,@UpdateTime ");
            query.AppendLine(@"); ");

            MySqlParameter[] paramCollection = new MySqlParameter[10];
            paramCollection[0] = new MySqlParameter("@DepartmentId", MySqlDbType.String, 40);
            paramCollection[1] = new MySqlParameter("@DepartmentCode", MySqlDbType.String, 10);
            paramCollection[2] = new MySqlParameter("@CompanyId", MySqlDbType.String, 40);
            paramCollection[3] = new MySqlParameter("@Name", MySqlDbType.String, 100);
            paramCollection[4] = new MySqlParameter("@RVersion", MySqlDbType.Int32);
            paramCollection[5] = new MySqlParameter("@Status", MySqlDbType.Int32);
            paramCollection[6] = new MySqlParameter("@CreaterId", MySqlDbType.String, 40);
            paramCollection[7] = new MySqlParameter("@CreateTime", MySqlDbType.DateTime);
            paramCollection[8] = new MySqlParameter("@UpdatorId", MySqlDbType.String, 40);
            paramCollection[9] = new MySqlParameter("@UpdateTime", MySqlDbType.DateTime);

            paramCollection[0].Value = department.DepartmentId;
            paramCollection[1].Value = department.DepartmentCode;
            paramCollection[2].Value = department.CompanyId;
            paramCollection[3].Value = department.Name;
            paramCollection[4].Value = department.RVersion;
            paramCollection[5].Value = department.Status;
            paramCollection[6].Value = department.CreaterId;
            paramCollection[7].Value = department.CreateTime;
            paramCollection[8].Value = department.UpdatorId;
            paramCollection[9].Value = department.UpdateTime;

            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)
                {
                    department.DepartmentId = string.Empty;
                    throw new ResponseException((int)ResultCode.NoDataInsert, department.DepartmentCode);
                }
            }
            catch(Exception ex)
            {
                department.DepartmentId = string.Empty;
                throw new Exception(ex.Message, ex);
            }

            return department;
        }