示例#1
0
 public MonitorRollback(BaseControlGroup currentPollutant, string currentStat)
 {
     InitializeComponent();
     _bgc                 = currentPollutant;
     _currentStat         = currentStat;
     _monitorRollbackLine = new MonitorModelRollbackLine();
 }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        public GridCreationMethods(BaseControlGroup bgc, string currentStat)
        {
            InitializeComponent();
            _bgc         = bgc;
            _currentStat = currentStat;
            switch (currentStat)
            {
            case "baseline":
                if (bgc.Base != null && bgc.Base.ModelResultAttributes != null && bgc.Base.ModelResultAttributes.Count > 0)
                {
                    this.btnSave.Enabled          = true;
                    this.btnSaveNewFormat.Enabled = true;
                }
                break;

            case "control":
                if (bgc.Control != null && bgc.Control.ModelResultAttributes != null && bgc.Control.ModelResultAttributes.Count > 0)
                {
                    this.btnSave.Enabled          = true;
                    this.btnSaveNewFormat.Enabled = true;
                }
                break;
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
 public MonitorData(BaseControlGroup currentPollutant, string currentStat)
 {
     InitializeComponent();
     _bgcMonitor  = currentPollutant;
     _currentStat = currentStat;
 }
示例#6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;
            bool   bCreateShapeFile = false;

            try
            {
                if (tabControl1.SelectedIndex == 0 && string.IsNullOrEmpty(txtModelDatabase.Text))
                {
                    return;
                }
                if (tabControl1.SelectedIndex == 0 && !File.Exists(txtModelDatabase.Text))
                {
                    msg = string.Format("{0} not Exists !", "File"); return;
                }
                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)
                {
                    saveAQGPath = sfd.FileName;
                    if (tabControl1.SelectedIndex == 0)
                    {
                        if (!File.Exists(txtModelDatabase.Text))
                        {
                            msg = string.Format("{0} does not exist.", "File"); return;
                        }
                        _strPath = "Model Data: " + txtModelDatabase.Text;
                        foreach (BaseControlGroup b in CommonClass.LstBaseControlGroup)
                        {
                            if (txtPollutant.Text == b.Pollutant.PollutantName)
                            {
                                saveBCG          = b;
                                bCreateShapeFile = CreateShapeFile(b);
                                break;
                            }
                        }
                        this.DialogResult = DialogResult.OK;
                    }
                    else if (tabControl1.SelectedIndex == 1)
                    {
                        if (!File.Exists(txtModelFile.Text))
                        {
                            msg = string.Format("{0} does not Exist.", "File"); return;
                        }
                        if (!File.Exists(txtModelFile.Text))
                        {
                            msg = string.Format("{0} does not Exist", txtModelFile.Text); return;
                        }
                        _strPath = "Model Data: " + txtModelFile.Text;
                        foreach (BaseControlGroup b in CommonClass.LstBaseControlGroup)
                        {
                            if (txtPollutant.Text == b.Pollutant.PollutantName)
                            {
                                saveBCG          = b;
                                bCreateShapeFile = CreateShapeFile(b);
                                break;
                            }
                        }
                        if (bCreateShapeFile)
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WaitClose();
                Logger.LogError(ex);
            }
            finally
            {
                if (msg != string.Empty)
                {
                    WaitClose();
                    { MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
                }
            }
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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);
                }
            }
        }
示例#9
0
        private void openAQG(string sourceFilePath, string currentState, BaseControlGroup bcg)
        {
            try
            {
                string     err        = "";
                BenMAPLine benMapLine = DataSourceCommonClass.LoadAQGFile(sourceFilePath, ref err);
                if (benMapLine == null)
                {
                    WaitClose();
                    MessageBox.Show(err);
                    return;
                }

                if (bcg.Pollutant != null && benMapLine.Pollutant.PollutantID != bcg.Pollutant.PollutantID)
                {
                    WaitClose();
                    MessageBox.Show("The AQG's pollutant does not match the selected pollutant. Please select another file.");
                    if (isGridTypeChanged)
                    {
                        CommonClass.GBenMAPGrid = benMAPGridOld;
                        isGridTypeChanged       = false;
                    }

                    return;
                }
                else if (benMapLine.GridType.GridDefinitionID != bcg.GridType.GridDefinitionID)
                {
                    WaitClose();
                    MessageBox.Show("The AQG's grid definition does not match the selected grid definition. Please select another file.");
                    if (isGridTypeChanged)
                    {
                        CommonClass.GBenMAPGrid = benMAPGridOld;
                        isGridTypeChanged       = false;
                    }

                    return;
                }
                if (bcg.Pollutant == null)
                {
                    bcg.Pollutant = benMapLine.Pollutant;
                }
                if (benMapLine.ShapeFile != null && !benMapLine.ShapeFile.Contains(@"\"))
                {
                    string AppPath      = Application.StartupPath;
                    string _filePath    = sourceFilePath.Substring(0, sourceFilePath.LastIndexOf(@"\") + 1);
                    string strShapePath = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, benMapLine.ShapeFile);
                    benMapLine.ShapeFile = _filePath + benMapLine.ShapeFile;
                    DataSourceCommonClass.SaveBenMAPLineShapeFile(bcg.GridType, bcg.Pollutant, benMapLine, strShapePath);
                }
                else if (benMapLine.ShapeFile != null && benMapLine.ShapeFile.Contains(@"\"))
                {
                    DataSourceCommonClass.SaveBenMAPLineShapeFile(bcg.GridType, bcg.Pollutant, benMapLine, benMapLine.ShapeFile);
                }
                switch (currentState)
                {
                case "baseline":
                    if (bcg.Pollutant == null || bcg.Pollutant.PollutantID == benMapLine.Pollutant.PollutantID)
                    {
                        bcg.Base = benMapLine; if (CommonClass.LstPollutant == null || CommonClass.LstPollutant.Count == 0)
                        {
                            CommonClass.LstPollutant = new List <BenMAPPollutant>();
                            CommonClass.LstPollutant.Add(benMapLine.Pollutant);
                            bcg.Pollutant = benMapLine.Pollutant;
                        }
                    }

                    break;

                case "control":
                    if (bcg.Pollutant == null || bcg.Pollutant.PollutantID == benMapLine.Pollutant.PollutantID)
                    {
                        bcg.Control = benMapLine;
                    }
                    if (CommonClass.LstPollutant == null || CommonClass.LstPollutant.Count == 0)
                    {
                        CommonClass.LstPollutant = new List <BenMAPPollutant>();
                        CommonClass.LstPollutant.Add(benMapLine.Pollutant);
                        bcg.Pollutant = benMapLine.Pollutant;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
示例#10
0
 public OpenExistingAQG(BaseControlGroup bcg)
 {
     InitializeComponent();
     bcgOpenAQG = bcg;
 }