3 Star 0 Fork 2

leegoobin/DBConvert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
csprdcz.cpp 24.85 KB
一键复制 编辑 原始数据 按行查看 历史
leegoobin 提交于 2018-11-13 14:06 . add AddpropertyToMateialMdb by ligb
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
// CSPRDcz.cpp : implementation file
//
#include "stdafx.h"
#include "dbconvert.h"
#include "CSPRDcz.h"
#include "CSPRDalian.h"
#include "dbconvertdlg.h"
#include "DBSetData.h"
extern CDBConvertApp theApp;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCSPRDcz dialog
CCSPRDcz::CCSPRDcz(CWnd* pParent /*=NULL*/)
: CDialog(CCSPRDcz::IDD, pParent)
{
//{{AFX_DATA_INIT(CCSPRDcz)
m_pathName = _T("");
//}}AFX_DATA_INIT
}
void CCSPRDcz::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCSPRDcz)
DDX_Text(pDX, IDC_EDIT1, m_pathName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCSPRDcz, CDialog)
//{{AFX_MSG_MAP(CCSPRDcz)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_GET_DBPATH, OnGetDbpath)
ON_BN_CLICKED(IDD_Create_CrudeCZ, OnCreateCrudeCZ)
ON_BN_CLICKED(IDC_Create_LugDiaofCSPRCZ, OnCreateLugDiaofCSPRCZ)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDCANCEL, &CCSPRDcz::OnBnClickedCancel)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCSPRDcz message handlers
bool CCSPRDcz::ConnectionDatamdb(_ConnectionPtr &pCon, CString strMdbName)
{
UpdateData(true);
if ( m_pathName.IsEmpty() )
{
AfxMessageBox("请设置数据库路径!");
return false;
}
pCon.CreateInstance(__uuidof(Connection));
CString conPRJDBSql = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source='"+m_pathName+"';PerSist Security Info=False";
try
{
pCon->Open(_bstr_t(conPRJDBSql),"","",-1);
}
catch(_com_error e)
{
AfxMessageBox( e.Description() );
return FALSE;
}
return true;
}
//生成常州恒力弹簧数据库
void CCSPRDcz::OnOK()
{
UpdateData(true);
_RecordsetPtr pRsA=NULL;//表:HDDIM_Primary_cz
_RecordsetPtr pRsA1=NULL;//表:HDDIM_Primary_cz的备份表
_RecordsetPtr pRsB=NULL;//表:HDcrudeCZ
_RecordsetPtr pRsDY=NULL;//CSPR_CZ_FieldNameSizeVar
CString strSQL=_T("");
int iRsCount=0;
CString ID=_T("");
int IsFirst=0;//是否是记录集中的第一条记录
pRsA1.CreateInstance(__uuidof(Recordset));
pRsA.CreateInstance(__uuidof(Recordset));
pRsB.CreateInstance(__uuidof(Recordset));
pRsDY.CreateInstance(__uuidof(Recordset));
long minDH=0;
long maxDH=0;
float fBmin=0.0;
float fBmax=0.0;
long DH=0;
CString BH=_T("");
CString INSTALLtype=_T("");
CString CustomID=_T("");
_variant_t key;
try
{
if ( !ConnectionDatamdb(m_pCon, "") )
{
return;
}
strSQL="drop table HDDIM_Primary_cz1";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
}
catch(_com_error e)
{
}
try
{
strSQL="select * into HDDIM_Primary_cz1 from HDDIM_Primary_cz";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("生成表(HDDIM_Primary_cz1)失败!");
}
try
{
strSQL="delete * from HDcrudeCZ";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="select * from HDDIM_Primary_CZ order by CustomID,minDH,maxDH,fBmin,fBmax";
pRsA->Open(_bstr_t(strSQL),(IDispatch *)m_pCon,adOpenStatic,\
adLockOptimistic,adCmdText);
strSQL="select * from HDDIM_Primary_CZ1 order by CustomID,minDH,maxDH,fBmin,fBmax";
pRsA1->Open(_bstr_t(strSQL),(IDispatch *)m_pCon,adOpenStatic,\
adLockOptimistic,adCmdText);
strSQL="select * from HDcrudeCZ";
pRsB->Open(_bstr_t(strSQL),(IDispatch *)m_pCon,adOpenStatic,\
adLockOptimistic,adCmdText);
strSQL="select * from CSPR_CZ_FieldNameSizeVar";
pRsDY->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
iRsCount=pRsA->GetRecordCount();
if(iRsCount>0)
{//表:HDDIM_Primary_CZ不为空(start)
for(pRsA->MoveFirst(),pRsA1->MoveFirst();!pRsA->adoEOF;pRsA->MoveNext())
{//对表(HDDIM_Primary_CZ)中的每一条记录进行处理(start)
if(IsFirst>1)
{
pRsA1->MoveNext();
}
IsFirst++;
minDH=vtoi(pRsA->GetCollect(_T("minDH")));
maxDH=vtoi(pRsA->GetCollect(_T("maxDH")));
if(maxDH<0||minDH<0||maxDH<minDH)
{
AfxMessageBox("输入有误!");
}
DH=0;
CustomID=vtos(pRsA->GetCollect("CustomID"));
//根据CustomID找与之对应的ID
ID=HDcrudeCZid(CustomID);
INSTALLtype=CustomID.Right(1);
for(DH=minDH;DH<=maxDH;DH++)
{//对每一条记录进行分解(start)
pRsB->AddNew();
BH.Format("%d",DH);
BH=CustomID.Left(CustomID.GetLength()-1)+"-"+BH+INSTALLtype;
pRsB->PutCollect(_T("BH"),_variant_t(BH));
pRsB->PutCollect(_T("DH"),_variant_t(DH));
pRsB->PutCollect(_T("ID"),_variant_t(ID));
pRsB->PutCollect(_T("INSTALLtype"),_variant_t(INSTALLtype));
//在表(CSPR_CZ_FieldNameSizeVar)选择当前弹簧需要导入的字段集
CCSPRDcz::FilterPRsDY(pRsDY,CustomID);
if(pRsDY->GetRecordCount()>0)
{
for(pRsDY->MoveFirst();!pRsDY->adoEOF;pRsDY->MoveNext())
{
key=pRsA->GetCollect(pRsDY->GetCollect("SourceFDName"));
if(key.vt==VT_NULL||key.vt==VT_EMPTY)
{
pRsB->PutCollect(pRsDY->GetCollect("FDName"),pRsA1->GetCollect(pRsDY->GetCollect("sourceFDName")));
}
else
{
pRsB->PutCollect(pRsDY->GetCollect("FDName"),pRsA->GetCollect(pRsDY->GetCollect("sourceFDName")));
}
}
}
//确定字段:fBmin和fBmax
key=pRsA->GetCollect("fBmin");
if(key.vt==VT_NULL||key.vt==VT_EMPTY)
{
fBmin=fBminFBmax(1,DH);
pRsB->PutCollect(_T("fBmin"),_variant_t(fBmin));
pRsB->PutCollect(_T("fBmax"),pRsA->GetCollect(_T("fBmax")));
}
else
{
key=pRsA->GetCollect("fBmax");
if(key.vt==VT_NULL||key.vt==VT_EMPTY)
{
fBmax=fBminFBmax(0,DH);
pRsB->PutCollect(_T("fBmin"),pRsA->GetCollect(_T("fBmin")));
pRsB->PutCollect(_T("fBmax"),_variant_t(fBmax));
}
}
pRsB->Update();
}//对每一条记录进行分解(end)
}//对表(HDDIM_Primary_CZ)中的每一条记录进行处理(end)
}//表:HDDIM_Primary_CZ不为空(end)
if(pRsA1->State==adStateOpen)
{
pRsA1->Close();
}
WriteWeight(pRsB);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
UpdateData(false);
}
//在表(CSPR_CZ_FieldNameSizeVar)选择当前弹簧需要导入的字段集
int CCSPRDcz::FilterPRsDY(_RecordsetPtr &pRs, CString str)
{
int iPRsCount=0;
CString strSQL=_T("");
for(int i=0;i<=11;i++)
{
pRs->Filter="";
if(i>0)
{
strSQL.Format("%d",i);
}
strSQL="CustomID"+strSQL;
strSQL+="= '"+str+"'";
pRs->Filter=_variant_t(strSQL);
iPRsCount=pRs->GetRecordCount();
if(iPRsCount>0)
{
break;
}
}
return iPRsCount;
}
//根据CustomID找与之对应的ID
CString CCSPRDcz::HDcrudeCZid(CString CustomID)
{
CString ID=_T("");
CString strSQL=_T("");
_RecordsetPtr pRs=NULL;
pRs.CreateInstance(__uuidof(Recordset));
strSQL="select * from HDcrudeCZid";
try
{
pRs->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
strSQL="CustomID='"+CustomID+"'";
pRs->Filter=_variant_t(strSQL);
if(pRs->GetRecordCount()>0)
{
ID=vtos(pRs->GetCollect("ID"));
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
if(pRs->State==adStateOpen)
{
pRs->Close();
}
return ID;
}
//确定字段:fBmin或者fBmax的值
//当flag=0;val等于已知的fBmin
//当flag=1;val等于已知的fBmax
float CCSPRDcz::fBminFBmax(int flag,long DH)
{
float value=0.0;
CString strDH=_T("");
strDH.Format("%d",DH);
_RecordsetPtr pRs=NULL;
pRs.CreateInstance(__uuidof(Recordset));
CString strSQL=_T("");
strSQL="select * from DisplacementRange where ";
strSQL+="minDH<="+strDH+" and maxDH>="+strDH+"";
try
{
pRs->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
int iCount=pRs->GetRecordCount();
if(iCount>0)
{
if(flag)
{//已知的fBmax
value=vtof(pRs->GetCollect(_T("fBmin")));
}
else
{
value=vtof(pRs->GetCollect(_T("fBmax")));
}
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
return value;
}
//写弹簧的重量
void CCSPRDcz::WriteWeight(_RecordsetPtr &pRs)
{
_RecordsetPtr pRs1=NULL;
_RecordsetPtr pRsWeight=NULL;
CString strSQL=_T("");
long DH=0;
float x=0.0;
float y=0.0;
float fBmin=0.0;
float fBmax=0.0;
float fBminWeight=0.0;
float fBmaxWeight=0.0;
float Weight=0.0;
float sizeH=0.0;
float pp=0.0;
float T=0.0;
float D=0.0;
CString CustomID=_T("");
CString strFields=_T("");
pRs1.CreateInstance(__uuidof(Recordset));
pRsWeight.CreateInstance(__uuidof(Recordset));
try
{
strSQL="drop table HDcrudeCZ1";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
}
catch(_com_error e)
{
}
if(pRs->State==adStateOpen)
{
pRs->Close();
}
try
{
strSQL="select * into HDcrudeCZ1 from HDcrudeCZ";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="delete * from HDcrudeCZ";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
try
{
strSQL="select * from HDcrudeCZ1 order by CustomID,dh,fBmin,fBmax";
pRs1->Open(_bstr_t(strSQL),(IDispatch *)m_pCon,adOpenStatic,\
adLockOptimistic,adCmdText);
strSQL="select * from HDcrudeCZ";
pRs->Open(_bstr_t(strSQL),(IDispatch *)m_pCon,adOpenStatic,\
adLockOptimistic,adCmdText);
strSQL="select * from HD_Weight_CZ";
pRsWeight->Open(_bstr_t(strSQL),(IDispatch *)m_pCon,adOpenStatic,\
adLockOptimistic,adCmdText);
for(pRs1->MoveFirst();!pRs1->adoEOF;pRs1->MoveNext())
{
DH=vtoi(pRs1->GetCollect("dh"));
CustomID=vtos(pRs1->GetCollect("CustomID"));
strFields=CustomID.Right(2);
if(CustomID=="80VF")
{
strFields="80v";
}
if(CustomID=="58VES")
{
strFields="ve";
}
fBmin=vtof(pRs1->GetCollect("fBmin"));
fBmax=vtof(pRs1->GetCollect("fBmax"));
for(int i=0;i<2;i++)
{//是否对记录进行分解(start)
pRs->AddNew();
//给x,y赋值(start)
x=0.0;
y=0.0;
if(DH<=83)
{
if(CustomID=="58VA"||CustomID=="58VB"||CustomID=="58VC"||CustomID=="58VE"||CustomID=="58VES"||CustomID=="58VG")
{
x=(DH<=74)?50:100;
y=(DH<=74)?55:75;
}
if(CustomID=="58HA"||CustomID=="58HB"||CustomID=="58HC"||CustomID=="58HD"||CustomID=="58HE")
{
x=(DH<=74)?50:100;
y=(DH<=74)?55:75;
}
}
else
{
if(CustomID=="58VA"||CustomID=="58VB"||CustomID=="58VC")
{
x=(DH<=94)?100:200;
y=95;
}
if(CustomID=="58HA"||CustomID=="58HB"||CustomID=="58HC"||CustomID=="58HE")
{
x=(DH<=94)?100:200;
y=95;
}
}
//给x,y赋值(end)
strSQL.Format("minDH<=%d and maxDH>=%d",DH,DH);
pRsWeight->Filter="";
pRsWeight->Filter=_variant_t(strSQL);
if(pRsWeight->GetRecordCount()>0)
{
fBminWeight=vtof(pRsWeight->GetCollect("fBmin"));
fBmaxWeight=vtof(pRsWeight->GetCollect("fBmax"));
if(fBmin<=fBminWeight)
{//当fBmin<=fBminWeight (start)
if(fBmax<=fBminWeight)
{//第一种情况(start)
strFields+="a";
i++;
if(CustomID=="80VF")
{
strFields="80v";
}
pRs->PutCollect(_T("fBmin"),pRs1->GetCollect(_variant_t("fBmin")));
pRs->PutCollect(_T("fBmax"),pRs1->GetCollect(_variant_t("fBmax")));
}//第一种情况(end)
else
{
strFields+="a";
if(CustomID=="80VF")
{
strFields="80v";
}
pRs->PutCollect(_T("fBmin"),pRs1->GetCollect(_variant_t("fBmin")));
pRs->PutCollect(_T("fBmax"),_variant_t(fBminWeight));
fBmin=fBmaxWeight;
}
}//当fBmin<=fBminWeight (end)
else
{//当fBmin>fBminWeight (start)
strFields+="b";
i++;
if(CustomID=="80VF")
{
strFields="80v";
}
pRs->PutCollect(_T("fBmin"),pRs1->GetCollect(_variant_t("fBmin")));
pRs->PutCollect(_T("fBmax"),pRs1->GetCollect(_variant_t("fBmax")));
}//当fBmin>fBminWeight (end)
pRs->PutCollect(_T("Weight"),pRsWeight->GetCollect(_variant_t(strFields)));
}
pRs->PutCollect(_T("CustomID"),pRs1->GetCollect(_T("CustomID")));
pRs->PutCollect(_T("ID"),pRs1->GetCollect(_T("ID")));
pRs->PutCollect(_T("Group"),pRs1->GetCollect(_T("Group")));
pRs->PutCollect(_T("DH"),pRs1->GetCollect(_T("DH")));
pRs->PutCollect(_T("BH"),pRs1->GetCollect(_T("BH")));
pRs->PutCollect(_T("INSTALLtype"),pRs1->GetCollect(_T("INSTALLtype")));
pRs->PutCollect(_T("A"),pRs1->GetCollect(_T("A")));
pRs->PutCollect(_T("C"),pRs1->GetCollect(_T("C")));
pRs->PutCollect(_T("D"),pRs1->GetCollect(_T("D")));
pRs->PutCollect(_T("F"),pRs1->GetCollect(_T("F")));
pRs->PutCollect(_T("G"),pRs1->GetCollect(_T("G")));
pRs->PutCollect(_T("H"),pRs1->GetCollect(_T("H")));
pRs->PutCollect(_T("K"),pRs1->GetCollect(_T("K")));
pRs->PutCollect(_T("L"),pRs1->GetCollect(_T("L")));
pRs->PutCollect(_T("M"),pRs1->GetCollect(_T("M")));
pRs->PutCollect(_T("N"),pRs1->GetCollect(_T("N")));
pRs->PutCollect(_T("P"),pRs1->GetCollect(_T("P")));
pRs->PutCollect(_T("PP"),pRs1->GetCollect(_T("PP")));
pRs->PutCollect(_T("S"),pRs1->GetCollect(_T("S")));
pRs->PutCollect(_T("T"),pRs1->GetCollect(_T("T")));
pRs->PutCollect(_T("U"),pRs1->GetCollect(_T("U")));
pRs->PutCollect(_T("W"),pRs1->GetCollect(_T("W")));
if(x>0.0)
{
pRs->PutCollect(_T("X"),_variant_t(x));
}
if(y>0.0)
{
pRs->PutCollect(_T("Y"),_variant_t(y));
}
pRs->PutCollect(_T("YY"),pRs1->GetCollect(_T("YY")));
pRs->PutCollect(_T("AY"),pRs1->GetCollect(_T("AY")));
pRs->PutCollect(_T("BY"),pRs1->GetCollect(_T("BY")));
pRs->PutCollect(_T("E"),pRs1->GetCollect(_T("E")));
//确定sizeH的值(start)
sizeH=vtof(pRs1->GetCollect("E"));
pp=vtof(pRs1->GetCollect("pp"));
T=vtof(pRs1->GetCollect("T"));
if(CustomID=="58VA"||CustomID=="58HA")
{
sizeH=sizeH+pp;
}
if((CustomID=="58VB"||CustomID=="58VC")&&DH>=84)
{
sizeH=sizeH+T;
}
if(CustomID=="58VE"||CustomID=="58VG"||CustomID=="58HD"||CustomID=="58HE")
{
sizeH=sizeH;
}
if(CustomID=="58VES")
{
D=vtof(pRs1->GetCollect(_T("D")));
sizeH=-(D-sizeH);
}
//确定sizeH的值(end)
pRs->PutCollect(_T("sizeH"),_variant_t(sizeH));
pRs->PutCollect(_T("sizeC"),pRs1->GetCollect(_T("sizeC")));
pRs->PutCollect(_T("FJmin"),pRs1->GetCollect(_T("FJmin")));
pRs->PutCollect(_T("FJmax"),pRs1->GetCollect(_T("FJmax")));
pRs->PutCollect(_T("GL"),pRs1->GetCollect(_T("GL")));
pRs->PutCollect(_T("I"),pRs1->GetCollect(_T("I")));
pRs->PutCollect(_T("R"),pRs1->GetCollect(_T("R")));
pRs->PutCollect(_T("O"),pRs1->GetCollect(_T("O")));
pRs->PutCollect(_T("B"),pRs1->GetCollect(_T("B")));
pRs->PutCollect(_T("Z"),pRs1->GetCollect(_T("Z")));
pRs->PutCollect(_T("P1"),pRs1->GetCollect(_T("P1")));
pRs->PutCollect(_T("PNUM1"),pRs1->GetCollect(_T("PNUM1")));
pRs->PutCollect(_T("PL1"),pRs1->GetCollect(_T("PL1")));
pRs->Update();
}//是否对记录进行分解(end)
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
//生成表:LugDiaofCSPRcz
void CCSPRDcz::OnButton2()
{
CString strSQL=_T("");
_RecordsetPtr pRsA=NULL;
_RecordsetPtr pRsA1=NULL;
int start=0;//开始位置
int end=0;//终点位置
_RecordsetPtr pRsB=NULL;
_variant_t key;
_variant_t key1;
long minDH=0;
long maxDH=0;
long Pmax=0;
long FJmax=0;
long FJmin=0;
CString CustomID1=_T("");
CString CustomID=_T("");
pRsA.CreateInstance(__uuidof(Recordset));
pRsB.CreateInstance(__uuidof(Recordset));
pRsA1.CreateInstance(__uuidof(Recordset));
try
{
if ( !ConnectionDatamdb(m_pCon, "") )
{
return;
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
try
{
strSQL="delete * from LugDiaofCSPRcz";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
try
{
strSQL="select * from LugDiaofCSPRcz";
pRsB->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
strSQL="select * from sourceRODDiaOfCSPRcz";
pRsA->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
for(pRsA->MoveFirst();!pRsA->adoEOF;pRsA->MoveNext())
{//对每一条记录进行处理(start)
start=0;
end=0;
CustomID1=vtos(pRsA->GetCollect("CustomID1"));
CustomID1+=" ";
minDH=vtoi(pRsA->GetCollect("minDH"));
maxDH=vtoi(pRsA->GetCollect("maxDH"));
while(1)
{//对CustomID1中每项进行分解为多条记录(start)
end=CustomID1.Find(_T(" "),start);
if(end!=-1)
{
CustomID=CustomID1.Mid(start,end-start);
start=end+1;
CustomID.TrimLeft();
CustomID.TrimRight();
if(CustomID!="")
{
pRsB->AddNew();
pRsB->PutCollect(_T("Pmax"),pRsA->GetCollect(_T("Pmax")));
pRsB->PutCollect(_T("PmaxKgf"),_variant_t( vtof(pRsA->GetCollect(_T("Pmax")))/9.8) );
pRsB->PutCollect(_T("FiJ"),pRsA->GetCollect(_T("FiJ")));
pRsB->PutCollect(_T("CustomID"),_variant_t(CustomID));
pRsB->PutCollect(_T("minDH"),pRsA->GetCollect(_T("minDH")));
pRsB->PutCollect(_T("maxDH"),pRsA->GetCollect(_T("maxDH")));
if(CustomID=="58VB"||CustomID=="58VC"||CustomID=="58HB"||CustomID=="58HC")
{//2
pRsB->PutCollect(_T("FiK"),pRsA->GetCollect(_T("FiK")));
pRsB->PutCollect(_T("R"),pRsA->GetCollect(_T("R")));
pRsB->PutCollect(_T("I"),pRsA->GetCollect(_T("I")));
if(maxDH<=83)
{
pRsB->PutCollect(_T("T"),pRsA->GetCollect(_T("T")));
}
if(CustomID=="58VC"||CustomID=="58HC")
{
pRsB->PutCollect(_T("S"),pRsA->GetCollect(_T("S")));
}
if(CustomID=="58HB"||CustomID=="58HC"||((CustomID=="58VB"||CustomID=="58VC")&&minDH>=84) )
{
pRsB->PutCollect(_T("W"),pRsA->GetCollect(_T("W")));
}
}//2
pRsB->Update();
}
}
else
{
break;
}
}//对CustomID1中每项进行分解为多条记录(end)
}//对每一条记录进行处理(end)
if(pRsA->State==adStateOpen)
{
pRsA->Close();
}
if(pRsB->State==adStateOpen)
{
pRsB->Close();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
try
{
strSQL="drop table LugDiaofCSPRcz1";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
}
catch(_com_error e)
{
}
try
{//对同一弹簧的值进行集中(start)
strSQL="select * into LugDiaofCSPRcz1 from LugDiaofCSPRcz where (CustomID='58VB' OR CustomID='58VC') and T IS NULL";
strSQL+=" and maxDH<=83";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="delete * from LugDiaofCSPRcz where (CustomID='58VB' OR CustomID='58VC') and T IS NULL";
strSQL+=" and maxDH<=83";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="select * from LugDiaofCSPRcz where (CustomID='58VB' or CustomID='58VC') and maxDH<=83";
pRsB->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
strSQL="select * from LugDiaofCSPRcz1";
pRsA->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
for(pRsB->MoveFirst();!pRsB->adoEOF;pRsB->MoveNext())
{
CustomID=vtos(pRsB->GetCollect(_T("CustomID")));
minDH=vtoi(pRsB->GetCollect(_T("minDH")));
maxDH=vtoi(pRsB->GetCollect(_T("maxDH")));
Pmax=vtoi(pRsB->GetCollect(_T("Pmax")));
strSQL.Format("CustomID=%s and minDH<=%d and maxDH>=%d and Pmax=%d",CustomID,minDH,maxDH,Pmax);
pRsA->Filter="";
pRsA->Filter=_variant_t(strSQL);
int iCount=pRsA->GetRecordCount();
if(iCount>0)
{
pRsA->MoveFirst();
}
for(;!pRsA->adoEOF;pRsA->MoveNext())
{
key=pRsA->GetCollect(_T("FiJ"));
if(!(key.vt==VT_NULL||key.vt==VT_EMPTY))
{
key1=pRsB->GetCollect(_T("FiJ"));
if(key1.vt==VT_NULL||key1.vt==VT_EMPTY)
{
pRsB->PutCollect(_T("FiJ"),pRsA->GetCollect(_T("FiJ")));
}
}
key=pRsA->GetCollect(_T("FiK"));
if(!(key.vt==VT_NULL||key.vt==VT_EMPTY))
{
key1=pRsB->GetCollect(_T("Fik"));
if(key1.vt==VT_NULL||key1.vt==VT_EMPTY)
{
pRsB->PutCollect(_T("FiK"),key);
}
}
key=pRsA->GetCollect(_T("R"));
if(!(key.vt==VT_NULL||key.vt==VT_EMPTY))
{
key1=pRsB->GetCollect(_T("R"));
if(key1.vt==VT_NULL||key1.vt==VT_EMPTY)
{
pRsB->PutCollect(_T("R"),key);
}
}
key=pRsA->GetCollect(_T("i"));
if(!(key.vt==VT_NULL||key.vt==VT_EMPTY))
{
key1=pRsB->GetCollect(_T("i"));
if(key1.vt==VT_NULL||key1.vt==VT_EMPTY)
{
pRsB->PutCollect(_T("i"),key);
}
}
key=pRsA->GetCollect(_T("S"));
if(!(key.vt==VT_NULL||key.vt==VT_EMPTY))
{
key1=pRsB->GetCollect(_T("S"));
if(key1.vt==VT_NULL||key1.vt==VT_EMPTY)
{
pRsB->PutCollect(_T("S"),key);
}
}
key=pRsA->GetCollect(_T("W"));
if(!(key.vt==VT_NULL||key.vt==VT_EMPTY))
{
key1=pRsB->GetCollect(_T("W"));
if(key1.vt==VT_NULL||key1.vt==VT_EMPTY)
{
pRsB->PutCollect(_T("W"),key);
}
}
}
}
}//对同一弹簧的值进行集中(end)
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
try
{//对58HD,58HE,58VEs,58VE的记录重新进行分解同时给Fik赋值(start)
if(pRsA->State==adStateOpen)
{
pRsA->Close();
}
if(pRsB->State==adStateOpen)
{
pRsB->Close();
}
strSQL="drop table LugDiaofCSPRcz1";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="select * into LugDiaofCSPRcz1 from LugDiaofCSPRcz where (CustomID='58VE'";
strSQL+=" or CustomID='58VES' or CustomID='58HE' or CustomID='58HD') and maxDH<=83";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="delete * from LugDiaofCSPRcz where (CustomID='58VE' or CustomID='58VES' or ";
strSQL+="CustomID='58HE' or CustomID='58HD') and maxDH<=83";
m_pCon->Execute(_bstr_t(strSQL),NULL,adCmdText);
strSQL="select * from LugDiaofCSPRcz1 order by CustomID,Pmax";
pRsA->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
strSQL="select distinct CustomID,minDH,maxDH,K,FJmax,FJmin from HDDIM_Primary_cz ";
strSQL+=" where ( CustomID='58VE' or CustomID='58VES' or CustomID='58HE' or CustomID='58HD') and ";
strSQL+=" maxDH<=83 and GL IS NOT NULL order by CustomID,minDH";
pRsA1->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
strSQL="select * from LugDiaofCSPRcz order by CustomID";
pRsB->Open(_bstr_t(strSQL),(IDispatch*)m_pCon,adOpenStatic,adLockOptimistic,adCmdText);
for(pRsA1->MoveFirst();!pRsA1->adoEOF;pRsA1->MoveNext())
{
CustomID=vtos(pRsA1->GetCollect(_T("CustomID")));
FJmax=vtoi(pRsA1->GetCollect("FJmax"));
FJmin=vtoi(pRsA1->GetCollect("FJmin"));
strSQL.Format("CustomID='%s' and FiJ<=%d and FiJ>=%d",CustomID,FJmax,FJmin);
pRsA->Filter="";
pRsA->Filter=_variant_t(strSQL);
int ii=pRsA->GetRecordCount();
for(pRsA->MoveFirst();!pRsA->adoEOF;pRsA->MoveNext())
{
pRsB->AddNew();
pRsB->PutCollect(_T("CustomID"),pRsA1->GetCollect("CustomID"));
pRsB->PutCollect(_T("minDH"),pRsA1->GetCollect("minDH"));
pRsB->PutCollect(_T("maxDH"),pRsA1->GetCollect("maxDH"));
pRsB->PutCollect(_T("Fik"),pRsA1->GetCollect("K"));
pRsB->PutCollect(_T("FiJ"),pRsA->GetCollect("FiJ"));
pRsB->PutCollect(_T("R"),pRsA->GetCollect("R"));
pRsB->PutCollect(_T("I"),pRsA->GetCollect("I"));
pRsB->PutCollect(_T("T"),pRsA->GetCollect("T"));
pRsB->PutCollect(_T("S"),pRsA->GetCollect("S"));
pRsB->PutCollect(_T("W"),pRsA->GetCollect("W"));
pRsB->PutCollect(_T("PmaxKgf"),pRsA->GetCollect("PmaxKgf"));
pRsB->PutCollect(_T("Pmax"),pRsA->GetCollect("Pmax"));
pRsB->Update();
}
}
if(pRsA->State==adStateOpen)
{
pRsA->Close();
}
if(pRsA1->State==adStateOpen)
{
pRsA1->Close();
}
if(pRsB->State==adStateOpen)
{
pRsB->Close();
}
}//对58HD,58HE,58VEs,58VE的记录重新进行分解同时给Fik赋值(end)
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
AfxMessageBox("生成表(LugDiaofCSPRcz)成功!");
}
//不处理较复杂,修改始数据
void CCSPRDcz::WritefBmax()
{
CString strFilter=_T("");
_variant_t key;
long minDH=0;
long maxDH=0;
minDH=vtoi(m_pRcz->GetCollect(_T("minDH")));
maxDH=vtoi(m_pRcz->GetCollect(_T("maxDH")));
strFilter.Format("minDH<=%d and maxDH>=%d",minDH,maxDH);
for(int i=0;i<4;i++)
{
if(i==1)
{
}
m_pRcz->Filter="";
m_pRcz->Filter=_variant_t(strFilter);
if(!m_pRcz->adoEOF)
{
key=m_pRes->GetCollect(_T("fBmax"));
if(key.vt==VT_NULL || key.vt==VT_EMPTY)
{
m_pRes->PutCollect(_T("fBmax"),m_pRD->GetCollect(_T("fBmax")));
}
key=m_pRes->GetCollect(_T("fBmin"));
if(key.vt==VT_NULL || key.vt==VT_EMPTY)
{
m_pRes->PutCollect(_T("fBmin"),m_pRD->GetCollect(_T("fBmin")));
}
}
}
}
BOOL CCSPRDcz::OnInitDialog()
{
InitDBPath();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCSPRDcz::InitDBPath()
{
CString strDBName = ((CDBConvertDlg*)(theApp.m_pMainWnd))->GetDBPath();
if ( !strDBName.IsEmpty() )
{
m_pathName = strDBName;
}
UpdateData( FALSE );
}
void CCSPRDcz::OnGetDbpath()
{
InitDBPath();
}
void CCSPRDcz::OnCreateCrudeCZ()
{
InitEnvironVar();
CDBSetData::Instance().CreateHDCrude();
CDBSetData::Instance().WriteWeight();
}
void CCSPRDcz::OnCreateLugDiaofCSPRCZ()
{
InitEnvironVar();
CDBSetData::Instance().CreateRODDiaofCSPR();
}
void CCSPRDcz::InitEnvironVar()
{
UpdateData( FALSE );
if ( m_pathName.IsEmpty() )
{
AfxMessageBox("请选择数据库路径!");
return;
}
CDBSetData::Instance().SetStandard( _T("CZ") );
CDBSetData::Instance().SetDBPath( m_pathName );
}
void CCSPRDcz::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
OnCancel();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/uesoft/DBConvert.git
git@gitee.com:uesoft/DBConvert.git
uesoft
DBConvert
DBConvert
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385