Exemple #1
0
        public string CadBarras(ModelCodBar bar, int mode)
        {
            SqlCeConnection conexao  = new SqlCeConnection();
            string          consulta = "";
            string          result   = "";

            if (mode == 0) //INSERT
            {
                consulta = "INSERT INTO BARRASPRO (procodbar, forcodbar, codbarras) VALUES (@procodbar, @forcodbar, @codbarras)";
            }

            if (mode == 1) //DELETE
            {
                consulta = "DELETE FROM BARRASPRO WHERE seqcodbar = @seqcodbar";
            }

            try
            {
                conexao = Funcoes.CriaConexao();
                SqlCeCommand cmd = new SqlCeCommand(consulta, conexao);

                //Parâmetros
                if (mode > 0) //DELETE
                {
                    cmd.Parameters.AddWithValue("@seqcodbar", bar.Seqcodbar);
                }

                cmd.Parameters.AddWithValue("@procodbar", bar.Procodbar);
                cmd.Parameters.AddWithValue("@forcodbar", bar.Forcodbar);
                cmd.Parameters.AddWithValue("@codbarras", bar.Codbarras);

                conexao.Open();
                cmd.ExecuteNonQuery();
                result = "OK";

                return(result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                return(result);
            }
            finally
            {
                conexao.Close();
            }
        }
Exemple #2
0
        }   //Produtos

        public DataTable Barras(ModelCodBar filtro)
        {
            string P0 = ""; string P1 = ""; string P2 = ""; string P3 = "";

            if (filtro.Seqcodbar > 0)
            {
                P0 = " AND seqcodbar = " + filtro.Seqcodbar;
            }

            if (filtro.Procodbar > 0)
            {
                P1 = " AND procodbar = " + filtro.Procodbar;
            }

            if (filtro.Forcodbar > 0)
            {
                P2 = " AND forcodbar = " + filtro.Forcodbar;
            }

            if (filtro.Codbarras != "" && filtro.Codbarras != null)
            {
                P3 = " AND codbarras = '" + filtro.Codbarras + "'";
            }

            string sql = String.Format("SELECT * FROM BARRASPRO WHERE seqcodbar > 0 {0}{1}{2}{3}",
                                       P0, P1, P2, P3);

            try
            {
                conexao = new SqlCeConnection(Funcoes.Busca_Conexao());
                cmd     = new SqlCeCommand(sql, conexao);
                daDados = new SqlCeDataAdapter(cmd);

                dtDados = new DataTable();
                daDados.Fill(dtDados);
                return(dtDados);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexao.Close();
            }
        }   //consulta Código de Barras