Esempio n. 1
0
 public List <WrokItemBase> GetWorkItem(IUserIdentity user)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         List <WrokItemBase> list = new List <WrokItemBase>();
         WrokItemBase        item = null;
         if (!(from r in context.Where <T_User_Role>(r => r.User_Id == user.User_ID) select r.Role_Id).ToList <int>().Contains(Uitity.SystemManger))
         {
             return(null);
         }
         List <AppFunc> appList = this.GetAppList(context, user);
         if ((appList != null) && (appList.Count > 0))
         {
             int workItemState = 0;
             List <T_WorkItemBase> workItemList = context.Where <T_WorkItemBase>(w => w.State == workItemState);
             foreach (AppFunc func in appList)
             {
                 item = new WrokItemBase {
                     FuncName       = func.FuncName,
                     workTaskList   = this.GetWorkTask(context, user, func, workItemList),
                     remindItemList = this.GetRemindItem(context, user, func)
                 };
                 list.Add(item);
             }
         }
         return(list);
     }
 }
        /// <summary>
        /// 删除流程,只有“新增”状态的可以删除
        /// </summary>
        public void DeleteProcess()
        {
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
            {
                using (BizDataContext db = new BizDataContext())
                {
                    if (_process != null && _process.ProcessStatus == (int)ProcessState.Created)
                    {
                        //删除流程
                        db.Delete(_process);

                        //删除活动
                        db.Where <SysActivity>(p => p.ProcessId == _process.ProcessId).ToList().ForEach(p =>
                        {
                            //删除活动
                            db.Delete(p);

                            //删除活动参与人
                            db.Where <SysActivityParticipant>(i => i.ActivityId == p.ActivityId).ToList().ForEach(i => db.Delete(i));
                        });

                        //删除流程参与人
                        db.Where <SysProcessParticipant>(p => p.ProcessId == _process.ProcessId).ToList().ForEach(p => db.Delete(p));

                        //删除连接线
                        db.Where <SysTransition>(p => p.ProcessId == _process.ProcessId).ToList().ForEach(p => db.Delete(p));
                    }
                    else
                    {
                        throw new Exception("流程不存在或当前流程状态不能删除");
                    }
                }
                ts.Complete();
            }
        }
