コード例 #1
0
        }   //ValidaUsuario

        public DataTable Empresa(ModelEmpresa Emp)
        {
            string P0 = ""; string P1 = ""; string P2 = ""; string P3 = "";
            string P4 = ""; //string P5 = "";

            if (Emp.codEmp > 0)
            {
                P0 = " AND codEmp = " + Emp.codEmp;
            }

            if (Emp.cnpjEmp != "" && Emp.cnpjEmp != null)
            {
                P1 = " AND cnpjEmp LIKE '" + Emp.cnpjEmp + "%'";
            }

            if (Emp.fantEmp != "" && Emp.fantEmp != null)
            {
                P2 = " AND fantEmp LIKE '" + Emp.fantEmp + "%'";
            }

            if (Emp.razaoEmp != "" && Emp.razaoEmp != null)
            {
                P3 = " AND razaoEmp LIKE '" + Emp.razaoEmp + "%'";
            }

            if (Emp.empPadrao != "" && Emp.empPadrao != null)
            {
                P4 = " AND empPadrao = '" + Emp.empPadrao + "'";
            }

            //if (Emp.nomeEmp != "" && Emp.nomeEmp != null)
            //    P5 = " AND (fantEmp LIKE '" + Emp.nomeEmp + "%' OR razaoEmp LIKE '" + Emp.nomeEmp + "%')";

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

            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();
            }
        }   //Empresa
コード例 #2
0
        public string CadEmpresa(ModelEmpresa Emp, int mode)
        {
            SqlCeConnection conexao  = new SqlCeConnection();
            string          consulta = "";
            string          result   = "";

            if (mode == 0) //INSERT
            {
                consulta = "INSERT INTO EMPRESA (cnpjEmp, statEmp, tipoEmp, codMatriz, razaoEmp, fantEmp, inscEstEmp, inscMunEmp, " +
                           "tel1Emp, tel2Emp, endEmp, nroEndEmp, compEndEmp, bairroEmp, cidadeEmp, dataCadEmp, logoEmp, CEPEmp, UFEmp, " +
                           "empPadrao, tipoData, versaoEmp, nomImglogo) \n" +
                           "VALUES (@cnpjEmp, @statEmp, @tipoEmp, @codMatriz, @razaoEmp, @fantEmp, @inscEstEmp, @inscMunEmp, @tel1Emp, " +
                           "@tel2Emp, @endEmp, @nroEndEmp, @compEndEmp, @bairroEmp, @cidadeEmp, @dataCadEmp, @logoEmp, @CEPEmp, @UFEmp, " +
                           "@empPadrao, @tipoData, @versaoEmp, @nomImglogo)";
            }

            if (mode == 1) //UPDATE
            {
                consulta = "UPDATE EMPRESA SET cnpjEmp = @cnpjEmp, statEmp = @statEmp, tipoEmp = @tipoEmp, codMatriz = @codMatriz, " +
                           "razaoEmp = @razaoEmp, fantEmp = @fantEmp, inscEstEmp = @inscEstEmp, inscMunEmp = @inscMunEmp, " +
                           "tel1Emp = @tel1Emp, tel2Emp = @tel2Emp, endEmp = @endEmp, nroEndEmp = @nroEndEmp, compEndEmp = @compEndEmp, " +
                           "bairroEmp = @bairroEmp, cidadeEmp = @cidadeEmp, dataCadEmp = @dataCadEmp, logoEmp = @logoEmp, " +
                           "CEPEmp = @CEPEmp, UFEmp = @UFEmp, empPadrao = @empPadrao, tipoData = @tipoData, " +
                           "versaoEmp = @versaoEmp, nomImglogo = @nomImglogo \n" +
                           "WHERE codEmp = @codEmp";
            }

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

                //Parâmetros
                if (mode > 0) //UPDATE
                {
                    cmd.Parameters.AddWithValue("@codEmp", Emp.codEmp);
                }

                cmd.Parameters.AddWithValue("@cnpjEmp", Emp.cnpjEmp);
                cmd.Parameters.AddWithValue("@statEmp", Emp.statEmp);
                cmd.Parameters.AddWithValue("@tipoEmp", Emp.tipoEmp);
                cmd.Parameters.AddWithValue("@codMatriz", Emp.codMatriz);
                cmd.Parameters.AddWithValue("@razaoEmp", Emp.razaoEmp);
                cmd.Parameters.AddWithValue("@fantEmp", Emp.fantEmp);
                cmd.Parameters.AddWithValue("@inscEstEmp", Emp.inscEstEmp);
                cmd.Parameters.AddWithValue("@inscMunEmp", Emp.inscMunEmp);
                cmd.Parameters.AddWithValue("@tel1Emp", Emp.tel1Emp);
                cmd.Parameters.AddWithValue("@tel2Emp", Emp.tel2Emp);
                cmd.Parameters.AddWithValue("@endEmp", Emp.endEmp);
                cmd.Parameters.AddWithValue("@nroEndEmp", Emp.nroEndEmp);
                cmd.Parameters.AddWithValue("@compEndEmp", Emp.compEndEmp);
                cmd.Parameters.AddWithValue("@bairroEmp", Emp.bairroEmp);
                cmd.Parameters.AddWithValue("@cidadeEmp", Emp.cidadeEmp);
                cmd.Parameters.AddWithValue("@dataCadEmp", Emp.dataCadEmp);
                cmd.Parameters.AddWithValue("@logoEmp", Funcoes.SetImage(Emp.logoEmp, Emp.extimglogo));
                cmd.Parameters.AddWithValue("@CEPEmp", Emp.CEPEmp);
                cmd.Parameters.AddWithValue("@UFEmp", Emp.UFEmp);
                cmd.Parameters.AddWithValue("@empPadrao", Emp.empPadrao);
                cmd.Parameters.AddWithValue("@tipoData", Emp.tipoData);
                cmd.Parameters.AddWithValue("@versaoEmp", Emp.versaoEmp);
                cmd.Parameters.AddWithValue("@nomImglogo", Emp.nomImglogo);

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

                return(result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                return(result);
            }
            finally
            {
                conexao.Close();
            }
        }