<%@ Page Language="C#" ContentType="text/html" %>
<%@ Register TagPrefix="My" TagName="MyHead" Src="head.ascx" %>
<%@ Import Namespace="System.Data.SqlClient" %> 

<%@ Register TagPrefix="My" TagName="MyFoot" Src="foot.ascx" %>
<%@ Register TagPrefix="My" TagName="MyMessage" Src="message.ascx" %>

 <!-- #INCLUDE file="../inc/Function.aspx" -->

<script runat="server">

     String strSQL;
	 String UserName;
     String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	 
     String AdvUserName;
	 
protected void Page_Load(Object Src, EventArgs E)
{
    //------判断用户是否登录---
     if(Session["Login_UserName"]==null || Session["IsLogin"]==null || Session["Userclass"]==null || Session["Login_UserName"]=="" || Session["IsLogin"].ToString().ToLower()!="true" )
   {   
      Response.Write("<script language=javascript>alert ('登录超时');document.location='../ ';<");
	  Response.Write("/script>");
	  Response.End();
    }
   AdvUserName=Session["Login_UserName"].ToString();
  //-------------------------
 
   
   System.DateTime currentTime=new System.DateTime(); 
   currentTime=System.DateTime.Now;
   
  if (!IsPostBack)
  {
   reg1.Visible=false;
   reg2.Visible=false;
   reg4.Visible=false;
    Bdata.Text=currentTime.ToString("d");
    Edata.Text=currentTime.AddYears(1).ToString("d");
   }else
   {
    ConvertSum_Unitprice.Text=ConvertSum(Unitprice.Text.ToString());
	ConvertSum_Unitprice1.Text=ConvertSum(BudgetMoney.Text.ToString());
	

   }
}

public void Bdata_Calendar1_OnClick(Object Src, EventArgs E)
{ 
   reg1.Visible=true;
}

public void Calendar1_OnClick(Object Src, EventArgs E)
{ 
   reg1.Visible=false;
   Bdata.Text=Calendar1.SelectedDate.ToString("d");
}

public void Bdata_Calendar2_OnClick(Object Src, EventArgs E)
{ 
   reg2.Visible=true;
}

public void Calendar2_OnClick(Object Src, EventArgs E)
{ 
   reg2.Visible=false;
   Edata.Text=Calendar2.SelectedDate.ToString("d");
  
}


public void RadioButton2_OnClick(Object Src, EventArgs E)
{ 
  if(RadioButton2.Checked==true)
   reg4.Visible=true;
}

public void RadioButton1_OnClick(Object Src, EventArgs E)
{ 
   if(RadioButton1.Checked==true)
    reg4.Visible=false;
}


//- 保存记录----------

