Exemplo n.º 1
0
        public DataTable PesquisarEstabelecimento(ModelEstabelecimento Estabelecimento)
        {
            DataTable     DtTbEstabelecimento = new DataTable("Estabelecimento");
            SqlConnection SqlCon = new SqlConnection();

            try
            {
                SqlCon.ConnectionString = Dbstring.Cnx;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "ProcPesquisarEstabelecimento";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParPesquisar = new SqlParameter();
                ParPesquisar.ParameterName = "@PesquisarEstabelecimento";
                ParPesquisar.SqlDbType     = SqlDbType.VarChar;
                ParPesquisar.Size          = 75;
                ParPesquisar.Value         = Estabelecimento.Pesquisar;
                SqlCmd.Parameters.Add(ParPesquisar);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtTbEstabelecimento);
            }
            catch (Exception ex)
            {
                DtTbEstabelecimento = null;
            }
            return(DtTbEstabelecimento);
        }
Exemplo n.º 2
0
        public string Editar(ModelEstabelecimento Estabelecimento)
        {
            string        resp   = "";
            SqlConnection SqlCon = new SqlConnection();

            try
            {
                SqlCon.ConnectionString = Dbstring.Cnx;
                SqlCon.Open();

                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "ProcEditarEstabelecimento";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParIDEstabelecimento = new SqlParameter();
                ParIDEstabelecimento.ParameterName = "@IDEstabelecimento";
                ParIDEstabelecimento.SqlDbType     = SqlDbType.Int;
                ParIDEstabelecimento.Value         = Estabelecimento.IDEstabelecimento;
                SqlCmd.Parameters.Add(ParIDEstabelecimento);

                SqlParameter ParEstabelecimento = new SqlParameter();
                ParEstabelecimento.ParameterName = "@Estabelecimento";
                ParEstabelecimento.SqlDbType     = SqlDbType.VarChar;
                ParEstabelecimento.Size          = 75;
                ParEstabelecimento.Value         = Estabelecimento.Estabelecimento;
                SqlCmd.Parameters.Add(ParEstabelecimento);

                resp = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "Cadastro não atualizado!";
            }
            catch (Exception ex)
            {
                resp = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }
            return(resp);
        }