Esempio n. 1
0
        //submit Query loops through all items in InputPanel and [roughly] builds a query string
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            StringBuilder sql  = new StringBuilder("SELECT * FROM Products WHERE ");
            string        type = "tstring";

            for (int i = c1InputPanel1.Items.IndexOf(hdrQueryBuilder); i < c1InputPanel1.Items.IndexOf(hdrSqlText); i++)
            {
                InputComponent ic = c1InputPanel1.Items[i];
                if (ic.GetType() == typeof(InputComboBox))
                {
                    //handle combo box
                    InputComboBox cb = (InputComboBox)ic;
                    //append ComboBox text if Property, Append ComboBox Tag if Operator
                    sql.Append(cb.SelectedOption.Tag != null && !cb.SelectedOption.Tag.ToString().StartsWith("t") ? cb.SelectedOption.Tag.ToString() + " " : ic.Text + " ");
                    //save type of Property ComboBox for later
                    if (cb.SelectedOption.Tag != null)
                    {
                        if (cb.SelectedOption.Tag.ToString().StartsWith("t"))
                        {
                            type = cb.SelectedOption.Tag.ToString();
                        }
                        if (cb.SelectedOption.Tag.ToString().Equals("LIKE"))
                        {
                            type = type + "_like";
                        }
                    }
                }
                else if (ic.GetType() == typeof(InputTextBox))
                {
                    //handle value text box
                    if (type.Equals("tstring"))
                    {
                        sql.Append("'" + ic.Text + "' ");
                    }
                    else if (type.Equals("tstring_like"))
                    {
                        sql.Append("'%" + ic.Text + "%' ");
                    }
                    else if (type.Equals("tnumber"))
                    {
                        sql.Append(ic.Text + " ");
                    }
                    else if (type.Equals("tbool"))
                    {
                        if (ic.Text.ToLower().Equals("true"))
                        {
                            sql.Append("true ");
                        }
                        else if (ic.Text.ToLower().Equals("false"))
                        {
                            sql.Append("false ");
                        }
                    }
                }
            }
            txtSqlText.Text = sql.ToString();
            try
            {
                c1FlexGrid1.DataSource = DemoDataSource(sql.ToString(), true);
                txtSqlText.ErrorText   = string.Empty;
            }
            catch (Exception ex)
            {
                //show error on SqlTextBox
                txtSqlText.ErrorText = ex.Message;
            }
        }