public void ButtonOKClick(ICustomerForm CustomerFormView, string inName, string inSurname, string inPhone, int inKol, Event inEvent)
        {
            if (inName == "")
            {
                MessageBox.Show("Upišite ime!");
            }
            else if (inSurname == "")
            {
                MessageBox.Show("Upišite prezime!");
            }
            else if (inPhone == "")
            {
                MessageBox.Show("Upišite broj telefona!");
            }
            else
            {
                DateTime time   = DateTime.Now;
                string   str    = time.ToString();
                byte[]   buffer = new byte[str.Length];
                int      i      = 0;
                foreach (char c in str.ToCharArray())
                {
                    buffer[i] = (byte)c;
                    i++;
                }
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                string md5string             = BitConverter.ToString(md5.ComputeHash(buffer)).Replace("-", "");
                md5string = md5string.Substring(10, 8);

                AddNewReservation(md5string, inKol, time, inEvent, inName, inSurname, inPhone);
                EventRepository.getInstance().RemoveTickets(inKol, inEvent.Name);

                List <Event> list = EventController.getInstance().GetEventList();
                EventController.getInstance().NotifyObservers(list);

                MessageBox.Show("Uspješna rezervacija!\n\nRezervacija:\n\nŠifra: " + md5string + "\nDogađaj: " + inEvent.Name + "\nKoličina: " + inKol.ToString());

                CustomerFormView.CloseCustomerForm();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建一个实例
        /// </summary>
        /// <returns></returns>
        public bool CreateInstance(AddFlowInstanceReq addFlowInstanceReq)
        {
            FlowScheme scheme = null;

            if (!string.IsNullOrEmpty(addFlowInstanceReq.SchemeId))
            {
                scheme = _flowSchemeApp.Get(addFlowInstanceReq.SchemeId);
            }

            if ((scheme == null) && !string.IsNullOrEmpty(addFlowInstanceReq.SchemeCode))
            {
                scheme = _flowSchemeApp.FindByCode(addFlowInstanceReq.SchemeCode);
            }

            if (scheme == null)
            {
                throw new Exception("该流程模板已不存在,请重新设计流程");
            }

            addFlowInstanceReq.SchemeContent = scheme.SchemeContent;

            var form = _formApp.FindSingle(scheme.FrmId);

            if (form == null)
            {
                throw new Exception("该流程模板对应的表单已不存在,请重新设计流程");
            }

            addFlowInstanceReq.FrmContentData  = form.ContentData;
            addFlowInstanceReq.FrmContentParse = form.ContentParse;
            addFlowInstanceReq.FrmType         = form.FrmType;
            addFlowInstanceReq.FrmId           = form.Id;

            var flowInstance = addFlowInstanceReq.MapTo <FlowInstance>();

            //创建运行实例
            var wfruntime = new FlowRuntime(flowInstance);
            var user      = _auth.GetCurrentUser();

            #region 根据运行实例改变当前节点状态

            flowInstance.ActivityId     = wfruntime.nextNodeId;
            flowInstance.ActivityType   = wfruntime.GetNextNodeType();
            flowInstance.ActivityName   = wfruntime.nextNode.name;
            flowInstance.PreviousId     = wfruntime.currentNodeId;
            flowInstance.CreateUserId   = user.User.Id;
            flowInstance.CreateUserName = user.User.Account;
            flowInstance.MakerList      = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
            flowInstance.IsFinish       = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);

            UnitWork.Add(flowInstance);
            wfruntime.flowInstanceId = flowInstance.Id;

            if (flowInstance.FrmType == 1)
            {
                var           t   = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App");
                ICustomerForm icf = (ICustomerForm)_serviceProvider.GetService(t);
                icf.Add(flowInstance.Id, flowInstance.FrmData);
            }

            #endregion 根据运行实例改变当前节点状态

            #region 流程操作记录

            FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
            {
                InstanceId     = flowInstance.Id,
                CreateUserId   = user.User.Id,
                CreateUserName = user.User.Name,
                CreateDate     = DateTime.Now,
                Content        = "【创建】"
                                 + user.User.Name
                                 + "创建了一个流程进程【"
                                 + addFlowInstanceReq.Code + "/"
                                 + addFlowInstanceReq.CustomName + "】"
            };
            UnitWork.Add(processOperationHistoryEntity);

            #endregion 流程操作记录

            AddTransHistory(wfruntime);
            UnitWork.Save();
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建一个实例
        /// </summary>
        /// <returns></returns>
        public bool CreateInstance(JObject obj)
        {
            var flowInstance = obj.ToObject <FlowInstance>();

            if (flowInstance.FrmType == 0)
            {
                //动态表单的数据
                var frmdata = new JObject();
                foreach (var property in obj.Properties().Where(U => U.Name.Contains("data_")))
                {
                    frmdata[property.Name] = property.Value;
                }
                flowInstance.FrmData = JsonHelper.Instance.Serialize(frmdata);
            }

            //创建运行实例
            var wfruntime = new FlowRuntime(flowInstance);
            var user      = _auth.GetCurrentUser();

            #region 根据运行实例改变当前节点状态

            flowInstance.ActivityId     = wfruntime.nextNodeId;
            flowInstance.ActivityType   = wfruntime.GetNextNodeType();
            flowInstance.ActivityName   = wfruntime.nextNode.name;
            flowInstance.PreviousId     = wfruntime.currentNodeId;
            flowInstance.CreateUserId   = user.User.Id;
            flowInstance.CreateUserName = user.User.Account;
            flowInstance.MakerList      = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
            flowInstance.IsFinish       = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);

            UnitWork.Add(flowInstance);
            wfruntime.flowInstanceId = flowInstance.Id;

            if (flowInstance.FrmType == 1)
            {
                var           t   = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App");
                ICustomerForm icf = (ICustomerForm)AutofacExt.GetFromFac(t);
                icf.Add(flowInstance.Id, flowInstance.FrmData);
            }

            #endregion 根据运行实例改变当前节点状态

            #region 流程操作记录

            FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
            {
                InstanceId     = flowInstance.Id,
                CreateUserId   = user.User.Id,
                CreateUserName = user.User.Name,
                CreateDate     = DateTime.Now,
                Content        = "【创建】"
                                 + user.User.Name
                                 + "创建了一个流程进程【"
                                 + flowInstance.Code + "/"
                                 + flowInstance.CustomName + "】"
            };
            UnitWork.Add(processOperationHistoryEntity);

            #endregion 流程操作记录

            AddTransHistory(wfruntime);
            UnitWork.Save();
            return(true);
        }
        public async Task UpdateInstance(FlowinstanceEntity entity)
        {
            FlowschemeEntity scheme = null;

            if (!string.IsNullOrEmpty(entity.F_SchemeId))
            {
                scheme = await uniwork.FindEntity <FlowschemeEntity>(entity.F_SchemeId);
            }
            if (scheme == null)
            {
                throw new Exception("该流程模板已不存在,请重新设计流程");
            }
            entity.F_SchemeContent = scheme.F_SchemeContent;
            var form = await uniwork.FindEntity <FormEntity>(scheme.F_FrmId);

            if (form == null)
            {
                throw new Exception("该流程模板对应的表单已不存在,请重新设计流程");
            }
            var wfruntime = new FlowRuntime(await repository.FindEntity(entity.F_Id));

            entity.F_FrmContentData   = form.F_ContentData;
            entity.F_FrmContentParse  = form.F_ContentParse;
            entity.F_FrmType          = form.F_FrmType;
            entity.F_FrmId            = form.F_Id;
            entity.F_InstanceSchemeId = "";
            entity.F_DbName           = form.F_WebId;
            entity.F_FlowLevel        = 0;
            //创建运行实例
            wfruntime = new FlowRuntime(entity);

            var user = currentuser;

            #region 根据运行实例改变当前节点状态
            entity.F_ActivityId      = wfruntime.nextNodeId;
            entity.F_ActivityType    = wfruntime.GetNextNodeType();
            entity.F_ActivityName    = wfruntime.nextNode.name;
            entity.F_PreviousId      = wfruntime.currentNodeId;
            entity.F_CreatorUserName = user.UserName;
            entity.F_MakerList       = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
            entity.F_IsFinish        = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);
            uniwork.BeginTrans();
            await uniwork.Update(entity);

            wfruntime.flowInstanceId = entity.F_Id;
            //复杂表单提交
            if (entity.F_FrmType == 1)
            {
                var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
                var referencedAssemblies = Directory.GetFiles(path, "*.dll").Select(Assembly.LoadFrom).ToArray();
                var t = referencedAssemblies
                        .SelectMany(a => a.GetTypes().Where(t => t.FullName.Contains("WaterCloud.Service.") && t.FullName.Contains("." + entity.F_DbName + "Service"))).FirstOrDefault();
                ICustomerForm icf = (ICustomerForm)GlobalContext.ServiceProvider.GetService(t);
                await icf.Edit(entity.F_Id, entity.F_FrmData);
            }
            #endregion

            #region 流程操作记录
            FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
            {
                F_Id              = Utils.GuId(),
                F_InstanceId      = entity.F_Id,
                F_CreatorUserId   = user.UserId,
                F_CreatorUserName = entity.F_CreatorUserName,
                F_CreatorTime     = DateTime.Now,
                F_Content         = "【修改】"
                                    + entity.F_CreatorUserName
                                    + "修改了一个流程【"
                                    + entity.F_Code + "/"
                                    + entity.F_CustomName + "】"
            };
            await uniwork.Insert(processOperationHistoryEntity);

            #endregion

            await AddTransHistory(wfruntime);

            MessageEntity msg = new MessageEntity();
            msg.F_CreatorUserName = currentuser.UserName;
            msg.F_EnabledMark     = true;
            if (entity.F_IsFinish == 1)
            {
                msg.F_MessageInfo = entity.F_CustomName + "--流程已完成";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                msg.F_ClickRead  = true;
                msg.F_KeyValue   = entity.F_Id;
            }
            else if (entity.F_IsFinish == 3)
            {
                msg.F_MessageInfo = entity.F_CustomName + "--流程已终止";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                var makerList = uniwork.IQueryable <FlowInstanceOperationHistory>(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList();
                msg.F_ToUserId  = entity.F_CreatorUserId;
                msg.F_ClickRead = true;
                msg.F_KeyValue  = entity.F_Id;
            }
            else
            {
                msg.F_MessageInfo = entity.F_CustomName + "--流程待处理";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow";
                msg.F_HrefTarget = module.F_Target;
                msg.F_ClickRead  = false;
                msg.F_KeyValue   = entity.F_Id;
            }
            msg.F_MessageType = 2;
            msg.F_ToUserId    = entity.F_MakerList == "1" ? "" : entity.F_MakerList;
            var lastmsg = uniwork.IQueryable <MessageEntity>(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault();
            if (lastmsg != null && uniwork.IQueryable <MessageHistoryEntity>(a => a.F_MessageId == lastmsg.F_Id).Count() == 0)
            {
                await messageApp.ReadMsgForm(lastmsg.F_Id);
            }
            await messageApp.SubmitForm(msg);

            uniwork.Commit();
            await CacheHelper.Remove(cacheKey + entity.F_Id);

            await CacheHelper.Remove(cacheKey + "list");

            msg.F_ClickRead = false;
            msg.F_KeyValue  = entity.F_Id;
        }
 public static UpdateCustomerInfo(ICustomerForm form, Customer customer)
 {
     form.Name    = customer.Name;
     form.Address = customer.Address;
 }
Exemplo n.º 6
0
        /// <summary>
        /// 节点审核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public bool NodeVerification(VerificationReq request)
        {
            var user       = _auth.GetCurrentUser().User;
            var instanceId = request.FlowInstanceId;

            var tag = new Tag
            {
                UserName    = user.Name,
                UserId      = user.Id,
                Description = request.VerificationOpinion,
                Taged       = Int32.Parse(request.VerificationFinally)
            };

            FlowInstance flowInstance = Get(instanceId);

            if (flowInstance.MakerList != "1" && !flowInstance.MakerList.Contains(user.Id))
            {
                throw new Exception("当前用户没有审批该节点权限");
            }

            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                InstanceId     = instanceId,
                CreateUserId   = tag.UserId,
                CreateUserName = tag.UserName,
                CreateDate     = DateTime.Now
            }; //操作记录
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            #region 会签

            if (flowInstance.ActivityType == 0) //当前节点是会签节点
            {
                //会签时的【当前节点】一直是会签开始节点
                //TODO: 标记会签节点的状态,这个地方感觉怪怪的
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);

                string canCheckId = ""; //寻找当前登录用户可审核的节点Id
                foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId]
                         .Select(u => u.to))
                {
                    var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点
                    canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag);
                    if (!string.IsNullOrEmpty(canCheckId))
                    {
                        break;
                    }
                }

                if (canCheckId == "")
                {
                    throw (new Exception("审核异常,找不到审核节点"));
                }

                flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;

                wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态
                string res = wfruntime.NodeConfluence(canCheckId, tag);
                if (res == TagState.No.ToString("D"))
                {
                    flowInstance.IsFinish = FlowInstanceStatus.Disagree;
                }
                else if (!string.IsNullOrEmpty(res))
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4
                        ? FlowInstanceStatus.Finished
                        : FlowInstanceStatus.Running);
                    flowInstance.MakerList =
                        (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime));

                    AddTransHistory(wfruntime);
                }
                else
                {
                    //会签过程中,需要更新用户
                    flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId);
                    AddTransHistory(wfruntime);
                }
            }

            #endregion 会签

            #region 一般审核

            else
            {
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
                if (tag.Taged == (int)TagState.Ok)
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.MakerList    = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime, request);
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4
                        ? FlowInstanceStatus.Finished
                        : FlowInstanceStatus.Running);
                }
                else
                {
                    flowInstance.IsFinish  = FlowInstanceStatus.Disagree; //表示该节点不同意
                    wfruntime.nextNodeId   = "-1";
                    wfruntime.nextNodeType = 4;
                }

                AddTransHistory(wfruntime);

                flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;
            }

            #endregion 一般审核

            flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj());

            if (!string.IsNullOrEmpty(request.FrmData))
            {
                flowInstance.FrmData = request.FrmData;

                if (flowInstance.FrmType == 1) //如果是开发者自定义的表单,更新对应数据库表数据
                {
                    var           t   = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App");
                    ICustomerForm icf = (ICustomerForm)_serviceProvider.GetService(t);
                    icf.Update(flowInstance.Id, flowInstance.FrmData);
                }
            }

            UnitWork.Update(flowInstance);
            UnitWork.Add(flowInstanceOperationHistory);

            //给流程创建人发送通知信息
            _messageApp.SendMsgTo(flowInstance.CreateUserId,
                                  $"你的流程[{flowInstance.CustomName}]已被{user.Name}处理。处理情况如下:{flowInstanceOperationHistory.Content}");

            UnitWork.Save();

            wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag);
            return(true);
        }