Esempio n. 3
0
        private void LoadDropDown()
        {
            try
            {
                using (BizDataContext context = new BizDataContext())
                {
                    var processList = context.Where <SysProcess>(p =>
                                                                 p.ProcessStatus == (int)ProcessState.StartUsed &&
                                                                 p.ProcessCategory != (int)ProcessCategory.FormApprove //2013-9-13 zhumin 排除表单流程
                                                                 );

                    cbProcess.DataTextField  = "ProcessName";
                    cbProcess.DataValueField = "ProcessType";
                    cbProcess.DataSource     = processList;
                    cbProcess.DataBind();

                    cbStartUser.DataTextField  = "User_Name";
                    cbStartUser.DataValueField = "User_ID";
                    cbStartUser.DataSource     = context.FetchAll <T_User>();
                    cbStartUser.DataBind();

                    cbStartUser.SetValue(this.LoginUserID.ToString());
                }
            }
            catch (ApplicationException ex)
            {
                this.AjaxAlert(ex.Message);
            }
        }
        private WfActivityEntityInstance GetApproveEntityData(BizDataContext context, SysApproveActivityData p)
        {
            WfActivityEntityInstance entity = new WfActivityEntityInstance()
            {
                ActivityEntityInstanceId = p.DataId,
            };
            var dic  = new Dictionary <string, WfActivityFieldData>();
            var list = context.Where <SysApproveActivityData>(i => i.ApproveGroupId == p.ApproveGroupId).OrderBy(i => i.ApproveTime).ToList();

            for (int i = 0; i < list.Count(); i++)
            {
                p = list.ElementAt(i);
                var user = context.FindById <T_User>(p.ApproveUserId);
                if (user != null)
                {
                    dic[(1 + 3 * i).ToString()] = new WfActivityFieldData()
                    {
                        DisplayText = "审核人", Value = user.User_Name
                    };
                }
                dic[(2 + 3 * i).ToString()] = new WfActivityFieldData()
                {
                    DisplayText = "审核时间", Value = Convert.ToString(p.ApproveTime)
                };
                dic[(3 + 3 * i).ToString()] = new WfActivityFieldData()
                {
                    DisplayText = "审核意见", Value = p.ApproveComment
                };
            }
            entity.ActivityEntityInstanceData = dic;

            return(entity);
        }
        private void BindSchedule()
        {
            try
            {
                using (BizDataContext context = new BizDataContext())
                {
                    var source = context.Where <Drision.Framework.OrgLibrary.InternalEntities.T_WorkItemBase>(p => p.OwnerId == LoginUserID && p.State == (int)WorkItemStatus.Created).ToList()
                                 .Select(p => new ScheduleEvent()
                    {
                        StartTime = p.StartTime,
                        EndTime   = p.EndTime,
                        EventId   = p.WorkItemBase_Id,
                        Title     = p.Title,
                        Url       = p.CompletePageUrl,
                        IsAllDay  = p.IsAllDay ?? false,
                        EventType = p.WorkItemTypeID == null ? ScheduleEventTypes.Blue : ScheduleEventTypes.Green,
                    });

                    foreach (var p in source)
                    {
                        this.sc.ScheduleEvents.Add(p);
                    }
                }
            }
            catch (Exception ex)
            {
                this.AjaxAlert(ex);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// 查询
 /// </summary>
 protected void btnQuery_Click(object sender, EventArgs e)
 {
     try
     {
         using (BizDataContext context = new BizDataContext())
         {
             string name   = this.tbT_ProcessName.Text.Trim();
             var    result = context.Where <SysProcess>(p =>
                                                        p.ProcessName.Contains(name) &&
                                                        p.ProcessCategory != (int)ProcessCategory.FormApprove && //2013-9-13 zhumin 排除表单流程
                                                        p.ProcessStatus == (int)ProcessState.StartUsed)
                             .OrderBy(p => p.ProcessType);
             var source = result.Select(p => new
             {
                 p.ProcessId,
                 ProcessCategory = EnumHelper.GetDescription(typeof(ProcessCategory), p.ProcessCategory.Value),
                 p.ProcessName,
                 //context.FindById<SysEntity>(p.EntityId).EntityName,
                 this.EntityCache.FindById <SysEntity>(p.EntityId).EntityName,
                 //ActivityEntityName = context.FindById<SysEntity>(p.ActivityEntityId).EntityName,
                 ActivityEntityName = this.EntityCache.FindById <SysEntity>(p.ActivityEntityId).EntityName,
                 p.ProcessType,
                 p.ProcessVersion,
                 ProcessStatus = EnumHelper.GetDescription(typeof(ProcessState), p.ProcessStatus.Value),
             });
             gcProcess.DataSource = source;
             gcProcess.DataBind();
         }
     }
     catch (ApplicationException ex)
     {
         this.AjaxAlert(ex.Message);
     }
 }
Esempio n. 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //加载数据
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    long ProcessId = long.Parse(Request.QueryString["id"]);
                    using (BizDataContext context = new BizDataContext())
                    {
                        SysProcess process = context.FindById <SysProcess>(ProcessId);
                        if (process != null)
                        {
                            this.lblProcessName.Text        = process.ProcessName;
                            this.lblProcessDescription.Text = process.ProcessDescription;
                            this.lblStatus.Text             = EnumHelper.GetDescription(typeof(ProcessState), process.ProcessStatus.Value);

                            this.gcProcessProxy.DataSource = context.Where <SysProcessProxy>(p => p.ProcessId == ProcessId).ToList();
                            this.gcProcessProxy.DataBind();
                        }
                    }
                    this.btnAdd.PostBackUrl = "~/SystemManagement/ProcessProxyAdd.aspx?ProcessId=" + Request.QueryString["id"];
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 删除流程参与人
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                long?id = (sender as LinkButton).CommandArgument.ToLongNullable();
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        SysProcessParticipant p = db.FindById <SysProcessParticipant>(id);
                        if (p != null)
                        {
                            //同步删除关联的活动参与人
                            var apList = db.Where <SysActivityParticipant>(x => x.ParticipantId == id);
                            foreach (var ap in apList)
                            {
                                db.Delete(ap);
                            }

                            db.Delete(p);
                        }
                    }
                    ts.Complete();
                }
                BindGrid();
            }
            catch (Exception ex)
            {
                this.AjaxAlert(ex);
            }
        }
        private List <SysFunction> GetChilds(SysFunction parent, List <SysFunction> res, BizDataContext context)
        {
            List <SysFunction> list = context.Where <SysFunction>(p => p.Permission_Type == parent.Function_ID);

            list.ForEach(delegate(SysFunction p) {
                res.AddRange(this.GetChilds(p, res, context));
            });
            return(list);
        }
 public static List <SysWorkflowMessage> GetNextMessages(string connectionStringOrName)
 {
     if (string.IsNullOrWhiteSpace(connectionStringOrName))
     {
         connectionStringOrName = DataContext.BizConnectionStringDefault;
     }
     using (BizDataContext context = new BizDataContext(connectionStringOrName, true))
     {
         return((from p in context.Where <SysWorkflowMessage>(p => ((int)p.State) == 0)
                 orderby p.MessageId
                 select p).Take <SysWorkflowMessage>(10).ToList <SysWorkflowMessage>());
     }
 }
Esempio n. 11
0
        private static IList <T_Role> GetRoleList(BizDataContext ctx, int userId)
        {
            List <T_Role> list  = new List <T_Role>();
            List <int>    list2 = (from t in ctx.Where <T_User_Role>(t => t.User_Id == userId) select t.Role_Id).ToList <int>();

            foreach (int num in list2)
            {
                T_Role item = new T_Role {
                    Role_ID = num
                };
                list.Add(item);
            }
            return(list);
        }
        /// <summary>
        /// 绑定第三层Repeater,这个是SysApproveActivityData(已经审核的)和SysWorkItem(未参与审核的)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rpApproveGroup_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rpApproveActivity    = e.Item.FindControl("rpApproveActivity") as Repeater;
            SysWorkItemApproveGroup group = e.Item.DataItem.GetPropertyValue("Group") as SysWorkItemApproveGroup;

            using (BizDataContext context = new BizDataContext())
            {
                var result = context.Where <SysApproveActivityData>(p => p.ApproveGroupId == group.ApproveGroupId)
                             .Select(p => new
                {
                    p.ApproveTime,
                    p.WorkItemId,
                    User_Name      = context.FindById <T_User>(p.ApproveUserId).User_Name,
                    ApproveResult  = p.ApproveResult,
                    ApproveComment = p.ApproveComment,
                    AddingUser     = p.IsAdded == true ? "[加签]" : "",
                    ProxyUser      = p.IsProxy == true ? "[代理]" : "",
                }).ToList().Select(p => new UserApproveComment()
                {
                    WorkItemId     = p.WorkItemId,
                    User_Name      = p.User_Name,
                    ApproveComment = p.ApproveComment,
                    AddingUser     = p.AddingUser,
                    ProxyUser      = p.ProxyUser,
                    ApproveResult  = GetCheckState(p.ApproveResult),
                    ApproveDate    = string.Format("{0:MM/dd HH:mm}", p.ApproveTime),
                }).ToList();

                var idList    = result.Select(p => p.WorkItemId);
                var otherList = group.WorkItems.Where(p => !idList.Contains(p.WorkItemId));
                int?state     = null;
                foreach (var other in otherList)
                {
                    result.Add(new UserApproveComment()
                    {
                        WorkItemId     = other.WorkItemId,
                        User_Name      = context.FindById <T_User>(other.OwnerId).User_Name,
                        ApproveComment = other.Status == (int)WorkItemStatus.CancelledBySystem ? "未参与审核" : GetCheckState(state),
                        AddingUser     = string.Empty,
                        ProxyUser      = string.Empty,
                        ApproveResult  = other.Status == (int)WorkItemStatus.CancelledBySystem ? "未参与审核" : GetCheckState(state),
                    });
                }

                rpApproveActivity.DataSource = result;
                rpApproveActivity.DataBind();
            }
        }
Esempio n. 13
0
        public ActionResult Index()
        {
            Case model = new Case();

            using (BizDataContext db = new BizDataContext())
            {
                var prot = db.Where <T_Product>(p => p.State == (int)T_ProductStateEnum.Enable).OrderBy(p => p.Product_Id).FirstOrDefault();
                if (prot != null)
                {
                    model.Id      = prot.Product_Id;
                    model.Title   = prot.Product_Name;
                    model.Content = prot.Content;
                }
            }
            return(View(model));
        }
