Example #1
0
        /// <summary>
        /// 保存当前工作项置完成状态
        /// </summary>
        /// <param name="p_isFinished"></param>
        /// <returns></returns>
        async Task SaveWorkItem(bool p_isFinished)
        {
            if (p_isFinished)
            {
                _info.AtvInst.Finished();
            }
            _info.WorkItem.Finished();

            List <object> ls = new List <object>();

            if (_info.AtvInst.IsChanged)
            {
                ls.Add(_info.AtvInst);
            }
            ls.Add(_info.WorkItem);

            if (await AtCm.BatchSave(ls, false))
            {
                Kit.Msg(p_isFinished ? "任务结束" : "当前工作项完成");
                _info.CloseWin();
            }
            else
            {
                Kit.Warn("工作项保存失败");
            }
        }
Example #2
0
        public async Task <bool> Save()
        {
            // 先保存表单数据
            if (!await _info.FormWin.Save())
            {
                return(false);
            }

            // 标题
            string name = _info.FormWin.GetPrcName();

            if (name != _info.PrcInst.Name)
            {
                _info.PrcInst.Name  = name;
                _info.FormWin.Title = name;
            }

            bool suc = true;

            if (_info.PrcInst.IsAdded)
            {
                DateTime time = Kit.Now;
                _info.PrcInst.Ctime   = time;
                _info.PrcInst.Mtime   = time;
                _info.PrcInst.Dispidx = await AtCm.NewSeq("sq_wfi_prc");

                _info.AtvInst.Ctime = time;
                _info.AtvInst.Mtime = time;

                _info.WorkItem.AcceptTime = time;
                _info.WorkItem.Dispidx    = await AtCm.NewSeq("sq_wfi_item");

                _info.WorkItem.Ctime = time;
                _info.WorkItem.Mtime = time;
                _info.WorkItem.Stime = time;
            }

            List <object> ls = new List <object>();

            if (_info.PrcInst.IsAdded || _info.PrcInst.IsChanged)
            {
                ls.Add(_info.PrcInst);
            }
            if (_info.AtvInst.IsAdded || _info.AtvInst.IsChanged)
            {
                ls.Add(_info.AtvInst);
            }
            if (_info.WorkItem.IsAdded || _info.WorkItem.IsChanged)
            {
                ls.Add(_info.WorkItem);
            }

            if (ls.Count > 0)
            {
                suc = await AtCm.BatchSave(ls, false);
            }
            return(suc);
        }
Example #3
0
 public Task<bool> MoveFiles(IEnumerable<Row> p_files, long p_folderID)
 {
     var ls = new List<Pubfile>();
     foreach (var row in p_files)
     {
         var pf = new Pubfile(ID: row.ID);
         pf.IsAdded = false;
         pf["ParentID"] = p_folderID;
         ls.Add(pf);
     }
     return AtCm.BatchSave(ls, false);
 }
Example #4
0
        async void OnAddRole(object sender, Mi e)
        {
            string         prvID = _lvPrv.SelectedItem.To <Prv>().ID;
            SelectRolesDlg dlg   = new SelectRolesDlg();

            if (await dlg.Show(RoleRelations.Prv, prvID, e))
            {
                List <RolePrv> ls = new List <RolePrv>();
                foreach (var row in dlg.SelectedItems.OfType <Row>())
                {
                    ls.Add(new RolePrv(row.ID, prvID));
                }
                if (ls.Count > 0 && await AtCm.BatchSave(ls))
                {
                    RefreshRelation(prvID);
                    await AtCm.DeleteDataVer(ls.Select(rm => rm.RoleID).ToList(), "privilege");
                }
            }
        }
Example #5
0
        async void OnAddPrv(object sender, Mi e)
        {
            long roleID = _lvRole.SelectedRow.ID;
            var  dlg    = new SelectRolePrvDlg();

            if (await dlg.Show(roleID, e))
            {
                List <RolePrv> ls = new List <RolePrv>();
                foreach (var row in dlg.SelectedItems.OfType <Row>())
                {
                    ls.Add(new RolePrv(roleID, row.Str("id")));
                }
                if (ls.Count > 0 && await AtCm.BatchSave(ls))
                {
                    _lvPrv.Data = await AtCm.Query("角色-关联的权限", new { roleid = roleID });

                    await AtCm.DeleteDataVer(ls.Select(rm => rm.RoleID).ToList(), "privilege");
                }
            }
        }
