using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using AVC.Passport;
using AVC.Passport.DataEntity;

	/// <summary>
	/// UserMst编辑
	/// </summary>
public partial class UserEdit : LoginPageBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				string strAction = Request.QueryString["action"];
				// 自动编号
				
				txtUserID.ReadOnly = true;
				txtUserID.Text = "自动增长";
				
				ViewState["Action"] = strAction;
				if(strAction == "edit")
				{
					System.Int32 UserID = System.Int32.Parse(Request.QueryString["UserID"]);UserMst objUserMst = UserMstBiz.GetUserMst(UserID);
					
					txtUserID.Text = objUserMst.UserID.ToString();
					txtUserName.Text = objUserMst.UserName;
					txtPassword.Text = objUserMst.Password;
					txtEMail.Text = objUserMst.EMail;
					txtTele.Text = objUserMst.Tele;
					txtTrueName.Text = objUserMst.TrueName;
					txtMemo.Text = objUserMst.Memo;
					txtUserID.ReadOnly = true;
					
				}
			}
		}

		public void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					UserMst objUserMst = new UserMst();
					objUserMst.UserName = txtUserName.Text;
					objUserMst.Password = txtPassword.Text;
					objUserMst.EMail = txtEMail.Text;
					objUserMst.Tele = txtTele.Text;
					objUserMst.TrueName = txtTrueName.Text;
					objUserMst.Memo = txtMemo.Text;
					ViewState["Action"] = "edit";			
					txtUserID.ReadOnly = true;	
					txtUserID.ReadOnly = true;
					txtUserID.Text = objUserMst.UserID.ToString();	
				}
				else if((string)ViewState["Action"] == "edit")
				{
					UserMst objUserMst = UserMstBiz.GetUserMst(System.Int32.Parse(txtUserID.Text));
					
					objUserMst.UserID = System.Int32.Parse(txtUserID.Text);
			
					objUserMst.UserName = txtUserName.Text;
					
					objUserMst.Password = txtPassword.Text;
					
					objUserMst.EMail = txtEMail.Text;
					
					objUserMst.Tele = txtTele.Text;
					
					objUserMst.TrueName = txtTrueName.Text;
					
					objUserMst.Memo = txtMemo.Text;
					
					UserMstBiz.UpdateUserMst(objUserMst);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
