使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 4905e2e7537d507f218e8e9595485e09d9f3a2b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
// CrowdMsgItem.cpp : implementation file
//
 
#include "stdafx.h"
#include "mbamdb.h"
#include "CrowdMsg.h"
#include "MBAMDBFun.h"
#include "PerfTimer.h"
 
 
#define        LISTMSG_TYPE_NONE            ( 0 )        // Ä¬ÈÏÏÔʾµÄÏûÏ¢
#define        LISTMSG_TYPE_MAGADMIN        ( 3 )        // ÁгöÏûÏ¢ID
 
 
// CCrowdMsgItem
extern CCriticalSection      m_csConnectDB;
CCrowdMsgItem::CCrowdMsgItem()
{
    m_nRowType    = ROWTYPE_CROWDMSG;
    Clear();
}
 
CCrowdMsgItem::~CCrowdMsgItem()
{
}
 
 
// CCrowdMsgItem member functions
void CCrowdMsgItem::Clear()
{
    m_strID            = GUID_EMPTY;
    m_strSender        = _T("");
    m_strSenderName    = _T("");
    m_strCrowdID    = _T("");
    m_strCrowdName    = _T("");
    m_tmDate    = COleDateTime::GetCurrentTime( );
    m_nMsgFlag            = 0;
    m_nReadState        = 0;
    m_strContentType = _T("");
    m_strContent = _T("");
    m_nContentSize = 0;
    m_strContentText = _T("");
}
 
BOOL CCrowdMsgItem::GetItemValue( CString strName, COleVariant &varData )
{  
    varData.Clear();
    if ( strName.IsEmpty() )
        return    false;
 
    if ( strName.CompareNoCase( _T( "ID" ) ) == 0 )
        varData        = m_strID;
    else if ( strName.CompareNoCase( _T("CrowdID") ) == 0 )
        varData        = m_strCrowdID;
    else if ( strName.CompareNoCase( _T("CrowdName") ) == 0 )
        varData        = m_strCrowdName;
    else if ( strName.CompareNoCase( _T( "Sender" ) ) == 0 )
        varData        = m_strSender;
    else if ( strName.CompareNoCase( _T( "SenderName" ) ) == 0 )
        varData        = m_strSenderName;
    else if ( strName.CompareNoCase( _T( "SendDate" ) ) == 0 )
    {
        if( !( m_tmDate.GetStatus() == COleDateTime::valid ) )
        {
            COleDateTime  temptime(2000,1,1, 0, 0, 0);
            m_tmDate = temptime;
        }
        
        COleDateTime    oleDate( m_tmDate.GetYear(), m_tmDate.GetMonth(), m_tmDate.GetDay(), m_tmDate.GetHour(), 
                            m_tmDate.GetMinute(), m_tmDate.GetSecond() );
        varData        = oleDate;
    }
    else if ( strName.CompareNoCase( _T( "ReadState" ) ) == 0 )
        varData        = m_nReadState;
    else if ( strName.CompareNoCase( _T( "MsgFlag" ) ) == 0 )
        varData        = m_nMsgFlag;
    else if ( strName.CompareNoCase( _T( "SenderName" ) ) == 0 )
        varData        = m_strSenderName;
    if ( strName.CompareNoCase( _T( "ContentType" ) ) == 0 )
        varData        = m_strContentType;
    else if ( strName.CompareNoCase( _T( "ContentSize" ) ) == 0 )
        varData        = (long)m_nContentSize;
    else if ( strName.CompareNoCase( _T( "Content" ) ) == 0 )
        varData        = m_strContent;
    else
        return    false;
 
    return    true;
}
 
