/// <summary> /// 生成任务书的pdf文档,单页面加载 /// </summary> /// <param name="bookTaskId"></param> /// <param name="path"></param> /// <param name="addYinhooTag"></param> /// <returns></returns> public bool GeneratePdf(int bookTaskId, out string path, string customerName) { var q = this.FindAllByBookId(bookTaskId).ToList(); var bookTask = BookTaskBll._().FindById(bookTaskId); var pdfPages = new List <PdfDoc>(); foreach (BsonDocument BsonDocument in q) { PdfDoc page = new PdfDoc(); page.Id = BsonDocument.Int("pageId"); if (BsonDocument.ChildBsonList("PageBodies").FirstOrDefault() != null) { //通过url直接生成pdf用 string url = string.Format("http://{0}/account/PageVersionDetail/?pagId={1}", System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"], BsonDocument.Int("pageId")); page.Url = url; } page.Name = BsonDocument.Text("name"); page.NodeKey = BsonDocument.Text("nodeKey"); page.NodeLevel = BsonDocument.Int("nodeLevel"); page.NodeOrder = BsonDocument.Int("nodeOrder"); page.NodePid = BsonDocument.Int("nodePid"); page.Expended = true; pdfPages.Add(page); } string dir2 = string.Empty; string savePath = GetBookPagePdf(bookTaskId, out dir2); dir2 = System.Web.HttpContext.Current.Server.MapPath(dir2); savePath = System.Web.HttpContext.Current.Server.MapPath(savePath); if (!System.IO.Directory.Exists(dir2)) { System.IO.Directory.CreateDirectory(dir2); } string bookTaskUrl = string.Format("<a href=\"{0}\">{1}</a>", "http://" + System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + "/MissionStatement/Home/BsonDocument/" + bookTaskId, bookTask.Text("name")); var tag = HtmlHelper.MergePdf2(pdfPages, savePath, customerName, bookTaskUrl); if (tag) { path = savePath; return(true); } else { path = null; return(false); } }
private List <TreeNode> GetSubNode(BsonDocument org, int level, int subOrgId) { if (level > 2) { return(null); } var orgId = org.Text("orgId"); List <TreeNode> treeList = new List <TreeNode>(); var orgList = dataOp.FindChildNodes("Organization", orgId).Where(o => o.Int("orgId") == subOrgId).ToList(); foreach (var o in orgList) { TreeNode tempnode = new TreeNode(); tempnode.Id = o.Int("orgId"); tempnode.Lv = 1; tempnode.Name = o.Text("name"); tempnode.Pid = o.Int("nodePid"); tempnode.TreeType = "0"; if ((o.ChildBsonList("OrgPost").Count() + dataOp.FindChildNodes("Organization", o.Text("orgId")).Count()) > 0) { tempnode.IsLeaf = 0; } else { tempnode.IsLeaf = 1; } tempnode.SubNodes = GetSubNode(o, level + 1); treeList.Add(tempnode); } foreach (var pos in org.ChildBsonList("OrgPost")) { TreeNode tempnode = new TreeNode(); tempnode.Id = pos.Int("postId"); tempnode.Lv = 1; tempnode.Name = pos.Text("name"); tempnode.Pid = pos.Int("orgId"); tempnode.TreeType = "1"; tempnode.IsLeaf = 1; treeList.Add(tempnode); } return(treeList); }
/// <summary> /// 更新页面 /// </summary> /// <param name="matCat"></param> /// <returns></returns> public InvokeResult Update(BsonDocument BsonDocument, BsonDocument updateBosn, string oldName, int bookId, List <int> patternIds) { try { using (TransactionScope scope = new TransactionScope()) { if (BsonDocument == null) { throw new ArgumentNullException(); } if (BsonDocument.Text("name") != oldName) { if (this.ExsistName(BsonDocument.Int("nodePid"), BsonDocument.Int("pageId"), BsonDocument.Text("name"), bookId) == true) { return(new InvokeResult <BsonDocument>() { Status = Status.Failed, Message = "该页面已经包含 " + BsonDocument.Text("name") + " 的子页面" }); } } var result = this._ctx.QuickDelete("BookPagePattern", BsonDocument.ChildBsonList("BookPagePattern")); if (result.Status != Status.Successful) { return(result); } var oldEntity = FindById(BsonDocument.Int("pageId")); if (oldEntity != null) { var updateResult = this._ctx.Update(BsonDocument, updateBosn); if (updateResult.Status != Status.Successful) { return(updateResult); } else { BsonDocument = updateResult.BsonInfo; } } else { var addResult = this._ctx.Insert("BookPage", BsonDocument); if (addResult.Status != Status.Successful) { return(addResult); } else { BsonDocument = addResult.BsonInfo; } } if (patternIds.Count() > 0) { var newBookPagePatternList = new List <BsonDocument>(); foreach (var id in patternIds) { var newBookPagePattern = new BsonDocument(); newBookPagePattern.Add("pageId", BsonDocument.Int("pageId")); newBookPagePattern.Add("patternId", id); if (this._ctx.FindAllByQueryStr("BookPagePattern", string.Format("pageId={0}&patternId={1}", BsonDocument.Int("pageId"), id)).Count() == 0) { newBookPagePatternList.Add(newBookPagePattern); } } this._ctx.QuickInsert("BookPagePattern", newBookPagePatternList); } scope.Complete(); } return(new InvokeResult <BsonDocument>() { Value = BsonDocument, Status = Status.Successful }); } catch (Exception ex) { return(new InvokeResult <BsonDocument>() { Value = BsonDocument, Status = Status.Failed, Message = ex.Message }); } //BuildIndex(BsonDocument); }
/// <summary> /// 新版构造组织架构树 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult newOrgTree(string id) { int orgId = 0; if (id == "") { id = PageReq.GetParam("id"); } if (id != null && id != "0") { orgId = int.Parse(id.Split('_')[1]); } // string[] idArr = id.Split('_').ToArray(); List <BsonDocument> orgList = new List <BsonDocument>(); BsonDocument orgTemp = new BsonDocument(); if (orgId == 0) { orgList = dataOp.FindAllByKeyVal("Organization", "nodeLevel", "1").ToList(); } else { orgTemp = dataOp.FindOneByKeyVal("Organization", "orgId", orgId.ToString()); orgList = dataOp.FindChildNodes("Organization", orgId.ToString()).ToList(); } List <TreeNode> treeList = new List <TreeNode>(); foreach (var org in orgList) { TreeNode node = new TreeNode(); node.Id = org.Int("orgId"); node.Lv = org.Int("nodeLevel"); node.Name = org.Text("name"); node.Pid = org.Int("nodePid"); node.TreeType = "0"; if ((org.ChildBsonList("OrgPost").Count() + dataOp.FindChildNodes("Organization", org.Text("orgId")).Count()) > 0) { node.IsLeaf = 0; } else { node.IsLeaf = 1; } #region 第一次显示两级 if (orgId == 0) { if (string.IsNullOrEmpty(PageReq.GetParam("orgId")) == false) { node.SubNodes = GetSubNode(org, 2, PageReq.GetParamInt("orgId")); } else { node.SubNodes = GetSubNode(org, 2); } } #endregion treeList.Add(node); } if (orgId != 0) { List <BsonDocument> orgPostList = new List <BsonDocument>(); orgPostList = orgTemp.ChildBsonList("OrgPost").ToList(); if (orgPostList.Count > 0) { foreach (var pos in orgPostList) { TreeNode node = new TreeNode(); node.Id = pos.Int("postId"); node.Lv = orgTemp.Int("nodeLevel") + 1; node.Name = pos.Text("name"); node.Pid = pos.Int("orgId"); node.TreeType = "1"; node.IsLeaf = 1; treeList.Add(node); } } } return(new DynamicXmlTree(treeList)); }
/// <summary> /// 保存任务书 /// </summary> /// <param name="entity"></param> /// <param name="ids"></param> /// <returns></returns> public InvokeResult Save(BsonDocument entity, int[] ids, int nodeType, int projNodeId, int engId) { if (entity == null) { throw new ArgumentNullException(); } InvokeResult result = new InvokeResult(); var needCreate = 0; var needCopy = 0; try { if (!CheckName(entity.Int("bookId"), entity.Int("type"), entity.Text("name"), nodeType, projNodeId)) { result.Status = Status.Failed; result.Message = "名称不能重复"; return(result); } List <BsonDocument> newBookPageList = new List <BsonDocument>(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0))) { if (entity.Int("bookId") == 0) { if (entity.Int("refBookId") == -1 || entity.Int("refBookId") == 0) { needCreate = 1; this._ctx.Update(entity, string.Format("refBookId={0}", "")); } else { needCopy = 1; } result = this._ctx.Insert("BookTask", entity); if (result.Status != Status.Successful) { return(result); } if (projNodeId != 0) { BsonDocument epsSummary = new BsonDocument(); epsSummary.Add("bookId", entity.Int("bookId")); epsSummary.Add("nodeType", nodeType); switch (nodeType) { case 0: default: epsSummary.Add("engId", projNodeId); break; case 1: case 2: epsSummary.Add("engId", engId); epsSummary.Add("epsId", projNodeId); break; case 3: epsSummary.Add("engId", engId); epsSummary.Add("projId", projNodeId); break; } result = this._ctx.Insert("EpsSummary", epsSummary); if (result.Status != Status.Successful) { return(result); } } } else { var rootPage = entity.ChildBsonList("BookPage").Where(m => m.Int("nodePid") == 0).FirstOrDefault(); if (rootPage != null) { var rootPageUpdateBson = new BsonDocument(); rootPageUpdateBson.Add("name", entity.Text("name")); this._ctx.Update(rootPage, rootPageUpdateBson); } } var bookId = entity.Int("bookId"); var delBsonList = this._ctx.FindAllByKeyVal("BookTaskPattern", "bookId", entity.Text("bookId")).ToList(); if (delBsonList.Count() > 0) { this._ctx.QuickDelete("BookTaskPattern", delBsonList); } if (ids.Count() > 0) { List <BsonDocument> bookTaskPatterns = new List <BsonDocument>(); foreach (var id in ids) { var newBsonDoc = new BsonDocument(); newBsonDoc.Add("bookId", bookId); newBsonDoc.Add("patternId", id); bookTaskPatterns.Add(newBsonDoc); } this._ctx.QuickInsert("BookTaskPattern", bookTaskPatterns); } #region 默认创建一个页面 if (needCreate == 1) { var bookPage = new BsonDocument(); bookPage.Add("name", entity.Text("name")); bookPage.Add("IsPageTempate", entity.Text("name")); bookPage.Add("lastVersion", 0); bookPage.Add("categoryId", entity.Text("categoryId")); List <BsonDocument> bookPageList = new List <BsonDocument>(); bookPageList.Add(bookPage); List <int> temp = new List <int>(); BookPageBll._(this._ctx).Create(bookPageList, 0, entity.Int("bookId"), temp); } if (needCopy == 1) { var updateBookTaskBson = new BsonDocument(); var bookTask = this._ctx.FindOneByKeyVal("BookTask", "bookId", entity.Text("refBookId")); updateBookTaskBson.Add("refTime", bookTask.Int("refTime") + 1); this._ctx.Update(bookTask, updateBookTaskBson); var oldBookPageList = bookTask.ChildBsonList("BookPage").ToList(); CopyNode(newBookPageList, oldBookPageList, 0, null, entity); } #endregion scope.Complete(); //#region 添加索引 //if (entity.type == 0) //{ // try // { // BuildIndex(entity); // } // catch (Exception ex) // { } //} //#endregion } //建设索引 //foreach (var bookPage in newBookPageList) // BookPageBll._(this._ctx).BuildIndex(bookPage); result.Status = Status.Successful; result.Message = "保存成功!"; } catch (Exception ex) { result.Status = Status.Failed; result.Message = ex.Message; } return(result); }
/// <summary> /// 保存任务书模板 /// </summary> /// <param name="entity"></param> /// <param name="ids"></param> /// <returns></returns> public InvokeResult Save(BsonDocument entity, BsonDocument updateEntityBson, int[] ids) { if (entity == null) { throw new ArgumentNullException(); } InvokeResult result = new InvokeResult(); var needCreate = 0; var needCopy = 0; try { if (!CheckTemplateName(entity.Int("bookId"), entity.Int("type"), string.IsNullOrEmpty(updateEntityBson.Text("name")) ? entity.Text("name") : updateEntityBson.Text("name"), entity.Int("categoryId"))) { result.Status = Status.Failed; if (entity.Int("type") == 0) { result.Message = "任务书名称不能重复!"; } else { result.Message = "任务书模板名称不能重复!"; } return(result); } List <BsonDocument> newBookPageList = new List <BsonDocument>(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0))) { var entityUpdateBson = new BsonDocument(); if (entity.Int("bookId") == 0) { if (entity.Int("refBookId") == -1 || string.IsNullOrEmpty(entity.Text("refBookId"))) { needCreate = 1; entity.Add("refBookId", ""); } else { needCopy = 1; } //entity.Add("type", "1"); result = this._ctx.Insert("BookTask", entity); if (result.Status != Status.Successful) { return(result); } else { entity = result.BsonInfo; } } else { var entityResult = this._ctx.Update(entity, updateEntityBson); if (entityResult.Status != Status.Successful) { return(entityResult); } entity = entityResult.BsonInfo; var rootPage = entity.ChildBsonList("BookPage").Where(m => m.Int("nodePid") == 0).FirstOrDefault(); if (rootPage != null) { var rootPageUpdateBson = new BsonDocument(); rootPageUpdateBson.Add("name", entity.Text("name")); this._ctx.Update(rootPage, rootPageUpdateBson); } } var bookId = entity.Int("bookId"); var delBsonList = this._ctx.FindAll("BookTaskPattern").Where(x => x.Int("bookId") == entity.Int("bookId")).ToList();//.FindAllByKeyVal("BookTaskPattern", "bookId", entity.Text("bookId")).ToList(); if (delBsonList.Count() > 0) { this._ctx.QuickDelete("BookTaskPattern", delBsonList); } if (ids.Count() > 0) { List <BsonDocument> bookTaskPatterns = new List <BsonDocument>(); foreach (var id in ids) { var newBsonDoc = new BsonDocument(); newBsonDoc.Add("bookId", bookId); newBsonDoc.Add("patternId", id); bookTaskPatterns.Add(newBsonDoc); } this._ctx.QuickInsert("BookTaskPattern", bookTaskPatterns); } #region 默认创建一个页面 if (needCreate == 1) { var bookPage = new BsonDocument(); bookPage.Add("name", entity.Text("name")); bookPage.Add("IsPageTempate", entity.Text("name")); bookPage.Add("lastVersion", 0); bookPage.Add("categoryId", entity.Text("categoryId")); List <BsonDocument> bookPageList = new List <BsonDocument>(); bookPageList.Add(bookPage); List <int> temp = new List <int>(); BookPageBll._(this._ctx).Create(bookPageList, 0, entity.Int("bookId"), temp); } if (needCopy == 1) { var updateBookTaskBson = new BsonDocument(); var bookTask = this._ctx.FindOneByKeyVal("BookTask", "bookId", entity.Text("refBookId")); updateBookTaskBson.Add("refTime", bookTask.Int("refTime") + 1); this._ctx.Update(bookTask, updateBookTaskBson); var oldBookPageList = bookTask.ChildBsonList("BookPage").ToList(); CopyNode(newBookPageList, oldBookPageList, 0, null, entity); } #endregion scope.Complete(); } if (entity.Int("type") == 0) { try { //BuildIndex(entity); } catch (Exception ex) { } } result.Status = Status.Successful; result.Message = "保存成功!"; } catch (Exception ex) { result.Status = Status.Failed; result.Message = ex.Message; } return(result); }