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

	/// <summary>
	/// CarIllegal编辑
	/// </summary>
public partial class CarIllegalEdit : LoginPageBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				string strAction = Request.QueryString["action"];
				// 自动编号
				
				txtID.ReadOnly = true;
				txtID.Text = "自动增长";
				
				ViewState["Action"] = strAction;
				if(strAction == "edit")
				{
					System.Int32 ID = System.Int32.Parse(Request.QueryString["ID"]);CarIllegal objCarIllegal = CarIllegalBiz.GetCarIllegal(ID);
					
					txtID.Text = objCarIllegal.ID.ToString();
					txtIllegalDateTime.Text = objCarIllegal.IllegalDateTime.ToString();
					txtIllegalAddress.Text = objCarIllegal.IllegalAddress;
					txtIllegalContent.Text = objCarIllegal.IllegalContent;
					txtProcessMan.Text = objCarIllegal.ProcessMan;
					txtProcessResult.Text = objCarIllegal.ProcessResult;
					txtCarID.Text = objCarIllegal.CarID.ToString();
					txtCarLicense.Text = objCarIllegal.CarLicense;
					txtID.ReadOnly = true;
					
				}
			}
		}

		public void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					CarIllegal objCarIllegal = new CarIllegal();
					
					objCarIllegal.IllegalDateTime = System.DateTime.Parse(txtIllegalDateTime.Text);
					objCarIllegal.IllegalAddress = txtIllegalAddress.Text;
					objCarIllegal.IllegalContent = txtIllegalContent.Text;
					objCarIllegal.ProcessMan = txtProcessMan.Text;
					objCarIllegal.ProcessResult = txtProcessResult.Text;
					objCarIllegal.CarID = System.Int32.Parse(txtCarID.Text);
					objCarIllegal.CarLicense = txtCarLicense.Text;
					objCarIllegal.CreateUser = UserName ;
					objCarIllegal.UpdateUser =  UserName ;
					objCarIllegal.UpdateDateTime = System.DateTime.Now ;
					objCarIllegal.Flag = 1;
					objCarIllegal.FlagDateTime = System.DateTime.Now;
                    CarIllegalBiz.AddCarIllegal(objCarIllegal);
					ViewState["Action"] = "edit";
					
					txtID.ReadOnly = true;
					
					txtID.ReadOnly = true;
					txtID.Text = objCarIllegal.ID.ToString();
					
				}
				else if((string)ViewState["Action"] == "edit")
				{
					CarIllegal objCarIllegal = CarIllegalBiz.GetCarIllegal(System.Int32.Parse(txtID.Text));
					
					objCarIllegal.ID = System.Int32.Parse(txtID.Text);
					
					objCarIllegal.IllegalDateTime = System.DateTime.Parse(txtIllegalDateTime.Text);
					
					objCarIllegal.IllegalAddress = txtIllegalAddress.Text;
					
					objCarIllegal.IllegalContent = txtIllegalContent.Text;
					
					objCarIllegal.ProcessMan = txtProcessMan.Text;
					
					objCarIllegal.ProcessResult = txtProcessResult.Text;
					
					objCarIllegal.CarID = System.Int32.Parse(txtCarID.Text);
					
					objCarIllegal.CarLicense = txtCarLicense.Text;
					
					objCarIllegal.UpdateUser = UserName ;

                    objCarIllegal.UpdateDateTime = System.DateTime.Now;

                    objCarIllegal.Flag = 1;

					CarIllegalBiz.UpdateCarIllegal(objCarIllegal);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
