/[H9]/trunk/FlisServer/FlisServerDlg.cpp
ViewVC logotype

Annotation of /trunk/FlisServer/FlisServerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 138 - (hide annotations) (download)
Mon Dec 3 14:40:44 2007 UTC (16 years, 5 months ago) by kevin
File size: 17337 byte(s)
updated server software after test with torben
1 kevin 70 // FlisServerDlg.cpp : implementation file
2     //
3    
4     #include "stdafx.h"
5     #include "FlisServer.h"
6     #include "FlisServerDlg.h"
7     #include <vector>
8 kevin 121 #include ".\flisserverdlg.h"
9 kevin 70
10     #ifdef _DEBUG
11     #define new DEBUG_NEW
12     #endif
13    
14    
15     // CAboutDlg dialog used for App About
16    
17     class CAboutDlg : public CDialog
18     {
19     public:
20     CAboutDlg();
21    
22     // Dialog Data
23     enum { IDD = IDD_ABOUTBOX };
24    
25     protected:
26     virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
27    
28     // Implementation
29     protected:
30     DECLARE_MESSAGE_MAP()
31     };
32    
33     CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
34     {
35     }
36    
37     void CAboutDlg::DoDataExchange(CDataExchange* pDX)
38     {
39     CDialog::DoDataExchange(pDX);
40     }
41    
42     BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
43     END_MESSAGE_MAP()
44    
45    
46     // CFlisServerDlg dialog
47    
48    
49    
50     CFlisServerDlg::CFlisServerDlg(CWnd* pParent /*=NULL*/)
51     : CDialog(CFlisServerDlg::IDD, pParent)
52     {
53     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
54     }
55    
56     void CFlisServerDlg::DoDataExchange(CDataExchange* pDX)
57     {
58     CDialog::DoDataExchange(pDX);
59     DDX_Control(pDX, IDC_Textwindow, m_Textwindow);
60     }
61    
62     BEGIN_MESSAGE_MAP(CFlisServerDlg, CDialog)
63     ON_WM_SYSCOMMAND()
64     ON_WM_PAINT()
65     ON_WM_QUERYDRAGICON()
66     //}}AFX_MSG_MAP
67 kevin 103 ON_BN_CLICKED(IDCLOSE, OnBnClickedClose)
68 kevin 105 ON_BN_CLICKED(IDC_GSMPIN, OnBnClickedGsmpin)
69 kevin 121 ON_BN_CLICKED(IDC_Start, OnBnClickedStart)
70 kevin 70 END_MESSAGE_MAP()
71    
72    
73     // CFlisServerDlg message handlers
74    
75     BOOL CFlisServerDlg::OnInitDialog()
76     {
77     CDialog::OnInitDialog();
78    
79     // Add "About..." menu item to system menu.
80    
81     // IDM_ABOUTBOX must be in the system command range.
82     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
83     ASSERT(IDM_ABOUTBOX < 0xF000);
84    
85     CMenu* pSysMenu = GetSystemMenu(FALSE);
86     if (pSysMenu != NULL)
87     {
88     CString strAboutMenu;
89     strAboutMenu.LoadString(IDS_ABOUTBOX);
90     if (!strAboutMenu.IsEmpty())
91     {
92     pSysMenu->AppendMenu(MF_SEPARATOR);
93     pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
94     }
95     }
96    
97     // Set the icon for this dialog. The framework does this automatically
98     // when the application's main window is not a dialog
99     SetIcon(m_hIcon, TRUE); // Set big icon
100     SetIcon(m_hIcon, FALSE); // Set small icon
101    
102     // TODO: Add extra initialization here
103     StartSerial();
104 kevin 81 DBConnect();
105 kevin 113 ResetSms = 0;
106 kevin 70
107     return TRUE; // return TRUE unless you set the focus to a control
108     }
109    
110     void CFlisServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
111     {
112     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
113     {
114     CAboutDlg dlgAbout;
115     dlgAbout.DoModal();
116     }
117     else
118     {
119     CDialog::OnSysCommand(nID, lParam);
120     }
121     }
122    
123     // If you add a minimize button to your dialog, you will need the code below
124     // to draw the icon. For MFC applications using the document/view model,
125     // this is automatically done for you by the framework.
126    
127     void CFlisServerDlg::OnPaint()
128     {
129     if (IsIconic())
130     {
131     CPaintDC dc(this); // device context for painting
132    
133     SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
134    
135     // Center icon in client rectangle
136     int cxIcon = GetSystemMetrics(SM_CXICON);
137     int cyIcon = GetSystemMetrics(SM_CYICON);
138     CRect rect;
139     GetClientRect(&rect);
140     int x = (rect.Width() - cxIcon + 1) / 2;
141     int y = (rect.Height() - cyIcon + 1) / 2;
142    
143     // Draw the icon
144     dc.DrawIcon(x, y, m_hIcon);
145     }
146     else
147     {
148     CDialog::OnPaint();
149     }
150     }
151    
152     // The system calls this function to obtain the cursor to display while the user drags
153     // the minimized window.
154     HCURSOR CFlisServerDlg::OnQueryDragIcon()
155     {
156     return static_cast<HCURSOR>(m_hIcon);
157     }
158     int CFlisServerDlg::StartSerial(void)
159     {
160 kevin 136
161 kevin 70 int Baud;
162    
163 kevin 136 ConfigFile config;
164     try {
165     config.ReadSettings();
166     } catch(...) {
167     MessageBox("Could not open config file");
168     OnOK();
169     return true;
170     }
171    
172 kevin 70 Baud = 1200;
173 kevin 132 if( Serial.isOpen() )
174     {
175 kevin 136 try
176     {
177     Serial.close();
178     Serial.open( config.comport, Baud );
179     }
180     catch (exception* e)
181     {
182     MessageBox( "Serial.open() exception" );
183     return 0;
184     }
185 kevin 70 }
186 kevin 136 else
187 kevin 132 {
188 kevin 136 try
189     {
190     Serial.open( config.comport, Baud );
191     }
192     catch (exception* e)
193     {
194     MessageBox( "Serial.open() exception 2" );
195     return 0;
196     }
197 kevin 70 }
198 kevin 136
199 kevin 70
200     return 0;
201     }
202     std::vector<unsigned char> CFlisServerDlg::readFrame()
203     {
204     std::vector<unsigned char> buf;
205     while(Serial.getComstat().cbInQue > 0)
206     {
207 kevin 132 unsigned char data = Serial.readByte();
208 kevin 70
209 kevin 132 buf.push_back(data);
210 kevin 70 }
211     return buf;
212     }
213    
214     void CFlisServerDlg::writeFrame(std::vector<unsigned char> data)
215     {
216     for (int i=0; i<data.size(); i++)
217     {
218     Serial.writeByte( data[i] );
219     Sleep(5);
220     }
221     Serial.writeByte(0x0D);
222     Sleep(100);
223    
224     }
225 kevin 110 void CFlisServerDlg::SetPin()
226 kevin 70 {
227 kevin 81 CString tekst;
228 kevin 70 std::vector<unsigned char> data;
229     data.push_back('a');
230     data.push_back('t');
231     data.push_back('+');
232     data.push_back('c');
233     data.push_back('p');
234     data.push_back('i');
235     data.push_back('n');
236     data.push_back('=');
237     data.push_back('2');
238     data.push_back('5');
239     data.push_back('9');
240     data.push_back('5');
241    
242     writeFrame(data);
243     }
244     void CFlisServerDlg::SendSmsData(std::vector<unsigned char> data)
245 kevin 103 {
246    
247 kevin 70 for (int i=0; i<data.size(); i++)
248     {
249     Serial.writeByte( data[i] );
250     Sleep(5);
251     }
252     Serial.writeByte(0x1A);
253 kevin 105 Sleep(3000);
254     if(Serial.getComstat().cbInQue > 0)
255     {
256     CString tekst;
257     std::vector<unsigned char> answer = readFrame();
258     Sleep(50);
259 kevin 136
260     for (int i=0; i<answer.size(); i++)
261 kevin 105 {
262 kevin 136 if ((answer[i] != 0x0A) && (answer[i] != 0x0D))
263 kevin 105 {
264 kevin 136 tekst.AppendChar(answer[i]);
265 kevin 105 }
266     }
267 kevin 136 AppendText(tekst);
268 kevin 105 }
269 kevin 70
270     }
271 kevin 136 void CFlisServerDlg::SendSmsHead(std::vector<unsigned char> tlfnr)
272 kevin 70 {
273 kevin 103 vector<unsigned char> atcommand;
274     atcommand.push_back('a');
275     atcommand.push_back('t');
276     atcommand.push_back('+');
277     atcommand.push_back('c');
278     atcommand.push_back('m');
279     atcommand.push_back('g');
280     atcommand.push_back('s');
281     atcommand.push_back('=');
282     atcommand.push_back('"');
283     int s = (atcommand.size() -1 );
284    
285     for (int i=0; i<(atcommand.size()); i++)
286     {
287     Serial.writeByte( atcommand[i] );
288     Sleep(5);
289     }
290    
291 kevin 136 for (int i=0; i<tlfnr.size(); i++)
292 kevin 70 {
293 kevin 136 Serial.writeByte( tlfnr[i] );
294 kevin 70 Sleep(5);
295     }
296 kevin 103 Serial.writeByte(atcommand[s]);
297 kevin 70 Serial.writeByte(0x0D);
298 kevin 103 Sleep(250);
299 kevin 70 }
300 kevin 81 void CFlisServerDlg::DBConnect()
301 kevin 70 {
302     CString dsn;
303 kevin 136 ConfigFile config;
304     try {
305     config.ReadSettings();
306     } catch(...) {
307     MessageBox("Could not open config file");
308     }
309    
310     dsn.Format("ODBC;Description=asd;DRIVER=PostgreSQL ANSI;SERVER=%s; uid=%s;password=%s;database=%s;sslmode=prefer",config.host,config.username, config.password, config.database);
311 kevin 103 db.OpenEx(dsn, CDatabase::noOdbcDialog);
312 kevin 81 }
313 kevin 136 vector<Commands> CFlisServerDlg::DBReadCommands(void)
314 kevin 81 {
315 kevin 103 vector<Commands> buffer;
316 kevin 81
317 kevin 103 CString SQL, IDnr, CommandID, InstallationsID;
318 kevin 136 SQL = "select id,date_trunc('second', created) as created,executed,commandid,installationid from command WHERE executed IS NULL ORDER BY created ASC LIMIT 1;";
319 kevin 103 CRecordset rs(&db);
320     rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
321     if (rs.GetRecordCount()>0)
322     {
323     rs.MoveFirst();
324 kevin 130
325 kevin 136 Commands Mycom;
326     rs.GetFieldValue((short)0, IDnr);
327     rs.GetFieldValue(3, CommandID);
328     rs.GetFieldValue(4, InstallationsID);
329    
330     Mycom.IDnr = IDnr;
331     Mycom.CommandID = CommandID;
332     Mycom.InstallationsID = InstallationsID;
333 kevin 103
334 kevin 136 buffer.push_back(Mycom);
335     rs.MoveNext();
336    
337 kevin 103 }
338     rs.Close();
339     return buffer;
340 kevin 81 }
341     void CFlisServerDlg::ReadSms()
342     {
343     CString tekst, oldtekst;
344 kevin 136 Sleep(950); //Holder en pause for at lade hele sms'en komme ind i serial køen.
345 kevin 81 if(Serial.getComstat().cbInQue > 0)
346     {
347     std::vector<unsigned char> answer = readFrame();
348 kevin 138 Sleep(50);
349 kevin 136
350 kevin 81 for (int i=0; i<answer.size(); i++)
351     {
352 kevin 136 if ((answer[i] != 0x0A) && (answer[i] != 0x0D))
353 kevin 81 {
354 kevin 136 tekst.AppendChar(answer[i]);
355 kevin 81 }
356     }
357    
358 kevin 136 AppendText(tekst);
359 kevin 81 SmsSplit(tekst);
360     }
361     }
362     void CFlisServerDlg::SmsSplit(CString data)
363     {
364     CString FyrData, TlfNr, SmsCount, Temper, Flamme, Flis, FremFejl, PowerFail, oldtekst;
365     char CharData[150];
366     strcpy(CharData,data);
367 kevin 136 TlfNr = data.Mid(24,8);
368 kevin 138 FyrData = data.Mid(57,data.GetLength()-59);
369 kevin 81 FyrData.Append(":");
370    
371     SmsCount = Splitter(FyrData);
372     Temper = Splitter(FyrData);
373     Flamme = Splitter(FyrData);
374     Flis = Splitter(FyrData);
375     FremFejl = Splitter(FyrData);
376     PowerFail = Splitter(FyrData);
377 kevin 132
378     CString SQL, Textwindow, InstallNR;
379     SQL.Format("select ID from installation where installationphonenr=%s",TlfNr);
380    
381     CRecordset rs(&db);
382     rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
383     if (rs.GetRecordCount()>0)
384     {
385     rs.MoveFirst();
386     rs.GetFieldValue((short)0,InstallNR);
387     }
388     rs.Close();
389    
390     SQL.Format("insert into logtable (logtime,temperature,flamedetector,solidfuelempty,conveyorerror,powerfailure,messagenr,installationnr) Values (now(),%s,'%s','%s','%s','%s',%s,%s)",Temper, Flamme, Flis, FremFejl, PowerFail, SmsCount,InstallNR);
391 kevin 138 try
392     {
393 kevin 132 db.ExecuteSQL(SQL);
394 kevin 138 }
395     catch(CDBException* e)
396     {
397     MessageBox(e->m_strError);
398     }
399 kevin 136 AppendText("Sms added to Log");
400 kevin 132 Sleep(150);
401 kevin 81 }
402     CString CFlisServerDlg::Splitter(CString& fyrdata)
403     {
404     CString Output;
405    
406     int pos = fyrdata.Find(':',0);
407     if (pos != -1)
408     {
409     Output = fyrdata.Left(pos);
410     fyrdata = fyrdata.Right( fyrdata.GetLength() - pos -1);
411     }
412     return Output;
413 kevin 103 }
414     void CFlisServerDlg::OnBnClickedClose()
415     {
416     // TODO: Add your control notification handler code here
417 kevin 113 continueThread = 0;
418 kevin 132 DeleteSms();
419 kevin 113
420     Sleep(500);
421 kevin 103 if( Serial.isOpen() )
422     {
423     Serial.close();
424     }
425    
426     if(db.IsOpen())
427     {
428 kevin 132 db.Close();
429 kevin 103 }
430 kevin 113
431 kevin 103 OnOK();
432 kevin 113
433 kevin 103 }
434 kevin 105
435     void CFlisServerDlg::OnBnClickedGsmpin()
436     {
437     // TODO: Add your control notification handler code here
438 kevin 132 m_Textwindow.SetWindowText("Indsætter Pinkode, efterfuldt af 60sec pause");
439     UpdateWindow();
440 kevin 105 SetPin();
441 kevin 132 Sleep(50000);
442    
443     while (Serial.getComstat().cbInQue > 0)
444     {
445     Serial.readByte(); //Flush the incoming queue
446     }
447    
448 kevin 121 OnBnClickedStart();
449 kevin 105 }
450 kevin 110 void CFlisServerDlg::DeleteSms()
451     {
452     vector<unsigned char> atcommand;
453     atcommand.push_back('a');
454     atcommand.push_back('t');
455     atcommand.push_back('+');
456     atcommand.push_back('c');
457     atcommand.push_back('m');
458     atcommand.push_back('g');
459     atcommand.push_back('d');
460     atcommand.push_back('=');
461     atcommand.push_back('1');
462     atcommand.push_back(',');
463     atcommand.push_back('3');
464    
465     writeFrame(atcommand);
466     Sleep(500);
467     }
468 kevin 136 UINT threadWrapper(LPVOID thread)
469 kevin 110 {
470     CFlisServerDlg *t = (CFlisServerDlg*) thread;
471     t->runthread();
472     return 0;
473     }
474    
475     void CFlisServerDlg::startthread()
476     {
477     AfxBeginThread(threadWrapper, (LPVOID) this);
478     }
479    
480     void CFlisServerDlg::runthread()
481     {
482 kevin 113 while (continueThread != 0)
483 kevin 110 {
484     Reader();
485     }
486     }
487     void CFlisServerDlg::Reader()
488     {
489 kevin 113 if(Serial.getComstat().cbInQue > 0)
490 kevin 110 {
491 kevin 113 Sleep(250);
492 kevin 110 std::vector<unsigned char> answer = readFrame();
493     Sleep(500);
494     CString tekst, oldtekst;
495     int lol;
496    
497     for (int i=0; i<answer.size(); i++)
498     {
499 kevin 136 if ((answer[i] != 0x0A) && (answer[i] != 0x0D))
500 kevin 110 {
501 kevin 136 tekst.AppendChar(answer[i]);
502 kevin 110 }
503     }
504     tekst.Append(":");
505    
506     CString command;
507     bool plus;
508     int pos = tekst.Find('+',0);
509     if (pos != -1)
510     {
511     plus = true;
512     tekst = tekst.Right( tekst.GetLength() - pos -1);
513     pos = tekst.Find(':');
514     command = tekst.Left(pos);
515     tekst = tekst.Right( tekst.GetLength() - pos -1);
516     }
517    
518    
519 kevin 138 if(tekst.MakeLower() == "ok")
520 kevin 110 {
521 kevin 136 AppendText("OK tekst modtaget");
522 kevin 110 }
523 kevin 138 else if (tekst.MakeLower() == "error")
524 kevin 110 {
525 kevin 136 CString send;
526     send.Append("error tekst");
527     send.Append("\r\n");
528     send.Append(tekst);
529     AppendText(send);
530 kevin 110 }
531 kevin 136 else if (plus == true)
532 kevin 110 {
533 kevin 138 if (command.MakeLower() == "cmti")
534 kevin 110 {
535 kevin 113 CString smscount, oldteskst;
536 kevin 110 int pos = tekst.Find(',',0);
537     if (pos != -1)
538     {
539     smscount = tekst.Right( tekst.GetLength() - pos -1);
540     smscount.Remove(':');
541     ResetSms++;
542     }
543     ////////////////Read sms ting//////////////////
544     std::vector<unsigned char> data;
545     data.push_back('a');
546     data.push_back('t');
547     data.push_back('+');
548     data.push_back('c');
549     data.push_back('m');
550     data.push_back('g');
551     data.push_back('r');
552     data.push_back('=');
553    
554     for (int i=0; i< smscount.GetLength(); i++)
555     {
556     data.push_back(smscount[i]);
557     }
558 kevin 132 m_Textwindow.GetWindowText(oldteskst);
559     oldteskst.Append("\r\n");
560 kevin 113 for (int i=0; i<data.size();i++)
561     {
562 kevin 132 oldteskst.AppendChar(data[i]);
563 kevin 113 }
564     m_Textwindow.SetWindowText(oldteskst);
565 kevin 110 writeFrame(data);
566 kevin 113 Sleep(200);
567 kevin 110 ReadSms();
568 kevin 121 ResetSms++;
569 kevin 110
570     }
571 kevin 138 else if(command.MakeLower() == "wind")
572 kevin 113 {
573 kevin 136
574     CString send;
575     send.Append("Wind modtaget");
576     send.Append("\r\n");
577     send.Append(tekst);
578     AppendText(send);
579 kevin 113 }
580 kevin 110 }
581 kevin 132 else
582 kevin 110 {
583 kevin 136 CString send;
584     send.Append("Anden tekst end forventet");
585     send.Append("\r\n");
586     send.Append(tekst);
587     AppendText(send);
588 kevin 132 }
589     if(ResetSms == 20)
590     {
591 kevin 110 DeleteSms();
592 kevin 136 AppendText("Sms'er slettet da vi nåede grænsen");
593 kevin 110 }
594 kevin 113
595     }
596 kevin 136 if (continueThread == 1)
597 kevin 113 {
598 kevin 110
599 kevin 121 CString testdata, dataframe,testprint, sIDnr, sCommandID, sInstallationsID, sImei;
600 kevin 130 int commandtest = 0;
601     int iAll = 1;
602 kevin 113 std::vector<Commands> data;
603 kevin 136 data = DBReadCommands();
604 kevin 113 for (int i=0; i<data.size(); i++)
605     {
606 kevin 136 sIDnr = data[i].IDnr;
607     sCommandID = data[i].CommandID;
608 kevin 130 commandtest = atoi(data[i].CommandID);
609 kevin 138 sInstallationsID = "0";
610 kevin 130
611     if(commandtest > 1)
612     {
613 kevin 136 sInstallationsID = data[i].InstallationsID;
614 kevin 130 }
615 kevin 113 }
616 kevin 138
617 kevin 130 if (commandtest > 1)
618     {
619 kevin 132 iAll = 0;
620 kevin 130 }
621 kevin 113
622     if (sIDnr.GetLength() > 0)
623     {
624 kevin 136 SendConfig(sIDnr,sCommandID,sInstallationsID);
625 kevin 113 }
626     Sleep(500);
627 kevin 110 }
628 kevin 113 }
629 kevin 136 void CFlisServerDlg::SendConfig(CString IDnr,CString CommandID,CString InstallationsID)
630 kevin 113 {
631 kevin 130 CString ServerTlfNr;
632     int i = 0;
633 kevin 121 ServerTlfNr = "29860132";
634 kevin 113
635 kevin 130
636 kevin 113 std::vector<Installation> inst;
637     inst = DBReadPhone(InstallationsID);
638 kevin 130 while (i < inst.size())
639 kevin 113 {
640 kevin 130 CString TlfNr, Imei, updaterate;
641     TlfNr.Empty();
642     Imei.Empty();
643     updaterate.Empty();
644    
645 kevin 113 CString dataen = inst[i].InstPhoneNr;
646     TlfNr.Append(dataen);
647 kevin 121 CString Imeidata = inst[i].Imei;
648     Imei.Append(Imeidata);
649     CString updaterat = inst[i].Updaterate;
650     updaterate.Append(updaterat);
651 kevin 130 i++;
652    
653 kevin 113 vector<unsigned char> tlfnr;
654     for (int i=0; i<TlfNr.GetLength(); i++)
655     {
656     tlfnr.push_back(TlfNr[i]);
657     }
658 kevin 121
659     int calcimei;
660 kevin 130 __int64 buf;
661 kevin 113
662 kevin 121 buf = atof(Imei);
663    
664     calcimei = tversum(buf);
665    
666     Imei.Format("%d",calcimei);
667    
668 kevin 113 SendSmsHead(tlfnr);
669 kevin 130 Sleep(250);
670    
671 kevin 113 vector<unsigned char> smsdata;
672 kevin 121
673     for (int i=0; i<Imei.GetLength(); i++)
674     {
675     smsdata.push_back(Imei[i]);
676     }
677 kevin 113 smsdata.push_back(':');
678 kevin 121 for (int i=0; i<ServerTlfNr.GetLength(); i++)
679     {
680     smsdata.push_back(ServerTlfNr[i]);
681     }
682 kevin 113 smsdata.push_back(':');
683 kevin 121 for (int i=0; i<updaterate.GetLength(); i++)
684     {
685     smsdata.push_back(updaterate[i]);
686     }
687 kevin 113
688     SendSmsData(smsdata);
689 kevin 130 Sleep(500);
690    
691     }
692     CString SQL, Textwindow;
693     SQL.Format("update command set executed=now() where id=%s",IDnr);
694     db.ExecuteSQL(SQL);
695 kevin 136 AppendText("Command executed");
696 kevin 130 Sleep(150);
697 kevin 113
698     }
699     vector<Installation> CFlisServerDlg::DBReadPhone(CString sInstallationsID)
700     {
701     vector<Installation> buffer;
702    
703 kevin 121 CString SQL, phonenr, imei, updaterate;
704 kevin 130 int installernull;
705     Installation Myinst;
706     installernull = atoi(sInstallationsID);
707     if (installernull > 1)
708     {
709     SQL.Format("select installationphonenr, imei, updaterate from installation WHERE id = %s", sInstallationsID);
710     }
711     else if(installernull < 2)
712     {
713     SQL.Format("select installationphonenr, imei, updaterate from installation");
714     }
715 kevin 113 CRecordset rs(&db);
716     rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
717     if (rs.GetRecordCount()>0)
718     {
719     rs.MoveFirst();
720     while(!rs.IsEOF())
721     {
722 kevin 130
723     rs.GetFieldValue((short)0,phonenr);
724     rs.GetFieldValue(1,imei);
725     rs.GetFieldValue(2,updaterate);
726 kevin 113
727 kevin 130 Myinst.InstPhoneNr = phonenr;
728     Myinst.Imei = imei;
729     Myinst.Updaterate = updaterate;
730 kevin 113
731 kevin 130 buffer.push_back(Myinst);
732     rs.MoveNext();
733 kevin 113 }
734     }
735     rs.Close();
736     return buffer;
737 kevin 121 }
738 kevin 130 int CFlisServerDlg::tversum(__int64 input)
739 kevin 121 {
740     int sum = 0;
741     while (input > 0)
742     {
743     sum += (input %10);
744     input /= 10;
745     }
746     return sum;
747     }
748     void CFlisServerDlg::OnBnClickedStart()
749     {
750     // TODO: Add your control notification handler code here
751    
752     continueThread = 1;
753 kevin 132 m_Textwindow.SetWindowText("Started");
754 kevin 121 AfxBeginThread(threadWrapper,AfxGetMainWnd());
755     }
756 kevin 136 void CFlisServerDlg::AppendText(CString s)
757     {
758     CString Tekst;
759     m_Textwindow.GetWindowText(Tekst);
760     Tekst.Append("\r\n");
761     Tekst.Append(s);
762     m_Textwindow.SetWindowText(Tekst);
763    
764     }
765     void ConfigFile::ReadSettings()
766     {
767     ifstream file("Server-Settings.ini");
768     if (!file.is_open())
769     throw("Could not open file");
770    
771     char buf[200];
772     while (!file.eof() ) {
773     file.getline(buf,200);
774     CString tmp(buf);
775    
776     if (tmp.GetAt(0) == '#')
777     continue;
778    
779     int pos = tmp.Find('=');
780     if (pos>0) {
781     CString key = tmp.Left(pos).Trim().MakeLower();;
782     CString value = tmp.Right(tmp.GetLength()-pos-1).Trim();
783    
784     if (key == "host")
785     host = value;
786     else if (key == "username")
787     username = value;
788     else if (key == "password")
789     password = value;
790     else if (key == "database")
791     database = value;
792     else if (key == "comport")
793     comport = value;
794     }
795    
796     }
797    
798     file.close();
799     }

  ViewVC Help
Powered by ViewVC 1.1.20