~opensynergy/os.cases/main

« back to all changes in this revision

Viewing changes to Cases/CasesVisual.py

  • Committer: Sebastian Żurek
  • Date: 2008-07-10 22:26:52 UTC
  • Revision ID: sebzur@gmail.com-20080710222652-dy7ikel1wsp2lvaa
Initial licenseless import. The OpenSource license will be added soon

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
import wx
 
4
import  Synergy.Visual as Visual
 
5
from . import Logo
 
6
import wx.lib.pubsub as pubsub
 
7
from Windows import Dialogs
 
8
from Synergy import Exceptions
 
9
 
 
10
class CasesVisual(Visual.Visual):
 
11
    def __init__(self,*args,**kwargs):
 
12
        super(CasesVisual,self).__init__(*args,**kwargs)
 
13
        self.loggedUser=None
 
14
 
 
15
    def _Subscribe(self):
 
16
        super(CasesVisual,self)._Subscribe()
 
17
        pubsub.Publisher().subscribe(self.OnDialogEvent, "Cases.Events.Dialog")
 
18
        pubsub.Publisher().subscribe(self.OnEvent, "Users.Events")
 
19
 
 
20
 
 
21
    def OnDialogEvent(self,message):
 
22
        if hasattr(self,message.data[0]):
 
23
            getattr(self,message.data[0])(*message.data[1:])
 
24
 
 
25
 
 
26
    def Login(self,data):
 
27
        self.loggedUser=data[0]
 
28
            
 
29
 
 
30
    def NewCaseDialog(self,*args,**kwargs):
 
31
        dlg=Dialogs.CasesDialog(self._model)            
 
32
        if dlg.ShowModal() == wx.ID_OK:
 
33
            data= dlg.GetData()
 
34
            dlg.Destroy()
 
35
            try:
 
36
                self._model.InsertCase(data)
 
37
            except Exceptions.DatabaseError,error:                              
 
38
                wiad=u"Pojawił się nieoczekiwany problem z wykoniem zapytania SQL. Szczegóły błędu:\n\n"
 
39
                dlg2=wx.MessageDialog(None,wiad+error.message,u"Problem z bazą danych",wx.OK|wx.ICON_ERROR)
 
40
                dlg2.ShowModal()
 
41
                dlg2.Destroy()
 
42
        else:
 
43
            dlg.Destroy()
 
44
 
 
45
    def NewActionDialog(self,*args,**kwargs):
 
46
        dlg=Dialogs.ActionDialog(self._model)           
 
47
        if dlg.ShowModal() == wx.ID_OK:
 
48
            data= dlg.GetData()
 
49
            dlg.Destroy()
 
50
            try:
 
51
                data['user_id']=self.loggedUser
 
52
                self._model.InsertAction(data)
 
53
            except Exceptions.DatabaseError,error:                              
 
54
                wiad=u"Pojawił się nieoczekiwany problem z wykoniem zapytania SQL. Szczegóły błędu:\n\n"
 
55
                dlg2=wx.MessageDialog(None,wiad+error.message,u"Problem z bazą danych",wx.OK|wx.ICON_ERROR)
 
56
                dlg2.ShowModal()
 
57
                dlg2.Destroy()
 
58
        else:
 
59
            dlg.Destroy()
 
60
 
 
61
 
 
62
    def UpdateAction(self,*args,**kwargs):
 
63
        dlg=Dialogs.UpdateActionDialog(args[0],self._model)             
 
64
        if dlg.ShowModal() == wx.ID_OK:
 
65
            data= dlg.GetData()
 
66
            dlg.Destroy()
 
67
            try:
 
68
                self._model.UpdateAction(data,{'aid':args[0]})
 
69
            except Exceptions.DatabaseError,error:                              
 
70
                wiad=u"Pojawił się nieoczekiwany problem z wykoniem zapytania SQL. Szczegóły błędu:\n\n"
 
71
                dlg2=wx.MessageDialog(None,wiad+error.message,u"Problem z bazą danych",wx.OK|wx.ICON_ERROR)
 
72
                dlg2.ShowModal()
 
73
                dlg2.Destroy()
 
74
        else:
 
75
            dlg.Destroy()
 
76
 
 
77
 
 
78
    def NewTermDialog(self,*args,**kwargs):
 
79
        dlg=Dialogs.TermDialog(self._model)             
 
80
        if dlg.ShowModal() == wx.ID_OK:
 
81
            data= dlg.GetData()
 
82
            dlg.Destroy()
 
83
            try:
 
84
                data['user_id']=self.loggedUser
 
85
                self._model.InsertTerm(data)
 
86
            except Exceptions.DatabaseError,error:                              
 
87
                wiad=u"Pojawił się nieoczekiwany problem z wykoniem zapytania SQL. Szczegóły błędu:\n\n"
 
88
                dlg2=wx.MessageDialog(None,wiad+error.message,u"Problem z bazą danych",wx.OK|wx.ICON_ERROR)
 
89
                dlg2.ShowModal()
 
90
                dlg2.Destroy()
 
91
        else:
 
92
            dlg.Destroy()
 
93
 
 
94
 
 
95
    def UpdateTerm(self,*args,**kwargs):
 
96
        dlg=Dialogs.UpdateTermDialog(args[0],self._model)               
 
97
        if dlg.ShowModal() == wx.ID_OK:
 
98
            data= dlg.GetData()
 
99
            dlg.Destroy()
 
100
            try:
 
101
                self._model.UpdateTerm(data,{'tid':args[0]})
 
102
            except Exceptions.DatabaseError,error:                              
 
103
                wiad=u"Pojawił się nieoczekiwany problem z wykoniem zapytania SQL. Szczegóły błędu:\n\n"
 
104
                dlg2=wx.MessageDialog(None,wiad+error.message,u"Problem z bazą danych",wx.OK|wx.ICON_ERROR)
 
105
                dlg2.ShowModal()
 
106
                dlg2.Destroy()
 
107
        else:
 
108
            dlg.Destroy()
 
109
 
 
110
 
 
111
 
 
112
    def UpdateCase(self,*args,**kwargs):
 
113
        dlg=Dialogs.UpdateCaseDialog(args[0],self._model)               
 
114
        if dlg.ShowModal() == wx.ID_OK:
 
115
            data= dlg.GetData()
 
116
            dlg.Destroy()
 
117
            try:
 
118
                self._model.UpdateCase(data,{'cid':args[0]})
 
119
            except Exceptions.DatabaseError,error:                              
 
120
                wiad=u"Pojawił się nieoczekiwany problem z wykoniem zapytania SQL. Szczegóły błędu:\n\n"
 
121
                dlg2=wx.MessageDialog(None,wiad+error.message,u"Problem z bazą danych",wx.OK|wx.ICON_ERROR)
 
122
                dlg2.ShowModal()
 
123
                dlg2.Destroy()
 
124
        else:
 
125
            dlg.Destroy()