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

	/// <summary>
	/// BusLine编辑
	/// </summary>
public partial class BusLineEdit : 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"]);BusLine objBusLine = BusLineBiz.GetBusLine(Id);
					
					txtId.Text = objBusLine.Id.ToString();
					txtLineName.Text = objBusLine.LineName;
					txtWaySites.Text = objBusLine.WaySites;
					txtStartSite.Text = objBusLine.StartSite;
					txtEndSite.Text = objBusLine.EndSite;
					txtSummerTime.Text = objBusLine.SummerTime;
					txtWinterTime.Text = objBusLine.WinterTime;
					txtMainSites.Text = objBusLine.MainSites;
					txtTimeInterval.Text = objBusLine.TimeInterval;
					txtMileage.Text = objBusLine.Mileage;
					txtId.ReadOnly = true;
					
				}
			}
		}

		public void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					BusLine objBusLine = new BusLine();
					
					objBusLine.LineName = txtLineName.Text;
					objBusLine.WaySites = txtWaySites.Text;
					objBusLine.StartSite = txtStartSite.Text;
					objBusLine.EndSite = txtEndSite.Text;
					objBusLine.SummerTime = txtSummerTime.Text;
					objBusLine.WinterTime = txtWinterTime.Text;
					objBusLine.MainSites = txtMainSites.Text;
					objBusLine.TimeInterval = txtTimeInterval.Text;
					objBusLine.Mileage = txtMileage.Text;
                    BusLineBiz.AddBusLine(objBusLine);
					ViewState["Action"] = "edit";
					txtId.ReadOnly = true;	
					txtId.Text = objBusLine.Id.ToString();
					
				}
				else if((string)ViewState["Action"] == "edit")
				{
					BusLine objBusLine = BusLineBiz.GetBusLine(System.Int32.Parse(txtId.Text));
					
					objBusLine.Id = System.Int32.Parse(txtId.Text);
					
					objBusLine.LineName = txtLineName.Text;
					
					objBusLine.WaySites = txtWaySites.Text;
					
					objBusLine.StartSite = txtStartSite.Text;
					
					objBusLine.EndSite = txtEndSite.Text;
					
					objBusLine.SummerTime = txtSummerTime.Text;
					
					objBusLine.WinterTime = txtWinterTime.Text;
					
					objBusLine.MainSites = txtMainSites.Text;
					
					objBusLine.TimeInterval = txtTimeInterval.Text;
					
					objBusLine.Mileage = txtMileage.Text;
					
					BusLineBiz.UpdateBusLine(objBusLine);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
