Ejemplo n.º 1
0
 internal Controller(MainWindow parent)
 {
     _parent         = parent;
     _categories     = new List <CategoryDto>();
     _dates          = new List <DateDto>();
     _dataGridView   = _parent.dataGridView;
     _dataTable      = new WorkoutDataTable();
     _columnSelector = new DataGridViewColumnSelector(_dataTable.DateColumnName, _parent.dataGridView);
     EraseDataTable();
     LoadCategoriesFromFile();
 }
Ejemplo n.º 2
0
            internal void FillDataTable()
            {
                foreach (var date in _dates)
                {
                    date.Workouts = date.Workouts.OrderBy(x => _categories.Find(y => y.Id == x.CategoryId).Order)
                                    .ThenBy(x => _categories.Find(y => y.Id == x.CategoryId).Types.Find(a => a.Id == x.TypeId).Order).ToList();
                }
                _dataTable = new WorkoutDataTable();
                _dataTable.FillWithDto(_dates, _categories);

                _bindingSource = new BindingSource();

                _dataGridView.DataSource = _bindingSource.DataSource = _dataTable;

                SetRowHeaders();
            }
Ejemplo n.º 3
0
            internal void LoadDataFromFile()
            {
                IBaseDao dao;

                _dataTable = new WorkoutDataTable();

                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    Filter = "XML|*.xml|CSV|*.csv",
                    Title  = "Select data file"
                };

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    switch (openFileDialog.FilterIndex)
                    {
                    case 1:
                        dao    = new XmlDao();
                        _dates = dao.DeserializeToObject <List <DateDto> >(openFileDialog.FileName);
                        EraseDataTable();
                        if (IsDataCorrect())
                        {
                            FillDataTable();
                        }
                        break;

                    case 2:
                        dao            = new CsvDao();
                        _dataTable     = dao.DeserializeToObject <WorkoutDataTable>(openFileDialog.FileName);
                        _bindingSource = new BindingSource();
                        _dates         = new List <DateDto>();
                        UpdateDatesFromDataTable();
                        if (_dates.Count != 0)
                        {
                            _parent.dataGridView.DataSource = _bindingSource.DataSource = _dataTable;
                            _dataGridView.RowHeadersVisible = true;
                            _dataGridView.RowHeadersWidth   = 100;
                        }
                        else
                        {
                            _dates = new List <DateDto>();
                        }

                        break;
                    }
                }
            }
Ejemplo n.º 4
0
        public T DeserializeToObject <T>(string path)
        {
            var dataTable = new WorkoutDataTable();

            using (StreamReader streamReader = new StreamReader(path))
            {
                string[] headers = streamReader.ReadLine().Split(';');

                foreach (string header in headers)
                {
                    if (header == dataTable.DateColumnName)
                    {
                        dataTable.Columns.Add(new DataColumn(header, typeof(string)));
                    }
                    else
                    {
                        dataTable.Columns.Add(new DataColumn(header, typeof(int)));
                    }
                }

                while (!streamReader.EndOfStream)
                {
                    string[] rows = streamReader.ReadLine().Split(';');

                    DataRow row = dataTable.NewRow();

                    for (int i = 0; i < headers.Length; i++)
                    {
                        if (i == 0)
                        {
                            row[i] = rows[i];
                        }
                        else
                        {
                            row[i] = int.Parse(rows[i]);
                        }
                    }

                    dataTable.Rows.Add(row);
                }
            }
            return((dynamic)dataTable);
        }
Ejemplo n.º 5
0
 internal void EraseDataTable()
 {
     _parent.dataGridView.DataSource = null;
     _dataTable     = new WorkoutDataTable();
     _bindingSource = new BindingSource();
 }