Exemple #1
0
        private void BatchForUI_EventHandler(object sender, BatchEventArgs e)
        {
            var    result  = e.Value;
            string rawData = e.RawData;

            if (result != null)
            {
                if (this.IsHandleCreated)
                {
                    //  导入数据库
                    BatchDataImport.Import(result);

                    //  更新界面
                    this.listView1.Invoke((Action) delegate
                    {
                        try
                        {
                            this.listView1.Items.Add(new ListViewItem()
                            {
                                Text = "接收数据 : " + rawData
                            });
                        }
                        catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        try
                        {
                            this.listView1.Items.Add(new ListViewItem()
                            {
                                Text = "站点ID : " + result.StationID
                            });
                        }
                        catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        try
                        {
                            this.listView1.Items.Add(new ListViewItem()
                            {
                                Text = "站点类型: " + result.StationType == "01" ? "水位" : "雨量"
                            });
                        }
                        catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        foreach (var item in result.Datas)
                        {
                            try
                            {
                                this.listView1.Items.Add(new ListViewItem()
                                {
                                    Text = item.Time.ToString() + "    " + item.Data
                                });
                            }
                            catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        }
                    });
                }
            }
        }
Exemple #2
0
        private void BatchForUI_EventHandler(object sender, BatchEventArgs e)
        {
            //20170512改动过
            var    result  = e.Value;
            string rawData = e.RawData;

            BatchDataImport m_batchDataImport = new BatchDataImport();

            if (result != null)
            {
                if (this.IsHandleCreated)
                {
                    //  导入数据库
                    //BatchDataImport.Import(result);
                    DateTime DStartTime = new DateTime();
                    DateTime DEndTime   = new DateTime();
                    if (this.radioHour.Checked == true)
                    {
                        DateTime tmp = this.dtp_StartTime.Value;
                        //DateTime tmp_1 = this.dtp_EndTime.Value;
                        DStartTime = new DateTime(tmp.Year, tmp.Month, tmp.Day, tmp.Hour, 0, 0);
                        DEndTime   = this.dtp_EndTime.Value;
                    }
                    else if (this.radioDay.Checked == true)
                    {
                        DateTime tmp   = this.dtp_StartTime.Value;
                        DateTime tmp_1 = this.dtp_EndTime.Value;
                        DStartTime = new DateTime(tmp.Year, tmp.Month, tmp.Day, 8, 0, 0);
                        DEndTime   = new DateTime(tmp_1.Year, tmp_1.Month, tmp_1.Day, 23, 59, 59);
                    }
                    //DateTime DStartTime = this.dtp_StartTime.Value;
                    //DateTime DEndTime = this.dtp_EndTime.Value;
                    if (radioButton2.Checked)
                    {
                        m_batchDataImport.Import(result, DStartTime, DEndTime);
                    }
                    //m_batchDataImport.Import(result, DStartTime, DEndTime);
                    if (radioButtonSave.Checked)
                    {
                        if (result.StationType == EStationType.ERainFall)
                        {
                            string filePath = @"BatchData\\Rain.txt";//这里是你的已知文件
                            string strPath  = Path.GetDirectoryName(filePath);
                            if (!Directory.Exists(strPath))
                            {
                                Directory.CreateDirectory(strPath);
                            }
                            StreamWriter sw = new StreamWriter(filePath, true, Encoding.GetEncoding("gb2312"));
                            sw.Write("---------------------------------------------" + "\r\n");
                            sw.Write("接收数据 : " + rawData + "\r\n");          //写你的字符串。
                            sw.Write("站点ID : " + result.StationID + "\r\n"); //写你的字符串。
                            sw.Write("站点类型: " + "水位" + "\r\n");              //写你的字符串。
                            foreach (var item in result.Datas)
                            {
                                try
                                {
                                    sw.Write(item.Time.ToString() + "    " + item.Data + "\r\n");
                                }
                                catch (Exception exp) { Debug.WriteLine(exp.Message); }
                            }
                            sw.Close();
                        }
                        if (result.StationType == EStationType.ERiverWater)
                        {
                            string filePath = "BatchData\\Water.txt";//这里是你的已知文件
                            string strPath  = Path.GetDirectoryName(filePath);
                            if (!Directory.Exists(strPath))
                            {
                                Directory.CreateDirectory(strPath);
                            }
                            StreamWriter sw = new StreamWriter(filePath, true, Encoding.GetEncoding("gb2312"));
                            sw.Write("---------------------------------------------" + "\r\n");
                            sw.Write("接收数据 : " + rawData + "\r\n");          //写你的字符串。
                            sw.Write("站点ID : " + result.StationID + "\r\n"); //写你的字符串。
                            sw.Write("站点类型: " + "雨量" + "\r\n");              //写你的字符串。
                            foreach (var item in result.Datas)
                            {
                                try
                                {
                                    sw.Write(item.Time.ToString() + "    " + item.Data + "\r\n");
                                }
                                catch (Exception exp) { Debug.WriteLine(exp.Message); }
                            }
                            sw.Close();
                        }
                    }

                    //  更新界面

                    this.listView1.Invoke((Action) delegate
                    {
                        try
                        {
                            this.listView1.Items.Add(new ListViewItem()
                            {
                                Text = "接收数据 : " + rawData
                            });
                        }
                        catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        try
                        {
                            this.listView1.Items.Add(new ListViewItem()
                            {
                                Text = "站点ID : " + result.StationID
                            });
                        }
                        catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        try
                        {
                            if (result.StationType == EStationType.ERiverWater)
                            {
                                this.listView1.Items.Add(new ListViewItem()
                                {
                                    Text = "站点类型: " + "雨量"
                                });
                            }
                            else if (result.StationType == EStationType.ERainFall)
                            {
                                this.listView1.Items.Add(new ListViewItem()
                                {
                                    Text = "站点类型: " + "水位"
                                });
                            }
                        }
                        catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        foreach (var item in result.Datas)
                        {
                            try
                            {
                                this.listView1.Items.Add(new ListViewItem()
                                {
                                    Text = item.Time.ToString() + "    " + item.Data
                                });
                            }
                            catch (Exception exp) { Debug.WriteLine(exp.Message); }
                        }
                    });
                }
            }
        }