Example #6
0
        async void OnAddMenu(object sender, Mi e)
        {
            long roleID = _lvRole.SelectedRow.ID;
            var  dlg    = new SelectRoleMenuDlg();

            if (await dlg.Show(roleID, e))
            {
                List <RoleMenu> ls = new List <RoleMenu>();
                foreach (var row in dlg.SelectedItems.OfType <Row>())
                {
                    ls.Add(new RoleMenu(roleID, row.ID));
                }
                if (ls.Count > 0 && await AtCm.BatchSave(ls))
                {
                    _lvMenu.Data = await AtCm.Query("角色-关联的菜单", new { roleid = roleID });

                    await AtCm.DeleteDataVer(ls.Select(rm => rm.RoleID).ToList(), "menu");
                }
            }
        }
Example #7
0
        async void OnAddRole(object sender, Mi e)
        {
            SelectRolesDlg dlg    = new SelectRolesDlg();
            long           menuID = _fv.Data.To <Menu>().ID;

            if (await dlg.Show(RoleRelations.Menu, menuID.ToString(), e))
            {
                List <RoleMenu> ls = new List <RoleMenu>();
                foreach (var row in dlg.SelectedItems.OfType <Row>())
                {
                    ls.Add(new RoleMenu(row.ID, menuID));
                }
                if (ls.Count > 0 && await AtCm.BatchSave(ls))
                {
                    _lvRole.Data = await AtCm.Query <RoleMenu>("菜单-关联的角色", new { menuid = menuID });

                    await AtCm.DeleteDataVer(ls.Select(rm => rm.RoleID).ToList(), "menu");
                }
            }
        }
Example #8
0
        async void Exchange(Option p_src, Option p_tgt)
        {
            var tbl = Table <Option> .Create();

            var save = (Option)tbl.AddRow(new { Name = p_src.Name, Category = p_src.Category });

            save.AcceptChanges();
            save.Dispidx = p_tgt.Dispidx;

            save = (Option)tbl.AddRow(new { Name = p_tgt.Name, Category = p_tgt.Category });
            save.AcceptChanges();
            save.Dispidx = p_src.Dispidx;

            if (await AtCm.BatchSave(tbl))
            {
                _lv.Data = await AtCm.Query <Option>("选项-分类选项", new { Category = p_src.Category });

                AtCm.PromptForUpdateModel();
            }
        }
Example #9
0
        /// <summary>
        /// 执行发送
        /// </summary>
        /// <param name="p_manualSend">是否手动选择接收者</param>
        async void DoSend(bool p_manualSend)
        {
            #region 后续活动
            // 生成后续活动的活动实例、工作项、迁移实例,一个或多个
            var tblAtvs = Table <WfiAtv> .Create();

            var tblItems = Table <WfiItem> .Create();

            var tblTrs = Table <WfiTrs> .Create();

            DateTime time = Kit.Now;

            if (_info.NextRecvs.FinishedAtv != null &&
                (!p_manualSend || _info.NextRecvs.FinishedAtv.IsSelected))
            {
                // 完成
                _info.PrcInst.Status = WfiAtvStatus.结束;
                _info.PrcInst.Mtime  = time;
            }
            else
            {
                // 普通活动
                foreach (AtvRecv ar in _info.NextRecvs.Atvs)
                {
                    // 手动无选择时
                    if (p_manualSend &&
                        (ar.SelectedRecvs == null || ar.SelectedRecvs.Count == 0))
                    {
                        continue;
                    }

                    var atvInst = new WfiAtv(
                        ID: await AtCm.NewID(),
                        PrciID: _info.PrcInst.ID,
                        AtvdID: ar.Def.ID,
                        Status: WfiAtvStatus.活动,
                        Ctime: time,
                        Mtime: time);
                    tblAtvs.Add(atvInst);

                    if (p_manualSend)
                    {
                        // 手动发送,已选择项可能为用户或角色
                        atvInst.InstCount = ar.SelectedRecvs.Count;
                        foreach (var recvID in ar.SelectedRecvs)
                        {
                            var wi = await WfiItem.Create(atvInst.ID, time, ar.IsRole, recvID, ar.Note, false);

                            tblItems.Add(wi);
                        }
                    }
                    else
                    {
                        // 自动发送,按角色
                        atvInst.InstCount = ar.Recvs.Count;
                        foreach (var row in ar.Recvs)
                        {
                            var wi = await WfiItem.Create(atvInst.ID, time, ar.IsRole, row.ID, ar.Note, false);

                            tblItems.Add(wi);
                        }
                    }

                    // 增加迁移实例
                    var trs = await _info.CreateAtvTrs(ar.Def.ID, atvInst.ID, time, false);

                    tblTrs.Add(trs);
                }

                // 同步活动
                var syncAtv = _info.NextRecvs.SyncAtv;
                if (syncAtv != null &&
                    (!p_manualSend || (syncAtv.SelectedRecvs != null && syncAtv.SelectedRecvs.Count > 0)))
                {
                    // 同步实例
                    var syncInst = new WfiAtv(
                        ID: await AtCm.NewID(),
                        PrciID: _info.PrcInst.ID,
                        AtvdID: syncAtv.SyncDef.ID,
                        Status: WfiAtvStatus.步,
                        InstCount: 1,
                        Ctime: time,
                        Mtime: time);
                    tblAtvs.Add(syncInst);

                    // 同步工作项
                    WfiItem item = new WfiItem(
                        ID: await AtCm.NewID(),
                        AtviID: syncInst.ID,
                        AssignKind: WfiItemAssignKind.普通指派,
                        Status: WfiItemStatus.步,
                        IsAccept: false,
                        UserID: Kit.UserID,
                        Sender: Kit.UserName,
                        Stime: time,
                        Ctime: time,
                        Mtime: time,
                        Dispidx: await AtCm.NewSeq("sq_wfi_item"));
                    tblItems.Add(item);

                    // 同步迁移实例
                    Dict dt = new Dict();
                    dt["prcid"]      = _info.PrcInst.PrcdID;
                    dt["SrcAtvID"]   = _info.AtvInst.AtvdID;
                    dt["TgtAtvID"]   = syncAtv.SyncDef.ID;
                    dt["IsRollback"] = false;
                    long trsdid = await AtCm.GetScalar <long>("流程-迁移模板ID", dt);

                    var trs = new WfiTrs(
                        ID: await AtCm.NewID(),
                        TrsdID: trsdid,
                        SrcAtviID: _info.AtvInst.ID,
                        TgtAtviID: syncInst.ID,
                        IsRollback: false,
                        Ctime: time);
                    tblTrs.Add(trs);

                    // 同步活动的后续活动实例
                    var nextInst = new WfiAtv(
                        ID: await AtCm.NewID(),
                        PrciID: _info.PrcInst.ID,
                        AtvdID: syncAtv.Def.ID,
                        Status: WfiAtvStatus.活动,
                        Ctime: time,
                        Mtime: time);
                    tblAtvs.Add(nextInst);

                    if (p_manualSend)
                    {
                        // 手动发送,已选择项可能为用户或角色
                        nextInst.InstCount = syncAtv.SelectedRecvs.Count;
                        foreach (var recvID in syncAtv.SelectedRecvs)
                        {
                            var wi = await WfiItem.Create(nextInst.ID, time, syncAtv.IsRole, recvID, "", false);

                            tblItems.Add(wi);
                        }
                    }
                    else
                    {
                        // 自动发送,按角色
                        nextInst.InstCount = syncAtv.Recvs.Count;
                        foreach (var row in syncAtv.Recvs)
                        {
                            var wi = await WfiItem.Create(nextInst.ID, time, syncAtv.IsRole, row.ID, "", false);

                            tblItems.Add(wi);
                        }
                    }

                    // 增加迁移实例
                    dt               = new Dict();
                    dt["prcid"]      = _info.PrcInst.PrcdID;
                    dt["SrcAtvID"]   = syncAtv.SyncDef.ID;
                    dt["TgtAtvID"]   = syncAtv.Def.ID;
                    dt["IsRollback"] = false;
                    trsdid           = await AtCm.GetScalar <long>("流程-迁移模板ID", dt);

                    trs = new WfiTrs(
                        ID: await AtCm.NewID(),
                        TrsdID: trsdid,
                        SrcAtviID: syncInst.ID,
                        TgtAtviID: nextInst.ID,
                        IsRollback: false,
                        Ctime: time);
                    tblTrs.Add(trs);
                }
            }

            // 发送是否有效
            // 1. 只有'完成'时有效
            // 2. 至少含有一个活动实例时有效
            if (tblAtvs.Count == 0 && _info.PrcInst.Status != WfiAtvStatus.结束)
            {
                Kit.Msg("所有后续活动均无接收者,发送失败!");
                return;
            }
            #endregion

            #region 整理待保存数据
            List <object> data = new List <object>();
            if (_info.PrcInst.IsChanged)
            {
                data.Add(_info.PrcInst);
            }

            _info.AtvInst.Finished();
            data.Add(_info.AtvInst);

            _info.WorkItem.Finished();
            data.Add(_info.WorkItem);

            if (tblAtvs.Count > 0)
            {
                data.Add(tblAtvs);
                data.Add(tblItems);
                data.Add(tblTrs);
            }
            #endregion

            if (await AtCm.BatchSave(data, false))
            {
                Kit.Msg("发送成功!");
                _info.CloseWin();
                // 推送客户端提醒
            }
            else
            {
                // 避免保存失败后,再次点击发送时和保存表单一起被保存,造成状态错误!
                _info.PrcInst.RejectChanges();
                _info.AtvInst.RejectChanges();
                _info.WorkItem.RejectChanges();
                Kit.Warn("发送失败!");
            }
        }
