コード例 #1
0
        public static string CreateUserToken(IUserIdentity user)
        {
            if (!IsSsoServer)
            {
                return(null);
            }
            var span = new TimeSpan(2, 0, 0);
            var str  = DateTime.Now.Ticks.ToString("X16");
            var str2 = Guid.NewGuid().ToString("N").ToUpper();
            var str3 = rnd.Next(0x989680, 0x7ffffffe).ToString("X");
            var str4 = str + str2 + str3;

            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                using (var context = new BizDataContext())
                {
                    var token = new SysUserToken {
                        TokenKey   = str4,
                        UserId     = user.User_ID,
                        ExpireTime = DateTime.Now.Add(span)
                    };
                    context.Insert(token);
                }
                scope.Complete();
            }
            user.SsoToken = str4;
            return(str4);
        }
コード例 #2
0
 public Task CreateAsync(SysUser user)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         user.User_ID = context.GetNextIdentity_Int(false);
         context.Insert(user);
     }
     return(Task.FromResult <int>(0));
 }
コード例 #3
0
ファイル: RoleBLL.cs プロジェクト: wangdaguo68/King.Framework
 public int AddRole(T_Role role)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         role.Role_ID = context.GetNextIdentity_Int(false);
         context.Insert(role);
     }
     return(role.Role_ID);
 }
コード例 #4
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //保存文本
            string OriginalTitleText = this.hcTemplate.Value;
            //翻译成模板文本
            string TemplateTitleText = Server.HtmlDecode(OriginalTitleText);

            AllNodes.ToList().ForEach(p => {
                TemplateTitleText = TemplateTitleText.Replace(p.Value, p.Key);
            });

            //保存文本
            string OriginalContentText = this.hcTemplate.Text;
            //翻译成模板文本
            string TemplateContentText = Server.HtmlDecode(OriginalContentText);

            AllNodes.ToList().ForEach(p =>
            {
                TemplateContentText = TemplateContentText.Replace(p.Value, p.Key);
            });

            using (BizDataContext context = new BizDataContext())
            {
                SysProcessRemindTemplate model;
                if (TemplateId == null)
                {
                    model            = new SysProcessRemindTemplate();
                    model.TemplateId = context.GetNextIdentity();
                    model.State      = 1;
                }
                else
                {
                    model = context.FindById <SysProcessRemindTemplate>(TemplateId.Value);
                }
                model.TemplateName        = this.tcTemplateName.Text;
                model.TemplateType        = this.ccTemplateType.SelectedValue.ToInt();
                model.ProcessEntityId     = this.ccProcessEntityId.SelectedValue.ToLong();
                model.ActivityEntityId    = this.ccActivityEntityId.SelectedValue.ToLong();
                model.UseTimeType         = this.ccUseTimeType.SelectedValue.ToInt();
                model.ResultType          = this.ccResultType.SelectedValue.ToInt();
                model.OriginalTitleText   = OriginalTitleText;
                model.OriginalContentText = OriginalContentText;
                model.TemplateContentText = TemplateContentText;
                model.TemplateTitleText   = TemplateTitleText;
                if (TemplateId == null)
                {
                    context.Insert(model);
                }
                else
                {
                    context.Update(model);
                }
            }
            Response.Redirect("~/SystemManagement/ProcessTemplateQuery.aspx");
        }
コード例 #5
0
 internal virtual int StartProcessAsync(int startUserId, int relativeObjectId, List <IApproveUser> nextApproveUserList)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         SysProcessInstance instance = new SysProcessInstance {
             StartTime         = new DateTime?(DateTime.Now),
             InstanceStatus    = 0,
             ObjectId          = relativeObjectId,
             ProcessId         = new long?(this._process.ProcessId),
             ProcessInstanceId = context.GetNextIdentity_Int(false),
             StartUserId       = new int?(startUserId)
         };
         this._pi = instance;
         SysWorkflowMessage message = new SysWorkflowMessage {
             ProcessId         = this._process.ProcessId,
             ProcessInstanceId = this._pi.ProcessInstanceId,
             CreateTime        = DateTime.Now,
             MessageId         = context.GetNextIdentity_Int(false),
             MessageType       = WorkflowMessageTypeEnum.StartingProcess,
             OperationUserId   = startUserId,
             State             = SysWorkflowMessageStateEnum.Inited
         };
         foreach (IApproveUser user in nextApproveUserList)
         {
             MessageApproveUser user2 = new MessageApproveUser(user)
             {
                 //WorkflowMessageId = message.MessageId,
                 WorkflowMessageId = context.GetNextIdentity_Int(false)
             };
             context.Insert(user2);
         }
         context.Insert(message);
         context.Insert(this._pi);
     }
     return(this._pi.ProcessInstanceId);
 }
