/// <summary>
 /// 添加
 /// </summary>
 /// <param name="workReportEntity">实体</param>
 /// <param name="statusCode">返回状态码</param>
 /// <returns>返回</returns>
 public string Add(BaseWorkReportEntity workReportEntity, out string statusCode)
 {
     string returnValue = string.Empty;
     returnValue = this.AddEntity(workReportEntity);
     // 运行成功
     statusCode = StatusCode.OKAdd.ToString();
     return returnValue;
 }
Example #2
0
        /// <summary>
        /// 工作日志添加
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="dataTable">数据表</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, DataTable dataTable, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif
            statusCode = string.Empty;
            statusMessage = string.Empty;

            string returnValue = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseWorkReportEntity WorkReportEntity = new BaseWorkReportEntity(dataTable);
                BaseWorkReportManager workReportManager = new BaseWorkReportManager(dbHelper, userInfo);
                returnValue = workReportManager.Add(WorkReportEntity, out statusCode);
                // 获得状态消息
                statusMessage = workReportManager.GetStateMessage(statusCode);
                // 写入日志
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return returnValue;
        }
 /// <summary>
 /// 批量保存
 /// </summary>
 /// <param name="dataTable">数据表</param>
 /// <returns>影响行数</returns>
 public override int BatchSave(DataTable dataTable)
 {
     int returnValue = 0;
     BaseWorkReportEntity workReportEntity = new BaseWorkReportEntity();
     foreach (DataRow dataRow in dataTable.Rows)
     {
         if (dataRow.RowState == DataRowState.Modified)
         {
             workReportEntity.GetFrom(dataRow);
             returnValue += this.UpdateEntity(workReportEntity) > 0 ? 1 : 0;
         }
         if (dataRow.RowState == DataRowState.Unchanged)
         {
             continue;
         }
         if (dataRow.RowState == DataRowState.Detached)
         {
             continue;
         }
     }
     return returnValue;
 }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">SQL生成器</param>
 /// <param name="workReportEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseWorkReportEntity workReportEntity)
 {
     sqlBuilder.SetValue(BaseWorkReportTable.FieldWorkDate, workReportEntity.WorkDate);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldCategoryId, workReportEntity.CategoryId);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldContent, workReportEntity.Content);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldManHour, workReportEntity.ManHour);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldProjectId, workReportEntity.ProjectId);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldStaffId, workReportEntity.StaffId);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldEnabled, workReportEntity.Enabled);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldAuditStaffId, workReportEntity.AuditStaffId);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldScore, workReportEntity.Score);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldDescription, workReportEntity.Description);
 }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="workReportEntity">实体</param>
        /// <returns>主键</returns>
        private string AddEntity(BaseWorkReportEntity workReportEntity)
        {
            string returnValue = string.Empty;
            BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper);
            string sequence = sequenceManager.GetSequence(BaseWorkReportTable.TableName);
            workReportEntity.SortCode = sequence;

            //获取职员的部门主键和公司主键
            BaseStaffManager staffManager = new BaseStaffManager(DbHelper, UserInfo);
            string CompanyId = staffManager.GetProperty(workReportEntity.StaffId, BaseStaffTable.FieldCompanyId);
            string DepartmentId = staffManager.GetProperty(workReportEntity.StaffId, BaseStaffTable.FieldDepartmentId);

            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
            sqlBuilder.BeginInsert(BaseWorkReportTable.TableName);
            sqlBuilder.SetValue(BaseWorkReportTable.FieldId, sequence);
            sqlBuilder.SetValue(BaseWorkReportTable.FieldCompanyId, CompanyId);
            sqlBuilder.SetValue(BaseWorkReportTable.FieldDepartmentId, DepartmentId);
            this.SetEntity(sqlBuilder, workReportEntity);
            sqlBuilder.SetValue(BaseWorkReportTable.FieldCreateUserId, UserInfo.Id);
            sqlBuilder.SetDBNow(BaseWorkReportTable.FieldCreateOn);
            returnValue = sqlBuilder.EndInsert() > 0 ? sequence : string.Empty;
            return returnValue;
        }
 /// <summary>
 /// 更新实体
 /// </summary>
 /// <param name="workReportEntity">实体</param>
 /// <returns>影响行数</returns>
 public int UpdateEntity(BaseWorkReportEntity workReportEntity)
 {
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
     sqlBuilder.BeginUpdate(BaseWorkReportTable.TableName);
     this.SetEntity(sqlBuilder, workReportEntity);
     sqlBuilder.SetValue(BaseWorkReportTable.FieldModifiedUserId, UserInfo.Id);
     sqlBuilder.SetDBNow(BaseWorkReportTable.FieldModifiedOn);
     sqlBuilder.SetWhere(BaseWorkReportTable.FieldId, workReportEntity.Id);
     return sqlBuilder.EndUpdate();
 }
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="workReportEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public int Update(BaseWorkReportEntity workReportEntity, out string statusCode)
        {
            int returnValue = 0;
            // 检查是否已被其他人修改
            //if (DbLogic.IsModifed(DbHelper, BaseWorkReportTable.TableName, workReportEntity.Id, workReportEntity.ModifiedUserId, workReportEntity.ModifiedOn))
            //{
            //    // 数据已经被修改
            //    statusCode = StatusCode.ErrorChanged.ToString();
            //}

                // 进行更新操作
                returnValue = this.UpdateEntity(workReportEntity);
                if (returnValue == 1)
                {
                    statusCode = StatusCode.OKUpdate.ToString();
                }
                else
                {
                    // 数据可能被删除
                    statusCode = StatusCode.ErrorDeleted.ToString();
                }

            return returnValue;
        }