public void Add_AdvList(Object Src, EventArgs E)
{ 
    if(Page.IsValid)
	{
	 strSQL="INSERT INTO AdvList(AdvUserName,AdvTitle,AdvLogo,AdvType,Advcatalog,AdvIntroduce,Bdata,Edata,EndAdv,IsExamine,AcceptAppearance,AdvAppearance,TotalMoney,GotoMoney,BudgetMoney,Unitprice,ComputeExplain,Quantity,Total,Commission,AddData,TempID,IsTemp,Payperiod,Limit)VALUES (";
	strSQL+="'"+ AdvUserName +"',";
	strSQL+="'"+ AdvTitle.Text.ToString() +"',";
	strSQL+="'"+ AdvLogo.Text.ToString() +"',";
	strSQL+=""+ AdvType.SelectedItem.Value.ToString() +",";
	strSQL+=""+ Advcatalog.SelectedItem.Value.ToString() +",";
	strSQL+="'"+ AdvIntroduce.Text.ToString() +"',";
	strSQL+="'"+ Bdata.Text.ToString() +"',";
	strSQL+="'"+ Edata.Text.ToString() +"',";
	
	 if (RadioButton1.Checked==true)
	  {
	   strSQL+="1,";
	   }
	  else{
	   strSQL+="0,";}
	   
	strSQL+=""+ IsExamine.SelectedItem.Value.ToString() +",";
	strSQL+="2,"; //AcceptAppearance 申请受理状态
	strSQL+="0,"; //AdvAppearance 广告状态
	strSQL+="0,"; // 广告投放总金额
	strSQL+="0,"; //
	strSQL+=""+Convert.ToDouble(BudgetMoney.Text) +","; //BudgetMoney
	strSQL+=""+Convert.ToDouble(Unitprice.Text) +","; //Unitprice 广告单价
	
	strSQL+="'"+ ComputeExplain.Text.ToString() +"',";
	strSQL+="0,"; //Quantity
	strSQL+="0,"; //Total	int	×	已被点的数量
	strSQL+="25,"; //Commission	int	×	佣金比例 整型
	strSQL+="'"+ System.DateTime.Now +"',";
	strSQL+="000000,"; 
	strSQL+="1,"; //新添的记录为正式记录
	strSQL+="3,";//付款周期 默认为 3月付
	strSQL+=Convert.ToInt32(Limit.Text)+")";
	
	
	//Response.Write(strSQL);
	//Response.End();
	  SqlConnection cn = new SqlConnection(strConn);
        cn.Open();
      SqlCommand cmd=new SqlCommand(strSQL,cn);
		cmd.ExecuteNonQuery();
		cn.Close();
      alertmsg(AdvTitle.Text.ToString()  +"添加成功!! 我们将尽快审核 谢谢您的支持","MangerAdvList.aspx");
	
	
	}
}



 //上传文件
 public void UploadFile(object sender , EventArgs E)
 {
   //检查上传文件不为空
   if(myFile.PostedFile!=null)
   {     
  string nam = myFile.PostedFile.FileName ;
  //取得文件名(抱括路径)里最后一个"."的索引
  int i= nam.LastIndexOf(".");
  //取得文件扩展名
    string newext =nam.Substring(i);
     newext=newext.ToLower();
   string myFileType=myFile.PostedFile.ContentType.ToLower();
   
  if(myFileType=="image/gif" ||  myFileType=="image/pjpeg" || myFileType=="image/bmp") 
   {
    if(newext.Substring(1)=="gif" || newext.Substring(1)=="jpg"||newext.Substring(1)=="bmp" || newext.Substring(1)=="swf")
    {
 
     DateTime now = DateTime.Now; 
     string newname=now.ToString().Replace(" ","").Replace("-","").Replace(":","")+myFile.PostedFile.ContentLength.ToString();
	  myFile.PostedFile.SaveAs(Server.MapPath("../count/advlogo/" + newname + newext));
   //fname.Text=newname;
   //fname.Text=myFile.PostedFile.FileName;
  //fname.Text=myFile.PostedFile.ContentType;
  //fname.Text=(myFile.PostedFile.ContentLength/1024).ToString();
  AdvLogo.Text="/count/advlogo/" + newname + newext;
   
   } else
   { Response.Write("<script>alert ('只允许上传 gif,jpg,bmp格式的文件')</"); Response.Write("script>");}
   }else 
   {  Response.Write("<script>alert ('格式不对 只允许上传图片文件 ')</"); Response.Write("script>");}
  }
 }

</script>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>5507广告联盟 - 广告商管理后台 - 添加新广告</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE1 {
	color: #666666;
	font-weight: bold;
}
.STYLE2 {color: #FFFFFF}
.STYLE3 {color: #FF0000}
-->
</style>
<SCRIPT>
var Obj=''
document.onmouseup=MUp
document.onmousemove=MMove

function MDown(Object){
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}

function MMove(){
if(Obj!=''){
 document.all(Obj).style.left=event.x-pX;
 document.all(Obj).style.top=event.y-pY;
 }
}

function MUp(){
if(Obj!=''){
 document.all(Obj).releaseCapture();
 Obj='';
 }
}
</SCRIPT>

</head>
<body>
<my:MyHead runat="server"/>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0" class="table_3">
  <tr>
    <td width="20" height="15"><img src="../web/images/body_1.gif" /></td>
    <td width="926" background="../web/images/body_2.gif"></td>
    <td width="20"><img src="../web/images/body_3.gif" width="20" height="15" /></td>
  </tr>
</table>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" background="../web/images/body_7.gif" bgcolor="#FFFFFF"><p>&nbsp;</p>
        <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="953" valign="top" bgcolor="#FFFFFF"><table width="950" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="140" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="30"><table width="98%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%"><div align="center"><img src="../images/adv_list.gif" width="25" height="25" /></div></td>
                <td width="30%"><strong>添加新广告</strong></td>
                <td width="64%"><span class="STYLE3">注：带 * 的不能为空以上资料请认真填写广告正式投放后将不能修改</span></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30">
			<form runat="server">
			<table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E4E4E4">
              <tr>
                <td height="25" colspan="2" background="../web/images/top_img.gif" bgcolor="#F7F7F7"><div align="center" class="STYLE1">基本信息</div></td>
                </tr>
              <tr>
                <td width="26%" height="25" bgcolor="#FFFFFF"><div align="right">广告名称:</div></td>
                <td width="74%" bgcolor="#FFFFFF"><asp:TextBox ID="AdvTitle" runat="server" />
                  <span class="STYLE3">* </span> <asp:RequiredFieldValidator ControlToValidate="AdvTitle" Display="Dynamic" runat="server" Text="广告名称不能为空" /></td>
                </tr>

              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">所属分类：</div></td>
                <td bgcolor="#FFFFFF">
				<asp:DropDownList ID="Advcatalog" runat="server">
				<asp:ListItem Value="1">短信服务</asp:ListItem>
	<asp:ListItem Value="2">彩信服务</asp:ListItem>
	<asp:ListItem Value="3">无线IVR</asp:ListItem>
	<asp:ListItem Value="4"> wap/KJava</asp:ListItem>
	<asp:ListItem Value="5">无线综合服务</asp:ListItem>
	<asp:ListItem Value="6">交友娱乐</asp:ListItem>
	<asp:ListItem Value="7">网络社区</asp:ListItem>
	<asp:ListItem Value="8">网络游戏</asp:ListItem>
	<asp:ListItem Value="9">收费邮箱</asp:ListItem>
	<asp:ListItem Value="10">即时通信</asp:ListItem>
	<asp:ListItem Value="11">下载服务</asp:ListItem>
	<asp:ListItem Value="12">宽带影院</asp:ListItem>
	<asp:ListItem Value="13">在线音乐</asp:ListItem>
	<asp:ListItem Value="14">旅游服务</asp:ListItem>
	<asp:ListItem Value="15">在线招聘</asp:ListItem>
	<asp:ListItem Value="16">会员资讯</asp:ListItem>
	<asp:ListItem Value="17">搜索引擎</asp:ListItem>
	<asp:ListItem Value="18">在线商城</asp:ListItem>
	<asp:ListItem Value="19">在线拍卖</asp:ListItem>
	<asp:ListItem Value="20">体育运动</asp:ListItem>
	<asp:ListItem Value="21">健康医疗</asp:ListItem>
	<asp:ListItem Value="22">教育培训</asp:ListItem>
	<asp:ListItem Value="23">证券财经</asp:ListItem>
	<asp:ListItem Value="24">电子刊物</asp:ListItem>
	<asp:ListItem Value="25">IT/网络</asp:ListItem>
	<asp:ListItem Value="26">礼品鲜花</asp:ListItem>
	<asp:ListItem Value="27">办公用品</asp:ListItem>
	<asp:ListItem Value="28">其他网络服务</asp:ListItem>
	</asp:DropDownList>
				<span class="STYLE3">* </span></td>
              </tr>
              <tr>
                <td rowspan="2" bgcolor="#FFFFFF"><div align="right">广告Logo:</div></td>
                <td height="25" bgcolor="#FFFFFF">
				  <input type="file" name="myFile" runat="server" onserverclick="UploadFile" id="myFile" />
                  <asp:Button ID="Button2" runat="server" Text="上传" CausesValidation="false" OnClick="UploadFile"/>
				  
				  只能上传 gif、jpg、bmp文件				</td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><asp:TextBox ID="AdvLogo" runat="server" ReadOnly="true" />
                  显示在广告边上的LOGO图片 大小 150*60 </td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">广告简介:</div></td>
                <td bgcolor="#FFFFFF"><asp:TextBox ID="AdvIntroduce" runat="server" TextMode="MultiLine" Columns="30" Rows="5" /></td>
                </tr>
              <tr>
                <td height="25" colspan="2" background="../web/images/top_img.gif" bgcolor="#F7F7F7"><div align="center" class="STYLE1">付费信息</div></td>
                </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">广告计费类型:</div></td>
                <td height="25" bgcolor="#FFFFFF"><asp:DropDownList ID="AdvType" runat="server">
                  <asp:ListItem Value="1">点击广告</asp:ListItem>
                  <asp:ListItem Value="2">弹窗广告</asp:ListItem>
                  <asp:ListItem Value="3">CPA按销售记费</asp:ListItem>
                </asp:DropDownList>
                  <span class="STYLE3">* </span></td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">投放需要审核:</div></td>
                <td height="25" bgcolor="#FFFFFF">
				<asp:DropDownList ID="IsExamine" runat="server">	
				<asp:ListItem Value="1">不需要审核</asp:ListItem>
                <asp:ListItem Value="2">需要审核</asp:ListItem>
                <asp:ListItem Value="3">申请已满</asp:ListItem>
                <asp:ListItem Value="4">暂停申请</asp:ListItem>
				</asp:DropDownList>
				<span class="STYLE3">* </span></td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">本次预算投放金额：</div></td>
                <td height="25" bgcolor="#FFFFFF">
				<asp:TextBox ID="BudgetMoney" runat="server" AutoPostBack="true" />元
				<span class="STYLE3">* </span>
				<asp:RequiredFieldValidator ControlToValidate="BudgetMoney" Display="Dynamic" runat="server" Text="预算投放金额不能为空" />
				
				<asp:RangeValidator ControlToValidate="BudgetMoney" Display="Dynamic" MaximumValue="9999999999" MinimumValue=1 Type="Double" runat="server" Text="金额必须打大1小于" />
			
				
				<asp:Label ID="ConvertSum_Unitprice1" runat="server" ForeColor="#0000ff"></asp:Label>				</td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">广告单价:</div></td>
                <td height="25" bgcolor="#FFFFFF"><asp:TextBox ID="Unitprice" runat="server" AutoPostBack="true" />                
                  元
				<span class="STYLE3">* </span>
				<asp:RequiredFieldValidator ControlToValidate="Unitprice" Display="Dynamic" runat="server" Text="广告单价不能为空" />
				<asp:RangeValidator ControlToValidate="Unitprice" Display="Dynamic" MaximumValue="9999999999" MinimumValue=0.001 Type="Double" runat="server" Text="金额必须打大0.0001小于" />
				<asp:Label ID="ConvertSum_Unitprice" runat="server" ForeColor="#0000ff"></asp:Label></td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">限制每天有效计费数:</div></td>
                <td height="25" bgcolor="#FFFFFF">
				<asp:TextBox ID="Limit" runat="server" Text="0"/>
				 <asp:RequiredFieldValidator ControlToValidate="Limit" Display="Dynamic" runat="server" Text="不能为空 如果不限请输入 0" />  次 <span class="STYLE3">* </span>                           
                  0 表示不限(CPA广告限制无效)  </td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">开始时间:</div></td>
                <td height="25" bgcolor="#FFFFFF"><asp:TextBox ID="Bdata" runat="server" ReadOnly="true" Columns="10" />
                  <asp:ImageButton CausesValidation="false" ID="ImageButton1" runat="server" ImageUrl="../images/icon-calendar.gif" OnClick="Bdata_Calendar1_OnClick"/>
			
		          <span class="STYLE3">* </span>
		          <asp:panel id="reg1" Runat="server">
			<DIV id=MoveDiv style="BACKGROUND: ffffff#; LEFT: 471px; WIDTH: 200px; POSITION: absolute; TOP: 382px; HEIGHT: 198px;">
<DIV onmousedown=MDown(MoveDiv) style="BACKGROUND: red; LEFT: 0px; WIDTH: 200px; POSITION: absolute; TOP: 180px; HEIGHT: 22px; background-color: #006600;">
  <div align="center" class="STYLE2">按住这里移动</div>
</DIV>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#E8E8E8" BorderColor="#666666" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" NextMonthText="上月" PrevMonthText="下月" Font-Size="10pt" ForeColor="#003399" Height="180px" Width="200px" OnSelectionChanged="Calendar1_OnClick">

        <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
        <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
        <WeekendDayStyle BackColor="#CCCCFF" />
        <OtherMonthDayStyle ForeColor="#999999" />
        <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
        <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
        <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True"
            Font-Size="10pt" ForeColor="#CCCCFF" Height="18px" />
    </asp:Calendar>
</DIV>
</asp:panel>				  </td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">结束广告:</div></td>
                <td height="25" bgcolor="#FFFFFF">
				
				  <asp:RadioButton ID="RadioButton1" runat="server" GroupName="EndAdv" Checked="true" Text="到投放结束" OnCheckedChanged="RadioButton1_OnClick" AutoPostBack="true"/>
                  <asp:RadioButton ID="RadioButton2" runat="server" GroupName="EndAdv" Text="按时间结束" OnCheckedChanged="RadioButton2_OnClick" AutoPostBack="true"/>       
                 <asp:panel id="reg4" Runat="server">
				 结束时间:<asp:TextBox ID="Edata" runat="server" ReadOnly="true" Columns="10" />
				<asp:ImageButton ID="ImageButton2" ImageUrl="../images/icon-calendar.gif" runat="server" CausesValidation="false" OnClick="Bdata_Calendar2_OnClick"/>
				</asp:panel>
						
						<span class="STYLE3">* </span>
						<asp:panel id="reg2" Runat="server">
			<DIV id=MoveDiv style="BACKGROUND: ffffff#; LEFT: 471px; WIDTH: 200px; POSITION: absolute; TOP: 382px; HEIGHT: 198px;">
<DIV onmousedown=MDown(MoveDiv) style="BACKGROUND: red; LEFT: 0px; WIDTH: 200px; POSITION: absolute; TOP: 180px; HEIGHT: 22px; background-color: #006600;">
  <div align="center" class="STYLE2">按住这里移动</div>
</DIV>
<asp:Calendar ID="Calendar2" runat="server" BackColor="#E8E8E8" BorderColor="#666666" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" NextMonthText="上月" PrevMonthText="下月" Font-Size="10pt" ForeColor="#003399" Height="180px" Width="200px" OnSelectionChanged="Calendar2_OnClick">

        <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
        <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
        <WeekendDayStyle BackColor="#CCCCFF" />
        <OtherMonthDayStyle ForeColor="#999999" />
        <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
        <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
        <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True"
            Font-Size="10pt" ForeColor="#CCCCFF" Height="18px" />
    </asp:Calendar>
</DIV>
</asp:panel>				</td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">广告计费说明：</div></td>
                <td height="25" bgcolor="#FFFFFF"><asp:TextBox ID="ComputeExplain" runat="server" TextMode="MultiLine" Columns="30" Rows="5" /></td>
              </tr>
              <tr>
                <td height="25" colspan="2" bgcolor="#F7F7F7"><div align="center">
                  <asp:Button ID="Button1" Text=" 提交申请 " runat="server" OnClick="Add_AdvList" />
</div></td>
              </tr>
            </table>
			</form>
			</td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
          </tr>
        </table></td>
        <td width="220" valign="top"><my:MyMessage runat="server"/></td>
      </tr>
    </table></td>
    <td width="15" background="../web/images/body_8.gif" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
</table>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20"><img src="../web/images/body_4.gif" width="20" /></td>
    <td width="926" background="../web/images/body_5.gif">&nbsp;</td>
    <td width="20"><div align="right"><img src="../web/images/body_6.gif" width="20" height="20" /></div></td>
  </tr>
</table>


<my:MyFoot runat="server"/>

</body>
</html>
