using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;

using Security;
namespace Security
{
    public partial class Comment : PageBase
    {
		protected void Page_Load(object sender, EventArgs e)
        {			
			btnDelAll.Attributes.Add("onclick","return confirm(\"是否确认删除？\")") ;
			
			if (!IsPostBack) 
			{ 
				GridviewBind();
			}
        }
		
		public string GetM(string strm)
		{
			if(strm == "False")
				return "[通过审核]";
			else
				return "[取消通过]";
		}
		
		protected void GridviewBind() 
		{ 
			///创建数据连接对象：
			MysqlHelp mh = new MysqlHelp();
			DataTable dt=new DataTable();
			dt = mh.GetDatabysql("Select * From Comment4DeepSoon Order By ID DESC");
			myGridView.DataSource = dt;        
			myGridView.DataBind();
		}
	
		protected void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
		{
			myGridView.PageIndex = e.NewPageIndex;
			GridviewBind();//重新执行自定义的GridView数据绑定函数
			((TextBox)myGridView.BottomPagerRow.FindControl("txtGoPage")).Text = ""+(myGridView.PageIndex+1);
		}
		
		protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e) 
		{ 
			if(e.CommandName == "deleteFeedBack"){
				///创建数据连接对象：
				MysqlHelp mh = new MysqlHelp();
				MySqlParameter[] updateParms ={new MySqlParameter("?ID",MySqlDbType.VarChar,8)};
				updateParms[0].Value = ""+e.CommandArgument.ToString();
				mh.Runsql("Delete From Comment4DeepSoon Where ID=?ID", updateParms);
				mh.Runsql("Delete From Comment4DeepSoon Where FatherID=?ID", updateParms);
				GridviewBind(); 
			}
			else if(e.CommandName == "setPass"){
				MysqlHelp mh = new MysqlHelp();
				string ID = e.CommandArgument.ToString();
				DataTable Dt = new DataTable();
				Dt = mh.GetDatabysql("Select isPass From Comment4DeepSoon Where ID="+ID);
				if(Dt.Rows.Count>0){
					string isPass = Dt.Rows[0]["isPass"].ToString();
					string isPassNowValue = "False";
					if(isPass == "False")isPassNowValue="True";
					else isPassNowValue = "False";
					mh.Runsql( "Update Comment4DeepSoon Set isPass="+isPassNowValue+" Where ID="+ID );
				}
				GridviewBind(); 
			}
		}
	
		protected void btnDelAll_Click(object sender, EventArgs e) 
		{ 
			string sqlText = "("; 
			int countNum = 0;//统计用户选取的记录数目
			for (int i = 0; i < myGridView.Rows.Count; i++) 
			{ 
				//搜索第n行3列 
				CheckBox cbx = (CheckBox)myGridView.Rows[i].FindControl("cbxId"); 
				if (cbx.Checked == true) 
				{ 
					sqlText = sqlText + Convert.ToInt32(myGridView.DataKeys[i].Value) + ",";
					countNum ++;
				} 
			} 
			//去掉最后的逗号，并且加上右括号 
			sqlText = sqlText.Substring(0,sqlText.Length - 1) + ")"; 
			if(countNum>0){///如果选择不为空
				MysqlHelp mh = new MysqlHelp();
				mh.Runsql("Delete From Comment4DeepSoon Where ID In" + sqlText);
				mh.Runsql("Delete From Comment4DeepSoon Where FatherID In" + sqlText);
			}
			GridviewBind(); 
		}

		#region 转到触发方法
		protected void btnGo_Click(object sender, EventArgs e)
		{
			if(((TextBox)myGridView.BottomPagerRow.FindControl("txtGoPage")).Text != ""){
				myGridView.PageIndex = int.Parse(((TextBox)myGridView.BottomPagerRow.FindControl("txtGoPage")).Text) - 1;
				GridviewBind();   //重新绑定GridView
				((TextBox)myGridView.BottomPagerRow.FindControl("txtGoPage")).Text = ""+(myGridView.PageIndex+1);
			}
		}
		#endregion
		
		protected void btnTruncate_Click(object sender, EventArgs e)
		{
			MysqlHelp mh = new MysqlHelp();
			mh.Runsql("Truncate Table Comment4DeepSoon");
			Response.Redirect("DeepSoonComment.aspx");
		}
    }
}