Esempio n. 1
0
        //protected void DdlMonth_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        generateCalander();

        //        ShowHideControlsForPrinter();
        //    }
        //    catch (Exception Ex)
        //    {
        //      //  ExceptionHandler.HandleTrainingException(Ex, "DdlMonth_SelectedIndexChanged", false);
        //    }

        //}
        //protected void DdlCourse_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        LblClassDuration.Text = string.Empty;
        //      //  AppContext.TimeTableClassID = null;
        //      //  AppContext.TimeTableCourseID = UtilityFunctions.MapValue<Int64>(DdlCourse.SelectedValue, typeof(long)); ;
        //        ClassesGetByCourseID();
        //        generateCalander();

        //        ShowHideControlsForPrinter();
        //    }
        //    catch (Exception Ex)
        //    {
        //      //  ExceptionHandler.HandleTrainingException(Ex, "DdlCourse_SelectedIndexChanged", false);
        //    }

        //}
        //protected void DdlClass_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (DdlClass.SelectedIndex > 0)
        //            ClassDuration(UtilityFunctions.MapValue<Int64>(DdlClass.SelectedValue, typeof(long)));
        //      //  AppContext.TimeTableClassID = UtilityFunctions.MapValue<Int64>(DdlClass.SelectedValue, typeof(long));
        //      //  AppContext.TimeTableCourseID = null;
        //        generateCalander();

        //        ShowHideControlsForPrinter();
        //    }
        //    catch (Exception Ex)
        //    {
        //     //   ExceptionHandler.HandleTrainingException(Ex, "DdlClass_SelectedIndexChanged", false);
        //    }

        //}



        //private void ShowHideControlsForPrinter()
        //{
        //    try
        //    {
        //        if (DdlClass.SelectedIndex > 0)
        //        {
        //            LblClassName.Text = DdlClass.SelectedItem.Text;
        //            LblClassName.Visible = DdlClass.SelectedIndex > 0;
        //        }
        //        if (DdlCourse.SelectedIndex > 0)
        //        {
        //            LblCourseName.Text = DdlCourse.SelectedItem.Text;
        //            LblCourseName.Visible = DdlCourse.SelectedIndex > 0;
        //        }
        //        LblCalenderSpan.Text = DdlYear.SelectedItem.Text + " - " + DdlMonth.SelectedItem.Text;
        //    }
        //    catch (Exception Ex)
        //    {
        //      //  ExceptionHandler.HandleTrainingException(Ex, "ShowHideControlsForPrinter", false);
        //    }
        //}
        //private void BindDropDowns()
        //{
        //    try
        //    {



        //        DropDownUtil.FillDropDown(DdlCourse, ddl.CourseDDLBAL(CurrentCulture, CompanyID), "Text", "Value", "Course");
        //        DropDownUtil.FillDropDown(DdlClass, ddl.ClassDDLBAL(CurrentCulture, CompanyID), "Text", "Value", "Class");
        //        UtilityFunctions.FillDropDownWithYears(DdlYear, 5, 20, false);
        //        UtilityFunctions.FillDropDownListFromEnumCollection(DdlMonth, EnumManager.GetEnumCollection(typeof(Month)), true, "Month");
        //        DdlYear.SelectedValue = DdlYear.Items.FindByText(UtilityFunctions.GetCurrentDateTime().Year.ToString()).ToString();
        //        DdlMonth.SelectedValue = UtilityFunctions.GetCurrentDateTime().Month.ToString();
        //        generateCalander();

        //    }
        //    catch (Exception)
        //    {
        //        throw;
        //    }
        //}

        /// <summary>
        /// <para>Description:
        /// This Method will get Classes of Course by CourseID and Rebind Class DropDown</para>
        /// <para>Created By: Majid ali </para>
        /// <para>Created Date: 9/26/2013 </para>
        /// </summary>
        //private void ClassesGetByCourseID()
        //{
        //    try
        //    {
        //        if (DdlCourse.SelectedIndex > 0)
        //        {
        //            DropDownUtil.FillDropDown(DdlClass, ddl.Course_ClassDDLBAL(CurrentCulture, CompanyID, Convert.ToInt64(DdlCourse.SelectedValue)), "Text", "Value", "Class");
        //        }
        //        else
        //        {
        //            BindDropDowns();
        //            // UCReport.ClearReport();
        //        }
        //    }
        //    catch (Exception)
        //    {

        //    }
        //}

        /// <summary>
        /// <para>Description:
        /// This Method will Bind Timetable of Sessions</para>
        /// <para>Created By: Majid ali </para>
        /// <para>Created Date: 9/26/2013 </para>
        /// </summary>
        protected void generateCalander()
        {
            CalendarContainer.Controls.Clear();
            try
            {
                long?ClassID  = 0;
                long?CourseID = 0;
                if (ClassIDCall == null)
                {
                    ClassID = 0;
                }
                else
                {
                    ClassID = Convert.ToInt64(ClassIDCall);
                }

                if (CourseIDCall == null)
                {
                    CourseID = 0;
                }
                else
                {
                    CourseID = Convert.ToInt64(CourseIDCall);
                }

                DateTime  now        = Convert.ToDateTime(startDate);
                var       startDate1 = new DateTime(now.Year, now.Month, 1);
                var       endDate1   = startDate1.AddMonths(1).AddDays(-1);
                DataTable list       = _PersonBAL.SessionsByCourseAndClassID(CourseID, ClassID, CompanyID, startDate1, endDate1);
                Table     tb         = new Table();


                TableHeaderCell thSunday = new TableHeaderCell();
                thSunday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Sunday);
                thSunday.Width = 120;

                TableHeaderCell thMonday = new TableHeaderCell();
                thMonday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Monday);
                thMonday.Width = 120;

                TableHeaderCell thTuesday = new TableHeaderCell();
                thTuesday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Tuesday);
                thTuesday.Width = 120;

                TableHeaderCell thWednesday = new TableHeaderCell();
                thWednesday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Wednesday);
                thWednesday.Width = 120;

                TableHeaderCell thThursday = new TableHeaderCell();
                thThursday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Thursday);
                thThursday.Width = 120;

                TableHeaderCell thFriday = new TableHeaderCell();
                thFriday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Friday);
                thFriday.Width = 120;

                TableHeaderCell thSaturday = new TableHeaderCell();
                thSaturday.Text  = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Days), Days.Days_Saturday);
                thSaturday.Width = 120;

                TableHeaderRow th = new TableHeaderRow();
                th.Cells.Add(thSunday);
                th.Cells.Add(thMonday);
                th.Cells.Add(thTuesday);
                th.Cells.Add(thWednesday);
                th.Cells.Add(thThursday);
                th.Cells.Add(thFriday);
                th.Cells.Add(thSaturday);
                tb.Rows.Add(th);

                for (int i = 0; i < 6; i++)
                {
                    TableRow tr = new TableRow();
                    for (int j = 0; j < 7; j++)
                    {
                        TableCell tc1 = new TableCell();
                        tc1.Height = 120;
                        tr.Cells.Add(tc1);
                    }
                    tr.Height    = 50;
                    tb.GridLines = GridLines.Both;
                    tb.CssClass  = "timetable";
                    tb.Rows.Add(tr);
                }
                CalendarContainer.Controls.Add(tb);
                //***********************************************
                String   str      = startDate;
                var      words    = str.Split(@"/");
                int      monthDDl = Convert.ToInt32(words[0]);
                int      yearDDl  = Convert.ToInt32(words[1]);
                DateTime dt       = new DateTime(Convert.ToInt32(words[1]), Convert.ToInt32(words[0]), 1);
                //int fDay = (int)dt.DayOfWeek + 1;
                int fDay             = (int)dt.DayOfWeek;
                int totalDaysInMonth = DateTime.DaysInMonth(Convert.ToInt32(words[1]), Convert.ToInt32(words[0]));
                int day                  = 0;
                int indexOfCalender      = 0;
                int nextMontDays         = 0;
                int TotalDaysInlastMonth = 0;
                int month                = int.Parse(words[0]);
                int year                 = int.Parse(words[1]);
                int LnkBtnID             = 0;

                if (Convert.ToInt32(words[0]) == 1)
                {
                    TotalDaysInlastMonth = DateTime.DaysInMonth(Convert.ToInt32(words[1]), 12);
                }
                else
                {
                    TotalDaysInlastMonth = DateTime.DaysInMonth(Convert.ToInt32(words[1]), Convert.ToInt32(words[0]));
                }
                int count = tb.Rows.Count * tb.Rows[0].Cells.Count;

                for (int dayOfWeek = 1; dayOfWeek < 7; dayOfWeek++)
                {
                    for (int weekOfMonth = 0; weekOfMonth < 7; weekOfMonth++)
                    {
                        ++indexOfCalender;

                        if (indexOfCalender == (DateTime.Now.Day + fDay) && (words[0] == DateTime.Now.Month.ToString()) && (words[1] == DateTime.Now.Year.ToString()))
                        {
                            tb.Rows[dayOfWeek].Cells[weekOfMonth].Style.Add("background-color", "LimeGreen");// = System.Drawing.Color.LimeGreen;
                        }
                        if (indexOfCalender <= fDay && day < totalDaysInMonth)
                        {
                            LinkButton linkbutton = new LinkButton();
                            TotalDaysInlastMonth++;
                            linkbutton.Text = (TotalDaysInlastMonth - fDay).ToString() + "<br/>";
                            tb.Rows[dayOfWeek].Cells[weekOfMonth].Controls.Add(linkbutton);
                            linkbutton.Enabled = false;
                            int TempYear  = month == 1 ? (year) : year;
                            int TempMonth = month == 1 ? 12 : month;
                            int TempDay   = (TotalDaysInlastMonth - fDay);
                            SetControlsInCells(list, indexOfCalender, TempYear, TempMonth, TempDay, linkbutton, LnkBtnID, tb, dayOfWeek, weekOfMonth);
                        }
                        else if (indexOfCalender > fDay && day < totalDaysInMonth)
                        {
                            ++day;
                            LinkButton linkbutton = new LinkButton();

                            if (indexOfCalender - 1 == fDay)
                            {
                                string monthName1 = new DateTime(yearDDl, monthDDl, 1)
                                                    .ToString("MMMM", CultureInfo.CreateSpecificCulture("en"));
                                linkbutton.Text = monthName1 + "<br/> " + day.ToString() + "<br/>";
                            }
                            else
                            {
                                linkbutton.Text = day.ToString() + "<br/>";
                            }

                            tb.Rows[dayOfWeek].Cells[weekOfMonth].Controls.Add(linkbutton);
                            linkbutton.Enabled = false;

                            SetControlsInCells(list, indexOfCalender, year, month, day, linkbutton, LnkBtnID, tb, dayOfWeek, weekOfMonth);
                        }
                        else if (indexOfCalender > totalDaysInMonth)
                        {
                            ++nextMontDays;
                            LinkButton linkbutton = new LinkButton();
                            if (nextMontDays == 1)
                            {
                                if (words[0] == "12")
                                {
                                    linkbutton.Text = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Month), Month.Month_January) + "<br/>" + nextMontDays.ToString() + "<br/>";
                                }
                                else
                                {
                                    if (12 > monthDDl)
                                    {
                                        string monthName1 = new DateTime(yearDDl, monthDDl + 1, 1)
                                                            .ToString("MMMM", CultureInfo.CreateSpecificCulture("en"));
                                        linkbutton.Text = monthName1 + "<br/>" + nextMontDays.ToString() + "<br/>";
                                    }
                                    else
                                    {
                                        linkbutton.Text = UtilityFunctions.GetEnumDescrptionFromObjectValue(typeof(Month), Month.Month_January) + "<br/>" + nextMontDays.ToString() + "<br/>";
                                    }
                                }
                            }
                            else
                            {
                                linkbutton.Text = nextMontDays.ToString() + "<br/>";
                            }

                            tb.Rows[dayOfWeek].Cells[weekOfMonth].Controls.Add(linkbutton);
                            linkbutton.Enabled = false;
                            int TempYear  = month == 12 ? (year + 1) : year;
                            int TempMonth = month == 12 ? 1 : month + 1;
                            int TempDay   = nextMontDays;

                            SetControlsInCells(list, indexOfCalender, TempYear, TempMonth, TempDay, linkbutton, LnkBtnID, tb, dayOfWeek, weekOfMonth);
                        }
                    }
                }

                if (Convert.ToInt32(monthDDl) == 1)
                {
                    TotalDaysInlastMonth = DateTime.DaysInMonth(Convert.ToInt32(yearDDl), 12);
                }
                else
                {
                    TotalDaysInlastMonth = DateTime.DaysInMonth(Convert.ToInt32(yearDDl), Convert.ToInt32(monthDDl));
                }

                //DateTime d1;//
                //if (month == 1)
                //    d1 = new DateTime(year - 1, 12, TotalDaysInlastMonth - fDay + 1);
                //else
                //    d1 = new DateTime(year, month - 1, TotalDaysInlastMonth - fDay + 1);

                //DateTime d2;// = new DateTime(2012, 6, 8);
                //if (month == 12)
                //    d2 = new DateTime(year + 1, 1, indexOfCalender - totalDaysInMonth - 1);
                //else
                //    d2 = new DateTime(year, month + 1, indexOfCalender - totalDaysInMonth - 1);


                foreach (var item in MyColorList)
                {
                    item.Name = item.Name.Replace("#*#", string.Empty);
                    item.Name = item.Name.Replace("<br>", ", ");
                }

                rptColors.DataSource = MyColorList;
                rptColors.DataBind();

                rptColors.Visible = rptColors.Items.Count > 0;
                //*******************************************
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }