示例#1
0
        public void  OutputFile()
        {
            OutPutFileLocation = TurbineDataUtility.Model.Utils.GetFolder();
            try
            {
                foreach (DataTable Data in DownloadedData)
                {
                    string filename = OutPutFileLocation + @"\" + SelectedSite.Substring(0, 4) + "_" + "set_" + DownloadedData.IndexOf(Data) + "_" + DateTime.Now.ToShortDateString().Replace(@"/", "") + ".csv";

                    // Create the CSV file to which grid data will be exported.
                    StreamWriter sw = new StreamWriter(filename, false);

                    //column heads
                    foreach (DataColumn col in Data.Columns)
                    {
                        sw.Write(col.ColumnName.Replace("#", "_"));
                        // Console.WriteLine(col.ColumnName.Replace("#", "_"));
                        if (Data.Columns.IndexOf(col) < Data.Columns.Count - 1)
                        {
                            sw.Write(",");
                        }
                    }



                    sw.Write(sw.NewLine);


                    //Now write all the rows.
                    foreach (DataRow dr in Data.Rows)
                    {
                        for (int i = 0; i < Data.Columns.Count; i++)
                        {
                            if (!Convert.IsDBNull(dr[Data.Columns[i]]) & dr[Data.Columns[i]].ToString().Length > 0)
                            {
                                sw.Write(dr[Data.Columns[i]].ToString());
                            }
                            else
                            {
                                sw.Write("-9999.99");
                            }
                            if (i < Data.Columns.Count - 1)
                            {
                                sw.Write(",");
                            }
                        }
                        sw.Write(sw.NewLine);
                    }
                    sw.Close();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#2
0
        void Download()
        {
            _isDownloading = true;
            worker         = new BackgroundWorker();
            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = true;
            DownloadProgress = 0;



            worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                DownloadProgress = e.ProgressPercentage;
            };

            worker.DoWork += delegate(object sender, DoWorkEventArgs args)
            {
                PIDownloader pi = new PIDownloader(DataSourceType.WindART_SQL);

                DownloadProgressText = "Initializing Connection....";


                foreach (string config in _configs.selectedItems)
                {
                    List <Tag> SelectedTags = new List <Tag>();
                    DownloadProgress = 0;
                    int    tagdownloadcount = 0;
                    string sitename         = SelectedSite.Substring(0, 7);

                    SelectedTags = SelectTags(sitename);

                    TagManager tmReference = null;

                    tmReference = new TagManager(SelectedTags, sitename);

                    TagManagers.Add(tmReference);

                    foreach (Tag tag in SelectedTags)
                    {
                        if (tag == null)
                        {
                            continue;
                        }
                        string tagname = tag.TagName;

                        if (_downloadCancelled)
                        {
                            tmReference = null;
                            worker.ReportProgress(0);
                            worker.CancelAsync();
                            _downloadCancelled = false;
                            break;
                        }
                        SortedDictionary <DateTime, double> TagData = new SortedDictionary <DateTime, double>();


                        StringBuilder sql = new StringBuilder();
                        sql.Append(@"select time, value from piserver.piarchive..picomp where tag='");
                        sql.Append(tagname);
                        sql.Append("' and time between '");
                        sql.Append(tag.StartDate.ToShortDateString());
                        sql.Append(" 00:00:00");
                        sql.Append("' and '");
                        sql.Append(tag.EndDate.ToShortDateString());
                        sql.Append(" 00:00:00");
                        sql.Append("' and value is not null");

                        //System.Diagnostics.Debug.Print(sql.ToString ());
                        DataTable pidata = data.GetData(sql.ToString());

                        foreach (DataRow row in pidata.Rows)
                        {
                            DateTime thisDate = (DateTime)row["time"];
                            if (!TagData.ContainsKey(thisDate))
                            {
                                // Console.WriteLine(row["time"].ToString() + " " + row["value"].ToString());
                                TagData.Add(thisDate, Double.Parse(row["value"].ToString()));
                            }
                            else
                            {
                                // Console.WriteLine(row["time"].ToString() + " not found in " + tag.TagName);
                                TagData[thisDate] = -9999.0;
                            }
                        }

                        tmReference[tag.TagName].Data = TagData;

                        tagdownloadcount++;

                        int progress = (int)(double.Parse(tagdownloadcount.ToString()) / double.Parse(SelectedTags.Count().ToString()) * 100);
                        worker.ReportProgress(progress);
                    }

                    //add the downloaded data to a datatable

                    DownloadedData.Add(CreateDateTimeDataTable(tmReference));
                }
            };

            worker.RunWorkerAsync();


            _isDownloading = false;
        }
示例#3
0
        void LoadConfigs()
        {
            string sitename = SelectedSite.Substring(0, 7);

            GetConfigs(sitename);
        }