/// <summary>
        /// Реализует логику добавления ного элемента в таблицу
        /// </summary>
        private void coffeeDataGrid_AddingNewItem(object sender, AddingNewItemEventArgs e)
        {
            var grade = new CoffeeGrade();

            e.NewItem = grade;
            var viewData = new CoffeeGradeViewData(grade);

            ProductsData.Add(viewData);
        }
        public HidableCoffeeGrade(CoffeeGrade grade)
        {
            if (grade == null)
            {
                throw new ArgumentException();
            }

            Grade      = grade;
            Visibility = true;
        }
        public CoffeeGradeViewData(CoffeeGrade grade)
        {
            if (grade == null)
            {
                throw new ArgumentException();
            }

            Grade   = grade;
            Visible = true;
        }
        /// <summary>
        /// Определяет, подходит ли grade под фильтр с заданной substr
        /// </summary>
        private bool searchPredicate(string substr, CoffeeGrade grade)
        {
            if (grade == null)
            {
                return(false);
            }

            bool   isNumber   = false;
            string cellString = string.Empty;
            int    cellNumber = 0;

            switch (searchComboBox.SelectedIndex)
            {
            case 0:
                cellString = grade.Name;
                break;

            case 1:
                cellString = grade.FullName;
                break;

            case 2:
                cellString = grade.Region;
                break;

            case 3:
                cellNumber = grade.Height;
                isNumber   = true;
                break;

            case 4:
                cellNumber = grade.RipeDuration;
                isNumber   = true;
                break;

            case 5:
                cellString = grade.Description;
                break;

            default: throw new NotImplementedException();
            }

            if (!isNumber)
            {
                return(cellString.ToLower().IndexOf(substr) != -1);
            }
            int searchVal;

            if (!int.TryParse(substr, out searchVal))
            {
                return(false);
            }
            return(searchVal == cellNumber);
        }
Beispiel #5
0
        /// <summary>
        /// Получает построчно объекты типа CoffeeGrade
        /// </summary>
        public IEnumerable <CoffeeGrade> ReadGrades()
        {
            var         enumerator = fileLines.GetEnumerator();
            CoffeeGrade grade;

            while (enumerator.MoveNext())
            {
                string line    = enumerator.Current;
                bool   success = CoffeeGrade.TryParse(out grade, line, CsvSeparator);
                yield return(success ? grade : null);
            }
        }