Exemplo n.º 1
0
        /// <summary>
        /// 写入灯箱配置信息
        /// </summary>
        /// <param name="lbModel">Lb model.</param>
        private static void write(LBModel lbModel)
        {
            XmlElement xmlModelWaitTime = doc.CreateElement(KEY_MODEL_WAIT_TIME);

            XmlElement xmlModelWaitMM = doc.CreateElement(KEY_MODEL_WAITMM);
            XmlText    txtModelWaitMM = doc.CreateTextNode(lbModel.MWaitTime.WaitMM.ToString());

            xmlModelWaitMM.AppendChild(txtModelWaitMM);

            XmlElement xmlModelWaitSS = doc.CreateElement(KEY_MODEL_WAITSS);
            XmlText    txtModelWaitSS = doc.CreateTextNode(lbModel.MWaitTime.WaitSS.ToString());

            xmlModelWaitSS.AppendChild(txtModelWaitSS);
            xmlModelWaitTime.AppendChild(xmlModelWaitMM);
            xmlModelWaitTime.AppendChild(xmlModelWaitSS);

            root.AppendChild(xmlModelWaitTime);

            XmlElement xmlModelSortIndex = doc.CreateElement(KEY_MODEL_SORT_INDEX);
            XmlText    txtModelSortIndex = doc.CreateTextNode(lbModel.sortIndex.ToString());

            xmlModelSortIndex.AppendChild(txtModelSortIndex);
            root.AppendChild(xmlModelSortIndex);

            XmlElement xmlModelActive = doc.CreateElement(KEY_MODEL_ACTIVE);
            XmlText    txtModelActive = doc.CreateTextNode(lbModel.Active.ToString());

            xmlModelActive.AppendChild(txtModelActive);
            root.AppendChild(xmlModelActive);

            XmlElement xmlRunAll = doc.CreateElement(KEY_MODEL_RUN_ALL);
            XmlText    txtRunAll = doc.CreateTextNode(lbModel.runAll.ToString());

            xmlRunAll.AppendChild(txtRunAll);
            root.AppendChild(xmlRunAll);

            foreach (LBMsg lbMsg in lbModel.ListLBMsg)
            {
                XmlElement xmlLightBox = doc.CreateElement(KEY_LIGHT_BOX);

                XmlElement xmlId     = doc.CreateElement(KEY_ID);
                XmlText    txtlbAddr = doc.CreateTextNode(lbMsg.Id.ToString());
                xmlId.AppendChild(txtlbAddr);

                XmlElement xmlLBX           = doc.CreateElement(KEY_LINE);
                XmlText    txtlbRotateAngle = doc.CreateTextNode(lbMsg.Row1.ToString());
                xmlLBX.AppendChild(txtlbRotateAngle);

                XmlElement xmlLBY           = doc.CreateElement(KEY_ROW);
                XmlText    txtlbRotateSpeed = doc.CreateTextNode(lbMsg.Column.ToString());
                xmlLBY.AppendChild(txtlbRotateSpeed);

                XmlElement xmlRunTime   = doc.CreateElement(KEY_RUN_TIME);
                XmlText    txtlbRunTime = doc.CreateTextNode(lbMsg.RunTime.ToString());
                xmlRunTime.AppendChild(txtlbRunTime);

                XmlElement xmlKeepTime   = doc.CreateElement(KEY_KEEP_TIME);
                XmlText    txtlbKeepTime = doc.CreateTextNode(lbMsg.KeepTime.ToString());
                xmlKeepTime.AppendChild(txtlbKeepTime);

                XmlElement xmlWaitTime   = doc.CreateElement(KEY_WAIT_TIME);
                XmlText    txtlbWaitTime = doc.CreateTextNode(lbMsg.WaitTime.ToString());
                xmlWaitTime.AppendChild(txtlbWaitTime);

                XmlElement xmlRepeatCount   = doc.CreateElement(KEY_REPEAT_COUNT);
                XmlText    txtlbRepeatCount = doc.CreateTextNode(lbMsg.RepeatCount.ToString());
                xmlRepeatCount.AppendChild(txtlbRepeatCount);

                xmlLightBox.AppendChild(xmlId);
                xmlLightBox.AppendChild(xmlLBX);
                xmlLightBox.AppendChild(xmlLBY);
                xmlLightBox.AppendChild(xmlRunTime);
                xmlLightBox.AppendChild(xmlKeepTime);
                xmlLightBox.AppendChild(xmlWaitTime);
                xmlLightBox.AppendChild(xmlRepeatCount);

                root.AppendChild(xmlLightBox);
            }
        }
