Example #1
0
 def GetValue (self):
     """Pega o valor da sequência. Use só na hora do insert, pliz"""
     db = dbManager.getDbManager ()
     _, valores = db.select ('seq_' + self.tabela + '.nextval', 'dual')
     valor = valores[0][0]
     self.SetValue (str (valor + 1))
     return valor
Example #2
0
    def onAtualiza(self, event):
        """Clicou em 'Atualizar'!"""
        # vê quais campos serão atualizados
        colunasAtualiza = []
        valoresAtualiza = []
        for c in self.campos:
            if not c[1].IsEmpty():
                colunasAtualiza.append(c[0])
                # formata a entrada dependendo do tipo
                if type(c[1]) is wx.Choice:
                    valor = "'" + c[1].GetString(c[1].GetSelection()) + "'"
                elif type(c[1]) is IntCtrl or type(c[1]) is sequenceCtrl:
                    valor = str(c[1].GetValue())
                elif type(c[1]) is meuDatePicker:
                    valor = "TO_DATE ('" + c[1].GetValue().FormatISODate() + "', 'yyyy-mm-dd')"
                else:
                    valor = "'" + str(c[1].GetValue()) + "'"
                valoresAtualiza.append(valor)

        # só tenta atualizar se tem alguma coisa pra atualizar
        if len(colunasAtualiza):
            # restrições são os próprios valores da tupla em questão
            colunasRestricao = self.colunas
            valoresRestricao = self.tupla

            app = self.GetParent().GetParent()
            try:
                dbManager.getDbManager().update(
                    self.tabela, colunasAtualiza, valoresAtualiza, colunasRestricao, valoresRestricao
                )
                app.algoMudou()
                app.SetStatusText("Tupla modificada")
                wx.MessageBox("Tupla modificada")
                self.Close()
            except Exception as e:
                app.SetStatusText("Erro ao modificar tupla(s)")
                wx.MessageBox(str(e), "Erro ao modificar tupla(s)", wx.CENTRE + wx.ICON_ERROR + wx.OK)
Example #3
0
    def __init__ (self):
        wx.Frame.__init__ (self, None, wx.ID_ANY, 'LabBD', wx.DefaultPosition, self.frameSize)
        self.CreateStatusBar ()

        # Menus
        self.montaMenus ()
        self.Bind (wx.EVT_MENU, self.onQuit, id = wx.ID_EXIT)
        self.Bind (wx.EVT_MENU, self.onAbout, id = wx.ID_ABOUT)
        self.Bind (wx.EVT_MENU, self.onSelect, id = self.ID_SELECT)
        self.Bind (wx.EVT_MENU, self.onInsert, id = self.ID_INSERT)
        self.Bind (wx.EVT_MENU, self.onRollback, id = self.ID_ROLLBACK)
        self.Bind (wx.EVT_MENU, self.onCommit, id = self.ID_COMMIT)
        self.Bind (wx.EVT_MENU, self.onRelatorio, id = self.ID_RELATORIO)
        self.Bind (wx.EVT_MENU, self.onSelectsEspecificos, id = self.ID_SELECTS_ESPECIFICOS)

        # Atalhos do teclado
        atalhos = wx.AcceleratorTable ([
            (wx.ACCEL_CTRL, ord ('Z'), self.ID_ROLLBACK),
            (wx.ACCEL_CTRL, ord ('S'), self.ID_COMMIT),
        ])
        self.SetAcceleratorTable (atalhos)

        # abre a tela e troca o ícone
        self.Show ()
        self.icon = wx.Icon ('cavalo.png')
        self.SetIcon (self.icon)

        # conecta com o banco de dados
        self.db = dbManager.getDbManager ()
        try:
            self.db.connect ()
            self.SetStatusText ('Conectado')
        except Exception as e:
            wx.MessageBox (str (e), "Erro de conexão", wx.CENTRE | wx.ICON_ERROR | wx.OK)
            self.Close ()
            return

        self.insertPanel = insertPanel (self, self.ID_INSERT, size = self.panelSize)
        self.insertPanel.Show (False)
        self.relatorioPanel = relatorioPanel (self, self.ID_RELATORIO, size = self.panelSize)
        self.relatorioPanel.Show (False)
        self.selectsEspecificosPanel = selectsEspecificosPanel (self, self.ID_SELECTS_ESPECIFICOS, size = self.panelSize)
        self.selectsEspecificosPanel.Show (False)
        self.selectPanel = selectPanel (self, self.ID_SELECT, size = self.panelSize)

        self.current = self.selectPanel
