Exemple #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int    index       = 0;
            string commandText = string.Empty;
            object obj;

            ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
            string setupVariableID   = string.Empty;
            string variableDatasetID = string.Empty;

            try
            {
                WaitShow("Deleting data...");
                string selectedItem  = lstDataSetVariable.SelectedItem.ToString();
                int    itemCount     = lstDataSetVariable.Items.Count;
                int    selectedIndex = lstDataSetVariable.SelectedIndex;
                lstDataSetVariable.Items.RemoveAt(selectedIndex);
                if (itemCount - 1 == selectedIndex)
                {
                    selectedIndex--;
                }
                index = _dsSelectedData.Tables.IndexOf(selectedItem);
                _dsSelectedData.Tables.RemoveAt(index);
                if (_dsSelectedDataTemp.Tables.Contains(selectedItem))
                {
                    _dsSelectedDataTemp.Tables.Remove(selectedItem);
                }
                if (_datasetName != string.Empty)
                {
                    commandText = string.Format("select SETUPVARIABLEDATASETID from SETUPVARIABLEDATASETS where setupid={0} and SETUPVARIABLEDATASETNAME='{1}'", CommonClass.ManageSetup.SetupID, _datasetName);
                    obj         = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                    int ID = int.Parse(obj.ToString());
                    commandText     = string.Format("select SetUpVariableID from SetUpVariables where SetUpVariableName='{0}' and SETUPVARIABLEDATASETID={1}", selectedItem, ID);
                    obj             = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                    setupVariableID = obj.ToString();
                    commandText     = string.Format("delete from SetUpGeographicVariables where SetUpVariableID={0}", setupVariableID);
                    int rtn = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                    commandText       = string.Format("select SetUpVariableDataSetID from SetUpVariableDataSets where SetUpVariableDataSetName='{0}'", txtDataSetName.Text);
                    obj               = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                    variableDatasetID = obj.ToString();
                    commandText       = string.Format("delete from SETUPVARIABLES where SetUpVariableID={0}", setupVariableID);
                    rtn               = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);

                    if (lstDataSetVariable.Items.Count == 0)
                    {
                        DataTable dt = new DataTable();
                        olvData.DataSource = dt;
                    }
                }
                lstDataSetVariable.SelectedIndex = selectedIndex;
                System.Threading.Thread.Sleep(300);
                WaitClose();
            }
            catch (Exception ex)
            {
                WaitClose();
                Logger.LogError(ex);
            }
        }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (lstAvailableDataSets.SelectedItem == null)
         {
             return;
         }
         ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
         string commandText = string.Empty;
         if (MessageBox.Show("Delete the selected inflation dataset?", "Confirm Deletion", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             commandText = string.Format("delete from Inflationdatasets where Inflationdatasetname='{0}' and setupid={1}", lstAvailableDataSets.Text, CommonClass.ManageSetup.SetupID);
             int i = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
         }
         commandText = string.Format("select * from INFLATIONDATASETS where SetupID={0}", CommonClass.ManageSetup.SetupID);
         DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText);
         lstAvailableDataSets.DataSource    = ds.Tables[0];
         lstAvailableDataSets.DisplayMember = "INCOMEGROWTHADJDATASETNAME";
         if (ds.Tables[0].Rows.Count == 0)
         {
             olvData.ClearObjects();
         }
     }
     catch
     { }
 }
Exemple #3
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (_dataSetID != null)
         {
             ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
             string commandText = string.Format("update MonitorDataSets set MonitorDataSetName='{0}' where MonitorDataSetID={1} and SetUpID={2}", txtDataSetName.Text, _dataSetID, CommonClass.ManageSetup.SetupID);
             fb.ExecuteNonQuery(CommonClass.Connection, CommandType.Text, commandText);
         }
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
                DataSet dsFunctions = new DataSet();
                string  commandText = "select * from FUNCTIONALFORMS";
                dsFunctions = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText);
                List <string> listFunctions     = new List <string>();
                int           rowFunctionsCount = dsFunctions.Tables[0].Rows.Count;
                for (int i = 0; i < rowFunctionsCount; i++)
                {
                    listFunctions.Add(dsFunctions.Tables[0].Rows[i][1].ToString());
                }

                commandText = "select * from BASELINEFUNCTIONALFORMS";
                DataSet       dsBaselineFunctions       = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText);
                List <string> listBaselineFunctions     = new List <string>();
                int           rowBaselineFunctionsCount = dsBaselineFunctions.Tables[0].Rows.Count;
                for (int j = 0; j < rowBaselineFunctionsCount; j++)
                {
                    listBaselineFunctions.Add(dsBaselineFunctions.Tables[0].Rows[j][1].ToString());
                }
                List <string> lstSystemVariableName     = Configuration.ConfigurationCommonClass.getAllSystemVariableNameList();
                Dictionary <string, double> dicVariable = new Dictionary <string, double>();
                foreach (string s in lstSystemVariableName)
                {
                    dicVariable.Add(s, 1);
                }
                string functionText   = Configuration.ConfigurationCommonClass.getFunctionStringFromDatabaseFunction(txtFunction.Text);
                double functionResult = Configuration.ConfigurationCommonClass.getValueFromPointEstimateFunctionString("0", functionText, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, dicVariable);
                if (txtFunction.Text == string.Empty || functionResult == -999999999.0)
                {
                    MessageBox.Show("Please input a valid value for 'Function'.");
                    return;
                }
                else
                {
                    if (!listFunctions.Contains(txtFunction.Text))
                    {
                        commandText = "select max(FUNCTIONALFORMID) from FUNCTIONALFORMS";
                        object objFunction = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                        int    functionsID = int.Parse(objFunction.ToString()) + 1;
                        commandText = string.Format("insert into FunctionalForms values ({0},'{1}')", functionsID, txtFunction.Text);
                        int rth = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                    }
                }
                if (Tools.CalculateFunctionString.dicPointEstimateMethodInfo != null)
                {
                    Tools.CalculateFunctionString.dicPointEstimateMethodInfo.Clear();
                }
                string baselineFunctionText   = Configuration.ConfigurationCommonClass.getFunctionStringFromDatabaseFunction(txtBaselineIncidenceFunction.Text);
                double baselineFunctionResult = Configuration.ConfigurationCommonClass.getValueFromBaseFunctionString("1", baselineFunctionText, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, dicVariable);
                if (baselineFunctionResult == -999999999.0)
                {
                    MessageBox.Show("Please input a valid value for 'Baseline Function'.");
                    return;
                }
                else
                {
                    if (!listBaselineFunctions.Contains(txtBaselineIncidenceFunction.Text))
                    {
                        commandText = "select max(FUNCTIONALFORMID) from BASELINEFUNCTIONALFORMS";
                        object objBaselineFunction = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                        int    BaselienFunctionID  = int.Parse(objBaselineFunction.ToString()) + 1;
                        commandText = string.Format("insert into BaselineFunctionalForms values ({0},'{1}')", BaselienFunctionID, txtBaselineIncidenceFunction.Text);
                        int rtn = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                    }
                }

                bool ok = false;
                ok = IsValidDate(txtYear.Text);
                if (ok == false)
                {
                    MessageBox.Show("Please input a valid year.");
                    return;
                }

                if (txtBetaParameter1.Text == string.Empty)
                {
                    MessageBox.Show("'Beta Parameter 1' can not be null. Please input a valid value.");
                    return;
                }
                if (txtBetaParameter2.Text == string.Empty)
                {
                    MessageBox.Show("'Beta Parameter 2' can not be null. Please input a valid value.");
                    return;
                }
                if (txtBeta.Text == string.Empty)
                {
                    MessageBox.Show("'Beta' can not be null. Please input a valid value.");
                    return;
                }
                if (txtCconstantValue.Text == string.Empty)
                {
                    MessageBox.Show("'C' can not be null. Please input a valid value.");
                    return;
                }
                if (txtBconstantValue.Text == string.Empty)
                {
                    MessageBox.Show("'B' can not be null. Please input a valid value.");
                    return;
                }
                if (nudownStartAge.Value > nudownEndAge.Value)
                {
                    MessageBox.Show("The end age must be higher than start age.");
                    return;
                }
                if (txtAconstantValue.Text == string.Empty)
                {
                    MessageBox.Show("'A' can not be null. Please input a valid value.");
                    return;
                }
                _healthImpacts.EndpointGroup             = cboEndpointGroup.Text;
                _healthImpacts.Endpoint                  = cboEndpoint.Text;
                _healthImpacts.Pollutant                 = cboPollutant.Text;
                _healthImpacts.Metric                    = cboMetric.Text;
                _healthImpacts.MetricStatistis           = cboMetricStatistic.Text;
                _healthImpacts.SeasonalMetric            = cboSeasonalMetric.Text;
                _healthImpacts.Race                      = cboRace.Text;
                _healthImpacts.Ethnicity                 = cboEthnicity.Text;
                _healthImpacts.Gender                    = cboGender.Text;
                _healthImpacts.StartAge                  = nudownStartAge.Value.ToString();
                _healthImpacts.EndAge                    = nudownEndAge.Value.ToString();
                _healthImpacts.Author                    = txtAnthor.Text;
                _healthImpacts.Year                      = txtYear.Text;
                _healthImpacts.Location                  = txtLocation.Text;
                _healthImpacts.LocationName              = cboLocationName.Text;
                _healthImpacts.Qualifier                 = txtQualifier.Text;
                _healthImpacts.OtherPollutant            = txtOtherPollutant.Text;
                _healthImpacts.Reference                 = txtReference.Text;
                _healthImpacts.Function                  = txtFunction.Text;
                _healthImpacts.BaselineIncidenceFunction = txtBaselineIncidenceFunction.Text;
                _healthImpacts.BetaDistribution          = cboBetaDistribution.Text;
                _healthImpacts.Beta                      = txtBeta.Text;
                _healthImpacts.BetaParameter1            = txtBetaParameter1.Text;
                _healthImpacts.BetaParameter2            = txtBetaParameter2.Text;
                _healthImpacts.AConstantDescription      = txtAconstantDescription.Text;
                _healthImpacts.AConstantValue            = txtAconstantValue.Text;
                _healthImpacts.BConstantDescription      = txtBconstantDescription.Text;
                _healthImpacts.BConstantValue            = txtBconstantValue.Text;
                _healthImpacts.CConstantDescription      = txtCconstantDescription.Text;
                _healthImpacts.CConstantValue            = txtCconstantValue.Text;
                _healthImpacts.Incidence                 = cboIncidenceDataSet.Text;
                _healthImpacts.Prevalence                = cboPrevalenceDataSet.Text;
                _healthImpacts.Variable                  = cboVariableDataSet.Text;
                _listCustom       = list;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDatabase.Text == string.Empty)
                {
                    MessageBox.Show("Please select a datafile.");
                    return;
                }
                ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
                string commandText = string.Format("select inflationdatasetid from inflationdatasets where setupid={0} and inflationdatasetname='{1}'", CommonClass.ManageSetup.SetupID, txtInflationDataSetName.Text);
                object obj         = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                if (obj != null)
                {
                    MessageBox.Show("This inflation dataset name is already in use. Please enter a different name.");
                    return;
                }
                DataTable dt           = new DataTable();
                string    strfilename  = string.Empty;
                string    strtablename = string.Empty;
                commandText = string.Empty;

                dt = CommonClass.ExcelToDataTable(txtDatabase.Text);
                int iYear             = -1;
                int iAllGoodsIndex    = -1;
                int iMedicalCostIndex = -1;
                int iWageIndex        = -1;

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    switch (dt.Columns[i].ColumnName.ToLower().Replace(" ", ""))
                    {
                    case "year": iYear = i;
                        break;

                    case "allgoodsindex": iAllGoodsIndex = i;
                        break;

                    case "medicalcostindex": iMedicalCostIndex = i;
                        break;

                    case "wageindex": iWageIndex = i;
                        break;
                    }
                }
                string warningtip = "";
                if (iYear < 0)
                {
                    warningtip = "'Year', ";
                }
                if (iAllGoodsIndex < 0)
                {
                    warningtip += "'AllGoodsIndex', ";
                }
                if (iMedicalCostIndex < 0)
                {
                    warningtip += "'MedicalCostIndex', ";
                }
                if (iWageIndex < 0)
                {
                    warningtip += "'WageIndex', ";
                }
                if (warningtip != "")
                {
                    warningtip = warningtip.Substring(0, warningtip.Length - 2);
                    warningtip = "Please check the column header of " + warningtip + ". It is incorrect or does not exist.";
                    MessageBox.Show(warningtip, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                commandText = "SELECT max(INFLATIONDATASETID) from INFLATIONDATASETS";
                int inflationdatasetid = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText)) + 1;
                commandText = string.Format("insert into INFLATIONDATASETS VALUES({0},{1},'{2}' )", inflationdatasetid, CommonClass.ManageSetup.SetupID, txtInflationDataSetName.Text);
                int rth = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                int currentDataSetID = inflationdatasetid;
                if (dt == null)
                {
                    return;
                }
                int rtn = 0;
                foreach (DataRow row in dt.Rows)
                {
                    if (row == null)
                    {
                        continue;
                    }
                    commandText = string.Format("insert into INFLATIONENTRIES values({0},{1},{2},{3},{4})", currentDataSetID, int.Parse(row[iYear].ToString()), row[iAllGoodsIndex], row[iMedicalCostIndex], row[iWageIndex]);
                    rtn         = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                }
                if (rtn != 0)
                {
                    InflationDataSetName = txtInflationDataSetName.Text;
                }
            }

            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDatabase.Text == string.Empty)
                {
                    MessageBox.Show("Please select a datafile.");
                    return;
                }
                ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
                string commandText = string.Format("select IncomeGrowthadjdatasetid from IncomeGrowthadjdatasets where setupid={0} and IncomeGrowthadjdatasetname='{1}'", CommonClass.ManageSetup.SetupID, txtDataSetName.Text);
                object obj         = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText);
                if (obj != null)
                {
                    MessageBox.Show("This income growth dataset name is already in use. Please enter a different name.");
                    return;
                }
                DataTable dt           = new DataTable();
                string    strfilename  = string.Empty;
                string    strtablename = string.Empty;
                commandText = string.Empty;

                dt = CommonClass.ExcelToDataTable(txtDatabase.Text);
                int iYear          = -1;
                int iMean          = -1;
                int iEndpointGroup = -1;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    switch (dt.Columns[i].ColumnName.ToLower().Replace(" ", ""))
                    {
                    case "year": iYear = i;
                        break;

                    case "mean": iMean = i;
                        break;

                    case "endpointgroup": iEndpointGroup = i;
                        break;
                    }
                }
                string warningtip = "";
                if (iYear < 0)
                {
                    warningtip = "'Year', ";
                }
                if (iMean < 0)
                {
                    warningtip += "'Mean', ";
                }
                if (iEndpointGroup < 0)
                {
                    warningtip += "'Endpoint Group', ";
                }
                if (warningtip != "")
                {
                    warningtip = warningtip.Substring(0, warningtip.Length - 2);
                    warningtip = "Please check the column header of " + warningtip + ". It is incorrect or does not exist.";
                    MessageBox.Show(warningtip, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                commandText = "SELECT max(INCOMEGROWTHADJDATASETID) from INCOMEGROWTHADJDATASETS";
                int incomegrowthadjdatasetID = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commandText)) + 1;
                commandText = string.Format("insert into INCOMEGROWTHADJDATASETS VALUES({0},{1},'{2}' )", incomegrowthadjdatasetID, CommonClass.ManageSetup.SetupID, txtDataSetName.Text);
                fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                int currentDataSetID = incomegrowthadjdatasetID;

                if (dt == null)
                {
                    return;
                }
                int rtn = 0;
                foreach (DataRow row in dt.Rows)
                {
                    if (row == null)
                    {
                        continue;
                    }
                    commandText = string.Format("insert into INCOMEGROWTHADJFACTORS(INCOMEGROWTHADJDATASETID,YYEAR,MEAN,ENDPOINTGROUPS) values({0},{1},{2},'{3}')", currentDataSetID, int.Parse(row[iYear].ToString()), row[iMean], row[iEndpointGroup]);
                    rtn         = fb.ExecuteNonQuery(CommonClass.Connection, new CommandType(), commandText);
                }
                if (rtn != 0)
                {
                    IncomeGrowthDataSetName = txtDataSetName.Text;
                }
            }

            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }