예제 #1
0
 /// <summary>
 /// 重命名节点
 /// </summary>
 /// <param name="strFilePath">XML文件完整路径</param>
 /// <param name="strOldNode">之前的节点名称</param>
 /// <param name="strNewNode">新的节点名称</param>
 /// <returns>true表示重命名成功,false则是失败</returns>
 public bool RenameNode(string strFilePath, string strOldNode, string strNewNode)
 {
     try
     {
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(strFilePath);
         XmlNode xnOldNode = FindNode(xmlDoc.DocumentElement, strOldNode);
         if (xnOldNode == null)
         {
             throw new Exception("未找到该名称的节点!");
         }
         XmlNode xnNewNode = xnOldNode.ParentNode.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, strNewNode, null));
         while (xnOldNode.HasChildNodes)
         {
             xnNewNode.AppendChild(xnOldNode.FirstChild);
             //xnOldNode.RemoveChild(xnOldNode.FirstChild);
         }
         xnOldNode.ParentNode.RemoveChild(xnOldNode);
         xmlDoc.Save(strFilePath);
         return(true);
     }
     catch (Exception ex)
     {
         AxPopMsg.Exception(ex.Message);
         return(false);
     }
 }
예제 #2
0
 /// <summary>
 /// 添加节点
 /// </summary>
 /// <param name="strFilePath">文件路径</param>
 /// <param name="strParentNode">需要添加子节点的节点名称</param>
 /// <param name="strAddNode">添加节点名称</param>
 /// <param name="strExp">执行发生异常提示</param>
 public void AddNode(string strFilePath, string strParentNode, string strAddNode)
 {
     try
     {
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(strFilePath);
         if (strParentNode == "" || strParentNode == null)
         {
             xmlDoc.AppendChild(xmlDoc.CreateElement(strAddNode));
             xmlDoc.Save(strFilePath);
         }
         else
         {
             XmlNode xnParent = FindNode(xmlDoc.DocumentElement, strParentNode);
             xnParent.AppendChild(xmlDoc.CreateElement(strAddNode));
             xmlDoc.Save(strFilePath);
         }
     }
     catch (Exception ex)
     {
         AxPopMsg.Exception(ex.Message);
     }
 }
예제 #3
0
        public void CommLogDisplay(string str, emMsgType nMsgType)
        {
            if (rtboxCMLog.InvokeRequired)
            {
                rtboxCMLog.BeginInvoke(new Action(() =>
                {
                    CommLogDisplay(str, nMsgType);
                }
                                                  ));
                return;
            }
            try
            {
                if (rtboxCMLog.Lines.Length > 200)
                {
                    rtboxCMLog.Text = "";
                }
                int   nSelectStart = rtboxCMLog.TextLength;
                Color clr          = Color.Lime;
                switch (nMsgType)
                {
                case emMsgType.SEND_TEXT_1:
                    clr = Color.Lime;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          "发送:" + str + "\n");
                    break;

                case emMsgType.SEND_TEXT_2:
                    clr = Color.GreenYellow;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          "发送:" + str + "\n");
                    break;

                case emMsgType.RECV_TEXT_1:    //接收的消息
                    clr = Color.Cyan;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          "接收:" + str + "\n");
                    break;

                case emMsgType.RECV_TEXT_2:    //接收的消息
                    clr = Color.Aqua;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          "接收:" + str + "\n");
                    break;

                case emMsgType.ERROR_TEXT:    //通信报错
                    clr = Color.Tomato;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          "通信出错:" + str + "\n");
                    break;

                case emMsgType.EXCEPTION_TEXT:    //运行异常
                    clr = Color.OliveDrab;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          "运行异常:" + str + "\n");
                    break;

                default:
                    clr = Color.Snow;
                    rtboxCMLog.AppendText(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff\n") +
                                          str + "\n");
                    break;
                }
                int nLength = rtboxCMLog.TextLength - 1;
                rtboxCMLog.Select(nSelectStart, nLength);
                rtboxCMLog.SelectionColor = clr;
                rtboxCMLog.AppendText("\n");
                //设置滚动条位置
                //rtboxCMLog.Select(nLength, 0);
                rtboxCMLog.ScrollToCaret();
            }
            catch (System.Exception ex)
            {
                AxPopMsg.Exception(ex.ToString());
                return;
            }
        }