コード例 #6
0
 public virtual string OnWorkItemCreating(T_WorkItemBase wiBase, SysWorkItem wi)
 {
     if (WebConfigAppSettings.UseSSOModel)
     {
         using (BizDataContext context = new BizDataContext(WebConfigAppSettings.HomeBizDBConnString, true))
         {
             wiBase.WorkItemBase_Id = context.GetNextIdentity_Int(false);
             context.Insert(wiBase);
             DbParameter parameter = context.CreateParameter();
             parameter.ParameterName = context.AddPrefixToParameterName("OwnerBiz");
             parameter.Value         = WebConfigAppSettings.ApplicationName;
             string sql = string.Format("update T_WorkItemBase set OwnerBiz = {0}", parameter.ParameterName);
             context.ExecuteNonQuery(sql, new DbParameter[] { parameter });
             return(wiBase.WorkItemBase_Id.ToString());
         }
     }
     return(null);
 }
コード例 #7
0
        /// <summary>
        /// 连接两个活动
        /// </summary>
        private void ConnectActivity(BizDataContext db, SysActivity prev, SysActivity post, FlowStepDirection direction)
        {
            SysTransition t = new SysTransition()
            {
                TransitionId   = db.GetNextIdentity(),
                PreActivityId  = prev.ActivityId,
                PostActivityId = post.ActivityId,
                ProcessId      = this.ProcessId,
                Direction      = (int)direction,
            };

            switch (direction)
            {
            case FlowStepDirection.False: t.DisplayText = "驳回"; break;

            case FlowStepDirection.True: t.DisplayText = "通过"; break;

            default: break;
            }
            db.Insert(t);
        }
コード例 #8
0
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         using (BizDataContext context = new BizDataContext())
         {
             SysProcessProxy ProcessProxyData;
             if (Id == null)
             {
                 ProcessProxyData = new SysProcessProxy()
                 {
                     ProcessProxyId = context.GetNextIdentity_Int(),
                     ProcessId      = ProcessId,
                     OwnerId        = Convert.ToInt32(this.scOwner.GetValue()),
                     ProxyId        = Convert.ToInt32(this.scProxy.GetValue()),
                     StartTime      = Convert.ToDateTime(this.dtcStartTime.GetValue()),
                     EndTime        = Convert.ToDateTime(this.dtcEndTime.GetValue()),
                     CreateTime     = DateTime.Now,
                     Status         = (int)ProxyStatus.Enable,
                 };
                 context.Insert(ProcessProxyData);
             }
             else
             {
                 ProcessProxyData           = context.FindById <SysProcessProxy>(Id);
                 ProcessProxyData.OwnerId   = Convert.ToInt32(this.scOwner.GetValue());
                 ProcessProxyData.ProxyId   = Convert.ToInt32(this.scProxy.GetValue());
                 ProcessProxyData.StartTime = Convert.ToDateTime(this.dtcStartTime.GetValue());
                 ProcessProxyData.EndTime   = Convert.ToDateTime(this.dtcEndTime.GetValue());
                 context.Update(ProcessProxyData);
             }
         }
         Response.Redirect(ViewState["UrlReferrer"].ToString());
     }
     catch (ApplicationException ex)
     {
         this.AjaxAlert(ex.Message);
     }
 }
コード例 #9
0
        private string InternalSaveWorkFlow(BizDataContext context, WfWorkflowData data, long?oldProcessId)
        {
            try
            {
                SendToClient("正在禁用外键约束...", 5);
                DisableConstraint();

                if (oldProcessId != null)
                {
                    Delete(oldProcessId.Value);
                }

                SendToClient("正在保存流程...", 20);
                SysProcess process = data.Process.ConvertTo <SysProcess>();
                if (!string.IsNullOrEmpty(data.Process.ProcessTemplate))
                {
                    process.TemplateId = Convert.FromBase64String(data.Process.ProcessTemplate);
                }
                context.Insert(process);

                SendToClient("正在保存活动列表...", 30);
                data.ActivityList.ConvertTo <SysActivity>().ForEach(p => context.Insert(p));

                SendToClient("正在保存活动自动操作...", 35);
                data.ActivityOperationList.ConvertTo <SysActivityOperation>().ForEach(p => context.Insert(p));

                SendToClient("正在保存活动自动操作步骤...", 40);
                data.ActivityStepList.ConvertTo <SysActivityStep>().ForEach(p => context.Insert(p));

                SendToClient("正在保存活动提醒...", 45);
                data.ActivityRemindList.ConvertTo <SysActivityRemind>().ForEach(p => context.Insert(p));

                SendToClient("正在保存活动提醒参与人...", 50);
                data.ActivityRemindParticipantList.ConvertTo <SysActivityRemindParticipant>().ForEach(p => context.Insert(p));

                SendToClient("正在保存活动参与人...", 60);
                data.ActivityParticipantList.ConvertTo <SysActivityParticipant>().ForEach(p => context.Insert(p));

                SendToClient("正在保存条件表达式列表...", 65);
                data.ExpressionList.ConvertTo <SysExpression>().ForEach(p => context.Insert(p));

                SendToClient("正在保存流程参与人列表...", 70);
                data.ParticipantList.ConvertTo <SysProcessParticipant>().ForEach(p => context.Insert(p));

                SendToClient("正在保存流程提醒列表...", 75);
                data.ProcessRemindList.ConvertTo <SysProcessRemind>().ForEach(p => context.Insert(p));

                SendToClient("正在保存流程提醒参与人列表...", 80);
                data.ProcessRemindParticipantList.ConvertTo <SysProcessRemindParticipant>().ForEach(p => context.Insert(p));

                SendToClient("正在保存连接线列表...", 90);
                data.TransitionList.ConvertTo <SysTransition>().ForEach(p => context.Insert(p));

                SendToClient("正在启用外键约束...", 95);
                EnableConstraint();

                return(null);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
コード例 #10
0
        /// <summary>
        /// 选中现有字段并添加为表单字段
        /// </summary>
        /// <param name="sectionId"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private string SelectField(long sectionId, string parameter)
        {
            StringBuilder sb = new StringBuilder();

            SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId);

            if (section != null)
            {
                JavaScriptSerializer js        = new JavaScriptSerializer();
                object[]             fieldList = js.DeserializeObject(parameter) as object[];
                if (fieldList == null)
                {
                    throw new Exception("回调参数不正确");
                }

                var source = fieldList.Select(p => p as Dictionary <string, object>)
                             .Select(p => new
                {
                    FieldId    = p["FieldId"].ToLong(),
                    RelationId = p["RelationId"].ToStringNullable().ToLongNullable(),
                });

                int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0);

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        foreach (var p in source)
                        {
                            SysField field = this.EntityCache.FindById <SysField>(p.FieldId);
                            if (field == null)
                            {
                                field = db.FindById <SysField>(p.FieldId);
                            }
                            if (field != null)
                            {
                                SysFormField ff = new SysFormField()
                                {
                                    FormFieldId   = db.GetNextIdentity(),
                                    FormSectionId = sectionId,
                                    FormId        = section.FormId,

                                    FieldId      = p.FieldId,
                                    RelationId   = p.RelationId,
                                    DisplayOrder = ++maxOrder,
                                    EntityId     = field.EntityId,
                                    DataType     = field.DataType,
                                    IsNullable   = true,

                                    CreateUserId = this.LoginUserID,
                                    CreateTime   = DateTime.Now,
                                };

                                db.Insert(ff);

                                sb.AppendFormat("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText);
                            }
                            else
                            {
                                throw new Exception("找不到关联字段");
                            }
                        }
                    }
                    ts.Complete();
                }
            }
            else
            {
                throw new Exception("找不到表单段落");
            }

            return(sb.ToString());
        }
コード例 #11
0
        /// <summary>
        /// 新增表单字段
        /// </summary>
        /// <param name="sectionId"></param>
        /// <param name="parameter"></param>
        /// <param name="otherContent"></param>
        /// <returns></returns>
        private string NewField(long sectionId, string parameter, ref object otherContent)
        {
            string result = string.Empty;
            SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId);

            if (section != null)
            {
                SysForm form = this.DataHelper.FindById <SysForm>(section.FormId);
                if (form == null)
                {
                    throw new Exception("表单不存在");
                }

                JavaScriptSerializer js = new JavaScriptSerializer();
                var valueDict           = js.DeserializeObject(parameter) as Dictionary <string, object>;
                if (valueDict == null)
                {
                    throw new Exception("回调参数不正确");
                }
                string displayText = valueDict["DisplayText"].ToStringNullable();
                string fieldName   = valueDict["FieldName"].ToStringNullable();
                int?   dataType    = valueDict["DataType"].ToStringNullable().ToIntNullable();

                int temp = this.DataHelper.Set <SysField>().Where(p => p.EntityId == form.EntityId &&
                                                                  (p.DisplayText == displayText || p.FieldName == fieldName)).Count();
                if (temp > 0)
                {
                    throw new Exception("当前新增的字段名称已经存在");
                }

                int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0);

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        //新增字段
                        SysField field = new SysField()
                        {
                            FieldId     = db.GetNextIdentity(),
                            DisplayText = displayText,
                            FieldName   = fieldName,
                            EntityId    = form.EntityId,
                            Description = displayText,
                            DataType    = dataType,
                            IsFormField = true,//2013-9-24 zhumin
                        };
                        db.Insert(field);

                        //新增表单字段
                        SysFormField ff = new SysFormField()
                        {
                            FormFieldId   = db.GetNextIdentity(),
                            FormSectionId = sectionId,
                            EntityId      = form.EntityId,
                            DisplayOrder  = maxOrder + 1,
                            FormId        = form.FormId,
                            FieldId       = field.FieldId,
                            DataType      = field.DataType,
                            IsNullable    = true,

                            CreateTime   = DateTime.Now,
                            CreateUserId = this.LoginUserID,
                        };
                        db.Insert(ff);

                        result       = string.Format("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText);
                        otherContent = string.Format("<div class=\"divField\"><span><input type=\"checkbox\" fid=\"{0}\" /></span><span>{1}</span><span>{2}</span></div>", field.FieldId, field.DisplayText, field.FieldName);
                    }
                    ts.Complete();
                }
            }

            return(result);
        }
