Example #1
0
        protected void ButtonFilter_Click(object sender, EventArgs e)
        {
            GridViewResult.Dispose();
            int state = int.Parse(DropDownListStates.SelectedValue);

            if (TextBoxStatDate.Text != "" && TextBoxEndDate.Text != "")
            {
                startDate = DateTime.Parse(TextBoxStatDate.Text);

                endDate = DateTime.Parse(TextBoxEndDate.Text);
            }

            if (TextBoxStatDate.Text != "" && TextBoxEndDate.Text == "")
            {
                startDate = DateTime.Parse(TextBoxStatDate.Text);
            }

            if (TextBoxStatDate.Text == "" && TextBoxEndDate.Text != "")
            {
                endDate = DateTime.Parse(TextBoxEndDate.Text);
            }



            try
            {
                // only email
                if ((!TextBoxEmail.Text.Equals("")) && (startDate == defaultDate) && (state == 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByEmail(TextBoxEmail.Text);
                    GridViewResult.DataBind();
                }
                // only date
                if ((TextBoxEmail.Text.Equals("")) && (startDate != defaultDate && endDate != defaultDate) && (state == 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByDate(startDate, endDate);
                    GridViewResult.DataBind();
                }
                // only state
                if ((TextBoxEmail.Text.Equals("")) && (startDate == defaultDate && endDate == defaultDate) && (state != 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByState(state);
                    GridViewResult.DataBind();
                }
                // email - date
                if ((!TextBoxEmail.Text.Equals("")) && (startDate != defaultDate && endDate != defaultDate) && (state == 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByEmail_Date(TextBoxEmail.Text, startDate, endDate);
                    GridViewResult.DataBind();
                }
                // email - state
                if ((!TextBoxEmail.Text.Equals("")) && (startDate == defaultDate && endDate == defaultDate) && (state != 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByEmail_State(TextBoxEmail.Text, state);
                    GridViewResult.DataBind();
                }
                // date - state
                if ((TextBoxEmail.Text.Equals("")) && (startDate != defaultDate && endDate != defaultDate) && (state != 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByDate_State(startDate, endDate, state);
                    GridViewResult.DataBind();
                }
                // email - date - state
                if ((!TextBoxEmail.Text.Equals("")) && (startDate != defaultDate && endDate != defaultDate) && (state != 0))
                {
                    GridViewResult.DataSource = bLLclass.FilterByEmail_Date_State(TextBoxEmail.Text, startDate, endDate, state);
                    GridViewResult.DataBind();
                }
            }
            catch (ArgumentException ex)
            {
                alertException(ex.Message, ex);
            }
            GridViewResult.DataBind();

            //clean controls
            TextBoxEmail.Text = "";
            startDate         = defaultDate;
            endDate           = defaultDate;
            DropDownListStates.SelectedIndex = 0;
        }