Exemple #1
0
        public TimeTableForm()
        {
            InitializeComponent();
            this.taali = new TaaliDataDataContext();
            this.table = new List <TimeCategory.TimeTableClass <TimeTable> >();
            var times = this.taali.UniversityHoldingTimes.Where(uht => uht.Possible)
                        .OrderBy(uht => uht.StartTime).Select(uht => new
            {
                Start = uht.StartTime,
                End   = uht.EndTime
            }).Distinct();

            foreach (var time in times)
            {
                TimeCategory.TimeTableClass <TimeTable> row =
                    new TimeCategory.TimeTableClass <TimeTable>(time.Start, time.End);
                this.table.Add(row);
            }
            this.timeTableGridView.DataSource = this.table;
            this.findDisableCells();
            this.styleDisableCells();
            if (this.taali.GroupSubjects != null && this.taali.GroupSubjects.Count() != 0)
            {
                this.boxYearCombo.Items.AddRange(this.taali.GroupSubjects
                                                 .OrderByDescending(gs => gs.TermYear).Select(tt => tt.TermYear.ToString())
                                                 .Distinct().ToArray());
                this.boxYearCombo.SelectedIndex = this.boxYearCombo.Items.Count - 1;
                if (this.boxYearCombo.SelectedItem != null)
                {
                    this.year = Convert.ToByte(this.boxYearCombo.SelectedItem);
                }
                this.semester = this.taali.GroupSubjects
                                .Where(gs => gs.TermYear == this.taali.GroupSubjects.Max(g => g.TermYear))
                                .Distinct().Max(gs => gs.Semester);
                this.boxSemesterCombo.SelectedIndex = this.semester - 1;
                this.isFilled = true;
            }
            this.readData();
            this.FillGroupComboBox();
            this.ShowData();
        }
        private void btnShowReport_Click(object sender, EventArgs e)
        {
            byte year     = 0;
            byte semester = 0;

            if (this.boxYearCombo.SelectedIndex >= 0)
            {
                year = Convert.ToByte(this.boxYearCombo.SelectedItem);
            }
            if (this.boxSemesterCombo.SelectedIndex >= 0)
            {
                semester = (byte)(this.boxSemesterCombo.SelectedIndex + 1);
            }
            if (year == 0)
            {
                MessageBox.Show("لطفا ابتدا مشخص کنید برای چه سالی قسد گزارش گیری دارید."
                                , "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return;
            }
            if (semester == 0)
            {
                MessageBox.Show("لطفا ابتدا مشخص کنید برای چه ترمی قسد گزارش گیری دارید."
                                , "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return;
            }
            ReportDocument       rd    = new ReportDocument();
            TaaliDataDataContext taali = new TaaliDataDataContext();
            var groups = (from tt in taali.TimeTables.Distinct()
                          where tt.GroupSubject.TermYear == year &&
                          tt.GroupSubject.Semester == semester
                          group tt by tt.GroupSubject.GroupID);

            if (groups == null && groups.Count() > 0)
            {
                MessageBox.Show("برای سال و ترمی که شما انتخاب کردید هیچ برنامه هفتگی وجود ندارد."
                                , "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return;
            }
            List <TimeTableView> tablesView = new List <TimeTableView>();

            foreach (var table in groups)
            {
                List <TimeCategory.TimeTableClass <TimeTable> > tables =
                    new List <TimeCategory.TimeTableClass <TimeTable> >();
                var periods = from uht in taali.UniversityHoldingTimes
                              where uht.Possible
                              select new
                {
                    StartTime = uht.StartTime,
                    EndTime   = uht.EndTime
                };
                periods = periods.Distinct();
                foreach (var period in periods)
                {
                    TimeCategory.TimeTableClass <TimeTable> row =
                        new TimeCategory.TimeTableClass <TimeTable>(period.StartTime,
                                                                    period.EndTime);
                    var days = from uht in taali.UniversityHoldingTimes
                               where uht.Possible
                               select uht.HoldingDay;
                    foreach (var day in days)
                    {
                        if (table.Where(t => t.GroupSubject.GroupID == table.Key &&
                                        t.TimeTeacher.UniversityHoldingTime.StartTime == period.StartTime &&
                                        t.TimeTeacher.UniversityHoldingTime.EndTime == period.EndTime &&
                                        t.TimeTeacher.UniversityHoldingTime.HoldingDay == day)
                            .Count() == 1)
                        {
                            row.Fill(table.Where(t => t.GroupSubject.GroupID == table.Key &&
                                                 t.TimeTeacher.UniversityHoldingTime.StartTime == period.StartTime &&
                                                 t.TimeTeacher.UniversityHoldingTime.EndTime == period.EndTime &&
                                                 t.TimeTeacher.UniversityHoldingTime.HoldingDay == day).Single(),
                                     day);
                        }
                    }
                    tables.Add(row);
                }
                foreach (var row in tables)
                {
                    TimeTableView records = new TimeTableView();
                    if (!row.IsEmpty)
                    {
                        records.Fill(taali.Groups.Where(g => g.GroupID == table.Key).Single(), row);
                        tablesView.Add(records);
                    }
                }
            }

            if (tablesView.Count == 0)
            {
                MessageBox.Show("برای سال و ترمی که شما انتخاب کردید هیچ برنامه هفتگی وجود ندارد."
                                , "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                this.boxYearCombo.SelectedIndex     = this.yearIndexCombo;
                this.boxSemesterCombo.SelectedIndex = this.semesterIndexCombo;
                return;
            }
            this.yearIndexCombo     = this.boxYearCombo.SelectedIndex;
            this.semesterIndexCombo = this.boxSemesterCombo.SelectedIndex;
            rd.Load("TimeTableReport.rpt");
            rd.VerifyDatabase();
            rd.SetDataSource(tablesView);
            timeTableViewer.ReportSource = rd;
        }