Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            //HACK: Not sure why, but compiler is requiring that Survey be Namespace qualified
            //      despite the using statement.
            gvSurveyList.DataSource = (
                    from DAL.Survey su in ctx.Surveys
                    select new
                    {
                        SurveyDate = su.SurveyDate,
                        StudentGroupName = su.StudentGroup.Name,
                        SchoolYear = su.StudentGroup.SchoolYear.Year.Name
                    }
                ).ToList();
            gvSurveyList.DataBind();
        }

        using (CocaDataContext ctx = new CocaDataContext())
        {
            //HACK: Not sure why, but compiler is requiring that Survey be Namespace qualified
            //      despite the using DAL statement.
            var x = from DAL.Survey su in ctx.Surveys
                    where su.Id == 1
                    select new { FirstName = su.SurveyStudents };
        }
    }
Пример #2
0
    protected void lnkAdd_Click(object sender, EventArgs e)
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            var school = ctx.Schools.Where(s => s.Id == _school).SingleOrDefault();
            var year = school.SchoolYears.Where(y => y.Year.Name == _year).SingleOrDefault();
            StudentGroup group = year.StudentGroups.Where(g => g.Id == _groupId && g.Surveys.Any(sg => sg.Season.Name == _season || string.IsNullOrEmpty(_season))).SingleOrDefault();

            Student student = new Student() { FirstName="", LastName = "", ClassRoom = "", StudentGroup = group};

            ctx.Students.InsertOnSubmit(student);
            ctx.SubmitChanges();
        }
        StudentGrid.EditIndex = 0;
        FillGrid();
    }
Пример #3
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        CocaDataContext ctx = new CocaDataContext();
        School sch = new School();
        sch.Name = txtSchool.Text;
        sch.Address1 = txtAddress1.Text;
        sch.Address2 = txtAddress2.Text;
        sch.Address3 = txtAddress3.Text;
        sch.City = txtCity.Text;
        sch.StateId = Convert.ToInt32(ddlStates.SelectedValue);
        sch.Zip = txtZip.Text;

        ctx.Schools.InsertOnSubmit(sch);

        ctx.SubmitChanges();

        MsgText.Text = "School successfully created!.";
        MsgText.Visible = true;
    }
Пример #4
0
    protected void FinishedId_Click(object sender, EventArgs e)
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            AnonStudent loggedInStudent = (from AnonStudent a in ctx.AnonStudents where a.Id == this.anonStudentId select a).FirstOrDefault();
            List<SurveyStudent> ssds = (from SurveyStudent ssd in ctx.SurveyStudents
                                                  where ssd.Survey.Equals(loggedInStudent.Survey)
                                                  select ssd).ToList();
            foreach (GridViewRow row in gvStudentSurveyList.Rows)
            {
                long ssdId = (long)gvStudentSurveyList.DataKeys[row.RowIndex].Value;
                SurveyStudent ssd = (from s in ssds where s.Id == ssdId select s).FirstOrDefault();

                TextBox commentText = (TextBox)row.FindControl("txtComment");
                DropDownList bullyAmount = (DropDownList)row.FindControl("ddlBullyTimes");
                DropDownList targetAmount = (DropDownList)row.FindControl("ddlTargetTimes");

                StudentSurveyRating rating = new StudentSurveyRating();

                rating.AnonStudent = loggedInStudent;
                rating.SurveyStudent = ssd;
                int timesBully;
                int timesTarget;
                if(!string.IsNullOrEmpty(bullyAmount.SelectedValue) && int.TryParse(bullyAmount.SelectedValue,out timesBully  ))
                    rating.IsBullyValue = timesBully;
                if(!string.IsNullOrEmpty(targetAmount.SelectedValue) && int.TryParse(targetAmount.SelectedValue, out timesTarget))
                    rating.IsTargetValue = timesTarget;
                rating.Comment = commentText.Text;

                ctx.StudentSurveyRatings.InsertOnSubmit(rating);

            }
            loggedInStudent.SavedDate = DateTime.Today;
            loggedInStudent.LoggedInDate = DateTime.Now;
            Session.Remove(KEY_AnonStudent);
            ctx.SubmitChanges();
            Session.Clear();
            ReturnToLogin();
        }
    }
Пример #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (CocaDataContext ctx = new CocaDataContext())
     {
         gvSchoolList.DataSource = (
                 from School d in ctx.Schools orderby d.Name
                 select new
                 {
                     ID = d.Id,
                     Name = d.Name,
                     Address1 = d.Address1,
                     Address2 = d.Address2,
                     Address3 = d.Address3,
                     City = d.City,
                     StateID = d.StateId,
                     StateName = d.State.Name,
                     Zip = d.Zip
                 }
             ).ToList();
         gvSchoolList.DataBind();
     }
 }
