Exemplo n.º 1
0
        }//Delete

        public List <Provider> Listar(string businessName)
        {
            var conn     = new SqlConnection();
            var command  = new SqlCommand();
            var dataBase = new DBConnect();
            var Lista    = new List <Provider>();


            try
            {
                conn = dataBase.Open();
                command.Connection  = conn;
                command.CommandText = "ListProvider";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@BusinessName", businessName);
                var rdr = command.ExecuteReader();

                while (rdr != null && rdr.Read())
                {
                    var reg = new Provider();
                    reg.Id           = (int)rdr["Id"];
                    reg.BusinessName = (string)rdr["BusinessName"];
                    reg.Telephone    = Convert.ToString(rdr["Telephone"] is DBNull ? "" : rdr["Telephone"]);
                    reg.Address      = Convert.ToString(rdr["Address"] is DBNull ? "" : rdr["Address"]);
                    reg.Mail         = Convert.ToString(rdr["Mail"] is DBNull ? "" : rdr["Mail"]);
                    reg.Observation  = Convert.ToString(rdr["Observation"] is DBNull ? "" : rdr["Observation"]);
                    if (rdr["IdTel"] is DBNull)
                    {
                        reg._providerData.IdTel = null;
                    }
                    else
                    {
                        reg._providerData.IdTel = (int)rdr["IdTel"];
                    }
                    if (rdr["IdAddress"] is DBNull)
                    {
                        reg._providerData.IdAddress = null;
                    }
                    else
                    {
                        reg._providerData.IdAddress = (int)rdr["IdAddress"];
                    }
                    if (rdr["IdMail"] is DBNull)
                    {
                        reg._providerData.IdMail = null;
                    }
                    else
                    {
                        reg._providerData.IdMail = (int)rdr["IdMail"];
                    }
                    Lista.Add(reg);
                }//while
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Concat(e.Message, e.StackTrace), "");
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }

            return(Lista);
        }//Listar