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.OleDb;
using System.Configuration;
using System.IO;
namespace baoge.Admin
{
	/// <summary>
	/// Admin_EditSoft 的摘要说明。
	/// </summary>
	public class Admin_EditSoft : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList ChannelID;
		protected System.Web.UI.WebControls.DropDownList ParentID;
		protected System.Web.UI.WebControls.TextBox Soft_Name;
		protected System.Web.UI.WebControls.TextBox Soft_WebSiteName;
		protected System.Web.UI.WebControls.TextBox Soft_WWW;
		protected System.Web.UI.WebControls.TextBox Soft_WWWtest;
		
		protected System.Web.UI.WebControls.TextBox Soft_pass;
		protected System.Web.UI.WebControls.TextBox Soft_huanjin;
		protected System.Web.UI.WebControls.TextBox Soft_Mail;
		protected System.Web.UI.WebControls.TextBox Soft_daxiao;
		protected System.Web.UI.WebControls.TextBox Soft_admin;
		protected System.Web.UI.WebControls.TextBox Soft_language;
		protected System.Web.UI.WebControls.TextBox Soft_jibie;
		protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
		protected System.Web.UI.WebControls.RadioButtonList RadioButtonList2;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Image Image1;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.TextBox Textbox5;
		protected System.Web.UI.WebControls.TextBox txthot;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.HtmlControls.HtmlInputFile File1;
		protected System.Web.UI.HtmlControls.HtmlInputFile File2;
		public int i;
		protected CuteEditor.Editor Editor1;
		public int CID;
//		public int face;
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("Admin_Login.aspx");
			}
			if(!IsPostBack)
			{
				CDataBind();
			}
		}



		private void CDataBind()
		{
			
			int CID=Convert.ToInt32(Request.QueryString["Soft_ID"].Trim());
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对像
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			//数据库操作
			try
			{
				ACconn.Open();
				//取得所需操作的记录ID

				//定义SQL语句
				string ACsql="select * from soft where Soft_ID="+CID;
				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				//通过执行Command实例化DataReader类
				OleDbDataReader ACdr=ACcomm.ExecuteReader();
				
				if(ACdr.Read())
				{
					Soft_Name.Text=ACdr["Soft_Name"].ToString();
					Soft_WebSiteName.Text=ACdr["Soft_WebSiteName"].ToString();
					Soft_Mail.Text=ACdr["Soft_Mail"].ToString();
                    Soft_WWW.Text=ACdr["Soft_WWW"].ToString();
					Soft_WWWtest.Text=ACdr["Soft_WWWtest"].ToString();
//					Soft_uploadpic.Text=ACdr["Soft_uploadpic"].ToString();
//					Soft_uploadsoft.Text=ACdr["Soft_uploadsoft"].ToString();
					Soft_daxiao.Text=ACdr["Soft_daxiao"].ToString();
					this.Editor1.Text=ACdr["Soft_jianjie"].ToString();
					Soft_huanjin.Text=ACdr["Soft_huanjin"].ToString();
					Soft_admin.Text=ACdr["Soft_admin"].ToString();
					Soft_language.Text=ACdr["Soft_language"].ToString();
					Soft_pass.Text=ACdr["Soft_pass"].ToString();
					
//					face=Convert.ToInt32(ACdr["Soft_star"].ToString());
					
					Soft_jibie.Text=ACdr["Soft_jibie"].ToString();
					
					this.txthot.Text=ACdr["hits"].ToString();
					this.TextBox1.Text=ACdr["Soft_uploadpic"].ToString();
					this.Textbox5.Text=ACdr["Soft_uploadsoft"].ToString();
					if((bool)ACdr["iscmd"])
					{
						RadioButtonList1.Items[0].Selected=true;
						//						i=(int)ACdr["Hits"];
					}
					else
					{
						RadioButtonList1.Items[1].Selected=true;
					}
					
					if((bool)ACdr["ishot"])
					{
						
						RadioButtonList2.Items[0].Selected=true;
						
					}
					else
					{
						RadioButtonList2.Items[1].Selected=true;
						
						
					}
					
					ACdr.Close();

				}
				else
				{
					Response.Write("对不起，请先填加信息");
				}
			
			}
			catch(Exception ex)
			{
				Response.Write(ex.ToString());
			}
			finally
			{
				ACconn.Close();

			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
			this.RadioButtonList2.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList2_SelectedIndexChanged);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			int face=Convert.ToInt32(Request.Form["face"]);
			if(RadioButtonList2.SelectedItem.Value=="1")
			{
				i+=10;
			}
			else if(RadioButtonList2.SelectedItem.Value=="0")
			{
				i=Convert.ToInt32(this.txthot.Text);
			}
	        
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库连接对像
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			//操作数据库
			try
			{
			
				int CID=Convert.ToInt32(Request.QueryString["Soft_ID"].Trim());
				ACconn.Open();

				//          string ACsqlI="insert into Article(ClassID,ChannelID,Title,LinkUrl,Hits,Content,Intro,Author,MY_Email,CopyFrom,MY_Site,Inputer,MY_QQ,UpdateTime,iscmd,ishot,uploadpic,ispic) values ('"+ParentID.SelectedValu)";
				//定义所需SQL
				string ACsql="Update soft set Soft_Name='"+Soft_Name.Text+"',Soft_WebSiteName='"+Soft_WebSiteName.Text+"',Soft_Mail='"+Soft_Mail.Text+"',Soft_WWW='"+Soft_WWW.Text+"',Soft_WWWtest='"+Soft_WWWtest.Text+"',Soft_uploadpic='"+this.TextBox1.Text+"',Soft_uploadsoft='"+this.Textbox5.Text+"',Soft_daxiao='"+Soft_daxiao.Text+"',Soft_jianjie='"+this.Editor1.Text+"',Soft_huanjin='"+Soft_huanjin.Text+"',Soft_admin='"+Soft_admin.Text+"',Soft_language='"+Soft_language.Text+"',Soft_pass='"+Soft_pass.Text+"',Soft_star="+face+",Soft_jibie='"+this.Soft_jibie.Text+"',iscmd="+this.RadioButtonList1.SelectedItem.Value+",ishot="+this.RadioButtonList2.SelectedItem.Value+",hits="+i+" where Soft_ID="+CID;

				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				ACcomm.ExecuteNonQuery();
				Response.Write("<script>alert('信息成功更新');</script>");
				//Response.Write(ACsql);
				


			}
			catch(Exception ex)
			{
				Response.Write(ex.ToString());
			}
			finally
			{
				ACconn.Close();
			}
		}

		private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int iscmd;
			if(RadioButtonList1.SelectedItem.Value=="1")
			{
				iscmd=1;
			}
			else
			{
				iscmd=0;
			}
		}

		private void RadioButtonList2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int ishot;
			if(RadioButtonList2.SelectedItem.Value=="1")
			{
				ishot=1;
			}
			else
			{
				ishot=0;
			}
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			string fullname=this.File1.PostedFile.FileName;
			string filename=fullname.Substring(fullname.LastIndexOf("\\")+1);
			string type=fullname.Substring(fullname.LastIndexOf(".")+1);
			if(type=="jpg"||type=="gif"||type=="bmp")
			{
				this.File1.PostedFile.SaveAs(Server.MapPath("uploadpic")+"\\"+filename);
				this.Image1.ImageUrl="uploadpic/"+filename;
				this.TextBox1.Text=filename;
				
			}
			else
			{
				Response.Write("<script language=javascript>alert('图片格式不正确');</script>");
			}
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			string fullname=this.File2.PostedFile.FileName;
			string filename=fullname.Substring(fullname.LastIndexOf("\\")+1);
			
		
			this.File2.PostedFile.SaveAs(Server.MapPath("uploadpic")+"\\"+filename);
				
			this.Textbox5.Text=filename;
		}
	}
}
