3 Star 0 Fork 2

leegoobin/DBConvert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
makelisega.cpp 21.52 KB
一键复制 编辑 原始数据 按行查看 历史
unknown 提交于 2015-02-03 14:32 . 代码移植到Git
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
// MakeLISEGA.cpp: implementation of the CMakeLISEGA class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MakeLISEGA.h"
//#include "modregistry.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMakeLISEGA::CMakeLISEGA()
{
}
CMakeLISEGA::~CMakeLISEGA()
{
}
//本程序中将使用到的返回值 的宏的定义
#ifndef RET
#define RET_OK 0
#define RET_FAILD -1
#endif
//函数声明区
//判断当前数据库连接对象是否打开
int conIsOpened(_ConnectionPtr &pCon);
//测试表是否存在
int testTable(_ConnectionPtr &pCon,const CString tableName);
//从表中删除指定条件的记录
int delRecord(_ConnectionPtr pCon,const CString tableName,const CString delCond);
//打开指定数据库对象连接
int openConnectDB(_ConnectionPtr &pCon,const CString strPathName,const CString strDBFileName);
//由pCon(Connection)对象执行指定SQL命令
int conExec(_ConnectionPtr &pCon,const CString strCmdSql,CString strDcrCmd );
//执行指定记录集对象指定SQL操作
int recOpen(_ConnectionPtr &pCon,_RecordsetPtr &pRs,CString strOpenSql,CString strDcrOpen );
//断开指定数据库连接对象连接
int closeConnectDB(_ConnectionPtr &pCon);
//关闭指定记录集对象
int closeRecordset(_RecordsetPtr &pRs);
//删除表
int dropTable(_ConnectionPtr &pCon,const CString tableName);
void CMakeLISEGA::MakeLISEGA_ConstantSPR_DH()
{ //LISEGA恒力弹簧编号生成函数
// TODO: Add your command handler code here
//初始化
_ConnectionPtr pCon;
pCon.CreateInstance(__uuidof(Connection));
_RecordsetPtr pRs;
pRs.CreateInstance(__uuidof(Recordset));
//初始化当前使用的表名
CString TBName_HDcrude_LISEGA;
CString TBName_HDforceDist_LISEGA_new;
CString TBName_TravelSeriesValue;
CString TBName_LISEGALoad;
TBName_LISEGALoad = "LISEGALoadCSPR";
TBName_TravelSeriesValue = "LISEGA_TravelSeriesValue";
TBName_HDforceDist_LISEGA_new = "HDforceDist_LISEGA_new";
TBName_HDcrude_LISEGA = "HDcrude_LISEGA";
CString strDBFileName; //文件名
strDBFileName.Format("ZDJcrudeLISEGA.mdb");
CString strDBPathName; //路径名
strDBPathName="C:\\Program Files\\长沙优易软件开发有限公司\\AutoPHS4.1\\Template";
// strDBPathName="\\\\system\\d";
// strDBPathName = "d:\\data";
CString strSql; //SQL命令
CString strDcr; //SQL命令描述符
CString tStr; //临时变量
//打开数据库连接
openConnectDB(pCon,strDBPathName,strDBFileName);
//初始化下列步骤中使用的记录集对象
_RecordsetPtr pRecLISEGALoad;
_RecordsetPtr pRecHDforceDist_LISEGA_new;
_RecordsetPtr pRecTravelSeriesValue;
_RecordsetPtr pRecHDcrude_LISEGA;
pRecLISEGALoad.CreateInstance(__uuidof(Recordset));
pRecTravelSeriesValue.CreateInstance(__uuidof(Recordset));
pRecHDforceDist_LISEGA_new.CreateInstance(__uuidof(Recordset));
pRecHDcrude_LISEGA.CreateInstance(__uuidof(Recordset));
int iret1;
//测试四表是否存在
iret1 = testTable(pCon,TBName_LISEGALoad);
CString tStrError;
if (iret1 != RET_OK)
{
tStrError.Empty();
tStrError.Format("表%s不能打开,退出!",TBName_LISEGALoad);
AfxMessageBox(tStrError);
return;
}
iret1 = testTable(pCon,TBName_HDforceDist_LISEGA_new);
if (iret1 != RET_OK)
{
tStrError.Empty();
tStrError.Format("表%s不能打开,退出!",TBName_HDforceDist_LISEGA_new);
AfxMessageBox(tStrError);
return;
}
iret1 = testTable(pCon,TBName_HDcrude_LISEGA);
if (iret1 != RET_OK)
{
tStrError.Empty();
tStrError.Format("表%s不能打开,退出!",TBName_HDcrude_LISEGA);
AfxMessageBox(tStrError);
return;
}
iret1 = testTable(pCon,TBName_TravelSeriesValue);
if (iret1 != RET_OK)
{
tStrError.Empty();
tStrError.Format("表%s不能打开,退出!",TBName_TravelSeriesValue);
AfxMessageBox(tStrError);
return;
}
//*********步骤一.*************
//designed by ligb on 2005.01.25
//programed by lfx on 2005.01.27
//LISEGA恒力弹簧编号生成函数
//方法与步骤:
//1.打开库ZDJcrudeLISEGA.MDB,有三个表:把LISEGALoadCSPR荷载系列表里的每一个荷载值LoadValue循环,
// 行程范围代号循环从LISEGALoadCSPR荷载系列表里的TravelRangeMin字段到TravelRangeMax字段,
// 根据行程范围代号从TravelSeriesValue行程系列表查得对应的LISEGATravelMaxValue值,
// 把荷载值LoadValue循环与行程TravelMaxValue值相乘,结果写到
// HDforceDist_LISEGA_new荷载容量表的capacity字段,把CSPRNo字段连接TravelRange字段
// 组合成LISEGACSPRNo字段。TravelMaxValue->MaxDist,MinDist->MinDist。
// manufactory="LISEGA"
//2.按capacity字段值升序排序HDforceDist_LISEGA_new表,对DH字段顺序编号1-73。
//3.这样形成了一个LISEGA恒力弹簧的载荷容量表,它比普通的表多了一个字段LISEGACSPRNo。
//4.以后对恒吊尺寸数据表HDcrude_LISEGA处理:循环该表每个记录,取BH的2、3和4位组成新的
// 荷载行程识别码,当识别码开头字符为6(恒力支架)或7(伺服吊架)或9(横担吊架)时,设置识别码开头字符为1。从HDforceDist_LISEGA_new表
// LISEGACSPRNo字段值查得与识别码相等的记录,取
// HDforceDist_LISEGA_new表DH字段值,写入恒吊尺寸数据表HDcrude_LISEGA的DH字段。
//5.完工。
//在表 DforceDist_LISEGA_new 插入记录前,先删除其所有记录
//*********************************************************************************//
//LISEGA弹簧编号生成函数
//1.打开库ZDJcrudeLISEGA.MDB,有2个表:取crudeSPRING_LISEGA弹簧尺寸表BH字段,
//************ 刘丰喜 2005.2.1日添加***************************
//作用: 修改 crudeSPRING_LISEGA 表 注:本说明中以 0 为起点
//从 BH字段中取第 3 位组成DH字段第 0 位,取BH字段第 1 、 2 位根据计算得到
//DH字段的第 1 , 2 位,具体情况见 fnModiDHFromBH 函数
fnModiDHFromBH(pCon);
//END********* 刘丰喜 2005.2.1日添加***************************
iret1 = delRecord(pCon,TBName_HDforceDist_LISEGA_new,"");
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
strDcr.Format("打开表%s",TBName_LISEGALoad);
strSql.Format("SELECT * FROM %s",TBName_LISEGALoad);
iret1 = recOpen(pCon,pRecLISEGALoad,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
while (VARIANT_FALSE == pRecLISEGALoad->adoEOF)
{
_variant_t vFieldValue;
int TravelRangeMin,TravelRangeMax;
float LoadValue;
float TempCountMulti;
CString LoadGroup;
CString CSPRNo;
//float minDist;
vFieldValue = pRecLISEGALoad->GetCollect("TravelRangeMin");
TravelRangeMin = vFieldValue.iVal;
vFieldValue.Clear();
vFieldValue = pRecLISEGALoad->GetCollect("TravelRangeMax");
TravelRangeMax = vFieldValue.iVal;
vFieldValue.Clear();
vFieldValue = pRecLISEGALoad->GetCollect("LoadValue");
LoadValue = vFieldValue.fltVal;
vFieldValue.Clear();
vFieldValue = pRecLISEGALoad->GetCollect("LoadGroup");
LoadGroup = (char *)_bstr_t(vFieldValue);
vFieldValue.Clear();
vFieldValue = pRecLISEGALoad->GetCollect("CSPRNo");
CSPRNo = (char *)_bstr_t(vFieldValue);
vFieldValue.Clear();
for (int i = TravelRangeMin;i <= TravelRangeMax; i++)
{
//判断下列记录集是否打开,如打开,则关闭
closeRecordset(pRecHDcrude_LISEGA);
closeRecordset(pRecHDforceDist_LISEGA_new);
closeRecordset(pRecTravelSeriesValue);
//从表 TravelSeriesValue 中得到 LISEGATravelMaxValue 值
strSql.Empty();
strSql.Format("SELECT * FROM %s WHERE TravelRange = %d",TBName_TravelSeriesValue,i);
strDcr.Format("打开表%s",TBName_TravelSeriesValue);
iret1 = recOpen(pCon,pRecTravelSeriesValue,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
//把荷载值LoadValue循环与行程LISEGATravelMaxValue值相乘
vFieldValue = pRecTravelSeriesValue->GetCollect("TravelMaxValue");
float fTravelMaxValue=vFieldValue.iVal;
TempCountMulti = LoadValue * fTravelMaxValue;
vFieldValue = pRecTravelSeriesValue->GetCollect("minDist");
float fTravelMinValue=vFieldValue.iVal;
TempCountMulti = LoadValue * fTravelMinValue;
//把CSPRNo字段 同 TravelRange字段连接起来
CString tempStr1;
tempStr1.Format("%s%d",CSPRNo,i);
//将各计算结果值存入HDforceDist_LISEGA_new荷载容量表的capacity字段
strSql.Empty();
strSql.Format("INSERT INTO %s(capacity,LISEGACSPRNo,MaxDist,MinDist,manufactory) VALUES(%f,'%s',%f,%f,'%s')",TBName_HDforceDist_LISEGA_new,TempCountMulti,tempStr1,fTravelMaxValue,fTravelMinValue,"LISEGA");
strDcr.Format("打开表%s",TBName_HDforceDist_LISEGA_new),
iret1 = recOpen(pCon,pRecHDforceDist_LISEGA_new,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
}
pRecLISEGALoad->MoveNext();
}
//关闭步骤一中使用的记录集对象
closeRecordset(pRecLISEGALoad);
closeRecordset(pRecTravelSeriesValue);
closeRecordset(pRecHDforceDist_LISEGA_new);
closeRecordset(pRecHDcrude_LISEGA);
closeRecordset(pRs);
//*********步骤二.*************
//按capacity字段值升序排序 HDforceDist_LISEGA_new 表,对DH字段顺序编号1-73。
//排序过程中临时文件表名
CString tTBName_HDforceDist_LISEGA_new;
tTBName_HDforceDist_LISEGA_new.Format("tHDforceDist_LISEGA_new");
//删除表
dropTable(pCon,tTBName_HDforceDist_LISEGA_new);
//重建表 tHDforceDist_LISEGA_new 表结构
strSql.Empty();
strSql.Format("CREATE TABLE %s \
(CustomID VARCHAR(20),\
DH SMALLINT,\
capacity FLOAT,\
MinDist SMALLINT,\
MidDist SMALLINT,\
MaxDist SMALLINT,\
manufactory VARCHAR(30),\
LISEGACSPRNo VARCHAR(50))",tTBName_HDforceDist_LISEGA_new);
strDcr.Empty();
strDcr.Format("建立临时表结构");
iret1 = conExec(pCon,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
//将表 HDforceDist_LISEGA_new 中的所有记录按capacity字段值升序排序输出
//并插入 表中tHDforceDist_LISEGA_new
strSql.Empty();
strSql.Format("INSERT INTO %s(CustomID,DH,capacity,MinDist,MidDist,MaxDist,manufactory,LISEGACSPRNo) \
SELECT CustomID,DH,capacity,MinDist,MidDist,MaxDist,manufactory,LISEGACSPRNo FROM %s ORDER BY capacity",\
tTBName_HDforceDist_LISEGA_new,TBName_HDforceDist_LISEGA_new);
strDcr.Empty();
strDcr.Format("复制记录并排序");
iret1 = conExec(pCon,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
//删除表HDforceDist_LISEGA_new
iret1 = delRecord(pCon,TBName_HDforceDist_LISEGA_new,"");
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
//将表 tHDforceDist_LISEGA_new 中的所有记录
//插入 表HDforceDist_LISEGA_new 中
strSql.Empty();
strSql.Format("INSERT INTO %s(CustomID,DH,capacity,MinDist,MidDist,MaxDist,manufactory,LISEGACSPRNo) \
SELECT CustomID,DH,capacity,MinDist,MidDist,MaxDist,manufactory,LISEGACSPRNo FROM %s",\
TBName_HDforceDist_LISEGA_new,tTBName_HDforceDist_LISEGA_new);
strDcr.Empty();
strDcr.Format("复制记录并排序");
iret1 = conExec(pCon,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
//删除临时表 tHDforceDist_LISEGA_new
dropTable(pCon,tTBName_HDforceDist_LISEGA_new);
//对表 tHDforceDist_LISEGA_new 中的DH字段顺序编号1-73。
strSql.Empty();
strSql.Format("SELECT * FROM %s",TBName_HDforceDist_LISEGA_new);
strDcr.Empty();
strDcr.Format("打开表%s",TBName_HDforceDist_LISEGA_new);
iret1 = recOpen(pCon,pRecHDforceDist_LISEGA_new,strSql,strDcr);
if (iret1 != RET_OK)
{
closeConnectDB(pCon);
return;
}
int loop = 0;
while (VARIANT_FALSE == pRecHDforceDist_LISEGA_new->adoEOF)
{
loop++;
_variant_t vFieldName,vFieldValue;
vFieldName.SetString("DH");
tStr.Empty();
tStr.Format("%d",loop);
vFieldValue.SetString(tStr);
pRecHDforceDist_LISEGA_new->Update(vFieldName,vFieldValue);
pRecHDforceDist_LISEGA_new->MoveNext();
}
closeRecordset(pRs);
closeRecordset(pRecHDforceDist_LISEGA_new);
closeConnectDB(pCon);
AfxMessageBox("函数执行成功!");
//函数结尾
closeConnectDB(pCon);
closeRecordset(pRs);
return;
}
//函数定义区
//打开指定数据库对象连接
int openConnectDB(_ConnectionPtr &pCon,const CString strDBPathName,const CString strDBFileName)
{
CString tstrDBPathName;
tstrDBPathName = strDBPathName;
int iret1;
//目录是否合法
iret1 = tstrDBPathName.FindOneOf("*?\"<>|");
if (iret1 != -1)
{
AfxMessageBox("非法目录,退出!");
return RET_FAILD;
}
iret1 = tstrDBPathName.ReverseFind('\\');
if (iret1 != 1)
{
tstrDBPathName += "\\";
}
CString strtemp1;
strtemp1.Empty();
strtemp1 += tstrDBPathName;
strtemp1 += strDBFileName;
if(!PathFileExists(_T(strtemp1)))
{
AfxMessageBox("文件不存在,退出!");
return RET_FAILD;
}
//判断当前连接对象是否已打开
if (pCon->State == adStateOpen)
{
pCon->Close();
}
try
{
//连接ACCESS2000数据库
CString strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + tstrDBPathName+strDBFileName;
pCon->Open(_bstr_t(strCon),"","",-1);
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return RET_FAILD;
}
return RET_OK;
}
int conExec(_ConnectionPtr &pCon,const CString strCmdSql,CString strDcrCmd = "")
{
//函数功能说明: 由pCon(Connection)对象执行指定SQL命令
//pCon 数据库连接对象
//strCmdSql 要执行SQL的命令语句
//strDcrCmd是对要使用SQL命令的描述
if (conIsOpened(pCon) != RET_OK) //判断当前连接对象是否已打开
{
AfxMessageBox("指定数据库对象未连接,退出!");
return RET_FAILD;
}
try
{
pCon->Execute(_bstr_t(strCmdSql),NULL,adCmdText);
}
catch(_com_error e)//捕捉异常
{
CString errormessage;
errormessage.Format("功能说明: %s\r\n数据库连接对象执行下列SQL命令\r\n%s\r\n失败! 错误信息:%s",strDcrCmd,strCmdSql,e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return RET_FAILD;
}
return RET_OK;
}
int recOpen(_ConnectionPtr &pCon,_RecordsetPtr &pRs,CString strOpenSql,CString strDcrOpen = "")
{
//函数说明:执行指定记录集对象指定SQL操作
//pCon 数据库连接对象
//pRs 当前操作用记录集对象
//strOpenSql 要执行的SQL命令
//strDcrOpen是对要使用SQL命令的描述
_variant_t tempStrSql;
tempStrSql = strOpenSql;
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation = adUseClient;
closeRecordset(pRs);
if (pRs->State == adStateOpen)
{
pRs->Close();
}
try
{
//有错 pRs->Open(tempStrSql,_variant_t(pCon),adOpenDynamic,adLockOptimistic,adCmdText);
pRs->Open(tempStrSql,(IDispatch *)pCon,adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)//捕捉异常
{
CString errormessage;
errormessage.Format("功能说明: %s\r\n记录集对象执行下列SQL命令\r\n%s\r\n失败! 错误信息:%s",strDcrOpen,strOpenSql,e.ErrorMessage());
AfxMessageBox(errormessage);//显示错误信息
return RET_FAILD;
}
return RET_OK;
}
//判断当前数据库连接对象是否打开
int conIsOpened(_ConnectionPtr &pCon)
{
//判断当前连接对象是否已打开
if (pCon->State != adStateOpen)
{
AfxMessageBox("连接数据库对象没打开!");
return RET_FAILD;
}
else
{
return RET_OK;
}
}
//断开指定数据库连接对象连接
int closeConnectDB(_ConnectionPtr &pCon)
{
if (pCon->State == adStateOpen)
{
pCon->Close();
}
return RET_OK;
}
//关闭指定记录集对象
int closeRecordset(_RecordsetPtr &pRs)
{
if (pRs->State == adStateOpen)
{
pRs->Close();
}
return RET_OK;
}
//删除表
int dropTable(_ConnectionPtr &pCon,const CString tableName)
{
CString strSql;
CString strDcr;
int iret1;
//测试表存不存在
//注意,如表不存在,不弹出警告
if (1)
{
_variant_t tStrSql;
strSql.Format("SELECT * FROM %s",tableName);
tStrSql = strSql;
_RecordsetPtr pRs;
pRs.CreateInstance(__uuidof(Recordset));
try
{
pRs->Open(tStrSql,(IDispatch *)pCon,adOpenDynamic,adLockOptimistic,adCmdText);
iret1 = RET_OK;
}
catch(_com_error e)
{
iret1 = RET_FAILD;
}
}
if ( iret1 == RET_OK)
{
//表存在
int iret2;
strDcr.Format("删除表");
strSql.Format("DROP TABLE %s",tableName);
iret2 = conExec(pCon,strSql,strDcr);
if (iret2 != RET_OK)
{
//删除出错
return RET_FAILD;
}
}
return RET_OK;
}
//测试表是否存在
int testTable(_ConnectionPtr &pCon,const CString tableName)
{ //注意:调用此函数,如表不存在,将弹出警告并退出
_RecordsetPtr pRs;
pRs.CreateInstance(__uuidof(Recordset));
CString strSql;
CString strDcr;
int iret1;
strDcr.Format("打开表");
strSql.Format("SELECT * FROM %s",tableName);
iret1 = recOpen(pCon,pRs,strSql,strDcr);
if (iret1 == RET_OK)
{
//打开成功
closeRecordset(pRs);
return RET_OK;
}
closeRecordset(pRs);
return RET_FAILD;
}
int delRecord(_ConnectionPtr pCon,const CString tableName,const CString delCond)
{
//函数功能: 从表中删除指定条件的记录
//delCond 指定删除条件
int iret1;
iret1 = testTable(pCon,tableName);
if (iret1 != RET_OK)
{
//表不存在则退出
return RET_FAILD;
}
CString strSql;
CString strDcr;
int iret2;
if (delCond.IsEmpty())
{
//如果条件字段为空
strSql.Format("DELETE FROM %s",tableName);
strDcr.Format("删除表中所有记录");
iret2 = conExec(pCon,strSql,strDcr);
if (iret2 == RET_OK)
{
//命令不成功退出
return RET_OK;
}
}
else
{
CString tempDelCond;
strDcr.Format("删除表中指定条件记录");
//更正条件命令
tempDelCond.Format("WHERE ");
tempDelCond = tempDelCond + delCond;
strSql.Format("DELETE FROM %s %s",tableName,tempDelCond);
iret2 = conExec(pCon,strSql,strDcr);
if (iret2 == RET_OK)
{
//命令不成功退出
return RET_OK;
}
}
return RET_FAILD;
}
int CMakeLISEGA::fnModiDHFromBH(_ConnectionPtr &pCon)
{
//注:本函数中均以0作基点开始
_RecordsetPtr pRs;
_RecordsetPtr pRs1;
pRs.CreateInstance(__uuidof(Recordset));
pRs1.CreateInstance(__uuidof(Recordset));
CString strSql;
strSql.Format("SELECT * FROM crudeSPRING_LISEGA");
recOpen(pCon,pRs,strSql,"打开表crudeSPRING_LISEGA");
_variant_t vFieldValue;
_variant_t vFieldName;
TCHAR ch1;
TCHAR ch2;
TCHAR ch3;
CString strFromBH;
CString strToDH;
CString strFromDH;
CString strTemp;
int nTmp;
char chTemp;
while (pRs->adoEOF == VARIANT_FALSE )
{
strFromBH.Empty();
strToDH.Empty();
//读取BH字段并进行处理写进 strToDH字符串中
vFieldValue = pRs->GetCollect("BH");
strFromBH = (char *)_bstr_t(vFieldValue);
vFieldValue = pRs->GetCollect("DH");
if ( (vFieldValue.vt == VT_NULL) || (vFieldValue.vt == VT_EMPTY) )
{
strFromDH.Empty();
}
else
{
strFromDH = (char *)_bstr_t(vFieldValue);
}
ch1 = strFromBH[1];
ch2 = strFromBH[2];
ch3 = strFromBH[3];
if ( (!strFromDH.IsEmpty()) && (ch3 == '.') ) //当前记录为原记录的复制,则忽略处理
{
pRs->MoveNext();
continue;
}
//2005.2.3 xdz修改
//**********START**********
strToDH.Format("%c",ch3);
nTmp = atoi(strToDH.GetBuffer(strToDH.GetLength()+1));
if(nTmp > 1)
{
nTmp = 2*(nTmp-1);
strToDH.Format("%d",nTmp);
}
else
strToDH = ch3;
//**********END**********
switch (ch1)
{
case '0':
case '1':
case '5':
case '7':
case '9':
{
switch (ch2)
{
case 'C':
strToDH += "01";
break;
case 'D':
strToDH += "02";
break;
case '1':
strToDH += "03";
break;
case '2':
strToDH += "04";
break;
case '3':
strToDH += "05";
break;
case '4':
strToDH += "06";
break;
case '5':
strToDH += "07";
break;
case '6':
strToDH += "08";
break;
case '7':
strToDH += "09";
break;
case '8':
strToDH += "10";
break;
case '9':
strToDH += "11";
break;
default:
AfxMessageBox("出错");
return RET_FAILD;
break;
}
break;
}
case '2':
case '6':
case '8':
{
switch (ch2)
{
case '1':
strToDH += "12";
break;
case '2':
strToDH += "13";
break;
case '3':
strToDH += "14";
break;
case '4':
strToDH += "15";
break;
case '5':
strToDH += "16";
break;
default:
AfxMessageBox("出错");
return RET_FAILD;
break;
}
}
break;
default:
strTemp.Format("字符%c出错,不在处理范围内",ch1);
AfxMessageBox(strTemp);
return RET_FAILD;
break;
}
if (ch3 != '.') //当第 3 位不位 '.' 时
{
//将 strToDH字符串中内容写进DH字段中
vFieldName.SetString("DH");
vFieldValue.SetString(strToDH);
pRs->Update(vFieldName,vFieldValue);
vFieldName.Clear();
vFieldValue.Clear();
}
if (ch3 == '.' && (strFromDH.IsEmpty())) //如果第三位为 '.',且原DH字段为空
//则DH字段的第0位为从1循环到5
//并将当前记录复制并改写DH字段后重新写进表中
{
for (int i = 1; i <= 5; i++)
{
//2005.2.3 XDZ修改
//*************START*************
CString str;
strTemp = strToDH.Mid(1);
if(i > 2)
nTmp = 2*(i - 1);
else
nTmp = i;
chTemp = 48 + nTmp; //将数字 转化成字母
//*************END***************
CString strEmpty;
strToDH.Empty();
strToDH = chTemp;
strToDH += strTemp;
//2005.2.3 XDZ修改
//*************START*************
strEmpty.Format("SELECT * FROM crudeSPRING_LISEGA WHERE BH='%s%d%s' AND DH=%s",strFromBH.Mid(0,3),i,strFromBH.Mid(4),strToDH);
if(recOpen(pCon,pRs1,strEmpty,"记录查询") == RET_OK)
{
if(!pRs1->adoEOF)
{
pRs1->Delete(adAffectCurrent);
pRs1->Update();
}
pRs1->Close();
}
//*************END***************
strSql.Format("INSERT INTO crudeSPRING_LISEGA(CustomID,DH,BH,sizeH,SIZE2,SIZE4,SIZE3,SIZE5,sizeC,SIZE7,TJ,PMAX,Weight,sizeB,sizeD,sizedelta1,sizedelta2,sixzeW,sizeW,sizeH0,sizeN,sizeE,P1,PNUM1,PL1) \
SELECT CustomID,'%s',BH,sizeH,SIZE2,SIZE4,SIZE3,SIZE5,sizeC,SIZE7,TJ,PMAX,Weight,sizeB,sizeD,sizedelta1,sizedelta2,sixzeW,sizeW,sizeH0,sizeN,sizeE,P1,PNUM1,PL1 \
FROM crudeSPRING_LISEGA WHERE BH = '%s' AND DH IS NULL",strToDH,strFromBH);
conExec(pCon,strSql,"插入记录");
//2005.2.3 XDZ修改
//*************START*************
strSql.Empty();
str = strFromBH.Mid(0,3);
strTemp = strFromBH.Mid(4);
chTemp = 48 + i;
str += chTemp;
str += strTemp;
strSql.Format("UPDATE crudeSPRING_LISEGA SET BH='%s' WHERE BH='%s' AND DH=%s",str,strFromBH,strToDH);
conExec(pCon,strSql,"修改记录");
strSql.Empty();
str.Empty();
strTemp.Empty();
//*************END***************
}
}
pRs->MoveNext(); //继续读取下一条记录
}
if(pRs1->GetState() == adStateOpen)
pRs1->Close();
pRs->Close();
pRs1 = NULL;
return RET_OK;
//函数结束
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/uesoft/DBConvert.git
git@gitee.com:uesoft/DBConvert.git
uesoft
DBConvert
DBConvert
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385