Example #4
0
    def __init__ (self, parent, id, position, size, tabela, obs = {}):
        """Ctor. 'obs' é um dicionário que mostra algumas observações sobre
        alguns campos (por nome), como por exemplo CONSTRAINTs de vários tipos.

        Observações possíveis (a partir do tipo/valor):
            'ignore' - ignora campo
            (tupla) - enum, lista de valores fixos (bom pra quando tem CHECK IN)
        """
        wx.Panel.__init__ (self, parent, id, position, size)
        self.tabela = tabela
        self.db = dbManager.getDbManager ()
        colunas = self.db.getTableInfo (tabela)
        #print colunas

        self.campos = []

        sizer = wx.BoxSizer (wx.VERTICAL)
        self.SetSizer (sizer)
        # primeira coisa (se tiver), põe as opções de FKs
        if obs.get ('fks'):
            # nossa lista de campos dependentes de FK
            self.fkCtrlList = []
            self.fks = obs['fks']
            self.fkChoices = []
            for i, fk in enumerate (self.fks):
                # descobre quais são as possíveis fks, e mostra pa nóis
                txt = wx.StaticText (self, wx.ID_ANY, 'FK ' + fk.descricao)
                chaves = fk.getKeys ()
                ctrl = wx.Choice (self, id = self.ID_FK + i, choices = chaves)
                self.fkChoices.append (ctrl)
                # e adiciona no BoxSizer
                hbox = wx.BoxSizer (wx.HORIZONTAL)
                hbox.Add (txt, flag = wx.CENTER | wx.RIGHT, border = 10)
                hbox.Add (ctrl, proportion = 1)
                sizer.Add (hbox, flag = wx.EXPAND)
                # adiciona uma posição no fkCtrls
                self.fkCtrlList.append ([])
                self.Bind (wx.EVT_CHOICE, self.atualizaFks, id = self.ID_FK + i)

        for c in colunas:
            observacao = obs.get (c[0])
            # Nada de ignorar, comportamento básico: "Label [ctrl]"
            if observacao != 'ignore':
                txt = wx.StaticText (self, wx.ID_ANY, dbManager.getColunaBonita (c[0]) +
                        (observacao == 'seq' and ' (seq)' or ''))
                ## Cada tipo de dados pede um input diferente, digo bora ##
                # Número: IntCtrl, com máximo e mínimo
                if c[1] is cx_Oracle.NUMBER:
                    if observacao == 'seq':
                        ctrl = sequenceCtrl (self, tabela = tabela)
                    else:
                        ctrl = IntCtrl (self, min = 0, max = c[4] and 10 ** c[4] or None)
                # Data: DatePickerCtrl, pq né
                elif c[1] is cx_Oracle.DATETIME:
                    ctrl = wx.DatePickerCtrl (self)
                # Enum (CHAR/VARCHAR2 com CHECK): Choice com as possibilidades
                elif type (observacao) is tuple:
                    ctrl = wx.Choice (self, choices = observacao)
                    ctrl.SetSelection (0)
                # String (CHAR/VARCHAR2): TextCtrl
                else:
                    ctrl = wx.TextCtrl (self)

                # FKs: salva o Ctrl na lista de Ctrls das FKs
                if type (observacao) is int:
                    # salva o Ctrl, pra que possamos completar quando as FKs
                    # forem selecionadas
                    self.fkCtrlList[observacao].append (ctrl)

                # adiciona o "Label [ctrl]" no BoxSizer, pra ficar tudo bonitão
                hbox = wx.BoxSizer (wx.HORIZONTAL)
                hbox.Add (txt, flag = wx.CENTER | wx.RIGHT, border = 10)
                hbox.Add (ctrl, proportion = 1)
                sizer.Add (hbox, flag = wx.EXPAND)
                # salva na lista, pra podermos pegar depois
                self.campos.append ((c[0], ctrl))

        # nosso botão de inserir tupla
        addButton = wx.Button (self, self.ID_INSERT, label = 'Inserir')
        sizer.Add ((-1, 20))
        sizer.Add (addButton, flag = wx.ALIGN_CENTER)
        self.Bind (wx.EVT_BUTTON, self.insere, id = self.ID_INSERT)
Example #5
0
 def onRel2 (self, event):
     """Botão de relatório 2"""
     db = dbManager.getDbManager ()
     saida = db.procedure ('relatorios.gera_relatorio2', [self.rel2.GetString (self.rel2.GetCurrentSelection ())])
     self.msgBox.SetValue (saida)
Example #6
0
 def onRel1 (self, event):
     """Botão de relatório 1"""
     db = dbManager.getDbManager ()
     saida = db.procedure ('relatorios.gera_relatorio', [self.rel1inicial.GetValue (),
             self.rel1final.GetValue ()])
     self.msgBox.SetValue (saida)
Example #7
0
 def __init__ (self, parent, id = wx.ID_ANY, position = wx.DefaultPosition, size = wx.DefaultSize):
     wx.ListCtrl.__init__ (self, parent, id, position, size, wx.LC_REPORT | wx.LC_VIRTUAL)
     self.db = dbManager.getDbManager ()
     self.ultimoClique = None