Esempio n. 1
0
        public int RetornaIdVersao(string NUMEROVERSAO)
        {
            int result = -1;

            try
            {
                RowsFiltroCollection RowCollection = new RowsFiltroCollection();
                RowCollection.Add(new RowsFiltro("NUMEROVERSAO", "System.String", "=", NUMEROVERSAO));
                LIS_SCRIPTVERSAOCollection LIS_SCRIPTVERSAOColl2 = new LIS_SCRIPTVERSAOCollection();
                LIS_SCRIPTVERSAOProvider   LIS_SCRIPTVERSAOP     = new LIS_SCRIPTVERSAOProvider();
                LIS_SCRIPTVERSAOColl2 = LIS_SCRIPTVERSAOP.ReadCollectionByParameter(RowCollection);

                if (LIS_SCRIPTVERSAOColl2.Count > 0)
                {
                    result = Convert.ToInt32(LIS_SCRIPTVERSAOColl2[0].IDVERSAO);
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(result);

                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }
Esempio n. 2
0
        private void GetAllAtualizaBD()
        {
            LIS_SCRIPTVERSAOColl = LIS_SCRIPTVERSAOP.ReadCollectionByParameter(null, "IDVERSAO desc");
            DataGriewDados.AutoGenerateColumns = false;
            DataGriewDados.DataSource          = LIS_SCRIPTVERSAOColl;

            lblTotalPesquisa.Text = LIS_SCRIPTVERSAOColl.Count.ToString();
        }
Esempio n. 3
0
        private void GetAllAtualizaBD()
        {
            try
            {
                LIS_SCRIPTVERSAOColl = LIS_SCRIPTVERSAOP.ReadCollectionByParameter(null, "IDSCRIPT desc");
                DataGriewDados.AutoGenerateColumns = false;
                DataGriewDados.DataSource          = LIS_SCRIPTVERSAOColl;

                lblTotalPesquisa.Text = LIS_SCRIPTVERSAOColl.Count.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ero técnico: " + ex.Message);
            }
        }
Esempio n. 4
0
        private static LIS_SCRIPTVERSAOCollection ExecuteReader(ref LIS_SCRIPTVERSAOCollection collection, ref FbDataReader dataReader, FbCommand dbCommand)
        {
            using (dataReader = dbCommand.ExecuteReader())
            {
                collection = new LIS_SCRIPTVERSAOCollection();

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

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

            return(collection);
        }
Esempio n. 5
0
        public LIS_SCRIPTVERSAOCollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder, string connectionString)
        {
            FbDataReader dataReader               = null;
            string       strSqlCommand            = String.Empty;
            LIS_SCRIPTVERSAOCollection collection = null;

            try
            {
                if (RowsFiltro != null)
                {
                    if (RowsFiltro.Count > 0)
                    {
                        strSqlCommand = "SELECT * FROM LIS_SCRIPTVERSAO 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 LIS_SCRIPTVERSAO  order by  " + FieldOrder;
                    }
                }
                else
                {
                    strSqlCommand = "SELECT * FROM LIS_SCRIPTVERSAO order by  " + FieldOrder;
                }

                //Verificando a existência de um transação aberta
                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;
            }
        }
Esempio n. 6
0
        private void AtualizaBancoDados()
        {
            try
            {
                lblMsg.ForeColor = System.Drawing.Color.Blue;
                lblMsg.Text      = "Executando os script no Banco de Dados... Aguarde";
                lblMsg.ForeColor = System.Drawing.Color.Blue;

                //Busca a ultima versão do banco de dados atual
                VERSAOBdOldColl = VERSAOP.ReadCollectionByParameter(null, "NUMEROVERSAO");
                string NUMEROVERSAOATUAL = VERSAOBdOldColl[VERSAOBdOldColl.Count - 1].NUMEROVERSAO;

                //Filtra os script do banco de dados novos
                //que serão executados no banco de dados Atual
                string BDScript         = BmsSoftware.ConfigSistema1.Default.BDScript.Trim() == string.Empty ? @"C:\IMEXSISTEMA\BD\SCRIPTBDIMEX.GDB" : BmsSoftware.ConfigSistema1.Default.BDScript.Trim();
                string connectionString = "User=SYSDBA;Password=masterkey;DataSource=localhost;Database=" + BDScript;


                RowsFiltroCollection RowBDAntigo = new RowsFiltroCollection();
                RowBDAntigo.Add(new RowsFiltro("NUMEROVERSAO", "System.String", ">", NUMEROVERSAOATUAL.ToString()));
                LIS_SCRIPTVERSAOColl = LIS_SCRIPTVERSAO2P.ReadCollectionByParameter(RowBDAntigo, "IDSCRIPT", connectionString);

                VERSAO2Provider VERSAO2P = new VERSAO2Provider();

                foreach (var item in LIS_SCRIPTVERSAOColl)
                {
                    string NUMEROVERSAO = item.NUMEROVERSAO;

                    //Verifica se ja existe uma id para a versao
                    _IDVERSAO = RetornaIdVersao(NUMEROVERSAO);

                    if (_IDVERSAO == -1)
                    {
                        _IDVERSAO = VERSAOP.Save(-1, NUMEROVERSAO);
                    }

                    try
                    {
                        if (ComandoScript2(item.DESCRICAO))
                        {
                            SCRIPTVERSAOP.Save(-1, _IDVERSAO, item.DESCRICAO, "S");
                        }
                        else
                        {
                            SCRIPTVERSAOP.Save(-1, _IDVERSAO, item.DESCRICAO, "N");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erro ao executar o script da versão: " + NUMEROVERSAO,
                                        ConfigSistema1.Default.NomeEmpresa,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information,
                                        MessageBoxDefaultButton.Button1);

                        MessageBox.Show("Erro técnico: " + ex.Message);
                    }
                }


                lblMsg.ForeColor = System.Drawing.Color.Blue;
                lblMsg.Text      = "Script executado com sucesso!";
                lblMsg.ForeColor = System.Drawing.Color.Blue;
            }
            catch (Exception ex)
            {
                lblMsg.ForeColor = System.Drawing.Color.Red;
                lblMsg.Text      = "Erro ao executar o script";
                lblMsg.ForeColor = System.Drawing.Color.Blue;

                MessageBox.Show("Erro ao executar o script!",
                                ConfigSistema1.Default.NomeEmpresa,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1);


                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }
Esempio n. 7
0
        public LIS_SCRIPTVERSAOCollection ReadCollection()
        {
            FbDataReader dataReader = null;

            try
            {
                LIS_SCRIPTVERSAOCollection collection = null;

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

                    dbCommand             = new FbCommand("SELECT * FROM LIS_SCRIPTVERSAO", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

                    dbCommand             = new FbCommand("SELECT * FROM LIS_SCRIPTVERSAO", dbCnn);
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                // Tipo do comando de banco Procedure ou SQL
                dbCommand.CommandType = CommandType.Text;

                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;
            }
        }