Esempio n. 14
0
        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPublish_Click(object sender, EventArgs e)
        {
            try
            {
                SysForm form = this.DataHelper.FindById <SysForm>(this.FormId);
                if (form != null)
                {
                    using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                    {
                        using (BizDataContext db = new BizDataContext())
                        {
                            //更新表单状态
                            form.State        = (int)FormState.StartUsed;
                            form.UpdateTime   = DateTime.Now;
                            form.UpdateUserId = this.LoginUserID;
                            db.UpdatePartial(form, p => new { p.State, p.UpdateUserId, p.UpdateTime });

                            //发布数据库
                            SysEntity entity = this.EntityCache.FindById <SysEntity>(this.EntityId);
                            if (entity == null) //新增加的实体
                            {
                                entity = db.FindById <SysEntity>(this.EntityId);
                                if (entity == null)
                                {
                                    throw new Exception("表单关联实体不存在");
                                }
                                entity.Fields = db.Where <SysField>(p => p.EntityId == entity.EntityId);

                                FormEntityPublishHelper publish = new FormEntityPublishHelper(entity, db);
                                publish.Publish();
                            }
                        }
                        ts.Complete();
                    }
                }
                else
                {
                    throw new Exception("表单不存在");
                }
                this.AjaxAlertAndRedirect("发布成功", "FormQuery.aspx");
            }
            catch (Exception ex)
            {
                this.AjaxAlertAndEnableButton(ex);
            }
        }
Esempio n. 15
0
 private void BindDDL()
 {
     try
     {
         using (BizDataContext context = new BizDataContext())
         {
             var source = context.Where <Drision.Framework.OrgLibrary.InternalEntities.T_WorkItemType>(p => p.AllowManualAdd == true).ToList();
             this.ccWorkItemType.DataSource     = source;
             this.ccWorkItemType.DataTextField  = "WorkItemType_Name";
             this.ccWorkItemType.DataValueField = "WorkItemType_Id";
             this.ccWorkItemType.DataBind();
         }
     }
     catch (Exception ex)
     {
         this.AjaxAlert(ex);
     }
 }
Esempio n. 16
0
 private void CheckTimeOut()
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         ParameterExpression         expression;
         ProcessInstanceCacheFactory factory = new ProcessInstanceCacheFactory(context);
         List <int>         list             = new List <int>();
         List <SysWorkItem> list2            = context.Where <SysWorkItem>(
             Expression.Lambda <Func <SysWorkItem, bool> >(
                 Expression.AndAlso(Expression.AndAlso(
                                        Expression.NotEqual(Expression.Property(
                                                                expression = Expression.Parameter(typeof(SysWorkItem), "p"),
                                                                (typeof(SysWorkItem).GetProperty("DeadLine"))),
                                                            Expression.Convert(Expression.Constant(null, typeof(DateTime?)),
                                                                               typeof(DateTime?)), false, (typeof(DateTime).GetMethod("Now"))),
                                        Expression.Equal(Expression.Property(expression, typeof(SysWorkItem).GetProperty("")),
                                                         Expression.Convert(Expression.Constant(0, typeof(int)), typeof(int?)))),
                                    Expression.GreaterThan(Expression.Convert(Expression.Property(null, typeof(DateTime).GetMethod("Now")),
                                                                              typeof(DateTime?)), Expression.Property(expression, typeof(SysWorkItem).GetProperty("DeadLine")),
                                                           false, typeof(SysWorkItem).GetMethod("Now"))), new ParameterExpression[] { expression })).ToList <SysWorkItem>();
         if (list2.Count > 0)
         {
             foreach (SysWorkItem item in list2)
             {
                 SysWorkItem        item2;
                 SysProcessInstance processInstanceCacheByWorkItem = factory.GetProcessInstanceCacheByWorkItem(item.WorkItemId, out item2);
                 if (!list.Contains(processInstanceCacheByWorkItem.ProcessInstanceId))
                 {
                     list.Add(processInstanceCacheByWorkItem.ProcessInstanceId);
                 }
                 factory.Manager.ExecutePython(processInstanceCacheByWorkItem, item2.ActivityInstance.Activity.TimeOutScript);
                 item2.Status  = 3;
                 item2.EndTime = new DateTime?(DateTime.Now);
                 factory.UpdateWorkItemBaseState(item2);
                 factory.Context.Update(item2);
             }
         }
         foreach (int num in list)
         {
             factory.ClearCache(num);
         }
     }
 }
