Created
February 8, 2018 15:52
-
-
Save riccardopirani/51a3de88b6db84718e8f79d52c893beb to your computer and use it in GitHub Desktop.
Search.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public DataTable RicercaClienti(String RagioneSociale, String Indirizzo, String Citta, String Provincia) | |
| { | |
| DataTable dt = new DataTable(); | |
| SqlConnection conn = Database.apriconnessione(); | |
| try | |
| { | |
| String Query = "Select * from Cliente "; | |
| if (RagioneSociale.ToString() != "") | |
| { | |
| Query = Query + " WHERE RagioneSociale Like '%@RagioneSociale%' "; | |
| } | |
| if (Indirizzo.ToString() != "") | |
| { | |
| int ricerca = Query.IndexOf("WHERE"); | |
| if (ricerca == -1) | |
| { | |
| Query = Query + " WHERE Indirizzo Like '%@Indirizzo%' "; | |
| } | |
| else | |
| { | |
| Query = Query + " AND Indirizzo Like '%@Indirizzo%' "; | |
| } | |
| } | |
| if (Citta.ToString() != "") | |
| { | |
| int ricerca = Query.IndexOf("WHERE"); | |
| if (ricerca == -1) | |
| { | |
| Query = Query + " WHERE Citta Like '%@Citta%' "; | |
| } | |
| else | |
| { | |
| Query = Query + " AND Citta Like '%@Citta%' "; | |
| } | |
| } | |
| if (Provincia.ToString() != "") | |
| { | |
| int ricerca = Query.IndexOf("WHERE"); | |
| if (ricerca == -1) | |
| { | |
| Query = Query + " WHERE Provincia Like '%@Provincia%' "; | |
| } | |
| else | |
| { | |
| Query = Query + " AND Provincia Like '%@Provincia%' "; | |
| } | |
| } | |
| Query = Query + " order by DataInserimento desc "; | |
| MessageBox.Show("Query: " + Query); | |
| SqlCommand cmd = new SqlCommand(Query, conn); | |
| if (RagioneSociale != "") | |
| { | |
| cmd.Parameters.AddWithValue("@RagioneSociale", SqlDbType.VarChar).Value = RagioneSociale; | |
| } | |
| if (Provincia != "") | |
| { | |
| cmd.Parameters.AddWithValue("@Provincia", SqlDbType.VarChar).Value = Provincia; | |
| } | |
| if (Citta != "") | |
| { | |
| cmd.Parameters.AddWithValue("@Citta", SqlDbType.VarChar).Value = Citta; | |
| } | |
| if (Indirizzo != "") | |
| { | |
| cmd.Parameters.AddWithValue("@Indirizzo", SqlDbType.VarChar).Value = Indirizzo; | |
| } | |
| SqlDataAdapter da = new SqlDataAdapter(cmd); | |
| dt = new DataTable(); | |
| da.Fill(dt); | |
| } | |
| catch (Exception ex) | |
| { | |
| MessageBox.Show("Errore: " + ex); | |
| Managementerror.SendError("Errore ricerca cliente: " + ex); | |
| } | |
| conn.Close(); | |
| return dt; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment