using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace shuangyulin.Admin
{
    public partial class M_EditStudent_QQ287307421 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DAL.Function.CheckState();
            if (!IsPostBack)
            {
                BindClassInfostudentClassNumber();
                /*进入本信息添加页显示无图的图片*/
                this.StudentPhotoImage.ImageUrl = "FileUpload\\NoImage.jpg";
                if (Request["studentNumber"] != null)
                {
                    LoadData();
                }
            }
        }
        private void BindClassInfostudentClassNumber()
        {
            studentClassNumber.DataSource = BLL.bllClassInfo.getAllClassInfo();
            studentClassNumber.DataTextField = "className";
            studentClassNumber.DataValueField = "classNumber";
            studentClassNumber.DataBind();
        }

        /*如果是需要对记录进行编辑需要在界面初始化显示数据*/
        private void LoadData()
        {
            if (!string.IsNullOrEmpty(Common.GetMes.GetRequestQuery(Request, "studentNumber")))
            {
                ENTITY.Student_QQ287307421 student_QQ287307421 = BLL.bllStudent_QQ287307421.getSomeStudent_QQ287307421(Common.GetMes.GetRequestQuery(Request, "studentNumber"));
                studentNumber.Value = student_QQ287307421.studentNumber;
                studentName.Value = student_QQ287307421.studentName;
                studentPassword.Value = student_QQ287307421.studentPassword;
                studentSex.Value = student_QQ287307421.studentSex;
                studentClassNumber.SelectedValue = student_QQ287307421.studentClassNumber;
                studentBirthday.Text = student_QQ287307421.studentBirthday.ToShortDateString();
                studentState.Value = student_QQ287307421.studentState;
                studentPhoto.Text = student_QQ287307421.studentPhoto;
                if (student_QQ287307421.studentPhoto != "") this.StudentPhotoImage.ImageUrl = student_QQ287307421.studentPhoto;
                studentTelephone.Value = student_QQ287307421.studentTelephone;
                studentEmail.Value = student_QQ287307421.studentEmail;
                studentQQ.Value = student_QQ287307421.studentQQ;
                studentAddress.Value = student_QQ287307421.studentAddress;
                studentMemo.Value = student_QQ287307421.studentMemo;
            }
        }

        protected void BtnStudent_QQ287307421Save_Click(object sender, EventArgs e)
        {
            ENTITY.Student_QQ287307421 student_QQ287307421 = new ENTITY.Student_QQ287307421();
            student_QQ287307421.studentNumber = this.studentNumber.Value;
            student_QQ287307421.studentName = studentName.Value;
            student_QQ287307421.studentPassword = studentPassword.Value;
            student_QQ287307421.studentSex = studentSex.Value;
            student_QQ287307421.studentClassNumber = studentClassNumber.SelectedValue;
            student_QQ287307421.studentBirthday = Convert.ToDateTime(studentBirthday.Text);
            student_QQ287307421.studentState = studentState.Value;
            if (studentPhoto.Text == "") studentPhoto.Text = "FileUpload\\NoImage.jpg";
            student_QQ287307421.studentPhoto = studentPhoto.Text;
            student_QQ287307421.studentTelephone = studentTelephone.Value;
            student_QQ287307421.studentEmail = studentEmail.Value;
            student_QQ287307421.studentQQ = studentQQ.Value;
            student_QQ287307421.studentAddress = studentAddress.Value;
            student_QQ287307421.studentMemo = studentMemo.Value;
            if (!string.IsNullOrEmpty(Common.GetMes.GetRequestQuery(Request, "studentNumber")))
            {
                student_QQ287307421.studentNumber = Request["studentNumber"];
                if (BLL.bllStudent_QQ287307421.EditStudent_QQ287307421(student_QQ287307421))
                {
                    Common.ShowMessage.myScriptMes(Page, "Suess", "if(confirm(\"信息修改成功，是否继续修改？否则返回信息列表。\")) {location.href=\"M_EditStudent_QQ287307421.aspx?studentNumber=" + Request["studentNumber"] + "\"} else  {location.href=\"M_Student_QQ287307421List.aspx\"} ");
                }
                else
                {
                    Common.ShowMessage.Show(Page, "error", "信息修改失败，请重试或联系管理人员..");
                }
            }
            else
            {
                if (BLL.bllStudent_QQ287307421.AddStudent_QQ287307421(student_QQ287307421))
                {
                   Common.ShowMessage.myScriptMes(Page, "Suess", "if(confirm(\"信息添加成功，是否继续添加？否则返回信息列表。\")) {location.href=\"M_EditStudent_QQ287307421.aspx\"} else  {location.href=\"M_Student_QQ287307421List.aspx\"} ");
                }
                else
                {
                    Common.ShowMessage.Show(Page, "error", "信息添加失败，请重试或联系管理人员..");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("M_Student_QQ287307421List.aspx");
        }
        protected void Btn_StudentPhotoUpload_Click(object sender, EventArgs e)
        {
            /*如果用户上传了文件*/
            if (this.StudentPhotoUpload.PostedFile.ContentLength > 0)
            {
                /*验证上传的文件格式，只能为gif和jpeg格式*/
                string mimeType = this.StudentPhotoUpload.PostedFile.ContentType;
                if (String.Compare(mimeType, "image/gif", true) == 0 || String.Compare(mimeType, "image/pjpeg", true) == 0 || String.Compare(mimeType, "image/jpeg", true) == 0)
                {
                    this.studentPhoto.Text = "上传文件中....";
                    string extFileString = System.IO.Path.GetExtension(this.StudentPhotoUpload.PostedFile.FileName); /*获取文件扩展名*/
                    string saveFileName = DAL.Function.MakeFileName(extFileString); /*根据扩展名生成文件名*/
                    string imagePath = "FileUpload\\" + saveFileName;/*图片路径*/
                    this.StudentPhotoUpload.PostedFile.SaveAs(Server.MapPath(imagePath));
                    this.StudentPhotoImage.ImageUrl = imagePath;
                    this.studentPhoto.Text = imagePath;
                }
                else
                {
                    Response.Write("<script>alert('上传文件格式不正确!');</script>");
                }
            }
        }
    }
}

