/// <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);
        }
예제 #2
0
        /// <summary>
        /// 获取序列号
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户</param>
        /// <param name="fullName">序列名称</param>
        /// <returns>序列号</returns>
        public string GetSequence(IDbHelper dbHelper, BaseUserInfo userInfo, string fullName)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper);
            return(sequenceManager.GetSequence(fullName));
        }
예제 #3
0
        /// <summary>
        /// 置底排序方法
        /// </summary>
        /// <param name="dbHelper">当前数据库连接</param>
        /// <param name="tableName">表名</param>
        /// <param name="id">主键</param>
        /// <returns>影响行数</returns>
        public static int SetBottom(IDbHelper dbHelper, string tableName, string id)
        {
            BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper);
            string sequence = sequenceManager.GetSequence(tableName);
            List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >();

            whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id));
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, sequence));
            return(DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters));
        }
예제 #4
0
        public virtual bool BeforeAutoStatr(string id)
        {
            // 3:按年生成单据编号。
            string sequenceCode = string.Empty;
            // 1:状态为空的、草稿状态、被退回状态的,才可以启动工作流
            string auditStatus = this.GetProperty(id, BaseBusinessLogic.FieldAuditStatus);

            if (string.IsNullOrEmpty(auditStatus) ||
                auditStatus.Equals(AuditStatus.Draft.ToString()))
            {
                /*
                 * if (!string.IsNullOrEmpty(entity.Source))
                 * {
                 *  if (newsEntity.Source.Equals("html"))
                 *  {
                 *      if (newsEntity.Contents.IndexOf("#DayCode#") > 0)
                 *      {
                 *          sequenceName = DateTime.Now.ToString("yyyyMMdd") + "_" + newsEntity.CategoryCode;
                 *          sequenceCode = DateTime.Now.ToString("yyyyMMdd") + "_" + sequenceManager.GetSequence(sequenceName, 1, 3, true);
                 *          entity.Contents = newsEntity.Contents.Replace("#DayCode#", sequenceCode);
                 *          entity.Code = sequenceCode;
                 *      }
                 *  }
                 * }
                 */
                string sequenceName = this.CurrentTableName;
                BaseSequenceManager sequenceManager = new BaseSequenceManager(this.DbHelper, this.UserInfo);
                // 没系统编号,自己生成一个编号
                if (string.IsNullOrEmpty(sequenceCode))
                {
                    sequenceCode = sequenceManager.GetSequence(sequenceName, 1, 6, true);
                    // newsEntity.Code = sequenceCode;
                }
            }

            // 4:修改单据表的状态,这里是成功了,才可以修改状态
            // newsEntity.AuditStatus = AuditStatus.StartAudit.ToString();
            // newsEntity.AuditStatusName = AuditStatus.StartAudit.ToDescription();
            // 5:这里需要重新走流程后才可以生效
            // newsEntity.Enabled = 0;
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldEnabled, 0));
            parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldDeletionStateCode, 0));
            parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldAuditStatus, AuditStatus.StartAudit.ToString()));
            if (!string.IsNullOrEmpty(sequenceCode))
            {
                parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldCode, sequenceCode));
            }
            this.SetProperty(new KeyValuePair <string, object>(this.PrimaryKey, id), parameters);
            return(true);
        }
예제 #5
0
        /// <summary>
        /// 获取新序列号
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="fullName">序列名称</param>
        /// <param name="defaultSequence">默认序列</param>
        /// <param name="sequenceLength">序列长度</param>
        /// <param name="fillZeroPrefix">是否填充补零</param>
        /// <returns>序列号</returns>
        public string GetNewSequence(BaseUserInfo userInfo, string fullName, int defaultSequence, int sequenceLength, bool fillZeroPrefix)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;

            // 这里是为了防止并发冲突用的
            lock (LOCK)
            {
                using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
                {
                    try
                    {
                        dbHelper.Open(UserCenterDbConnection);
                        BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper);
                        returnValue = sequenceManager.GetSequence(fullName, defaultSequence, sequenceLength, fillZeroPrefix);
                    }
                    catch (Exception ex)
                    {
                        BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                        throw ex;
                    }
                    finally
                    {
                        dbHelper.Close();
                    }
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return(returnValue);
        }
