Exemplo n.º 1
0
        private Dictionary <string, object> GetNextAvailableCells(string targetCell, int countOfCells)
        {
            string rowPosition;
            string columnPosition;

            Dictionary <string, object> _availableCells = new Dictionary <string, object>();

            char[]   arrayofAlphabets = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' };
            string[] arrayofNumbers   = new string[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };

            bool isRowAlphabet = !String.IsNullOrEmpty(targetCell) && Char.IsLetter(targetCell.ToCharArray()[0]);

            GetPlate_RowColumnPosition(isRowAlphabet, targetCell, out rowPosition, out columnPosition);


            int rowCount    = isRowAlphabet ? Array.IndexOf(arrayofAlphabets, Convert.ToChar(rowPosition)) : Convert.ToInt32(rowPosition);
            int columnCount = !isRowAlphabet?Array.IndexOf(arrayofNumbers, Convert.ToChar(columnPosition)) : Convert.ToInt32(columnPosition);

            ObservableCollection <RowViewModel>     RowCollection     = (this._sourceDataContext as MainWindowViewModel).RowCollection;
            ObservableCollection <ColumnsViewModel> ColumnsCollection = (this._sourceDataContext as MainWindowViewModel).ColumnsCollection;
            MappedValueCollection RowColumnValues = (this._sourceDataContext as MainWindowViewModel).RowColumnValues;


            for (int currentRow = rowCount; currentRow < RowCollection.Count; currentRow++)
            {
                string row            = isRowAlphabet ? Convert.ToString(arrayofAlphabets[currentRow]) : string.Format("{0:D2}", currentRow);
                var    tempRowBinding = RowCollection.Where(q => q.Name.Equals(row)).FirstOrDefault();

                for (int currentColumn = columnCount; currentColumn < ColumnsCollection.Count; currentColumn++)
                {
                    if (countOfCells == _availableCells.Count)
                    {
                        break;
                    }
                    else
                    {
                        string column = !isRowAlphabet?Convert.ToString(arrayofAlphabets[currentColumn]) : string.Format("{0:D2}", currentColumn);

                        var         tempColumnBinding = ColumnsCollection.Where(p => p.Currency.Equals(column)).FirstOrDefault();
                        string      currentCell       = row + column;
                        MappedValue tempRowColumn     = RowColumnValues.Where(Z => Z.RowBinding == tempRowBinding && Z.ColumnBinding == tempColumnBinding).FirstOrDefault();

                        if (tempRowColumn.Value == null || (tempRowColumn.Value != null && (tempRowColumn.Value as CellData).ColorName == null))
                        {
                            _availableCells.Add(currentCell, tempRowColumn);
                        }
                    }
                }

                if (countOfCells == _availableCells.Count)
                {
                    break;
                }
            }


            return(_availableCells);
        }