Exemplo n.º 2
0
 public static void saveModel(LBModel lbModel)
 {
     initDoc();
     write(lbModel);
     save(FILE_MODEL + lbModel.ModelName + ".xml");
 }
Exemplo n.º 3
0
 public static void saveLBConfig(LBModel lbModel)
 {
     initDoc();
     write(lbModel);
     save(FILE_DOC + "lbConfig.xml");
 }
Exemplo n.º 4
0
        /// <summary>
        /// 获取模式下所有灯箱的信息
        /// </summary>
        /// <returns></returns>
        public static LBModel getListBoxMsgs(string fileName)
        {
            LBModel     lbModel  = new LBModel();
            XmlDocument document = new XmlDocument();

            document.Load(fileName);
            XmlNode rootElement = document.SelectSingleNode(WriteXmlHelper.KEY_MODEL);

            List <LBMsg> listLightBoxMsg = new List <LBMsg>();
            //try {

            XmlNode xmlModelWaitTime = rootElement.SelectSingleNode(WriteXmlHelper.KEY_MODEL_WAIT_TIME);
            XmlNode xmlModelWaitMM   = xmlModelWaitTime.SelectSingleNode(WriteXmlHelper.KEY_MODEL_WAITMM);

            lbModel.MWaitTime.WaitMM = Convert.ToDouble(xmlModelWaitMM.InnerText);

            XmlNode xmlModelWaitSS = xmlModelWaitTime.SelectSingleNode(WriteXmlHelper.KEY_MODEL_WAITSS);

            lbModel.MWaitTime.WaitSS = Convert.ToDouble(xmlModelWaitSS.InnerText);

            XmlNode xmlModelSortIndex = rootElement.SelectSingleNode(WriteXmlHelper.KEY_MODEL_SORT_INDEX);

            lbModel.sortIndex = Convert.ToInt32(xmlModelSortIndex.InnerText);

            XmlNode xmlModelActive = rootElement.SelectSingleNode(WriteXmlHelper.KEY_MODEL_ACTIVE);

            if (null != xmlModelActive)
            {
                lbModel.Active = Convert.ToBoolean(xmlModelActive.InnerText);
            }

            XmlNode xmlRunAll = rootElement.SelectSingleNode(WriteXmlHelper.KEY_MODEL_RUN_ALL);

            if (null != xmlRunAll)
            {
                lbModel.runAll = Convert.ToBoolean(xmlRunAll.InnerText);
            }

            XmlNodeList xmlLightBoxMsgs = rootElement.SelectNodes(WriteXmlHelper.KEY_LIGHT_BOX);

            foreach (XmlNode xmlLBMsg in xmlLightBoxMsgs)
            {
                LBMsg lbmsg = new LBMsg();

                XmlNode xmlLBAddr = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_ID);
                lbmsg.Id = Convert.ToInt16(xmlLBAddr.InnerText);

                XmlNode xmlLBAddrNum = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_LINE);
                lbmsg.Row1 = Convert.ToInt16(xmlLBAddrNum.InnerText);

                XmlNode xmlRotateSpeed = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_ROW);
                lbmsg.Column = Convert.ToInt16(xmlRotateSpeed.InnerText);

                XmlNode xmlRunTime = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_RUN_TIME);
                lbmsg.RunTime = Convert.ToDouble(xmlRunTime.InnerText);

                XmlNode xmlKeepTime = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_KEEP_TIME);
                lbmsg.KeepTime = Convert.ToDouble(xmlKeepTime.InnerText);

                XmlNode xmlWaitTime = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_WAIT_TIME);
                lbmsg.WaitTime = Convert.ToDouble(xmlWaitTime.InnerText);

                XmlNode xmlRepeatCount = xmlLBMsg.SelectSingleNode(WriteXmlHelper.KEY_REPEAT_COUNT);
                if (null != xmlRepeatCount)
                {
                    lbmsg.RepeatCount = Convert.ToInt16(xmlRepeatCount.InnerText);
                }

                listLightBoxMsg.Add(lbmsg);
            }
            //} catch (NullReferenceException) {
            //    MessageBox.Show("文件格式不正确");
            //}
            lbModel.ListLBMsg = listLightBoxMsg;
            return(lbModel);
        }