Exemple #1
0
        private Boolean VerificaExisteUnidade(int IDUNIDADE)
        {
            Boolean result = false;

            try
            {
                RowRelatorio.Clear();
                RowRelatorio.Add(new RowsFiltro("IDUNIDADE", "System.Int32", "=", IDUNIDADE.ToString()));
                UNIDADECollection UNIDADEColl = new UNIDADECollection();
                UNIDADEColl = UNIDADEP.ReadCollectionByParameter(RowRelatorio);

                if (UNIDADEColl.Count > 0)
                {
                    result = true;
                }


                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao Verificar se Unidade Existe");
                MessageBox.Show("Erro técnico: " + ex.Message);
                return(result);
            }
        }
Exemple #2
0
        private void GetAllUnidade()
        {
            try
            {
                UNIDADEColl = UNIDADEP.ReadCollectionByParameter(null, "NOME");
                DataGriewDados.AutoGenerateColumns = false;
                DataGriewDados.DataSource          = UNIDADEColl;

                lblTotalPesquisa.Text = UNIDADEColl.Count.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro Técnico: " + ex.Message);
            }
        }
Exemple #3
0
        private static UNIDADECollection ExecuteReader(ref UNIDADECollection collection, ref FbDataReader dataReader, FbCommand dbCommand)
        {
            using (dataReader = dbCommand.ExecuteReader())
            {
                collection = new UNIDADECollection();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        collection.Add(FillEntityObject(ref dataReader));
                    }
                }

                if (!(dataReader.IsClosed))
                {
                    dataReader.Close();
                }
                dataReader.Dispose();
            }

            return(collection);
        }
Exemple #4
0
        public void CriaArquivoCSV()
        {
            try
            {
                System.IO.StreamWriter sw = null;

                try
                {
                    //Pega o caminho do arquivo
                    string caminho = BmsSoftware.ConfigSistema1.Default.PathInstall + @"\sicronizacao.csv";
                    //Cria um StreamWriter no local
                    sw = new System.IO.StreamWriter(caminho, false, System.Text.Encoding.GetEncoding(1252));

                    //Dados de Status
                    STATUSCollection STATUSColl = new STATUSCollection();
                    STATUSColl = STATUSP.ReadCollectionByParameter(null);
                    foreach (var item in STATUSColl)
                    {
                        //Dados de Status
                        string IDSTATUS      = Convert.ToInt32(item.IDSTATUS).ToString().PadLeft(6, '0');
                        string IDGRUPOSTATUS = "000000";
                        if (ValidacoesLibrary.ValidaTipoInt32(item.IDGRUPOSTATUS.ToString()))
                        {
                            IDGRUPOSTATUS = Convert.ToInt32(item.IDGRUPOSTATUS).ToString().PadLeft(6, '0');
                            string NOMESTATUS = item.NOME;
                            //grava dados de Status
                            sw.WriteLine("STA" + ";" + IDSTATUS + ";" + IDGRUPOSTATUS + ";" + NOMESTATUS);
                        }
                    }

                    //Categoria Produto
                    GRUPOCATEGORIACollection GRUPOCATEGORIAColl = new GRUPOCATEGORIACollection();
                    GRUPOCATEGORIAColl = GRUPOCATEGORIAP.ReadCollectionByParameter(null);
                    foreach (var item2 in GRUPOCATEGORIAColl)
                    {
                        //Dados de Categoria Produto
                        string IDGRUPOCATEGORIA   = Convert.ToInt32(item2.IDGRUPOCATEGORIA).ToString().PadLeft(6, '0');
                        string NOMEGRUPOCATEGORIA = item2.NOME;

                        //grava dados de Categoria Produto
                        sw.WriteLine("GSA" + ";" + IDGRUPOCATEGORIA + ";" + NOMEGRUPOCATEGORIA);
                    }

                    //Categoria Produto
                    UNIDADECollection UNIDADEColl = new UNIDADECollection();
                    UNIDADEColl = UNIDADEP.ReadCollectionByParameter(null);
                    foreach (var item3 in UNIDADEColl)
                    {
                        //Dados Unidade
                        string IDUNIDADE   = Convert.ToInt32(item3.IDUNIDADE).ToString().PadLeft(6, '0');
                        string NOMEUNIDADE = item3.NOME;

                        //grava dados da Unidade
                        sw.WriteLine("UNI" + ";" + IDUNIDADE + ";" + NOMEUNIDADE);
                    }

                    //Dados da Marca
                    MARCACollection MARCAColl = new MARCACollection();
                    MARCAColl = MARCAP.ReadCollectionByParameter(null);
                    foreach (var item5 in MARCAColl)
                    {
                        //Dados MARCA
                        string IDMARCA   = Convert.ToInt32(item5.IDMARCA).ToString().PadLeft(6, '0');
                        string NOMEMARCA = item5.NOME;

                        //grava dados da MARCA
                        sw.WriteLine("MAR" + ";" + IDMARCA + ";" + NOMEMARCA);
                    }

                    //Cor
                    CORCollection CORColl = new CORCollection();
                    CORColl = CORP.ReadCollectionByParameter(null);
                    foreach (var item9 in CORColl)
                    {
                        //Dados Cor
                        string IDCOR   = Convert.ToInt32(item9.IDCOR).ToString().PadLeft(6, '0');
                        string NOMECOR = item9.NOME;

                        //grava dados da Cor
                        sw.WriteLine("COR" + ";" + IDCOR + ";" + NOMECOR);
                    }

                    //Ambiente
                    AMBIENTECollection AMBIENTEColl = new AMBIENTECollection();
                    AMBIENTEColl = AMBIENTEP.ReadCollectionByParameter(null);
                    foreach (var item8 in AMBIENTEColl)
                    {
                        //Dados AMBIENTE
                        string IDAMBIENTE   = Convert.ToInt32(item8.IDAMBIENTE).ToString().PadLeft(6, '0');
                        string NOMEAMBIENTE = item8.NOME;

                        //grava dados do Ambiente
                        sw.WriteLine("AMB" + ";" + IDAMBIENTE + ";" + NOMEAMBIENTE);
                    }

                    //Vendedor
                    FUNCIONARIOCollection FUNCIONARIOColl = new FUNCIONARIOCollection();
                    FUNCIONARIOColl = FUNCIONARIOP.ReadCollectionByParameter(null);
                    foreach (var item10 in FUNCIONARIOColl)
                    {
                        //Dados FUNCIONARIO
                        string IDFUNCIONARIO   = Convert.ToInt32(item10.IDFUNCIONARIO).ToString().PadLeft(6, '0');
                        string NOMEFUNCINAROIO = item10.NOME;
                        string ENDERECO        = item10.ENDERECO;
                        string CIDADE          = item10.CIDADE;
                        string UF        = item10.UF;
                        string CEP       = item10.CEP;
                        string BAIRRO    = item10.BAIRRO;
                        string CPF       = item10.CPF;
                        string EMAIL     = item10.EMAIL;
                        string TELEFONE1 = item10.TELEFONE1;
                        string TELEFONE2 = item10.TELEFONE2;
                        string FUNCAO    = item10.FUNCAO;

                        //grava dados do FUNCIONARIO
                        sw.WriteLine("FUNC" + ";" + IDFUNCIONARIO + ";" + NOMEFUNCINAROIO + ";" + ENDERECO + ";" + CIDADE + ";" + UF + ";" + CEP + ";" + BAIRRO + ";" + CPF + ";" +
                                     EMAIL + ";" + TELEFONE1 + ";" + TELEFONE2 + ";" + FUNCAO);
                    }

                    //Cadastro de Produto
                    PRODUTOSCollection PRODUTOSColl = new PRODUTOSCollection();
                    PRODUTOSColl = PRODUTOSP.ReadCollectionByParameter(null);
                    foreach (var item4 in PRODUTOSColl)
                    {
                        //Dados Produto
                        string IDPRODUTO            = Convert.ToInt32(item4.IDPRODUTO).ToString().PadLeft(6, '0');
                        string NOMEPRODUTO          = item4.NOMEPRODUTO;
                        string CODPRODUTOFORNECEDOR = item4.CODPRODUTOFORNECEDOR.ToString().PadLeft(10, '0');
                        string VALORVENDA1          = Convert.ToDecimal(item4.VALORVENDA1).ToString("n2");

                        string IDUNIDADE = "000000";
                        if (ValidacoesLibrary.ValidaTipoInt32(item4.IDUNIDADE.ToString()))
                        {
                            IDUNIDADE = item4.IDUNIDADE.ToString().PadLeft(6, '0');
                        }

                        string IDGRUPOCATEGORIA = "000000";
                        if (ValidacoesLibrary.ValidaTipoInt32(item4.IDGRUPOCATEGORIA.ToString()))
                        {
                            IDGRUPOCATEGORIA = item4.IDGRUPOCATEGORIA.ToString().PadLeft(6, '0');
                        }

                        string IDSTATUS = "000000";
                        if (ValidacoesLibrary.ValidaTipoInt32(item4.IDSTATUS.ToString()))
                        {
                            IDSTATUS = item4.IDSTATUS.ToString().PadLeft(6, '0');
                        }

                        string IDMARCA = "000000";
                        if (ValidacoesLibrary.ValidaTipoInt32(item4.IDMARCA.ToString()))
                        {
                            IDMARCA = item4.IDMARCA.ToString().PadLeft(6, '0');
                        }

                        string FLAGINATIVO = item4.FLAGINATIVO;


                        //grava dados da Produto
                        sw.WriteLine("PRO" + ";" + IDPRODUTO + ";" + NOMEPRODUTO + ";" + CODPRODUTOFORNECEDOR + ";" + VALORVENDA1 + ";" + IDUNIDADE + ";"
                                     + IDGRUPOCATEGORIA + ";" + IDSTATUS + ";" + IDMARCA + ";" + FLAGINATIVO);
                    }

                    //Cadastro de Cliente
                    CLIENTECollection CLIENTEColl = new CLIENTECollection();
                    CLIENTEColl = CLIENTEP.ReadCollectionByParameter(null);
                    foreach (var item6 in CLIENTEColl)
                    {
                        string IDCLIENTE     = Convert.ToInt32(item6.IDCLIENTE).ToString().PadLeft(6, '0');
                        string NOMECLIENTE   = item6.NOME;
                        string TELEFONE1     = item6.TELEFONE1;
                        string TELEFONE2     = item6.TELEFONE2;
                        string CPF           = item6.CPF;
                        string CNPJ          = item6.CNPJ;
                        string IE            = item6.IE;
                        string ENDERECO1     = item6.ENDERECO1;
                        string NUMEROENDER   = item6.NUMEROENDER;
                        string COMPLEMENTO1  = item6.COMPLEMENTO1;
                        string BAIRRO1       = item6.BAIRRO1;
                        string CEP1          = item6.CEP1;
                        string COD_MUN_IBGE  = item6.COD_MUN_IBGE.ToString();
                        string EMAILCLIENTE  = item6.EMAILCLIENTE;
                        string FLAGBLOQUEADO = item6.FLAGBLOQUEADO;

                        sw.WriteLine("CLI" + ";" + IDCLIENTE + ";" + NOMECLIENTE + ";" + TELEFONE1 + ";" + TELEFONE2 + ";" + CPF + ";" +
                                     CNPJ + ";" + IE + ";" + ENDERECO1 + ";" + NUMEROENDER + ";" + COMPLEMENTO1 + ";" + BAIRRO1 + ";" + CEP1 + ";" +
                                     COD_MUN_IBGE + ";" + EMAILCLIENTE + ";" + FLAGBLOQUEADO);
                    }


                    sw.Close();

                    //Dados da Empresa
                    EMPRESAtY = EMPRESAP.Read(1);

                    //faz o upload do arquivo sicronizado
                    if (File.Exists(caminho))
                    {
                        Upload(caminho, Util.RetiraLetras(EMPRESAtY.CNPJCPF));
                    }
                    else
                    {
                        MessageBox.Show("Arquivo: " + caminho + " Não Localizado!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    //Fechar stream SEMPRE
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao criar arquivo de sicronização!");
                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }
Exemple #5
0
        public UNIDADECollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder)
        {
            FbDataReader      dataReader = null;
            UNIDADECollection collection = null;

            string strSqlCommand = String.Empty;

            try
            {
                if (RowsFiltro != null)
                {
                    if (RowsFiltro.Count > 0)
                    {
                        strSqlCommand = "SELECT * FROM UNIDADE WHERE (";

                        ArrayList _rowsFiltro = new ArrayList();
                        RowsFiltro.ForEach(delegate(RowsFiltro i)
                        {
                            string[] item = { i.Condicao.ToString(), i.Campo.ToString(), i.Tipo.ToString(), i.Operador.ToString(), i.Valor.ToString() };
                            _rowsFiltro.Add(item);
                        });

                        int _count = 1;
                        foreach (string[] item in _rowsFiltro)
                        {
                            strSqlCommand += "(" + item[1] + " " + item[3];
                            switch (item[2])
                            {
                            case ("System.String"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " '" + item[4] + "')";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Int16"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " " + item[4] + ")";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Int32"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " " + item[4] + ")";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Int64"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " " + item[4] + ")";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Double"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " " + item[4] + ")";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Decimal"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " " + item[4] + ")";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Float"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " " + item[4] + ")";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Byte"):
                                strSqlCommand += " " + item[4] + ")";
                                break;

                            case ("System.SByte"):
                                strSqlCommand += " " + item[4] + ")";
                                break;

                            case ("System.Char"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " '" + item[4] + "')";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.DateTime"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " '" + item[4] + "')";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Guid"):
                                if (item[3].ToUpper() != "LIKE")
                                {
                                    strSqlCommand += " '" + item[4] + "')";
                                }
                                else
                                {
                                    strSqlCommand += " '%" + item[4] + "%')";
                                }
                                break;

                            case ("System.Boolean"):
                                strSqlCommand += " " + item[4] + ")";
                                break;
                            }
                            if (_rowsFiltro.Count > 1)
                            {
                                if (_count < _rowsFiltro.Count)
                                {
                                    strSqlCommand += " " + item[0] + " ";
                                }
                                _count++;
                            }
                        }
                        strSqlCommand += ")  order by  " + FieldOrder;
                    }
                    else
                    {
                        strSqlCommand = "SELECT * FROM UNIDADE  order by  " + FieldOrder;
                    }
                }
                else
                {
                    strSqlCommand = "SELECT * FROM UNIDADE  order by " + FieldOrder;
                }

                //Verificando a existência de um transação
                if (dbTransaction != null)
                {
                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand(strSqlCommand, dbCnn);
                    dbCommand.CommandType = CommandType.Text;
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = new FbConnection(connectionString);
                    }

                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand(strSqlCommand, dbCnn);
                    dbCommand.CommandType = CommandType.Text;
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }


                collection = ExecuteReader(ref collection, ref dataReader, dbCommand);

                if (dataReader != null)
                {
                    dataReader.Close();
                    dataReader.Dispose();
                }

                if (dbTransaction == null)
                {
                    dbCommand.Transaction.Commit();
                    dbCnn.Close();
                }

                return(collection);
            }
            catch (Exception ex)
            {
                // Deleta reader
                if (dataReader != null)
                {
                    dataReader.Close();
                    dataReader.Dispose();
                }

                if (dbTransaction != null)
                {
                    this.RollbackTransaction();
                }
                else
                {
                    if (dbCommand.Transaction != null)
                    {
                        dbCommand.Transaction.Rollback();
                    }
                    if (dbCnn.State == ConnectionState.Open)
                    {
                        dbCnn.Close();
                    }
                }

                throw ex;
            }
        }