Exemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the viewButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void ViewButton_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string strSQLQuery = string.Empty;
                string strColumnName = string.Empty;

                DropDownList cboOperator = null;
                TextBox txtCriteria = null;
                CheckBox chbColumn = null;
                CheckBox chbSelectAll = chbHeaderColumn;

                QueryBuilderHelper objQueryBuilder = new QueryBuilderHelper();
                #region sql query builder
                objQueryBuilder.TableName = querySearchTree.SelectedNode.Value;

                if(chbSelectAll.Checked)
                {
                    objQueryBuilder.ColumnNames.Add(ALLCOLUMNS);
                }
                else
                {

                    for(int intIndex = 0; intIndex < tblColumnNames.Rows.Count; intIndex++)
                    {
                        chbColumn = (CheckBox)(tblColumnNames.Rows[intIndex].Cells[0].FindControl("chbColumns"));
                        if(chbColumn != null)
                        {
                            if(chbColumn.Checked)
                            {
                                objQueryBuilder.ColumnNames.Add(tblColumnNames.Rows[intIndex].Cells[1].Text.ToString());
                            }
                        }
                    }
                }

                for(int intIndex = 0; intIndex < tblColumnNames.Rows.Count; intIndex++)
                {
                    strColumnName = tblColumnNames.Rows[intIndex].Cells[1].Text;
                    cboOperator = (DropDownList)tblColumnNames.Rows[intIndex].Cells[2].FindControl("cboOperator");
                    txtCriteria = (TextBox)tblColumnNames.Rows[intIndex].Cells[3].FindControl("txtCriteria");

                    if(txtCriteria.Text.ToString().Length > 0 && cboOperator.SelectedIndex != 0)
                    {
                        string strCriteria = txtCriteria.Text;
                        strCriteria = strCriteria.Replace("*", "%");
                        strCriteria = strCriteria.Replace("?", "_");
                        strCriteria = strCriteria.Replace("'", "''");

                        objQueryBuilder.AddSubClause(strColumnName, cboOperator.SelectedItem.Text, strCriteria);
                    }
                }

                strSQLQuery = objQueryBuilder.BuildQuery();
                #endregion

                txtSQLQuery.Text = strSQLQuery;
                tblColumnNames.Enabled = true;
                txtSQLQuery.ReadOnly = true;

                if(!string.Equals(btnSaveSearch.Text.ToString(), MODIFYSRCH) && (
                       !string.Equals(btnSaveSearch.Text.ToString(), MODIFYSQL)))
                {
                    btnSaveSearch.Text = SAVESRCH;
                }

                EnableCriteria();
            }
            catch(WebException webEx)
            {
                CommonUtility.HandleException(strCurrSiteUrl, webEx, 1);
                ShowLableMessage(webEx.Message);
            }
            catch(Exception ex)
            {
                CommonUtility.HandleException(strCurrSiteUrl, ex);
            }
        }