Esempio n. 17
0
 public SysPathRule GetRule(int id)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         SysPathRule            rule = context.FindById <SysPathRule>(new object[] { id });
         List <SysPathRuleItem> list = context.Where <SysPathRuleItem>(p => p.PathRuleId == id);
         foreach (SysPathRuleItem item in list)
         {
             if (item.ItemType == PathRuleMasterType.Role)
             {
                 rule.Roles.Add(item.ObjectId);
             }
             else
             {
                 rule.Users.Add(item.ObjectId);
             }
         }
         return(rule);
     }
 }
Esempio n. 18
0
 public bool DeleteRoleFunction(int roleId)
 {
     try
     {
         using (BizDataContext context = new BizDataContext(true))
         {
             List <T_Role_Function> list = context.Where <T_Role_Function>(r => r.Role_ID == roleId);
             if ((list != null) && (list.Count > 0))
             {
                 foreach (T_Role_Function function in list)
                 {
                     context.Delete(function);
                 }
             }
         }
         return(true);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception);
         return(false);
     }
 }
Esempio n. 19
0
        /// <summary>
        /// 绑定数据到用户控件上
        /// </summary>
        private void BingDataToUserControl()
        {
            if (string.IsNullOrEmpty(this.ddlCategory.SelectedValue))
            {
                return;
            }
            long CategoryId = Convert.ToInt64(this.ddlCategory.SelectedValue);

            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(x => new
                {
                    x.EntityId,
                    x.EntityName,
                    x.DisplayText,
                    x.Description,
                    PrivilegeMode = x.PrivilegeMode ?? (int)PrivilegeModel.Persional
                }).ToList();
                //获取该角色权限信息
                var dataList = Context.Where <SysDataPrivilege>(x => x.RoleId == this.RoleId);
                //组合数据
                var sourceList = entityList.Select(x => new ReptBindItem()
                {
                    EntityId      = x.EntityId,
                    EntityName    = x.EntityName,
                    DisplayText   = x.DisplayText,
                    Description   = x.Description,
                    PrivilegeMode = x.PrivilegeMode,
                    addRight      = dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Add).FirstOrDefault() == null ? (int)EntityPrivilegeEnum.NoPermission :
                                    dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Add).FirstOrDefault().PrivelegeLevel,
                    delRight = dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Delete).FirstOrDefault() == null ? (int)EntityPrivilegeEnum.NoPermission :
                               dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Delete).FirstOrDefault().PrivelegeLevel,
                    updtRight = dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Update).FirstOrDefault() == null ? (int)EntityPrivilegeEnum.NoPermission :
                                dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Update).FirstOrDefault().PrivelegeLevel,
                    queryRight = dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Query).FirstOrDefault() == null ? (int)EntityPrivilegeEnum.NoPermission :
                                 dataList.Where(y => y.EntityId == x.EntityId && y.OperationId == (int)EntityOperationEnum.Query).FirstOrDefault().PrivelegeLevel
                }).ToList();

                #region 左连接不成功,传说EF里面不支持左连接,本人测试结果是简单语句可以左连接,复杂条件下不成功
                //var source = from n in Context.SysEntity
                //             join d in Context.SysDataPrivilege on n.EntityId equals d.EntityId into right
                //             select new
                //             {
                //                 n.EntityId,
                //                 n.EntityName,
                //                 n.DisplayText,
                //                 n.Description,
                //                 RoleId = 1,
                //                 addRight = right.Where(x => x.RoleId == 1 && x.OperationId == 1).FirstOrDefault() == null ? -1 : 1,
                //                 delRight = right.Where(x => x.RoleId == 1 && x.OperationId == 2).FirstOrDefault() == null ? -1 : 2,
                //                 updtRight = right.Where(x => x.RoleId == 1 && x.OperationId == 3).FirstOrDefault() == null ? -1 : 3,
                //                 queryRight = right.Where(x => x.RoleId == 1 && x.OperationId == 4).FirstOrDefault() == null ? -1 : 4,
                //                 //delRight = gb.FirstOrDefault().right == null ? -1 : gb.FirstOrDefault().right.Where(r => r.OperationId == 2).FirstOrDefault() == null ? -1 : 2,
                //                 //updtRight = gb.FirstOrDefault().right == null ? -1 : gb.FirstOrDefault().right.Where(r => r.OperationId == 3).FirstOrDefault() == null ? -1 : 3,
                //                 //queryRight = gb.FirstOrDefault().right == null ? -1 : gb.FirstOrDefault().right.Where(r => r.OperationId == 4).FirstOrDefault() == null ? -1 : 4,
                //                 //OperationId = gb.Key.OperationId, //增删改查方式
                //                 //PrivelegeLevel = gb.Key.PrivelegeLevel
                //             };
                //var sourceList = source.ToList();
                #endregion

                RoleOfEntityControl1.RightSource = sourceList;
            }
        }
