protected void ApplyForCourses(object sender, EventArgs e)
 {
     foreach (GridViewRow row in CoursesGrid.Rows)
     {
         if (row.RowType == DataControlRowType.DataRow)
         {
             CheckBox applyBox = row.FindControl("ApplyCheckBox") as CheckBox;
             if (applyBox != null)
             {
                 Label labelRow = row.FindControl("CourseId") as Label;
                 string courseId = labelRow == null ? string.Empty : labelRow.Text;
                 using (var client = new StudentsManagerClient())
                 {
                     if (applyBox.Checked)
                     {
                         client.ApplyForCourse(Id, int.Parse(courseId));
                     }
                     else
                     {
                         client.LeaveCourse(Id, int.Parse(courseId));
                     }
                 }
             }
         }
     }
     LoadCourses();
 }
 public void UpdateStudent(int id)
 {
     TryUpdateModel(currentStudent);
     using (var client = new StudentsManagerClient())
     {
         client.UpdateStudent(currentStudent.Id, currentStudent.FirstName, currentStudent.LastName, currentStudent.Age.ToString(), currentStudent.Sex);
     }
 }
 public StudentInfo SelectStudent()
 {
     using(var client = new StudentsManagerClient())
     {
         this.currentStudent = client.GetStudent(this.Id);
         return currentStudent;
     }
 }
 protected void LoadFile(object sender, EventArgs e)
 {
     RawStudentInfo[] rawStudents = new RawStudentInfo[] { };
     RawStudentInfo[] validStudents = new RawStudentInfo[] { };
     StudentTrackerService.InvalidRecord[] invalidRecords = new StudentTrackerService.InvalidRecord[] { };
     string path = String.Empty;
     if (FileUploadControl.HasFile && (Path.GetExtension(FileUploadControl.FileName) == ".xlsx" || Path.GetExtension(FileUploadControl.FileName) == ".xls"))
     {
         try
         {
             ExcelFileParser parser = new ExcelFileParser(FileUploadControl.PostedFile.InputStream);
             List<RawStudentInfo> rawStudentsInforamtion = new List<RawStudentInfo>();
             foreach (var record in parser.StudentsRowInformation)
             {
                 rawStudentsInforamtion.Add(new RawStudentInfo { FirstName = record.FirstName, LastName = record.LastName, Age = record.Age, Sex = record.Sex });
             }
             rawStudents = rawStudentsInforamtion.ToArray();
             using (var client = new StudentsManagerClient())
             {
                 ExcelDocumentImportResult result = client.GetRecords(rawStudents, System.Threading.Thread.CurrentThread.CurrentCulture.Name);
                 validStudents = result.ValidRecords;
                 invalidRecords = result.InvalidRecords;
             }
             StatusLabel.Text = LocalizedText.UploadStatusSuccess;
         }
         catch (Exception)
         {
             StatusLabel.Text = LocalizedText.UploadedStatusFailed;
         }
         finally
         {
             UploadedStudents.DataSource = validStudents;
             UploadedStudents.DataBind();
             if (invalidRecords.Any())
             {
                 InvalidRecords.DataSource = invalidRecords;
                 InvalidRecords.DataBind();
                 InvalidGridPannel.Visible = true;
             }
             else
             {
                 InvalidRecords.DataSource = null;
                 InvalidRecords.DataBind();
                 InvalidGridPannel.Visible = false;
             }
             GridPannel.Visible = true;
             if (validStudents.Any())
             {
                 using (StudentTrackerService.StudentsManagerClient client = new StudentTrackerService.StudentsManagerClient())
                 {
                     client.SaveStudents(validStudents);
                 }
             }
         }
     }
     else
     {
         StatusLabel.Text = LocalizedText.UploadStatusWrongFormat;
     }
     StatusLabel.Visible = true;
 }
Exemplo n.º 5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         ddlLanguage.SelectedValue = Thread.CurrentThread.CurrentCulture.Name;
         this.uiConfigLink.Visible = false;
         if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
         {
             this.uiConfigLink.Visible = true;
             var currentUserName = HttpContext.Current.User.Identity.Name;
             string bgColour = string.Empty;
             string hdColour = string.Empty;
             using (var client = new StudentsManagerClient())
             {
                 var settings = client.GetUiColoursByName(currentUserName);
                 bgColour = settings.BackgroundColour;
                 hdColour = settings.HeaderColour;
             }
             if (!string.IsNullOrEmpty(bgColour))
             {
                 masterPageBody.Attributes.Add("style", string.Format("background-color:{0}", bgColour));
             }
             if (!string.IsNullOrEmpty(hdColour))
             {
                 masterPageHeader.Attributes.Add("style", string.Format("background-color:{0}", hdColour));
             }
         }
     }
 }
 private void LoadCourses()
 {
     using (StudentsManagerClient client = new StudentsManagerClient())
     {
         CoursesGrid.DataSource = client.GetStudentsCourses(Id);
         CoursesGrid.DataBind();
     }
 }
        protected void StudentForm_OnItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            string firstName = ((TextBox) this.StudentForm.FindControl("txtFirstName")).Text;
            string lastName = ((TextBox)this.StudentForm.FindControl("txtLastName")).Text;
            string sex = ((DropDownList) this.StudentForm.FindControl("ddlSex")).SelectedValue;
            string age = ((TextBox) this.StudentForm.FindControl("txtAge")).Text;

            using (var client = new StudentsManagerClient())
            {
                client.UpdateStudent(Id, firstName, lastName, age, sex);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Id == -1)
         {
             Server.Transfer("~/Students.aspx");
         }
         using (var client = new StudentsManagerClient())
         {
             this.StudentName.Text = client.GetStudentFullName(Id);
         }
         LoadCourses();
     }
 }
 protected void OnDataBound(object sender, EventArgs e)
 {
     string sex = string.Empty;
     using (var client = new StudentsManagerClient())
     {
         sex = client.GetStudentsSex(Id);
     }
     DropDownList ddlSex = (DropDownList)this.StudentForm.FindControl("ddlSex");
     ddlSex.Items.Add(new ListItem("Female", "Female"));
     ddlSex.Items.Add(new ListItem("Male", "Male"));
     ddlSex.SelectedValue = sex;
     ddlSex.DataBind();
 }