public Acceptance SearchAcceptance(string consignmentNo) { Acceptance acceptance = null; var connString = ConfigurationManager.ConnectionStrings["EnttConnectionString"].ConnectionString; var conn = new SqlConnection(connString); var sql = $"SELECT [ConsignmentNo],[DateTime],[CourierId],[LocationId],[Comment],[ScannerId],[CreatedDate] FROM [Entt].[Acceptance] WHERE [ConsignmentNo] = '{consignmentNo}'"; using (var cmd = new SqlCommand(sql, conn)) { if (conn.State != ConnectionState.Open) { conn.Open(); } using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { acceptance = new Acceptance { ConsignmentNo = reader.GetValue(0).ToString(), DateTime = reader.GetDateTime(1), CourierId = reader.GetValue(2).ToString(), LocationId = reader.GetValue(3).ToString(), Comment = reader.GetValue(4).ToString(), ScannerId = reader.GetValue(5).ToString(), CreatedDate = reader.GetDateTime(6) }; } } } return(acceptance); }
public async Task <Acceptance> GetConsignmentInfoById(string consignmentNo) { Acceptance acceptance = null; using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EnttConnectionString"].ConnectionString)) using (var cmd = new SqlCommand("[Entt].[usp_search_consignment]", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@connote", SqlDbType.NVarChar, 50).Value = consignmentNo; await conn.OpenAsync(); using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection)) { while (await reader.ReadAsync()) { acceptance = new Acceptance { ConsignmentNo = reader["ConsignmentNo"].ToNullableString(), DateTime = reader["DateTime"].ToDateTime(), ProductType = reader["ProductType"].ToNullableString(), ProductTypeDesc = reader["ProductTypeDescription"].ToNullableString(), ItemCategory = reader["ItemCategory"].ToNullableString(), ItemCategoryDesc = reader["ItemCategoryDescription"].ToNullableString(), CourierId = reader["CourierId"].ToNullableString(), LocationId = reader["LocationId"].ToNullableString(), LocationName = reader["LocationName"].ToNullableString(), Weight = reader["Weight"].ToDecimal(), Width = reader["Width"].ToDecimal(), Height = reader["Height"].ToDecimal(), Length = reader["Length"].ToDecimal(), Comment = reader["Comment"].ToNullableString(), ScannerId = reader["ScannerId"].ToNullableString(), CreatedDate = reader["CreatedDate"].ToDateTime() }; } } } return(acceptance); }