/[H8]/trunk/h8server/h8serverDlg.cpp
ViewVC logotype

Annotation of /trunk/h8server/h8serverDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 103 - (hide annotations) (download)
Sun May 27 13:32:36 2007 UTC (17 years ago) by kevin
File size: 7839 byte(s)
case 0 problem
1 kevin 87 // h8serverDlg.cpp : implementation file
2     //
3    
4     #include "stdafx.h"
5     #include "h8server.h"
6     #include "h8serverDlg.h"
7     #include "ConfigFile.h"
8     #include "MySQLLayer.h"
9     #include "Containers.h"
10     #include <vector>
11    
12     #ifdef _DEBUG
13     #define new DEBUG_NEW
14     #endif
15    
16    
17     // CAboutDlg dialog used for App About
18    
19     class CAboutDlg : public CDialog
20     {
21     public:
22     CAboutDlg();
23    
24     // Dialog Data
25     enum { IDD = IDD_ABOUTBOX };
26    
27     protected:
28     virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
29    
30     // Implementation
31     protected:
32     DECLARE_MESSAGE_MAP()
33     };
34    
35     class mysocket : public CSocket
36     {
37     public:
38     virtual void OnReceive(int nErrorCode);
39     virtual void OnAccept(int nErrorCode);
40     };
41     mysocket sock;
42     mysocket worksock;
43     CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
44     {
45     }
46    
47     void CAboutDlg::DoDataExchange(CDataExchange* pDX)
48     {
49     CDialog::DoDataExchange(pDX);
50     }
51    
52     BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
53     END_MESSAGE_MAP()
54    
55    
56     // Ch8serverDlg dialog
57    
58    
59    
60     Ch8serverDlg::Ch8serverDlg(CWnd* pParent /*=NULL*/)
61     : CDialog(Ch8serverDlg::IDD, pParent)
62     {
63     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
64     }
65    
66     void Ch8serverDlg::DoDataExchange(CDataExchange* pDX)
67     {
68     CDialog::DoDataExchange(pDX);
69     }
70    
71     BEGIN_MESSAGE_MAP(Ch8serverDlg, CDialog)
72     ON_WM_SYSCOMMAND()
73     ON_WM_PAINT()
74     ON_WM_QUERYDRAGICON()
75     //}}AFX_MSG_MAP
76     END_MESSAGE_MAP()
77    
78    
79     // Ch8serverDlg message handlers
80    
81     BOOL Ch8serverDlg::OnInitDialog()
82     {
83     CDialog::OnInitDialog();
84    
85     // Add "About..." menu item to system menu.
86    
87     // IDM_ABOUTBOX must be in the system command range.
88     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
89     ASSERT(IDM_ABOUTBOX < 0xF000);
90    
91     CMenu* pSysMenu = GetSystemMenu(FALSE);
92     if (pSysMenu != NULL)
93     {
94     CString strAboutMenu;
95     strAboutMenu.LoadString(IDS_ABOUTBOX);
96     if (!strAboutMenu.IsEmpty())
97     {
98     pSysMenu->AppendMenu(MF_SEPARATOR);
99     pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
100     }
101     }
102    
103     // Set the icon for this dialog. The framework does this automatically
104     // when the application's main window is not a dialog
105     SetIcon(m_hIcon, TRUE); // Set big icon
106     SetIcon(m_hIcon, FALSE); // Set small icon
107    
108     // TODO: Add extra initialization here
109    
110     int listenPort = 4000;
111    
112     sock.Create(listenPort);
113     sock.Listen();
114    
115     ConfigFile config;
116     try {
117     config.Read();
118     } catch(...) {
119     MessageBox("Could not open config file");
120     OnOK();
121     return true;
122     }
123    
124     try {
125     DatabaseLayer *dbl = 0;
126     if (config.driver.MakeLower() == "mysql")
127     dbl = new MySQLLayer(config);
128     else {
129     CString tmp;
130     tmp.Format("Unsupported driver: %s", config.driver);
131     MessageBox(tmp);
132     OnOK();
133     }
134     CommonStorage::Instance()->setDBLayer(dbl);
135     } catch (CDBException *ex) {
136     MessageBox(CString("Could not establish connection to the database server\r\n") +
137     "Please contact your network administrator\r\n\r\n" +
138     "ODBC Returned the following message:\r\n" +
139     ex->m_strError);
140    
141     OnOK();
142     } catch (...) {
143     MessageBox("Unknown DB exception");
144     OnOK();
145     }
146     return TRUE; // return TRUE unless you set the focus to a control
147     }
148    
149     void Ch8serverDlg::OnSysCommand(UINT nID, LPARAM lParam)
150     {
151     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
152     {
153     CAboutDlg dlgAbout;
154     dlgAbout.DoModal();
155     }
156     else
157     {
158     CDialog::OnSysCommand(nID, lParam);
159     }
160     }
161    
162     // If you add a minimize button to your dialog, you will need the code below
163     // to draw the icon. For MFC applications using the document/view model,
164     // this is automatically done for you by the framework.
165    
166     void Ch8serverDlg::OnPaint()
167     {
168     if (IsIconic())
169     {
170     CPaintDC dc(this); // device context for painting
171    
172     SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
173    
174     // Center icon in client rectangle
175     int cxIcon = GetSystemMetrics(SM_CXICON);
176     int cyIcon = GetSystemMetrics(SM_CYICON);
177     CRect rect;
178     GetClientRect(&rect);
179     int x = (rect.Width() - cxIcon + 1) / 2;
180     int y = (rect.Height() - cyIcon + 1) / 2;
181    
182     // Draw the icon
183     dc.DrawIcon(x, y, m_hIcon);
184     }
185     else
186     {
187     CDialog::OnPaint();
188     }
189     }
190    
191     // The system calls this function to obtain the cursor to display while the user drags
192     // the minimized window.
193     HCURSOR Ch8serverDlg::OnQueryDragIcon()
194     {
195     return static_cast<HCURSOR>(m_hIcon);
196     }
197    
198     void mysocket::OnReceive(int nErrorCode)
199     {
200     // TODO: Add your specialized code here and/or call the base class
201     Ch8serverDlg* parent = (Ch8serverDlg*) AfxGetMainWnd();
202     char buffer[30];
203     char barcode[15];
204     int ack = 1;
205 kevin 100 CString senddata, termID, ssum, hellodata1, hellodata2;
206 kevin 87 unsigned char Output[30];
207     unsigned int price, isum, cash, bytte;
208     int status;
209 kevin 103 int intlogid;
210 kevin 87 unsigned char reqID;
211     log l;
212 kevin 100 translog tl;
213 kevin 87 Equipment eq;
214    
215     status = worksock.Receive(buffer,30);
216     if (status != SOCKET_ERROR) {
217    
218     switch(buffer[0])
219     {
220    
221     //Hello request
222     case '0':
223     //LOG SKAL LAVES NUUUUUUUUUUUUUUUUUUUUUUU
224     reqID = buffer[0];
225     termID = buffer[1];
226    
227     senddata.Format("%d", ack);
228     worksock.Send(senddata, senddata.GetLength(),0);
229 kevin 103 tl = CommonStorage::Instance()->getDBLayer()->Transaktionslog(termID,0);
230     intlogid = (atoi(tl.logID));
231 kevin 87 break;
232    
233     case '2':
234     //return sum
235     isum = atoi(l.sum);
236     isum = (isum*100);
237     Output[0] = ack;
238     Output[1] = 2;
239     Output[2] = isum >> 24;
240     Output[3] = isum >> 16;
241     Output[4] = isum >> 8;
242     Output[5] = isum;
243     ssum = Output;
244     worksock.Send(ssum, ssum.GetLength(),0);
245     break;
246     case '3':
247     //byttepenge
248     cash = buffer[1] << 24 | buffer[2] << 16 | buffer[3] << 8 | buffer[4];
249     isum = atoi(l.sum);
250     isum = (isum*100);
251     bytte = isum - cash;
252     Output[0] = ack;
253     Output[1] = 3;
254     Output[2] = bytte >> 24;
255     Output[3] = bytte >> 16;
256     Output[4] = bytte >> 8;
257     Output[5] = bytte;
258     ssum = Output;
259     worksock.Send(ssum, ssum.GetLength(),0);
260     l.logID = "0";
261     break;
262     case '4':
263     //annulér sidste scanning
264     CommonStorage::Instance()->getDBLayer()->Deletelastentry(l.logID, l.barcode);
265     Output[0] = ack;
266     senddata = Output;
267     worksock.Send(senddata,senddata.GetLength(),0);
268     break;
269    
270     case '5':
271     //annulér hele sessionen
272     CommonStorage::Instance()->getDBLayer()->Deletesession(l.logID);
273     Output[0] = ack;
274     senddata = Output;
275     worksock.Send(senddata,senddata.GetLength(),0);
276     break;
277     case '6':
278     //Farvel
279     Output[0] = ack;
280     senddata = Output;
281     worksock.Send(senddata,senddata.GetLength(),0);
282     worksock.Close();
283     break;
284    
285     }
286    
287 kevin 103 //getvareinfo og sendvareinfo
288     if(status < 18 && status > 10)
289     {
290     reqID = buffer[0];
291     unsigned char antal = buffer[1];
292     unsigned char length = buffer[2];
293     int test;
294     if(length == 'A')
295     {
296     test = 10;
297     }
298    
299     //l.logID = "5";
300    
301     for (int i=3; i < (3+test); i++){
302     barcode[i-3] = buffer[i];
303     }
304     barcode[test] = '\0';
305     eq = CommonStorage::Instance()->getDBLayer()->GetEquipment(barcode,0,0);
306     price = (atoi(eq.price)*100);
307     Output[0] = 1;
308     Output[1] = 1;
309     Output[2] = price >> 24;
310     Output[3] = price >> 16;
311     Output[4] = price >> 8;
312     Output[5] = price;
313     Output[6] = eq.description.GetLength();
314     int outputlength;
315     outputlength = Output[6];
316     for (int i = 7; i < (7+outputlength); i++){
317     Output[i] = eq.description[i-7];
318     }
319     Output[outputlength] = '\0';
320    
321     worksock.Send(Output,7);
322    
323     //LOG SKAL LAVES NUUUUUUUUUUUUUUUUUUUUUUU
324     if(intlogid > 0)
325     {
326     CString logantal;
327     logantal.Format("%d",antal-48);
328     CommonStorage::Instance()->getDBLayer()->TransaktionsEnhed(tl.logID, eq.price, barcode,logantal);
329     }
330 kevin 87 }
331    
332 kevin 103 }
333    
334 kevin 87 CSocket::OnReceive(nErrorCode);
335     }
336    
337    
338     void mysocket::OnAccept(int nErrorCode)
339     {
340     // TODO: Add your specialized code here and/or call the base class
341     sock.Accept(worksock);
342     CSocket::OnAccept(nErrorCode);
343     }

  ViewVC Help
Powered by ViewVC 1.1.20