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

	/// <summary>
	/// Group编辑
	/// </summary>
public partial class GroupEdit : LoginPageBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				string strAction = Request.QueryString["action"];
				// 自动编号
				
				txtGroupID.ReadOnly = true;
				txtGroupID.Text = "自动增长";
				
				ViewState["Action"] = strAction;
				if(strAction == "edit")
				{
					System.Int32 GroupID = System.Int32.Parse(Request.QueryString["GroupID"]);Group objGroup = GroupBiz.GetGroup("SYS002",GroupID);
					
					txtGroupID.Text = objGroup.GroupID.ToString();
					txtSubSystemID.Text = objGroup.SubSystemID;
					txtCompanyID.Text = objGroup.CompanyID.ToString();
					txtGroupName.Text = objGroup.GroupName;
					txtMemo.Text = objGroup.Memo;
					txtGroupType.Text = objGroup.GroupType.ToString();
					txtParentGroupID.Text = objGroup.ParentGroupID.ToString();
					txtChildrenCount.Text = objGroup.ChildrenCount.ToString();
					txtDegree.Text = objGroup.Degree.ToString();
					txtIsDefault.Text = objGroup.IsDefault.ToString();
					txtGroupID.ReadOnly = true;
					
				}
			}
		}

		public void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					Group objGroup = new Group();
					
					objGroup.SubSystemID = txtSubSystemID.Text;
					objGroup.CompanyID = System.Int32.Parse(txtCompanyID.Text);
					objGroup.GroupName = txtGroupName.Text;
					objGroup.Memo = txtMemo.Text;
					objGroup.GroupType = System.Int16.Parse(txtGroupType.Text);
					objGroup.ParentGroupID = System.Int32.Parse(txtParentGroupID.Text);
					objGroup.ChildrenCount = System.Int32.Parse(txtChildrenCount.Text);
					objGroup.Degree = System.Byte.Parse(txtDegree.Text);
					objGroup.IsDefault = System.Int16.Parse(txtIsDefault.Text);GroupBiz.AddGroup(objGroup);
					ViewState["Action"] = "edit";
					
					txtGroupID.ReadOnly = true;
					
					txtGroupID.ReadOnly = true;
					txtGroupID.Text = objGroup.GroupID.ToString();
					
				}
				else if((string)ViewState["Action"] == "edit")
				{
					Group objGroup = GroupBiz.GetGroup("SYS002",System.Int32.Parse(txtGroupID.Text));
					
					objGroup.GroupID = System.Int32.Parse(txtGroupID.Text);
					
					objGroup.SubSystemID = txtSubSystemID.Text;
					
					objGroup.CompanyID = System.Int32.Parse(txtCompanyID.Text);
					
					objGroup.GroupName = txtGroupName.Text;
					
					objGroup.Memo = txtMemo.Text;
					
					objGroup.GroupType = System.Int16.Parse(txtGroupType.Text);
					
					objGroup.ParentGroupID = System.Int32.Parse(txtParentGroupID.Text);
					
					objGroup.ChildrenCount = System.Int32.Parse(txtChildrenCount.Text);
					
					objGroup.Degree = System.Byte.Parse(txtDegree.Text);
					
					objGroup.IsDefault = System.Int16.Parse(txtIsDefault.Text);
					GroupBiz.UpdateGroup(objGroup);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