Esempio n. 20
0
        /// <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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                long?entityId = this.scEntity.SelectedValues.FirstOrDefault().ToLongNullable();
                if (entityId == null)
                {
                    throw new Exception("请选择实体");
                }
                List <int> roleIdList = this.scRole.SelectedValues.Select(p => p.ToIntNullable()).Where(p => p != null).Select(p => p.Value).ToList();
                if (roleIdList.Count == 0)
                {
                    throw new Exception("请选择角色");
                }
                List <int> opList = this.scOperation.SelectedValues.Select(p => p.ToIntNullable()).Where(p => p != null).Select(p => p.Value).ToList();
                if (opList.Count == 0)
                {
                    throw new Exception("请选择操作");
                }
                int?privilege = this.ccPrivilege.SelectedValue.ToIntNullable();
                if (privilege == null)
                {
                    throw new Exception("请选择权限");
                }

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        var delList = db.Where <SysDataPrivilege>(p => p.EntityId == entityId.Value)
                                      .Where(p => roleIdList.Contains(p.RoleId)).ToList();
                        foreach (var del in delList)
                        {
                            db.Delete(del);
                        }

                        var insertList = new List <SysDataPrivilege>();
                        foreach (var roleId in roleIdList)
                        {
                            foreach (var op in opList)
                            {
                                SysDataPrivilege data = new SysDataPrivilege()
                                {
                                    RoleId         = roleId,
                                    EntityId       = entityId.Value,
                                    OperationId    = op,
                                    PrivelegeLevel = privilege.Value,
                                };
                                insertList.Add(data);
                            }
                        }
                        db.BatchInsert(insertList);
                    }
                    ts.Complete();
                }
                Clear();
                this.AjaxAlert("保存成功");
            }
            catch (Exception ex)
            {
                this.AjaxAlert(ex);
            }
        }
Esempio n. 23
0
        public static MvcHtmlString KingUploaderFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, string name, string objectName = null, string fileType = null, string fileSize = null, int fileCount = 1, bool readOnly = false, string jsCallBack = null)
        {
            UploaderModel model = new UploaderModel {
                Name = name
            };

            helper.RenderPartial("~/Views/ControlScripts/_UploaderScripts.cshtml", model);
            List <string> keyList  = new List <string>();
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, helper.ViewData);
            string        s        = (metadata.Model == null) ? "" : metadata.Model.ToString();
            StringBuilder builder  = new StringBuilder();
            int           objId    = 0;

            using (BizDataContext context = new BizDataContext(true))
            {
                builder.AppendLine("<div class=\"divUpload\">");
                if (!readOnly)
                {
                    builder.AppendLine("<input type=\"file\" name=\"uploadify_" + name + "\" id=\"uploadify_" + name + "\" />");
                    builder.AppendLine("<input type=\"hidden\" class=\"currentFlag\" value=\"" + name + "\" />");
                }
                string        str2     = string.Empty;
                StringBuilder builder2 = new StringBuilder();
                builder2.AppendLine("<div id=\"divAttachmentList_" + name + "\">");
                if (int.TryParse(s, out objId))
                {
                    List <T_Attachment> list2 = context.Where <T_Attachment>(a => ((a.State == 0) && (a.OwnerObjectId == objId)) && (string.IsNullOrWhiteSpace(objectName) || (a.OwnerEntityType == objectName)));
                    if ((list2 != null) && (list2.Count > 0))
                    {
                        foreach (T_Attachment attachment in list2)
                        {
                            str2 = str2 + attachment.Attachment_ID + ",";
                            builder2.AppendLine("<div class='CurrCount_" + name + "'>");
                            if (!readOnly)
                            {
                                builder2.AppendLine(string.Concat(new object[] { "<a href='javascript:void(0)' onclick='DeleteAttachment(this)' extAttachmentName='", name, "' extAttachmentId='", attachment.Attachment_ID, "'>[删除]</a>&nbsp;" }));
                            }
                            builder2.AppendLine(string.Concat(new object[] { "<a href='/Attachment/Download?attachmentId=", attachment.Attachment_ID, "'>", attachment.DisplayName, "</a></div>" }));
                        }
                    }
                }
                builder2.AppendLine("</div>");
                builder.AppendLine("<input type=\"hidden\" id=\"" + name + "\" name=\"" + name + "\" value=\"" + str2 + "\" />");
                builder.AppendLine("<input type=\"hidden\" id=\"hidCallBack_" + name + "\" name=\"hidCallBack_" + name + "\"  value=\"" + jsCallBack + "\" />");
                fileSize = string.IsNullOrEmpty(fileSize) ? string.Empty : fileSize;
                builder.AppendLine("<input type=\"hidden\" id=\"hidFileSize_" + name + "\" name=\"hidFileSize_" + name + "\" value=\"" + fileSize + "\" />");
                fileCount = (fileCount < 1) ? 1 : fileCount;
                builder.AppendLine(string.Concat(new object[] { "<input type=\"hidden\" id=\"hidFileCount_", name, "\" name=\"hidFileCount_", name, "\" value=\"", fileCount, "\" />" }));
                if (!string.IsNullOrEmpty(fileType))
                {
                    StringBuilder builder3 = new StringBuilder();
                    string[]      strArray = fileType.Split(new char[] { ',', Convert.ToChar(0xff0c) }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string str3 in strArray)
                    {
                        builder3.AppendFormat("*.{0};", str3);
                    }
                    builder.AppendLine("<input type=\"hidden\" id=\"hidFileType_" + name + "\" name=\"hidFileType_" + name + "\" value=\"" + builder3.ToString() + "\" />");
                }
                builder.AppendLine(builder2.ToString());
                builder.AppendLine("</div>");
                builder.AppendLine(CtrlScripts.RenderScript(helper, keyList));
            }
            return(MvcHtmlString.Create(builder.ToString()));
        }
