public ActionResult Leave(LeaveViewModel model)
        {
            string result = "no";
            //Guid instanceGuid = WorkFlowHelper.Run(new Leave(), new Dictionary<string, object>()
            //{
            //    {"R2",model.Reason},
            //    {"D2",model.Days}
            //});
            string     title    = model.LeaveTitle == "1" ? "事假" : model.LeaveTitle == "2" ? "病假" : "休假";
            WFInstance instance = new WFInstance()
            {
                InstanceTitle = "请假--" + title,
                Details       = string.Format("事由:{0},天数:{1}天。", model.Reason, model.Days),
                InstanceGuid  = "",
                InstanceState = (short)InstanceState.Approving,
                Remark        = string.IsNullOrWhiteSpace(model.Remark) ? string.Format("{0}至{1}", DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(model.Days).ToString("yyyy-MM-dd")) : model.Remark,
                SubBy         = UserLogin.UserId,
                SubTime       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            instance.WFStep.Add(new WFStep()
            {
                NextId  = model.NextId,
                SubBy   = UserLogin.UserId,
                SubTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            });
            if (WFInstanceBll.Add(instance))
            {
                result = "ok";
            }
            return(Content(result));
        }
Exemple #2
0
        private void btnProcess_Click(object sender, RoutedEventArgs e)
        {
            if (this.dgFlow.SelectedItem != null)
            {
                WFInstance wfInstance = this.dgFlow.SelectedItem as WFInstance;
                DateTime   T1         = EAS.Application.Instance.Time;

                //回调函数。
                WfAddInHelper.WorkflowInstanceCallBack callback = () =>
                {
                    IList <WFInstance> xList = this.dgFlow.ItemsSource as IList <WFInstance>;

                    if (xList.Contains(wfInstance))
                    {
                        DataPortal <WFInstance> dataPortal = new DataPortal <WFInstance>();
                        dataPortal.BeginRead(wfInstance).Completed += (s1, e1) =>
                        {
                            QueryTask <WFInstance> task = s1 as QueryTask <WFInstance>;
                            string[] sv = task.DataEntity.Handlers.Split(',');
                            if (sv.Where(p => p == ContextHelper.Account.LoginID).Count() > 0)
                            {
                                xList.Remove(wfInstance);
                                this.dgFlow.ItemsSource = null;
                                this.dgFlow.ItemsSource = xList;
                            }
                        };
                    }
                };

                //处理流程
                WfAddInHelper.LoadWorkflowInstance(wfInstance, true, callback);
            }
        }
        public ActionResult Expense(ExpenseViewModel model)
        {
            string result = "no";
            //Guid instanceGuid = WorkFlowHelper.Run(new Expense(), new Dictionary<string, object>()
            //{
            //    {"R2",model.Reason},
            //    {"M2",model.Money}
            //});
            WFInstance instance = new WFInstance()
            {
                InstanceTitle = "报销--" + model.ExpenseTitle,
                Details       = string.Format("事由:{0},金额:{1}元。", model.Reason, model.Money),
                InstanceGuid  = "",
                InstanceState = (short)InstanceState.Approving,
                Remark        = model.Remark,
                SubBy         = UserLogin.UserId,
                SubTime       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            instance.WFStep.Add(new WFStep()
            {
                NextId  = model.NextId,
                SubBy   = UserLogin.UserId,
                SubTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            });
            if (WFInstanceBll.Add(instance))
            {
                result = "ok";
            }
            return(Content(result));
        }
Exemple #4
0
 private void btnExecute_Click(object sender, RoutedEventArgs e)
 {
     if (this.dgFlow.SelectedItem != null)
     {
         WFInstance      wfInstance = this.dgFlow.SelectedItem as WFInstance;
         WfExecuteWindow window     = new WfExecuteWindow();
         window.InstanceID = wfInstance.ID;
         window.Show();
     }
 }
Exemple #5
0
 private void btnTrack_Click(object sender, RoutedEventArgs e)
 {
     if (this.dgFlow.SelectedItem != null)
     {
         WFInstance    wfInstance = this.dgFlow.SelectedItem as WFInstance;
         WfTrackWindow wfTrack    = new WfTrackWindow();
         wfTrack.WFInstance = wfInstance;
         wfTrack.Show();
     }
 }
Exemple #6
0
 public static void preSet_Workflow(WFInstance obj, PropertyPreSetterEventArgs <Zetbox.Basic.Workflow.WFDefinition> e)
 {
     if (e.OldValue == null)
     {
         return;                     // OK
     }
     if (e.OldValue != e.NewValue)
     {
         throw new NotSupportedException("Changing the workflow is not supported");
     }
 }
Exemple #7
0
 public static void Start(WFInstance obj, Zetbox.Basic.Workflow.WFDefinition workflow)
 {
     if (workflow != null)
     {
         Logging.Log.InfoFormat("Starting workflow {0}", workflow.Name);
         obj.Workflow = workflow;
         foreach (var stateDef in workflow.StateDefinitions.Where(s => s.IsStartState))
         {
             StateActions.CreateState(obj, stateDef);
         }
         obj.Recalculate("IsActive");
     }
 }
Exemple #8
0
        /// <summary>
        /// 加载流程。
        /// </summary>
        /// <param name="wfDefine"></param>
        public static void LoadWorkflowInstance(WFInstance wfInstance, bool isEnabled, WorkflowInstanceCallBack callBack)
        {
            DataPortal <WFDefine> dataPortal = new DataPortal <WFDefine>();

            WFDefine wfDefine = new WFDefine();

            wfDefine.FlowID = wfInstance.FlowID;

            dataPortal.BeginRead(wfDefine).Completed += (s, e)
                                                        =>
            {
                QueryTask <WFDefine> task = s as QueryTask <WFDefine>;
                if (task.Error != null)
                {
                    MessageBox.Show(string.Format("读取流程定义错误:" + task.Error.Message, wfDefine.Module), "提示", MessageBoxButton.OK);
                }
                else      //
                {
                    wfDefine = task.DataEntity;

                    System.Type T = EAS.Objects.ClassProvider.GetType(wfDefine.SilverMType);

                    if (T == null)
                    {
                        MessageBox.Show(string.Format("没有找到名称为\"{0}\"的功能模块", wfDefine.Module), "提示", MessageBoxButton.OK);
                        return;
                    }

                    if (EAS.Application.Instance != null)
                    {
                        if (typeof(Control).IsAssignableFrom(T))
                        {
                            object           wfAddIn        = System.Activator.CreateInstance(T);
                            WfInstanceWindow wfInstanceForm = new WfInstanceWindow(wfAddIn, isEnabled, new Guid(wfInstance.ID));
                            wfInstanceForm.Closed += (s2, e2) => { callBack(); };
                            wfInstanceForm.Show();
                        }
                        else if (typeof(ChildWindow).IsAssignableFrom(T))
                        {
                            ChildWindow wfAddIn = System.Activator.CreateInstance(T) as ChildWindow;
                            wfAddIn.Closed += (s2, e2) => { callBack(); };
                            WfAddInHelper.LoadWorkflowInstance(wfAddIn, isEnabled, new Guid(wfInstance.ID));
                        }
                        else
                        {
                            WfAddInHelper.LoadWorkflowInstance(System.Activator.CreateInstance(T), isEnabled, new Guid(wfInstance.ID));
                        }
                    }
                }
            };
        }
        internal static State CreateState(WFInstance instance, StateDefinition def)
        {
            Logging.Log.InfoFormat("Creating WorkflowState [{0}].{1}", instance, def.Name);

            var ctx   = instance.Context;
            var state = ctx.Create <State>();

            state.Instance        = instance;
            state.StateDefinition = def;
            foreach (var action in def.Actions.Where(a => a.IsOnEnterAction))
            {
                action.Action.Execute(action, state);
            }
            return(state);
        }
Exemple #10
0
        public ActionResult ReApply(ReApplyViewModel model)
        {
            string     result   = "no";
            WFInstance instance = WFInstanceBll.GetById(model.InstanceId);

            if (instance.InstanceTitle.StartsWith("报销"))
            {
                //WorkFlowHelper.Resume(new Expense(), Guid.Parse(instance.InstanceGuid), "BackInput", new ExpenseModel()
                //{
                //    Reason = model.Reason,
                //    Money = model.Num
                //});
                instance.InstanceTitle = model.InstanceTitle.StartsWith("报销--") ? model.InstanceTitle : "报销--" + model.InstanceTitle;
                instance.Details       = string.Format("事由:{0},金额:{1}元。", model.Reason, model.Num);
            }
            else if (instance.InstanceTitle.StartsWith("请假"))
            {
                //WorkFlowHelper.Resume(new Leave(), Guid.Parse(instance.InstanceGuid), "ReInput", new LeaveModel()
                //{
                //    Reason = model.Reason,
                //    Days = model.Num
                //});
                string title = model.InstanceTitle == "1" ? "事假" : model.InstanceTitle == "2" ? "病假" : "休假";
                instance.InstanceTitle = "请假--" + title;
                instance.Details       = string.Format("事由:{0},天数:{1}天。", model.Reason, model.Num);
            }
            else
            {
                return(Content("no"));
            }
            instance.InstanceState = (int)InstanceState.Approving;
            instance.RejectMsg     = "";
            instance.Remark        = model.Remark;
            instance.WFStep.Add(new WFStep()
            {
                IsEnd   = 0,
                NextId  = model.NextId,
                SubBy   = UserLogin.UserId,
                SubTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            });
            if (WFInstanceBll.Edit(instance))
            {
                result = "ok";
            }
            return(Content(result));
        }
Exemple #11
0
        public ActionResult ReApply(int InstanceId)
        {
            WFStep           lastStep = WFStepBll.GetList <int>(s => s.WFInstance.InstanceId == InstanceId).OrderByDescending(s => s.StepId).FirstOrDefault();
            WFInstance       instance = lastStep.WFInstance;
            var              uu       = UserInfoBll.GetById(lastStep.SubBy);
            ReApplyViewModel raView   = new ReApplyViewModel
            {
                InstanceId    = instance.InstanceId,
                InstanceTitle = instance.InstanceTitle,
                Details       = instance.Details,
                Tips          = lastStep.Tips,
                RejectBy      = uu.RealName != null && uu.RealName != "" ? uu.RealName : uu.Username,
                RejectTime    = lastStep.SubTime
            };
            var result = GetNextIdList();

            ViewData["SelectList"] = result;
            return(View(raView));
        }
Exemple #12
0
        private static List <WFItem> GetWFItems(WFInstance instance, WFBusinessData businessData, ref string sql)
        {
            List <WFItem> list = new List <WFItem>();

            if (!string.IsNullOrWhiteSpace(sql))
            {
                if (sql.IndexOf("WF_M_STEP") >= 0 && sql.IndexOf("WF_M_MODEL") >= 0)
                {
                    using (var db = Pub.DB)
                    {
                        list = db.Query <VM_WF_M_STEP>(sql, Pub.ToDynamic(businessData))
                               .Select(a => new WFItem()
                        {
                            text = a.StepName, value = a.StepId
                        }).ToList();
                    }
                }
                else
                {
                    using (var db = Pub.DB)
                    {
                        var StepNames = db.Query <string>(sql, Pub.ToDynamic(businessData)).ToList();
                        if (StepNames.Count == 0)
                        {
                            StepNames.Add("-1");
                        }
                        sql = "SELECT a.StepId,a.StepName FROM dbo.WF_M_STEP a, dbo.WF_M_MODEL b WHERE a.ModelId=b.ModelId AND b.ModelName=@ModelName AND a.StepName IN @StepNames";

                        list = db.Query <VM_WF_M_STEP>(sql, new
                        {
                            ModelName = instance.ModelName,
                            StepNames = StepNames
                        })
                               .Select(a => new WFItem()
                        {
                            text = a.StepName, value = a.StepId
                        }).ToList();
                    }
                }
            }
            return(list);
        }
Exemple #13
0
        public ActionResult Approve(ApproveViewModel model)
        {
            string     result    = "no";
            WFInstance wInstance = WFInstanceBll.GetById(model.InstanceId);

            //int status = !model.Approve ? -1 : model.Approve && model.NextId == 0 ? 1 : 0;
            //if (wInstance.InstanceTitle.StartsWith("报销"))
            //{
            //    WorkFlowHelper.Resume(new Expense(), Guid.Parse(wInstance.InstanceGuid), "Check", status);
            //}
            //else if (wInstance.InstanceTitle.StartsWith("请假"))
            //{
            //    WorkFlowHelper.Resume(new Leave(), Guid.Parse(wInstance.InstanceGuid), "LeaveCheck", status);
            //}
            //else
            //{
            //    return Content("no");
            //}
            wInstance.WFStep.Add(new WFStep
            {
                Tips    = string.IsNullOrWhiteSpace(model.Tips) ? "" : model.Approve ? "同意,意见为:" + model.Tips : "驳回,意见为:" + model.Tips,
                NextId  = model.NextId,
                SubBy   = UserLogin.UserId,
                SubTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                IsEnd   = model.NextId == 0 ? (byte)1 : (byte)0
            });
            if (model.Approve && model.NextId == 0)
            {
                wInstance.InstanceState = (int)InstanceState.Over;
            }
            else if (!model.Approve)
            {
                wInstance.InstanceState = (int)InstanceState.Reject;
            }
            wInstance.RejectMsg = model.Tips;
            WFStepBll.GetById(model.StepId).IsEnd = 1;
            if (WFInstanceBll.Edit(wInstance))
            {
                result = "ok";
            }
            return(Content(result));
        }
Exemple #14
0
        public static void AddLogEntry(WFInstance obj, string formatString)
        {
            if (!string.IsNullOrEmpty(formatString))
            {
                var      ctx             = obj.Context;
                Identity identity        = null;
                var      currentIdentity = _idResolver.GetCurrent();
                if (currentIdentity != null)
                {
                    identity = ctx.Find <Identity>(currentIdentity.ID);
                }

                var msg = formatString
                          .Replace("{User}", (identity ?? (object)string.Empty).ToString())
                          .Replace("{Date}", DateTime.Today.ToShortDateString())
                          .Replace("{Time}", DateTime.Now.ToShortTimeString());
                Logging.Log.InfoFormat("Adding WF-Logentry: {0}", msg);
                var logEntry = ctx.Create <LogEntry>();
                logEntry.Message  = msg;
                logEntry.Identity = identity;
                obj.LogEntries.Add(logEntry);
            }
        }
Exemple #15
0
    private void DealAgent()
    {
        WFInstanceService wFInstanceService = new WFInstanceService();
        WFInstance        byId = wFInstanceService.GetById(this.InstanceID);

        if (byId == null || !byId.NodeID.HasValue)
        {
            return;
        }
        System.Collections.Generic.IList <WFInstance> byNodeId = wFInstanceService.GetByNodeId(byId.ID.Value, byId.NodeID.Value);
        WFTemplateNodeService wFTemplateNodeService            = new WFTemplateNodeService();
        WFTemplateNode        byNodeId2 = wFTemplateNodeService.GetByNodeId(byId.NodeID.Value);

        if (byNodeId2 != null && byNodeId2.AuditorType == "1" && byNodeId.Count == 2 && this.IsAgentShip(byNodeId[0].Operator, byNodeId[1].Operator, byId.NodeID.Value))
        {
            if (byId.Operator == byNodeId[0].Operator)
            {
                wFInstanceService.Delete(byNodeId[1]);
                return;
            }
            wFInstanceService.Delete(byNodeId[0]);
        }
    }
Exemple #16
0
 public static void ToString(WFInstance obj, MethodReturnEventArgs <string> e)
 {
     e.Result = obj.Summary;
 }
Exemple #17
0
 public static void StartCanExec(WFInstance obj, MethodReturnEventArgs <bool> e)
 {
     e.Result = obj.Workflow == null;
 }
Exemple #18
0
 public static void StartCanExecReason(WFInstance obj, MethodReturnEventArgs <string> e)
 {
     e.Result = "A workflow was started already";
 }
Exemple #19
0
 public static void Abort(WFInstance obj)
 {
 }
Exemple #20
0
 public static void get_IsActive(WFInstance obj, PropertyGetterEventArgs <bool> e)
 {
     e.Result = obj.Workflow != null && obj.States.Any(s => s.IsActive);
 }