private void cboEndpointGroup_SelectedValueChanged_1(object sender, EventArgs e) { try { string str = cboEndpointGroup.Text; string commandText = string.Format("select * from ENDPOINTS where ENDPOINTGROUPID=(select ENDPOINTGROUPID from ENDPOINTGROUPS where ENDPOINTGROUPNAME='{0}' )", str); ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboEndpoint.DataSource = ds.Tables[0]; cboEndpoint.DisplayMember = "ENDPOINTNAME"; int maxWidth = 177; int width = 177; foreach (DataRow dr in ds.Tables[0].Rows) { using (Graphics g = this.CreateGraphics()) { SizeF string_size = g.MeasureString(dr["ENDPOINTNAME"].ToString(), this.Font); width = Convert.ToInt16(string_size.Width) + 50; } maxWidth = Math.Max(maxWidth, width); } cboEndpoint.DropDownWidth = maxWidth; } catch (Exception ex) { Logger.LogError(ex); } }
private void cboMetric_SelectedValueChanged(object sender, EventArgs e) { try { string str = cboMetric.Text; DataTable dt = (DataTable)cboMetric.DataSource; string metricID = ""; foreach (DataRow dr in dt.Rows) { if (dr["METRICNAME"].ToString() == str) { metricID = dr["METRICID"].ToString(); } } if (string.IsNullOrEmpty(metricID)) { return; } string commandText = "select '' as SeasonalMetricName from SeasonalMetrics union select SeasonalMetricName from SeasonalMetrics where MetricID=" + metricID; ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboSeasonalMetric.DataSource = ds.Tables[0]; cboSeasonalMetric.DisplayMember = "SeasonalMetricName"; } catch (Exception ex) { Logger.LogError(ex); } }
private void lstAvailableDataSets_SelectedValueChanged(object sender, EventArgs e) { try { if (sender == null) { return; } var lst = sender as ListBox; if (lst.SelectedItem == null) { return; } DataRowView dr = lst.SelectedItem as DataRowView; string str = dr.Row["INFLATIONDATASETNAME"].ToString(); string commandText = string.Format("select YYEAR,ALLGOODSINDEX,MEDICALCOSTINDEX,WAGEINDEX from INFLATIONENTRIES WHERE INFLATIONDATASETID in (select INFLATIONDATASETID from INFLATIONDATASETS where INFLATIONDATASETNAME='{0}' and setupid={1}) ORDER BY YYEAR ASC", str, CommonClass.ManageSetup.SetupID); ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); olvData.DataSource = ds.Tables[0]; } catch (Exception ex) { 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 { } }
private void loadGrid() { try { ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); string commondtext = string.Format("select GridDefinitionName,GridDefinitionID,Ttype from GridDefinitions where setupid={0} order by GridDefinitionName asc", CommonClass.ManageSetup.SetupID); System.Data.DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commondtext); Dictionary <int, string> dicGridType = new Dictionary <int, string>(); dicShapeOrRegular = new Dictionary <int, int>(); foreach (DataRow dr in ds.Tables[0].Rows) { dicGridType.Add(Convert.ToInt32(dr["GridDefinitionID"]), dr["GridDefinitionName"].ToString()); dicShapeOrRegular.Add(Convert.ToInt16(dr["GridDefinitionID"]), Convert.ToInt16(dr["Ttype"])); } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lstAvailableGrid.Items.Add(new ListItem(ds.Tables[0].Rows[i]["GridDefinitionID"].ToString(), ds.Tables[0].Rows[i]["GridDefinitionName"].ToString())); cboDefaultGridType.Items.Add(ds.Tables[0].Rows[i]["GridDefinitionName"].ToString()); } commondtext = string.Format("select GridDefinitionName from GridDefinitions where setupid={0} and defaultType=1", CommonClass.ManageSetup.SetupID); object defaultGrid = fb.ExecuteScalar(CommonClass.Connection, new CommandType(), commondtext); if (defaultGrid != null) { cboDefaultGridType.Text = defaultGrid.ToString(); } if (lstAvailableGrid.Items.Count != 0) { lstAvailableGrid.SelectedIndex = 0; } } catch (Exception ex) { Logger.LogError(ex.Message); } }
private void ExportDataForlistbox() { try { string commandText = string.Format("select * from INFLATIONDATASETS where setupid={0} ", CommonClass.ManageSetup.SetupID); ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); lstAvailableDataSets.DataSource = ds.Tables[0]; lstAvailableDataSets.DisplayMember = "INFLATIONDATASETNAME"; } catch (Exception ex) { Logger.LogError(ex); } }
private void cboPollutant_SelectedValueChanged(object sender, EventArgs e) { try { string str = cboPollutant.Text; string commandText = string.Format("select * from METRICS where POLLUTANTID=(select POLLUTANTID from POLLUTANTS where POLLUTANTNAME='{0}'and setupID={1} )", str, CommonClass.ManageSetup.SetupID); ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboMetric.DataSource = ds.Tables[0]; cboMetric.DisplayMember = "METRICNAME"; } catch (Exception ex) { Logger.LogError(ex); } }
private static Dictionary <int, string> getSeasonalMetric() { try { Dictionary <int, string> dicSMetric = new Dictionary <int, string>(); string commandText = "select SeasonalMetricID,SeasonalMetricName from SeasonalMetrics "; ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, commandText); foreach (DataRow dr in ds.Tables[0].Rows) { if (!dicSMetric.Keys.Contains(Convert.ToInt32(dr["SeasonalMetricID"]))) { dicSMetric.Add(Convert.ToInt32(dr["SeasonalMetricID"]), dr["SeasonalMetricName"].ToString()); } } return(dicSMetric); } catch (Exception ex) { Logger.LogError(ex.Message); return(null); } }
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); } }
public void BindItems() { try { string commandText = "select ENDPOINTGROUPNAME from ENDPOINTGROUPS "; ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboEndpointGroup.DataSource = ds.Tables[0]; cboEndpointGroup.DisplayMember = "ENDPOINTGROUPNAME"; if (cboEndpointGroup.Items.Count > 0) { cboEndpointGroup.SelectedIndex = 0; } cboEndpointGroup.DropDownWidth = 250; commandText = "select POLLUTANTNAME from POLLUTANTS where setupID=" + CommonClass.ManageSetup.SetupID; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboPollutant.DataSource = ds.Tables[0]; cboPollutant.DisplayMember = "POLLUTANTNAME"; commandText = "select ETHNICITYNAME from ETHNICITY"; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboEthnicity.DataSource = ds.Tables[0]; cboEthnicity.DisplayMember = "ETHNICITYNAME"; cboEthnicity.SelectedIndex = -1; commandText = "select RACENAME from RACES"; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboRace.DataSource = ds.Tables[0]; cboRace.DisplayMember = "RACENAME"; cboRace.SelectedIndex = -1; commandText = "select GENDERNAME from GENDERS"; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboGender.DataSource = ds.Tables[0]; cboGender.DisplayMember = "GENDERNAME"; cboGender.SelectedIndex = -1; cboMetricStatistic.Items.Add("None"); cboMetricStatistic.Items.Add("Mean"); cboMetricStatistic.Items.Add("Median"); cboMetricStatistic.Items.Add("Max"); cboMetricStatistic.Items.Add("Min"); cboMetricStatistic.Items.Add("Sum"); cboMetricStatistic.SelectedIndex = 0; commandText = string.Format("select INCIDENCEDATASETNAME from INCIDENCEDATASETS where setupid={0} order by INCIDENCEDATASETNAME asc", CommonClass.ManageSetup.SetupID); ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboIncidenceDataSet.DataSource = ds.Tables[0]; cboIncidenceDataSet.DisplayMember = "INCIDENCEDATASETNAME"; cboIncidenceDataSet.SelectedIndex = -1; commandText = string.Format("select INCIDENCEDATASETNAME from INCIDENCEDATASETS where setupid={0} order by INCIDENCEDATASETNAME asc", CommonClass.ManageSetup.SetupID); ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboPrevalenceDataSet.DataSource = ds.Tables[0]; cboPrevalenceDataSet.DisplayMember = "INCIDENCEDATASETNAME"; cboPrevalenceDataSet.SelectedIndex = -1; commandText = string.Format("select SETUPVARIABLEDATASETNAME from SETUPVARIABLEDATASETS where setupid={0}", CommonClass.ManageSetup.SetupID); ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboVariableDataSet.DataSource = ds.Tables[0]; cboVariableDataSet.DisplayMember = "SETUPVARIABLEDATASETNAME"; cboVariableDataSet.SelectedIndex = -1; string[] AvailableFunctions = new string[] { "ABS(x)", "EXP(x)", "LOG(x)", "POW(x,y)", "SQR(x)", "ACOS(x)", "ASIN(x)", "ATAN(x)", "ATAN2(x,y)", "BIGMUL(x,y)", "CEILING(x)", "COS(x)", "COSH(x)", "DIVREM(x,y,z)", "FLOOR(x)", "IEEEREMAINDER(x,y)", "LOG10(x)", "MAX(x,y)", "MIN(x,y)", "ROUND(x,y)", "SIGN(x)", "SIN(x)", "SINH(x)", "TAN(x)", "TANH(x)", "TRUNCATE(x)" }; lstFuncAvailableFunctions.Items.AddRange(AvailableFunctions); commandText = "select * from COMMONFNFORMS"; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); lstCommonUsedFunctions.DataSource = ds.Tables[0]; lstCommonUsedFunctions.DisplayMember = "FUNCTIONALFORMTEXT"; lstCommonUsedFunctions.SelectedIndex = -1; string[] AvailableVariables = new string[] { "Beta", "DELTAQ", "POP", "Incidence", "Prevalence", "Q0", "Q1", "A", "B", "C" }; lstFuncAvailableVariables.Items.AddRange(AvailableVariables); lstFuncAvailableVariables.SelectedIndex = -1; commandText = string.Format("select distinct lower(SetupVariableName) as SetupVariableName from SetupVariables where setupvariabledatasetid in (select setupvariabledatasetid from setupvariabledatasets where setupid={0})", CommonClass.ManageSetup.SetupID); ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); lstFuncAvailableSetupVariables.DataSource = ds.Tables[0]; lstFuncAvailableSetupVariables.DisplayMember = "SetupVariableName"; lstFuncAvailableSetupVariables.SelectedIndex = -1; lstBaselineAvailableSetupVariables.DataSource = ds.Tables[0]; lstBaselineAvailableSetupVariables.DisplayMember = "SetupVariableName"; lstBaselineAvailableSetupVariables.SelectedIndex = -1; string[] BaselineAvailableFunctions = new string[] { "ABS(x)", "EXP(x)", "LOG(x)", "POW(x,y)", "SQR(x)", "ACOS(x)", "ASIN(x)", "ATAN(x)", "ATAN2(x,y)", "BIGMUL(x,y)", "CEILING(x)", "COS(x)", "COSH(x)", "DIVREM(x,y,z)", "FLOOR(x)", "IEEEREMAINDER(x,y)", "LOG10(x)", "MAX(x,y)", "MIN(x,y)", "ROUND(x,y)", "SIGN(x)", "SIN(x)", "SINH(x)", "TAN(x)", "TANH(x)", "TRUNCATE(x)" }; lstBaselineAvailableFunctions.Items.AddRange(BaselineAvailableFunctions); lstBaselineAvailableFunctions.SelectedIndex = -1; commandText = "select FUNCTIONALFORMTEXT from COMMONBLFNFORMS"; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); lstBaselineCommonUsedFunctions.DataSource = ds.Tables[0]; lstBaselineCommonUsedFunctions.DisplayMember = "FUNCTIONALFORMTEXT"; lstBaselineCommonUsedFunctions.SelectedIndex = -1; string[] BaselineAvailableVariables = new string[] { "Beta", "DELTAQ", "POP", "Incidence", "Prevalence", "Q0", "Q1", "A", "B", "C" }; lstBaselineAvailableVariables.Items.AddRange(BaselineAvailableVariables); lstBaselineAvailableVariables.SelectedIndex = -1; commandText = "select LocationTypeName from LocationType"; ds = fb.ExecuteDataset(CommonClass.Connection, new CommandType(), commandText); cboLocationName.DataSource = ds.Tables[0]; cboLocationName.DisplayMember = "LocationTypeName"; cboLocationName.SelectedIndex = -1; } catch (Exception ex) { Logger.LogError(ex); } }
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); } }
private void btnOK_Click(object sender, EventArgs e) { try { List <ModelResultAttribute> lstResult = new List <ModelResultAttribute>(); BenMAPLine inputBenMAPLine = new BenMAPLine(); List <ModelResultAttribute> outModelResultAttributes = new List <ModelResultAttribute>(); List <Dictionary <string, float> > lstBig = new List <Dictionary <string, float> >(); List <ModelResultAttribute> lstSmall = new List <ModelResultAttribute>(); string err = ""; inputBenMAPLine = DataSourceCommonClass.LoadAQGFile(txtAirQualitySurface.Text, ref err); if (inputBenMAPLine == null) { MessageBox.Show(err); return; } DataRowView drOutput = (cboAggregationSurface.SelectedItem) as DataRowView; int outputGridDefinitionID = Convert.ToInt32(drOutput["GridDefinitionID"]); if (inputBenMAPLine.GridType.GridDefinitionID == outputGridDefinitionID) { MessageBox.Show("The AQG file you want to aggregate is already at the spatial resolution of the selected aggregation surface."); return; } SaveFileDialog saveOutAQG = new SaveFileDialog(); saveOutAQG.Filter = "aqgx file|*.aqgx"; saveOutAQG.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG"; saveOutAQG.RestoreDirectory = true; if (saveOutAQG.ShowDialog() == DialogResult.Cancel) { return; } WaitShow("Aggregating air quality surface..."); string filePath = saveOutAQG.FileName.Substring(0, saveOutAQG.FileName.LastIndexOf(@"\") + 1); string fileName = saveOutAQG.FileName.Substring(saveOutAQG.FileName.LastIndexOf(@"\") + 1).Replace("aqgx", "shp"); int GridFrom = inputBenMAPLine.GridType.GridDefinitionID; if (GridFrom == 28) { GridFrom = 27; } int GridTo = outputGridDefinitionID; if (GridTo == 28) { GridTo = 27; } if (GridFrom == GridTo) { outModelResultAttributes = inputBenMAPLine.ModelResultAttributes; } else { string str = string.Format("select sourcecolumn, sourcerow, targetcolumn, targetrow,Percentage from GridDefinitionPercentages a,GridDefinitionPercentageEntries b where a.PercentageID=b.PercentageID and a.SourceGridDefinitionID={0} and a.TargetGridDefinitionID={1} and normalizationstate in (0,1)", GridFrom, GridTo); ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); DataSet ds; int iCount = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, CommandType.Text, "select count(*) from (" + str + " ) a")); if (iCount == 0) { Configuration.ConfigurationCommonClass.creatPercentageToDatabase(GridTo, GridFrom); iCount = 1; } if (iCount != 0) { Dictionary <string, Dictionary <string, double> > dicRelationShip = new Dictionary <string, Dictionary <string, double> >(); ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, str); foreach (DataRow dr in ds.Tables[0].Rows) { if (dicRelationShip.ContainsKey(dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString())) { if (!dicRelationShip[dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()].ContainsKey(dr["sourcecolumn"].ToString() + "," + dr["sourcerow"].ToString())) { dicRelationShip[dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()].Add(dr["sourcecolumn"].ToString() + "," + dr["sourcerow"].ToString(), Convert.ToDouble(dr["Percentage"])); } } else { dicRelationShip.Add(dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString(), new Dictionary <string, double>()); dicRelationShip[dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()].Add(dr["sourcecolumn"].ToString() + "," + dr["sourcerow"].ToString(), Convert.ToDouble(dr["Percentage"])); } } ds.Dispose(); Dictionary <string, ModelResultAttribute> dicModelFrom = new Dictionary <string, ModelResultAttribute>(); foreach (ModelResultAttribute mo in inputBenMAPLine.ModelResultAttributes) { dicModelFrom.Add(mo.Col + "," + mo.Row, mo); } foreach (KeyValuePair <string, Dictionary <string, double> > gra in dicRelationShip) { if (gra.Value == null || gra.Value.Count == 0) { continue; } ModelResultAttribute anew = new ModelResultAttribute(); anew.Col = Convert.ToInt32(gra.Key.Split(new char[] { ',' }).ToArray()[0]); anew.Row = Convert.ToInt32(gra.Key.Split(new char[] { ',' }).ToArray()[1]); anew.Values = new Dictionary <string, float>(); Dictionary <string, float> dicValue = new Dictionary <string, float>(); for (int i = 0; i < gra.Value.Count; i++) { if (dicModelFrom.ContainsKey(gra.Value.ToList()[i].Key)) { foreach (KeyValuePair <string, float> k in dicModelFrom[gra.Value.ToList()[i].Key].Values) { if (!anew.Values.ContainsKey(k.Key)) { anew.Values.Add(k.Key, Convert.ToSingle(k.Value * gra.Value.ToList()[i].Value)); } else { anew.Values[k.Key] += Convert.ToSingle(k.Value * gra.Value.ToList()[i].Value); } } } } if (anew.Values != null && anew.Values.Count > 0) { List <string> lstKey = anew.Values.Keys.ToList(); foreach (string k in lstKey) { anew.Values[k] = Convert.ToSingle(anew.Values[k] / gra.Value.Sum(p => p.Value)); } } outModelResultAttributes.Add(anew); } } } inputBenMAPLine.ModelResultAttributes = outModelResultAttributes; inputBenMAPLine.ModelAttributes = null; inputBenMAPLine.GridType = Grid.GridCommon.getBenMAPGridFromID(outputGridDefinitionID); DataSourceCommonClass.CreateAQGFromBenMAPLine(inputBenMAPLine, saveOutAQG.FileName); WaitClose(); MessageBox.Show("File saved.", "File saved"); this.DialogResult = DialogResult.OK; } catch (Exception ex) { WaitClose(); Logger.LogError(ex.Message); } }