Ejemplo n.º 1
0
        /// <summary>
        /// 新建公司
        /// </summary>
        /// <param name="company">公司实体对象</param>
        /// <param name="tran">中间事务对象</param>
        /// <returns>返回处理后的公司实体对象</returns>
        public Company Add(Company company, ICTransaction tran)
        {
            if (company == null)
            {
                throw new ArgumentNullException("company");
            }

            company.CompanyId = KeyGenerator.GenNewGuidKey();
            StringBuilder query = new StringBuilder();

            query.AppendLine(@"INSERT INTO ");
            query.AppendLine(@"  `Company` ( ");
            query.AppendLine(@"     `CompanyId` ");
            query.AppendLine(@"    ,`CompanyCode` ");
            query.AppendLine(@"    ,`Name` ");
            query.AppendLine(@"    ,`Address` ");
            query.AppendLine(@"    ,`ParentCompanyId` ");
            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(@"     @CompanyId ");
            query.AppendLine(@"    ,@CompanyCode ");
            query.AppendLine(@"    ,@Name ");
            query.AppendLine(@"    ,@Address ");
            query.AppendLine(@"    ,@ParentCompanyId ");
            query.AppendLine(@"    ,@RVersion ");
            query.AppendLine(@"    ,@Status ");
            query.AppendLine(@"    ,@CreaterId ");
            query.AppendLine(@"    ,@CreateTime ");
            query.AppendLine(@"    ,@UpdatorId ");
            query.AppendLine(@"    ,@UpdateTime ");
            query.AppendLine(@"); ");

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

            paramCollection[0].Value  = company.CompanyId;
            paramCollection[1].Value  = company.CompanyCode;
            paramCollection[2].Value  = company.Name;
            paramCollection[3].Value  = company.Address;
            paramCollection[4].Value  = company.ParentCompanyId;
            paramCollection[5].Value  = company.RVersion;
            paramCollection[6].Value  = company.Status;
            paramCollection[7].Value  = company.CreaterId;
            paramCollection[8].Value  = company.CreateTime;
            paramCollection[9].Value  = company.UpdatorId;
            paramCollection[10].Value = company.UpdateTime;

            try
            {
                int effectCount = 0;

                if (company != 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)
                {
                    company.CompanyId = string.Empty;
                    throw new ResponseException((int)ResultCode.NoDataInsert, company.CompanyCode);
                }
            }
            catch (Exception ex)
            {
                company.CompanyId = string.Empty;
                throw new Exception(ex.Message, ex);
            }

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

            company.CompanyId = KeyGenerator.GenNewGuidKey();
            StringBuilder query = new StringBuilder();

            query.AppendLine(@"INSERT INTO ");
            query.AppendLine(@"  [Company] ( ");
            query.AppendLine(@"     [CompanyId] ");
            query.AppendLine(@"    ,[CompanyCode] ");
            query.AppendLine(@"    ,[Name] ");
            query.AppendLine(@"    ,[Address] ");
            query.AppendLine(@"    ,[ParentCompanyId] ");
            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(@"     @CompanyId ");
            query.AppendLine(@"    ,@CompanyCode ");
            query.AppendLine(@"    ,@Name ");
            query.AppendLine(@"    ,@Address ");
            query.AppendLine(@"    ,@ParentCompanyId ");
            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("@CompanyId", company.CompanyId, DbType.String, 40));
            paramCollection.Add(new DBParam("@CompanyCode", company.CompanyCode, DbType.String, 5));
            paramCollection.Add(new DBParam("@Name", company.Name, DbType.String, 200));
            paramCollection.Add(new DBParam("@Address", company.Address, DbType.String, 500));
            paramCollection.Add(new DBParam("@ParentCompanyId", company.ParentCompanyId, DbType.String, 40));
            paramCollection.Add(new DBParam("@RVersion", company.RVersion, DbType.Int32));
            paramCollection.Add(new DBParam("@Status", company.Status, DbType.Int32));
            paramCollection.Add(new DBParam("@CreaterId", company.CreaterId, DbType.String, 40));
            paramCollection.Add(new DBParam("@CreateTime", company.CreateTime, DbType.DateTime));
            paramCollection.Add(new DBParam("@UpdatorId", company.UpdatorId, DbType.String, 40));
            paramCollection.Add(new DBParam("@UpdateTime", company.UpdateTime, DbType.DateTime));

            try
            {
                int effectCount = 0;

                if (company != 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)
                {
                    company.CompanyId = string.Empty;
                    throw new ResponseException((int)ResultCode.NoDataInsert, company.CompanyCode);
                }
            }
            catch (Exception ex)
            {
                company.CompanyId = string.Empty;
                throw new Exception(ex.Message, ex);
            }

            return(company);
        }
Ejemplo n.º 3
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.º 4
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);
        }