예제 #1
0
        private void cboRollbackGridType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboRollbackGridType.SelectedIndex == -1)
            {
                return;
            }
            DataRowView drv = (cboRollbackGridType.SelectedItem as DataRowView);

            _monitorRollbackGrid = Grid.GridCommon.getBenMAPGridFromID(Convert.ToInt32(drv["GridDefinitionID"]));
        }
예제 #2
0
        public Dictionary <string, List <GridRelationshipAttributePercentage> > getRelationshipFromBenMAPGridPercentage(int big, int small)
        {
            try
            {
                IFeatureSet fsBig           = new FeatureSet();
                IFeatureSet fsSmall         = new FeatureSet();
                BenMAPGrid  bigBenMAPGrid   = Grid.GridCommon.getBenMAPGridFromID(big == 20 ? 18 : big);
                BenMAPGrid  smallBenMAPGrid = Grid.GridCommon.getBenMAPGridFromID(small == 20 ? 18 : small);
                if (bigBenMAPGrid == null)
                {
                    bigBenMAPGrid = new ShapefileGrid()
                    {
                        ShapefileName = "County_epa2",
                    }
                }
                ;
                if (smallBenMAPGrid == null)
                {
                    smallBenMAPGrid = new ShapefileGrid()
                    {
                        ShapefileName = "County_epa2",
                    }
                }
                ;
                string bigShapefileName   = "";
                string smallShapefileName = "";
                if (bigBenMAPGrid as ShapefileGrid != null)
                {
                    bigShapefileName = (bigBenMAPGrid as ShapefileGrid).ShapefileName;
                }
                else
                {
                    bigShapefileName = (bigBenMAPGrid as RegularGrid).ShapefileName;
                }
                if (smallBenMAPGrid as ShapefileGrid != null)
                {
                    smallShapefileName = (smallBenMAPGrid as ShapefileGrid).ShapefileName;
                }
                else
                {
                    smallShapefileName = (smallBenMAPGrid as RegularGrid).ShapefileName;
                }
                ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
                string finsSetupname = string.Format("select setupname from setups where setupid in (select setupid from griddefinitions where griddefinitionid={0})", big);
                string setupname     = Convert.ToString(fb.ExecuteScalar(CommonClass.Connection, CommandType.Text, finsSetupname));
                if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + setupname + "\\" + bigShapefileName + ".shp"))
                {
                    string shapeFileName = CommonClass.DataFilePath + @"\Data\Shapefiles\" + setupname + "\\" + bigShapefileName + ".shp";
                    fsBig = DotSpatial.Data.FeatureSet.Open(shapeFileName);
                    string shapeFileNameSmall = CommonClass.DataFilePath + @"\Data\Shapefiles\" + setupname + "\\" + smallShapefileName + ".shp";
                    fsSmall = DotSpatial.Data.FeatureSet.Open(shapeFileNameSmall);


                    List <GridRelationshipAttributePercentage> lstGR = null; if (big == 20 || small == 20)
                    {
                        lstGR = CommonClass.IntersectionPercentageNation(fsBig, fsSmall, FieldJoinType.All, big, small);
                    }
                    else
                    {
                        lstGR = CommonClass.IntersectionPercentage(fsBig, fsSmall, FieldJoinType.All);
                    }
                    Dictionary <string, List <GridRelationshipAttributePercentage> > dic = new Dictionary <string, List <GridRelationshipAttributePercentage> >();
                    dic.Add(small + "," + big, lstGR);
                    return(dic);

                    string commandText = "select max(PercentageID) from GridDefinitionPercentages";
                    int    iMax        = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, CommandType.Text, commandText)) + 1;

                    commandText = string.Format("insert into GridDefinitionPercentages values({0},{1},{2})", iMax, small, big);
                    fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
                    foreach (GridRelationshipAttributePercentage grp in lstGR)
                    {
                        commandText = string.Format("insert into GridDefinitionPercentageEntries values({0},{1},{2},{3},{4},{5},{6})",
                                                    iMax, grp.sourceCol, grp.sourceRow, grp.targetCol, grp.targetRow, grp.percentage, 0);
                        fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            FireBirdHelperBase fb          = new ESILFireBirdHelper();
            string             commandText = string.Empty;

            _columns = int.Parse(nudColumns.Value.ToString());
            _rrows   = int.Parse(nudRows.Value.ToString());
            try
            {
                if (cboGridType.SelectedIndex == 0)
                {
                    _shapeFileName = lblShapeFileName.Text;
                }
                else
                {
                    _gridType = 0;
                    try
                    {
                        _columns         = int.Parse(nudColumns.Value.ToString());
                        _rrows           = int.Parse(nudRows.Value.ToString());
                        _colPerLongitude = int.Parse(nudColumnsPerLongitude.Value.ToString());
                        _rowPerLatitude  = int.Parse(nudRowsPerLatitude.Value.ToString());
                        _minLongitude    = System.Convert.ToDouble(txtMinimumLongitude.Text);
                        _minLatitude     = System.Convert.ToDouble(txtMinimumLatitude.Text);
                    }
                    catch
                    {
                        MessageBox.Show("Input data was not in a correct format.");
                        return;
                    }
                }
                if (IsEditor)
                {
                    commandText = string.Format("select Ttype from GridDefinitions where GridDefinitionID=" + _gridID + "");
                    int type = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText));

                    switch (_gridType)
                    {
                    case 1:
                        if (_shapeFilePath == string.Empty)
                        {
                            commandText = string.Format("Update GridDefinitions set GridDefinitionName='{0}'WHERE GridDefinitionID={1}", txtGridID.Text, _gridID);
                            fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                            this.DialogResult = DialogResult.OK; return;
                        }
                        if (type == 1)
                        {
                            commandText = string.Format("Update GridDefinitions set GridDefinitionName='{0}',COLUMNS={1},RROWS={2},TTYPE={3} WHERE GridDefinitionID={4}", txtGridID.Text, _shapeCol, _shapeRow, _gridType, _gridID);
                            fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                            if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + _shapeFileName + ".shp"))
                            {
                                RenameorOverride ro = new RenameorOverride();
                                DialogResult     dr = ro.ShowDialog();
                                if (dr == DialogResult.Cancel)
                                {
                                    return;
                                }
                                else
                                {
                                    if (dr == DialogResult.OK)
                                    {
                                        Renamefile frm = new Renamefile();
                                        frm.newfileName = _shapeFileName;
                                        frm.manage      = "GridDefinition";
                                        DialogResult dresult = frm.ShowDialog();
                                        if (dresult == DialogResult.OK)
                                        {
                                            _shapeFileName = frm.newfileName;
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                    commandText = string.Format("Update ShapefileGriddefinitiondetails set shapefilename='{0}' where GridDefinitionID={1}", _shapeFileName, _gridID);
                                    fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                                }
                            }
                        }
                        else
                        {
                            DialogResult rtn = MessageBox.Show("Replace the 'Regular Grid' with 'Shapefile'?", "", MessageBoxButtons.YesNo);
                            if (rtn == DialogResult.Yes)
                            {
                                if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + _shapeFileName + ".shp"))
                                {
                                    RenameorOverride ro = new RenameorOverride();
                                    DialogResult     dr = ro.ShowDialog();
                                    if (dr == DialogResult.Cancel)
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        if (dr == DialogResult.OK)
                                        {
                                            Renamefile frm = new Renamefile();
                                            frm.newfileName = _shapeFileName;
                                            frm.manage      = "GridDefinition";
                                            DialogResult dresult = frm.ShowDialog();
                                            if (dresult == DialogResult.OK)
                                            {
                                                _shapeFileName = frm.newfileName;
                                            }
                                            else
                                            {
                                                return;
                                            }
                                        }
                                        commandText = string.Format("insert into ShapeFileGridDefinitionDetails (GridDefinitionID,ShapeFileName) values ({0},'{1}')", _gridID, _shapeFileName);
                                        fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                                    }
                                }
                                commandText = string.Format("Update GridDefinitions set GridDefinitionName='{0}',COLUMNS={1},RROWS={2},TTYPE={3} WHERE GridDefinitionID={4}", txtGridID.Text, _shapeCol, _shapeRow, _gridType, _gridID);
                                fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                                commandText = "delete From RegularGridDefinitionDetails where GridDefinitionID=" + _gridID + "";
                                fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                            }
                            else
                            {
                                return;
                            }
                        }

                        IFeatureSet fs = FeatureSet.Open(_shapeFilePath);
                        try
                        {
                            if (fs.DataTable.Columns["ROW"].DataType == typeof(System.String) || fs.DataTable.Columns["COL"].DataType == typeof(System.String))
                            {
                                for (int iDt = 0; iDt < fs.DataTable.Rows.Count; iDt++)
                                {
                                    int r = (int)Convert.ToDouble(fs.DataTable.Rows[iDt]["ROW"].ToString());
                                    int c = (int)Convert.ToDouble(fs.DataTable.Rows[iDt]["COL"].ToString());
                                    fs.DataTable.Rows[iDt]["ROW"] = r;
                                    fs.DataTable.Rows[iDt]["COL"] = c;
                                }
                            }
                            fs.SaveAs(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + _shapeFileName + ".shp", true);
                        }
                        finally
                        {
                            fs.Close();
                        }
                        break;

                    case 0:
                        if (Math.Abs(_minLongitude) > 180 || Math.Abs(_minLatitude) > 90)
                        {
                            MessageBox.Show("Longitude must be less than 180 degrees and latitude less than 90 degrees. Please check the longitude and latitude values."); return;
                        }
                        if (type == 0)
                        {
                            commandText = string.Format("Update GridDefinitions set GridDefinitionName='{0}',COLUMNS={1},RROWS={2},TTYPE={3} WHERE GridDefinitionID={4}", txtGridID.Text, _columns, _rrows, _gridType, _gridID);
                            fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                            commandText = string.Format("Update RegularGriddefinitionDetails set minimumlatitude={0},minimumlongitude={1},columnsperlongitude={2},rowsperlatitude={3} where GridDefinitionID={4}", _minLatitude, _minLongitude, _colPerLongitude, _rowPerLatitude, _gridID);
                            fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                        }
                        else
                        {
                            DialogResult rtn = MessageBox.Show("Replace the 'Shapefile' with 'Regular Grid'?", "", MessageBoxButtons.YesNo);
                            if (rtn == DialogResult.Yes)
                            {
                                commandText = string.Format("Update GridDefinitions set GridDefinitionName='{0}',COLUMNS={1},RROWS={2},TTYPE={3} WHERE GridDefinitionID={4}", txtGridID.Text, _columns, _rrows, _gridType, _gridID);
                                fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                                commandText = "delete From ShapefileGriddefinitiondetails where GridDefinitionID=" + _gridID + "";
                                fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                                commandText = string.Format("insert into RegularGriddefinitionDetails (GridDefinitionID,MinimumLatitude,MinimumLongitude,ColumnsPerLongitude,RowsPerLatitude,ShapeFileName) values ({0},{1},{2},{3},{4},'{5}')", _gridID, _minLatitude, _minLongitude, _colPerLongitude, _rowPerLatitude, txtGridID.Text);
                                fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                            }
                            else
                            {
                                return;
                            }
                        }
                        fs = getFeatureSetFromRegularGrid(_columns, _rrows, _minLatitude, _minLongitude, _colPerLongitude, _rowPerLatitude);
                        try
                        {
                            fs.SaveAs(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + txtGridID.Text + ".shp", true);
                        }
                        finally
                        {
                            fs.Close();
                        }
                        break;
                    }
                    if (!chkBoxCreatePercentage.Checked)
                    {
                        WaitShow("Updating the grid definition...");
                        commandText = string.Format("delete from GridDefinitionPercentageEntries where PercentageID in ( select PercentageID  from GridDefinitionPercentages where SourceGridDefinitionID={0} or TargetGridDefinitionID={0})", _gridID);
                        fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
                        commandText = string.Format("delete from GridDefinitionPercentages where SourceGridDefinitionID={0} or TargetGridDefinitionID={0}", _gridID);
                        fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
                        this.DialogResult = DialogResult.OK;
                        WaitClose();
                        return;
                    }
                }

                else
                {
                    commandText = "select GridDefinitionID from GridDefinitions where GridDefinitionName='" + txtGridID.Text + "' and SetupID=" + CommonClass.ManageSetup.SetupID;
                    object obj = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                    if (obj != null)
                    {
                        MessageBox.Show("This grid definition name is already in use. Please enter a different name.");
                        return;
                    }
                    commandText = string.Format("select max(GRIDDEFINITIONID) from GRIDDEFINITIONS");
                    _gridID     = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText)) + 1;

                    switch (_gridType)
                    {
                    case 1:
                        if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + _shapeFileName + ".shp"))
                        {
                            Renamefile frm = new Renamefile();
                            frm.newfileName = _shapeFileName;
                            frm.manage      = "GridDefinition";
                            DialogResult dr = frm.ShowDialog();
                            if (dr == DialogResult.OK)
                            {
                                _shapeFileName = frm.newfileName;
                            }
                            else
                            {
                                return;
                            }
                        }

                        commandText = string.Format("INSERT INTO GRIDDEFINITIONS (GridDefinitionID,SetUpID,GridDefinitionName,Columns,Rrows,Ttype,DefaultType) VALUES(" + _gridID + ",{0},'{1}',{2},{3},{4},{5})", CommonClass.ManageSetup.SetupID, txtGridID.Text, _shapeCol, _shapeRow, _gridType, 0);
                        fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                        commandText = string.Format("INSERT INTO SHAPEFILEGRIDDEFINITIONDETAILS (GridDefinitionID,ShapeFileName) VALUES(" + _gridID + ",'{0}')", _shapeFileName);
                        fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                        CommonClass.DeleteShapeFileName(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + _shapeFileName + ".shp");
                        IFeatureSet fs = FeatureSet.Open(_shapeFilePath);
                        try
                        {
                            if (fs.DataTable.Columns["ROW"].DataType == typeof(System.String) || fs.DataTable.Columns["COL"].DataType == typeof(System.String))
                            {
                                for (int iDt = 0; iDt < fs.DataTable.Rows.Count; iDt++)
                                {
                                    int r = (int)Convert.ToDouble(fs.DataTable.Rows[iDt]["ROW"].ToString());
                                    int c = (int)Convert.ToDouble(fs.DataTable.Rows[iDt]["COL"].ToString());
                                    fs.DataTable.Rows[iDt]["ROW"] = r;
                                    fs.DataTable.Rows[iDt]["COL"] = c;
                                }
                            }
                            fs.SaveAs(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + _shapeFileName + ".shp", true);
                        }
                        finally
                        {
                            fs.Close();
                        }
                        break;

                    case 0:
                        DialogResult rtn = MessageBox.Show("Save this grid?", "", MessageBoxButtons.YesNo);
                        if (rtn == DialogResult.No)
                        {
                            this.DialogResult = DialogResult.Cancel; return;
                        }
                        else
                        {
                            commandText = string.Format("INSERT INTO GRIDDEFINITIONS (GridDefinitionID,SetUpID,GridDefinitionName,Columns,Rrows,Ttype,DefaultType) VALUES(" + _gridID + ",{0},'{1}',{2},{3},{4},{5})", CommonClass.ManageSetup.SetupID, txtGridID.Text, _columns, _rrows, _gridType, 0);
                            fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);

                            if (Math.Abs(_minLongitude) > 180 || Math.Abs(_minLatitude) > 90)
                            {
                                MessageBox.Show("Please input valid longitude and latitude values."); return;
                            }
                            commandText = string.Format("INSERT INTO RegularGridDefinitionDetails (GridDefinitionID,MinimumLatitude,MinimumLongitude,ColumnsPerLongitude,RowsPerLatitude,ShapeFileName)  VALUES ({0},{1},{2},{3},{4},'{5}')", _gridID, txtMinimumLatitude.Text, txtMinimumLongitude.Text, nudColumnsPerLongitude.Value, nudRowsPerLatitude.Value, txtGridID.Text);
                            fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);

                            fs = getFeatureSetFromRegularGrid(_columns, _rrows, _minLatitude, _minLongitude, _colPerLongitude, _rowPerLatitude);
                            CommonClass.DeleteShapeFileName(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + txtGridID.Text + ".shp");

                            try
                            {
                                fs.SaveAs(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.ManageSetup.SetupName + "\\" + txtGridID.Text + ".shp", true);
                            }
                            finally
                            {
                                fs.Close();
                            }
                        }
                        break;
                    }
                    if (!chkBoxCreatePercentage.Checked)
                    {
                        this.DialogResult = DialogResult.OK;
                        return;
                    }
                }
                lblprogress.Visible = true;
                lblprogress.Refresh();
                progressBar1.Visible = true;
                progressBar1.Refresh();
                BenMAPGrid addBenMAPGrid = Grid.GridCommon.getBenMAPGridFromID(_gridID);
                try
                {
                    commandText = "select a.GridDefinitionID,SetupID,GridDefinitionName,Columns,RRows,TType,b.ShapeFileName from GridDefinitions a,ShapeFileGridDefinitionDetails b " +
                                  " where a.GridDefinitionID=b.GridDefinitionID and a.TType=1  and a.SetupID=" + addBenMAPGrid.SetupID +
                                  " union " +
                                  " select a.GridDefinitionID,SetupID,GridDefinitionName,Columns,RRows,TType,b.ShapeFileName from GridDefinitions a,RegularGridDefinitionDetails b " +
                                  " where a.GridDefinitionID=b.GridDefinitionID and a.TType=0  and a.SetupID=" + addBenMAPGrid.SetupID;
                    fb = new ESIL.DBUtility.ESILFireBirdHelper();
                    System.Data.DataSet ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, commandText);
                    commandText = string.Format("delete from GridDefinitionPercentageEntries where PercentageID in ( select PercentageID  from GridDefinitionPercentages where SourceGridDefinitionID={0} or TargetGridDefinitionID={0})", addBenMAPGrid.GridDefinitionID);
                    fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
                    commandText = string.Format("delete from GridDefinitionPercentages where SourceGridDefinitionID={0} or TargetGridDefinitionID={0}", addBenMAPGrid.GridDefinitionID);
                    fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
                    string AppPath = Application.StartupPath;
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        int gridDefinitionID = Convert.ToInt32(dr["GridDefinitionID"]);
                        if (gridDefinitionID == addBenMAPGrid.GridDefinitionID)
                        {
                            continue;
                        }



                        int bigGridID, smallGridID;



                        bigGridID   = gridDefinitionID;
                        smallGridID = addBenMAPGrid.GridDefinitionID;
                        AsyncgetRelationshipFromBenMAPGridPercentage dlgt = new AsyncgetRelationshipFromBenMAPGridPercentage(getRelationshipFromBenMAPGridPercentage);
                        lstAsyns.Add(bigGridID + "," + smallGridID);
                        lstAsyns.Add(smallGridID + "," + bigGridID);
                        iAsyns++; iAsyns++;
                        IAsyncResult ar = dlgt.BeginInvoke(bigGridID, smallGridID, new AsyncCallback(outPut), dlgt);


                        IAsyncResult ar2 = dlgt.BeginInvoke(smallGridID, bigGridID, new AsyncCallback(outPut), dlgt);
                    }
                    progressBar1.Step    = 1;
                    progressBar1.Minimum = 1;
                    progressBar1.Maximum = iAsyns + 1;
                    this.Enabled         = false;
                }

                catch (Exception ex)
                {
                    Logger.LogError(ex);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtBase.Text == string.Empty || txtControl.Text == string.Empty)
                {
                    MessageBox.Show("Please select both the baseline and control file.", "Error");
                    return;
                }
                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)
                {
                    benMAPGridOld           = Grid.GridCommon.getBenMAPGridFromID(CommonClass.GBenMAPGrid.GridDefinitionID);
                    CommonClass.GBenMAPGrid = benMAPGrid;
                    isGridTypeChanged       = true;
                }
                bcgOpenAQG.GridType = CommonClass.GBenMAPGrid;

                string inputFileFormat = string.Empty;

                saveBasePath    = string.Empty;
                saveControlPath = string.Empty;
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter           = "AQG files (*.aqgx)|*.aqgx";
                sfd.RestoreDirectory = true;
                sfd.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
                if (!txtBase.Text.ToLower().EndsWith("aqgx"))
                {
                    sfd.Title = "Save the baseline Grid.";
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        saveBasePath = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                sfd.FileName = "";
                if (!txtControl.Text.ToLower().EndsWith("aqgx"))
                {
                    sfd.Title = "Save the control Grid.";
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        saveControlPath = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }
                }

                WaitShow("Loading AQ data file...");
                if (txtBase.Text != "")
                {
                    basePath        = "Model Data:" + txtBase.Text;
                    inputFileFormat = basePath.Substring(basePath.LastIndexOf("."));
                    switch (inputFileFormat)
                    {
                    case ".csv":
                        if (!File.Exists(txtBase.Text))
                        {
                            MessageBox.Show("File not found.", "Error"); return;
                        }
                        if (txtPollutant.Text == bcgOpenAQG.Pollutant.PollutantName)
                        {
                            bcgOpenAQG.GridType = CommonClass.GBenMAPGrid;
                            CreateShapeFile(bcgOpenAQG, "baseline", txtBase.Text);
                            bcgOpenAQG.Base.CreateTime = DateTime.Now;
                        }
                        break;

                    case ".aqgx":
                        openAQG(txtBase.Text, "baseline", bcgOpenAQG);
                        break;

                    case ".xls":
                        if (!File.Exists(txtBase.Text))
                        {
                            MessageBox.Show("File not found.", "Error"); return;
                        }
                        if (txtPollutant.Text == bcgOpenAQG.Pollutant.PollutantName)
                        {
                            bcgOpenAQG.GridType = CommonClass.GBenMAPGrid;
                            CreateShapeFile(bcgOpenAQG, "baseline", txtBase.Text);
                            bcgOpenAQG.Base.CreateTime = DateTime.Now;
                        }
                        break;

                    case ".xlsx":
                        if (!File.Exists(txtBase.Text))
                        {
                            MessageBox.Show("File not found.", "Error"); return;
                        }
                        if (txtPollutant.Text == bcgOpenAQG.Pollutant.PollutantName)
                        {
                            bcgOpenAQG.GridType = CommonClass.GBenMAPGrid;
                            CreateShapeFile(bcgOpenAQG, "baseline", txtBase.Text);
                            bcgOpenAQG.Base.CreateTime = DateTime.Now;
                        }
                        break;
                    }
                }
                if (txtControl.Text != "")
                {
                    controlPath     = "Model Data:" + txtControl.Text;
                    inputFileFormat = controlPath.Substring(controlPath.LastIndexOf("."));
                    switch (inputFileFormat)
                    {
                    case ".csv":
                        if (!File.Exists(txtControl.Text))
                        {
                            MessageBox.Show("File not found.", "Error"); return;
                        }
                        if (txtPollutant.Text == bcgOpenAQG.Pollutant.PollutantName)
                        {
                            CreateShapeFile(bcgOpenAQG, "control", txtControl.Text);
                            bcgOpenAQG.Control.CreateTime = DateTime.Now;
                        }
                        break;

                    case ".aqgx":
                        openAQG(txtControl.Text, "control", bcgOpenAQG);
                        break;

                    case ".xls":
                        if (!File.Exists(txtControl.Text))
                        {
                            MessageBox.Show("File not found.", "Error"); return;
                        }
                        if (txtPollutant.Text == bcgOpenAQG.Pollutant.PollutantName)
                        {
                            CreateShapeFile(bcgOpenAQG, "control", txtControl.Text);
                            bcgOpenAQG.Control.CreateTime = DateTime.Now;
                        }
                        break;

                    case ".xlsx":
                        if (!File.Exists(txtControl.Text))
                        {
                            MessageBox.Show("File not found.", "Error"); return;
                        }
                        if (txtPollutant.Text == bcgOpenAQG.Pollutant.PollutantName)
                        {
                            CreateShapeFile(bcgOpenAQG, "control", txtControl.Text);
                            bcgOpenAQG.Control.CreateTime = DateTime.Now;
                        }
                        break;
                    }
                }
                WaitClose();
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WaitClose();
                Logger.LogError(ex);
            }
        }