private void CreateShapeFile(BaseControlGroup b, string state, string filePath) { string msg = string.Empty; ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper(); ModelDataLine modelDataLine = new ModelDataLine(); try { modelDataLine.DatabaseFilePath = filePath; System.Data.DataTable dtModel = CommonClass.ExcelToDataTable(filePath); DataSourceCommonClass.UpdateModelDataLineFromDataSet(b.Pollutant, modelDataLine, dtModel); switch (state) { case "baseline": b.Base = null; b.Base = modelDataLine; break; case "control": b.Control = null; b.Control = modelDataLine; break; } if (modelDataLine.ModelAttributes.Count == 0) { msg = "Error reading files."; return; } int threadId = -1; AsyncDelegate asyncD = new AsyncDelegate(AsyncCreateFile); IAsyncResult ar = asyncD.BeginInvoke(b, modelDataLine, state, out threadId, null, null); return; } catch (Exception ex) { Logger.LogError(ex); return; } finally { if (msg != string.Empty) { MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private bool DrawMointorMap() { bool ok = false; double value = 0.0; string msg = string.Empty; try { if (rbtnClosestMonitor.Checked) { _mDataLine.InterpolationMethod = InterpolationMethodEnum.ClosestMonitor; } else if (rbtnVoronoi.Checked) { _mDataLine.InterpolationMethod = InterpolationMethodEnum.VoronoiNeighborhoodAveragin; } else if (rbtnFixedRadiums.Checked) { _mDataLine.InterpolationMethod = InterpolationMethodEnum.FixedRadius; ok = double.TryParse(txtRadiums.Text, out value); if (!ok) { msg = "To select fixed radius interpolation you must provide a radius in kilometers."; txtRadiums.Text = string.Empty; return(false); } _mDataLine.FixedRadius = value; } int selectedIndex = cboMonitorType.SelectedIndex; switch (selectedIndex) { case 0: _mDataLine.MonitorDirectType = selectedIndex; if (cboMonitorDataSet.Text != string.Empty && cboMonitorLibraryYear.Text != string.Empty) { DataRowView drv = cboMonitorDataSet.SelectedItem as DataRowView; int dsID = int.Parse(drv["MonitorDataSetID"].ToString()); _mDataLine.MonitorDataSetID = dsID; drv = cboMonitorLibraryYear.SelectedItem as DataRowView; _mDataLine.MonitorLibraryYear = int.Parse(drv["Yyear"].ToString()); } else { msg = string.Format("Settings are not complete."); return(false); } _strPath = "Monitor data: library"; break; case 1: _mDataLine.MonitorDirectType = selectedIndex; if (txtMonitorDataFile.Text != string.Empty) { _mDataLine.MonitorDataFilePath = txtMonitorDataFile.Text; } else { msg = string.Format("Settings are not complete."); return(false); } _strPath = "Monitor data: " + txtMonitorDataFile.Text; break; } if (_monitorAdvance != null) { _mDataLine.MonitorAdvance = _monitorAdvance; } ModelDataLine m = new ModelDataLine(); switch (_currentStat) { case "baseline": DataSourceCommonClass.UpdateModelValuesMonitorData(_bgcMonitor.GridType, _bgcMonitor.Pollutant, ref _mDataLine); lock (CommonClass.LstBaseControlGroup) { foreach (BaseControlGroup bc in CommonClass.LstBaseControlGroup) { if (bc.Pollutant.PollutantID == _bgcMonitor.Pollutant.PollutantID) { _mDataLine.GridType = _bgcMonitor.GridType; _mDataLine.Pollutant = _bgcMonitor.Pollutant; _mDataLine.ShapeFile = _mDataLine.Pollutant.PollutantID + "G" + CommonClass.GBenMAPGrid.GridDefinitionID + "B" + _currentStat + ".shp"; string shipFile = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, _mDataLine.ShapeFile); bc.Base = _mDataLine; DataSourceCommonClass.SaveBenMAPLineShapeFile(_mDataLine.GridType, _mDataLine.Pollutant, _mDataLine, shipFile); bc.Base.ShapeFile = ""; } } } _bgcMonitor.Base = _mDataLine; break; case "control": DataSourceCommonClass.UpdateModelValuesMonitorData(_bgcMonitor.GridType, _bgcMonitor.Pollutant, ref _mDataLine); lock (CommonClass.LstBaseControlGroup) { foreach (BaseControlGroup bc in CommonClass.LstBaseControlGroup) { if (bc.Pollutant.PollutantID == _bgcMonitor.Pollutant.PollutantID) { _mDataLine.GridType = _bgcMonitor.GridType; _mDataLine.Pollutant = _bgcMonitor.Pollutant; _mDataLine.ShapeFile = _mDataLine.Pollutant.PollutantID + "G" + CommonClass.GBenMAPGrid.GridDefinitionID + "C" + _currentStat + ".shp"; string shipFile = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, _mDataLine.ShapeFile); bc.Control = _mDataLine; DataSourceCommonClass.SaveBenMAPLineShapeFile(_mDataLine.GridType, _mDataLine.Pollutant, _mDataLine, shipFile); bc.Control.ShapeFile = ""; } } } _bgcMonitor.Control = _mDataLine; break; } return(true); } catch (Exception ex) { Logger.LogError(ex); return(false); } }
private string AsyncUpdateMonitorData(BaseControlGroup bcg, ModelDataLine m, string currentStat, out int threadId) { threadId = -1; string str = string.Empty; try { if (CommonClass.LstAsynchronizationStates == null) { CommonClass.LstAsynchronizationStates = new List <string>(); } lock (CommonClass.LstAsynchronizationStates) { str = string.Format("{0}{1}", bcg.Pollutant.PollutantName.ToLower(), currentStat); CommonClass.LstAsynchronizationStates.Add(str); if (currentStat != "") { CommonClass.CurrentMainFormStat = currentStat.Substring(0, 1).ToUpper() + currentStat.Substring(1) + " is being created."; } } lock (CommonClass.NodeAnscyStatus) { CommonClass.NodeAnscyStatus = string.Format("{0};{1};on", bcg.Pollutant.PollutantName.ToLower(), _currentStat); } switch (_currentStat) { case "baseline": DataSourceCommonClass.UpdateModelValuesMonitorData(_bgcMonitor.GridType, _bgcMonitor.Pollutant, ref _mDataLine); lock (CommonClass.LstBaseControlGroup) { foreach (BaseControlGroup bc in CommonClass.LstBaseControlGroup) { if (bc.Pollutant.PollutantID == _bgcMonitor.Pollutant.PollutantID) { _mDataLine.GridType = _bgcMonitor.GridType; _mDataLine.Pollutant = _bgcMonitor.Pollutant; _mDataLine.ShapeFile = _mDataLine.Pollutant.PollutantID + "G" + CommonClass.GBenMAPGrid.GridDefinitionID + "B" + _currentStat + ".shp"; string shipFile = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, _mDataLine.ShapeFile); bc.Base = _mDataLine; DataSourceCommonClass.SaveBenMAPLineShapeFile(_mDataLine.GridType, _mDataLine.Pollutant, _mDataLine, shipFile); DataSourceCommonClass.CreateAQGFromBenMAPLine(bc.Base, saveAQGPath); bc.Base.ShapeFile = ""; } } } _bgcMonitor.Base = _mDataLine; break; case "control": DataSourceCommonClass.UpdateModelValuesMonitorData(_bgcMonitor.GridType, _bgcMonitor.Pollutant, ref _mDataLine); lock (CommonClass.LstBaseControlGroup) { foreach (BaseControlGroup bc in CommonClass.LstBaseControlGroup) { if (bc.Pollutant.PollutantID == _bgcMonitor.Pollutant.PollutantID) { _mDataLine.GridType = _bgcMonitor.GridType; _mDataLine.Pollutant = _bgcMonitor.Pollutant; _mDataLine.ShapeFile = _mDataLine.Pollutant.PollutantID + "G" + CommonClass.GBenMAPGrid.GridDefinitionID + "C" + _currentStat + ".shp"; string shipFile = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, _mDataLine.ShapeFile); bc.Control = _mDataLine; DataSourceCommonClass.SaveBenMAPLineShapeFile(_mDataLine.GridType, _mDataLine.Pollutant, _mDataLine, shipFile); DataSourceCommonClass.CreateAQGFromBenMAPLine(bc.Control, saveAQGPath); bc.Control.ShapeFile = ""; } } } _bgcMonitor.Control = _mDataLine; break; } List <ModelResultAttribute> lstRemove = new List <ModelResultAttribute>(); foreach (ModelResultAttribute model in _mDataLine.ModelResultAttributes) { if (model.Values == null || model.Values.Count == 0) { lstRemove.Add(model); } } foreach (ModelResultAttribute model in lstRemove) { _mDataLine.ModelResultAttributes.Remove(model); } lock (CommonClass.LstAsynchronizationStates) { CommonClass.LstAsynchronizationStates.Remove(str); if (CommonClass.LstAsynchronizationStates.Count == 0) { CommonClass.CurrentMainFormStat = "Current Setup: " + CommonClass.MainSetup.SetupName; } } lock (CommonClass.NodeAnscyStatus) { CommonClass.NodeAnscyStatus = string.Format("{0};{1};off", bcg.Pollutant.PollutantName.ToLower(), _currentStat); } return(str); } catch (Exception ex) { lock (CommonClass.LstAsynchronizationStates) { CommonClass.LstAsynchronizationStates.Remove(str); if (CommonClass.LstAsynchronizationStates.Count == 0) { CommonClass.CurrentMainFormStat = "Current Setup: " + CommonClass.MainSetup.SetupName; } } lock (CommonClass.NodeAnscyStatus) { CommonClass.NodeAnscyStatus = string.Format("{0};{1};off", bcg.Pollutant.PollutantName.ToLower(), _currentStat); } Logger.LogError(ex); return(string.Empty); } }
private void btnGo_Click(object sender, EventArgs e) { string msg = string.Empty; bool ok = false; double value = 0.0; try { if (rbtnClosestMonitor.Checked) { _mDataLine.InterpolationMethod = InterpolationMethodEnum.ClosestMonitor; } else if (rbtnVoronoi.Checked) { _mDataLine.InterpolationMethod = InterpolationMethodEnum.VoronoiNeighborhoodAveragin; } else if (rbtnFixedRadiums.Checked) { _mDataLine.InterpolationMethod = InterpolationMethodEnum.FixedRadius; ok = double.TryParse(txtRadiums.Text, out value); if (!ok || Convert.ToDouble(txtRadiums.Text) <= 0) { msg = "To select fixed radius interpolation you must provide a radius in kilometers."; txtRadiums.Text = string.Empty; return; } _mDataLine.FixedRadius = value; } int selectedIndex = cboMonitorType.SelectedIndex; switch (selectedIndex) { case 0: _mDataLine.MonitorDirectType = selectedIndex; if (cboMonitorDataSet.Text != string.Empty && cboMonitorLibraryYear.Text != string.Empty) { DataRowView drv = cboMonitorDataSet.SelectedItem as DataRowView; int dsID = int.Parse(drv["MonitorDataSetID"].ToString()); _mDataLine.MonitorDataSetID = dsID; drv = cboMonitorLibraryYear.SelectedItem as DataRowView; _mDataLine.MonitorLibraryYear = int.Parse(drv["Yyear"].ToString()); } else { msg = string.Format("Settings are not completed."); return; } _strPath = "Monitor data: library"; break; case 1: _mDataLine.MonitorDirectType = selectedIndex; if (txtMonitorDataFile.Text != string.Empty) { _mDataLine.MonitorDataFilePath = txtMonitorDataFile.Text; } else { msg = string.Format("Settings are not completed."); return; } _strPath = "Monitor data: " + txtMonitorDataFile.Text; break; } SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "AQG files (*.aqgx)|*.aqgx"; sfd.FilterIndex = 2; sfd.RestoreDirectory = true; sfd.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG"; if (sfd.ShowDialog() != DialogResult.OK) { return; } saveAQGPath = sfd.FileName; if (_monitorAdvance != null) { _mDataLine.MonitorAdvance = _monitorAdvance; } ModelDataLine m = new ModelDataLine(); int threadId = -1; AsyncDelegate asyncD = new AsyncDelegate(AsyncUpdateMonitorData); IAsyncResult ar = asyncD.BeginInvoke(_bgcMonitor, m, _currentStat, out threadId, null, null); this.DialogResult = DialogResult.OK; } catch (Exception ex) { Logger.LogError(ex); } finally { if (msg != string.Empty) { MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private string AsyncCreateFile(BaseControlGroup bcg, ModelDataLine m, string currentStat, out int threadId) { threadId = -1; string shapeFile = string.Empty; string strShapePath = string.Empty; string AppPath = Application.StartupPath; string str = string.Empty; try { if (CommonClass.LstAsynchronizationStates == null) { CommonClass.LstAsynchronizationStates = new List <string>(); } lock (CommonClass.LstAsynchronizationStates) { str = string.Format("{0}{1}", bcg.Pollutant.PollutantName.ToLower(), currentStat); CommonClass.LstAsynchronizationStates.Add(str); if (currentStat != "") { CommonClass.CurrentMainFormStat = currentStat.Substring(0, 1).ToUpper() + currentStat.Substring(1) + " is being created."; } } lock (CommonClass.NodeAnscyStatus) { CommonClass.NodeAnscyStatus = string.Format("{0};{1};on", bcg.Pollutant.PollutantName.ToLower(), _currentStat); } DateTime dt = DateTime.Now; shapeFile = string.Format("{0}{1}{2}{3}{4}{5}.shp", new string[] { bcg.Pollutant.PollutantName.ToLower(), currentStat, dt.ToString("yyyyMMdd"), dt.Hour.ToString("00"), dt.Minute.ToString("00"), dt.Second.ToString("00") }); Random random = new Random(); shapeFile = string.Format("{0}{1}{2}.shp", new string[] { bcg.Pollutant.PollutantName.ToLower(), currentStat, random.Next(100).ToString() }); shapeFile = bcg.Pollutant.PollutantID + "G" + CommonClass.GBenMAPGrid.GridDefinitionID + "B" + currentStat + ".shp"; strShapePath = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, shapeFile); Dictionary <int, string> dicSeasonStatics = new Dictionary <int, string>(); DataSourceCommonClass.UpdateModelValuesModelData(DataSourceCommonClass.DicSeasonStaticsAll, bcg.GridType, bcg.Pollutant, m, strShapePath); lock (CommonClass.LstAsynchronizationStates) { CommonClass.LstAsynchronizationStates.Remove(str); if (CommonClass.LstAsynchronizationStates.Count == 0) { CommonClass.CurrentMainFormStat = "Current Setup: " + CommonClass.MainSetup.SetupName; } } lock (CommonClass.NodeAnscyStatus) { CommonClass.NodeAnscyStatus = string.Format("{0};{1};off", bcg.Pollutant.PollutantName.ToLower(), _currentStat); } switch (_currentStat) { case "baseline": DataSourceCommonClass.CreateAQGFromBenMAPLine(saveBCG.Base, saveAQGPath); saveBCG.Base.ShapeFile = ""; break; case "control": DataSourceCommonClass.CreateAQGFromBenMAPLine(saveBCG.Control, saveAQGPath); saveBCG.Control.ShapeFile = ""; break; } return(str); } catch (Exception ex) { Logger.LogError(ex); return(string.Empty); } }
private bool CreateShapeFile(BaseControlGroup b) { string msg = string.Empty; System.Data.DataSet ds; string currentStat = string.Empty; try { currentStat = _currentStat; ModelDataLine modelDataLine = new ModelDataLine(); if (tabControl1.SelectedIndex == 0) { WaitShow("Loading model data file."); modelDataLine.DatabaseFilePath = txtModelDatabase.Text; System.Data.DataTable dtModel = CommonClass.ExcelToDataTable(txtModelDatabase.Text); DataSourceCommonClass.UpdateModelDataLineFromDataSet(b.Pollutant, modelDataLine, dtModel); } else { StreamReader sr = new StreamReader(txtModelFile.Text); string csvDataLine; csvDataLine = ""; string fileDataLine; fileDataLine = sr.ReadLine(); string[] sMatchArray = fileDataLine.Split(new char[] { ',' }); if (!(sMatchArray[0].Replace("\"", "") == b.Pollutant.PollutantName && sMatchArray[1] == b.GridType.GridDefinitionName && sMatchArray[2].Replace("\"", "") == "Model")) { MessageBox.Show("The pollutant or grid definition do not match."); return(false); } WaitShow("Loading model data file..."); string strLine = ""; ds = new System.Data.DataSet(); DataTable dt = new DataTable(); DataRow dr = null; string[] strArray; strLine = sr.ReadLine(); if (strLine != null && strLine.Length > 0) { strArray = strLine.Split(','); for (int i = 0; i < strArray.Count(); i++) { dt.Columns.Add(strArray[i]); } } while (strLine != null) { strLine = sr.ReadLine(); if (strLine != null && strLine.Length > 0) { dr = dt.NewRow(); strArray = strLine.Split(','); for (int i = 0; i < strArray.Count(); i++) { dr[i] = strArray[i]; } dt.Rows.Add(dr); } } ds.Tables.Add(dt); modelDataLine.DatabaseFilePath = txtModelFile.Text; DataSourceCommonClass.UpdateModelDataLineFromDataSetNewFormat(b.Pollutant, ref modelDataLine, ds); sr.Close(); switch (currentStat) { case "baseline": b.Base = null; b.Base = modelDataLine; b.Base.GridType = b.GridType; break; case "control": b.Control = null; b.Control = modelDataLine; b.Control.GridType = b.GridType; break; } } System.Threading.Thread.Sleep(100); WaitClose(); switch (currentStat) { case "baseline": b.Base = null; b.Base = modelDataLine; break; case "control": b.Control = null; b.Control = modelDataLine; break; } if (modelDataLine.ModelAttributes.Count == 0 && modelDataLine.ModelResultAttributes.Count == 0) { msg = "Error reading files."; return(false); } int threadId = -1; AsyncDelegate asyncD = new AsyncDelegate(AsyncCreateFile); IAsyncResult ar = asyncD.BeginInvoke(b, modelDataLine, currentStat, out threadId, null, null); return(true); } catch (Exception ex) { WaitClose(); Logger.LogError(ex); return(false); } finally { if (msg != string.Empty) { MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }