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

	/// <summary>
	/// BusOwners编辑
	/// </summary>
public partial class BusOwnersEdit : LoginPageBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				string strAction = Request.QueryString["action"];
				// 自动编号
				
				txtID.ReadOnly = true;
				txtID.Text = "自动增长";
                ddlBusinessNature.DataSource = OptionalValueBiz.GetOptionValueByDescription("ownermode");
                ddlBusinessNature.DataBind();
				ViewState["Action"] = strAction;
				if(strAction == "edit")
				{
					System.Int32 ID = System.Int32.Parse(Request.QueryString["ID"]);BusOwners objBusOwners = BusOwnersBiz.GetBusOwners(ID);
					
					txtID.Text = objBusOwners.ID.ToString();
					txtOwnersName.Text = objBusOwners.OwnersName;
					txtOwnersAdress.Text = objBusOwners.OwnersAdress;
					txtOwnersLicenseNo.Text = objBusOwners.OwnersLicenseNo;
                    txtLicenseNoApprovalDate.Text = objBusOwners.LicenseNoApprovalDate.ToString("yyyy-MM-dd");
                    txtLicenseNoFromDate.Text = objBusOwners.LicenseNoFromDate.ToString("yyyy-MM-dd");
                    txtLicenseNoToDate.Text = objBusOwners.LicenseNoToDate.ToString("yyyy-MM-dd");
					txtBusinessNo.Text = objBusOwners.BusinessNo;
                    txtBusinessNoApprovalDate.Text = objBusOwners.BusinessNoApprovalDate.ToString("yyyy-MM-dd");
                    txtBusinessNoFromDate.Text = objBusOwners.BusinessNoFromDate.ToString("yyyy-MM-dd");
                    txtBusinessNoToDate.Text = objBusOwners.BusinessNoToDate.ToString("yyyy-MM-dd");
					ddlBusinessNature.Text = objBusOwners.BusinessNature;
					txtCorporate.Text = objBusOwners.Corporate;
					txtAnnual.Text = objBusOwners.Annual;
					txtPhone.Text = objBusOwners.Phone;
					txtID.ReadOnly = true;
					
				}
			}
		}

		public void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					BusOwners objBusOwners = new BusOwners();
					
					objBusOwners.OwnersName = txtOwnersName.Text;
					objBusOwners.OwnersAdress = txtOwnersAdress.Text;
					objBusOwners.OwnersLicenseNo = txtOwnersLicenseNo.Text;
					objBusOwners.LicenseNoApprovalDate = System.DateTime.Parse(txtLicenseNoApprovalDate.Text);
					objBusOwners.LicenseNoFromDate = System.DateTime.Parse(txtLicenseNoFromDate.Text);
					objBusOwners.LicenseNoToDate = System.DateTime.Parse(txtLicenseNoToDate.Text);
					objBusOwners.BusinessNo = txtBusinessNo.Text;
					objBusOwners.BusinessNoApprovalDate = System.DateTime.Parse(txtBusinessNoApprovalDate.Text);
					objBusOwners.BusinessNoFromDate = System.DateTime.Parse(txtBusinessNoFromDate.Text);
					objBusOwners.BusinessNoToDate = System.DateTime.Parse(txtBusinessNoToDate.Text);
					objBusOwners.BusinessNature = ddlBusinessNature.SelectedItem.Text;
					objBusOwners.Corporate = txtCorporate.Text;
					objBusOwners.Annual = txtAnnual.Text;
					objBusOwners.Phone = txtPhone.Text;
					objBusOwners.CreateUser =  UserName ;
					objBusOwners.UpdateUser =  UserName ;
                    objBusOwners.UpdateDateTime = System.DateTime.Now;
                    objBusOwners.Flag = 1;
					objBusOwners.FlagDateTime = System.DateTime.Now;
                    BusOwnersBiz.AddBusOwners(objBusOwners);
					ViewState["Action"] = "edit";
					
					txtID.ReadOnly = true;
					
					txtID.ReadOnly = true;
					txtID.Text = objBusOwners.ID.ToString();
					
				}
				else if((string)ViewState["Action"] == "edit")
				{
					BusOwners objBusOwners = BusOwnersBiz.GetBusOwners(System.Int32.Parse(txtID.Text));
					
					objBusOwners.ID = System.Int32.Parse(txtID.Text);
					
					objBusOwners.OwnersName = txtOwnersName.Text;
					
					objBusOwners.OwnersAdress = txtOwnersAdress.Text;
					
					objBusOwners.OwnersLicenseNo = txtOwnersLicenseNo.Text;
					
					objBusOwners.LicenseNoApprovalDate = System.DateTime.Parse(txtLicenseNoApprovalDate.Text);
					
					objBusOwners.LicenseNoFromDate = System.DateTime.Parse(txtLicenseNoFromDate.Text);
					
					objBusOwners.LicenseNoToDate = System.DateTime.Parse(txtLicenseNoToDate.Text);
					
					objBusOwners.BusinessNo = txtBusinessNo.Text;
					
					objBusOwners.BusinessNoApprovalDate = System.DateTime.Parse(txtBusinessNoApprovalDate.Text);
					
					objBusOwners.BusinessNoFromDate = System.DateTime.Parse(txtBusinessNoFromDate.Text);
					
					objBusOwners.BusinessNoToDate = System.DateTime.Parse(txtBusinessNoToDate.Text);
					
					objBusOwners.BusinessNature = ddlBusinessNature.SelectedItem.Text;
					
					objBusOwners.Corporate = txtCorporate.Text;
					
					objBusOwners.Annual = txtAnnual.Text;
					
					objBusOwners.Phone = txtPhone.Text;

                    objBusOwners.UpdateUser = UserName;

                    objBusOwners.UpdateDateTime = System.DateTime.Now;

					BusOwnersBiz.UpdateBusOwners(objBusOwners);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