コード例 #12
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.SelectedRoleId == null)
                {
                    throw new Exception("请选择角色");
                }

                //现有配置
                var fpDict = this.DataHelper.Set <SysFormRolePrivilege>()
                             .Where(p => p.RoleId == this.SelectedRoleId &&
                                    p.FormId == this.FormId).ToList().ToDictionary(p => p.FormFieldId);

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        foreach (RepeaterItem section in rSection.Items)
                        {
                            Repeater rField = section.FindControl("rField") as Repeater;
                            foreach (RepeaterItem field in rField.Items)
                            {
                                var hf          = field.FindControl("hf") as HiddenField;
                                var ccInvisible = field.FindControl("ccInvisible") as RadioButton;
                                var ccReadOnly  = field.FindControl("ccReadOnly") as RadioButton;
                                var ccReadWrite = field.FindControl("ccReadWrite") as RadioButton;

                                if (hf != null && ccInvisible != null && ccReadOnly != null && ccReadWrite != null)
                                {
                                    var id = hf.Value.ToLong();
                                    FormFieldPrivilege privilege = FormFieldPrivilege.Invisible;
                                    if (ccReadOnly.Checked)
                                    {
                                        privilege = FormFieldPrivilege.ReadOnly;
                                    }
                                    else if (ccReadWrite.Checked)
                                    {
                                        privilege = FormFieldPrivilege.ReadWrite;
                                    }

                                    if (fpDict.ContainsKey(id))
                                    {
                                        var fp = fpDict[id];
                                        if (fp.DisplayPrivilege != (int)privilege)
                                        {
                                            fp.DisplayPrivilege = (int)privilege;
                                            db.UpdatePartial(fp, p => new { p.DisplayPrivilege });
                                        }
                                    }
                                    else
                                    {
                                        SysFormRolePrivilege fp = new SysFormRolePrivilege()
                                        {
                                            PrivilegeId      = db.GetNextIdentity(),
                                            FormFieldId      = id,
                                            FormId           = this.FormId,
                                            RoleId           = this.SelectedRoleId,
                                            DisplayPrivilege = (int)privilege,
                                            CreateTime       = DateTime.Now,
                                            CreateUserId     = this.LoginUserID,
                                        };
                                        db.Insert(fp);
                                    }
                                }
                            }
                        }
                    }
                    ts.Complete();
                }

                this.AjaxAlertAndEnableButton("保存成功");
            }
            catch (Exception ex)
            {
                this.AjaxAlertAndEnableButton(ex);
            }
        }
コード例 #13
0
        protected void btnNextStep_Click(object sender, EventArgs e)
        {
            try
            {
                string entityType     = this.ddlEntityType.SelectedValue;
                string displayText    = this.txtSysEntity.Text.Trim();
                string entityName     = "T_" + displayText.ToPingYin();
                string formName       = this.txtFormName.Text.Trim();
                string formTitle      = this.txtFormTitle.Text.Trim();
                string formDecription = this.txtFormDescription.Text.Trim();

                if (string.IsNullOrEmpty(formName))
                {
                    throw new Exception("表单名称不能为空");
                }

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        switch (entityType)
                        {
                        case "0":
                        case "1":
                            if (this.EntityId == null)
                            {
                                throw new Exception("关联实体不能为空");
                            }
                            break;

                        case "2":
                            if (string.IsNullOrEmpty(displayText))
                            {
                                throw new Exception("关联实体不能为空");
                            }
                            if (string.IsNullOrEmpty(entityName))
                            {
                                throw new Exception("关联实体表名不能为空");
                            }
                            SysEntity tempEntity = db.FirstOrDefault <SysEntity>(p =>
                                                                                 p.EntityName == entityName || p.DisplayText == displayText);
                            if (tempEntity != null)
                            {
                                throw new Exception("当前新增的关联实体名称已存在");
                            }
                            tempEntity = new SysEntity()
                            {
                                EntityId     = db.GetNextIdentity(),
                                EntityName   = entityName,
                                DisplayText  = displayText,
                                Description  = displayText,
                                IsFormEntity = true,
                                CreateTime   = DateTime.Now,
                            };
                            db.Insert(tempEntity);
                            this.EntityId = tempEntity.EntityId;

                            //默认加一个主键字段
                            SysField tempField = new SysField()
                            {
                                FieldId     = db.GetNextIdentity(),
                                EntityId    = tempEntity.EntityId,
                                FieldName   = displayText.ToPingYin() + "_Id",
                                DisplayText = displayText + "ID",
                                Description = displayText + "ID",
                                DataType    = (int)DataTypeEnum.pkey,
                                IsFormField = true,    //2013-9-24 zhumin
                            };
                            db.Insert(tempField);
                            break;

                        default: break;
                        }

                        if (this.FormId != null)
                        {
                            SysForm form = db.FindById <SysForm>(this.FormId);
                            if (form != null)
                            {
                                form.FormName        = formName;
                                form.EntityId        = this.EntityId;
                                form.UpdateTime      = DateTime.Now;
                                form.UpdateUserId    = this.LoginUserID;
                                form.FormTitle       = formTitle;
                                form.FormDescription = formDecription;

                                db.UpdatePartial(form, p => new { p.FormName, p.FormTitle, p.FormDescription, p.EntityId, p.UpdateTime, p.UpdateUserId });
                            }
                            else
                            {
                                throw new Exception("表单不存在");
                            }
                        }
                        else
                        {
                            SysForm form = new SysForm()
                            {
                                FormId          = db.GetNextIdentity(),
                                FormName        = formName,
                                FormTitle       = formTitle,
                                FormDescription = formDecription,
                                EntityId        = this.EntityId,
                                CreateTime      = DateTime.Now,
                                CreateUserId    = this.LoginUserID,
                                OwnerId         = this.LoginUserID,
                                State           = (int)FormState.New,
                            };
                            db.Insert(form);
                            this.FormId = form.FormId;
                        }
                    }
                    ts.Complete();
                }
                Response.Redirect(string.Format("FormDesigner_SecondStep.aspx?id={0}", this.FormId));
            }
            catch (Exception ex)
            {
                this.AjaxAlertAndEnableButton(ex);
            }
        }
コード例 #14
0
        /// <summary>
        /// 新增一个活动,并选中
        /// </summary>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                //所有活动
                Dictionary <long, SysActivity> activityDict = this.DataHelper.Set <SysActivity>()
                                                              .Where(p => p.ProcessId == this.ProcessId).ToDictionary(p => p.ActivityId);

                //最后一个审核活动
                SysActivity lastActivity = activityDict.Values.Where(p => p.ActivityType == (int)ActivityType.Approve)
                                           .OrderByDescending(p => p.DisplayOrder).FirstOrDefault();

                SysActivity endReject = activityDict.Values.FirstOrDefault(p => p.ActivityType == (int)ActivityType.End && p.ActivityName == "驳回");
                SysActivity endPass   = activityDict.Values.FirstOrDefault(p => p.ActivityType == (int)ActivityType.End && p.ActivityName == "通过");

                int maxCount = activityDict.Values.Max(p => p.DisplayOrder ?? 0);

                //最后一个审核活动通过指向的连接线
                SysTransition t = this.DataHelper.Set <SysTransition>()
                                  .Where(p => p.PreActivityId == lastActivity.ActivityId &&
                                         p.Direction == (int)FlowStepDirection.True).FirstOrDefault();

                SysActivity newActivity;
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        //新活动
                        newActivity = new SysActivity()
                        {
                            ActivityId   = db.GetNextIdentity(),
                            ProcessId    = this.ProcessId,
                            ActivityType = (int)ActivityType.Approve,
                            DisplayOrder = maxCount + 1,
                            ExecType     = (int)ActivityExecType.Manual,
                            PassType     = (int)ActivityPassType.FirstDefault,
                            IsPassedWithNoParticipants = true,
                            ActivityName = "活动名称",
                            LeftPos      = 350,
                            TopPos       = (maxCount + 1) * 130 + 50,
                        };
                        db.Insert(newActivity);

                        //把上一个活动接到新活动
                        t.PostActivityId = newActivity.ActivityId;
                        db.UpdatePartial(t, p => new { p.PostActivityId });

                        //按默认规则链接新活动和结束活动
                        ConnectActivity(db, newActivity, endPass, FlowStepDirection.True);
                        ConnectActivity(db, newActivity, endReject, FlowStepDirection.False);
                    }
                    ts.Complete();
                }

                //选中新活动
                SelectActivity(newActivity);

                this.EnableButton();
            }
            catch (Exception ex)
            {
                this.AjaxAlertAndEnableButton(ex);
            }
        }
コード例 #15
0
        /// <summary>
        /// 进入页面,如果没有任何活动,自动添加隐藏的开始活动、结束活动、以及第一个审核活动,并选中第一个审核活动
        /// </summary>
        private void AddHiddenAndFirstActivity()
        {
            int count = this.DataHelper.Set <SysActivity>()
                        .Where(p => p.ProcessId == this.ProcessId).Count();

            if (count == 0)
            {
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        //开始活动
                        SysActivity start = new SysActivity()
                        {
                            ActivityId   = db.GetNextIdentity(),
                            ActivityName = "开始",
                            ActivityType = (int)ActivityType.Start,
                            ProcessId    = this.ProcessId,
                            ExecType     = (int)ActivityExecType.Auto,
                            LeftPos      = 350,
                            TopPos       = 50,
                        };
                        db.Insert(start);

                        //第一个审核活动
                        SysActivity first = new SysActivity()
                        {
                            ActivityId   = this.DataHelper.GetNextIdentity(),
                            ProcessId    = this.ProcessId,
                            ActivityType = (int)ActivityType.Approve,
                            ActivityName = "活动名称",
                            DisplayOrder = 1,
                            ExecType     = (int)ActivityExecType.Manual,
                            PassType     = (int)ActivityPassType.FirstDefault,
                            LeftPos      = 350,
                            TopPos       = 180,
                        };
                        db.Insert(first);

                        //结束活动(通过)
                        SysActivity endPass = new SysActivity()
                        {
                            ActivityId   = db.GetNextIdentity(),
                            ActivityName = "通过",
                            ActivityType = (int)ActivityType.End,
                            ProcessId    = this.ProcessId,
                            ExecType     = (int)ActivityExecType.Auto,
                            IsPassedWithNoParticipants = true,
                            LeftPos       = 100,
                            TopPos        = 350,
                            ApproveResult = (int)ApproveResultEnum.Pass,
                        };
                        db.Insert(endPass);

                        //结束活动(驳回)
                        SysActivity endReject = new SysActivity()
                        {
                            ActivityId    = db.GetNextIdentity(),
                            ActivityName  = "驳回",
                            ActivityType  = (int)ActivityType.End,
                            ProcessId     = this.ProcessId,
                            ExecType      = (int)ActivityExecType.Auto,
                            LeftPos       = 600,
                            TopPos        = 350,
                            ApproveResult = (int)ApproveResultEnum.Reject,
                        };
                        db.Insert(endReject);

                        //按默认规则链接这三个活动
                        ConnectActivity(db, start, first, FlowStepDirection.True);
                        ConnectActivity(db, first, endPass, FlowStepDirection.True);
                        ConnectActivity(db, first, endReject, FlowStepDirection.False);
                    }
                    ts.Complete();
                }
            }

            //选中第一个活动
            var a = this.DataHelper.Set <SysActivity>()
                    .Where(p => p.ProcessId == this.ProcessId && p.ActivityType == (int)ActivityType.Approve)
                    .OrderBy(p => p.DisplayOrder).FirstOrDefault();

            SelectActivity(a);
        }
コード例 #16
0
        /// <summary>
        /// 复制流程,从“已启用”或“已升级”的流程进入设计,需要先复制一份流程供设计
        /// 状态为“新增”,版本为当前最高版本 + 1
        /// </summary>
        public SysProcess CopyProcess()
        {
            SysProcess result;

            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
            {
                using (BizDataContext db = new BizDataContext())
                {
                    //新流程
                    SysProcess newP = _process.ConvertTo <SysProcess>();
                    newP.ProcessId = db.GetNextIdentity();

                    //版本处理
                    newP.ProcessStatus = (int)ProcessState.Created;
                    string maxVersion = db.Set <SysProcess>().Where(p => p.ProcessType == _process.ProcessType).OrderByDescending(p => p.ProcessVersion).First().ProcessVersion;
                    newP.ProcessVersion = (maxVersion.ToInt() + 1).ToString();

                    result = newP;
                    db.Insert(newP);

                    //新流程参与人
                    var ppList = db.Set <SysProcessParticipant>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    Dictionary <long?, SysProcessParticipant> tempPpDict = new Dictionary <long?, SysProcessParticipant>();
                    foreach (var pp in ppList)
                    {
                        SysProcessParticipant newPp = pp.ConvertTo <SysProcessParticipant>();
                        newPp.ParticipantId = db.GetNextIdentity();
                        newPp.ProcessId     = newP.ProcessId;

                        tempPpDict[pp.ParticipantId] = newPp; //记录原始ID和新对象的关系
                    }
                    foreach (var newPp in tempPpDict.Values)
                    {
                        if (newPp.Param_ParticipantId != null) //通过刚才记录的关系找到实际的值
                        {
                            newPp.Param_ParticipantId = tempPpDict[newPp.Param_ParticipantId].ParticipantId;
                        }
                        db.Insert(newPp);
                    }

                    //新活动
                    var aList = db.Set <SysActivity>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    Dictionary <long?, SysActivity> tempADict = new Dictionary <long?, SysActivity>();
                    foreach (var a in aList)
                    {
                        SysActivity newA = a.ConvertTo <SysActivity>();
                        newA.ActivityId = db.GetNextIdentity();
                        newA.ProcessId  = newP.ProcessId;

                        tempADict[a.ActivityId] = newA;//记录原始ID和新对象的关系
                        db.Insert(newA);

                        //新活动参与人
                        var apList = db.Set <SysActivityParticipant>().Where(p => p.ActivityId == a.ActivityId).ToList();
                        foreach (var ap in apList)
                        {
                            SysActivityParticipant newAp = ap.ConvertTo <SysActivityParticipant>();
                            newAp.ActivityParticipantId = db.GetNextIdentity();
                            newAp.ActivityId            = newA.ActivityId;
                            newAp.ParticipantId         = tempPpDict[newAp.ParticipantId].ParticipantId; //通过刚才记录的关系找到实际的值
                            db.Insert(newAp);
                        }
                    }

                    //连接线
                    var tList = db.Set <SysTransition>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    foreach (var t in tList)
                    {
                        SysTransition newT = t.ConvertTo <SysTransition>();
                        newT.TransitionId = db.GetNextIdentity();
                        newT.ProcessId    = newP.ProcessId;

                        //通过刚才记录的关系找到实际的值
                        newT.PreActivityId  = tempADict[newT.PreActivityId].ActivityId;
                        newT.PostActivityId = tempADict[newT.PostActivityId].ActivityId;

                        db.Insert(newT);
                    }

                    //表单活动权限
                    var fpList = db.Set <SysFormPrivilege>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    foreach (var fp in fpList)
                    {
                        SysFormPrivilege newFp = fp.ConvertTo <SysFormPrivilege>();
                        newFp.PrivilegeId = db.GetNextIdentity();
                        newFp.ProcessId   = newP.ProcessId;
                        newFp.ActivityId  = tempADict[newFp.ActivityId].ActivityId;//通过刚才记录的关系找到实际的值

                        db.Insert(newFp);
                    }
                }
                ts.Complete();
            }
            return(result);
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
        /// <summary>
        /// 保存流程参与人
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cbc_CallBack(object sender, CallBackEventArgs e)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            string errorMsg         = string.Empty; //错误消息
            bool   isError          = false;

            try
            {
                int?   functionType    = e.Context["FunctionType"].ToStringNullable().ToIntNullable();
                int?   userId          = e.Context["UserId"].ToStringNullable().ToIntNullable();
                int?   roleId          = e.Context["RoleId"].ToStringNullable().ToIntNullable();
                long   processId       = e.Context["ProcessId"].ToLong();
                string participantName = string.Empty;

                if (functionType == null)
                {
                    throw new Exception("参与人类型不能为空");
                }
                if (functionType == (int)ParticipantFunctionType.SpecialUser)
                {
                    T_User user = this.DataHelper.FindById <T_User>(userId);
                    if (user == null)
                    {
                        throw new Exception("请指定具体人员");
                    }
                    participantName = user.User_Name;
                }
                if (functionType == (int)ParticipantFunctionType.SpecialRole)
                {
                    T_Role role = this.DataHelper.FindById <T_Role>(roleId);
                    if (role == null)
                    {
                        throw new Exception("请指定具体角色");
                    }
                    participantName = string.Format("{0}角色", role.Role_Name);
                }
                if (functionType == (int)ParticipantFunctionType.DIRECT_MANAGER)
                {
                    participantName = "直属主管";
                }

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        int count = db.Set <SysProcessParticipant>().Where(p =>
                                                                           p.ProcessId == processId && p.FunctionType == functionType && p.Param_RoleId == roleId && p.Param_UserId == userId).Count();
                        if (count > 0)
                        {
                            throw new Exception("已存在相同的流程参与人");
                        }

                        long?param_partId = null;
                        if (functionType == (int)ParticipantFunctionType.DIRECT_MANAGER)
                        {
                            SysProcessParticipant pStartUser = new SysProcessParticipant()
                            {
                                ParticipantId   = db.GetNextIdentity(),
                                ProcessId       = processId,
                                FunctionType    = (int)ParticipantFunctionType.StartUser,
                                ParticipantName = "流程启动人",
                            };
                            param_partId = pStartUser.ParticipantId;
                            db.Insert(pStartUser);
                        }

                        SysProcessParticipant pCurrent = new SysProcessParticipant()
                        {
                            ParticipantId       = db.GetNextIdentity(),
                            ProcessId           = processId,
                            FunctionType        = functionType,
                            Param_UserId        = userId,
                            Param_RoleId        = roleId,
                            Param_ParticipantId = param_partId,
                            ParticipantName     = participantName,
                        };
                        db.Insert(pCurrent);
                    }
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                isError  = true;
                errorMsg = ex.Message;
            }

            string result = js.Serialize(new
            {
                IsError = isError,
                Error   = errorMsg,
            });

            e.Result = result;
        }
