Example #1
0
        private CCellMatrix BuildMatrixFromGrid(DataGridView pDataGrid)
        {
            CCellMatrix theMatrix = new CCellMatrix();
            CCellVector theCellVector;

            int i_row = 0;
            int i_col = 0;

            foreach (DataGridViewRow row in pDataGrid.Rows)
            {
                theCellVector = new CCellVector();
                //theMatrix.AddVector(i_row, theCellVector);

                i_col = 0;

                bool last_empty_line = true;

                foreach (DataGridViewCell cell in row.Cells)
                {
                    string colName = _theMatrix._cellHeaderVector._cellHeaders[i_col]._name;

                    // check if the last row is completely empty in order to insert the vector
                    if (!(cell.Value is null))
                    {
                        last_empty_line = false;
                    }

                    double cell_value = Convert.ToDouble(cell.Value);

                    //CCell cellToInsert = new CCell(0, cell_value);
                    CCell cellToInsert = new CCell(cell_value.ToString(), i_row);

                    var x = _theMatrix._cellHeaderVector._cellHeaders[i_col];
                    cellToInsert._cellHeader = _theMatrix._cellHeaderVector._cellHeaders[i_col];

                    theCellVector.Add(colName, cellToInsert);

                    i_col++;
                }

                if (!last_empty_line)
                {
                    theMatrix.AddVector(i_row, theCellVector);
                }


                i_row++;
            }

            return(theMatrix);
        }
Example #2
0
        private void BuildListViewFields()
        {
            listViewField.View      = View.Details;
            listViewField.GridLines = true;

            listViewField.Columns.Add("Field");
            listViewField.Columns.Add("Current Value");
            listViewField.Columns.Add("Prev Value");

            listViewField.Columns[0].Width = 80;
            listViewField.Columns[1].Width = 100;
            listViewField.Columns[2].Width = 100;

            int id_vecteur     = _cell._idCellVector;
            int id_vecteurPrev = _cell._idCellVector - 1;

            if (id_vecteurPrev < 0)
            {
                id_vecteurPrev = 0;
            }

            CCellVector currentCellVector  = _cellMatrix._Vectors[id_vecteur];
            CCellVector previousCellVector = _cellMatrix._Vectors[id_vecteurPrev];

            _cellMatrix._idCurrentVector  = id_vecteur;
            _cellMatrix._idPreviousVector = id_vecteurPrev;
            _cellMatrix._currentVector    = currentCellVector;
            _cellMatrix._previousVector   = previousCellVector;


            foreach (var c_cell in currentCellVector._Cells)
            {
                string nomChamp  = c_cell.Key;
                string curValeur = c_cell.Value._value.ToString();
                string prevValeur;

                if (id_vecteurPrev == id_vecteur)
                {
                    prevValeur = "N/A";
                }
                else
                {
                    prevValeur = previousCellVector._Cells[nomChamp]._value.ToString();
                }

                listViewField.Items.Add(new ListViewItem(new string[] { nomChamp, curValeur, prevValeur }));
            }
        }
Example #3
0
        // Load XML matrice xxxIo file and build a new matrix
        public void LoadDatagrid_Data()
        {
            // xxxIO allow to easily serialise/deserialise to xml, because no dictionary
            CCellMatrixIO matrixIO = CCellMatrixIO.Load(_fileName);

            // Create the new matrix
            _theMatrix = new CCellMatrix();

            // take back from xxxIO the Cell Columns header
            _theMatrix._cellHeaderVector = matrixIO._cellHeaderVector;

            // loop thru IO
            foreach (CCellMatrixElementIO v in matrixIO._matrixIO)
            {
                int    t_keyID   = v._keyID;
                string t_keyName = v._keyName;
                CCell  t_cell    = v._cell;

                CCellVector currentCellVector;

                // 1. determine wether the key is in the dico or not
                if (_theMatrix._Vectors.ContainsKey(t_keyID))
                {
                    // key is in: retrieve the pointe cellvector pointé par la clé
                    currentCellVector = _theMatrix._Vectors[t_keyID];
                }
                else
                {
                    // key not in, create a new cellvector and add it to the dico
                    currentCellVector = new CCellVector();
                    _theMatrix._Vectors.Add(t_keyID, currentCellVector);
                }

                // add the key and the cell to the cell vector
                currentCellVector.Add(t_keyName, t_cell);
            }

            AddDataToGrid();
        }
Example #4
0
        private void LoadDatagrid_Data(DataGridView pDataGrid, string pFileName)
        {
            CCellMatrixIO matrixIO = CCellMatrixIO.Load(pFileName);

            //CCellMatrix theMatrix = new CCellMatrix();

            this._theMatrix = new CCellMatrix();

            _theMatrix._cellHeaderVector = matrixIO._cellHeaderVector;

            foreach (CCellMatrixElementIO v in matrixIO._matrixIO)
            {
                int    t_keyID   = v._keyID;
                string t_keyName = v._keyName;
                CCell  t_cell    = v._cell;

                CCellVector currentCellVector;

                // 1. recherche si la key n'est pas déja présente dans le dico
                if (_theMatrix._Vectors.ContainsKey(t_keyID))
                {
                    // si présente, on prend comme référence  le cellvector pointé par la clé
                    currentCellVector = _theMatrix._Vectors[t_keyID];
                }
                else
                {
                    //    sinon on crée ce cellvector et on l'ajoute au dico
                    currentCellVector = new CCellVector();
                    _theMatrix._Vectors.Add(t_keyID, currentCellVector);
                }

                // add the key and the cell to the cell vector
                currentCellVector.Add(t_keyName, t_cell);
            }

            AddDataToGrid(pDataGrid, _theMatrix);
        }
Example #5
0
        private void RefreshSlaveMonitors(CCell pCell, ListView pListView)
        {
            pListView.Clear();
            pListView.View      = View.Details;
            pListView.GridLines = true;

            pListView.Columns.Add("Field");
            pListView.Columns.Add("Status");
            pListView.Columns.Add("Cycle");
            pListView.Columns.Add("Type");
            pListView.Columns.Add("Value");

            pListView.Columns.Add("PreValue");
            pListView.Columns.Add("NewValue");
            pListView.Columns.Add("Script");

            int colId = 0;

            pListView.Columns[colId++].Width = 80;
            pListView.Columns[colId++].Width = 60;
            pListView.Columns[colId++].Width = 30;
            pListView.Columns[colId++].Width = 60;
            pListView.Columns[colId++].Width = 60;

            pListView.Columns[colId++].Width = 60;
            pListView.Columns[colId++].Width = 60;
            pListView.Columns[colId++].Width = 200;

            int id_vecteur     = pCell._idCellVector;
            int id_vecteurPrev = pCell._idCellVector - 1;

            if (id_vecteurPrev < 0)
            {
                id_vecteurPrev = 0;
            }

            CCellVector currentCellVector  = _theMatrix._Vectors[id_vecteur];
            CCellVector previousCellVector = _theMatrix._Vectors[id_vecteurPrev];

            _theMatrix._idCurrentVector  = id_vecteur;
            _theMatrix._idPreviousVector = id_vecteurPrev;
            _theMatrix._currentVector    = currentCellVector;
            _theMatrix._previousVector   = previousCellVector;


            foreach (var c_cell in currentCellVector._Cells)
            {
                string nomChamp = c_cell.Key;

                string curValeur = "";
                if (!(c_cell.Value._value is null))
                {
                    curValeur = c_cell.Value._value.ToString();
                }

                string prevValeur;
                string script     = "";
                string cellType   = "?";
                string cellStatus = "?";
                string cycle      = c_cell.Value._calculationPass.ToString();

                if (id_vecteurPrev == id_vecteur)
                {
                    prevValeur = "N/A";
                }
                else
                {
                    prevValeur = previousCellVector._Cells[nomChamp]._value.ToString();
                }

                try  // This is the Script at header level
                {
                    var ceelH = _theMatrix._cellHeaderVector._cellHeaders;

                    script   = (ceelH.First(s => s._name == nomChamp))._script;
                    cellType = ((ceelH.First(s => s._name == nomChamp))._type == ECellType.Input) ? "Input" : "Script";


                    switch (c_cell.Value._status)
                    {
                    case ECellStatus.Clean:
                        cellStatus = "Clean";
                        break;

                    case ECellStatus.Dirty:
                        cellStatus = "Dirty";
                        break;

                    case ECellStatus.Error:
                        cellStatus = "Error";
                        break;

                    case ECellStatus.N_A:
                        cellStatus = "N_A";
                        break;

                    default:
                        cellStatus = "Other";
                        break;
                    }
                }
                catch (Exception) { script = ""; } // Much better than linq.FirstOrDefault: in case of nothing found then empty script



                pListView.Items.Add(new ListViewItem(new string[] { nomChamp, cellStatus, cycle, cellType, curValeur, prevValeur, "", script }));
            }
        }
Example #6
0
        public CCellMatrix BuildMatrixFromGrid()
        {
            // back the headerVector
            CCellHeaderVector tCellHeaderVector = _theMatrix._cellHeaderVector;

            // back the new matrix
            CCellMatrix theMatrix = new CCellMatrix();

            // back the headerVector
            theMatrix._cellHeaderVector = tCellHeaderVector;

            CCellVector theCellVector;


            int i_row = 0;
            int i_col = 0;

            foreach (DataGridViewRow row in _theDataGrid.Rows)
            {
                theCellVector = new CCellVector();

                i_col = 0;

                bool last_empty_line = true;

                foreach (DataGridViewCell gridCell in row.Cells)
                {
                    string colName = _theMatrix.ColumnsHeader[i_col]._name;

                    // check if the last row is completely empty in order to insert the vector
                    // see also comment after the foreach loop
                    if (!(gridCell.Value is null))
                    {
                        last_empty_line = false;
                    }

                    CCell cellToInsert;

                    if (gridCell.Tag is null)
                    {
                        string cell_value = (string)gridCell.Value;
                        cellToInsert = new CCell(cell_value, i_row);

                        cellToInsert._cellHeader = _theMatrix.ColumnsHeader[i_col];
                    }
                    else
                    {
                        cellToInsert = (CCell)gridCell.Tag;
                    }

                    theCellVector.Add(colName, cellToInsert);

                    i_col++;
                }

                // in the row is not empty it is added
                if (!last_empty_line)
                {
                    theMatrix.AddVector(i_row, theCellVector);
                }


                i_row++;
            }

            return(theMatrix);
        }