Exemplo n.º 1
0
        /// <summary>
        /// 获取所有Test
        /// </summary>
        /// <returns></returns>
        public List <Clazz.Config.XML_Test> GetAllTests()
        {
            List <Clazz.Config.XML_Test> ListTest = new List <Clazz.Config.XML_Test>();

            try
            {
                XmlNodeList nodeList = Utility.XmlHelper.GetXmlNodeListByXpath(PATH, "/Config/Tests/Test");
                foreach (XmlNode item in nodeList)
                {
                    XmlElement            xel  = (XmlElement)item;
                    Clazz.Config.XML_Test test = new Clazz.Config.XML_Test();
                    test.StationUnique  = int.Parse(xel.GetAttribute("StationUnique"));
                    test.StationId      = int.Parse(xel.GetAttribute("StationId"));
                    test.RegisterNo     = ushort.Parse(xel.GetAttribute("RegisterNo"));
                    test.TestId         = int.Parse(xel.GetAttribute("TestId"));
                    test.Multiple       = double.Parse(xel.GetAttribute("Multiple"));
                    test.FunctionCode   = Convert.ToInt32(xel.GetAttribute("FunctionCode"));
                    test.ReceiveTimeout = Convert.ToInt32(xel.GetAttribute("ReceiveTimeout"));
                    test.DataType       = xel.GetAttribute("DataType");
                    test.Address        = byte.Parse(xel.GetAttribute("Address"));
                    test.DecodeOrder    = xel.GetAttribute("DecodeOrder");
                    test.Min            = double.Parse(xel.GetAttribute("Min"));
                    test.Max            = double.Parse(xel.GetAttribute("Max"));
                    test.AddNumber      = double.Parse(xel.GetAttribute("AddNumber"));
                    ListTest.Add(test);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
            return(ListTest);
        }
Exemplo n.º 2
0
        public bool GenerateFromDbToXML()
        {
            List <Clazz.Config.XML_Station> XML_stations = new List <Clazz.Config.XML_Station>(); //从数据库中找出来的站点信息列表
            List <Clazz.Config.XML_Test>    XML_Tests    = new List <Clazz.Config.XML_Test>();    //从数据库中找出来的test信息
            SWS_DBDataContext SWS_DB  = new SWS_DBDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, SysConfig.userProfile.DbName, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword));
            List <SWS_DB.org> db_orgs = SWS_DB.org.Where(c => c.org_type == 2 || c.org_type == 3).ToList();

            foreach (SWS_DB.org _org in db_orgs)
            {
                SWSDataContext country_db = new SWSDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, _org.dbname, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword));
                try
                {
                    //List<country_station> db_stations = country_db.country_station.Where(c => c.transfer_code != "" && c.transfer_code != "NULL" && c.Protocol != "" && c.deleteflag == false).ToList();
                    List <country_station> db_stations = country_db.ExecuteQuery <country_station>("select * from country_station where transfer_code <> '' and transfer_code <> 'NULL' and Protocol <> '' and deleteflag=0").ToList();
                    List <syscode>         syscodes    = country_db.syscode.Where(c => c.type == "0060").ToList();
                    foreach (country_station station in db_stations)
                    {
                        try
                        {
                            //将站点信息添加到列表
                            Clazz.Config.XML_Station xml_sta = new Clazz.Config.XML_Station();
                            xml_sta.Unique    = XML_stations.Count;
                            xml_sta.StationId = station.id;
                            xml_sta.Name      = station.name;
                            xml_sta.OrgId     = _org.orgid.ToString();
                            xml_sta.Tel       = station.transfer_code;
                            xml_sta.Protocol  = syscodes.Single(c => c.code == station.Protocol).name;

                            XML_stations.Add(xml_sta);

                            //找出站点的检测指标
                            List <test> tests             = country_db.test.Where(c => c.station_id == station.id && c.means.Contains("自动获取") && c.delete_flag == false).ToList();
                            List <gong_kuang_config> gkcs = country_db.gong_kuang_config.Where(c => c.testid != 0 && c.config_type != "03" && c.config_type != "04").ToList();

                            foreach (test _test in tests)
                            {
                                try
                                {
                                    List <gong_kuang_config> gkc = gkcs.Where(c => c.testid == _test.testid).ToList();  //这个一般只有一行   但配置的时候可能会出现两行,
                                    if (gkc.Count > 0)
                                    {
                                        Clazz.Config.XML_Test xml_t = new Clazz.Config.XML_Test();
                                        xml_t.StationUnique  = xml_sta.Unique;
                                        xml_t.StationId      = xml_sta.StationId;
                                        xml_t.RegisterNo     = ushort.Parse(gkc[0].read_register);
                                        xml_t.TestId         = _test.testid;
                                        xml_t.Multiple       = gkc[0].Multiple == null ? 1 : (double)gkc[0].Multiple; //如果没填,则默认为0
                                        xml_t.FunctionCode   = int.Parse(gkc[0].function_code);
                                        xml_t.ReceiveTimeout = (int)gkc[0].receive_timeout;
                                        xml_t.DataType       = gkc[0].data_type;
                                        xml_t.Address        = byte.Parse(gkc[0].address.ToString());
                                        if (!string.IsNullOrEmpty(gkc[0].decode_order))
                                        {
                                            xml_t.DecodeOrder = gkc[0].decode_order;
                                        }
                                        xml_t.Min       = gkc[0].dmin == null ? 0 : (double)gkc[0].dmin;           //如果没填,则默认为0
                                        xml_t.Max       = gkc[0].dmax == null ? 4294967296 : (double)gkc[0].dmax;  //如果没填,则默认为0
                                        xml_t.AddNumber = gkc[0].AddNumber == null ? 0 : (double)gkc[0].AddNumber; //如果没填,则默认为0
                                        xml_t.备注        = _test.name;
                                        XML_Tests.Add(xml_t);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    LogMg.AddError(ex);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogMg.AddError(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex);
                }
            }
            SaveConfigToXML(XML_stations, XML_Tests);
            return(true);
        }