Example #10
0
        async void OnRetrieve(object sender, Mi e)
        {
            Row row    = e.Row;
            var status = (WfiPrcStatus)row.Int("status");

            if (status != WfiPrcStatus.活动)
            {
                Kit.Warn($"该任务已{status},无法追回");
                return;
            }
            if (row.Int("reCount") > 0)
            {
                Kit.Warn("含回退,无法追回");
                return;
            }

            var tbl = await AtCm.Query("流程-后续活动工作项", new { atvdid = row.Long("atvdid"), prciid = row.Long("prciid") });

            if (tbl.Count == 0)
            {
                Kit.Warn("无后续活动,无法追回");
                return;
            }

            HashSet <long> ls = new HashSet <long>();

            foreach (var r in tbl)
            {
                var itemState = (WfiItemStatus)r.Int("Status");
                if (itemState == WfiItemStatus.步)
                {
                    Kit.Warn("后续活动包含同步,无法追回");
                    return;
                }

                if (itemState != WfiItemStatus.活动 ||
                    r.Bool("IsAccept"))
                {
                    Kit.Warn("已签收无法追回!");
                    return;
                }
                ls.Add(r.Long("atviid"));
            }

            // 更新当前实例状态为活动
            DateTime time    = Kit.Now;
            WfiAtv   curAtvi = await AtCm.GetByID <WfiAtv>(row.Long("atviid"));

            curAtvi.Status     = WfiAtvStatus.活动;
            curAtvi.InstCount += 1;
            curAtvi.Mtime      = time;

            // 根据当前工作项创建新工作项并更改指派方式
            var curItem = await AtCm.GetByID <WfiItem>(row.Long("itemid"));

            var newItem = new WfiItem(
                ID: await AtCm.NewID(),
                AtviID: curItem.AtviID,
                Status: WfiItemStatus.活动,
                AssignKind: WfiItemAssignKind.追回,
                Sender: curItem.Sender,
                Stime: curItem.Stime,
                IsAccept: false,
                RoleID: curItem.RoleID,
                UserID: curItem.UserID,
                Note: curItem.Note,
                Dispidx: await AtCm.NewSeq("sq_wfi_item"),
                Ctime: time,
                Mtime: time);

            // 删除已发送的后续活动实例,关联删除工作项及迁移实例
            Table <WfiAtv> nextAtvs = new Table <WfiAtv>();

            nextAtvs.StartRecordDelRows();
            foreach (var id in ls)
            {
                nextAtvs.DeletedRows.Add(new WfiAtv(id));
            }

            // 一个事务批量保存
            List <object> data = new List <object>();

            data.Add(nextAtvs);
            data.Add(curAtvi);
            data.Add(newItem);
            bool suc = await AtCm.BatchSave(data, false);

            if (suc)
            {
                Kit.Msg("追回成功");
                OnSearch(null, null);
            }
            else
            {
                Kit.Warn("追回失败");
            }
        }
Example #11
0
        async Task Rollback()
        {
            // 活动执行者多于一人时,不允许进行回退
            if (_info.AtvInst.InstCount > 1)
            {
                Kit.Msg("该活动执行者多于一人,不允许回退!");
                return;
            }

            // 获得前一活动实例
            var pre = await _info.AtvInst.GetRollbackAtv();

            if (pre == null)
            {
                Kit.Msg("该活动不允许回退!");
                return;
            }

            if (!await Kit.Confirm("确认要回退吗?"))
            {
                return;
            }

            DateTime time       = Kit.Now;
            var      newAtvInst = new WfiAtv(
                ID: await AtCm.NewID(),
                PrciID: _info.PrcInst.ID,
                AtvdID: pre.AtvdID,
                Status: WfiAtvStatus.活动,
                InstCount: 1,
                Ctime: time,
                Mtime: time);

            // 创建迁移实例
            var newTrs = await _info.CreateAtvTrs(pre.AtvdID, newAtvInst.ID, time, true);

            // 当前活动完成状态
            _info.AtvInst.Finished();

            // 当前工作项置成完成状态
            _info.WorkItem.Finished();

            Dict dict = new Dict();

            dict["name"] = await GetSender();

            long userId = await AtCm.GetScalar <long>("流程-获取用户ID", dict);

            var newItem = await WfiItem.Create(newAtvInst.ID, time, false, userId, null, true);

            List <object> ls = new List <object>();

            if (_info.AtvInst.IsChanged)
            {
                ls.Add(_info.AtvInst);
            }
            ls.Add(_info.WorkItem);
            ls.Add(newAtvInst);
            ls.Add(newItem);
            ls.Add(newTrs);

            if (await AtCm.BatchSave(ls, false))
            {
                Kit.Msg("回退成功!");
                _info.CloseWin();
            }
            else
            {
                Kit.Msg("回退失败!");
            }
        }