Exemplo n.º 1
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            String Name;
            String Permit;
            String Address;

            Name    = txtSearchName.Text;
            Name    = Name.ToUpper();
            Permit  = txtSearchPermit.Text;
            Permit  = Permit.ToUpper();
            Address = txtSearchAddress.Text;
            Address = Address.ToUpper();
            OleDbConnection conn;

            using (conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
            {
                if (txtSearchName.Text != "")
                {
                    try
                    {
                        string       SqlQ    = "SELECT * FROM Overview WHERE [Full_Name] =@Name";
                        OleDbCommand command = new OleDbCommand(SqlQ, conn);
                        conn.Open();
                        command.Parameters.Add("@Name", OleDbType.VarChar).Value = txtSearchName.Text.Trim();
                        command.Parameters["@Name"].Value = Name;
                        OleDbDataReader reader = command.ExecuteReader();
                        reader.Read();

                        txtPermit.Text       = (reader["Permit_Number"].ToString());
                        txtCove.Text         = reader["Cove"].ToString();
                        txtDockExp.Text      = reader["Dock_Expiration"].ToString();
                        txtElectrical.Text   = reader["Electrical"].ToString();
                        txtEexpiration.Text  = reader["E_Expiration"].ToString();
                        txtEncroachment.Text = reader["Encroachment_Status"].ToString();
                        txtEType.Text        = reader["E_Type"].ToString();
                        txtLandUse.Text      = reader["Land_Use_Text"].ToString();
                        txtLexpiration.Text  = reader["L_Expiration"].ToString();
                        txtLType.Text        = reader["L_Type"].ToString();
                        txtMowing.Text       = reader["Mowing_Text"].ToString();
                        txtName.Text         = reader["Full_Name"].ToString();
                        txtWater.Text        = reader["Water"].ToString();
                        txtWaterType.Text    = reader["Water_Type"].ToString();
                        txtWExpiration.Text  = reader["W_Expiration"].ToString();
                        txtwORB.Text         = reader["W_ORB_Number"].ToString();
                        if (reader["Land_Use"].Equals(true))
                        {
                            radLandUseYes.Checked = true;
                        }
                        else
                        {
                            radLandUseNo.Checked = true;
                        }
                        if (reader["Electrical"].Equals(true))
                        {
                            radElectricalYes.Checked = true;
                        }
                        else
                        {
                            radElectricalNo.Checked = true;
                        }
                        if (reader["E_Affidavit"].Equals(true))
                        {
                            radAffidavitYes.Checked = true;
                        }
                        else
                        {
                            radAffidavitNo.Checked = true;
                        }
                        if (reader["Mowing"].Equals(true))
                        {
                            radMowingYes.Checked = true;
                        }
                        else
                        {
                            radMowingNo.Checked = true;
                        }

                        SqlQ    = "SELECT * FROM Dock WHERE [Name] =@Name";
                        command = new OleDbCommand(SqlQ, conn);
                        command.Parameters.Add("@Name", OleDbType.VarChar).Value = txtSearchName.Text.Trim();
                        command.Parameters["@Name"].Value = Name;
                        reader = command.ExecuteReader();
                        reader.Read();

                        txtLastInspection.Text = reader["Last_Inspection"].ToString();
                        txtNumOfSlips.Text     = reader["Number_of_Slips"].ToString();
                        txtNotes.Text          = reader["Notes"].ToString();
                        txtSize.Text           = reader["Craft_Size"].ToString();
                        txtDockType.Text       = reader["Dock_Type"].ToString();
                        if (reader["Sundeck"].Equals(true))
                        {
                            radSundeckYes.Checked = true;
                        }
                        else
                        {
                            radSundeckNo.Checked = true;
                        }
                        if (reader["Shoreline_Usage"].Equals(true))
                        {
                            radShorelineUsageYes.Checked = true;
                        }
                        else
                        {
                            radShorelineUsageNo.Checked = true;
                        }
                        if (reader["Covered"].Equals(true))
                        {
                            radCoveredYes.Checked = true;
                        }
                        else
                        {
                            radCoveredNo.Checked = true;
                        }
                        if (reader["Enclosed_Dock"].Equals(true))
                        {
                            radEnclosedYes.Checked = true;
                        }
                        else
                        {
                            radEnclosedNo.Checked = true;
                        }

                        SqlQ    = "SELECT * FROM Contact WHERE [Name] =@Name";
                        command = new OleDbCommand(SqlQ, conn);
                        command.Parameters.Add("@Name", OleDbType.VarChar).Value = txtSearchName.Text.Trim();
                        command.Parameters["@Name"].Value = Name;
                        reader = command.ExecuteReader();
                        reader.Read();

                        txtState.Text      = reader["State"].ToString();
                        txtAltState.Text   = reader["Alternate_State"].ToString();
                        txtAddress.Text    = reader["Address"].ToString();
                        txtAltAddress.Text = reader["Alternate_Address"].ToString();
                        txtCity.Text       = reader["City"].ToString();
                        txtAltCity.Text    = reader["Alternate_City"].ToString();
                        txtZipCode.Text    = reader["Zip_Code"].ToString();
                        txtAltZipCode.Text = reader["Alternate_Zip_Code"].ToString();
                        txtPhone.Text      = reader["Phone"].ToString();
                        txtAltPhone.Text   = reader["Alternate_Phone"].ToString();
                        txtEmail.Text      = reader["Email"].ToString();
                        txtAltEmail.Text   = reader["Alternate_Email"].ToString();
                    }
                    catch (InvalidOperationException)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "Error: That name doesn't exist!");
                    }
                }


                else if (txtSearchAddress.Text != "")
                {
                    try
                    {
                        string       SqlQ    = "SELECT * FROM Overview WHERE [Address] =@Address";
                        OleDbCommand command = new OleDbCommand(SqlQ, conn);
                        conn.Open();
                        command.Parameters.Add("@Address", OleDbType.VarChar).Value = txtSearchAddress.Text.Trim();
                        command.Parameters["@Address"].Value = Address;
                        OleDbDataReader reader = command.ExecuteReader();
                        reader.Read();

                        txtPermit.Text       = (reader["Permit_Number"].ToString());
                        txtCove.Text         = reader["Cove"].ToString();
                        txtDockExp.Text      = reader["Dock_Expiration"].ToString();
                        txtElectrical.Text   = reader["Electrical"].ToString();
                        txtEexpiration.Text  = reader["E_Expiration"].ToString();
                        txtEncroachment.Text = reader["Encroachment_Status"].ToString();
                        txtEType.Text        = reader["E_Type"].ToString();
                        txtLandUse.Text      = reader["Land_Use_Text"].ToString();
                        txtLexpiration.Text  = reader["L_Expiration"].ToString();
                        txtLType.Text        = reader["L_Type"].ToString();
                        txtMowing.Text       = reader["Mowing_Text"].ToString();
                        txtName.Text         = reader["Full_Name"].ToString();
                        txtWater.Text        = reader["Water"].ToString();
                        txtWaterType.Text    = reader["Water_Type"].ToString();
                        txtWExpiration.Text  = reader["W_Expiration"].ToString();
                        txtwORB.Text         = reader["W_ORB_Number"].ToString();
                        if (reader["Land_Use"].Equals(true))
                        {
                            radLandUseYes.Checked = true;
                        }
                        else
                        {
                            radLandUseNo.Checked = true;
                        }
                        if (reader["Electrical"].Equals(true))
                        {
                            radElectricalYes.Checked = true;
                        }
                        else
                        {
                            radElectricalNo.Checked = true;
                        }
                        if (reader["E_Affidavit"].Equals(true))
                        {
                            radAffidavitYes.Checked = true;
                        }
                        else
                        {
                            radAffidavitNo.Checked = true;
                        }
                        if (reader["Mowing"].Equals(true))
                        {
                            radMowingYes.Checked = true;
                        }
                        else
                        {
                            radMowingNo.Checked = true;
                        }

                        SqlQ    = "SELECT * FROM Dock WHERE [Address] =@Address";
                        command = new OleDbCommand(SqlQ, conn);
                        command.Parameters.Add("@Address", OleDbType.VarChar).Value = txtSearchAddress.Text.Trim();
                        command.Parameters["@Address"].Value = Address;
                        reader = command.ExecuteReader();
                        reader.Read();

                        txtLastInspection.Text = reader["Last_Inspection"].ToString();
                        txtNumOfSlips.Text     = reader["Number_of_Slips"].ToString();
                        txtNotes.Text          = reader["Notes"].ToString();
                        txtSize.Text           = reader["Craft_Size"].ToString();
                        txtDockType.Text       = reader["Dock_Type"].ToString();
                        if (reader["Sundeck"].Equals(true))
                        {
                            radSundeckYes.Checked = true;
                        }
                        else
                        {
                            radSundeckNo.Checked = true;
                        }
                        if (reader["Shoreline_Usage"].Equals(true))
                        {
                            radShorelineUsageYes.Checked = true;
                        }
                        else
                        {
                            radShorelineUsageNo.Checked = true;
                        }
                        if (reader["Covered"].Equals(true))
                        {
                            radCoveredYes.Checked = true;
                        }
                        else
                        {
                            radCoveredNo.Checked = true;
                        }
                        if (reader["Enclosed_Dock"].Equals(true))
                        {
                            radEnclosedYes.Checked = true;
                        }
                        else
                        {
                            radEnclosedNo.Checked = true;
                        }

                        SqlQ    = "SELECT * FROM Contact WHERE [Address] =@Address";
                        command = new OleDbCommand(SqlQ, conn);
                        command.Parameters.Add("@Address", OleDbType.VarChar).Value = txtSearchAddress.Text.Trim();
                        command.Parameters["@Address"].Value = Address;
                        reader = command.ExecuteReader();
                        reader.Read();

                        txtState.Text      = reader["State"].ToString();
                        txtAltState.Text   = reader["Alternate_State"].ToString();
                        txtAddress.Text    = reader["Address"].ToString();
                        txtAltAddress.Text = reader["Alternate_Address"].ToString();
                        txtCity.Text       = reader["City"].ToString();
                        txtAltCity.Text    = reader["Alternate_City"].ToString();
                        txtZipCode.Text    = reader["Zip_Code"].ToString();
                        txtAltZipCode.Text = reader["Alternate_Zip_Code"].ToString();
                        txtPhone.Text      = reader["Phone"].ToString();
                        txtAltPhone.Text   = reader["Alternate_Phone"].ToString();
                        txtEmail.Text      = reader["Email"].ToString();
                        txtAltEmail.Text   = reader["Alternate_Email"].ToString();
                    }
                    catch (InvalidOperationException)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "Error: That Address doesn't exist!");
                    }
                }

                else if (txtSearchPermit.Text != "")
                {
                    try
                    {
                        string       SqlQ    = "SELECT * FROM Overview WHERE [Permit_Number] =@Permit";
                        OleDbCommand command = new OleDbCommand(SqlQ, conn);
                        conn.Open();
                        command.Parameters.Add("@Permit", OleDbType.VarChar).Value = txtSearchPermit.Text.Trim();
                        command.Parameters["@Permit"].Value = Permit;
                        OleDbDataReader reader = command.ExecuteReader();
                        reader.Read();

                        txtPermit.Text       = (reader["Permit_Number"].ToString());
                        txtCove.Text         = reader["Cove"].ToString();
                        txtDockExp.Text      = reader["Dock_Expiration"].ToString();
                        txtElectrical.Text   = reader["Electrical"].ToString();
                        txtEexpiration.Text  = reader["E_Expiration"].ToString();
                        txtEncroachment.Text = reader["Encroachment_Status"].ToString();
                        txtEType.Text        = reader["E_Type"].ToString();
                        txtLandUse.Text      = reader["Land_Use_Text"].ToString();
                        txtLexpiration.Text  = reader["L_Expiration"].ToString();
                        txtLType.Text        = reader["L_Type"].ToString();
                        txtMowing.Text       = reader["Mowing_Text"].ToString();
                        txtName.Text         = reader["Full_Name"].ToString();
                        txtWater.Text        = reader["Water"].ToString();
                        txtWaterType.Text    = reader["Water_Type"].ToString();
                        txtWExpiration.Text  = reader["W_Expiration"].ToString();
                        txtwORB.Text         = reader["W_ORB_Number"].ToString();
                        if (reader["Land_Use"].Equals(true))
                        {
                            radLandUseYes.Checked = true;
                        }
                        else
                        {
                            radLandUseNo.Checked = true;
                        }
                        if (reader["Electrical"].Equals(true))
                        {
                            radElectricalYes.Checked = true;
                        }
                        else
                        {
                            radElectricalNo.Checked = true;
                        }
                        if (reader["E_Affidavit"].Equals(true))
                        {
                            radAffidavitYes.Checked = true;
                        }
                        else
                        {
                            radAffidavitNo.Checked = true;
                        }
                        if (reader["Mowing"].Equals(true))
                        {
                            radMowingYes.Checked = true;
                        }
                        else
                        {
                            radMowingNo.Checked = true;
                        }

                        SqlQ    = "SELECT * FROM Dock WHERE [Permit_Number] =@Permit";
                        command = new OleDbCommand(SqlQ, conn);
                        command.Parameters.Add("@Permit", OleDbType.VarChar).Value = txtSearchPermit.Text.Trim();
                        command.Parameters["@Permit"].Value = Permit;
                        reader = command.ExecuteReader();
                        reader.Read();

                        txtLastInspection.Text = reader["Last_Inspection"].ToString();
                        txtNumOfSlips.Text     = reader["Number_of_Slips"].ToString();
                        txtNotes.Text          = reader["Notes"].ToString();
                        txtSize.Text           = reader["Craft_Size"].ToString();
                        txtDockType.Text       = reader["Dock_Type"].ToString();
                        if (reader["Sundeck"].Equals(true))
                        {
                            radSundeckYes.Checked = true;
                        }
                        else
                        {
                            radSundeckNo.Checked = true;
                        }
                        if (reader["Shoreline_Usage"].Equals(true))
                        {
                            radShorelineUsageYes.Checked = true;
                        }
                        else
                        {
                            radShorelineUsageNo.Checked = true;
                        }
                        if (reader["Covered"].Equals(true))
                        {
                            radCoveredYes.Checked = true;
                        }
                        else
                        {
                            radCoveredNo.Checked = true;
                        }
                        if (reader["Enclosed_Dock"].Equals(true))
                        {
                            radEnclosedYes.Checked = true;
                        }
                        else
                        {
                            radEnclosedNo.Checked = true;
                        }

                        SqlQ    = "SELECT * FROM Contact WHERE [Permit_Number] =@Permit";
                        command = new OleDbCommand(SqlQ, conn);
                        command.Parameters.Add("@Permit", OleDbType.VarChar).Value = txtSearchPermit.Text.Trim();
                        command.Parameters["@Permit"].Value = Permit;
                        reader = command.ExecuteReader();
                        reader.Read();

                        txtState.Text      = reader["State"].ToString();
                        txtAltState.Text   = reader["Alternate_State"].ToString();
                        txtAddress.Text    = reader["Address"].ToString();
                        txtAltAddress.Text = reader["Alternate_Address"].ToString();
                        txtCity.Text       = reader["City"].ToString();
                        txtAltCity.Text    = reader["Alternate_City"].ToString();
                        txtZipCode.Text    = reader["Zip_Code"].ToString();
                        txtAltZipCode.Text = reader["Alternate_Zip_Code"].ToString();
                        txtPhone.Text      = reader["Phone"].ToString();
                        txtAltPhone.Text   = reader["Alternate_Phone"].ToString();
                        txtEmail.Text      = reader["Email"].ToString();
                        txtAltEmail.Text   = reader["Alternate_Email"].ToString();
                    }
                    catch (InvalidOperationException)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "Error: That Permit Number doesn't exist!");
                    }
                }
            }
        }