示例#1
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                DataRowView drv        = cboGrid.SelectedItem as DataRowView;
                BenMAPGrid  benMAPGrid = Grid.GridCommon.getBenMAPGridFromID(Convert.ToInt32(drv["GridDefinitionID"]));

                if (CommonClass.GBenMAPGrid == null)
                {
                    CommonClass.GBenMAPGrid = benMAPGrid;
                }
                else if (CommonClass.GBenMAPGrid.GridDefinitionID != benMAPGrid.GridDefinitionID)
                {
                    CommonClass.GBenMAPGrid = benMAPGrid;
                    isGridTypeChanged       = true;
                }
                _bgc.GridType = CommonClass.GBenMAPGrid;
                string tip = "Reading and checking the data file.";
                if (rbtnModelData.Checked)
                {
                    ModelData    frm = new ModelData(_bgc, _currentStat);
                    DialogResult rtn = frm.ShowDialog();
                    if (rtn == DialogResult.Cancel)
                    {
                        return;
                    }
                    _strPath          = frm.StrPath;
                    this.DialogResult = rtn;
                }
                else if (rbtnMonitorData.Checked)
                {
                    MonitorData  frm = new MonitorData(_bgc, _currentStat);
                    DialogResult rtn = frm.ShowDialog();
                    if (rtn == DialogResult.Cancel)
                    {
                        return;
                    }
                    _mDataLine        = frm.MDataLine;
                    _strPath          = frm.StrPath;
                    this.DialogResult = rtn;
                }
                else if (rbtnMonitorRollback.Checked)
                {
                    MonitorRollback frm = new MonitorRollback(_bgc, _currentStat);
                    DialogResult    rtn = frm.ShowDialog();
                    if (rtn == DialogResult.Cancel)
                    {
                        return;
                    }
                    _mDataLine        = frm._monitorRollbackLine;
                    _strPath          = frm.StrPath;
                    this.DialogResult = rtn;
                }
                else if (this.rbtnOpenFile.Checked)
                {
                    if (txtExistingAQG.Text != "")
                    {
                        ParaserAQG(txtExistingAQG.Text);
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
示例#2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtAirQualitySurface.Text != "")
                {
                    string     err        = "";
                    BenMAPLine benMAPLine = DataSourceCommonClass.LoadAQGFile(txtAirQualitySurface.Text, ref err);
                    if (benMAPLine == null)
                    {
                        MessageBox.Show(err);
                        return;
                    }
                    if (benMAPLine is MonitorDataLine)
                    {
                        MonitorDataLine monitorDataLine = (benMAPLine as MonitorDataLine);
                        if (monitorDataLine.MonitorNeighbors != null && monitorDataLine.MonitorNeighbors.Count > 0)
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Filter           = "Neighbors files (*.csv)|*.csv";
                            sfd.FilterIndex      = 2;
                            sfd.RestoreDirectory = true;
                            sfd.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
                            string _filePath = "";
                            _filePath = sfd.FileName.Substring(0, sfd.FileName.LastIndexOf(@"\") + 1);

                            if (sfd.ShowDialog() == DialogResult.OK)
                            {
                                DataTable dt = new DataTable();
                                dt.Columns.Add("Col");
                                dt.Columns.Add("Row");
                                dt.Columns.Add("MonitorName");
                                dt.Columns.Add("Weight");
                                dt.Columns.Add("Distance");
                                foreach (MonitorNeighborAttribute m in monitorDataLine.MonitorNeighbors)
                                {
                                    DataRow dr = dt.NewRow();
                                    dr["Col"]         = m.Col;
                                    dr["Row"]         = m.Row;
                                    dr["MonitorName"] = m.MonitorName;
                                    dr["Weight"]      = m.Weight;
                                    dr["Distance"]    = m.Distance;
                                    dt.Rows.Add(dr);
                                }
                                CommonClass.SaveCSV(dt, sfd.FileName);
                            }
                        }
                        else
                        {
                            MessageBox.Show("No neighbors in this air quality grid.");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("This air quality grid is not a monitor direct grid.");
                        return;
                    }
                }
            }
            catch
            {
            }
        }
        private void btnGo_Click(object sender, EventArgs e)
        {
            try
            {
                bool   ok    = false;
                double value = 0.0;
                if (rbtnClosestMonitor.Checked)
                {
                    _monitorRollbackLine.InterpolationMethod = InterpolationMethodEnum.ClosestMonitor;
                }
                else if (rbtnVoronoiNeighborhood.Checked)
                {
                    _monitorRollbackLine.InterpolationMethod = InterpolationMethodEnum.VoronoiNeighborhoodAveragin;
                }
                else if (rbtnFixedRadius.Checked)
                {
                    _monitorRollbackLine.InterpolationMethod = InterpolationMethodEnum.FixedRadius;
                    ok = double.TryParse(txtFixRadio.Text, out value);
                    if (!ok || Convert.ToDouble(txtFixRadio.Text) <= 0)
                    {
                        MessageBox.Show("To select fixed radius interpolation you must provide a radius in kilometers.");
                        txtFixRadio.Text = string.Empty;
                        return;
                    }
                    _monitorRollbackLine.FixedRadius = value;
                }

                MonitorDataLine baselinegrid = new MonitorDataLine();
                SaveFileDialog  sfd          = new SaveFileDialog();
                if (chbMakeBaselineGrid.Checked)
                {
                    baselinegrid = new MonitorDataLine()
                    {
                        CreateTime            = _monitorRollbackLine.CreateTime,
                        GridType              = _monitorRollbackLine.GridType,
                        FixedRadius           = _monitorRollbackLine.FixedRadius,
                        InterpolationMethod   = _monitorRollbackLine.InterpolationMethod,
                        MonitorAdvance        = _monitorRollbackLine.MonitorAdvance,
                        MonitorDataFilePath   = _monitorRollbackLine.MonitorDataFilePath,
                        MonitorDataSetID      = _monitorRollbackLine.MonitorDataSetID,
                        MonitorDefinitionFile = _monitorRollbackLine.MonitorDefinitionFile,
                        MonitorDirectType     = _monitorRollbackLine.MonitorDirectType,
                        MonitorLibraryYear    = _monitorRollbackLine.MonitorLibraryYear,
                        MonitorNeighbors      = _monitorRollbackLine.MonitorNeighbors,
                        Pollutant             = _monitorRollbackLine.Pollutant,
                        ShapeFile             = _monitorRollbackLine.ShapeFile
                    };
                    sfd.Title            = "Save the baseline Grid.";
                    sfd.Filter           = "AGQ files (*.aqgx)|*.aqgx";
                    sfd.RestoreDirectory = true;
                    sfd.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
                    if (sfd.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                }
                SaveFileDialog sfd2 = new SaveFileDialog();
                sfd2.Title            = "Save the rolled back Grid.";
                sfd2.Filter           = "AGQ files (*.aqgx)|*.aqgx";
                sfd2.RestoreDirectory = true;
                sfd2.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
                if (sfd2.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (chbMakeBaselineGrid.Checked)
                {
                    WaitShow("Saving the baseline grid...");
                    DataSourceCommonClass.UpdateModelValuesMonitorData(baselinegrid.GridType, baselinegrid.Pollutant, ref baselinegrid);
                    DataSourceCommonClass.CreateAQGFromBenMAPLine(baselinegrid, sfd.FileName);
                    WaitClose();
                    makeBaselineGrid = "T" + sfd.FileName;
                }
                else
                {
                    makeBaselineGrid = "F";
                }
                saveAQGPath = sfd2.FileName;
                int threadId = -1;
                AsynDelegateRollBack asyncD = new AsynDelegateRollBack(AsyncUpdateMonitorRollbackData);
                IAsyncResult         ar     = asyncD.BeginInvoke(_currentStat, _monitorRollbackLine, out threadId, null, null);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WaitClose();
                Logger.LogError(ex);
            }
        }