예제 #1
0
    public void CopyScheduleFromLastMonth(int branchID, int year, int month)
    {
        DateTime lastPeriod = new DateTime(year, month, 1).AddMonths(-1);

        var schedules =
            ctx.ClassScheduleDetails.Where(
                sch => sch.BranchID == branchID && sch.Year == lastPeriod.Year && sch.Month == lastPeriod.Month);

        ctx.ClassScheduleDetails.DeleteAllOnSubmit(
            ctx.ClassScheduleDetails.Where(sch => sch.BranchID == branchID && sch.Year == year && sch.Month == month));
        ctx.SubmitChanges();

        foreach (var schedule in schedules)
        {
            var newSchedule = new ClassScheduleDetail();
            newSchedule.InstructorID = schedule.InstructorID;
            newSchedule.Level        = schedule.Level;
            newSchedule.ClassRoomID  = schedule.ClassRoomID;
            newSchedule.ClassID      = schedule.ClassID;
            newSchedule.DayOfWeek    = schedule.DayOfWeek;
            newSchedule.TimeStart    = schedule.TimeStart;
            newSchedule.TimeEnd      = schedule.TimeEnd;
            newSchedule.BranchID     = schedule.BranchID;
            newSchedule.Year         = year;
            newSchedule.Month        = month;
            newSchedule.IsActive     = schedule.IsActive;
            EntityHelper.SetAuditFieldForInsert(newSchedule, HttpContext.Current.User.Identity.Name);
            ctx.ClassScheduleDetails.InsertOnSubmit(newSchedule);
        }
        ctx.SubmitChanges();
    }
예제 #2
0
    public void UpdateSchedule(int id, int classID, int classRoomID, int instructorID, string level)
    {
        ClassScheduleDetail schedule = GetSchedule(id);

        if (schedule != null)
        {
            schedule.ClassID      = classID;
            schedule.ClassRoomID  = classRoomID;
            schedule.InstructorID = instructorID;
            schedule.Level        = level;
            EntityHelper.SetAuditFieldForUpdate(schedule, HttpContext.Current.User.Identity.Name);
            ctx.SubmitChanges();
        }
    }
예제 #3
0
        public void UpdateSchedule(int id, int classID, int classRoomID, int instructorID, string level)
        {
            ClassScheduleDetail schedule = GetSchedule(id);

            if (schedule != null)
            {
                schedule.ClassID      = classID;
                schedule.ClassRoomID  = classRoomID;
                schedule.InstructorID = instructorID;
                schedule.Level        = level;
                EntityHelper.SetAuditFieldForUpdate(schedule, principal.Identity.Name);
                context.SaveChanges();
            }
        }
예제 #4
0
    public bool VerifyScheduleDeletion(int id)
    {
        ClassScheduleDetail schedule = GetSchedule(id);

        if (schedule != null)
        {
            foreach (ClassRunning classRunning in schedule.ClassRunnings)
            {
                if (classRunning.ClassAttendances.Count > 0)
                {
                    return(false);
                }
            }
        }

        return(true);
    }
예제 #5
0
    public void AddSchedule(int dayOfWeek, int branchID, int year, int month, int classID, string level, int roomID, string timeStart, string timeEnd, int instructorID)
    {
        ClassScheduleDetail sch = new ClassScheduleDetail();

        sch.BranchID  = branchID;
        sch.Month     = Convert.ToByte(month);
        sch.Year      = year;
        sch.DayOfWeek = dayOfWeek;
        EntityHelper.SetAuditFieldForInsert(sch, HttpContext.Current.User.Identity.Name);
        sch.ClassID      = classID;
        sch.Level        = level;
        sch.ClassRoomID  = roomID;
        sch.TimeStart    = timeStart;
        sch.TimeEnd      = timeEnd;
        sch.InstructorID = instructorID;
        ctx.ClassScheduleDetails.InsertOnSubmit(sch);
        ctx.SubmitChanges();
    }
