public bool AddCountryTest(XML_CountryTest ct, ref string msg) { bool flag = true; try { if (AllCountryTest.Exists(c => c.StationUniqueId == ct.StationUniqueId && c.NodeId == ct.NodeId)) { msg = ct.StationName + " 站点已经存在 " + ct.Remark + " 检测节点"; flag = false; } else if (AllCountryTest.Exists(c => c.StationUniqueId == ct.StationUniqueId && c.TestId == ct.TestId)) { msg = ct.StationName + " 站点已经存在testid= " + ct.Remark + " 检测节点"; flag = false; } else { lock (AllCountryTest) { int uniqueId = AllCountryTest.Max(c => c.UniqueId); ct.UniqueId = uniqueId + 1; AllCountryTest.Add(ct); flag = AddCountryTestToXML(ct); } } } catch (Exception ex) { flag = false; LogMg.AddError(ex); } return(flag); }
/// <summary> /// 修改countrytest /// </summary> /// <param name="_test"></param> /// <param name="msg"></param> /// <returns></returns> public bool EditCountryTest(XML_CountryTest _test, ref string msg) { bool flag = true; try { lock (AllCountryTest) { XML_CountryTest s = AllCountryTest.SingleOrDefault(c => c.UniqueId == _test.UniqueId); AllCountryTest.Remove(s); //先把这个对象删了 AllCountryTest.Add(_test); //再把新的对象添加进去 flag = EditCountryTestFromXML(_test); } } catch (Exception ex) { LogMg.AddError(ex); flag = false; } return(flag); }