コード例 #1
0
        private void LoadData()
        {
            try
            {
                var routes = logicReport.GetRoutes(new ReportBindingModel
                {
                    UserId   = Program.User.Id,
                    DateFrom = dateTimePickerFrom.Value,
                    DateTo   = dateTimePickerTo.Value
                });

                if (routes != null)
                {
                    dataGridView.Rows.Clear();
                    int i = 0;
                    List <ReserveViewModel> reserves = null;
                    foreach (var route in routes)
                    {
                        reserves = null; // чтоб не ругалось, формы всё равно не нужны =(
                        dataGridView.Rows.Add(new object[] { route.Name, route.Count, reserves[0].Name, route.DateVisit.ToString("d"), route.Cost, reserves[0].Price });

                        if (dataGridView.Rows[i].Cells[2] is DataGridViewComboBoxCell cb)
                        {
                            cb.DataSource    = reserves;
                            cb.ValueMember   = "Name";
                            cb.DisplayMember = "Name";
                        }
                        ++i;
                    }
                    //foreach (DataGridViewRow row in dataGridView.Rows)
                    //{
                    //    var res = reserves.FirstOrDefault(x => x.Name == row.Cells[2].Value.ToString());
                    //    row.Cells[5].Value = res?.Price;
                    //}
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }