public JsonResult Save() { IDictionary <string, object> data = Request.Form.ToDictionary(); string key = string.Empty; string pageId = Request.QueryString[NamingCenter.PARAM_PAGE_ID]; string ctrlId = Request.QueryString[NamingCenter.PARAM_CTRL_ID]; string formViewMode = Request.Form[NamingCenter.PARAM_FORM_VIEW_MODE]; var page = PageBuilder.BuildPage(pageId); if (page == null) { throw new FoxOneException("Page_Not_Found"); } var form = page.FindControl(ctrlId) as Form; if (form == null) { throw new FoxOneException("Ctrl_Not_Found"); } var ds = form.FormService as IFormService; int effectCount = 0; WorkflowHelper helper = new WorkflowHelper(Sec.User); if (formViewMode.Equals(FormMode.Edit.ToString(), StringComparison.OrdinalIgnoreCase)) { string instanceId = Request.Form[INST_ID]; int itemId = Request.Form[TASK_ID].ConvertTo <int>(); helper.OpenWorkflow(instanceId, itemId); key = helper.FlowInstance.DataLocator; effectCount = ds.Update(key, data); helper.UpdateInstance(Env.Parse(helper.FlowInstance.Application.InstanceTitleTemplate), key, 0, 0); return(Json(new { Insert = false, InstanceId = instanceId, ItemId = itemId, DataLocator = key, ApplicationId = helper.FlowInstance.ApplicationId })); } else { string applicationId = Request.Form[APP_ID]; key = Guid.NewGuid().ToString(); data["Id"] = key; effectCount = ds.Insert(data); IWorkflowApplication app = DBContext <IWorkflowApplication> .Instance.Get(applicationId); helper.StartWorkflow(applicationId, Env.Parse(app.InstanceTitleTemplate), key, 0, 0); return(Json(new { Insert = true, InstanceId = helper.FlowInstance.Id, ItemId = 1, DataLocator = key, ApplicationId = applicationId })); } }
/// <summary> /// Initializes the specified application. /// </summary> /// <typeparam name="TInput">The type of the input.</typeparam> /// <param name="application">The application.</param> /// <param name="workflowDefinition">The workflow definition.</param> /// <param name="inputs">The inputs.</param> public static void Initialize <TInput>(this IWorkflowApplication application, Activity workflowDefinition, TInput inputs) where TInput : class { application.Initialize(workflowDefinition, inputs.ToDict()); }
public ActionResult Index() { Form form = null; var appCode = Request.QueryString[APP_ID]; string title = string.Empty; Page page = null; string formType = string.Empty; var relatePages = new List <PageRelateEntity>(); IWorkflowApplication app = null; bool canDelete = false; if (appCode.IsNotNullOrEmpty()) { app = DBContext <IWorkflowApplication> .Instance.Get(appCode); formType = app.FormType; page = PageBuilder.BuildPage(app.FormType); form = page.Controls.FirstOrDefault(o => o is Form) as Form; form.FormMode = FormMode.Insert; title = app.Name; } else { var instanceId = Request.QueryString[INST_ID]; int itemId = Request.QueryString[TASK_ID].ConvertTo <int>(); var helper = new WorkflowHelper(Sec.User); helper.OpenWorkflow(instanceId, itemId); if (helper.CurrentItem.Status >= WorkItemStatus.Finished) { throw new FoxOneException("当前工作项已完成!"); } if (!helper.CurrentItem.PartUserId.Equals(Sec.User.Id, StringComparison.OrdinalIgnoreCase) && !Sec.IsSuperAdmin) { throw new FoxOneException("您没有处理该审批步骤的权限!"); } canDelete = helper.CurrentItem.PartUserId.Equals(helper.FlowInstance.CreatorId, StringComparison.OrdinalIgnoreCase); helper.SetReadTime(); formType = helper.FlowInstance.Application.FormType; app = helper.FlowInstance.Application; page = PageBuilder.BuildPage(formType); form = page.Controls.FirstOrDefault(o => o is Form) as Form; form.Key = helper.FlowInstance.DataLocator; InsertTable(helper); title = string.Format("{0} - {1}", helper.FlowInstance.InstanceName, helper.CurrentItem.Alias); var tempRelate = DBContext <PageRelateEntity> .Instance.Where(o => o.PageId.Equals(formType, StringComparison.OrdinalIgnoreCase)); if (!tempRelate.IsNullOrEmpty()) { foreach (var item in tempRelate) { relatePages.Add(new PageRelateEntity() { Id = item.Id, PageId = item.PageId, RelateUrl = Env.Parse(item.RelateUrl).Replace("KEY", form.Key), RentId = item.RentId, TabName = item.TabName, TabRank = item.TabRank }); } } if (app.NeedAttachement) { relatePages.Add(new PageRelateEntity() { Id = "AttachmentInfo", RelateUrl = "/Attachment/Index/" + form.Key, TabName = "附件信息", TabRank = 1000 }); } } form.AppendQueryString = true; form.PostUrl = "/Workflow/Save"; ViewData["Tab"] = relatePages; ViewData["Form"] = page.Children.OrderBy(o => o.Rank).ToList(); ViewData["Title"] = title; ViewData["DefinitionId"] = app.WorkflowId; ViewData["CanDelete"] = canDelete; return(View()); }