/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { //保存文本 string OriginalTitleText = this.hcTemplate.Value; //翻译成模板文本 string TemplateTitleText = Server.HtmlDecode(OriginalTitleText); AllNodes.ToList().ForEach(p => { TemplateTitleText = TemplateTitleText.Replace(p.Value, p.Key); }); //保存文本 string OriginalContentText = this.hcTemplate.Text; //翻译成模板文本 string TemplateContentText = Server.HtmlDecode(OriginalContentText); AllNodes.ToList().ForEach(p => { TemplateContentText = TemplateContentText.Replace(p.Value, p.Key); }); using (BizDataContext context = new BizDataContext()) { SysProcessRemindTemplate model; if (TemplateId == null) { model = new SysProcessRemindTemplate(); model.TemplateId = context.GetNextIdentity(); model.State = 1; } else { model = context.FindById <SysProcessRemindTemplate>(TemplateId.Value); } model.TemplateName = this.tcTemplateName.Text; model.TemplateType = this.ccTemplateType.SelectedValue.ToInt(); model.ProcessEntityId = this.ccProcessEntityId.SelectedValue.ToLong(); model.ActivityEntityId = this.ccActivityEntityId.SelectedValue.ToLong(); model.UseTimeType = this.ccUseTimeType.SelectedValue.ToInt(); model.ResultType = this.ccResultType.SelectedValue.ToInt(); model.OriginalTitleText = OriginalTitleText; model.OriginalContentText = OriginalContentText; model.TemplateContentText = TemplateContentText; model.TemplateTitleText = TemplateTitleText; if (TemplateId == null) { context.Insert(model); } else { context.Update(model); } } Response.Redirect("~/SystemManagement/ProcessTemplateQuery.aspx"); }
/// <summary> /// 给当前的自动ID加上count,然后获得当前的自动ID /// </summary> /// <param name="count"></param> /// <returns></returns> public long GetCurrentIdentity(long count) { try { using (BizDataContext context = new BizDataContext()) { long result = 0; for (int i = 0; i < count; i++) { result = context.GetNextIdentity(); } return(result - count + 1); } } catch { return(-1); } }
/// <summary> /// 连接两个活动 /// </summary> private void ConnectActivity(BizDataContext db, SysActivity prev, SysActivity post, FlowStepDirection direction) { SysTransition t = new SysTransition() { TransitionId = db.GetNextIdentity(), PreActivityId = prev.ActivityId, PostActivityId = post.ActivityId, ProcessId = this.ProcessId, Direction = (int)direction, }; switch (direction) { case FlowStepDirection.False: t.DisplayText = "驳回"; break; case FlowStepDirection.True: t.DisplayText = "通过"; break; default: break; } db.Insert(t); }
/// <summary> /// 保存流程参与人 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cbc_CallBack(object sender, CallBackEventArgs e) { JavaScriptSerializer js = new JavaScriptSerializer(); string errorMsg = string.Empty; //错误消息 bool isError = false; try { int? functionType = e.Context["FunctionType"].ToStringNullable().ToIntNullable(); int? userId = e.Context["UserId"].ToStringNullable().ToIntNullable(); int? roleId = e.Context["RoleId"].ToStringNullable().ToIntNullable(); long processId = e.Context["ProcessId"].ToLong(); string participantName = string.Empty; if (functionType == null) { throw new Exception("参与人类型不能为空"); } if (functionType == (int)ParticipantFunctionType.SpecialUser) { T_User user = this.DataHelper.FindById <T_User>(userId); if (user == null) { throw new Exception("请指定具体人员"); } participantName = user.User_Name; } if (functionType == (int)ParticipantFunctionType.SpecialRole) { T_Role role = this.DataHelper.FindById <T_Role>(roleId); if (role == null) { throw new Exception("请指定具体角色"); } participantName = string.Format("{0}角色", role.Role_Name); } if (functionType == (int)ParticipantFunctionType.DIRECT_MANAGER) { participantName = "直属主管"; } using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { int count = db.Set <SysProcessParticipant>().Where(p => p.ProcessId == processId && p.FunctionType == functionType && p.Param_RoleId == roleId && p.Param_UserId == userId).Count(); if (count > 0) { throw new Exception("已存在相同的流程参与人"); } long?param_partId = null; if (functionType == (int)ParticipantFunctionType.DIRECT_MANAGER) { SysProcessParticipant pStartUser = new SysProcessParticipant() { ParticipantId = db.GetNextIdentity(), ProcessId = processId, FunctionType = (int)ParticipantFunctionType.StartUser, ParticipantName = "流程启动人", }; param_partId = pStartUser.ParticipantId; db.Insert(pStartUser); } SysProcessParticipant pCurrent = new SysProcessParticipant() { ParticipantId = db.GetNextIdentity(), ProcessId = processId, FunctionType = functionType, Param_UserId = userId, Param_RoleId = roleId, Param_ParticipantId = param_partId, ParticipantName = participantName, }; db.Insert(pCurrent); } ts.Complete(); } } catch (Exception ex) { isError = true; errorMsg = ex.Message; } string result = js.Serialize(new { IsError = isError, Error = errorMsg, }); e.Result = result; }
protected void btnNextStep_Click(object sender, EventArgs e) { try { string entityType = this.ddlEntityType.SelectedValue; string displayText = this.txtSysEntity.Text.Trim(); string entityName = "T_" + displayText.ToPingYin(); string formName = this.txtFormName.Text.Trim(); string formTitle = this.txtFormTitle.Text.Trim(); string formDecription = this.txtFormDescription.Text.Trim(); if (string.IsNullOrEmpty(formName)) { throw new Exception("表单名称不能为空"); } using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { switch (entityType) { case "0": case "1": if (this.EntityId == null) { throw new Exception("关联实体不能为空"); } break; case "2": if (string.IsNullOrEmpty(displayText)) { throw new Exception("关联实体不能为空"); } if (string.IsNullOrEmpty(entityName)) { throw new Exception("关联实体表名不能为空"); } SysEntity tempEntity = db.FirstOrDefault <SysEntity>(p => p.EntityName == entityName || p.DisplayText == displayText); if (tempEntity != null) { throw new Exception("当前新增的关联实体名称已存在"); } tempEntity = new SysEntity() { EntityId = db.GetNextIdentity(), EntityName = entityName, DisplayText = displayText, Description = displayText, IsFormEntity = true, CreateTime = DateTime.Now, }; db.Insert(tempEntity); this.EntityId = tempEntity.EntityId; //默认加一个主键字段 SysField tempField = new SysField() { FieldId = db.GetNextIdentity(), EntityId = tempEntity.EntityId, FieldName = displayText.ToPingYin() + "_Id", DisplayText = displayText + "ID", Description = displayText + "ID", DataType = (int)DataTypeEnum.pkey, IsFormField = true, //2013-9-24 zhumin }; db.Insert(tempField); break; default: break; } if (this.FormId != null) { SysForm form = db.FindById <SysForm>(this.FormId); if (form != null) { form.FormName = formName; form.EntityId = this.EntityId; form.UpdateTime = DateTime.Now; form.UpdateUserId = this.LoginUserID; form.FormTitle = formTitle; form.FormDescription = formDecription; db.UpdatePartial(form, p => new { p.FormName, p.FormTitle, p.FormDescription, p.EntityId, p.UpdateTime, p.UpdateUserId }); } else { throw new Exception("表单不存在"); } } else { SysForm form = new SysForm() { FormId = db.GetNextIdentity(), FormName = formName, FormTitle = formTitle, FormDescription = formDecription, EntityId = this.EntityId, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, OwnerId = this.LoginUserID, State = (int)FormState.New, }; db.Insert(form); this.FormId = form.FormId; } } ts.Complete(); } Response.Redirect(string.Format("FormDesigner_SecondStep.aspx?id={0}", this.FormId)); } catch (Exception ex) { this.AjaxAlertAndEnableButton(ex); } }
/// <summary> /// 复制流程,从“已启用”或“已升级”的流程进入设计,需要先复制一份流程供设计 /// 状态为“新增”,版本为当前最高版本 + 1 /// </summary> public SysProcess CopyProcess() { SysProcess result; using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { //新流程 SysProcess newP = _process.ConvertTo <SysProcess>(); newP.ProcessId = db.GetNextIdentity(); //版本处理 newP.ProcessStatus = (int)ProcessState.Created; string maxVersion = db.Set <SysProcess>().Where(p => p.ProcessType == _process.ProcessType).OrderByDescending(p => p.ProcessVersion).First().ProcessVersion; newP.ProcessVersion = (maxVersion.ToInt() + 1).ToString(); result = newP; db.Insert(newP); //新流程参与人 var ppList = db.Set <SysProcessParticipant>().Where(p => p.ProcessId == _process.ProcessId).ToList(); Dictionary <long?, SysProcessParticipant> tempPpDict = new Dictionary <long?, SysProcessParticipant>(); foreach (var pp in ppList) { SysProcessParticipant newPp = pp.ConvertTo <SysProcessParticipant>(); newPp.ParticipantId = db.GetNextIdentity(); newPp.ProcessId = newP.ProcessId; tempPpDict[pp.ParticipantId] = newPp; //记录原始ID和新对象的关系 } foreach (var newPp in tempPpDict.Values) { if (newPp.Param_ParticipantId != null) //通过刚才记录的关系找到实际的值 { newPp.Param_ParticipantId = tempPpDict[newPp.Param_ParticipantId].ParticipantId; } db.Insert(newPp); } //新活动 var aList = db.Set <SysActivity>().Where(p => p.ProcessId == _process.ProcessId).ToList(); Dictionary <long?, SysActivity> tempADict = new Dictionary <long?, SysActivity>(); foreach (var a in aList) { SysActivity newA = a.ConvertTo <SysActivity>(); newA.ActivityId = db.GetNextIdentity(); newA.ProcessId = newP.ProcessId; tempADict[a.ActivityId] = newA;//记录原始ID和新对象的关系 db.Insert(newA); //新活动参与人 var apList = db.Set <SysActivityParticipant>().Where(p => p.ActivityId == a.ActivityId).ToList(); foreach (var ap in apList) { SysActivityParticipant newAp = ap.ConvertTo <SysActivityParticipant>(); newAp.ActivityParticipantId = db.GetNextIdentity(); newAp.ActivityId = newA.ActivityId; newAp.ParticipantId = tempPpDict[newAp.ParticipantId].ParticipantId; //通过刚才记录的关系找到实际的值 db.Insert(newAp); } } //连接线 var tList = db.Set <SysTransition>().Where(p => p.ProcessId == _process.ProcessId).ToList(); foreach (var t in tList) { SysTransition newT = t.ConvertTo <SysTransition>(); newT.TransitionId = db.GetNextIdentity(); newT.ProcessId = newP.ProcessId; //通过刚才记录的关系找到实际的值 newT.PreActivityId = tempADict[newT.PreActivityId].ActivityId; newT.PostActivityId = tempADict[newT.PostActivityId].ActivityId; db.Insert(newT); } //表单活动权限 var fpList = db.Set <SysFormPrivilege>().Where(p => p.ProcessId == _process.ProcessId).ToList(); foreach (var fp in fpList) { SysFormPrivilege newFp = fp.ConvertTo <SysFormPrivilege>(); newFp.PrivilegeId = db.GetNextIdentity(); newFp.ProcessId = newP.ProcessId; newFp.ActivityId = tempADict[newFp.ActivityId].ActivityId;//通过刚才记录的关系找到实际的值 db.Insert(newFp); } } ts.Complete(); } return(result); }
/// <summary> /// 选中现有字段并添加为表单字段 /// </summary> /// <param name="sectionId"></param> /// <param name="parameter"></param> /// <returns></returns> private string SelectField(long sectionId, string parameter) { StringBuilder sb = new StringBuilder(); SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId); if (section != null) { JavaScriptSerializer js = new JavaScriptSerializer(); object[] fieldList = js.DeserializeObject(parameter) as object[]; if (fieldList == null) { throw new Exception("回调参数不正确"); } var source = fieldList.Select(p => p as Dictionary <string, object>) .Select(p => new { FieldId = p["FieldId"].ToLong(), RelationId = p["RelationId"].ToStringNullable().ToLongNullable(), }); int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { foreach (var p in source) { SysField field = this.EntityCache.FindById <SysField>(p.FieldId); if (field == null) { field = db.FindById <SysField>(p.FieldId); } if (field != null) { SysFormField ff = new SysFormField() { FormFieldId = db.GetNextIdentity(), FormSectionId = sectionId, FormId = section.FormId, FieldId = p.FieldId, RelationId = p.RelationId, DisplayOrder = ++maxOrder, EntityId = field.EntityId, DataType = field.DataType, IsNullable = true, CreateUserId = this.LoginUserID, CreateTime = DateTime.Now, }; db.Insert(ff); sb.AppendFormat("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText); } else { throw new Exception("找不到关联字段"); } } } ts.Complete(); } } else { throw new Exception("找不到表单段落"); } return(sb.ToString()); }
/// <summary> /// 新增表单字段 /// </summary> /// <param name="sectionId"></param> /// <param name="parameter"></param> /// <param name="otherContent"></param> /// <returns></returns> private string NewField(long sectionId, string parameter, ref object otherContent) { string result = string.Empty; SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId); if (section != null) { SysForm form = this.DataHelper.FindById <SysForm>(section.FormId); if (form == null) { throw new Exception("表单不存在"); } JavaScriptSerializer js = new JavaScriptSerializer(); var valueDict = js.DeserializeObject(parameter) as Dictionary <string, object>; if (valueDict == null) { throw new Exception("回调参数不正确"); } string displayText = valueDict["DisplayText"].ToStringNullable(); string fieldName = valueDict["FieldName"].ToStringNullable(); int? dataType = valueDict["DataType"].ToStringNullable().ToIntNullable(); int temp = this.DataHelper.Set <SysField>().Where(p => p.EntityId == form.EntityId && (p.DisplayText == displayText || p.FieldName == fieldName)).Count(); if (temp > 0) { throw new Exception("当前新增的字段名称已经存在"); } int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { //新增字段 SysField field = new SysField() { FieldId = db.GetNextIdentity(), DisplayText = displayText, FieldName = fieldName, EntityId = form.EntityId, Description = displayText, DataType = dataType, IsFormField = true,//2013-9-24 zhumin }; db.Insert(field); //新增表单字段 SysFormField ff = new SysFormField() { FormFieldId = db.GetNextIdentity(), FormSectionId = sectionId, EntityId = form.EntityId, DisplayOrder = maxOrder + 1, FormId = form.FormId, FieldId = field.FieldId, DataType = field.DataType, IsNullable = true, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, }; db.Insert(ff); result = string.Format("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText); otherContent = string.Format("<div class=\"divField\"><span><input type=\"checkbox\" fid=\"{0}\" /></span><span>{1}</span><span>{2}</span></div>", field.FieldId, field.DisplayText, field.FieldName); } ts.Complete(); } } return(result); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { try { if (this.SelectedRoleId == null) { throw new Exception("请选择角色"); } //现有配置 var fpDict = this.DataHelper.Set <SysFormRolePrivilege>() .Where(p => p.RoleId == this.SelectedRoleId && p.FormId == this.FormId).ToList().ToDictionary(p => p.FormFieldId); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { foreach (RepeaterItem section in rSection.Items) { Repeater rField = section.FindControl("rField") as Repeater; foreach (RepeaterItem field in rField.Items) { var hf = field.FindControl("hf") as HiddenField; var ccInvisible = field.FindControl("ccInvisible") as RadioButton; var ccReadOnly = field.FindControl("ccReadOnly") as RadioButton; var ccReadWrite = field.FindControl("ccReadWrite") as RadioButton; if (hf != null && ccInvisible != null && ccReadOnly != null && ccReadWrite != null) { var id = hf.Value.ToLong(); FormFieldPrivilege privilege = FormFieldPrivilege.Invisible; if (ccReadOnly.Checked) { privilege = FormFieldPrivilege.ReadOnly; } else if (ccReadWrite.Checked) { privilege = FormFieldPrivilege.ReadWrite; } if (fpDict.ContainsKey(id)) { var fp = fpDict[id]; if (fp.DisplayPrivilege != (int)privilege) { fp.DisplayPrivilege = (int)privilege; db.UpdatePartial(fp, p => new { p.DisplayPrivilege }); } } else { SysFormRolePrivilege fp = new SysFormRolePrivilege() { PrivilegeId = db.GetNextIdentity(), FormFieldId = id, FormId = this.FormId, RoleId = this.SelectedRoleId, DisplayPrivilege = (int)privilege, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, }; db.Insert(fp); } } } } } ts.Complete(); } this.AjaxAlertAndEnableButton("保存成功"); } catch (Exception ex) { this.AjaxAlertAndEnableButton(ex); } }
/// <summary> /// 新增一个活动,并选中 /// </summary> protected void btnAdd_Click(object sender, EventArgs e) { try { //所有活动 Dictionary <long, SysActivity> activityDict = this.DataHelper.Set <SysActivity>() .Where(p => p.ProcessId == this.ProcessId).ToDictionary(p => p.ActivityId); //最后一个审核活动 SysActivity lastActivity = activityDict.Values.Where(p => p.ActivityType == (int)ActivityType.Approve) .OrderByDescending(p => p.DisplayOrder).FirstOrDefault(); SysActivity endReject = activityDict.Values.FirstOrDefault(p => p.ActivityType == (int)ActivityType.End && p.ActivityName == "驳回"); SysActivity endPass = activityDict.Values.FirstOrDefault(p => p.ActivityType == (int)ActivityType.End && p.ActivityName == "通过"); int maxCount = activityDict.Values.Max(p => p.DisplayOrder ?? 0); //最后一个审核活动通过指向的连接线 SysTransition t = this.DataHelper.Set <SysTransition>() .Where(p => p.PreActivityId == lastActivity.ActivityId && p.Direction == (int)FlowStepDirection.True).FirstOrDefault(); SysActivity newActivity; using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { //新活动 newActivity = new SysActivity() { ActivityId = db.GetNextIdentity(), ProcessId = this.ProcessId, ActivityType = (int)ActivityType.Approve, DisplayOrder = maxCount + 1, ExecType = (int)ActivityExecType.Manual, PassType = (int)ActivityPassType.FirstDefault, IsPassedWithNoParticipants = true, ActivityName = "活动名称", LeftPos = 350, TopPos = (maxCount + 1) * 130 + 50, }; db.Insert(newActivity); //把上一个活动接到新活动 t.PostActivityId = newActivity.ActivityId; db.UpdatePartial(t, p => new { p.PostActivityId }); //按默认规则链接新活动和结束活动 ConnectActivity(db, newActivity, endPass, FlowStepDirection.True); ConnectActivity(db, newActivity, endReject, FlowStepDirection.False); } ts.Complete(); } //选中新活动 SelectActivity(newActivity); this.EnableButton(); } catch (Exception ex) { this.AjaxAlertAndEnableButton(ex); } }
/// <summary> /// 进入页面,如果没有任何活动,自动添加隐藏的开始活动、结束活动、以及第一个审核活动,并选中第一个审核活动 /// </summary> private void AddHiddenAndFirstActivity() { int count = this.DataHelper.Set <SysActivity>() .Where(p => p.ProcessId == this.ProcessId).Count(); if (count == 0) { using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { //开始活动 SysActivity start = new SysActivity() { ActivityId = db.GetNextIdentity(), ActivityName = "开始", ActivityType = (int)ActivityType.Start, ProcessId = this.ProcessId, ExecType = (int)ActivityExecType.Auto, LeftPos = 350, TopPos = 50, }; db.Insert(start); //第一个审核活动 SysActivity first = new SysActivity() { ActivityId = this.DataHelper.GetNextIdentity(), ProcessId = this.ProcessId, ActivityType = (int)ActivityType.Approve, ActivityName = "活动名称", DisplayOrder = 1, ExecType = (int)ActivityExecType.Manual, PassType = (int)ActivityPassType.FirstDefault, LeftPos = 350, TopPos = 180, }; db.Insert(first); //结束活动(通过) SysActivity endPass = new SysActivity() { ActivityId = db.GetNextIdentity(), ActivityName = "通过", ActivityType = (int)ActivityType.End, ProcessId = this.ProcessId, ExecType = (int)ActivityExecType.Auto, IsPassedWithNoParticipants = true, LeftPos = 100, TopPos = 350, ApproveResult = (int)ApproveResultEnum.Pass, }; db.Insert(endPass); //结束活动(驳回) SysActivity endReject = new SysActivity() { ActivityId = db.GetNextIdentity(), ActivityName = "驳回", ActivityType = (int)ActivityType.End, ProcessId = this.ProcessId, ExecType = (int)ActivityExecType.Auto, LeftPos = 600, TopPos = 350, ApproveResult = (int)ApproveResultEnum.Reject, }; db.Insert(endReject); //按默认规则链接这三个活动 ConnectActivity(db, start, first, FlowStepDirection.True); ConnectActivity(db, first, endPass, FlowStepDirection.True); ConnectActivity(db, first, endReject, FlowStepDirection.False); } ts.Complete(); } } //选中第一个活动 var a = this.DataHelper.Set <SysActivity>() .Where(p => p.ProcessId == this.ProcessId && p.ActivityType == (int)ActivityType.Approve) .OrderBy(p => p.DisplayOrder).FirstOrDefault(); SelectActivity(a); }