예제 #6
0
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="logEntity">日志对象</param>
        /// <returns>主键</returns>
        public int AddEntity(BaseLogEntity logEntity)
        {
            int returnValue = 0;
            // if (!BaseSystemInfo.RecordLog)
            // {
            //    return string.Empty;
            // }
            // 由于并发控制,没有能获得有效ID的错误处理,测试一下错误发生的数量。
            // if (Log.ID.Length == 0)
            // {
            //    return returnValue;
            // }
            // string sequence = BaseSequenceManager.Instance.GetSequence(DbHelper, BaseLogEntity.TableName);
            // string sequence = BaseSequenceManager.Instance.NewGuid();
            string     sequence   = string.Empty;
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            if (DbHelper.CurrentDbType == CurrentDbType.Access)
            // sqlBuilder.BeginInsert(this.CurrentTableName, "LogId", this.Identity);
            {
                // 写入日志 04-24
                dbHelper.Open(BaseSystemInfo.UserCenterDbConnection);
                // 用户已经不存在的需要整理干净,防止数据不完整。
                string sqlQuery = " INSERT INTO [BaseLog]([ProcessId],[ProcessName],[MethodId] " +
                                  " ,[MethodName],[Parameters],[UserId],[UserRealName],[IPAddress],[UrlReferrer],[WebUrl],[Description],[CreateOn],[ModifiedOn]) VALUES " +
                                  "( '" + logEntity.ProcessId + "','" + logEntity.ProcessName + "','" + logEntity.MethodId.ToString() + "','" + logEntity.MethodName + "','" +
                                  logEntity.Parameters + "','" + logEntity.UserId + "','" + logEntity.UserRealName + "','" + logEntity.IPAddress + "','" + logEntity.UrlReferrer + "','" +
                                  logEntity.WebUrl + " ','" + logEntity.Description + "'," + DbHelper.GetDBNow() + "," + DbHelper.GetDBNow() + ")";

                return(dbHelper.ExecuteNonQuery(sqlQuery));;
            }
            else
            {
                sqlBuilder.BeginInsert(this.CurrentTableName, this.Identity);
            }

            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseLogEntity.FieldId, logEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseLogEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseLogEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (string.IsNullOrEmpty(logEntity.Id))
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            logEntity.Id = sequence;
                        }
                        sqlBuilder.SetValue(BaseLogEntity.FieldId, logEntity.Id);
                    }
                }
            }
            if (String.IsNullOrEmpty(logEntity.UserId))
            {
                logEntity.UserId = logEntity.IPAddress;
            }
            sqlBuilder.SetValue(BaseLogEntity.FieldUserId, logEntity.UserId);
            sqlBuilder.SetValue(BaseLogEntity.FieldUserRealName, logEntity.UserRealName);
            sqlBuilder.SetValue(BaseLogEntity.FieldProcessId, logEntity.ProcessId);
            sqlBuilder.SetValue(BaseLogEntity.FieldProcessName, logEntity.ProcessName);
            sqlBuilder.SetValue(BaseLogEntity.FieldMethodId, logEntity.MethodId);
            sqlBuilder.SetValue(BaseLogEntity.FieldMethodName, logEntity.MethodName);
            sqlBuilder.SetValue(BaseLogEntity.FieldParameters, logEntity.Parameters);
            sqlBuilder.SetValue(BaseLogEntity.FieldUrlReferrer, logEntity.UrlReferrer);
            sqlBuilder.SetValue(BaseLogEntity.FieldWebUrl, logEntity.WebUrl);
            sqlBuilder.SetValue(BaseLogEntity.FieldIPAddress, logEntity.IPAddress);
            sqlBuilder.SetValue(BaseLogEntity.FieldDescription, logEntity.Description);
            //if (logEntity.CreateUserId.Length == 0)
            //{
            //    logEntity.CreateUserId = logEntity.IPAddress;
            //}
            //sqlBuilder.SetValue(BaseLogEntity.FieldCreateUserId, logEntity.CreateUserId);
            sqlBuilder.SetDBNow(BaseLogEntity.FieldCreateOn);
            // return sqlBuilder.EndInsert() > 0 ? sequence : string.Empty;
            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer)
            {
                returnValue = sqlBuilder.EndInsert();
            }
            else
            {
                sqlBuilder.EndInsert();
                if (this.ReturnId)//如果需要反回值
                {
                    returnValue = int.Parse(logEntity.Id);
                }
                else
                {
                    returnValue = 0;
                }
            }
            return(returnValue);
        }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="baseWorkFlowBillTemplateEntity">实体</param>
        public string AddEntity(BaseWorkFlowBillTemplateEntity baseWorkFlowBillTemplateEntity)
        {
            string sequence = string.Empty;

            this.Identity = false;
            if (baseWorkFlowBillTemplateEntity.SortCode == null || baseWorkFlowBillTemplateEntity.SortCode == 0)
            {
                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                baseWorkFlowBillTemplateEntity.SortCode = int.Parse(sequence);
            }
            if (baseWorkFlowBillTemplateEntity.Id != null)
            {
                sequence = baseWorkFlowBillTemplateEntity.Id.ToString();
            }
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseWorkFlowBillTemplateEntity.FieldId);
            if (!this.Identity)
            {
                if (string.IsNullOrEmpty(baseWorkFlowBillTemplateEntity.Id))
                {
                    sequence = BaseBusinessLogic.NewGuid();
                    baseWorkFlowBillTemplateEntity.Id = sequence;
                }
                sqlBuilder.SetValue(BaseWorkFlowBillTemplateEntity.FieldId, baseWorkFlowBillTemplateEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseWorkFlowBillTemplateEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseWorkFlowBillTemplateEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (string.IsNullOrEmpty(baseWorkFlowBillTemplateEntity.Id))
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            baseWorkFlowBillTemplateEntity.Id = sequence;
                        }
                        sqlBuilder.SetValue(BaseWorkFlowBillTemplateEntity.FieldId, baseWorkFlowBillTemplateEntity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, baseWorkFlowBillTemplateEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseWorkFlowBillTemplateEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseWorkFlowBillTemplateEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseWorkFlowBillTemplateEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseWorkFlowBillTemplateEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseWorkFlowBillTemplateEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseWorkFlowBillTemplateEntity.FieldModifiedOn);
            if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access))
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
예제 #8
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userEntity">实体</param>
        public string AddEntity(BaseUserEntity userEntity)
        {
            string sequence = string.Empty;

            if (userEntity.SortCode == 0)
            {
                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                sequence            = sequenceManager.GetSequence(this.CurrentTableName);
                userEntity.SortCode = int.Parse(sequence);
            }
            userEntity.QuickQuery = StringUtil.GetPinyin(userEntity.RealName);
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseUserEntity.FieldId);
            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseUserEntity.FieldId, userEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseUserEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseUserEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (userEntity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            userEntity.Id = sequence;
                        }
                        sqlBuilder.SetValue(BaseUserEntity.FieldId, userEntity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, userEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserEntity.FieldModifiedOn);
            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
