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.Admin
{
	/// <summary>
	/// ModifyUserDetail 的摘要说明。
	/// </summary>
	public partial class ModifyAdvUserDetail : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				if(this.Session["USERNAME"]==null||this.Session["Role"]==null||this.Session["USERNAME"].ToString()==""||this.Session["Role"].ToString()=="")
				{
					Response.Redirect("login.aspx");
				}
				else
				{
					string [] role=this.Session["Role"].ToString().Split('#');
					bool exists=false;
					for(int i=0;i<role.Length;i++)
					{
                        if (role[i].Equals("2") || role[i].Equals("0"))
						{
							exists=true;break;
						}
					}
					if(exists)
					{
					
				
						if((Request.Params["name"]!=null))
						{
				
							string useraccount=Request.Params["name"].ToString();
							SB.ADOHelper help=new SB.ADOHelper();
							SqlDataReader rd=help.getReader("select * from AdvHost where UserName='"+useraccount+"'");
							if(rd.Read())
							{  
								this.TextAccount.Text=rd["UserName"].ToString();
								this.TextAddress.Text=rd["Address"].ToString();
								this.TextAgent.Text=rd["agent"].ToString();
								this.TextCompanyAddress.Text=rd["url"].ToString();
								this.TextCompanyIntro.Text=rd["CompanyExplain"].ToString();
								this.TextCompanyName.Text=rd["Company"].ToString();
								this.regdate.Value=rd["RegDate"].ToString();
								this.TextEmail.Text=rd["Email"].ToString();
								this.TextFax.Text=rd["fax"].ToString();
								this.loaddate.Value=rd["Register"].ToString();
								this.TextFinallyIp.Text=rd["RegisterIp"].ToString();
								this.TextIp.Text=rd["Regip"].ToString();
								this.TextMemo.Text=rd["Remarks"].ToString();
								this.TextName.Text=rd["Name"].ToString();
								this.TextPostal.Text=rd["Postal"].ToString();
								this.TextQQ.Text=rd["qq"].ToString();
								this.TextTel.Text=rd["tel"].ToString();
								this.Textmoney.Text=rd["Money"].ToString();
								this.TextCommi.Text=rd["Commission"].ToString();
								switch(int.Parse(rd["Appearance"].ToString()))
								{
									case 1:this.Lbstate.Text="正常";break;
									case 2:this.Lbstate.Text="禁用";break;
									case 3:this.Lbstate.Text="待审核";break;
								}
								 
								this.RBLUserType.SelectedIndex=Convert.ToInt32(rd["UserType"].ToString())-1;
								rd.Close();
					
							}
					
						}
				
					
					}
					else
					{
						Response.Redirect("NoAuthor.aspx");
					}
				}
			}
//			Response.Write(Request.Params["name"].ToString());// 在此处放置用户代码以初始化页面
		}

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

		}
		#endregion

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			SB.ADOHelper help=new SB.ADOHelper();
			string acc= this.TextAccount.Text;
			string password= this.TextPwd.Text;
			string add= this.TextAddress.Text;
			string agent= this.TextAgent.Text;
			string companyadd= this.TextCompanyAddress.Text;
			string companyintro= this.TextCompanyIntro.Text;
			string companyname= this.TextCompanyName.Text;
			string date=this.regdate.Value;
			string email= this.TextEmail.Text;
			string fax= this.TextFax.Text;
			string finallyate= this.loaddate.Value;
			string finallyip= this.TextFinallyIp.Text;
			string ip= this.TextIp.Text;
			string memo= this.TextMemo.Text;
			string name= this.TextName.Text;
			string postal= this.TextPostal.Text;
			string qq= this.TextQQ.Text;
			string tel= this.TextTel.Text;
			string commi=this.TextCommi.Text;
			string money=this.Textmoney.Text;

			string username=this.Session["USERNAME"].ToString();
			DateTime dt=DateTime.Now;
			string IP=Request.UserHostAddress.ToString();
			string url=Request.Url.ToString();
			string reurl=Request.UrlReferrer.ToString();
			string accesslog="修改"+Request.Params["name"].ToString()+"用户资料";	
			
			string usertype=this.RBLUserType.SelectedValue.ToString();
			DataSet ds=new DataSet();
			SqlDataAdapter da=new SqlDataAdapter("select * from AdvHost where UserName='"+Request.Params["name"].ToString()+"'",help.conn);
			help.conn.Open();
			da.Fill(ds);
			SqlCommandBuilder sb=new SqlCommandBuilder(da);
			DataRow row=ds.Tables[0].Rows[0];
			row.BeginEdit();
			row["UserName"]=acc;
			row["UserType"]=usertype;
			row["Name"]=name;
			row["Company"]=companyname;
			row["Email"]=email;
			row["qq"]=qq;
			row["tel"]=tel;
			row["fax"]=fax;
			row["Postal"]=postal;
			row["Address"]=add;
			row["url"]=companyadd;
			row["CompanyExplain"]=companyintro;
			row["RegDate"]=date;
			row["Regip"]=ip;
			row["Register"]=finallyate;
			row["RegisterIp"]=finallyip;
			row["Remarks"]=memo;
			row["agent"]=agent;
			row["Commission"]=Convert.ToInt32(commi);
			row["Money"]=Convert.ToDouble(money);
			if(!(this.TextPwd.Text==null)||!(this.TextPwd.Text==""))
			{
				row["PassWord"]=SB.ADOHelper.Encrypt(password);
			}
			row.EndEdit();
		   da.Update(ds,ds.Tables[0].ToString());
			help.conn.Close();
     SB.ADOHelper.alertmsg("修改完成！","UserSearchadv.aspx");
	// help.execSql("insert into FinanceLogin(Affairs,AffairsType,UserName,DataAndTime,ip,webPage,fromPage,Remarks) values('3','"+affairstype+"','"+username+"','"+dt.ToString()+"','"+IP+"','"+url+"','"+reurl+"','"+accesslog+"')");
	
		}

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			Response.Redirect("usermoneyadd.aspx?username="+this.TextAccount.Text.Trim()+"&&db=AdvHost");
		}
	}
}
