Ejemplo n.º 1
0
        public static int GetUserIdFromToken(string token, BizDataContext db = null)
        {
            SysUserToken token2;

            if (string.IsNullOrWhiteSpace(token))
            {
                throw new SsoException("令牌为空", SsoException.NullToken);
            }
            if (db == null)
            {
                using (db = new BizDataContext())
                {
                    token2            = db.FindById <SysUserToken>(token);
                    token2.ExpireTime = DateTime.Now.AddHours(2.0);
                    db.UpdatePartial(token2, p => new { p.ExpireTime });
                }
            }
            else
            {
                token2            = db.FindById <SysUserToken>(token);
                token2.ExpireTime = DateTime.Now.AddHours(2.0);
                db.UpdatePartial(token2, p => new { p.ExpireTime });
            }
            if (token2 == null)
            {
                throw new SsoException("令牌无效", SsoException.InvalidToken);
            }
            if (token2.ExpireTime < DateTime.Now)
            {
                throw new SsoException("令牌已过期", SsoException.ExpiredToken);
            }
            return(token2.UserId);
        }
        /// <summary>
        /// 启用流程,只有“停用”状态的可以启用
        /// </summary>
        public void StartProcess()
        {
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
            {
                using (BizDataContext db = new BizDataContext())
                {
                    if (_process != null && _process.ProcessStatus == (int)ProcessState.Stoped)
                    {
                        int count = db.Set <SysProcess>().Count(p => p.ProcessType == _process.ProcessType &&
                                                                p.ProcessStatus == (int)ProcessState.StartUsed);
                        if (count > 0)
                        {
                            throw new Exception("该流程已经存在已启用的版本,请先停用");
                        }

                        _process.ProcessStatus = (int)ProcessState.StartUsed;
                        db.UpdatePartial(_process, p => new { p.ProcessStatus });
                    }
                    else
                    {
                        throw new Exception("流程不存在或当前流程状态不能启用");
                    }
                }
                ts.Complete();
            }
        }
Ejemplo n.º 3
0
        public bool ChangeWorkItemState(int id, T_WorkItemBaseStateEnum state, out string errorMsg)
        {
            bool flag;

            errorMsg = string.Empty;
            try
            {
                using (BizDataContext context = new BizDataContext(true))
                {
                    T_WorkItemBase base2 = context.FindById <T_WorkItemBase>(new object[] { id });
                    if ((base2 != null) && (base2.WorkItemBase_Id > 0))
                    {
                        base2.State = new int?((int)state);
                        context.UpdatePartial <T_WorkItemBase>(base2, p => new { State = p.State });
                        return(true);
                    }
                    errorMsg = "未获取到T_WorkItemBase实体";
                    flag     = false;
                }
            }
            catch (Exception exception)
            {
                errorMsg = exception.Message;
                flag     = false;
            }
            return(flag);
        }
        /// <summary>
        /// 发布
        /// </summary>
        public void Publish()
        {
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
            {
                using (BizDataContext db = new BizDataContext())
                {
                    //TO DO 验证流程的完整性

                    //将对应的已启用的流程的状态改为已升级
                    SysProcess oldProcess = db.FirstOrDefault <SysProcess>(p => p.ProcessType == _process.ProcessType &&
                                                                           p.ProcessStatus == (int)ProcessState.StartUsed);
                    if (oldProcess != null)
                    {
                        oldProcess.ProcessStatus = (int)ProcessState.Updated;
                        db.UpdatePartial(oldProcess, p => new { p.ProcessStatus });
                    }

                    //将当前流程版本,状态改为已启用
                    _process.ProcessStatus = (int)ProcessState.StartUsed;
                    db.UpdatePartial(_process, p => new { p.ProcessStatus });
                }
                ts.Complete();
            }
        }
Ejemplo n.º 5
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);
            }
        }
 /// <summary>
 /// 停用流程,只有“启用”状态的可以停用
 /// </summary>
 public void StopProcess()
 {
     using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
     {
         using (BizDataContext db = new BizDataContext())
         {
             if (_process != null && _process.ProcessStatus == (int)ProcessState.StartUsed)
             {
                 _process.ProcessStatus = (int)ProcessState.Stoped;
                 db.UpdatePartial(_process, p => new { p.ProcessStatus });
             }
             else
             {
                 throw new Exception("流程不存在或当前流程状态不能停用");
             }
         }
         ts.Complete();
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 发布工作流
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string PublishWorkFlow(WfWorkflowData data, long?oldProcessId)
        {
            try
            {
                using (BizDataContext context = new BizDataContext())
                {
                    //先把对应的已启用的流程状态改为已升级
                    var oldProcess = context.FirstOrDefault <SysProcess>(p => p.ProcessType == data.Process.ProcessType && p.ProcessStatus == (int)ProcessState.StartUsed);
                    if (oldProcess != null)
                    {
                        oldProcess.ProcessStatus = (int)ProcessState.Updated;
                        context.UpdatePartial(oldProcess, p => new { p.ProcessStatus });
                    }

                    return(InternalSaveWorkFlow(context, data, oldProcessId));
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        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);
            }
        }
Ejemplo n.º 9
0
        public void DoStatisticsMobile()
        {
            try
            {
                using (var db = new BizDataContext())
                {
                    string sql = @"select t2.equipmenttype,t2.osversion from 
    (
      select row_number() over(partition by t0.ownerid order by  t0.createtime desc) rownumb, t0.equipmenttype, t0.osversion from t_Gw_Loginlog t0 
      inner join T_user t1 on (t1.state <> 9999 and t0.ownerid = t1.user_id)
        
      order by t0.ownerid, t0.createtime desc 
    ) t2 where t2.rownumb = 1";

                    DataTable dt = db.ExecuteDataTable(sql);

                    var query = dt.Rows.OfType <DataRow>()
                                .Select(p => new
                    {
                        equipmenttype = p["equipmenttype"].ToString(),
                        osversion     = p["osversion"].ToString(),
                    });

                    var model = query.GroupBy(x => x.equipmenttype).Select(x => new
                    {
                        ostype = x.Key,
                        count  = x.Count(),
                        vals   = x
                    });
                    //获取所有数据
                    var modelList = db.Set <T_GW_MobileStatistics>().ToList();


                    List <T_GW_MobileStatistics> addlist    = new List <T_GW_MobileStatistics>();
                    List <T_GW_MobileStatistics> updatelist = new List <T_GW_MobileStatistics>();
                    foreach (var x in model)
                    {
                        T_GW_MobileStatistics entity = new T_GW_MobileStatistics();
                        string ostype = x.ostype;
                        if (string.IsNullOrEmpty(x.ostype))
                        {
                            ostype = null;
                        }

                        entity.OSType         = ostype;
                        entity.TotalCount     = x.count;
                        entity.StatisticsType = "os";


                        if (modelList.Where(p => p.StatisticsType == "os" && p.OSType == ostype).FirstOrDefault() != null)
                        {
                            updatelist.Add(entity);
                        }
                        else
                        {
                            entity.GW_MobileStatistics_Id = db.GetNextIdentity_Int();
                            entity.CreateTime             = DateTime.Now;
                            entity.State = 1;
                            addlist.Add(entity);
                        }


                        //string ostype = x.ostype;
                        foreach (var item in x.vals.GroupBy(p => p.osversion).Select(p => new { osvertion = p.Key, count = p.Count() }))
                        {
                            T_GW_MobileStatistics entity2 = new T_GW_MobileStatistics();
                            string osversion = item.osvertion;
                            if (string.IsNullOrEmpty(item.osvertion))
                            {
                                osversion = null;
                            }
                            entity2.OSType         = ostype;
                            entity2.OSVersion      = osversion;
                            entity2.TotalCount     = item.count;
                            entity2.StatisticsType = "ver";


                            if (modelList.Where(p => p.StatisticsType == "ver" && p.OSType == ostype && p.OSVersion == osversion).FirstOrDefault() != null)
                            {
                                updatelist.Add(entity2);
                            }
                            else
                            {
                                entity2.GW_MobileStatistics_Id = db.GetNextIdentity_Int();
                                entity2.CreateTime             = DateTime.Now;
                                entity2.State = 1;
                                addlist.Add(entity2);
                            }
                        }
                    }


                    foreach (var x in updatelist)
                    {
                        if (x.StatisticsType == "os")
                        {
                            var entity = db.Set <T_GW_MobileStatistics>().Where(p => p.StatisticsType == x.StatisticsType && p.OSType == x.OSType).FirstOrDefault();
                            if (entity != null)
                            {
                                entity.TotalCount = x.TotalCount;
                                entity.UpdateTime = DateTime.Now;
                                db.UpdatePartial(entity, xx => new { xx.TotalCount, xx.UpdateTime });
                            }
                        }
                        else if (x.StatisticsType == "ver")
                        {
                            var entity = db.Set <T_GW_MobileStatistics>().Where(p => p.StatisticsType == x.StatisticsType && p.OSType == x.OSType && p.OSVersion == x.OSVersion).FirstOrDefault();
                            if (entity != null)
                            {
                                entity.TotalCount = x.TotalCount;
                                entity.UpdateTime = DateTime.Now;
                                db.UpdatePartial(entity, xx => new { xx.TotalCount, xx.UpdateTime });
                            }
                        }
                    }

                    db.BatchInsert(addlist);
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "手机app版本号统计", rootdir);
            }
        }
Ejemplo n.º 10
0
        public void ActiveUsersByMonth_Update()
        {
            try
            {
                using (var db = new BizDataContext())
                {
                    string currenttime = DateTime.Now.ToString("yyyy-MM");

                    string sql = string.Format(@"select t6.year_int,t6.month_int,t6.createtimestr,t6.opaccountcode,t6.ownerid,t6.createtime,t7.area_name from 
  (
    select * from 
      (
        select to_number(to_char(t4.createtime, 'yyyy')) year_int,to_number(to_char(t4.createtime, 'mm')) month_int,to_char(t4.createtime, 'yyyy-mm')createtimestr,  t4.* from
          (
            select t3.opaccountcode,t2.ownerid, t2.createtime from t_user t3 
             inner join 
             (select t1.* from 
            (select row_number() over(partition by t0.ownerid, to_char(t0.createtime, 'yyyy-mm') order by  t0.createtime desc) rownumb, t0.ownerid, t0.phone, t0.createtime from t_Gw_Loginlog t0 
            order by t0.phone, t0.createtime desc) t1 where t1.rownumb = 1
            ) t2 on (t3.state <> 9999 and t2.ownerid = t3.user_id)
          ) t4
       ) t5 where t5.createtimestr = '{0}' 
   ) t6 
   left join T_area t7 on t6.opaccountcode = t7.area_id 
   order by t6.month_int", currenttime);



                    DataTable dt    = db.ExecuteDataTable(sql);
                    var       query = dt.Rows.OfType <DataRow>()
                                      .Select(p => new
                    {
                        createtime    = Convert.ToDateTime(p["createtime"]),
                        createtimestr = p["createtimestr"].ToString(),
                        year_int      = Convert.ToInt32(p["year_int"]),
                        month_int     = Convert.ToInt32(p["month_int"]),
                        ownerid       = p["ownerid"].ToString(),
                        area_id       = p["opaccountcode"].ToString(),
                        area_name     = p["area_name"].ToString(),
                        monthval      = p["month_int"].ToString(),
                    });


                    #region 用户表用户统计
                    string sql2 = @"select a.area_id, a.area_name, u.createtime ,u.loginname 
from T_user u
left join t_area a on u.opaccountcode = a.area_id
where u.state <> 9999";

                    DataTable dt2 = db.ExecuteDataTable(sql2);

                    var queryuser = dt2.Rows.OfType <DataRow>()
                                    .Select(p => new
                    {
                        areaid     = p["area_id"].ToString(),
                        areaname   = p["area_name"].ToString(),
                        createtime = p["createtime"].ToString(),
                        loginname  = p["loginname"].ToString(),
                    });

                    var modeluser  = queryuser.ToList();
                    var queryuser2 = modeluser.GroupBy(x => new { x.areaid, x.areaname }).
                                     Select(x => new v_areauser {
                        areaid = x.Key.areaid, areaname = x.Key.areaname, mulist = x.Select(p => new v_mu {
                            createtime = Convert.ToDateTime(p.createtime)
                        }).ToList()
                    });

                    var modeluser2 = queryuser2.ToList();
                    #endregion

                    var model  = query.ToList();
                    var query2 = model.GroupBy(x => new { x.area_id, x.area_name }).Select(x => new v_activeusers
                    {
                        areaid   = x.Key.area_id,
                        areaname = x.Key.area_name,
                        users    = x.GroupBy(p => new { p.month_int, p.createtimestr }).Select(p => new v_monthusers {
                            month = p.Key.month_int, createtimestr = p.Key.createtimestr, countusers = p.Count()
                        }).ToList()
                    }
                                                                                           );


                    var model2 = query2.ToList();
                    List <v_activeusers> aulist = new List <v_activeusers>();
                    List <v_monthusers>  mulist = null;;
                    v_activeusers        au     = null;
                    v_monthusers         mu     = null;

                    foreach (var x in model2)
                    {
                        au          = new v_activeusers();
                        au.areaid   = x.areaid;
                        au.areaname = x.areaname;
                        mulist      = new List <v_monthusers>();
                        foreach (var item in x.users)
                        {
                            mu               = new v_monthusers();
                            mu.month         = item.month;
                            mu.createtimestr = item.createtimestr;
                            mu.countusers    = item.countusers;
                            mulist.Add(mu);
                        }
                        au.users = mulist;
                        aulist.Add(au);
                    }
                    ///获取用户总数


                    List <T_GW_UserStatistics> addlist        = new List <T_GW_UserStatistics>();
                    List <T_GW_UserStatistics> updatelist     = new List <T_GW_UserStatistics>();
                    T_GW_UserStatistics        userstatistics = null;
                    foreach (var item in aulist)
                    {
                        if (item.areaname == "")
                        {
                            var M = modeluser2.Where(x => x.areaname == item.areaname).FirstOrDefault().mulist;
                            foreach (var x in item.users)
                            {
                                userstatistics = new T_GW_UserStatistics();

                                userstatistics.AreaId          = 0;
                                userstatistics.AreaName        = "未填写";
                                userstatistics.YearMonth       = x.createtimestr;
                                userstatistics.MonthVal        = x.month;
                                userstatistics.ActiveUserCount = x.countusers;
                                userstatistics.UserCount       = M.Count();
                                var entity = db.Set <T_GW_UserStatistics>().Where(p => p.AreaId == 0 && p.AreaName == "未填写" && p.YearMonth == x.createtimestr).FirstOrDefault();
                                if (entity != null)
                                {
                                    entity.ActiveUserCount = userstatistics.ActiveUserCount;
                                    entity.UserCount       = userstatistics.UserCount;
                                    entity.UpdateTime      = DateTime.Now;
                                    db.UpdatePartial(entity, xx => new { xx.ActiveUserCount, xx.UserCount, xx.UpdateTime });
                                }
                                else
                                {
                                    userstatistics.GW_UserStatistics_Id = db.GetNextIdentity_Int();
                                    userstatistics.CreateTime           = DateTime.Now;
                                    addlist.Add(userstatistics);
                                }
                            }
                        }
                        else
                        {
                            var M = modeluser2.Where(x => x.areaname == item.areaname).FirstOrDefault().mulist;
                            foreach (var x in item.users)
                            {
                                userstatistics                 = new T_GW_UserStatistics();
                                userstatistics.AreaId          = item.areaid.ToInt();
                                userstatistics.AreaName        = item.areaname;
                                userstatistics.YearMonth       = x.createtimestr;
                                userstatistics.MonthVal        = x.month;
                                userstatistics.ActiveUserCount = x.countusers;
                                userstatistics.UserCount       = M.Count();

                                var entity = db.Set <T_GW_UserStatistics>().Where(p => p.AreaId == item.areaid.ToInt() && p.AreaName == item.areaname && p.YearMonth == x.createtimestr).FirstOrDefault();
                                if (entity != null)
                                {
                                    entity.ActiveUserCount = userstatistics.ActiveUserCount;
                                    entity.UserCount       = userstatistics.UserCount;
                                    entity.UpdateTime      = DateTime.Now;
                                    db.UpdatePartial(entity, xx => new { xx.ActiveUserCount, xx.UserCount, xx.UpdateTime });
                                }
                                else
                                {
                                    userstatistics.GW_UserStatistics_Id = db.GetNextIdentity_Int();
                                    userstatistics.CreateTime           = DateTime.Now;
                                    addlist.Add(userstatistics);
                                }
                            }
                        }
                    }

                    db.BatchInsert(addlist);
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "每天统计用户活跃度", rootdir);
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
        }
        /// <summary>
        /// 删除活动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                //所有活动
                Dictionary <long, SysActivity> activityDict = this.DataHelper.Set <SysActivity>()
                                                              .Where(p => p.ProcessId == this.ProcessId).ToDictionary(p => p.ActivityId);

                if (activityDict.Count == 4)
                {
                    throw new Exception("只有一个审核活动,不能删除");
                }

                //当前活动
                SysActivity a = activityDict[this.SelectedActivityId];

                //当前活动参与人
                List <SysActivityParticipant> apList = this.DataHelper.Set <SysActivityParticipant>()
                                                       .Where(p => p.ActivityId == this.SelectedActivityId).ToList();

                //此活动之后的审核活动
                List <SysActivity> nextActivityList = activityDict.Values.Where(p => (p.DisplayOrder ?? 0) > a.DisplayOrder).ToList();

                //最后一个审核活动
                SysActivity lastActivity = activityDict.Values.OrderByDescending(p => p.DisplayOrder ?? 0).FirstOrDefault();

                //结束活动(驳回)
                SysActivity endReject = activityDict.Values.FirstOrDefault(p => p.ActivityType == (int)ActivityType.End && p.ActivityName == "驳回");

                //通过指向当前活动的连接线
                SysTransition tIn_Pass = this.DataHelper.Set <SysTransition>()
                                         .Where(p => p.PostActivityId == this.SelectedActivityId &&
                                                p.Direction == (int)FlowStepDirection.True).FirstOrDefault();

                //驳回指向当前活动的连接线(集合)
                List <SysTransition> tIn_RejectList = this.DataHelper.Set <SysTransition>()
                                                      .Where(p => p.PostActivityId == this.SelectedActivityId &&
                                                             p.Direction == (int)FlowStepDirection.False).ToList();

                //从当前活动通过指向的连接线
                SysTransition tOut_Pass = this.DataHelper.Set <SysTransition>()
                                          .Where(p => p.PreActivityId == this.SelectedActivityId &&
                                                 p.Direction == (int)FlowStepDirection.True).FirstOrDefault();

                //从当前活动驳回指向的连接线
                SysTransition tOut_Reject = this.DataHelper.Set <SysTransition>()
                                            .Where(p => p.PreActivityId == this.SelectedActivityId &&
                                                   p.Direction == (int)FlowStepDirection.False).FirstOrDefault();

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        //让上一个活动通过指向当前活动通过指向的活动
                        tIn_Pass.PostActivityId = tOut_Pass.PostActivityId;
                        db.UpdatePartial(tIn_Pass, p => new { p.PostActivityId });

                        //让其它驳回指向当前活动的活动驳回指向结束活动(驳回)
                        foreach (var tIn_Reject in tIn_RejectList)
                        {
                            tIn_Reject.PostActivityId = endReject.ActivityId;
                            db.UpdatePartial(tIn_Reject, p => new { p.PostActivityId });
                        }

                        //删除当前活动及连接线
                        db.Delete(a);
                        db.Delete(tOut_Pass);
                        if (tOut_Reject != null)
                        {
                            db.Delete(tOut_Reject);
                        }

                        //删除当前活动参与人
                        foreach (var ap in apList)
                        {
                            db.Delete(ap);
                        }

                        //将后面的活动的顺序提前1位
                        foreach (var na in nextActivityList)
                        {
                            na.DisplayOrder--;
                            na.TopPos -= 130;
                            db.UpdatePartial(na, p => new { p.DisplayOrder, p.TopPos });
                        }
                    }
                    ts.Complete();
                }

                //选择最后一个活动
                SelectActivity(lastActivity);

                this.EnableButton();
            }
            catch (Exception ex)
            {
                this.AjaxAlertAndEnableButton(ex);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// 保存当前活动配置
        /// </summary>
        protected void btnSave_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 a = activityDict[this.SelectedActivityId];

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        a.ActivityName = this.txtActivityName.Text.Trim();
                        db.UpdatePartial(a, p => new { p.ActivityName });

                        #region 处理驳回方式
                        //找到当前活动驳回指向的连接线
                        SysTransition t = this.DataHelper.Set <SysTransition>()
                                          .Where(p => p.PreActivityId == this.SelectedActivityId && p.Direction == (int)FlowStepDirection.False).FirstOrDefault();
                        FormProcessActivityRejectType rejectType = (FormProcessActivityRejectType)this.ccRejectType.SelectedValue.ToInt();
                        switch (rejectType)
                        {
                        case FormProcessActivityRejectType.SelectActivityWhenRunning:
                        {
                            if (t != null)
                            {
                                db.Delete(t);
                            }
                            break;
                        }

                        case FormProcessActivityRejectType.SelectActivity:
                        {
                            SysActivity target = activityDict[this.ccRejectTargetActivity.SelectedValue.ToLong()];
                            if (t == null)
                            {
                                ConnectActivity(db, a, target, FlowStepDirection.False);
                            }
                            else if (t.PostActivityId != target.ActivityId)
                            {
                                t.PostActivityId = target.ActivityId;
                                db.UpdatePartial(t, p => new { p.PostActivityId });
                            }
                            break;
                        }

                        case FormProcessActivityRejectType.EndActivity:
                        {
                            SysActivity end = activityDict.Values.FirstOrDefault(p => p.ActivityType == (int)ActivityType.End && p.ActivityName == "驳回");
                            if (t == null)
                            {
                                ConnectActivity(db, a, end, FlowStepDirection.False);
                            }
                            else if (t.PostActivityId != end.ActivityId)
                            {
                                t.PostActivityId = end.ActivityId;
                                db.UpdatePartial(t, p => new { p.PostActivityId });
                            }
                            break;
                        }

                        default: break;
                        }
                        #endregion
                    }
                    ts.Complete();
                }

                //重新选择一下
                SelectActivity(a);

                this.AjaxAlertAndEnableButton("保存成功");
            }
            catch (Exception ex)
            {
                this.AjaxAlertAndEnableButton(ex);
            }
        }