BOOL CCrowdMsgItem::InsertRecord( CDBConnect *pAConnect)
{
    CString            strSQL;
    BOOL            bReturn = true;
 
    strSQL.Format( _T("INSERT INTO TN_STK_CROWDMSG(G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 ) VALUES ( \
        '%s', '%s', '%s', '%s', '%s','%s', %d, %d,'%s', %d,'%s','%s' )"),  
        m_strID, m_strCrowdID,m_strCrowdName, CMBAMDBFun::GetDBReplaceStr( m_strSender ),
        CMBAMDBFun::GetDBReplaceStr( m_strSenderName ), CMBAMDBFun::FormatDBTIMEToStr( m_tmDate ),
        m_nReadState, m_nMsgFlag, CMBAMDBFun::GetDBReplaceStr( m_strContentType), m_nContentSize ,
        CMBAMDBFun::GetDBReplaceStr( m_strContent ),CMBAMDBFun::GetDBReplaceStr( m_strContentText)  );
    try
    {
        bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
    }
    catch ( CDBSQliteException ex )
    {
        CString        strError = ex.GetErrInfo();
        CString        strErrInfo;
 
        strErrInfo = _T("InsertRecord - CrowdMsg- ") + strError;
        CMBAMDBFun::WriteDBErrToFile( strErrInfo );
        return false;
    }
    return true;
}
BOOL CCrowdMsgItem::UpdateRecord( CDBConnect *pAConnect )
{
    CString            strSQL;
    BOOL            bReturn = true;
 
    strSQL.Format( _T("UPDATE TN_STK_CROWDMSG SET G_C2 = '%s' ,S_C3= '%s', S_C4 = '%s', S_C5 = '%s', T_C6 = '%s',\
        N_C7 = %d, N_C8 =%d , S_C9 ='%s', N_C10 =%d, S_C11 ='%s',S_C12 ='%s' WHERE G_C1 = '%s'"), 
        m_strCrowdID,m_strCrowdName, CMBAMDBFun::GetDBReplaceStr( m_strSender ), CMBAMDBFun::GetDBReplaceStr( m_strSenderName ),
        CMBAMDBFun::FormatDBTIMEToStr( m_tmDate ),m_nReadState, m_nMsgFlag, CMBAMDBFun::GetDBReplaceStr( m_strContentType ),
        m_nContentSize,CMBAMDBFun::GetDBReplaceStr( m_strContent ),CMBAMDBFun::GetDBReplaceStr( m_strContentText ),  m_strID );
    try
    {
        bReturn = CDBSQLiteCommFun::RunSQL(strSQL, pAConnect);
    }
    catch ( CDBSQliteException ex )
    {
        CString        strError = ex.GetErrInfo();
        CString        strErrInfo;
 
        strErrInfo.Format( _T("UpdateRecord(%s) - CrowdMsg - %s "),strSQL, strError);
        CMBAMDBFun::WriteDBErrToFile( strErrInfo );
        return false;
    }
    return true;
}
 
CCrowdMsgs::CCrowdMsgs(CMBAMDBConnect *pAConnect)
{
    m_pAConnect = pAConnect;
    InitFilter();
    
}
 
CCrowdMsgs::~CCrowdMsgs()
{
    
}
void CCrowdMsgs::operator =( const CCrowdMsgs& item )
{
    m_nListMsgType    = item.m_nListMsgType;
    m_tmStartDate        = item.m_tmStartDate;
    m_tmEndDate            = item.m_tmEndDate;
    m_nReaded            = item.m_nReaded; // "-1"±íʾ²»Ö¸¶¨Õâ¸ö¹ýÂËÌõ¼þ
    m_pAConnect            = item.m_pAConnect;
    m_strSQL            = item.m_strSQL;
    m_nRowType            = item.m_nRowType;
    m_strID = item.m_strID;
    m_strCrowdID = item.m_strCrowdID;
    m_strCrowdName = item.m_strCrowdName;
    m_strSender = item.m_strSender;
    m_strSenderName = item.m_strSenderName;
    m_tmDate = item.m_tmDate;
    m_nReadState = item.m_nReadState;
    m_nMsgFlag = item.m_nMsgFlag;
    m_strContentType = item.m_strContentType;
    m_nContentSize = item.m_nContentSize;
    m_strContent = item.m_strContent;
}
void CCrowdMsgs::InitFilter()
    // ³õʼ»¯¹ýÂËÆ÷ʹȥ³ý¹ýÂË
    m_tmStartDate    = COleDateTime( 1970, 1, 1, 0, 0, 0 );
    m_tmEndDate        = COleDateTime( 1970, 1, 1, 0, 0, 0 );
    m_nListMsgType = LISTMSG_TYPE_NONE;
    m_nReaded        = -1; // "-1"±íʾ²»Ö¸¶¨Õâ¸ö¹ýÂËÌõ¼þ
}
int CCrowdMsgs::ListUnreadMsg( )
{
    CString            strSQL;
    int                nCount;
    // end modify
    strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE N_C7 <= 1 ORDER BY T_C6 DESC") );
    m_strSQL = strSQL; // 2: IOPEN , 1: InBox
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    try
    {
        nCount = ListRecordCount();
        m_ARecordSet.Close();
        m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
        if(nCount >0)
            m_ARecordSet.MoveFirst();
        
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo();
 
        return 0;
    }
 
    if ( nCount > 0 )
        GetData( );
 
    return nCount;
}
void CCrowdMsgs::SetCrowdMsgReadState(CString  strCrowdID  )
{
    CString            strSQL;
    // end modify
    strSQL.Format(_T("UPDATE TN_STK_CROWDMSG SET N_C7=%d WHERE N_C7 <= 1 AND G_C2 ='%s'"), MSG_READSTATE_IOPEN,strCrowdID);
    m_strSQL = strSQL; // 2: IOPEN , 1: InBox
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return;
    try
    {
        CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,m_pAConnect->GetDBConnect());
        
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo();
 
        return ;
    }
    return ;
}
 
int CCrowdMsgs::ListCrowdAll2(CString  strCrowdID,long nLimitCount,  BOOL bTimeAsc /*= FALSE*/ )
{ // Ê¹ÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
    CString            strSQL;
    int                    nCount = 0;
    CString             strStartDate;
    CString                strEndDate;
    CString                strSQLTempM;
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
    {
        if ( m_tmEndDate.GetYear() == 1970 )
            m_tmEndDate = COleDateTime::GetCurrentTime( );    
        
        strStartDate    = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
        strEndDate        = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
        
        strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
    }
    CString strLimitSQL = _T("");
    if(nLimitCount > 0)
        strLimitSQL.Format( _T("limit 0,%d"), nLimitCount);
    if( bTimeAsc)
        strSQL.Format(_T("SELECT T.* FROM ( \
            SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 DESC %s)T ORDER BY T.T_C6 ASC "), strCrowdID, strSQLTempM,strLimitSQL);
    else
        strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 DESC %s"), strCrowdID, strSQLTempM,strLimitSQL);
    m_strSQL = strSQL;
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    try
    {
        nCount = ListRecordCount();
        m_ARecordSet.Close();
        m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
        //m_ARecordSet.MoveFirst();
        //nCount = m_ARecordSet.GetRecordCount( );    
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo(  );
 
        return 0;
    }
 
    return nCount;
}
 
int CCrowdMsgs::ListCrowdAll(CString  strCrowdID, BOOL bTimeAsc /*= FALSE*/ )
{ // Ê¹ÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
    CString            strSQL;
    int                    nCount = 0;
    CString             strStartDate;
    CString                strEndDate;
    CString                strSQLTempM;
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
    {
        if ( m_tmEndDate.GetYear() == 1970 )
            m_tmEndDate = COleDateTime::GetCurrentTime( );    
        
        strStartDate    = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
        strEndDate        = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
        
        strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
    }
    if( bTimeAsc)
        strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 ASC "), strCrowdID,strSQLTempM);
    else
        strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C2 = '%s' %s ORDER BY T_C6 DESC "), strCrowdID,strSQLTempM);
    m_strSQL = strSQL;
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    try
    {
        nCount = ListRecordCount();
        m_ARecordSet.Close();
        m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
        //m_ARecordSet.MoveFirst();
        //nCount = m_ARecordSet.GetRecordCount( );    
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo(  );
 
        return 0;
    }
 
    return nCount;
}
 
bool CCrowdMsgs::GetMsgData( )
{
    CString        strFieldName;
    CString        strTempValue;
 
    try    
    {
        m_ARecordSet.GetValue( 1, strTempValue, true );
        m_strID            = strTempValue;
 
        m_ARecordSet.GetValue( 2, strTempValue, true );
        m_strCrowdID    = strTempValue;
 
        m_ARecordSet.GetValue( 3, strTempValue, true );
        m_strCrowdName    = strTempValue;
 
        m_ARecordSet.GetValue( 4, strTempValue, true );
        m_strSender        = strTempValue;
 
        m_ARecordSet.GetValue( 5, strTempValue, true );
        m_strSenderName = strTempValue;
 
        m_ARecordSet.GetValue( 6, m_tmDate);
        m_ARecordSet.GetValue( 7, m_nReadState );
        m_ARecordSet.GetValue( 8, m_nMsgFlag );
 
        m_ARecordSet.GetValue( 9, strTempValue, true );
        m_strContentType = strTempValue;
        m_ARecordSet.GetValue( 10, m_nContentSize );
        m_ARecordSet.GetValue( 11, strTempValue, true );
        m_strContent = strTempValue;
        m_ARecordSet.GetValue( 12, strTempValue, true );
        m_strContentText = strTempValue;
    }
    catch ( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo( );
        return false;
    }
 
    return true;
}
bool CCrowdMsgs::GetMsgAdminData( )
{
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    CDBRecord    ARecordset;
    CString                strTempValue;
    try    
    {
        m_ARecordSet.GetValue( 1, strTempValue, true );
        m_strID            = strTempValue;
    }
    catch ( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo();
        return false;
    }
 
    return true;
}
bool CCrowdMsgs::GetData( )
{
    InitMsgData( );
    if(m_nListMsgType == LISTMSG_TYPE_MAGADMIN)
    {
        GetMsgAdminData( );
    }
    else
        GetMsgData( );
    return true;
}
void CCrowdMsgs::InitMsgData( )
{
    Clear( );
}
int CCrowdMsgs::ListSpMsgID( LPCTSTR lpszMsgID )
{ // Ê¹ÓÃÕâ¸öº¯Êý£¬¹ýÂËÌõ¼þÎÞЧ
    if ( lpszMsgID == NULL )
        return    0;
 
    CString            strSQL;
    int                    nCount;
    strSQL.Format( _T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C1 = '%s'"), lpszMsgID);
    m_strSQL = strSQL;
 
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    try
    {
        m_ARecordSet.Close();
        m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
        m_ARecordSet.MoveFirst();
        nCount = m_ARecordSet.GetRecordCount( );
        m_strID = lpszMsgID;
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo( );
 
        return 0;
    }
 
    return nCount;
}
 
int CCrowdMsgs::ListSearchCrowdAll(CString  strCrowdID, CString strKey, BOOL bTimeAsc /*= FALSE*/ )
{ // Ê¹ÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
    CString            strSQL;
    int                nCount = 0;
    CString            strTemp;
    CString             strStartDate;
    CString                strEndDate;
    CString                strSQLTempM;
 
    
    if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
    {
        if ( m_tmEndDate.GetYear() == 1970 )
            m_tmEndDate = COleDateTime::GetCurrentTime( );    
        
        strStartDate    = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
        strEndDate        = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
        
        strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
    }
    if( !strKey.IsEmpty() )
    strTemp.Format( _T("AND S_C12 LIKE '%%%s%%' "), strKey );
 
    if( bTimeAsc)
        strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 ASC "), strCrowdID, strSQLTempM, strTemp);
    else
        strSQL.Format(_T("SELECT G_C1, G_C2 ,S_C3, S_C4, S_C5, T_C6, \
            N_C7, N_C8,S_C9,N_C10,S_C11,S_C12 \
            FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 DESC "), strCrowdID,strSQLTempM, strTemp);
    m_strSQL = strSQL;
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    try
    {
        nCount = ListRecordCount();
        m_ARecordSet.Close();
        m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
        //m_ARecordSet.MoveFirst();
        //nCount = m_ARecordSet.GetRecordCount( );    
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo(  );
 
        return 0;
    }
 
    return nCount;
}
 
BOOL CCrowdMsgs::DoSaveCrowdMsg( CCrowdMsgItem *pMsg )
{
    if ( !pMsg || pMsg->m_strID.IsEmpty() )
        return    false;
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    CDBConnect    *pAConnect = m_pAConnect->GetDBConnect();
    long            nMsgIndex(0);
    BOOL            bRetValue = false;
    CPerfTimer        pt;
    CString            strMsgID;
    
    strMsgID            = pMsg->m_strID;
    m_strID            = pMsg->m_strID;
    m_strCrowdID    = pMsg->m_strCrowdID;
    m_strCrowdName    = pMsg->m_strCrowdName;
    m_strSender        = pMsg->m_strSender;
    m_strSenderName    = pMsg->m_strSenderName;
    m_tmDate        = pMsg->m_tmDate;;
    m_nMsgFlag            = pMsg->m_nMsgFlag;
    m_nReadState    = pMsg->m_nReadState;
    m_strContentType    = pMsg->m_strContentType;
    m_nContentSize    = pMsg->m_strContent.GetLength();
    m_strContent        = pMsg->m_strContent;
    m_strContentText        = pMsg->m_strContentText;
 
    {
        pt.Start();
        InsertRecord( pAConnect );
        pt.Stop();
        pt.Trace( _T("DoSaveCrowdMsg\r\n") );
    }
    CString strSubject,strTempData;
    strTempData = CMBAMDBFun::GetSubjectFromFormatText(m_strContent);
    strTempData = CMBAMDBFun::GetRelSubject(strTempData, 64);
 
    strSubject.Format(_T("%s:%s"),m_strSenderName,strTempData);
    UpldateLastContactDate( m_strCrowdID,m_strCrowdName, CMBAMDBFun::FormatDBTIMEToStr( m_tmDate ),strSubject  );
    return    true;
}
 
long CCrowdMsgs::ListRecordCount(  )
{
    CString strTempSQL;
    if(m_strSQL.IsEmpty())
        return  m_ARecordSet.GetRecordCount( );    
    else
    {
        strTempSQL.Format(_T("    SELECT COUNT(*) FROM ( %s)T"), m_strSQL);
        long            nTempValue = 0;
        if( !m_pAConnect || !m_pAConnect->IsOpenDB())
            return    nTempValue;
        CDBRecord    ARecordset;
        try    
        {
            ARecordset.Open( m_pAConnect->GetDBConnect(), strTempSQL );
            while ( S_OK == ARecordset.MoveNext() )
            {
                ARecordset.GetValue( 1, nTempValue );
                break;
            }
        }
        catch ( CDBSQliteException ex )
        {
            CString        strError;
 
            strError = (LPCTSTR)ex.GetErrInfo( );
            return    nTempValue;
        }
        return    nTempValue;
    }
}
BOOL CCrowdMsgs::UpldateLastContactDate( CString strID, CString strName, CString strLastDate, CString strSubject)
{
    CString            strSQL;
    CDBRecord        ARecordset;
    BOOL            bReturn = FALSE;
    int                nVaule = 0;
    CString            strSubSQL = _T("");
    CHighTime        dtCurrent = CHighTime::GetPresentTime();
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    CDBConnect    *pAConnect = m_pAConnect->GetDBConnect();
 
    if( strID.IsEmpty() )
        return TRUE;
    if( !strName.IsEmpty() && strName.CompareNoCase(strID) != 0)
    {
        strSubSQL.Format( _T("S_C2 ='%s',"), CMBAMDBFun::GetDBReplaceStr( strName));
    }
    strSQL.Format( _T("SELECT COUNT(*) FROM TN_STK_LASTCONTACT WHERE S_C1='%s' AND  N_C4=%d "),CMBAMDBFun::GetDBReplaceStr( strID),AM_VIEWITEMTYPE_CROWD);
    try
    {
        ARecordset.Open( pAConnect,strSQL );
        while ( S_OK == ARecordset.MoveNext()  )
        {
            nVaule = 0;
            ARecordset.GetValue( 1, nVaule );
            bReturn = TRUE;
            break;
        }
        if( nVaule > 1 )
        {
            strSQL.Format( _T("DELETE FROM TN_STK_LASTCONTACT WHERE S_C1= '%s' AND  N_C4=%d "), CMBAMDBFun::GetDBReplaceStr( strID),AM_VIEWITEMTYPE_CROWD );
            bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
            if( !bReturn)
                return false;
            strSQL.Format( _T("INSERT INTO TN_STK_LASTCONTACT(S_C1, S_C2 ,T_C3, N_C4, S_C5 ) VALUES ( \
                '%s', '%s', '%s', %d, '%s' )"),  CMBAMDBFun::GetDBReplaceStr( strID), CMBAMDBFun::GetDBReplaceStr( strName),strLastDate,AM_VIEWITEMTYPE_CROWD,CMBAMDBFun::GetDBReplaceStr( strSubject)  );
            bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
            return bReturn;
        }
        else if( nVaule == 1 )
        {
            strSQL.Format( _T("UPDATE TN_STK_LASTCONTACT SET S_C2='%s', T_C3 ='%s', S_C5 ='%s' WHERE S_C1= '%s' AND  N_C4=%d  AND (T_C3<= '%s' OR T_C3 > '%s')"), CMBAMDBFun::GetDBReplaceStr( strName),strLastDate, CMBAMDBFun::GetDBReplaceStr( strSubject), CMBAMDBFun::GetDBReplaceStr( strID),AM_VIEWITEMTYPE_CROWD, strLastDate, CMBAMDBFun::FormatDBTIMEToStr( dtCurrent )  );
            bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
            return bReturn;
        }
        else
        {
            strSQL.Format( _T("INSERT INTO TN_STK_LASTCONTACT(S_C1, S_C2 ,T_C3, N_C4, S_C5 ) VALUES ( \
                '%s', '%s', '%s', %d, '%s' )"),  CMBAMDBFun::GetDBReplaceStr( strID), CMBAMDBFun::GetDBReplaceStr( strName),strLastDate,AM_VIEWITEMTYPE_CROWD,CMBAMDBFun::GetDBReplaceStr( strSubject)  );
            bReturn = CDBSQLiteCommFun::RunSQL( (LPCTSTR)strSQL,pAConnect);
            return bReturn;
        }
    }
    catch ( CDBSQliteException ex )
    {
        CString        strError, strErrInfo;
        
        strError    = ex.GetErrInfo();
        strErrInfo    = _T("CCrowdMsgs UpldateLastContactDate - ") + strError;
        CMBAMDBFun::WriteDBErrToFile( strErrInfo );
        return FALSE;
    }
    return bReturn;
}
 
int CCrowdMsgs::ListSearchCrowdMsgBox(CString  strCrowdID, CString strKey, BOOL bTimeAsc /*= FALSE*/ )
{ // Ê¹ÓÃÕâ¸öº¯Êý¹ýÂËÆ÷ÎÞЧ
    CString            strSQL;
    int                nCount = 0;
    CString            strTemp;
    CString             strStartDate;
    CString                strEndDate;
    CString                strSQLTempM;
 
    
    if ( m_tmStartDate.GetYear() > 1970 || m_tmEndDate.GetYear() > 1970 )
    {
        if ( m_tmEndDate.GetYear() == 1970 )
            m_tmEndDate = COleDateTime::GetCurrentTime( );    
        
        strStartDate    = CMBAMDBFun::FormatDBTIMEToStr( m_tmStartDate );
        strEndDate        = CMBAMDBFun::FormatDBTIMEToStr( m_tmEndDate );
        
        strSQLTempM.Format( _T(" AND T_C6 >= '%s' AND T_C6 <= '%s'"), strStartDate, strEndDate );
    }
    if( !strKey.IsEmpty() )
    strTemp.Format( _T("AND S_C12 LIKE '%%%s%%' "), strKey );
 
    if( bTimeAsc)
        strSQL.Format(_T("SELECT G_C1,T_C6 FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 ASC "), strCrowdID, strSQLTempM, strTemp);
    else
        strSQL.Format(_T("SELECT G_C1,T_C6 FROM TN_STK_CROWDMSG WHERE G_C2 = '%s'%s %s ORDER BY T_C6 DESC "), strCrowdID,strSQLTempM, strTemp);
    m_strSQL = strSQL;
 
    if( !m_pAConnect || !m_pAConnect->IsOpenDB())
        return    0;
    try
    {
        nCount = ListRecordCount();
        m_ARecordSet.Close();
        m_ARecordSet.Open( m_pAConnect->GetDBConnect(), strSQL );
    }
    catch( CDBSQliteException ex )
    {
        CString        strError;
 
        strError = (LPCTSTR)ex.GetErrInfo(  );
 
        return 0;
    }
    m_nListMsgType = LISTMSG_TYPE_MAGADMIN;
    return nCount;
}