/// <summary> /// 将xmlNode转化为布局元素 /// </summary> /// <param name="node"></param> /// <returns></returns> public static ElementEntity XmlNodeToElement(XmlNode node) { ElementEntity elementEntity = new ElementEntity(); if (node != null) { //转化属性 XmlAttribute id_attribute = node.Attributes["android:id"]; //转化基本信息 elementEntity.type = node.Name; if (id_attribute != null) { elementEntity.id = id_attribute.Value.Replace("@+id/", ""); } //转化所有子信息 //处理当前结点 foreach (XmlAttribute item in node.Attributes) { elementEntity.addAttribute(item.Name, item.InnerText); } } return(elementEntity); }
// PUT api/element/5 /// <summary> /// Update an element. Add Header with Token "authToken" /// </summary> /// <param name="id">Element Id</param> /// <param name="elementEntity">SParameters set</param> /// <returns></returns> public HttpResponseMessage Put(int id, [FromBody] ElementEntity elementEntity) { try { if (elementEntity != null) { if (ModelState.IsValid) { if (id > 0) { return(Request.CreateResponse(HttpStatusCode.OK, _elementServices.UpdateElement(id, elementEntity))); } else { throw new ApiBusinessException(2004, "Object not updated. There is no Element with Id:" + id, HttpStatusCode.NotModified); } } else { throw new ApiBusinessException(2003, "Bad Request. Invalid object", HttpStatusCode.BadRequest); } } throw new ApiBusinessException(2002, "Bad Request. Null element", HttpStatusCode.BadRequest); } catch { throw new ApiDataException(3001, "Internal error", HttpStatusCode.InternalServerError); } }
ArrayJoinUtil definition = new ArrayJoinUtil(); //定义数组 public override string handler(ElementEntity tnode) { foreach (var item in XmlTreeHandler.getAllElement(tnode, XmlTreeHandler.elementStatus.hasId)) { String resultDeclaration = ""; String resultdefinition = ""; String id = item.id; if (isUpper)//首字母是否大写 { id = item.id.firstToUpper(); } switch (type) { case javaTypeEnum.standard: resultDeclaration = String.Format("" + modifier + " {0} " + prefix + "{1}" + subffix + ";\n", item.type, id); resultdefinition = String.Format("" + prefix + "{0}=({1}) findViewById(R.id.{2});\n", id, item.type, item.id); break; case javaTypeEnum.annotations: resultDeclaration = String.Format(@" @ViewById {2} {0} {1};", item.type, item.id, modifier); break; case javaTypeEnum.xutils: resultDeclaration = String.Format(@" @ViewInject(R.id.{0}) " + modifier + " {1} " + prefix + "{2};" + subffix + "", item.id, item.type, id); break; } declaration.add(resultDeclaration); definition.add(resultdefinition); } return(""); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, ElementEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
public override string handler(ElementEntity tnode) { List <ElementEntity> list = XmlTreeHandler.getAllElement(tnode, XmlTreeHandler.elementStatus.hasId); //生成getViewItem中的部分代码 StringBuilder builder = new StringBuilder(); builder.Append("\n\n\n"); //生成viewHolder对象 builder.Append(getViewHoler(list)); return(builder.ToString()); }
/// <summary> /// Returns the element as an <see cref="ElementEntity"/> object. /// </summary> /// <returns></returns> internal ElementEntity ToEntity() { var entity = new ElementEntity { Title = _title, SubTitle = _subTitle, ImageUrl = _imageUrl?.ToString(), DefaultAction = _defaultAction?.ToEntity(), Buttons = _buttons?.Select(_ => _.ToEntity()).ToList() }; return(entity); }
public HttpRequestMessage SaveElement(ElementModel model) { var document = (IHtmlPageDocument)Session[SessionNameDocument]; var elementEntity = new ElementEntity { TagName = model.TagName, XPath = document.GetXpathElement(model.ElementId), Value = document.GetHashObjectValue(document.GetXpathElement(model.ElementId) /*TODO FIX*/) }; _service.Insert(elementEntity); return(null); }
/// <summary> /// Creates a element /// </summary> /// <param name="ElementEntity"></param> /// <returns></returns> public int CreateElement(ElementEntity ElementEntity) { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { var element = new Element { Name = ElementEntity.Name, Created = ElementEntity.Created, Modified = ElementEntity.Modified }; _unitOfWork.ElementRepository.Insert(element); _unitOfWork.Save(); scope.Complete(); return(element.Id); } }
/// <summary> /// 递归加载树结构 /// </summary> /// <param name="root"></param> /// <param name="rootNode"></param> private void searchThree(XmlNode root, TreeNode rootNode, ElementEntity element) { foreach (XmlNode item in root.ChildNodes) { //初始化当前结点 TreeNode tNode = new TreeNode(); tNode.Text = item.Name; //处理布局元素对象 ElementEntity elementitem = XmlTreeHandler.XmlNodeToElement(item); element.addElement(elementitem); tNode.Tag = elementitem;//树里面放布局元素对象 rootNode.Nodes.Add(tNode); //处理该结点的子节点 searchThree(item, tNode, elementitem); } }
public override string handler(ElementEntity tnode) { StringBuilder builder = new StringBuilder(); foreach (var item in XmlTreeHandler.getAllElement(tnode)) { if (item.hasAttribute("android:onClick") && item.hasAttribute("android:text")) { builder.Append(string.Format("\t\t\t/**\n\t\t\t* {0}\n\t\t\t* @param view\n\t\t\t*/\n\t\t\t", item.getAttribute("android:text"))); } if (item.hasAttribute("android:onClick")) { builder.Append(string.Format("public void {0}(View view){{\n\t\n\t\t\t}}\n", item.getAttribute("android:onClick"))); } } return(builder.ToString()); }
/// <summary> /// 获取当前结点下的所有子元素 /// </summary> /// <param name="rootEntity"></param> /// <returns></returns> public static List <ElementEntity> getAllElement(ElementEntity rootEntity, elementStatus status = elementStatus.noId) { bool isOk = false; List <ElementEntity> list = new List <ElementEntity>(); if (status == elementStatus.hasId) { isOk = true; } if (!(isOk && string.IsNullOrEmpty(rootEntity.id))) { list.Add(rootEntity); } foreach (var item in rootEntity.Elements) { list.AddRange(getAllElement(item, status)); } return(list); }
public override string handler(ElementEntity tnode) { var styleBuilder = new StringBuilder(); var oldArributeText = new StringBuilder(); foreach (var itemNode in XmlTreeHandler.getAllElement(tnode)) { if (itemNode.type == null) { continue; } oldArributeText.Append("<" + itemNode.type + "\n"); //========生成style======== styleBuilder.Append("/*样式代码*/\n\n"); //头处理 styleBuilder.Append(string.Format("<style name=\"{0}_style\">\n", styleName)); //处理当前结点 foreach (var item in itemNode.getAttributes()) { //不需要执行的跳过 if (Regex.IsMatch(item.Key, RegexStr)) { oldArributeText.Append(String.Format("{0}=\"{1}\"\n", item.Key, item.Value)); continue; } if (Regex.IsMatch(item.Value, textRegexStr)) { oldArributeText.Append(String.Format("{0}=\"{1}\"\n", item.Key, item.Value)); continue; } styleBuilder.Append(string.Format("<item name=\"{0}\">{1}</item>\n", item.Key, item.Value)); } //尾处理 styleBuilder.Append("</style>\n\n"); oldArributeText.Append(string.Format("android:style=\"@style/{0}_style\" />", styleName)); styleBuilder.Append("\n\n"); styleBuilder.Append("/*原来的xml元素代码*/\n\n"); } return(styleBuilder.Append(oldArributeText).ToString()); }
/// <summary> /// Updates a element /// </summary> /// <param name="elementId"></param> /// <param name="ElementEntity"></param> /// <returns></returns> public bool UpdateElement(int elementId, ElementEntity ElementEntity) { var success = false; if (ElementEntity != null) { using (var scope = new TransactionScope()) { var element = _unitOfWork.ElementRepository.GetByID(elementId); if (element != null) { element.Name = ElementEntity.Name; _unitOfWork.ElementRepository.Update(element); _unitOfWork.Save(); scope.Complete(); success = true; } } } return(success); }
/// <summary> /// 初始化xml文档结构 /// </summary> private void InitTree() { /* * 主要思想就是:递归解析xml生成树节点,树节点绑定了布局元素信息对象 */ treeView.Nodes.Clear(); //xml文档=结构 doc = new XmlDocument(); doc.LoadXml(oldText); root = doc.DocumentElement; ElementEntity rootElementEntity = new ElementEntity(); rootNode = new TreeNode(); rootNode.Text = root.Name; rootNode.Tag = rootElementEntity; searchThree(root, rootNode, rootElementEntity); treeView.Nodes.Add(rootNode); treeView.ExpandAll(); treeView.SelectedNode = rootNode; }
// POST api/element /// <summary> /// Creates a new element. Add Header with Token "authToken" /// </summary> /// <param name="elementEntity">Parameters set</param> /// <returns>Id of the element</returns> public HttpResponseMessage Post([FromBody] ElementEntity elementEntity) { try { if (elementEntity != null) { if (ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.OK, _elementServices.CreateElement(elementEntity))); } else { throw new ApiBusinessException(2003, "Bad Request. Invalid object", HttpStatusCode.BadRequest); } } throw new ApiBusinessException(2002, "Bad Request. Null element", HttpStatusCode.BadRequest); } catch { throw new ApiDataException(3001, "Internal error", HttpStatusCode.InternalServerError); } }
public ActionResult SaveForm(string keyValue, ElementEntity entity) { elementbll.SaveForm(keyValue, entity); return(Success("操作成功。")); }
public abstract string handler(ElementEntity tnode);
public string ImportStandard(string standardtype, string categorycode) { if (OperatorProvider.Provider.Current().IsSystem) { return("超级管理员无此操作权限"); } string orgId = OperatorProvider.Provider.Current().OrganizeId;//所属公司 int error = 0; string message = "请选择文件格式正确的文件再导入!"; string falseMessage = ""; int count = HttpContext.Request.Files.Count; if (count > 0) { if (HttpContext.Request.Files.Count != 2) { return("请按正确的方式导入两个文件."); } HttpPostedFileBase file = HttpContext.Request.Files[0]; HttpPostedFileBase file2 = HttpContext.Request.Files[1]; if (string.IsNullOrEmpty(file.FileName) || string.IsNullOrEmpty(file2.FileName)) { return(message); } Boolean isZip1 = file.FileName.Substring(file.FileName.IndexOf('.')).Contains("zip"); //第一个文件是否为Zip格式 Boolean isZip2 = file2.FileName.Substring(file2.FileName.IndexOf('.')).Contains("zip"); //第二个文件是否为Zip格式 if ((isZip1 || isZip2) == false || (isZip1 && isZip2) == true) { return(message); } string fileName1 = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName); file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName1)); string fileName2 = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file2.FileName); file2.SaveAs(Server.MapPath("~/Resource/temp/" + fileName2)); string decompressionDirectory = Server.MapPath("~/Resource/decompression/") + DateTime.Now.ToString("yyyyMMddhhmmssfff") + "\\"; Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(); if (isZip1) { UnZip(Server.MapPath("~/Resource/temp/" + fileName1), decompressionDirectory, "", true); wb.Open(Server.MapPath("~/Resource/temp/" + fileName2)); } else { UnZip(Server.MapPath("~/Resource/temp/" + fileName2), decompressionDirectory, "", true); wb.Open(Server.MapPath("~/Resource/temp/" + fileName1)); } Aspose.Cells.Cells cells = wb.Worksheets[0].Cells; DataTable dt = cells.ExportDataTable(2, 0, cells.MaxDataRow - 1, cells.MaxColumn + 1, false); for (int i = 1; i < dt.Rows.Count; i++) { //文件名称 string filename = dt.Rows[i][0].ToString(); //文件路径 string filepath = dt.Rows[i][1].ToString(); //相应元素 string relevantelement = ""; string relevantelementname = ""; string relevantelementid = ""; //实施日期 string carrydate = ""; if (standardtype == "1" || standardtype == "2" || standardtype == "3" || standardtype == "4" || standardtype == "5" || standardtype == "6") { relevantelement = dt.Rows[i][2].ToString(); carrydate = dt.Rows[i][3].ToString(); } //文学字号 string dispatchcode = ""; //颁布部门 string publishdept = ""; if (standardtype == "6") { dispatchcode = dt.Rows[i][4].ToString(); publishdept = dt.Rows[i][5].ToString(); } string dutyid = ""; string dutyName = ""; //---****值存在空验证*****-- if (string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(filepath)) { falseMessage += "</br>" + "第" + (i + 3) + "行值存在空,未能导入."; error++; continue; } //---****文件格式验证*****-- if (!(filepath.Substring(filepath.IndexOf('.')).Contains("doc") || filepath.Substring(filepath.IndexOf('.')).Contains("docx") || filepath.Substring(filepath.IndexOf('.')).Contains("pdf"))) { falseMessage += "</br>" + "第" + (i + 3) + "行附件格式不正确,未能导入."; error++; continue; } //---****文件是否存在验证*****-- if (!System.IO.File.Exists(decompressionDirectory + filepath)) { falseMessage += "</br>" + "第" + (i + 3) + "行附件不存在,未能导入."; error++; continue; } //--**验证岗位是否存在 * *-- int startnum = 4; if (standardtype == "1" || standardtype == "2" || standardtype == "3" || standardtype == "4" || standardtype == "5") { startnum = 4; } else if (standardtype == "6") { startnum = 6; } else if (standardtype == "7" || standardtype == "8" || standardtype == "9") { startnum = 2; } for (int j = startnum; j < dt.Columns.Count; j++) { if (!dt.Rows[i][j].IsEmpty()) { foreach (var item in dt.Rows[i][j].ToString().Split(',')) { DepartmentEntity dept = DepartmentBLL.GetList().Where(t => t.OrganizeId == orgId && t.FullName == dt.Rows[0][j].ToString()).FirstOrDefault(); if (dept == null) { continue; } RoleEntity re = postBLL.GetList().Where(a => a.FullName == item.ToString() && a.OrganizeId == orgId && a.DeleteMark == 0 && a.EnabledMark == 1 && a.DeptId == dept.DepartmentId).FirstOrDefault(); if (re == null) { //falseMessage += "</br>" + "第" + (i + 3) + "行岗位有误,未能导入."; //error++; continue; } else { dutyid += re.RoleId + ","; dutyName += re.FullName + ","; } } } } dutyid = dutyid.Length > 0 ? dutyid.Substring(0, dutyid.Length - 1) : ""; dutyName = dutyName.Length > 0 ? dutyName.Substring(0, dutyName.Length - 1) : ""; StandardsystemEntity standard = new StandardsystemEntity(); try { if (!string.IsNullOrEmpty(carrydate)) { standard.CARRYDATE = DateTime.Parse(DateTime.Parse(carrydate).ToString("yyyy-MM-dd")); } } catch { falseMessage += "</br>" + "第" + (i + 3) + "行时间有误,未能导入."; error++; continue; } if (!string.IsNullOrEmpty(relevantelement)) { foreach (var item in relevantelement.Split(',')) { ElementEntity re = elementBLL.GetList("").Where(a => a.NAME == item.ToString()).FirstOrDefault(); if (re == null) { //falseMessage += "</br>" + "第" + (i + 2) + "行相应元素有误,未能导入."; //error++; continue; } else { relevantelementname += re.NAME + ","; relevantelementid += re.ID + ","; } } } relevantelementname = string.IsNullOrEmpty(relevantelementname) ? "" : relevantelementname.Substring(0, relevantelementname.Length - 1); relevantelementid = string.IsNullOrEmpty(relevantelementid) ? "" : relevantelementid.Substring(0, relevantelementid.Length - 1); standard.FILENAME = filename; standard.STATIONID = dutyid; standard.STATIONNAME = dutyName; standard.RELEVANTELEMENTNAME = relevantelementname; standard.RELEVANTELEMENTID = relevantelementid; standard.DISPATCHCODE = dispatchcode; standard.PUBLISHDEPT = publishdept; standard.STANDARDTYPE = standardtype; standard.CATEGORYCODE = categorycode; standard.CONSULTNUM = 0; standard.ID = Guid.NewGuid().ToString(); var fileinfo = new FileInfo(decompressionDirectory + filepath); FileInfoEntity fileInfoEntity = new FileInfoEntity(); string fileguid = Guid.NewGuid().ToString(); fileInfoEntity.Create(); fileInfoEntity.RecId = standard.ID; //关联ID fileInfoEntity.FileName = filepath; fileInfoEntity.FilePath = "~/Resource/StandardSystem/" + fileguid + fileinfo.Extension; fileInfoEntity.FileSize = (Math.Round(decimal.Parse(fileinfo.Length.ToString()) / decimal.Parse("1024"), 2)).ToString();//文件大小(kb) fileInfoEntity.FileExtensions = fileinfo.Extension; fileInfoEntity.FileType = fileinfo.Extension.Replace(".", ""); TransportRemoteToServer(Server.MapPath("~/Resource/StandardSystem/"), decompressionDirectory + filepath, fileguid + fileinfo.Extension); fileinfobll.SaveForm("", fileInfoEntity); try { standardsystembll.SaveForm(standard.ID, standard); } catch { error++; } } count = dt.Rows.Count - 1; message = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条"; message += "</br>" + falseMessage; } return(message); }
public void Insert(ElementEntity entity) { _dataBase.Insert(entity); }
public int[] PathsWithMaxScore(IList <string> board) { var constNum = (int)1e9 + 7; var rows = board.Count; var cols = board.First().Length; var dp = new ElementEntity[rows, cols]; dp[rows - 1, cols - 1] = new ElementEntity(0, 1); for (int colIndex = cols - 2; colIndex >= 0; colIndex--) { if (board[rows - 1][colIndex] == 'X') { continue; } var intTemp = int.Parse(board[rows - 1][colIndex].ToString()); if (dp[rows - 1, colIndex + 1] != null) { dp[rows - 1, colIndex] = new ElementEntity(dp[rows - 1, colIndex + 1].TotalNum + intTemp, 1); } } for (int rowIndex = rows - 2; rowIndex >= 0; rowIndex--) { if (board[rowIndex][cols - 1] == 'X') { continue; } var intTemp = int.Parse(board[rowIndex][cols - 1].ToString()); if (dp[rowIndex + 1, cols - 1] != null) { dp[rowIndex, cols - 1] = new ElementEntity(dp[rowIndex + 1, cols - 1].TotalNum + intTemp, 1); } } for (int rowIndex = rows - 2; rowIndex >= 0; rowIndex--) { for (int colIndex = cols - 2; colIndex >= 0; colIndex--) { if (board[rowIndex][colIndex] == 'X') { continue; } var maxNum = 0; var right = dp[rowIndex, colIndex + 1]; if (right != null) { maxNum = Math.Max(maxNum, right.TotalNum); } var down = dp[rowIndex + 1, colIndex]; if (down != null) { maxNum = Math.Max(maxNum, down.TotalNum); } var rd = dp[rowIndex + 1, colIndex + 1]; if (rd != null) { maxNum = Math.Max(maxNum, rd.TotalNum); } if (right == null && down == null && rd == null) { continue; } var totalPath = 0; if (right != null && maxNum == right.TotalNum) { totalPath += right.Count; totalPath %= constNum; } if (down != null && maxNum == down.TotalNum) { totalPath += down.Count; totalPath %= constNum; } if (rd != null && maxNum == rd.TotalNum) { totalPath += rd.Count; totalPath %= constNum; } var curValue = 0; if (rowIndex != 0 || colIndex != 0) { curValue = int.Parse(board[rowIndex][colIndex].ToString()); } if (totalPath == 0) { dp[rowIndex, colIndex] = new ElementEntity(curValue, 1); } else { dp[rowIndex, colIndex] = new ElementEntity(curValue + maxNum, totalPath); } } } if (dp[0, 0] == null) { return new int[] { 0, 0 } } ; return(new int[] { dp[0, 0].TotalNum, dp[0, 0].Count }); } }
/// <summary> /// 根据结点处理字符串 /// </summary> /// <param name="tnode"></param> /// <returns></returns> public virtual string excute(TreeNode tnode) { ElementEntity node = tnode.Tag as ElementEntity; return(handler(node)); }