Exemplo n.º 1
0
        /// <summary>
        /// 初始化DataSourceFormat.xml
        /// </summary>
        /// <returns></returns>
        private List<Model.KJFileds> InitDataSourceFormat()
        {
            List<Model.KJFileds> kjFileds = new List<Model.KJFileds>();
            if (IsDebug)
                Log.Write("初始化数据源配置--传感器结构信息");
            XmlDocument xmlDoc = GetXmlDocument(DataFormatPath);
            if (xmlDoc != null)
            {
                GetDataFrequency = int.Parse(xmlDoc.SelectSingleNode(@"DataFormat/SendFrequency").InnerText);
                DataPath = xmlDoc.SelectSingleNode(@"DataFormat/DataPath").InnerText;
                FileDevName = xmlDoc.SelectSingleNode(@"DataFormat/DevFileName").InnerText;
                FileRtmName = xmlDoc.SelectSingleNode(@"DataFormat/RtmFileName").InnerText;
                SplitRowChar = xmlDoc.SelectSingleNode(@"DataFormat/RowSplitChar").InnerText;
                SplitCloumnChar = xmlDoc.SelectSingleNode(@"DataFormat/ColumnSplitChar").InnerText;
                DevCodeHaveSubCode = bool.Parse(xmlDoc.SelectSingleNode(@"DataFormat/DevCodeHaveSubCode").InnerText);

                XmlNode xmlDHBS = xmlDoc.SelectSingleNode(@"DataFormat/DHBS");
                if (xmlDHBS.Attributes["Valid"].Value.ToString() == "true")
                    UseDHBS = true;
                else
                    UseDHBS = false;
                StatnByPort = xmlDHBS.Attributes["StandbyPort"].Value.ToString();
                if (xmlDHBS.Attributes["Active"].Value.ToString() == "true")
                {
                    AppType = "主机";
                    StandByIP = xmlDHBS.Attributes["StandbyIP"].Value;
                }
                else
                    AppType = "备机";

                XmlNode xmlDevConvert = xmlDoc.SelectSingleNode(@"DataFormat/Columns");
                XmlNodeList xmlDevConvertList = xmlDevConvert.ChildNodes;
                foreach (XmlNode xn in xmlDevConvertList)
                {
                    Model.KJFileds kjFiled = new global::TDTK.MSCM.Client.Model.KJFileds();
                    kjFiled.FiledName = xn.Attributes["Name"].Value;
                    kjFiled.FiledIndex = xn.Attributes["Value"].Value;
                    kjFiled.FiledShowName = xn.Attributes["ShowName"].Value;
                    kjFileds.Add(kjFiled);
                }
            }
            else
                Log.Write("配置文件路径不正确,请检查DataSourceFormat.xml");
            return kjFileds;
        } 
Exemplo n.º 2
0
 private void btnDataFormartSave_Click(object sender, EventArgs e)
 {
     bool result = true;
     initConfig.GetDataFrequency = int.Parse(this.txtFrequcy.Text);
     initConfig.DataPath = this.txtDataPath.Text;
     initConfig.FileDevName = this.txtDevName.Text;
     initConfig.FileRtmName = this.txtRtmName.Text;
     initConfig.SplitRowChar = this.txtRowSplit.Text;
     initConfig.SplitCloumnChar = this.txtColumnSplit.Text;
     initConfig.DevCodeHaveSubCode = this.cboxHaveSubCode.Checked;
     List<Model.KJFileds> kjFileds = new List<global::TDTK.MSCM.Client.Model.KJFileds>();
     try
     {
         foreach (DataGridViewRow dgvr in this.dataGridView_FormatConfig.Rows)
         {
             Model.KJFileds kjfiled = new global::TDTK.MSCM.Client.Model.KJFileds
             {
                 FiledName = dgvr.Cells["ColumnRealFiledName"].Value.ToString(),
                 FiledShowName = dgvr.Cells["ColumnKey"].Value.ToString(),
                 FiledIndex = dgvr.Cells["ColumnValue"].Value != null ? dgvr.Cells["ColumnValue"].Value.ToString() : string.Empty
             };
             kjFileds.Add(kjfiled);
         }
     }
     catch (NullReferenceException exec)
     {
         Tcs.Libary.Log.Write(exec);
         result = false;
     }
     catch (Exception exec)
     {
         Tcs.Libary.Log.Write(exec);
         result = false;
     }
     if (result && initConfig.SaveDataSourceFormat(kjFileds))
         MessageBox.Show("保存数据格式配置信息成功!", "成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     else
         MessageBox.Show("保存数据格式配置信息失败!", "失败!", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }