| | 49 | |
| | 50 | public Agent FindByShortName(string shortName) |
| | 51 | { |
| | 52 | const string query = "SELECT Symbol, F_ROZ, InvoiceProviderId FROM dbo.Agenci WHERE F_ROZ=@shortName"; |
| | 53 | SqlConnection conn = null; |
| | 54 | SqlCommand cmd = null; |
| | 55 | SqlDataReader reader = null; |
| | 56 | |
| | 57 | try |
| | 58 | { |
| | 59 | conn = new SqlConnection(ConnString.getConnString().Value); |
| | 60 | conn.Open(); |
| | 61 | cmd = new SqlCommand(query, conn); |
| | 62 | reader = cmd.ExecuteReader(); |
| | 63 | if (reader != null && reader.Read()) |
| | 64 | return new Agent(reader.GetString(0).Trim().ToLower(), |
| | 65 | reader.GetString(1).Trim().ToUpper(), |
| | 66 | reader.GetInt32(2)); |
| | 67 | } |
| | 68 | finally |
| | 69 | { |
| | 70 | if (reader != null) |
| | 71 | { |
| | 72 | reader.Close(); |
| | 73 | reader.Dispose(); |
| | 74 | } |
| | 75 | if (cmd != null) cmd.Dispose(); |
| | 76 | if (conn != null) |
| | 77 | { |
| | 78 | conn.Close(); |
| | 79 | conn.Dispose(); |
| | 80 | } |
| | 81 | |
| | 82 | } |
| | 83 | return null; |
| | 84 | } |