Ejemplo n.º 1
0
        private void ExcluirBanco()
        {
            try
            {
                if (lstBancos.Items.Count == 1)
                {
                    Msg.Warning("É necessário que exista pelo menos um banco de dados!");
                    return;
                }

                if (lstBancos.SelectedIndex != -1)
                {
                    string DbName = lstBancos.Items[lstBancos.SelectedIndex].ToString();

                    if (DbName.ToUpper() == Cnn.Info.Database.ToUpper())
                    {
                        Msg.Warning("Não é permitido excluir o banco de dados em que o sistema está conectado!");
                        return;
                    }

                    if (Msg.Question(
                            string.Format(
                                "Tem certeza que deseja apagar o banco de dados:\n" +
                                " {0}.\n(Obs.:Esta operação é irreversível)", DbName)))
                    {
                        Cnn.Exec("drop database " + DbName);
                        ListaBancos();
                    }
                }
            }
            catch (Exception ex)
            {
                FormError.ShowError(ex);
            }
        }
Ejemplo n.º 2
0
        private void CriaBanco()
        {
            string NovoNome = GetNewDbName();

            Cnn.Exec("create database " + NovoNome);
            UsarBanco(NovoNome);
            Msg.Information(string.Format("Banco de dados {0} criado com sucesso!", NovoNome));
        }
Ejemplo n.º 3
0
        private void DbRestore(string FileName)
        {
            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Reading, FileName, Encoding.UTF8);

            DbUpdate Dbup = new DbUpdate();

            Dbup.Connection = Cnn;
            Dbup.PrepareDb();

            string buffer = "";

            string[] lines = tf.GetLines();

            pbRestauracao.Maximum = lines.Length;
            EstimatedTime et = new EstimatedTime();

            Dbup.Connection.BeginTransaction();

            try
            {
                for (int i = 0; i < lines.Length; i++)
                {
                    if (DateTime.Now.Second != uSeg)
                    {
                        lblTempoEstimado.Text = "Tempo estimado:" + et.Get(i, lines.Length);
                        lblTempoEstimado.Refresh();
                        pbRestauracao.Value = i + 1;
                        pbRestauracao.Refresh();
                        uSeg = DateTime.Now.Second;
                        this.Refresh();
                        System.Threading.Thread.Sleep(10);
                        Application.DoEvents();
                    }

                    if (string.IsNullOrEmpty(lines[i]))
                    {
                        continue;
                    }

                    if (lines[i] == DbScript.COMMIT_COMMAND)
                    {
                        Dbup.Connection.CommitTransaction();
                        Dbup.Connection.BeginTransaction();
                        continue;
                    }

                    if (lines[i].StartsWith(DbUpdate.IniStr))
                    {
                        continue;
                    }

                    buffer += " " + lines[i];
                    if (buffer.IndexOf(";") != -1)
                    {
                        Cnn.Exec(buffer);
                        buffer = "";
                    }
                }

                if (!string.IsNullOrEmpty(buffer))
                {
                    Cnn.Exec(buffer);
                }

                Dbup.Connection.CommitTransaction();
            }
            catch
            {
                Dbup.Connection.RollbackTransaction();
            }
        }