コード例 #19
0
        protected void btnSaveAA_Click(object sender, EventArgs e)
        {
            var dataList = RoleOfEntityControl1.GetReptBindItem();

            try
            {
                if (string.IsNullOrEmpty(this.ddlCategory.SelectedValue))
                {
                    return;
                }
                long   CategoryId = Convert.ToInt64(this.ddlCategory.SelectedValue);
                string msg        = string.Empty;
                //先清除该角色权限,然后添加当前设定的权限
                using (BizDataContext Context = new BizDataContext())
                {
                    //var moduleList = Context.Where<SysModule>(p => p.CategoryId == CategoryId).Select(p => p.ModuleId).ToList();
                    var moduleList = this.EntityCache.SysModule.Where(p => p.CategoryId == CategoryId).Select(p => p.ModuleId).ToList();

                    //var entityList = Context.Where<SysEntity>(p => p.ModuleId != null)
                    var entityList = this.EntityCache.SysEntity.Where(p => p.ModuleId != null)
                                     .Where(p => moduleList.Contains(p.ModuleId.Value))
                                     .Select(p => p.EntityId);

                    var delList = Context.Where <SysDataPrivilege>(x => x.RoleId == this.RoleId)
                                  .Where(x => entityList.Contains(x.EntityId)).ToList();
                    //delList.Clear();
                    foreach (var del in delList)
                    {
                        Context.Delete(del);
                    }

                    foreach (var add in dataList)
                    {
                        Context.Insert(new SysDataPrivilege()
                        {
                            EntityId       = add.EntityId,
                            OperationId    = (int)EntityOperationEnum.Add,
                            RoleId         = this.RoleId,
                            PrivelegeLevel = add.addRight
                        });
                        Context.Insert(new SysDataPrivilege()
                        {
                            EntityId       = add.EntityId,
                            OperationId    = (int)EntityOperationEnum.Delete,
                            RoleId         = this.RoleId,
                            PrivelegeLevel = add.delRight
                        });
                        Context.Insert(new SysDataPrivilege()
                        {
                            EntityId       = add.EntityId,
                            OperationId    = (int)EntityOperationEnum.Update,
                            RoleId         = this.RoleId,
                            PrivelegeLevel = add.updtRight
                        });
                        Context.Insert(new SysDataPrivilege()
                        {
                            EntityId       = add.EntityId,
                            OperationId    = (int)EntityOperationEnum.Query,
                            RoleId         = this.RoleId,
                            PrivelegeLevel = add.queryRight
                        });
                    }


                    //1.无权限,2.个人,3.部门,4.部门及子部门,5.全部权限
                    //循环遍历所有实体表(即父实体)
                    foreach (var reptBindItem in dataList)
                    {
                        //获取当前父实体的一对多关系
                        var sysOneMoreRelations =
                            //    Context.Where<SysOneMoreRelation>(
                            this.EntityCache.SysOneMoreRelation.Where(
                                p => p.ParentEntityId == reptBindItem.EntityId && p.IsParentChild == true);
                        //循环所有一对多关系
                        foreach (var sysOneMoreRelation in sysOneMoreRelations)
                        {
                            //sysOneMoreRelation.ChildEntity = Context.FindById<SysEntity>(sysOneMoreRelation.ChildEntityId);

                            //获取父实体的子实体的所有权限
                            var delChild =
                                Context.Where <SysDataPrivilege>(
                                    x => x.RoleId == this.RoleId && sysOneMoreRelation.ChildEntityId == x.EntityId).ToList();
                            //删除子实体的所有权限
                            foreach (var sysDataPrivilege in delChild)
                            {
                                Context.Delete(sysDataPrivilege);
                            }
                            msg += string.Format("{0}为{1}的子实体,权限随{1}的权限而改变!\\n",
                                                 sysOneMoreRelation.ChildEntity.DisplayText,
                                                 reptBindItem.DisplayText);
                            //判断子实体的授权方式
                            //1.个人类,在此情况下子实体无需担心父实体的授权方式,子实体所包含的权限(即上面5种)>=父实体所包含权限
                            //2.组织类(只含有无权限和全部权限),在此情况下需判断父实体所选择的权限(即上面5种之一),如果父实体选择无权限,子实体即无权限,否则子实体为全部权限
                            if (sysOneMoreRelation.ChildEntity.PrivilegeMode == (int)PrivilegeModel.Persional)//子实体为个人类
                            {
                                //子实体的Add权限跟随父实体的Update权限,其余权限与父实体一一对应
                                Context.Insert(new SysDataPrivilege()
                                {
                                    EntityId       = sysOneMoreRelation.ChildEntityId.Value,
                                    OperationId    = (int)EntityOperationEnum.Add,
                                    RoleId         = this.RoleId,
                                    PrivelegeLevel = reptBindItem.updtRight
                                });
                                Context.Insert(new SysDataPrivilege()
                                {
                                    EntityId       = sysOneMoreRelation.ChildEntityId.Value,
                                    OperationId    = (int)EntityOperationEnum.Delete,
                                    RoleId         = this.RoleId,
                                    PrivelegeLevel = reptBindItem.delRight
                                });
                                Context.Insert(new SysDataPrivilege()
                                {
                                    EntityId       = sysOneMoreRelation.ChildEntityId.Value,
                                    OperationId    = (int)EntityOperationEnum.Update,
                                    RoleId         = this.RoleId,
                                    PrivelegeLevel = reptBindItem.updtRight
                                });
                                Context.Insert(new SysDataPrivilege()
                                {
                                    EntityId       = sysOneMoreRelation.ChildEntityId.Value,
                                    OperationId    = (int)EntityOperationEnum.Query,
                                    RoleId         = this.RoleId,
                                    PrivelegeLevel = reptBindItem.queryRight
                                });
                            }
                            else//子实体为组织类
                            {
                                if (reptBindItem.delRight == 1)//父实体对于删除选择无权限
                                {
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Delete,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = reptBindItem.delRight
                                    });
                                }
                                else
                                {
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Delete,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = 5
                                    });
                                }
                                if (reptBindItem.updtRight == 1)//父实体对于更新选择无权限,子实体Add权限跟随父实体update权限
                                {
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Update,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = reptBindItem.updtRight
                                    });
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Add,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = reptBindItem.updtRight
                                    });
                                }
                                else
                                {
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Update,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = 5
                                    });
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Add,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = 5
                                    });
                                }
                                if (reptBindItem.queryRight == 1)//父实体对于查询选择无权限
                                {
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Query,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = reptBindItem.queryRight
                                    });
                                }
                                else
                                {
                                    Context.Insert(new SysDataPrivilege()
                                    {
                                        EntityId =
                                            sysOneMoreRelation.ChildEntityId.Value,
                                        OperationId    = (int)EntityOperationEnum.Query,
                                        RoleId         = this.RoleId,
                                        PrivelegeLevel = 5
                                    });
                                }
                            }
                        }
                    }
                }

                IOperationManager dom = new DefaultOperationManager(this.DataHelper, this.LoginUser);
                int count             = dom.ValidateSharedPrivilege();
                if (count > 0)
                {
                    msg = string.Format("{0},修改导致{1}条权限共享规则被移除", msg, count);
                }

                //清除菜单的缓存,2011-10-8 zhu min
                Session["T_Function"] = null;
                this.AjaxAlert("保存成功!\\n" + msg, "window.location.reload()");
            }
            catch (Exception ex)
            {
                this.AjaxAlert(ex);
            }
        }