Esempio n. 24
0
        /// <summary>
        /// 清除流程
        /// </summary>
        /// <param name="processId"></param>
        public string Delete(long processId)
        {
            try
            {
                using (BizDataContext context = new BizDataContext())
                {
                    SendToClient("正在删除旧流程定义...", 10);

                    SysProcess process = context.FindById <SysProcess>(processId);
                    if (process != null)
                    {
                        //禁用外键
                        DisableConstraint();

                        //删除流程
                        context.Delete(process);

                        //删除活动
                        context.Where <SysActivity>(p => p.ProcessId == processId).ToList().ForEach(p =>
                        {
                            //删除活动
                            context.Delete(p);

                            //删除活动操作
                            context.Where <SysActivityOperation>(i => i.ActivityId == p.ActivityId).ToList().ForEach(i =>
                            {
                                //删除活动操作
                                context.Delete(i);

                                //删除活动操作步骤
                                context.Where <SysActivityStep>(q => q.OperationId == i.OperationId).ToList().ForEach(q => context.Delete(q));
                            });

                            //删除活动提醒
                            context.Where <SysActivityRemind>(i => i.ActivityId == p.ActivityId).ToList().ForEach(i =>
                            {
                                //删除活动提醒
                                context.Delete(i);

                                //删除活动提醒参与人
                                context.Where <SysActivityRemindParticipant>(q => q.RemindId == i.RemindId).ToList().ForEach(q => context.Delete(q));
                            });

                            //删除活动参与人
                            context.Where <SysActivityParticipant>(i => i.ActivityId == p.ActivityId).ToList().ForEach(i => context.Delete(i));

                            //删除表达式
                            context.Where <SysExpression>(i => i.ActivityId == p.ActivityId).ToList().ForEach(i => context.Delete(i));
                        });

                        //删除流程参与人
                        context.Where <SysProcessParticipant>(p => p.ProcessId == processId).ToList().ForEach(p => context.Delete(p));

                        //删除流程提醒
                        context.Where <SysProcessRemind>(p => p.ProcessId == processId).ToList().ForEach(p =>
                        {
                            //删除流程提醒
                            context.Delete(p);

                            //删除流程提醒参与人
                            context.Where <SysProcessRemindParticipant>(q => q.RemindId == p.RemindId).ToList().ForEach(q => context.Delete(q));
                        });

                        //删除连接线
                        context.Where <SysTransition>(p => p.ProcessId == processId).ToList().ForEach(p => context.Delete(p));

                        //启用外键
                        EnableConstraint();

                        return(null);
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Esempio n. 25
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);
            }
        }