-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMk4DataContainer.cpp
5143 lines (4495 loc) · 178 KB
/
CMk4DataContainer.cpp
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Master include file
#include "Mk4Data.h"
#if (_WIN32_WCE < 300)
#include "preCE3fixes.h"
#endif
//@START_USER2
//@END_USER2
//
// Group: GlobalData
//
// Static members
bool CMk4DataContainer::m_bOpenViewsInMemory = FALSE;
// End of Group: GlobalData
//
// Group: DBFileManagement
//
/*@NOTE_121
Open the db file in a member function rather than the class constructor. Name
of file need not be known at the time of the storage constructor. Open or
reopen a file when it needs to be. Checks to make sure this file is not already
open.
*/
int CMk4DataContainer::OpenDBFile(const char* ptrFileToOpen,
bool bOpenViewsInMemory)
{//@CODE_121
int value;
value = ERR_NONE; // set return value
// check to see if already an open db, close if there is one open
if (m_iDBStatus != DB_NOT_AVAIL)
{
CloseDB();
}
// save the request to open views as copies in memory
m_bOpenViewsInMemory = bOpenViewsInMemory;
// if file exists make sure it is not already open since twice will corrupt
// skip this if on win ce
#ifndef q4_WINCE
int iTemp = FileAlreadyOpen(ptrFileToOpen);
if (iTemp != 0)
return ERR_NOFILE;
#endif
// copy the file name into class
m_ptrFileName = (char*) new char[(strlen(ptrFileToOpen) + 1)];
strcpy(m_ptrFileName, ptrFileToOpen);
m_sFileName = m_ptrFileName; // save a copy as a string also
// *** need to check for file existance
// open up the database file
OpenStorage();
// *** need to check for success
// set db status flag
m_iDBStatus = DB_AVAIL_STORE_OPEN;
BuildListOfViews();
return value;
}//@CODE_121
/*@NOTE_174
Override open function to open with CString rather than char array. Converts to
a char array then calls open with char array.
*/
int CMk4DataContainer::OpenDBFile(CString sFileToOpen, bool bOpenViewsInMemory)
{//@CODE_174
int value;
value = 0; // initialize return value
// convert the string into a char for SBCS
char * temp = NULL; // to hold the string
StringToChar(sFileToOpen, &temp);
value = OpenDBFile(temp, bOpenViewsInMemory);
DELETEANDNULLALL(temp); // clean up allocation
return value;
/*
// need to handle unicode conversion of string if ce based
// this is a first cut at a conversion
#ifdef q4_WINCE
char* sbcharstring;
sbcharstring = (char*) new char[cs.GetLength() + 1];
((c4_StringProp&) p)(r) = sbcharstring;
delete sbcharstring;
// else, handle as non unicode
#else
((c4_StringProp&) p)(r) = cs;
#endif
*/
}//@CODE_174
/*@NOTE_192
Commit the changes made to the storage to make them permanant.
*/
int CMk4DataContainer::SaveData()
{//@CODE_192
int value = 0;
int i;
CString sTemp;
bool bNeedToCloseStorage = FALSE;
if (m_iDBStatus == DB_NOT_AVAIL)
{
// error if store not open
value = ERR_DBNOTOPEN;
#ifndef q4_WINCE
PopMsg("Committing ata", value);
#endif
return value;
}
// check to see if the storage is open
if (m_ptrDataStore == NULL)
{
OpenStorage();
bNeedToCloseStorage = TRUE;
}
// copy any views in memory back to the file
for (i = 0; i < VGMAXOPEN; i++)
{
if (m_ptrActiveTableName[i] != NULL && m_bViewIsCopyInMemory[i])
{
sTemp = m_ptrActiveTableName[i];
CopyViewFromMemoryToFile(sTemp, i);
}
}
// make the data permenant
m_ptrDataStore->Commit();
//close the storage if needed
if (bNeedToCloseStorage)
{
// make the data permenant
//m_ptrDataStore->Commit();
DELETEANDNULL(m_ptrDataStore);
}
return value;
}//@CODE_192
/*@NOTE_148
Build a comma delimited list of first level views by examining all of the
storage properties and looking for the view(V) property type. Store the string
list with the view names in a global data class member.
*/
int CMk4DataContainer::BuildListOfViews()
{//@CODE_148
int value = 0;
int nviews;
m_sListOfFirstLevelTables = ""; // blank out the list
if (m_iDBStatus == DB_NOT_AVAIL)
{
// error if store not open
value = ERR_DBNOTOPEN;
#ifndef q4_WINCE
PopMsg("Building List of Views", value);
#endif
return value;
}
// build the comma delimited list of view names in this file
nviews = m_ptrDataStore->NumProperties(); // the number of attributes (views) in db
for (int k = 0; k < nviews; k++)
{
// iterate through props and build list of names
c4_Property prop(m_ptrDataStore->NthProperty(k));
CString sName = prop.Name();
if (m_sListOfFirstLevelTables.GetLength() > 0)
m_sListOfFirstLevelTables += ", ";
if (prop.Type() == 'V')
m_sListOfFirstLevelTables += sName;
}
/* old stuff, superseeded
CString desc, views, temp, temp2;
int loc, loc2;
value = 0;
// start off with the mk4 description/structure
desc = ptrCharsToParse;
loc = 1; // initialize so it goes into while loop
// loop through and find the all of the views
while (loc > 0)
{
loc = desc.Find(":V"); // a view is indicated by :V in the structure
if (loc > 0)
{
// get everything up to (not including) the :V
temp = desc.Left(loc - 1);
// get the back end of the string up to next delimiter, ie. table name
loc2 = temp.ReverseFind(','); // find delimiter at front of name
temp2 = temp.Right(temp.GetLength() - loc2 - 1); // grab the table name
if (views.GetLength() > 0)
views += ", "; // add the comma delimiter to list
views += temp2; // add the name to the list
// lop off front for next itteration
temp = desc.Right(desc.GetLength() - loc);
desc = temp;
}
} // while a :V has been found
// set the list into member variable
if (m_sListOfFirstLevelTables != NULL)
delete m_sListOfFirstLevelTables;
m_sListOfFirstLevelTables = new char[views.GetLength() + 1];
strcpy(m_sListOfFirstLevelTables, views);
*/
return value;
}//@CODE_148
/*@NOTE_140
Initialize the variables in the class. Just sets a bunch of constants.
*/
int CMk4DataContainer::Initialize()
{//@CODE_140
int value;
value = 0;
// Initialize all of the member variables
m_bdbIsValid = false;
m_iDBStatus = DB_NOT_AVAIL;
m_ptrFileName = NULL;
m_ptrDataStore = NULL;
m_sListOfFirstLevelTables;
int i;
for (i = 0; i < VGMAXOPEN; i++)
{
m_ptrActiveTableName[i] = NULL;
m_ptrActiveTableStructure[i] = NULL;
m_ActiveViewHandle[i] = c4_View(); // initialize to empty
m_ptrParentTableName[i] = NULL;
m_iParentIndex[i] = -1;
m_bViewUsesDD[i] = FALSE;
m_ptrDefaultValues[i] = NULL;
m_bViewIsCopyInMemory[i] = FALSE;
}
// will have to deal with this: wanting string to be unicode - can't be for metakit
// will need to re-declare as char* or char and not cstring.
// set the structure of the data dictionary--these exact names are always used
m_sDDStructure = "DataDictionary[TableName:S,FieldType:S,Description:S,ColumnName:S,IsUsed:S,Length:I,Min:S,Max:S,Validate:S,Callbacks:S,DefaultValue:S,FieldEdit:S,CompoundSelection:S,Order1:I,Order2:I,Order3:I,Order4:I,Order5:I,Order6:I,Order7:I,Order8:I,Order9:I,Order10:I,Order11:I,Order12:I]";
#if defined q4_WINCE
m_sDDViewName = m_sDDStructure.SpanExcluding(TEXT("[")); // pull off the view name
#else
m_sDDViewName = m_sDDStructure.SpanExcluding("["); // pull off the view name
#endif
m_sDDColNameForTable = "TableName";
m_sDDColNameForIsUsed = "IsUsed";
m_sDDColNameForFType = "FieldType";
m_sDDColNameForColumnName = "ColumnName";
m_sDDColNameForColHead = "ColumnName";
m_sDDColNameForDispLen = "Length";
m_sDDColNameForDefValue = "DefaultValue";
m_sMsgLogViewName = "MessageLog";
m_sVersionNumber = "01.00.2003.12.10";
return value;
}//@CODE_140
/*@NOTE_196
Re Open the database. Generally, when views are added or removed, the db
should be colsed and reopened to update the class info.
*/
int CMk4DataContainer::ReopenDB()
{//@CODE_196
int value;
value = ERR_NONE;
CString FileName = m_sFileName;
OpenDBFile(FileName);
return value;
}//@CODE_196
/*@NOTE_102
Close the active database and clean up anything hanging around. This will close
any open views.
*/
int CMk4DataContainer::CloseDB(bool bCloseFileOnlyLeaveViewsInMemory)
{//@CODE_102
int value;
value = 0;
int i; // loop counter
if (m_iDBStatus == DB_NOT_AVAIL)
{
// error if store not open
value = ERR_DBNOTOPEN;
return value;
}
// clean up anything left hanging around
// clean up some file name allocated memory
// set db status
if (bCloseFileOnlyLeaveViewsInMemory)
{ // do nothing to file name if leaving around
// initialize flag to no views, reset below if some remain open
m_iDBStatus = DB_AVAIL_STORE_CLOSED_NO_VIEWS;
}
// close derived views first
// do not close if derived view is from a memory view
for (i = 0; i < VGMAXOPEN; i++)
{
if (m_iParentIndex[i] >= 0
&& m_ptrActiveTableName[i] != NULL
&& (m_bViewIsCopyInMemory[m_iParentIndex[i]] && bCloseFileOnlyLeaveViewsInMemory))
CloseAView(i);
}
// then close all other views
// do not close memory views if requested to leave there
for (i = 0; i < VGMAXOPEN; i++)
{
if (m_ptrActiveTableName[i] != NULL) // there is view in this slot
{
if (m_bViewIsCopyInMemory[i] && bCloseFileOnlyLeaveViewsInMemory)
{ // leave in memory if requested
m_iDBStatus = DB_AVAIL_STORE_CLOSED_HAS_VIEWS;
}
else
{ // get rid of this view
CloseAView(i);
}
}
}
// blank out list
m_sListOfFirstLevelTables.Empty();
if (!bCloseFileOnlyLeaveViewsInMemory)
{ // clean up file name for regular close
DELETEANDNULLALL(m_ptrFileName);
m_iDBStatus = DB_NOT_AVAIL;
}
// release any memory for the storage
DELETEANDNULL(m_ptrDataStore);
return value;
}//@CODE_102
/*@NOTE_629
Will actually open the mk4 storage file.
*/
int CMk4DataContainer::OpenStorage()
{//@CODE_629
int value=-1;
// release any memory for the storage
DELETEANDNULL(m_ptrDataStore);
// open up the database file
m_ptrDataStore = new c4_Storage(m_ptrFileName, true);
return value;
}//@CODE_629
// End of Group: DBFileManagement
//
// Group: Data access
//
/*@NOTE_240
The main mk4 access routine which will be called by the GetDataItemAs members.
Has place holders for all possible mk4 data types and flag that indicates which
one has the actual data that has been retrieved from storage. By using this
function, caller does not need to know how the data is stored, and need not
instantiate the c4_Property.
*/
int CMk4DataContainer::GetDataItem(const int ViewNum, const long RowNum,
const int ColNum, char* FieldType,
CString* StrRet, long* LongOrIntRet,
double* DoubleOrFloatRet)
{//@CODE_240
int value;
value = 0; // set return value
CString cs; // temp string to hold contents
c4_RowRef r = m_ActiveViewHandle[ViewNum][RowNum];
c4_Property p = m_ActiveViewHandle[ViewNum].NthProperty(ColNum);
// handle the data in the MK4 storage types
*FieldType = p.Type();
switch (*FieldType)
{
case 'I':
*LongOrIntRet = (int)((c4_IntProp&) p)(r);
break;
case 'L':
*LongOrIntRet = (long)((c4_LongProp&) p)(r);
break;
case 'F':
*DoubleOrFloatRet = (float)((c4_FloatProp&) p)(r);
break;
case 'D':
*DoubleOrFloatRet = (double)((c4_DoubleProp&) p)(r);
break;
case 'S':
*StrRet = (const char*)((c4_StringProp&) p)(r);
break;
/* do not handle memos or byte fields initially, may need to include
case 'M': // backward compatibility
case 'B':
(p(r)).GetData(data);
sprintf(buff, " (%db)", data.Size());
break;
*/
default:
value = 1;
}
return value;
}//@CODE_240
/*@NOTE_197
Generic way to retrieve a data item from a view. Returns int value 0 if ok, and
>0 for an error number. Since the stored data type is known to Mk4, the
requested data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::GetDataItemAs(const int ViewNum, const long RowNum,
const int ColNum, int* RetVal)
{//@CODE_197
int value;
// these are possible return values from call to get mk4 data
char FieldType; // the storage type in Mk4-tells which ret value is filled
// only one of these return variables will have a value
CString StrRet; // returned if type is string
long LongOrIntRet; // returned if type is long
double DoubleOrFloatRet; // returned if type is double
value = 0; // clear error return value
// get the typed value from the mk4 table-stored type in FieldType
GetDataItem(ViewNum, RowNum, ColNum, &FieldType, &StrRet,
&LongOrIntRet, &DoubleOrFloatRet);
// convert the value to the requested type
switch (FieldType)
{
case 'I':
case 'L':
*RetVal = LongOrIntRet;
break;
case 'F':
case 'D':
*RetVal = (int)(DoubleOrFloatRet + 0.5);
break;
case 'S':
*RetVal = _ttoi(StrRet);
break;
/* do not handle memos or byte fields initially, may need to include
case 'M': // backward compatibility
case 'B':
(p(r)).GetData(data);
sprintf(buff, " (%db)", data.Size());
break;
*/
default:
// dont know what to do so return error
*RetVal = 0;
value = 1;
}
return value;
}//@CODE_197
/*@NOTE_202
Generic way to retrieve a data item from a view. Returns int value 0 if ok, and
>0 for an error number. Since the stored data type is known to Mk4, the
requested data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::GetDataItemAs(const int ViewNum, const long RowNum,
const int ColNum, CString& RetVal)
{//@CODE_202
int value;
value = 0; // set the status return value
// these are possible return values from call to get mk4 data
char FieldType; // the storage type in Mk4-tells which ret value is filled
// only one of these return variables will have a value
CString StrRet; // returned if type is string
long LongOrIntRet; // returned if type is long
double DoubleOrFloatRet; // returned if type is double
value = 0; // clear error return value
// get the typed value from the mk4 table-stored type in FieldType
GetDataItem(ViewNum, RowNum, ColNum, &FieldType, &StrRet,
&LongOrIntRet, &DoubleOrFloatRet);
// convert the value to the requested type
switch (FieldType)
{
case 'I':
case 'L':
RetVal.Format(TEXT("%ld"), LongOrIntRet);
break;
case 'F':
RetVal.Format(TEXT("%g"), DoubleOrFloatRet);
break;
case 'D':
RetVal.Format(TEXT("%.15g"), DoubleOrFloatRet);
break;
case 'S':
RetVal = StrRet;
break;
/* do not handle memos or byte fields initially, may need to include
case 'M': // backward compatibility
case 'B':
(p(r)).GetData(data);
sprintf(buff, " (%db)", data.Size());
break;
*/
default:
// dont know what to do so return error
value = 1;
}
return value;
}//@CODE_202
/*@NOTE_207
Generic way to retrieve a data item from a view. Returns int value 0 if ok, and
>0 for an error number. Since the stored data type is known to Mk4, the
requested data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::GetDataItemAs(const int ViewNum, const long RowNum,
const int ColNum, float* RetVal)
{//@CODE_207
int value;
// these are possible return values from call to get mk4 data
char FieldType; // the storage type in Mk4-tells which ret value is filled
// only one of these return variables will have a value
CString StrRet; // returned if type is string
long LongOrIntRet; // returned if type is long
double DoubleOrFloatRet; // returned if type is double
// TCHAR* stopchar; // character that stops conversion
value = 0; // clear error return value
// get the typed value from the mk4 table-stored type in FieldType
GetDataItem(ViewNum, RowNum, ColNum, &FieldType, &StrRet,
&LongOrIntRet, &DoubleOrFloatRet);
// convert the value to the requested type
switch (FieldType)
{
case 'I':
case 'L':
*RetVal = (float)LongOrIntRet;
break;
case 'F':
case 'D':
*RetVal = (float)DoubleOrFloatRet;
break;
case 'S':
*RetVal = (float)(_tcstod(StrRet, NULL));
break;
/* do not handle memos or byte fields initially, may need to include
case 'M': // backward compatibility
case 'B':
(p(r)).GetData(data);
sprintf(buff, " (%db)", data.Size());
break;
*/
default:
// dont know what to do so return error
*RetVal = 0;
value = 1;
}
return value;
}//@CODE_207
/*@NOTE_212
Generic way to retrieve a data item from a view. Returns int value 0 if ok, and
>0 for an error number. Since the stored data type is known to Mk4, the
requested data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::GetDataItemAs(const int ViewNum, const long RowNum,
const int ColNum, double* RetVal)
{//@CODE_212
int value;
// these are possible return values from call to get mk4 data
char FieldType; // the storage type in Mk4-tells which ret value is filled
// only one of these return variables will have a value
CString StrRet; // returned if type is string
long LongOrIntRet; // returned if type is long
double DoubleOrFloatRet; // returned if type is double
// TCHAR* stopchar; // character that stops conversion
value = 0; // clear error return value
// get the typed value from the mk4 table-stored type in FieldType
GetDataItem(ViewNum, RowNum, ColNum, &FieldType, &StrRet,
&LongOrIntRet, &DoubleOrFloatRet);
// convert the value to the requested type
switch (FieldType)
{
case 'I':
case 'L':
*RetVal = LongOrIntRet;
break;
case 'F':
case 'D':
*RetVal = DoubleOrFloatRet;
break;
case 'S':
*RetVal = _tcstod(StrRet, NULL);
break;
/* do not handle memos or byte fields initially, may need to include
case 'M': // backward compatibility
case 'B':
(p(r)).GetData(data);
sprintf(buff, " (%db)", data.Size());
break;
*/
default:
// dont know what to do so return error
*RetVal = 0;
value = 1;
}
return value;
}//@CODE_212
/*@NOTE_260
Generic way to retrieve a data item from a view. Returns int value 0 if ok, and
>0 for an error number. Since the stored data type is known to Mk4, the
requested data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::GetDataItemAs(const int ViewNum, const long RowNum,
const int ColNum, long* RetVal)
{//@CODE_260
int value;
// these are possible return values from call to get mk4 data
char FieldType; // the storage type in Mk4-tells which ret value is filled
// only one of these return variables will have a value
CString StrRet; // returned if type is string
long LongOrIntRet; // returned if type is long
double DoubleOrFloatRet; // returned if type is double
value = 0; // clear error return value
// get the typed value from the mk4 table-stored type in FieldType
GetDataItem(ViewNum, RowNum, ColNum, &FieldType, &StrRet,
&LongOrIntRet, &DoubleOrFloatRet);
// convert the value to the requested type
switch (FieldType)
{
case 'I':
case 'L':
*RetVal = LongOrIntRet;
break;
case 'F':
case 'D':
*RetVal = (long)(DoubleOrFloatRet + 0.5);
break;
case 'S':
*RetVal = _ttol(StrRet);
break;
/* do not handle memos or byte fields initially, may need to include
case 'M': // backward compatibility
case 'B':
(p(r)).GetData(data);
sprintf(buff, " (%db)", data.Size());
break;
*/
default:
// dont know what to do so return error
*RetVal = 0;
value = 1;
}
return value;
}//@CODE_260
/*@NOTE_250
The main mk4 access routine which will be called by the SetDataItemAs members.
Has place holders for all possible mk4 data types and flag that indicates which
one has the actual data. By using this function, caller does not need to know
how the data is stored, and need not instantiate the c4_Property.
*/
int CMk4DataContainer::SetDataItem(const int ViewNum, const long RowNum,
const int ColNum, const char DataTypeIn,
const CString StrIn, const int IntIn,
const long LongIn, const float FloatIn,
const double DoubleIn)
{//@CODE_250
int value; // return value
// reset return value
value = 0;
int RawViewNum = m_iParentIndex[ViewNum];
if (RawViewNum < 0)
{
// this is a raw view, so just call worker to make data save
value = SetDataItemWorker(ViewNum, RowNum, ColNum, DataTypeIn,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
}
else
{ // this is a derived view so unmap to raw view
// set the pointers to the specified row and column
c4_RowRef r = m_ActiveViewHandle[ViewNum][RowNum];
c4_Property p = m_ActiveViewHandle[ViewNum].NthProperty(ColNum);
// check if this is a derived view and if so, unmap to parent view
long iRawRowNum;
int iRawColNum;
// find out which row in raw view corresponds to row in derived view
iRawRowNum = m_ActiveViewHandle[RawViewNum].GetIndexOf(m_ActiveViewHandle[ViewNum][RowNum]);
// since the derived view may have permuted cols, find corresponding
CString sTemp = p.Name(); // the name of the property
char* cTemp = NULL;
StringToChar(sTemp, &cTemp);
// char* cTemp = new char[sTemp.GetLength() + 1];
//#if defined q4_WINCE
// wcstombs(cTemp, sTemp, sTemp.GetLength() + 1);
//#else
// strcpy(cTemp, sTemp.operator LPCTSTR());
//#endif
iRawColNum = m_ActiveViewHandle[RawViewNum].FindPropIndexByName(cTemp);
DELETEANDNULLALL(cTemp);
// set the row and col to raw view rather than derived
// r = m_ActiveViewHandle[RawViewNum][iRawRowNum];
// p = m_ActiveViewHandle[RawViewNum].NthProperty(iRawColNum);
value = SetDataItemWorker(RawViewNum, iRawRowNum, iRawColNum, DataTypeIn,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
}
return value;
}//@CODE_250
/*@NOTE_220
Generic way to set a data item into a view. Returns int value 0 if ok, and >0
for an error number. Since the stored data type is known to Mk4, the requested
data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::SetDataItemFrom(const int ViewNum, const long RowNum,
const int ColNum, const int SetVal)
{//@CODE_220
int value;
// a list of possible values to pass to data access routine
// set the passed value into the appropriate variable and set the type
char FieldType = 'I';
CString StrIn;
int IntIn = SetVal;
long LongIn = 0;
float FloatIn = 0.0;
double DoubleIn = 0.0;
// set the passed value into the data table
value = SetDataItem(ViewNum, RowNum, ColNum, FieldType,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
return value;
}//@CODE_220
/*@NOTE_225
Generic way to set a data item into a view. Returns int value 0 if ok, and >0
for an error number. Since the stored data type is known to Mk4, the requested
data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::SetDataItemFrom(const int ViewNum, const long RowNum,
const int ColNum, const CString& SetVal)
{//@CODE_225
int value;
// a list of possible values to pass to data access routine
// set the passed value into the appropriate variable and set the type
char FieldType = 'S';
CString StrIn = SetVal;
int IntIn = 0;
long LongIn = 0;
float FloatIn = 0.0;
double DoubleIn = 0.0;
// set the passed value into the data table
value = SetDataItem(ViewNum, RowNum, ColNum, FieldType,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
return value;
}//@CODE_225
/*@NOTE_230
Generic way to set a data item into a view. Returns int value 0 if ok, and >0
for an error number. Since the stored data type is known to Mk4, the requested
data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::SetDataItemFrom(const int ViewNum, const long RowNum,
const int ColNum, const float SetVal)
{//@CODE_230
int value;
// a list of possible values to pass to data access routine
// set the passed value into the appropriate variable and set the type
char FieldType = 'F';
CString StrIn;
int IntIn = 0;
long LongIn = 0;
float FloatIn = SetVal;
double DoubleIn = 0.0;
// set the passed value into the data table
value = SetDataItem(ViewNum, RowNum, ColNum, FieldType,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
return value;
}//@CODE_230
/*@NOTE_235
Generic way to set a data item into a view. Returns int value 0 if ok, and >0
for an error number. Since the stored data type is known to Mk4, the requested
data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::SetDataItemFrom(const int ViewNum, const long RowNum,
const int ColNum, const double SetVal)
{//@CODE_235
int value;
// a list of possible values to pass to data access routine
// set the passed value into the appropriate variable and set the type
char FieldType = 'D';
CString StrIn;
int IntIn = 0;
long LongIn = 0;
float FloatIn = 0.0;
double DoubleIn = SetVal;
// set the passed value into the data table
value = SetDataItem(ViewNum, RowNum, ColNum, FieldType,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
return value;
}//@CODE_235
/*@NOTE_265
Generic way to set a data item into a view. Returns int value 0 if ok, and >0
for an error number. Since the stored data type is known to Mk4, the requested
data type may imply a conversion; this should also allow dealing with
conversions for Unicode(UCS2). There are multiple member functions with
overrides for all data types available.
*/
int CMk4DataContainer::SetDataItemFrom(const int ViewNum, const long RowNum,
const int ColNum, const long SetVal)
{//@CODE_265
int value;
// a list of possible values to pass to data access routine
// set the passed value into the appropriate variable and set the type
char FieldType = 'L';
CString StrIn;
int IntIn = 0;
long LongIn = SetVal;
float FloatIn = 0.0;
double DoubleIn = 0.0;
// set the passed value into the data table
value = SetDataItem(ViewNum, RowNum, ColNum, FieldType,
StrIn, IntIn, LongIn, FloatIn, DoubleIn);
return value;
}//@CODE_265
/*@NOTE_352
The main mk4 access routine which will be called by the SetDataItemAs members.
Has place holders for all possible mk4 data types and flag that indicates which
one has the actual data.
*/
int CMk4DataContainer::SetDataItemWorker(const int ViewNum, const long RowNum,
const int ColNum,
const char DataTypeIn,
const CString StrIn, const int IntIn,
const long LongIn, const float FloatIn,
const double DoubleIn)
{//@CODE_352
int value; // return value
// some temporary typed variables
int tempint;
long templong;
float tempfloat;
double tempdouble;
char* SBCSstring = NULL;
CString sTemp;
// reset return value
value = 0;
SBCSstring = NULL;
// set the pointers to the specified row and column
c4_RowRef r = m_ActiveViewHandle[ViewNum][RowNum];
c4_Property p = m_ActiveViewHandle[ViewNum].NthProperty(ColNum);
char DataTypeStored = p.Type(); // retrieve the stored type
// compare the data type coming in with the data type in the storage
// if the same, just set it, but if different, convert in to stored type
switch (DataTypeIn)
{
case 'S':
// TCHAR* stopchar;