private void Login()
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         List <ElectricityService.ConfigStationInformation> StationList = esc.SelectConfigStationInformation().ToList();
         foreach (ElectricityService.ConfigStationInformation record in StationList)
         {
             StationUIList.Add(new StationUI()
             {
                 ID              = record.ID,
                 StationName     = record.StationName,
                 Longitude       = record.Longitude,
                 Latitude        = record.Latitude,
                 BuildTime       = record.BuildTime,
                 VoltageLevel    = record.VoltageLevel,
                 InstallCapacity = record.InstallCapacity
             });
         }
         ListViewStationList.Items.Clear();
         foreach (StationUI stationui in StationUIList)
         {
             ListViewStationList.Items.Add(stationui);
         }
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }
 private void Forecast(int StationID, DateTime TargetDate)
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         this.Dispatcher.Invoke(new Action(() => { WriteLine("[BGW_ForeCast]正在生成预测数据:{0}...", StationID); }));
         esc.Forecast(StationID, DateTime.Now);
         this.Dispatcher.Invoke(new Action(() => { WriteLine("[BGW_ForeCast]预测数据生成完毕:{0}", StationID); }));
         this.Dispatcher.Invoke(new Action(() => { WriteLine("[UI]正在填充预测数据:{0}...", StationID); }));
         if (RadioForecastPointToPoint.IsChecked ?? false)
         {
             TemplateWebBrowserChart.JavaScript("DeleteData", "PointToPoint");
             List <ElectricityService.ForecastDayStationData> DataList = esc.SelectForecastDayStationData(StationID, DateTime.Now, 1).ToList();
             foreach (ElectricityService.ForecastDayStationData record in DataList)
             {
                 TemplateWebBrowserChart.JavaScript("AddData", "PointToPoint", record.Time.ToString("yyyy-MM-dd HH:mm:ss"), record.ActivePower);
             }
         }
         if (RadioForecastSmooth.IsChecked ?? false)
         {
             TemplateWebBrowserChart.JavaScript("DeleteData", "Smooth");
             List <ElectricityService.ForecastDayStationData> DataList = esc.SelectForecastDayStationData(StationID, DateTime.Now, 2).ToList();
             foreach (ElectricityService.ForecastDayStationData record in DataList)
             {
                 TemplateWebBrowserChart.JavaScript("AddData", "Smooth", record.Time.ToString("yyyy-MM-dd HH:mm:ss"), record.ActivePower);
             }
         }
         if (RadioForecastDayGray.IsChecked ?? false)
         {
             TemplateWebBrowserChart.JavaScript("DeleteData", "DayGray");
             List <ElectricityService.ForecastDayStationData> DataList = esc.SelectForecastDayStationData(StationID, DateTime.Now, 3).ToList();
             foreach (ElectricityService.ForecastDayStationData record in DataList)
             {
                 TemplateWebBrowserChart.JavaScript("AddData", "DayGray", record.Time.ToString("yyyy-MM-dd HH:mm:ss"), record.ActivePower);
             }
         }
         if (RadioForecastVariationCoefficient.IsChecked ?? false)
         {
             TemplateWebBrowserChart.JavaScript("DeleteData", "VariationCoefficient");
             List <ElectricityService.ForecastDayStationData> DataList = esc.SelectForecastDayStationData(StationID, DateTime.Now, 4).ToList();
             foreach (ElectricityService.ForecastDayStationData record in DataList)
             {
                 TemplateWebBrowserChart.JavaScript("AddData", "VariationCoefficient", record.Time.ToString("yyyy-MM-dd HH:mm:ss"), record.ActivePower);
             }
         }
         this.Dispatcher.Invoke(new Action(() => { WriteLine("[UI]填充预测数据完毕:{0}", StationID); }));
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }
 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();
     }
 }
 private void LoadLineFromFile(string filename)
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         FileStream fs = new FileStream(filename, FileMode.Open);
         List <ElectricityService.ConfigLineInformation> LineList = new List <ElectricityService.ConfigLineInformation>();
         StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312"));
         string       line;
         string[]     paras;
         while (!sr.EndOfStream)
         {
             line  = sr.ReadLine();
             paras = System.Text.RegularExpressions.Regex.Split(line, @"\s+");
             if (paras.Length == 19)
             {
                 int StationID_Start = esc.FindConfigStationInformationByStationName(paras[1]).ID;
                 int StationID_End   = esc.FindConfigStationInformationByStationName(paras[2]).ID;
                 ElectricityService.ConfigLineInformation tmpLine = new ElectricityService.ConfigLineInformation();
                 tmpLine.LineName        = paras[0];
                 tmpLine.StationID_Start = StationID_Start;
                 tmpLine.StationID_End   = StationID_End;
                 tmpLine.VoltageLevel    = double.Parse(paras[3]);
                 LineList.Add(tmpLine);
             }
         }
         foreach (ElectricityService.ConfigLineInformation tmpLine in LineList)
         {
             esc.AddConfigLineInformation(tmpLine);
         }
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }
        private void ListViewStationList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TemplateWebBrowserChart.JavaScript("DeleteData", "runtime");
            if (ListViewStationList.SelectedItem == null)
            {
                return;
            }
            StationUI stationui = ListViewStationList.SelectedItem as StationUI;

            MapCenter = new Point(stationui.Longitude, stationui.Latitude);
            ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
            try
            {
                this.Dispatcher.Invoke(new Action(() => { WriteLine("[UI]正在请求当日历史数据:{0}", stationui.ID); }));
                List <ElectricityService.RuntimeStationData> DataList = esc.SelectRuntimeStationData(stationui.ID, DateTime.Today).ToList();
                this.Dispatcher.Invoke(new Action(() => { WriteLine("[UI]当日历史数据请求完毕:{0}", stationui.ID); }));
                if (DataList.Count == 0)
                {
                    return;
                }
                foreach (ElectricityService.RuntimeStationData record in DataList)
                {
                    if (record.Time > DateTime.Now)
                    {
                        break;
                    }
                    TemplateWebBrowserChart.JavaScript("AddData", "runtime", record.Time.ToString("yyyy-MM-dd HH:mm:ss"), record.ActivePower);
                }
                Forecast(stationui.ID, DateTime.Today);
                esc.Close();
            }
            catch (TimeoutException)
            {
                MessageBox.Show("服务器请求超时");
                esc.Abort();
            }
        }
 private void LoadBusFromFile(string filename)
 {
     ElectricityService.ElectricityServiceClient esc = new ElectricityService.ElectricityServiceClient();
     try
     {
         FileStream fs = new FileStream(filename, FileMode.Open);
         List <ElectricityService.ConfigStationInformation> StationList = new List <ElectricityService.ConfigStationInformation>();
         StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312"));
         string       line;
         string[]     paras;
         while (!sr.EndOfStream)
         {
             line  = sr.ReadLine();
             paras = System.Text.RegularExpressions.Regex.Split(line, @"\s+");
             if (paras.Length == 5)
             {
                 ElectricityService.ConfigStationInformation tmpStation = new ElectricityService.ConfigStationInformation();
                 tmpStation.StationName  = paras[1];
                 tmpStation.Longitude    = double.Parse(paras[2]);
                 tmpStation.Latitude     = double.Parse(paras[3]);
                 tmpStation.VoltageLevel = double.Parse(paras[4]);
                 StationList.Add(tmpStation);
             }
         }
         foreach (ElectricityService.ConfigStationInformation tmpStation in StationList)
         {
             esc.AddConfigStationInformation(tmpStation);
         }
         esc.Close();
     }
     catch (TimeoutException)
     {
         MessageBox.Show("服务器请求超时");
         esc.Abort();
     }
 }