Beispiel #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void Initialize()
        {
            int?id = QueryString <int?>("id");

            if (id == null)
            {
                throw new Exception("参数不正确");
            }
            SysFormInstance fi = this.DataHelper.FindById <SysFormInstance>(id);

            if (fi == null)
            {
                throw new Exception("表单实例不存在");
            }

            //2013-10-8 zhumin 审核中的不能再提交
            this.rApply.Visible = fi.State != (int)FormInstanceState.Approving;

            SysForm form = this.DataHelper.FindById <SysForm>(fi.FormId);

            if (form == null)
            {
                throw new Exception("表单不存在");
            }
            this.FormInstanceId = fi.FormInstanceId;
            this.FormId         = form.FormId;
        }
Beispiel #2
0
        internal virtual int StartFormProcess(int startUserId, int formInstanceId)
        {
            IOrgProxy proxy        = OrgProxyFactory.GetProxy(this._context);
            int       nextIdentity = this._manager.GetNextIdentity();
            IUser     userById     = proxy.GetUserById(startUserId);

            if (userById == null)
            {
                throw new ApplicationException("用户不存在");
            }
            if (!userById.Department_ID.HasValue)
            {
                throw new ApplicationException("未指定用户部门");
            }
            IDepartment departmentById = proxy.GetDepartmentById(userById.Department_ID.Value);

            if (departmentById == null)
            {
                throw new ApplicationException("用户部门无效");
            }
            SysFormInstance fi = this._context.FindById <SysFormInstance>(new object[] { formInstanceId });

            if (fi == null)
            {
                throw new ApplicationException("表单实例不存在");
            }
            if (!fi.ObjectId.HasValue)
            {
                throw new ApplicationException("表单实例未关联对象ID");
            }
            fi.State = 1;
            this.ProcessInstanceCache.UpdateFormInstance(fi);
            SysProcessInstance instance2 = new SysProcessInstance {
                StartTime         = new DateTime?(DateTime.Now),
                EndTime           = null,
                InstanceStatus    = 0,
                ObjectId          = fi.ObjectId.Value,
                FormInstanceId    = new int?(fi.FormInstanceId),
                FormInstance      = fi,
                ProcessId         = new long?(this._process.ProcessId),
                ProcessInstanceId = nextIdentity,
                StartUserId       = new int?(startUserId),
                StartDeptId       = new int?(departmentById.Department_ID),
                WwfInstanceId     = null
            };

            this._pi = instance2;
            this._pi.FormInstance = fi;
            this._piCacheFactory.AddProcessInstance(this._pi);
            Queue <WorkflowMessage> queue = new Queue <WorkflowMessage>(10);
            WorkflowMessage         item  = this.NewStartProcessMessage();

            queue.Enqueue(item);
            while (queue.Count > 0)
            {
                queue.Dequeue().Execute(queue);
            }
            this._piCacheFactory.ClearCache(nextIdentity);
            return(nextIdentity);
        }
Beispiel #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void Initialize()
        {
            int?id = QueryString <int?>("id");

            if (id == null)
            {
                throw new Exception("参数不正确");
            }
            SysFormInstance fi = this.DataHelper.FindById <SysFormInstance>(id);

            if (fi == null)
            {
                throw new Exception("表单实例不存在");
            }

            if (fi.State == (int)FormInstanceState.Approving)
            {
                throw new Exception("表单实例审核中,不能编辑");
            }


            SysForm form = this.DataHelper.FindById <SysForm>(fi.FormId);

            if (form == null)
            {
                throw new Exception("表单不存在");
            }
            this.FormInstanceId = fi.FormInstanceId;
            this.FormId         = form.FormId;
        }
        /// <summary>
        /// 加载表单(含表单实体对象数据),根据表单权限显示,审核页面上会额外根据活动判断权限
        /// </summary>
        /// <param name="formInstanceId">表单实例ID</param>
        /// <param name="activityId">当前活动ID,审核页面用</param>
        public void LoadFormWithInstance(int formInstanceId, long?activityId = null)
        {
            SysFormInstance fi = this.DataHelper.FindById <SysFormInstance>(formInstanceId);

            if (fi == null)
            {
                throw new Exception("表单实例不存在");
            }

            SysForm form = this.DataHelper.FindById <SysForm>(fi.FormId);

            if (form != null && form.EntityId != null)
            {
                this.Form           = form;
                this.FormId         = form.FormId;
                this.EntityId       = form.EntityId.Value;
                this.FormInstanceId = fi.FormInstanceId;
                this.FormInstance   = this.DataHelper.FindById <SysFormInstance>(this.FormInstanceId);
                if (this.FormInstance != null)
                {
                    this.ObjectId = this.FormInstance.ObjectId;

                    var fpDict      = GetFormPrivilege(activityId);
                    var controlDict = LoadFormContentControl(fpDict);

                    if (!this.Page.IsPostBack)
                    {
                        LoadFormInstance();
                        LoadObjectData(controlDict);
                        LoadProcessApproveHistory();
                    }
                }
                else
                {
                    throw new Exception("流程实例不存在");
                }
            }
            else
            {
                throw new Exception("表单不存在");
            }
        }
 public void UpdateFormInstance(SysFormInstance fi)
 {
     this._context.Update(fi);
 }
        /// <summary>
        /// 新增表单实例,新增表单实体对象
        /// </summary>
        public int SaveFormInstance(BizDataContext db)
        {
            SysFormInstance fi = new SysFormInstance()
            {
                FormInstanceId = db.GetNextIdentity_Int(),
                FormId         = this.FormId,
                //--------------//
                FormDate        = Convert.ToDateTime(this.lblFormDate.Text.Trim()),
                FormCode        = this.lblFormCode.Text.Trim(),
                FormDescription = Server.HtmlDecode(this.lblFormDescription.Text.Trim()).Replace("<br />", "\r\n"),
                FormTitle       = this.lblFormTitle.Text.Trim(),
                State           = (int)FormInstanceState.New,
                //---------------//
                CreateTime   = DateTime.Now,
                CreateUserId = this.BasePage.LoginUserID,
                OwnerId      = this.BasePage.LoginUserID,
            };

            #region 收集实体字段的值,创建实体对象
            List <SysFormField>         ffList    = db.Where <SysFormField>(p => p.FormId == this.FormId);
            Dictionary <string, object> valueDict = new Dictionary <string, object>();
            foreach (var ff in ffList)
            {
                string          controlId = string.Format("ff_{0}", ff.FormFieldId);
                IDrisionControl control   = this.BasePage.GetControlById <IDrisionControl>(controlId);
                if (control == null)
                {
                    throw new Exception("表单控件解析出错");
                }
                valueDict[control.FieldName] = control.GetValue();
            }
            SysEntity entity = this.BasePage.EntityCache.FindById <SysEntity>(this.EntityId);
            if (entity != null) //元数据预置实体,利用EntitySchema创建对象插入
            {
                var es = IEntitySchemaHelper.Get(this.EntityId);
                if (es == null)
                {
                    throw new Exception("元数据实体EntitySchema找不到");
                }

                object obj      = es.CreateInstance();
                int    objectId = db.GetNextIdentity_Int();
                obj.SetPropertyConvertValue(es.KeyName, objectId); //主键
                foreach (var p in valueDict)
                {
                    obj.SetPropertyConvertValue(p.Key, p.Value);
                }

                //一些默认字段
                if (es.RequiredLevel() != RequireLevelEnum.PlatForm)
                {
                    if (obj.GetPropertyValue(ConstFieldNames.CreateTime) == null)
                    {
                        obj.SetPropertyConvertValue(ConstFieldNames.CreateTime, DateTime.Now);
                    }
                    if (obj.GetPropertyValue(ConstFieldNames.CreateUserId) == null)
                    {
                        obj.SetPropertyConvertValue(ConstFieldNames.CreateUserId, this.BasePage.LoginUserID);
                    }
                    if (obj.GetPropertyValue(ConstFieldNames.OwnerId) == null)
                    {
                        obj.SetPropertyConvertValue(ConstFieldNames.OwnerId, this.BasePage.LoginUserID);
                    }
                    if (obj.GetPropertyValue(ConstFieldNames.State) == null)
                    {
                        obj.SetPropertyConvertValue(ConstFieldNames.State, 0);
                    }
                    if (obj.GetPropertyValue(ConstFieldNames.StateDetail) == null)
                    {
                        obj.SetPropertyConvertValue(ConstFieldNames.StateDetail, 0);
                    }
                }

                db.Insert(obj);

                fi.ObjectId = objectId;
            }
            else //自定义实体
            {
                entity      = this.DataHelper.FindById <SysEntity>(this.EntityId);
                fi.ObjectId = db.DynamicInsert(entity, valueDict);
            }
            #endregion

            db.Insert(fi);
            return(fi.FormInstanceId);
        }
        /// <summary>
        /// 保存表单实体,和表单实体对象
        /// </summary>
        /// <param name="db"></param>
        public int UpdateFormInstance(BizDataContext db)
        {
            SysFormInstance fi = db.FindById <SysFormInstance>(this.FormInstanceId);

            if (fi == null)
            {
                throw new Exception("表单实例不存在");
            }

            if (fi.State != (int)FormInstanceState.Approving)
            {
                fi.State = (int)FormInstanceState.New; //2013-10-8 zhumin 重新保存后状态改为新增,审核中除外
            }
            fi.UpdateUserId = this.BasePage.LoginUserID;
            fi.UpdateTime   = DateTime.Now;

            //收集实体字段的值,创建实体对象
            List <SysFormField>         ffList    = db.Where <SysFormField>(p => p.FormId == this.FormId);
            Dictionary <string, object> valueDict = new Dictionary <string, object>();

            foreach (var ff in ffList)
            {
                string          controlId = string.Format("ff_{0}", ff.FormFieldId);
                IDrisionControl control   = this.BasePage.GetControlById <IDrisionControl>(controlId);
                if (control == null)
                {
                    throw new Exception("表单控件解析出错");
                }
                valueDict[control.FieldName] = control.GetValue();
            }
            SysEntity entity = this.BasePage.EntityCache.FindById <SysEntity>(this.EntityId);

            if (entity != null) //元数据预置实体,利用EntitySchema创建对象插入
            {
                var es = IEntitySchemaHelper.Get(this.EntityId);
                if (es == null)
                {
                    throw new Exception("元数据实体EntitySchema找不到");
                }

                object        obj  = db.FindById(es.EntityType, this.ObjectId);
                List <string> cols = new List <string>();
                foreach (var p in valueDict)
                {
                    if (obj.GetPropertyValue(p.Key) != p.Value)
                    {
                        obj.SetPropertyConvertValue(p.Key, p.Value);
                        cols.Add(p.Key);
                    }
                }

                db.UpdatePartial(obj, cols);
            }
            else //自定义实体
            {
                entity = this.DataHelper.FindById <SysEntity>(this.EntityId);
                db.DynamicUpdate(entity, this.ObjectId, valueDict);
            }

            db.UpdatePartial(fi, p => new { p.State, p.UpdateTime, p.UpdateUserId });
            return(fi.FormInstanceId);
        }