示例#1
0
        private void btnAddTeacher_Click(object sender, EventArgs e)
        {
            TeacherCategory.BaseTeacherForm btf  = new TeacherCategory.BaseTeacherForm();
            TaaliClasses.DataList           data = new TaaliClasses.DataList();
            btf.Teachers = data.TeacherList().Where(t => t.SubjectTeachers.Where(st =>
                                                                                 st.SubjectID == this.TheSubject.SubjectID && st.Active).Count() > 0 &&
                                                    (from tt in t.TimeTeachers
                                                     join uht in this.Times
                                                     on tt.TimeID equals uht.HoldingTimeID
                                                     where uht.Enabled && tt.Active
                                                     select tt.Teacher).Count() > 0 &&
                                                    (from ti in this.Times
                                                     join tt in this.TimeTableCells
                                                     on ti.HoldingTimeID equals tt.TimeTeacher.TimeID
                                                     where tt.TimeTeacher.TeacherID == t.TeacherID
                                                     select ti).Count() == 0).ToList();
            btf.SetDontShowControls();
            btf.MultiSelect = false;
            DialogResult dr = btf.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    this.TheTeacher = taali.Teachers.ToList().Where(t => t.TeacherID == btf.SelectedItems
                                                                    .SelectedItems[0].TeacherID && t.SubjectTeachers.Where(st => st.Active &&
                                                                                                                           st.SubjectID == this.TheSubject.SubjectID).Count() > 0 &&
                                                                    (from tt in t.TimeTeachers
                                                                     join ti in this.Times
                                                                     on tt.TimeID equals ti.HoldingTimeID
                                                                     where ti.Enabled
                                                                     select tt.Teacher).Count() > 0).Single();
                    this.boxTeacher.Text          = this.TheTeacher.ToString();
                    this.btnAddTeacher.Enabled    = false;
                    this.btnDeleteTeacher.Enabled = true;
                    this.btnAddClass.Enabled      = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "خطا",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                    MessageBoxOptions.RtlReading);
                }
            }
        }
        private void btnAddTeacher_Click(object sender, EventArgs e)
        {
            TeacherCategory.BaseTeacherForm btf   = new TeacherCategory.BaseTeacherForm();
            TaaliDataDataContext            taali = new TaaliDataDataContext();

            btf.Teachers = taali.TimeTeachers.Select(tt => tt.Teacher).Distinct()
                           .OrderBy(t => t.FirstName).OrderBy(t => t.LastName).ToList();
            btf.SetDontShowControls();
            btf.MultiSelect = true;
            DialogResult dr = btf.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                int id = 0;
                if (btf.SelectedItems.SelectedItems == null || btf.SelectedItems.SelectedItems.Count == 0)
                {
                    return;
                }
                if (this.Teachers == null || this.Teachers.Count() == 0)
                {
                    this.Teachers = btf.SelectedItems.SelectedItems.ToList();
                }
                else
                {
                    this.Teachers.AddRange(from g in btf.SelectedItems.SelectedItems
                                           where this.Teachers.Where(gr =>
                                                                     gr.TeacherID == g.TeacherID).Count() == 0
                                           select g);
                }
                this.Teachers = (from t in this.Teachers
                                 orderby t.LastName, t.FirstName
                                 select t).ToList();
                this.dataSource.DataSource = this.Teachers;
                foreach (var s in btf.SelectedItems.SelectedItems)
                {
                    int i = this.Teachers.IndexOf(this.Teachers.Where
                                                      (t => t.TeacherID == s.TeacherID).Single());
                    this.teacherDataGridView.Rows[i].Selected = true;
                }
                if (this.teacherDataGridView.RowCount > 0)
                {
                    this.btnDeleteTeacher.Enabled = true;
                }
            }
        }