日期:2014-05-18  浏览次数:20972 次

在线等 发生了 System.NullReferenceException
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using COM.JcTech.XPlatform.Base.XSoftBus;
using COM.JcTech.XPlatform.DataModel;
using System.Threading;
using COM.JcTech.XPlatform.Data;
using COM.JcTech.XPlatform.DataModel.TopoAnalyze;
using COM.JcTech.XPlatform.Base.WinForm;
using COM.JcTech.XPlatform.Base;

namespace XAutoSetPowerPointProperty
{
  internal static class Program
  {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  private static void Main()
  {
  JSoftBusClientInit.InitSoftBus();
  JDataModel.InitDataModel(true);

  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  while (true) // 一直循环
  {
  JDevice[] feeder_list = JDataModel.GetDeviceListByAbility(enumDeviceAbility.is_pd_feeder);//获取10kv线路列表


  if (feeder_list==null || feeder_list.Length <=0)
  {
  break;
  }

  JCommonDatabase db = JDatabaseMgr.GetDatabase(enumTableStore.db_oracle, enumDataSource.normal);
  db.BeginTrans();
  try
  {
  foreach (JDevice a_feeder in feeder_list)
  {
  if (a_feeder == null)
  {
  continue;
  }
  JDevice cx_kg = a_feeder.CxkgOfFeeder; //线路对应的10kv出线开关

  if (cx_kg == null)
  {
  continue;
  }

  JTopoAnalyzeClient client = new JTopoAnalyzeClient();
  JDataModel.JDeviceInfo[] info_list = client.GetPowerArea(JDataModel.enumTopoMode.rt,
  cx_kg.DeviceID); // 查询选中设备查询实时数据

  if (info_list != null && info_list.Length != 0) //写入数据库相应的表里
  {
  foreach (JDataModel.JDeviceInfo info in info_list)
  {
  enumDatabaseTableID main_table_id =
  JDataModel.GetMainTableIDByDeviceType(info.device_type_id);
  string tablename = JDDCacheMgr.GetTableNameByTableID(main_table_id);
  string sql =
  string.Format("update {0} set powerpoint_id={1},powerpoint='{2}'where ID= {3}",
  tablename, a_feeder.DeviceID, a_feeder.DeviceName, info.device_id);
  //TODOs 向数据库写入电源点属性

  (db as JRdbDatabase).ExecSQL(sql);
   
  }
  }
  }
  db.CommitTrans();
  }
  catch (Exception ex)
  {  
  db.RollbackTrans();