private void LoadDaysFromFiles(string[] filenames, DateTime StartDate)
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         for (int i = 0; i < filenames.Length; i++)
         {
             DateTime   TimeReady = StartDate + TimeSpan.FromDays(i);
             string     filename  = filenames[i];
             FileStream fs        = new FileStream(filename, FileMode.Open);
             List <ElectricityService.RuntimeStationData> DataList = new List <ElectricityService.RuntimeStationData>();
             StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312"));
             string       line;
             string[]     paras;
             int          istationid = 1, jrecordid = 0;
             while (!sr.EndOfStream)
             {
                 line  = sr.ReadLine();
                 paras = System.Text.RegularExpressions.Regex.Split(line, @"\s+");
                 if (paras.Length == 3)
                 {
                     ElectricityService.RuntimeStationData tmpData = new ElectricityService.RuntimeStationData()
                     {
                         StationID     = istationid,
                         ActivePower   = double.Parse(paras[0]),
                         ReactivePower = double.Parse(paras[1]),
                         Time          = TimeReady + TimeSpan.FromMinutes(15 * jrecordid)
                     };
                     DataList.Add(tmpData);
                     jrecordid++;
                     if (jrecordid >= 96)
                     {
                         jrecordid = 0;
                         istationid++;
                     }
                 }
             }
             foreach (ElectricityService.RuntimeStationData tmpData in DataList)
             {
                 esc.AddRuntimeStationData(tmpData);
             }
         }
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }
 private void UpdateAll()
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         foreach (StationUI stationui in StationUIList)
         {
             List <ElectricityService.RuntimeStationData> DataList = esc.UpdateRuntimeStationData(stationui.RuntimeID, stationui.ID).ToList();
             if (DataList.Count == 0)
             {
                 return;
             }
             ElectricityService.RuntimeStationData LastRecord = null;
             foreach (ElectricityService.RuntimeStationData record in DataList)
             {
                 if (record.Time > DateTime.Now)
                 {
                     break;
                 }
                 if (ListViewStationList.SelectedItem == stationui)
                 {
                     TemplateWebBrowserChart.JavaScript("AddData", "runtime", record.Time.ToString("yyyy-MM-dd HH:mm:ss"), record.ActivePower);
                 }
                 LastRecord = record;
             }
             if (LastRecord != null)
             {
                 stationui.Active    = LastRecord.ActivePower;
                 stationui.Reactive  = LastRecord.ReactivePower;
                 stationui.RuntimeID = LastRecord.ID;
                 this.Dispatcher.Invoke(new Action(() => { WriteLine("[BGW_UpdateRuntime]数据已更新:{0}", stationui.ID); }));
             }
         }
         ListViewStationList.UpdateLayout();
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }
 private void FetchAll()
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         foreach (StationUI stationui in StationUIList)
         {
             List <ElectricityService.RuntimeStationData> DataList = esc.SelectRuntimeStationData(stationui.ID, DateTime.Today).ToList();
             if (DataList.Count == 0)
             {
                 return;
             }
             ElectricityService.RuntimeStationData LastRecord = null;
             foreach (ElectricityService.RuntimeStationData record in DataList)
             {
                 if (record.Time > DateTime.Now)
                 {
                     break;
                 }
                 LastRecord = record;
             }
             if (LastRecord != null)
             {
                 stationui.Active    = LastRecord.ActivePower;
                 stationui.Reactive  = LastRecord.ReactivePower;
                 stationui.RuntimeID = LastRecord.ID;
             }
         }
         ListViewStationList.UpdateLayout();
         DrawStations();
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }