Exemplo n.º 1
0
        private void FormUser_Load(object sender, EventArgs e)
        {
            List <UserViewModel> userList = userLogic.Read(null);

            if (userList != null)
            {
                comboBoxTeacher.DisplayMember = "UserName";
                comboBoxTeacher.ValueMember   = "Id";
                comboBoxTeacher.DataSource    = userList.Where(rec => rec.NameRole == "Преподаватель").ToList();
                comboBoxTeacher.SelectedItem  = null;
            }

            if (_id.HasValue)
            {
                try
                {
                    var view = disciplineLogic.Read(new DisciplineBindingModel {
                        Id = _id
                    })?[0];
                    int selectedUserIndex = Array.IndexOf(userList.ToArray(), userList
                                                          .FirstOrDefault(rec => rec.Id == view.UserId));

                    if (view != null)
                    {
                        textBoxName.Text             = view.NameDiscipline;
                        comboBoxTeacher.SelectedItem = comboBoxTeacher.Items[selectedUserIndex];
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        private void FormUser_Load(object sender, EventArgs e)
        {
            List <DisciplineViewModel> disciplineList = disciplineLogic.Read(null);

            if (disciplineList != null)
            {
                comboBoxDiscipline.DisplayMember = "NameDiscipline";
                comboBoxDiscipline.ValueMember   = "Id";
                comboBoxDiscipline.DataSource    = disciplineList;
                comboBoxDiscipline.SelectedItem  = null;
            }

            List <UserViewModel> userList = userLogic.Read(null);

            if (userList != null)
            {
                cbTeacher.DisplayMember = "UserName";
                cbTeacher.ValueMember   = "Id";
                cbTeacher.DataSource    = userList.Where(rec => rec.NameRole == "Студент").ToList();;
                cbTeacher.SelectedItem  = null;
            }

            if (_id.HasValue)
            {
                try
                {
                    var view = markLogic.Read(new MarksBindingModel {
                        Id = _id
                    })?[0];
                    int selectedDisciplineIndex = Array.IndexOf(disciplineList.ToArray(), disciplineList.FirstOrDefault(rec => rec.Id == view.DisciplineId));
                    int selectedUserIndex       = Array.IndexOf(userList.ToArray(), userList.FirstOrDefault(rec => rec.Id == view.UserId));

                    if (view != null)
                    {
                        maskedTextBoxMark.Text          = Convert.ToString(view.Mark);
                        comboBoxDiscipline.SelectedItem = comboBoxDiscipline.Items[selectedDisciplineIndex];
                        cbTeacher.SelectedItem          = cbTeacher.Items[selectedUserIndex];
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 3
0
 private void LoadData()
 {
     try
     {
         var list = logic.Read(null);
         if (list != null)
         {
             dataGridView.DataSource              = list;
             dataGridView.Columns[0].Visible      = false;
             dataGridView.Columns[1].Visible      = false;
             dataGridView.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }