modifyinfo.aspx.cs

来自「实现电子病历功能 有医生护士等角色 分别可以增加病历修改病历删除病历等等功能」· CS 代码 · 共 145 行

CS
145
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class CommonOperation_ModifyInfo_ModifyInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (int i = 1950; i < 2050; i++)
            {
                DropDownListYear.Items.Add(i.ToString());
            }
            UserInfo user = (UserInfo)Session["user"];
            if (user != null)
            {
                init(user);
            }
            
        }  
    }
    private static string fn;
    private void init(UserInfo user)
    {
        TextBoxAddress.Text = user.Address;
        TextBoxAnswer.Text = user.Answer;
        TextBoxEmailAddress.Text = user.EmailAddress;
        TextBoxIdentItycardNum.Text = user.IdentitycardNum;       
        TextBoxQuestion.Text = user.Question;
        TextBoxRealName.Text = user.RealName;
        TextBoxTelephone.Text = user.TelephoneNum;
        Image1.ImageUrl = "~/Src/CommonOperation/Photograph/" + user.Photo;
        if (user.Sex == 0)
        {
            DropDownListSex.SelectedValue = "0";
        }
        else
        {
            DropDownListSex.SelectedValue = "1";
        }
        DropDownListYear.SelectedValue = user.BirthDay.Year.ToString();
        DropDownListMonth.SelectedValue = user.BirthDay.Month.ToString();
        DropDownListDay.SelectedValue = user.BirthDay.Day.ToString();
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        if (TextBoxEmailAddress.Text.Trim() != ((UserInfo)Session["user"]).EmailAddress)
        {
            if (!CommonService.isExistUser(TextBoxEmailAddress.Text))
            {
                saveUserChange();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", @"<script language='Javascript'>
                 alert('此邮箱已经注册,请重新填写!');</script>");
            }
        }
        else
        {
            saveUserChange();
        }
    }

    private void saveUserChange()
    {
        UserInfo user = (UserInfo)Session["user"];
        string deleteFileName = user.Photo;     
        user.Address = TextBoxAddress.Text;
        user.Answer = TextBoxAnswer.Text;
        user.BirthDay = Convert.ToDateTime(DropDownListYear.SelectedValue + "-" + DropDownListMonth.SelectedValue + "-" + DropDownListDay.SelectedValue);
        user.EmailAddress = TextBoxEmailAddress.Text;
        user.IdentitycardNum = TextBoxIdentItycardNum.Text;
        if (fn != null)
        {
            user.Photo = fn;
        }
        user.Question = TextBoxQuestion.Text;
        user.RealName = TextBoxRealName.Text;
        user.Sex = Convert.ToInt32(DropDownListSex.SelectedValue);
        user.TelephoneNum = TextBoxTelephone.Text;
        if (CommonService.saveUser(user))
        {            
            string deleteFileNamePath = Server.MapPath("..\\Photograph") + "\\" + deleteFileName;
            if (deleteFileNamePath != "" && deleteFileName != ConfigurationManager.ConnectionStrings["FileName"].ConnectionString)
            {
                File.Delete(deleteFileNamePath);
            }
            string redirect = Request.ApplicationPath + "/Default.aspx";                     
            moveTo();
        }    
    }
    

    private void moveTo()
    {
        UserInfo user = (UserInfo)Session["user"];
        string redirect = "";
        if (user.IsAdmin)
        {
            redirect = Request.ApplicationPath+"/Src/IndividualOperation/Administrator/UserList.aspx";
        }
        if (user.IsDoctor)
        {
            redirect = Request.ApplicationPath + "/Src/IndividualOperation/Doctor/AddEMR.aspx";
        }
        if (user.IsLeader)
        {
            redirect = Request.ApplicationPath + "/Src/IndividualOperation/Leader/CheckEMR.aspx";
        }
        if (user.IsNurse)
        {
            redirect = Request.ApplicationPath + "/Src/IndividualOperation/Nurse/CheckEMR.aspx";
        }
        Response.Write(@"<script language='Javascript'>alert('修改成功!');window.location.href='"+redirect+"';</script>");
    }
    protected void ButtonUpLoad_Click(object sender, EventArgs e)
    {      
        if ((FileUploadPhoto.PostedFile != null) && (FileUploadPhoto.PostedFile.ContentLength > 0))
        {
             fn = ((UserInfo)Session["user"]).UserName + "_" + Path.GetFileName(FileUploadPhoto.PostedFile.FileName);
            string SaveLocation = Server.MapPath("..\\Photograph") + "\\" + fn;
            string uploadfile = "~/Src/CommonOperation/Photograph/" + fn;
            try
            {
                FileUploadPhoto.PostedFile.SaveAs(SaveLocation);
                Image1.ImageUrl = uploadfile;
            }
            catch (Exception ex)
            {
                Response.Write("Error: " + ex.Message);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?