菜单的结构是:
OptionID OptionFirst OptionSec OptionThr ModelName VehicleID
1 ES240 1690
1 CAMRY,-0605 W/ VSC 505
1 CAMRY,-0605 W/0 VSC 575
1 CAMRY,0605-0801 W/ Memory Seat W/ VSC 581
1 CAMRY,0605-0801 W/ Memory Seat W/O VSC 616
2 CAMRY,0801- W/ Memory Seat W/ VSC 599
.........
要求处理成的结构是:
OptionID Index Sequence StringID VehicleID NextIndex
01 00 01 00 01 00 CA 7A 9A 06 00 00
01 00 01 00 02 00 CA 77 00 00 02 00
01 00 01 00 03 00 CA 78 00 00 03 00
01 00 02 00 01 00 CA 60 F9 01 00 00
01 00 02 00 02 00 CA 61 3F 02 00 00
01 00 03 00 01 00 CA 80 00 00 04 00
01 00 04 00 01 00 CA 60 45 02 00 00
01 00 04 00 02 00 CA 61 68 02 00 00
我把要处理的数据放到ACCESS中, 字符串对应的StringID放在IDString中,
IDString表的结构是:
StringID String
CA 60 W/ VSC
CA 61 W/o VSC
CA 7A ES240
CA 77 CAMRY,-0605
CA 78 CAMRY,0605-0801
CA 80 W/ Memory Seat
程序中用到的ACCESS表的操作类CADOConnection和树类CTree在其他文章中
CTree myTree;
CADOConnection adoOption;
处理完的数据放在Excel表中
myTree.root->data = strOptionID;
while(!adoOption.adoEOF())
{
strOptionFirst = adoOption.GetItemText(35);
strOptionSec = adoOption.GetItemText(36);
strOptionThr = adoOption.GetItemText(37);
strVehicleID = adoOption.GetItemText(39);
strSQL = "SELECT * FROM IDString WHERE IDString.String = '";
strSQL = strSQL + strOptionFirst + "'";
adoIDString.Open(strSQL);
strOptionFirst = adoIDString.GetItemText(0);
myTree.CreateOptionTree(strOptionFirst);
strSQL = "SELECT * FROM IDString WHERE IDString.String = '";
strSQL = strSQL + strOptionSec + "'";
if (strOptionSec != "")
{
adoIDString.Open(strSQL);
strOptionSec = adoIDString.GetItemText(0);
myTree.CreateOptionTree(strOptionSec);
}
strSQL = "SELECT * FROM IDString WHERE IDString.String = '";
strSQL = strSQL + strOptionThr + "'";
if (strOptionThr != "")
{
adoIDString.Open(strSQL);
strOptionThr = adoIDString.GetItemText(0);
myTree.CreateOptionTree(strOptionThr);
}
myTree.tag--;
strVehicleID = DecToMemoryHexCString(StrToDec(strVehicleID));
myTree.CreateOptionTree(strVehicleID);
myTree.curr->tagSelf = 0;
myTree.tag--;
myTree.curr = myTree.root;
adoOption.MoveNext();
}
adoOption.ExitConnect();
adoIDString.ExitConnect();
myExcel.OpenSheet("2A");
TreeNode *p = myTree.root->firstChild;
int childNum = 0, seq = 1;
while (p != NULL)
{
myExcel.SetItemText(optionLine, 1, strOptionID);
myExcel.SetItemText(optionLine, 2, DecToMemoryHexCString(p->tagParent));
myExcel.SetItemText(optionLine, 3, DecToMemoryHexCString(seq++));
myExcel.SetItemText(optionLine, 4, p->data);
if (p->firstChild->tagSelf == 0)
{
myExcel.SetItemText(optionLine, 5, p->firstChild->data);
myExcel.SetItemText(optionLine++, 6, "00 00");
}
else
{
myExcel.SetItemText(optionLine, 5, "00 00");
myExcel.SetItemText(optionLine++, 6, DecToMemoryHexCString(p->tagSelf));
}
p = p->nextSibling;
}
p = myTree.root->firstChild;
seq = 1;
while(p != NULL)
{
if (p->firstChild->tagSelf != 0)
{
TreeNode *q = p->firstChild;
while(q != NULL)
{
myExcel.SetItemText(optionLine, 1, strOptionID);
myExcel.SetItemText(optionLine, 2, DecToMemoryHexCString(q->tagParent));
myExcel.SetItemText(optionLine, 3, DecToMemoryHexCString(seq++));
myExcel.SetItemText(optionLine, 4, q->data);
if (q->firstChild->tagSelf == 0)
{
myExcel.SetItemText(optionLine, 5, q->firstChild->data);
myExcel.SetItemText(optionLine++, 6, "00 00");
}
else
{
myExcel.SetItemText(optionLine, 5, "00 00");
myExcel.SetItemText(optionLine++, 6, DecToMemoryHexCString(q->tagSelf));
}
q = q->nextSibling;
}
TreeNode *ptr = p->firstChild;
seq = 1;
while(ptr != NULL)
{
if (ptr->firstChild->tagSelf != 0)
{
TreeNode *q = ptr->firstChild;
while(q != NULL)
{
myExcel.SetItemText(optionLine, 1, strOptionID);
myExcel.SetItemText(optionLine, 2, DecToMemoryHexCString(q->tagParent));
myExcel.SetItemText(optionLine, 3, DecToMemoryHexCString(seq++));
myExcel.SetItemText(optionLine, 4, q->data);
if (q->firstChild->tagSelf == 0)
{
myExcel.SetItemText(optionLine, 5, q->firstChild->data);
myExcel.SetItemText(optionLine++, 6, "00 00");
}
else
{
myExcel.SetItemText(optionLine, 5, "00 00");
myExcel.SetItemText(optionLine++, 6, DecToMemoryHexCString(q->tagSelf));
}
q = q->nextSibling;
}
}
ptr = ptr->nextSibling;
}
}
p = p->nextSibling;
}
adoMain.MoveNext();