Пример #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (CocaDataContext ctx = new CocaDataContext())
            {

                ddlStates.DataSource = (
                            from State d in ctx.States
                            orderby d.Name
                            select new
                            {
                                ID = d.Id,
                                State = d.Name
                            }
                        ).ToList();
                ddlStates.DataTextField = "State";
                ddlStates.DataValueField = "ID";
                ddlStates.DataBind();
            }
        }
    }
Пример #7
0
    protected void btnStartSurvey_Click(object sender, EventArgs e)
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            long anonStudentID = (from AnonStudent s in ctx.AnonStudents
                                      where s.UserId == txtStudentID.Text && s.Password == txtPassword.Text
                                       && s.SurveyId == Convert.ToInt32(SurveyIdTextbox.Text)
                                       && s.SavedDate == null
                                      select s.Id).FirstOrDefault();

            if (anonStudentID != 0)
            {
                Session["LoggedIn_AnonStudentId"] = anonStudentID;
                Response.Redirect("SurveyInfo.aspx");
            }
            else
            {
                lblLoginError.Text = "Login unsuccessful, try again.";
                lblLoginError.Visible = true;
            }
        }
    }
Пример #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (CocaDataContext ctx = new CocaDataContext())
            {

                ddlSeason.DataSource = (
                            from Season d in ctx.Seasons
                            orderby d.Id
                            select new
                            {
                                ID = d.Id,
                                Name = d.Name
                            }
                        ).ToList();
                ddlSeason.DataTextField = "Name";
                ddlSeason.DataValueField = "ID";
                ddlSeason.DataBind();
                ddlSeason.Items.Insert(0, new ListItem("--Select Season--", "0"));

                ddlGrade.DataSource = (
                           from ClassLevel d in ctx.ClassLevels
                           orderby d.Id
                           select new
                           {
                               ID = d.Id,
                               Name = d.Name
                           }
                       ).ToList();
                ddlGrade.DataTextField = "Name";
                ddlGrade.DataValueField = "ID";
                ddlGrade.DataBind();
                ddlGrade.Items.Insert(0, new ListItem("--Select Grade--", "0"));
            }
        }
    }
Пример #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (CocaDataContext ctx = new CocaDataContext())
            {

                ddlSchool.DataSource = (
                        from School sc in ctx.Schools
                        orderby sc.Name
                        select new
                        {
                            ID = sc.Id,
                            Name = sc.Name
                        }
                    ).ToList();
                ddlSchool.DataTextField = "Name";
                ddlSchool.DataValueField = "ID";
                ddlSchool.DataBind();

                if (Request["SurveyID"] != null)
                    InitializeWithSurvey(ctx);
                else
                    InitializeWithFirstSchool();
            }
        }
    }
Пример #10
0
    private IList<Student> retrieveStudents()
    {
        IList<Student> students;
        try
        {
            using (CocaDataContext ctx = new CocaDataContext())
            {
                var school = ctx.Schools.Where(s => s.Id == _school).SingleOrDefault();
                var year = school.SchoolYears.Where(y => y.Year.Name == _year).SingleOrDefault();
                var group = year.StudentGroups.Where(g => g.Id == _groupId && g.Surveys.Any(sg => sg.Season.Name == _season || string.IsNullOrEmpty(_season))).SingleOrDefault();
                students = group.Students.OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList();

                if (students.Count < 1) throw new InvalidDataException("No students found");
            }
        }
        catch (Exception ex)
        {
            ErrorText.Text = "Unable to find the students for the data you selected:" + ex.Message;
            ErrorText.Visible = true;
            return null;
        }

        return students;
    }
Пример #11
0
    protected void StudentGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string firstName = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("fnameEdit")).Text;
        string lastName = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("lnameEdit")).Text;
        string classroom = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("classroomEdit")).Text;
        long id = (long)((GridView)sender).DataKeys[e.RowIndex].Value;

        using (CocaDataContext ctx = new CocaDataContext())
        {
            Student student = (from s in ctx.Students where s.Id == id select s).FirstOrDefault();
            if (student != null)
            {
                student.FirstName = firstName;
                student.LastName = lastName;
                student.ClassRoom = classroom;

                ctx.SubmitChanges();
            }
        }
        StudentGrid.EditIndex = -1;
        FillGrid();
    }
Пример #12
0
 protected void StudentGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     long id = (long)((GridView)sender).DataKeys[e.RowIndex].Value;
     using (CocaDataContext ctx = new CocaDataContext())
     {
         Student student = (from s in ctx.Students where s.Id == id select s).FirstOrDefault();
         if (student != null)
         {
             ctx.Students.DeleteOnSubmit(student);
             ctx.SubmitChanges();
         }
     }
     StudentGrid.EditIndex = -1;
     FillGrid();
 }
Пример #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Disable page caching:
        Response.Buffer = true;
        Response.ExpiresAbsolute = DateTime.Now.AddHours(-1);
        Response.Expires = -1500;
        Response.AddHeader("Pragma", "no-cache");
        Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        Response.Cache.SetNoStore();

        if (anonStudentId == 0)
            ReturnToLogin();

        if (!IsPostBack)
        {

            using (CocaDataContext ctx = new CocaDataContext())
            {
                // HACK: Not sure why, but compiler is requiring that "Survey" is namespace qualified even though there is a using statement
                //       and there are no other "Survey" definitions in the page without that using.
                DAL.Survey su = (from AnonStudent a in ctx.AnonStudents where a.Id == this.anonStudentId select a.Survey).FirstOrDefault();
                Random randomNumber = new Random();
                gvStudentSurveyList.DataSource = (from d in
                                                      (
                                                         from SurveyStudent ssd in ctx.SurveyStudents
                                                         where ssd.Survey.Equals(su)
                                                         select new
                                                         {
                                                             fn = ssd.Student.FirstName,
                                                             ln = ssd.Student.LastName,
                                                             Id = ssd.Id
                                                         }
                                                     ).ToList()
                                                  select new { FirstName = d.fn, LastName = d.ln, Id = d.Id, RandomNumber = randomNumber.Next(5000) }).OrderBy(i => i.RandomNumber).ToList();
                gvStudentSurveyList.DataBind();
            }
        }
    }
Пример #14
0
 private void BindGroups()
 {
     using (CocaDataContext ctx = new CocaDataContext())
     {
         ddlGroupName.DataSource = (
                   from StudentGroup sg in ctx.StudentGroups
                   where sg.SchoolYear.Year.Name == ddlYear.SelectedValue && sg.SchoolYear.School.Id == long.Parse(ddlSchool.SelectedValue)
                   orderby sg.Name
                   select new
                   {
                       GroupID = sg.Id,
                       GroupName = sg.Name
                   }
               ).ToList();
         ddlGroupName.DataTextField = "GroupName";
         ddlGroupName.DataValueField = "GroupID";
         ddlGroupName.DataBind();
     }
 }
Пример #15
0
    private void BindSeasons()
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {
            long groupID = 0;
            long.TryParse(ddlGroupName.SelectedValue, out groupID);

            ddlSeason.DataSource = (
                     from Season sea in ctx.Seasons
                     where sea.Surveys.Any(sg => sg.StudentGroup.Id == groupID)
                     orderby sea.Name
                     select new
                     {
                         SeasonName = sea.Name
                     }
                 ).ToList();
            ddlSeason.DataTextField = "SeasonName";
            ddlSeason.DataValueField = "SeasonName";
            ddlSeason.DataBind();
        }
    }
Пример #16
0
 private void InitializeWithSurvey(CocaDataContext ctx)
 {
     long surveyId;
     if (long.TryParse(Request["SurveyId"], out surveyId))
     {
         Survey survey = (from s in ctx.Surveys where s.Id == surveyId select s).FirstOrDefault();
         if (survey != null)
         {
             if (SetDropDown(ddlSchool, survey.StudentGroup.SchoolYear.SchoolId.ToString(), BindYears))
                 if (SetDropDown(ddlYear, survey.StudentGroup.SchoolYear.Year.Name, BindGroups))
                     if (SetDropDown(ddlGroupName, survey.StudentGroupId.ToString(), BindSeasons))
                         SetDropDown(ddlSeason, survey.Season.Name, null);
             BindSurveyID();
         }
     }
 }
Пример #17
0
    private void BindYears()
    {
        using (CocaDataContext ctx = new CocaDataContext())
        {

            long theType = long.Parse(ddlSchool.SelectedValue);

            ddlYear.DataSource = (
                  from Year y in ctx.Years
                  where y.SchoolYears.Any(sy => sy.School.Id == theType)
                  orderby y.Name
                  select new
                  {
                      YearName = y.Name
                  }
              ).ToList();
            ddlYear.DataTextField = "YearName";
            ddlYear.DataValueField = "YearName";
            ddlYear.DataBind();
        }
    }
Пример #18
0
    private void BindSurveyID()
    {
        string initId = this.SurveyID;
        using (CocaDataContext ctx = new CocaDataContext())
        {
            long groupID = 0;
            long.TryParse(ddlGroupName.SelectedValue, out groupID);

            var survey = ctx.Surveys.Where(sgs => sgs.Season.Name == ddlSeason.SelectedValue && sgs.StudentGroup.Id == groupID).SingleOrDefault();
            if (survey != null)
                this.SurveyID = survey.Id.ToString();
            else
                this.SurveyID = null;
        }

        if (initId != this.SurveyID && this.SurveyIDChanged!=null)
            this.SurveyIDChanged(this, new SurveyIDChangedEventArgs(initId, this.SurveyID));
    }