/// <summary> /// 执行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDel_Click(object sender, EventArgs e) { string sql = txtSql.Text; DataTable dt = new NxLogMO(txtConn.Text).GetTableBySql(sql); gvTable.DataSource = dt; gvTable.DataBind(); }
/// <summary> /// 导出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOut_Click(object sender, EventArgs e) { string sql = txtSql.Text; DataTable dt = new NxLogMO(txtConn.Text).GetTableBySql(sql); //DataTableToExcel(dt, "sql导出数据"); DataTableToExcel(dt, Resources.Resource.SQL_export_data); }
/// <summary> /// 绑定日志数据 /// </summary> private DataTable BindLogs() { string STime = txtStartTime.Text.Trim(); string ETime = txtEndTime.Text.Trim(); if (string.IsNullOrEmpty(STime) || string.IsNullOrEmpty(ETime)) { PubFuncs.ResponseRandomAlert("查询开始时间或者结束时间不能为空", this); return(null); } TimeSpan timespan = (TimeSpan)(DateTime.Parse(ETime) - DateTime.Parse(STime)); if (timespan.Days > 32) { PubFuncs.ResponseRandomAlert("查询天数不能大于30天", this); return(null); } else { StringBuilder strWhere = new StringBuilder(); strWhere.Append(" 1=1"); IList <MySqlParameter> parm = new List <MySqlParameter>(); //if (!string.IsNullOrEmpty(this.ddlPf.SelectedValue)) //{ // //strWhere.Append(string.Format(" And log.Lg_text2 = '{0}' ", ddlPf.SelectedValue)); // strWhere.Append(" And log.Lg_text2 = @SelectedValue "); // parm.Add(new MySqlParameter("@SelectedValue", this.ddlPf.SelectedValue)); //} //else //{ // if (GetUserLeave() < 90) // { // CloseDivImplementation(); // Jswork.Alert("请选择要查询的平台"); // return null; // } //} //if (!string.IsNullOrEmpty(this.txtName.Text.Trim())) //{ // //strWhere.Append(string.Format(" And log.Lg_name like '%{0}%'",this.txtName.Text.Trim())); // strWhere.Append(" And log.Lg_name like @Cnname"); // parm.Add(new MySqlParameter("@Cnname", "%" + this.txtName.Text.Trim() + "%")); //} if (!string.IsNullOrEmpty(this.txtUrName.Text.Trim())) { //strWhere.Append(string.Format(" And users.Ur_name like '%{0}%'",this.txtUrName.Text.Trim())); strWhere.Append(" And users.Ur_name like @Unname"); parm.Add(new MySqlParameter("@Unname", "%" + this.txtUrName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtStartTime.Text.Trim())) { //strWhere.Append(string.Format(" And log.Lg_addtime >= '{0}'", Convert.ToDateTime(this.txtStartTime.Text.Trim()))); strWhere.Append(" And log.Lg_addtime >= @Lgaddtime"); parm.Add(new MySqlParameter("@Lgaddtime", Convert.ToDateTime(this.txtStartTime.Text.Trim()))); } if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim())) { //strWhere.Append(string.Format(" And log.Lg_addtime < '{0}'", Convert.ToDateTime(this.txtEndTime.Text.Trim()))); strWhere.Append(" And log.Lg_addtime < @LgEddtime"); parm.Add(new MySqlParameter("@LgEddtime", Convert.ToDateTime(this.txtEndTime.Text.Trim()))); } //DataTable dt = loPfanage.GetList(strWhere.ToString()); DataTable dt = new NxLogMO().GetTableBySql(strWhere.ToString(), parm); DataView view = dt.DefaultView; string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"]; view.Sort = sort; this.gvLogs.DataSource = view; this.gvLogs.DataBind(); if (dt != null && dt.Rows.Count > 0) { this.divAlert.Visible = true; this.lblAlert.Text = "一共:" + view.Count.ToString() + "数据"; this.btnExport.Enabled = true; } else { this.divAlert.Visible = false; this.btnExport.Enabled = false; } return(dt); } }