protected void uiGridViewStatusHistory_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView row = (DataRowView) e.Row.DataItem;
                GridView gvattachments = (GridView)e.Row.FindControl("uiGridViewAttachments");
                ApplicationAttachment attachments = new ApplicationAttachment();
                attachments.Where.ApplicationStatusID.Value = Convert.ToInt32(row["ApplicationStatusID"]);
                attachments.Where.ApplicationStatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                attachments.Where.ApplicationDataID.Value = Convert.ToInt32(row["ApplicationDataID"]);
                attachments.Where.ApplicationDataID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                attachments.Query.Load();

                gvattachments.DataSource = attachments.DefaultView;
                gvattachments.DataBind();

                GridView gvadminattachments = (GridView)e.Row.FindControl("uiGridViewAdminAttachments");
                AdminAttachment adminattachments = new AdminAttachment();
                adminattachments.Where.ApplicationStatusID.Value = Convert.ToInt32(row["ApplicationStatusID"]);
                adminattachments.Where.ApplicationStatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                adminattachments.Where.ApplicationDataID.Value = Convert.ToInt32(row["ApplicationDataID"]);
                adminattachments.Where.ApplicationDataID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                adminattachments.Query.Load();

                gvadminattachments.DataSource = adminattachments.DefaultView;
                gvadminattachments.DataBind();
            }
        }
        protected void uiLinkButtonUpdate_Click(object sender, EventArgs e)
        {
            if (uiDropDownListStatus.SelectedIndex != 0 || uiDropDownListStatus.SelectedIndex != -1)
            {
                ApplicationData app = new ApplicationData();
                app.LoadByPrimaryKey(CurrentApp);

                ApplicationStatusHistory history = new ApplicationStatusHistory();
                history.AddNew();
                history.StudentID = app.StudentID;
                history.ApplicationDataID = app.ApplicationDataID;
                history.StatusDate = DateTime.Now;
                history.StatusComment = uiTextBoxComment.Text;
                history.ApplicationStatusID = Convert.ToInt32(uiDropDownListStatus.SelectedValue);
                if (uiDropDownListStatus.SelectedValue == "7") // Tuition  Fees
                {
                    decimal fees = 0;
                    decimal.TryParse(uiTextBoxFees.Text, out fees);
                    history.TuitionFees = fees;
                }
                history.Save();

                EmailTemplates template = new EmailTemplates();
                template.GetTemplateByStatusID(history.ApplicationStatusID);

                Student student = new Student ();
                student.LoadByPrimaryKey(app.StudentID);

                Course course = new Course();
                course.LoadByPrimaryKey(app.SelectedCourseID);

                CourseLangauge lang = new CourseLangauge();
                lang.LoadByPrimaryKey(course.CourseLangaugeID);
                if (template.RowCount > 0)
                {
                    try
                    {
                        MailMessage msg = new MailMessage();
                        string mail = ConfigurationManager.AppSettings["StatusEMail"];
                        string mailto = student.Email;
                        msg.To.Add(mailto);
                        msg.From = new MailAddress(mail);
                        msg.Subject = template.Subject.Replace('\r', ' ').Replace('\n', ' ');
                        msg.IsBodyHtml = true;
                        msg.BodyEncoding = System.Text.Encoding.UTF8;

                        string missingDocs = "";
                        for (int i = 0; i < uiCheckBoxListMissingDocs.Items.Count; i++)
                        {
                            if (uiCheckBoxListMissingDocs.Items[i].Selected)
                            {
                                missingDocs += "<li>" + uiCheckBoxListMissingDocs.Items[i].Text + "</li>";
                            }
                        }

                        string refusalReasons = "";
                        for (int i = 0; i < uiCheckBoxListRefusalReason.Items.Count; i++)
                        {
                            if (uiCheckBoxListRefusalReason.Items[i].Selected)
                            {
                                refusalReasons += "<li>" + uiCheckBoxListRefusalReason.Items[i].Text + "</li>";
                            }
                        }

                        msg.Body = string.Format(Server.HtmlDecode(template.Body.Replace('\r', ' ').Replace('\n', ' ')), student.FirstName + " " + student.FamilyName, student.Email, course.CourseName + " - " + lang.Langauge, missingDocs , refusalReasons, string.IsNullOrEmpty(uiTextBoxComment.Text) ? "N/A" : uiTextBoxComment.Text);

                        // attachments
                        if (Session["CurrentUploadedFiles"] != null)
                        {
                            Hashtable Files;
                            Files = (Hashtable)Session["CurrentUploadedFiles"];

                            if (Files.Count > 0)
                            {
                                AdminAttachment attachment = new AdminAttachment();
                                foreach (DictionaryEntry item in Files)
                                {
                                    msg.Attachments.Add(new Attachment(Server.MapPath("~" + item.Value.ToString())));
                                    attachment.AddNew();
                                    attachment.ApplicationDataID = history.ApplicationDataID;
                                    attachment.ApplicationStatusID = history.ApplicationStatusID;
                                    attachment.AttachmentPath = item.Value.ToString();

                                }
                                attachment.Save();
                                Session["CurrentUploadedFiles"] = null;
                            }

                        }

                        if (history.ApplicationStatusID == 16 || history.ApplicationStatusID == 6) // application refused - refund policy attached
                        {
                            msg.Attachments.Add(new Attachment(Server.MapPath("~/files/Refund_Policy_Agreement.pdf")));
                        }

                        SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["mailserver"], 25);

                        client.UseDefaultCredentials = false;

                        client.Credentials = new System.Net.NetworkCredential(mail, ConfigurationManager.AppSettings["StatusMailpass"]);
                        client.Send(msg);

                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                //BindHistory();
                BindApplicationData();
                BindData();
            }
        }