当前位置: 首页 > news >正文

出入广州最新通知今天南昌seo计费管理

出入广州最新通知今天,南昌seo计费管理,网站策划书注意事项,公司网站建设分录一个项目涉及XML文档中节点的自动计算,就是XML文档的每个节点都参与运算,要求: ⑴如果节点有计算公式则按照计算公式进行; ⑵如果节点没有计算公式则该节点的值就是所有子节点的值之和; ⑶节点有4种类型,计…

  一个项目涉及XML文档中节点的自动计算,就是XML文档的每个节点都参与运算,要求:

  ⑴如果节点有计算公式则按照计算公式进行;

  ⑵如果节点没有计算公式则该节点的值就是所有子节点的值之和;

  ⑶节点有4种类型,计算节点、输入框、单选节点、多选节点;

    计算节点:汇总;

    输入框:点击该节点弹出输入框用于输入数据;

    单选节点:众多选项中只能选择一个,根据选择项确定该节点的具体值;

    多选节点:众多选项中可以选择多个,该节点的值是所有选择项的和;

  类似下图(实际选项近100个):

  问题是点击任何图标节点后都要完成的自动计算。

  开始的时候,我将所有XML信息加载到Treeview中,包括属性,在Treeview中进行计算,完成后同步到XML文档,这样完成后效果不好,选项多了速度慢,如果计算机配置一般的话有略微的卡顿。

  今天下午,我修改了方法,直接在XML文档中进行操作,使用递归完成节点的自动计算,这样速度很快,并且不需要同步到Treeview中(因为Treeview只是用于显示)。

  1、点击节点

  在Treeview中确定节点,根据节点类型完成图标变化,在XML中找到对应的节点。

  ⑴完成状态标识,如果是Radio则标识单选;如果是Checkbox标识多选;

  ⑵提取Value值,如果是Textbox则是输入值,如果是Radio则是父项value值是点击节点的Value值;如果是Checkbox则父项是所有选择项的value值之和。

  ⑶调用自动计算,如果是Radio或者Checkbox则是从父项的父项开始,如果是Textbox则是从父项开始。

        private void treeView1_MouseDown(object sender, MouseEventArgs e){//获取鼠标点击的位置TreeNode FocusNode = treeView1.GetNodeAt(e.Location);string StrCurrentFullPath = FocusNode.FullPath;string StrNodeType = "";if (FocusNode != null){//获取鼠标点击的位置是否在节点的图标上//在Treeview中针对Radio、Checkbox、TextBook分别进行设置TreeViewHitTestInfo hitTestInfo = treeView1.HitTest(e.Location);if (hitTestInfo.Location == TreeViewHitTestLocations.Image){StrNodeType = FocusNode.Tag.ToString();//鼠标点击了节点的图标switch (StrNodeType){case "Radio":// 取消同级节点的选中状态foreach (TreeNode node1 in FocusNode.Parent.Nodes){if (node1 != FocusNode){node1.ImageKey = "Radio";node1.SelectedImageKey = "Radio";}}// 设置当前节点为选中状态FocusNode.ImageKey = "RadioChecked";FocusNode.SelectedImageKey = "RadioChecked";//在XML文档中处理HandleNodeInfoAtXmlContent(StrCurrentFullPath, StrNodeType,"");//在文档中找到该节点并处理//break;case "Checkbox":if (FocusNode.ImageKey == "Checkbox"){FocusNode.ImageKey = "CheckboxChecked";FocusNode.SelectedImageKey = "CheckboxChecked";}else{FocusNode.ImageKey = "Checkbox";FocusNode.SelectedImageKey = "Checkbox";}//在XML文档中处理HandleNodeInfoAtXmlContent(StrCurrentFullPath, StrNodeType,"");//在文档中找到该节点并处理break;case "Textbox":string StrMin = "";string StrMax = "";string StrMemo = "";float fTemp;ToTextboxInputWinPara.fMax = 0;ToTextboxInputWinPara.fMin = 0;ToTextboxInputWinPara.StrMemo = "";FrmTextBoxInput FTI= new FrmTextBoxInput();DialogResult result= FTI.ShowDialog();if(result == DialogResult.OK){StrCurrentTextboxValue = FTI.StrReturn;}//在XML文档中处理HandleNodeInfoAtXmlContent(StrCurrentFullPath, StrNodeType, StrCurrentTextboxValue);//在文档中找到该节点并处理break;}treeView1.Invalidate();}if (hitTestInfo.Location == TreeViewHitTestLocations.Label){//点击标签if (FocusNode.Tag != null){switch (FocusNode.Tag.ToString()){case "Radio":if (FocusNode.ImageKey == "RadioChecked"){FocusNode.SelectedImageKey = "RadioChecked";}if (FocusNode.ImageKey == "Radio"){FocusNode.SelectedImageKey = "Radio";}break;case "Checkbox":if (FocusNode.ImageKey == "Checkbox"){FocusNode.SelectedImageKey = "Checkbox";}if (FocusNode.ImageKey == "CheckboxChecked"){FocusNode.SelectedImageKey = "CheckboxChecked";}break;default: break;}treeView1.Invalidate();}}}}

  对应在XML文档中的处理函数:

        private void HandleNodeInfoAtXmlContent(string StrCurrentFullPath,string StrNodeType,string StrInputTextValue){//在XML文档内容中处理节点信息,传入参数:StrCurrentFullPath是当前点击选择的节点全路径名称int FirstIndex = StrCurrentFullPath.IndexOf("\\");int LastIndex = StrCurrentFullPath.LastIndexOf("\\");string StrCurrentNodeName = StrCurrentFullPath.Substring(LastIndex + 1);//提取父节点的名称string[] SubStr= StrCurrentFullPath.Split("\\");string ParentStr = SubStr[SubStr.Length - 2];// 使用XPath表达式定位到具体的节点,点击的节点名称是caption值string XpathExpression="";XmlNode CalculateNode=null;//计算节点switch (StrNodeType){case "Radio":XpathExpression = "//" + ParentStr + "/option[@caption='" + StrCurrentNodeName + "']";break;case "Checkbox":XpathExpression = "//" + ParentStr + "/input[@caption='" + StrCurrentNodeName + "']";break;case "Textbox":XpathExpression = "//" + ParentStr + "/"+ StrCurrentNodeName;break;}XmlNode BeSelectNode = XmlDoc.SelectSingleNode(XpathExpression);//得到父节点的全路径名string SParentPath = StrCurrentFullPath.Substring(0, LastIndex);//得到父节点XmlNode ParentNode = FindNodeAtXmlContentByFullPath(SParentPath);XmlNode TempNode = null;if (BeSelectNode != null && ParentNode!=null){//根据节点类型处理本节点switch (StrNodeType){case "Radio":string StrValue = "";//找到该节点标识选中状态foreach (XmlNode RadioChildNode in ParentNode.ChildNodes){//单选,先将父节点下的子节点的select属性全部删除if (RadioChildNode.Attributes["select"] != null){RadioChildNode.Attributes.Remove(RadioChildNode.Attributes["select"]);}//找到子节点if (RadioChildNode.Attributes["caption"].Value == StrCurrentNodeName){TempNode = RadioChildNode;StrValue = TempNode.Attributes["value"].Value;}}//添加select属性if (TempNode!=null){                                if (HasAttribute(TempNode, "select")){TempNode.Attributes["select"].Value = "true";}else{XmlAttribute RadioNodeAttr = XmlDoc.CreateAttribute("select");RadioNodeAttr.Value = "true";TempNode.Attributes.Append(RadioNodeAttr);}}//为父节点的value属性赋值ParentNode.Attributes["value"].Value = StrValue;//寻找父节点的父节点CalculateNode = ParentNode.ParentNode;//计算Autocalculate(CalculateNode);break;case "Checkbox":Single TempSum = 0.0f;//找到该节点标识状态,如果是选择则去掉,没有选择则加上,同时计算和foreach (XmlNode CheckChildNode in ParentNode.ChildNodes){if (CheckChildNode.Attributes["caption"].Value == StrCurrentNodeName){TempNode = CheckChildNode;}}//添加select属性if (HasAttribute(TempNode, "select")){if (TempNode.Attributes["select"].Value == "true"){//如果已经选择了,需要去掉选择TempNode.Attributes.Remove(TempNode.Attributes["select"]);}else{TempNode.Attributes["select"].Value = "true";}}else{XmlAttribute CheckSelectedAttr = XmlDoc.CreateAttribute("select");CheckSelectedAttr.Value = "true";TempNode.Attributes.Append(CheckSelectedAttr);}foreach (XmlNode CheckChildNode in ParentNode.ChildNodes){if (HasAttribute(CheckChildNode, "select")){TempSum += Convert.ToSingle(CheckChildNode.Attributes["value"].Value);}}//为父节点的value属性赋值ParentNode.Attributes["value"].Value = TempSum.ToString();//寻找父节点的父节点CalculateNode = ParentNode.ParentNode;//计算Autocalculate(CalculateNode);break;case "Textbox"://找到该节点修改Value值BeSelectNode.Attributes["value"].Value = StrInputTextValue;//寻找本节点的父节点CalculateNode = BeSelectNode.ParentNode;//计算Autocalculate(CalculateNode);break;}}else{textBox1.Text += "提取属性值发生错误,没有找到对应节点或者属性值错误!" + Environment.NewLine;}}

  2、递归计算

        private void Autocalculate(XmlNode CalculateNode){//在XML文档中,节点自动计算结果//CalculateResult MyCalcuteResult= new CalculateResult();float fSum = 0f;string StrID = "";string StrValue = "";string StrFormula = "";Boolean Continue = true;string StrFalse = "";//判断是否有子节点if (CalculateNode.HasChildNodes){//有子节点需要看是否有计算公式,根据指定的节点进行自动计算if (HasAttribute(CalculateNode, "formula")){//如果节点有formula属性,则提取出计算公式。StrFormula = GetAttrValue(CalculateNode, "formula");//将所有子节点的值进行替换完成后再进行计算。foreach (XmlNode MyNode in CalculateNode.ChildNodes){if (HasAttribute(MyNode,"id")){StrID = MyNode.Attributes["id"].Value;StrValue = MyNode.Attributes["value"].Value;if (StrValue.IsNullOrEmpty()){Continue = false;StrFalse = $"{StrID}为空";break;}else{//替换公式中的字符串,ID和值StrFormula = StrFormula.Replace(StrID, StrValue);}}else{Continue = false;}}if (Continue){//进行计算获得结果fSum = GetFormulaResult(StrFormula);}}else{//没有formula属性,计算结果等于所有子节点的和。foreach (XmlNode MyNode in CalculateNode.ChildNodes){StrValue = MyNode.Attributes["value"].Value;if (StrValue.IsNullOrEmpty()){Continue = false;StrFalse = MyNode.Name +"的值为空";break;}else{fSum += Convert.ToSingle(StrValue);}}}if (Continue){//修改本节点的Value属性CalculateNode.Attributes["value"].Value = fSum.ToString();}CalculateNode = CalculateNode.ParentNode;//if (CalculateNode.NodeType == XmlNodeType.Document)if(CalculateNode==null){StrFalse = "没有了父节点";Continue = false;}//是否继续计算if (Continue){Autocalculate(CalculateNode);}else{textBox1.Text += StrFalse+Environment.NewLine;}}}

  这个问题看似简单,实际上也的确不难,就是有一点麻烦,需要耐心去解决细节问题。

http://www.hkea.cn/news/364120/

相关文章:

  • 黑河做网站首页关键词排名优化
  • 网站二级域名怎么解析公司网络搭建
  • wordpress做网店win10优化大师是官方的吗
  • 弄个做网站公司产品宣传
  • 商品房建设信息网站googleplay商店
  • 菏泽 网站建设优化工具箱
  • 网站建设找哪家公司百度搜索热度
  • 网页设计论文引言北海百度seo
  • 网站空间哪家做的好网络营销的常用工具
  • 网站开发具体问题优化营商环境
  • wordpress4.5 火车头廊坊seo培训
  • 怎么做多个网站单点登录艺考培训
  • 网站怎么做双语种seo关键词如何设置
  • 用java做的游戏下载网站有哪些内容成都网络推广优化
  • 慈溪市网站建设google官网
  • 网站建设计划seo网站排名优化软件是什么
  • 大连网站建设谁家好郴州网站定制
  • 网站建设背景怎么写一个企业该如何进行网络营销
  • 为女朋友做的表白网站百度大数据分析工具
  • 上海高端网站建设服务公seo推广公司
  • 找人合伙做网站平台仿站定制模板建站
  • 深圳市网站建设科技公司腾讯网网站网址
  • wordpress语言文件夹seo销售好做吗
  • 河北建设集团官网西安网站seo
  • 在外汇局网站做登记报告恢复原来的百度
  • 做外贸做的很好的网站全国疫情突然又严重了
  • 开发app需要什么样的团队百度seo优化培训
  • ftp上传网站之后软文什么意思范例
  • 询广西南宁网站运营推广系统
  • wordpress侧边栏小工具佛山网站优化