public static async Task <WfiItem> Create( long p_atviID, DateTime p_date, bool p_isRole, long p_receiver, string p_note, bool p_isBack) { WfiItem item = new WfiItem( ID: await AtCm.NewID(), AtviID: p_atviID, AssignKind: (p_isBack ? WfiItemAssignKind.回退 : WfiItemAssignKind.普通指派), Status: WfiItemStatus.活动, IsAccept: false, Sender: Kit.UserName, Stime: p_date, Ctime: p_date, Mtime: p_date, Note: p_note, Dispidx: await AtCm.NewSeq("sq_wfi_item")); if (p_isRole) { item.RoleID = p_receiver; } else { item.UserID = p_receiver; } return(item); }
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); }
async void AddMenu(bool p_isGroup) { var sel = _tv.Selected <Menu>(); Menu m = new Menu( ID: await AtCm.NewID(), Name: p_isGroup ? "新组" : "新菜单", Icon: p_isGroup ? "文件夹" : "文件", IsGroup: p_isGroup, ParentID: sel.ID > 0 ? (long?)sel.ID : null, Dispidx: await AtCm.NewSeq("sq_menu"), Ctime: Kit.Now, Mtime: Kit.Now); m.AddCell("parentname", sel.Name); _fv.Data = m; }
public static async Task <WfdPrc> New() { var prc = new WfdPrc( ID: await AtCm.NewID(), Name: "新流程", IsLocked: true, Dispidx: await AtCm.NewSeq("sq_wfd_prc"), Ctime: Kit.Now); prc.Atvs = Table <WfdAtv> .Create(); prc.Trss = Table <WfdTrs> .Create(); prc.AtvRoles = Table <WfdAtvrole> .Create(); prc.AttachEvent(); return(prc); }
async void OnAdd(object sender, Mi e) { string cate = ""; var op = _fv.Data.To <Option>(); if (op != null) { cate = op.Category; } else if (_lvCate.SelectedRow != null) { cate = _lvCate.SelectedRow.Str(0); } _fv.Data = new Option( Name: "新选项", Category: cate, Dispidx: await AtCm.NewSeq("sq_option")); }
/// <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("发送失败!"); } }
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("追回失败"); } }