예제 #6
0
        protected void gvwDetail_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteRow")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                if (ClassService.VerifyScheduleDeletion(id))
                {
                    ClassService.DeleteSchedule(id);
                    gvwDetail.DataBind();
                }
                else
                {
                    WebFormHelper.SetLabelTextWithCssClass(
                        lblStatusDelete,
                        "Cannot delete schedule because it has attendees, please clear all of the attendees first to delete this schedule.",
                        LabelStyleNames.ErrorMessage);
                }
            }
            else if (e.CommandName == "EditRow")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                mvwForm.ActiveViewIndex = 2;
                DynamicControlBinding.BindDropDown(ddlInstructor0, InstructorService.GetActiveInstructors(), "Name", "ID", false);
                DynamicControlBinding.BindDropDown(ddlClass0, ClassService.GetAllActiveClasses().ToList(), "Name", "ID", false);
                DynamicControlBinding.BindDropDown(ddlClassRoom0, ClassService.GetActiveClassRooms(Convert.ToInt32(ddlBranch.SelectedValue)).ToList(), "Name", "ID", false);
                ddlTimeStart0.DataSource = ClassService.GetTimeSlots(Convert.ToInt32(ddlBranch.SelectedValue), Convert.ToInt32(ddlDayOfWeek.SelectedValue));
                ddlTimeStart0.DataBind();

                ClassScheduleDetail schedule = ClassService.GetSchedule(id);
                if (schedule != null)
                {
                    lblBranch0.Text              = ddlBranch.SelectedItem.Text;
                    lblPeriod0.Text              = ddlMonth.SelectedItem.Text + " " + ddlYear.SelectedItem.Text;
                    lblDayOfWeek0.Text           = ddlDayOfWeek.SelectedItem.Text;
                    ddlClass0.SelectedValue      = schedule.ClassID.ToString();
                    ddlClassRoom0.SelectedValue  = schedule.ClassRoomID.ToString();
                    ddlInstructor0.SelectedValue = schedule.InstructorID.ToString();
                    ddlTimeStart0.FindItemByText(schedule.TimeStart + "-" + schedule.TimeEnd).Selected = true;
                    ddlLevel0.SelectedValue = schedule.Level;
                    ViewState["ScheduleID"] = id;
                }
                Form.DefaultButton = btnUpdate.UniqueID;
            }
        }
예제 #7
0
    public void UploadFromExcel(int branchID, int year, int month, string fileName)
    {
        IList <ExcelClassScheduleViewModel> data = ReadFromExcel(fileName);

        ctx.ClassScheduleDetails.DeleteAllOnSubmit(
            ctx.ClassScheduleDetails
            .Where(row => row.BranchID == branchID &&
                   row.Year == year &&
                   row.Month == month));

        foreach (var row in data)
        {
            Class cls = ctx.Classes.SingleOrDefault(item => item.Code == row.ClassCode);
            if (cls != null)
            {
                ClassRoom room = ctx.ClassRooms.SingleOrDefault(item => item.Code == row.ClassRoomCode);
                if (room != null)
                {
                    Instructor inst = ctx.Instructors.SingleOrDefault(item => item.Barcode == row.InstructorBarcode);
                    if (inst != null)
                    {
                        TimeSpan startTime, endTime;
                        if (TimeSpan.TryParse(row.TimeStart, out startTime))
                        {
                            if (TimeSpan.TryParse(row.TimeEnd, out endTime))
                            {
                                if (row.Level.Length <= 10)
                                {
                                    if (row.DayOfWeek >= 1 && row.DayOfWeek <= 7)
                                    {
                                        ClassScheduleDetail csd = new ClassScheduleDetail();
                                        csd.BranchID     = branchID;
                                        csd.Year         = year;
                                        csd.Month        = month;
                                        csd.DayOfWeek    = row.DayOfWeek;
                                        csd.ClassID      = cls.ID;
                                        csd.ClassRoomID  = room.ID;
                                        csd.InstructorID = inst.ID;
                                        csd.TimeStart    = row.TimeStart;
                                        csd.TimeEnd      = row.TimeEnd;
                                        csd.Level        = row.Level;
                                        csd.IsActive     = true;
                                        EntityHelper.SetAuditFieldForInsert(csd, HttpContext.Current.User.Identity.Name);
                                        ctx.ClassScheduleDetails.InsertOnSubmit(csd);
                                    }
                                    else
                                    {
                                        throw new Exception("Wrong format in Excel file: day of week should be between 1 and 7, 1 for monday and 7 for sunday");
                                    }
                                }
                                else
                                {
                                    throw new Exception("Wrong format in Excel file: level should be less than 10 chars");
                                }
                            }
                            else
                            {
                                throw new Exception("Wrong format in Excel file: invalid time end for " + row.TimeEnd);
                            }
                        }
                        else
                        {
                            throw new Exception("Wrong format in Excel file: invalid time start for " + row.TimeStart);
                        }
                    }
                    else
                    {
                        throw new Exception("Wrong format in Excel file: No instructor defined for " + row.InstructorBarcode);
                    }
                }
                else
                {
                    throw new Exception("Wrong format in Excel file: No class room defined for " + row.ClassRoomCode);
                }
            }
            else
            {
                throw new Exception("Wrong format in Excel file: No class defined for " + row.ClassCode);
            }
        }

        ctx.SubmitChanges();
    }