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

	/// <summary>
	/// RightsType编辑
	/// </summary>
public partial class RightsTypeEdit : LoginPageBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				string strAction = Request.QueryString["action"];
				// 自动编号
				
				txtTypeID.ReadOnly = true;
				txtTypeID.Text = "自动增长";
				
				ViewState["Action"] = strAction;
				if(strAction == "edit")
				{
					System.Int32 TypeID = System.Int32.Parse(Request.QueryString["TypeID"]);RightsType objRightsType = RightsTypeBiz.GetRightsType(TypeID);
					
					txtTypeID.Text = objRightsType.TypeID.ToString();
					txtSubSystemID.Text = objRightsType.SubSystemID;
					txtTypeName.Text = objRightsType.TypeName;
					txtParentTypeID.Text = objRightsType.ParentTypeID.ToString();
					txtCreateTime.Text = objRightsType.CreateTime.ToString();
					txtCreateUser.Text = objRightsType.CreateUser.ToString();
					txtUpdateTime.Text = objRightsType.UpdateTime.ToString();
					txtUpdateUser.Text = objRightsType.UpdateUser.ToString();
					txtTypeID.ReadOnly = true;
					
				}
			}
		}

		public void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					RightsType objRightsType = new RightsType();
					
					objRightsType.SubSystemID = txtSubSystemID.Text;
					objRightsType.TypeName = txtTypeName.Text;
					objRightsType.ParentTypeID = System.Int32.Parse(txtParentTypeID.Text);
					objRightsType.CreateTime = System.DateTime.Parse(txtCreateTime.Text);
					objRightsType.CreateUser = System.Int32.Parse(txtCreateUser.Text);
					objRightsType.UpdateTime = System.DateTime.Parse(txtUpdateTime.Text);
					objRightsType.UpdateUser = System.Int32.Parse(txtUpdateUser.Text);RightsTypeBiz.AddRightsType(objRightsType);
					ViewState["Action"] = "edit";
					
					txtTypeID.ReadOnly = true;
					
					txtTypeID.ReadOnly = true;
					txtTypeID.Text = objRightsType.TypeID.ToString();
					
				}
				else if((string)ViewState["Action"] == "edit")
				{
					RightsType objRightsType = RightsTypeBiz.GetRightsType(System.Int32.Parse(txtTypeID.Text));
					
					objRightsType.TypeID = System.Int32.Parse(txtTypeID.Text);
					
					objRightsType.SubSystemID = txtSubSystemID.Text;
					
					objRightsType.TypeName = txtTypeName.Text;
					
					objRightsType.ParentTypeID = System.Int32.Parse(txtParentTypeID.Text);
					
					objRightsType.CreateTime = System.DateTime.Parse(txtCreateTime.Text);
					
					objRightsType.CreateUser = System.Int32.Parse(txtCreateUser.Text);
					
					objRightsType.UpdateTime = System.DateTime.Parse(txtUpdateTime.Text);
					
					objRightsType.UpdateUser = System.Int32.Parse(txtUpdateUser.Text);
					RightsTypeBiz.UpdateRightsType(objRightsType);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
