using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace WebApplication2
{
	/// <summary>
	/// check_detail 的摘要说明。
	/// </summary>
	public partial class check_adv : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
              Bind();
			}
			
			// 在此处放置用户代码以初始化页面
		}
		private void Bind()
		{
			SB.ADOHelper help=new SB.ADOHelper();
			if(Request.Params["id"]!=null||Request.Params["id"].ToString()!="")
			{
				
				string id=Request.Params["id"].ToString();
				
				SqlDataReader rd=help.getReader("select id,AcceptAppearance,IsTemp,TempID from AdvList where id='"+id+"'");
				
				if(rd.Read())
				{
				
				       
					if(Convert.ToInt32(rd["AcceptAppearance"].ToString())==1||Convert.ToInt32(rd["AcceptAppearance"].ToString())==2)
					{
						rd.Close();
						Response.Redirect("ModifAdvList.aspx?id="+id);   
							
					}
					else
					{
						rd.Close();
					    rd=help.getReader("select AdvTitle,AdvType,TotalMoney,GotoMoney,Unitprice,Commission from AdvList where id='"+Request.Params["id"].ToString()+"'");
						if(rd.Read())
						{
			
							this.Label2.Text=rd["AdvTitle"].ToString();
							switch(Convert.ToInt32(rd["AdvType"].ToString()))
							{
								case 1:this.Label3.Text="CPC点击广告";Label10.Text="CPC点击广告";break;
								case 2:this.Label3.Text="弹窗广告";Label10.Text="弹窗广告";break;
								case 3:this.Label3.Text="CPA按销售记费";Label10.Text="CPA按销售记费";break;
							}
							this.Label11.Text=rd["TotalMoney"].ToString();
							this.Label12.Text=rd["GotoMoney"].ToString();
			
							this.Label13.Text=rd["Commission"].ToString();
							this.Label4.Text=rd["TotalMoney"].ToString();
							this.Label5.Text=rd["GotoMoney"].ToString();
							this.Label6.Text=rd["Unitprice"].ToString();
							this.Label7.Text=rd["Commission"].ToString();
							rd.Close();
							
						}
						rd=help.getReader("select AdvTitle,AdvType,TotalMoney,GotoMoney,Unitprice,Commission from AdvList where TempID='"+Request.Params["id"].ToString()+"'");
						if(rd.Read())
						{
							this.Label9.Text=rd["AdvTitle"].ToString();
							this.TextBox1.Text=rd["Unitprice"].ToString();
						}

					}
				}
				else
				{
					Response.Write("<script>alert(\"没有数据！\")</script>");
				}
				
			}

			
			
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			SB.ADOHelper help=new SB.ADOHelper();
			double price=Convert.ToDouble(this.TextBox1.Text);

	help.execSql("update AdvList set  Unitprice="+price+",AcceptAppearance='1' where id='"+Request.Params["id"].ToString()+"'");
	
	  help.execSql("delete from AdvList where TempID='"+Request.Params["id"].ToString()+"'and id=(select id from AdvList where TempID='"+Request.Params["id"].ToString()+"')");
    Response.Redirect("AdvList.aspx");

		}

		protected void Button2_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("AdvList.aspx");
		}
	}
}
