/// <summary>
        /// 根据条件查找是否存在包含关键字的协议节点
        /// </summary>
        /// <param name="Node"></param>
        /// <param name="protocolname"></param>
        /// <param name="factroy"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private static bool ContainsNode(CLDC_DataCore.DataBase.clsXmlControl Node, string protocolname, string factroy, string size)
        {
            if (Node == null)
            {
                Node = new CLDC_DataCore.DataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);
            }
            if (Node == null)
            {
                return(false);
            }

            if (protocolname != "")
            {
                if (CommDataBase.clsXmlControl.FindSencetion(Node.toXmlNode(), CommDataBase.clsXmlControl.XPath(string.Format("R,Name,{0}", protocolname))) != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (factroy != "" && size != "")
            {
                if (CommDataBase.clsXmlControl.FindSencetion(Node.toXmlNode(), CommDataBase.clsXmlControl.XPath(string.Format("R,ZZCJ,{0},BXH,{1}", factroy, size))) != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
        /// <summary>
        /// 移除一个协议节点
        /// </summary>
        /// <param name="protocolname">协议名称</param>
        /// <param name="factory">制造厂家</param>
        /// <param name="size">表型号</param>
        /// <returns></returns>
        private static bool Remove(string protocolname, string factory, string size)
        {
            if (protocolname == "" && (factory == "" || size == ""))
            {
                return(false);
            }
            CLDC_DataCore.DataBase.clsXmlControl _XmlNode = new CLDC_DataCore.DataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);

            if (_XmlNode.Count() == 0)
            {
                return(false);
            }

            if (protocolname != "")
            {
                _XmlNode.RemoveChild(CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,Name,{0}", protocolname)));
            }
            if (factory != "" && size != "")
            {
                _XmlNode.RemoveChild(CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,ZZCJ,{0},BXH,{1}", factory, size)));
            }

            _XmlNode.SaveXml();
            return(true);
        }
        /// <summary>
        /// 获取协议唯一标志组合名称列表
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, string> getProtocolString()
        {
            CLDC_DataCore.DataBase.clsXmlControl _XmlNode = new CLDC_DataCore.DataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);

            if (_XmlNode.Count() == 0)
            {
                return(new Dictionary <string, string>());
            }

            Dictionary <string, string> _ReturnNames = new Dictionary <string, string>();

            System.Xml.XmlNode _Xml = _XmlNode.toXmlNode();

            for (int i = 0; i < _Xml.ChildNodes.Count; i++)
            {
                _ReturnNames.Add(_Xml.ChildNodes[i].Attributes["Name"].Value, string.Format("协议名称:{0};制造厂家:{1};表型号:{2}", _Xml.ChildNodes[i].Attributes["Name"].Value
                                                                                            , _Xml.ChildNodes[i].Attributes["ZZCJ"].Value
                                                                                            , _Xml.ChildNodes[i].Attributes["BXH"].Value));
            }

            _Xml     = null;
            _XmlNode = null;

            return(_ReturnNames);
        }
 /// <summary>
 /// 存储功耗方案
 /// </summary>
 public void Save()
 {
     if (_LstPowerConsume.Count == 0)
     {
         return;
     }
     CLDC_DataCore.DataBase.clsXmlControl _XmlNode = new CLDC_DataCore.DataBase.clsXmlControl();
     _XmlNode.appendchild("", "PowerConsume", "Name", Name);
     for (int _i = 0; _i < _LstPowerConsume.Count; _i++)
     {
         _XmlNode.appendchild(""
                              , "R"
                              , "bChecked"
                              , _LstPowerConsume[_i].PowerConsumePrjID
                              , "ItemName"
                              , _LstPowerConsume[_i].PowerConsumePrjName
                              , "Para"
                              , _LstPowerConsume[_i].PrjParm);
     }
     _XmlNode.SaveXml(_FAPath);
 }
        /// <summary>
        /// 获取协议名称列表
        /// </summary>
        /// <returns></returns>
        public static List <string> getProtocolNames()
        {
            CLDC_DataCore.DataBase.clsXmlControl _XmlNode = new CLDC_DataCore.DataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);

            if (_XmlNode.Count() == 0)
            {
                return(new List <string>());
            }

            List <string> _ReturnNames = new List <string>();

            System.Xml.XmlNode _Xml = _XmlNode.toXmlNode();

            for (int i = 0; i < _Xml.ChildNodes.Count; i++)
            {
                _ReturnNames.Add(_Xml.ChildNodes[i].Attributes["Name"].Value);
            }

            _Xml     = null;
            _XmlNode = null;

            return(_ReturnNames);
        }
        /// <summary>
        /// 根据制造厂家和表型号获取协议名称
        /// </summary>
        /// <param name="Factroy">制造厂家</param>
        /// <param name="Size">表型号</param>
        /// <returns></returns>
        public static string getProtocolName(string Factroy, string Size)
        {
            if (Factroy == "" || Size == "")
            {
                return("");
            }
            CLDC_DataCore.DataBase.clsXmlControl _XmlNode = new CLDC_DataCore.DataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);

            if (_XmlNode.Count() == 0)
            {
                return("");
            }

            System.Xml.XmlNode Xml_Child = null;

            Xml_Child = CLDC_DataCore.DataBase.clsXmlControl.FindSencetion(_XmlNode.toXmlNode()
                                                                           , CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,ZZCJ,{0},BXH,{1}", Factroy, Size)));
            if (Xml_Child == null)
            {
                return("");
            }

            return(CLDC_DataCore.DataBase.clsXmlControl.getNodeAttributeValue(Xml_Child, "Name"));
        }
        /// <summary>
        /// 加载XML文档
        /// </summary>
        /// <param name="protocolname"></param>
        /// <param name="factroy"></param>
        /// <param name="size"></param>
        private void LoadXmlData(string protocolname, string factory, string size)
        {
            if (protocolname == "" && (factory == "" || size == ""))
            {
                return;
            }

            CommDataBase.clsXmlControl _XmlNode = new CommDataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);

            if (_XmlNode.Count() == 0)
            {
                return;
            }

            System.Xml.XmlNode _FindXmlNode = null;

            if (protocolname != "")
            {
                _FindXmlNode = CLDC_DataCore.DataBase.clsXmlControl.FindSencetion(_XmlNode.toXmlNode()
                                                                                  , CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,Name,{0}", protocolname)));
            }
            else if (factory != "" && size != "")
            {
                _FindXmlNode = CLDC_DataCore.DataBase.clsXmlControl.FindSencetion(_XmlNode.toXmlNode()
                                                                                  , CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,ZZCJ,{0},BXH,{1}", factory, size)));
            }
            if (_FindXmlNode == null)
            {
                return;
            }

            #region ----------------------------加载协议文件信息----------------------------------------------------------------------

            this.ProtocolName = _FindXmlNode.Attributes["Name"].Value;                                          //协议名称

            this.DnbFactroy = CLDC_DataCore.DataBase.clsXmlControl.getNodeAttributeValue(_FindXmlNode, "ZZCJ"); //制造厂家

            this.DnbSize = CLDC_DataCore.DataBase.clsXmlControl.getNodeAttributeValue(_FindXmlNode, "BXH");     //表型号

            this.DllFile = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                             , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,DllFile"));                                                         //协议库名称
            this.ClassName = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                               , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClassName"));                                                     //说使用协议类名称
            this.Setting = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                             , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,Setting"));                                                         //通信参数
            this.UserID = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                            , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,UserID"));                                                           //用户名
            this.VerifyPasswordType = int.Parse(CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                                  , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,VerifyPasswordType")));                        //验证类型
            this.WritePassword = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                   , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,WritePassword"));                                             //写密码
            this.WriteClass = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,WriteClass"));                                                   //写密码等级
            this.ClearDemandPassword = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                         , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClearDemandPassword"));                                 //清需量密码
            this.ClearDemandClass = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                      , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClearDemandClass"));                                       //请需量密码等级
            this.ClearDLPassword = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                     , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClearDLPassword"));                                         //清电量密码
            this.ClearDLClass = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                  , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClearDLClass"));                                               //清电量等级
            this.TariffOrderType = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                     , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,TariffOrderType"));                                         //费率类型
            this.DateTimeFormat = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                    , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,DateTimeFormat"));                                           //日期格式
            this.SundayIndex = int.Parse(CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                           , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,SundayIndex")));                                      //星期天表示
            this.ClockPL = float.Parse(CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode, CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClockPL")) == "" ? "1"
                                                                : CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode, CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ClockPL")));     //时钟频率
            this.FECount = int.Parse(CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                       , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,FECount")));                                              //唤醒FE个数
            this.DataFieldPassword = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                       , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,DataFieldPassword")) == "0" ? false : true;               //数据域是否包含密码
            this.BlockAddAA = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,BlockAddAA")) == "0" ? false : true;                             //写数据块是否加AA
            this.ConfigFile = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode
                                                                                , CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,ConfigFile"));                                                   //配置文件
            this.HaveProgrammingkey = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode, CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,HaveProgrammingkey")) == "0" ? false : true; //有无编程键
            this.IsSouthEncryption  = CLDC_DataCore.DataBase.clsXmlControl.getNodeValue(_FindXmlNode, CLDC_DataCore.DataBase.clsXmlControl.XPath("C,Name,IsSouthEn")) == "0" ? false : true;          //有无编程键

            _FindXmlNode = CLDC_DataCore.DataBase.clsXmlControl.FindSencetion(_FindXmlNode, CLDC_DataCore.DataBase.clsXmlControl.XPath("Prjs"));                                                      //转到项目数据节点


            this._Loading = true;                //改写加载标志,表示加载协议成功

            this.DgnPras = new Dictionary <string, string>();

            if (_FindXmlNode == null)
            {
                return;
            }

            for (int i = 0; i < _FindXmlNode.ChildNodes.Count; i++)
            {
                this.DgnPras.Add(_FindXmlNode.ChildNodes[i].Attributes["ID"].Value, _FindXmlNode.ChildNodes[i].ChildNodes[0].Value);        //加入ID,值
            }

            if (this.DgnPras.Count == 0)
            {
                return;
            }



            #endregion
        }
        /// <summary>
        /// 添加一个新的协议!
        /// </summary>
        /// <returns></returns>
        public bool AddNewProtocol()
        {
            if (ProtocolName == "" || _DnbFactroy == "" || _DnbSize == "")
            {
                return(false);
            }
            CLDC_DataCore.DataBase.clsXmlControl _XmlNode = new CLDC_DataCore.DataBase.clsXmlControl(System.Windows.Forms.Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_DGNPROTOCOL);
            if (ContainsNode(_XmlNode, ProtocolName, "", ""))
            {
                Remove(ProtocolName, "", "");
            }
            if (ContainsNode(_XmlNode, "", _DnbFactroy, _DnbSize))
            {
                Remove("", _DnbFactroy, _DnbSize);
            }
            if (_XmlNode.toXmlNode() == null)
            {
                _XmlNode.appendchild("", "DgnProtocol");
            }
            _XmlNode.appendchild("", "R", "Name", ProtocolName, "ZZCJ", _DnbFactroy, "BXH", _DnbSize);

            #region -----------------------------------------插入XML节点---------------------------------------------

            string _Xpath = CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,Name,{0}", ProtocolName));

            _XmlNode.appendchild(_Xpath, "C", "Name", "DllFile", this.DllFile);                                   //协议库名称
            _XmlNode.appendchild(_Xpath, "C", "Name", "ClassName", this.ClassName);                               //所使用的协议名称
            _XmlNode.appendchild(_Xpath, "C", "Name", "Setting", this.Setting);                                   //通信参数
            _XmlNode.appendchild(_Xpath, "C", "Name", "UserID", this.UserID);                                     //用户名
            _XmlNode.appendchild(_Xpath, "C", "Name", "VerifyPasswordType", this.VerifyPasswordType.ToString());  //验证类型
            _XmlNode.appendchild(_Xpath, "C", "Name", "WritePassword", this.WritePassword);                       //写密码
            _XmlNode.appendchild(_Xpath, "C", "Name", "WriteClass", this.WriteClass);                             //写等级
            _XmlNode.appendchild(_Xpath, "C", "Name", "ClearDemandPassword", this.ClearDemandPassword);           //清需量密码
            _XmlNode.appendchild(_Xpath, "C", "Name", "ClearDemandClass", this.ClearDemandClass);                 //请需量密码等级
            _XmlNode.appendchild(_Xpath, "C", "Name", "ClearDLPassword", this.ClearDLPassword);                   //清电量密码
            _XmlNode.appendchild(_Xpath, "C", "Name", "ClearDLClass", this.ClearDLClass);                         //清电量等级
            _XmlNode.appendchild(_Xpath, "C", "Name", "TariffOrderType", this.TariffOrderType);                   //费率类型
            _XmlNode.appendchild(_Xpath, "C", "Name", "DateTimeFormat", this.DateTimeFormat);                     //日期格式
            _XmlNode.appendchild(_Xpath, "C", "Name", "SundayIndex", this.SundayIndex.ToString());                //星期天表示
            _XmlNode.appendchild(_Xpath, "C", "Name", "ClockPL", this.ClockPL.ToString());                        //时钟频率
            _XmlNode.appendchild(_Xpath, "C", "Name", "FECount", this.FECount.ToString());                        //唤醒FE个数
            _XmlNode.appendchild(_Xpath, "C", "Name", "DataFieldPassword", this.DataFieldPassword ? "1" : "0");   //数据域是否包含密码
            _XmlNode.appendchild(_Xpath, "C", "Name", "BlockAddAA", this.BlockAddAA ? "1" : "0");                 //写数据块是否加AA
            _XmlNode.appendchild(_Xpath, "C", "Name", "ConfigFile", this.ConfigFile);                             //配置文件
            _XmlNode.appendchild(_Xpath, "C", "Name", "HaveProgrammingkey", this.HaveProgrammingkey ? "1" : "0"); //有无编程键
            _XmlNode.appendchild(_Xpath, "C", "Name", "IsSouthEn", this.IsSouthEncryption ? "1" : "0");           //是否是南网13加密机

            if (this.DgnPras.Count > 0)
            {
                _XmlNode.appendchild(_Xpath, "Prjs");               //插入项目节点
            }
            else
            {
                _XmlNode.SaveXml();
                return(true);
            }
            _Xpath = CLDC_DataCore.DataBase.clsXmlControl.XPath(string.Format("R,Name,{0}|Prjs", ProtocolName));

            foreach (string _Key in this.DgnPras.Keys)
            {
                _XmlNode.appendchild(_Xpath, "D", "ID", _Key, DgnPras[_Key]);
            }
            _XmlNode.SaveXml();
            #endregion

            return(true);
        }