예제 #9
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="newsEntity">实体</param>
        public string AddEntity(BaseNewsEntity newsEntity)
        {
            string sequence = string.Empty;

            sequence = newsEntity.Id;
            if (newsEntity.SortCode == 0)
            {
                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                sequence            = sequenceManager.GetSequence(this.CurrentTableName);
                newsEntity.SortCode = int.Parse(sequence);
            }
            if (newsEntity.Id is string)
            {
                this.Identity = false;
            }
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseNewsEntity.FieldId);
            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseNewsEntity.FieldId, newsEntity.Id);
            }
            else
            {
                if (!this.ReturnId && DbHelper.CurrentDbType == CurrentDbType.Oracle)
                {
                    sqlBuilder.SetFormula(BaseNewsEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                }
                else
                {
                    if (this.Identity && DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        if (string.IsNullOrEmpty(newsEntity.Id))
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            newsEntity.Id = sequence;
                        }
                        sqlBuilder.SetValue(BaseNewsEntity.FieldId, newsEntity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, newsEntity);
            if (UserInfo != null)
            {
                newsEntity.CreateUserId = UserInfo.Id;
                newsEntity.CreateBy     = UserInfo.RealName;
                sqlBuilder.SetValue(BaseNewsEntity.FieldCreateUserId, newsEntity.CreateUserId);
                sqlBuilder.SetValue(BaseNewsEntity.FieldCreateBy, newsEntity.CreateBy);
                newsEntity.ModifiedBy = UserInfo.RealName;
                sqlBuilder.SetValue(BaseNewsEntity.FieldModifiedUserId, newsEntity.CreateUserId);
                sqlBuilder.SetValue(BaseNewsEntity.FieldModifiedBy, newsEntity.CreateBy);
            }
            sqlBuilder.SetDBNow(BaseNewsEntity.FieldCreateOn);
            sqlBuilder.SetDBNow(BaseNewsEntity.FieldModifiedOn);

            /*
             * if (UserInfo != null)
             * {
             *  sqlBuilder.SetValue(BaseNewsEntity.FieldModifiedUserId, UserInfo.Id);
             *  sqlBuilder.SetValue(BaseNewsEntity.FieldModifiedBy, UserInfo.RealName);
             * }
             * sqlBuilder.SetDBNow(BaseNewsEntity.FieldModifiedOn);
             */
            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }