📄 newdlg.cpp
字号:
void CNewDlg::OnOK()
{
CDialog::OnOK();
}
void CNewDlg::GetCustomerInfo(CString strCustomerName)
{
try
{
CString strBuf;
strBuf.Format("SELECT * FROM tb_Customer WHERE CustomerName = '%s'", strCustomerName);
_bstr_t CommText;
CommText = strBuf;
_variant_t vRecordsAffected;
OperDb.pRecordset = OperDb.pConn->Execute(CommText, &vRecordsAffected, adCmdText);
if(vRecordsAffected.lVal==0) return ;
OperDb.pRecordset->MoveFirst();
_variant_t vtGet = OperDb.pRecordset->GetCollect("IdIndex");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strIdIndex = strBuf;
}
vtGet = OperDb.pRecordset->GetCollect("CustomerCode");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strCustomerCode = strBuf;
}
vtGet = OperDb.pRecordset->GetCollect("ClassCode");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strClassCode = strBuf;
}
vtGet = OperDb.pRecordset->GetCollect("CustomerAddress");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strCustomerAddress = strBuf;
}
vtGet = OperDb.pRecordset->GetCollect("CustomerLinkMan");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strCustomerLinkMan = strBuf;
}
vtGet = OperDb.pRecordset->GetCollect("CustomerTelephone");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strCustomerTelephone = strBuf;
}
vtGet = OperDb.pRecordset->GetCollect("Memo");
if(vtGet.vt != NULL)
{
strBuf.Format("%s", OperDb.CrackStrVariant(vtGet));
m_CustomerInfo.m_strMemo = strBuf;
}
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// AfxMessageBox(e.Description());
return ;
}
catch(...)
{
return ;
}
}
bool CNewDlg::WriteToCard()
{
return true;
}
void CNewDlg::OnButtonWrCard()
{
// TODO: Add extra validation here
UpdateData(true);
//取得产品型号代码
m_strProductTypeCode = GetProductTypeCode(m_strMType);
CString strDescription;
CString strTimeLimit;
strTimeLimit.Format("%04d-%02d-%02d 00:00:00", m_timeRepairEnd.GetYear(),
m_timeRepairEnd.GetMonth(), m_timeRepairEnd.GetDay());
// GetCustomerInfo(m_strCustomer);
int nYear = (m_timeRepairEnd.GetYear()-2000);
int nMonth = m_timeRepairEnd.GetMonth();
int nYM = (nYear*16)+ nMonth;
int nDay = m_timeRepairEnd.GetDay();
_ParameterPtr pParamProductCode;//ProductCode
_ParameterPtr pParamProductTypeCode;//ProductTypeCode
_ParameterPtr pParamRegisterCode;//RegisterCode
_ParameterPtr pParamCustomerCode;//CustomerCode
_ParameterPtr pParamDescriptions;//Descriptions
_ParameterPtr pParamDateRegist;//DateRegist
_ParameterPtr pParamIdIndex;//IdIndex
_ParameterPtr pParamPlanRepairDate;//PlanRepairDate
_ParameterPtr pParamMemo;//Memo
// ProductCode
pParamProductCode.CreateInstance("ADODB.Parameter");
pParamProductCode->Name="ProductCode"; //存储过程的参数1
pParamProductCode->Type=adChar; //
pParamProductCode->Size=50; //
pParamProductCode->Direction=adParamInput;//表明是输入参数
pParamProductCode->Value=_variant_t(m_strProductCode);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamProductCode);
//ProductTypeCode
pParamProductTypeCode.CreateInstance("ADODB.Parameter");
pParamProductTypeCode->Name="ProductTypeCode"; //存储过程的参数1
pParamProductTypeCode->Type=adChar; //
pParamProductTypeCode->Size=50; //
pParamProductTypeCode->Direction=adParamInput;//表明是输入参数
pParamProductTypeCode->Value=_variant_t(m_strProductTypeCode);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamProductTypeCode);
//RegisterCode
pParamRegisterCode.CreateInstance("ADODB.Parameter");
pParamRegisterCode->Name="RegisterCode"; //存储过程的参数1
pParamRegisterCode->Type=adChar; //
pParamRegisterCode->Size=20; //
pParamRegisterCode->Direction=adParamInput;//表明是输入参数
pParamRegisterCode->Value=_variant_t(m_strOperatorCode);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamRegisterCode);
//CustomerCode
pParamCustomerCode.CreateInstance("ADODB.Parameter");
pParamCustomerCode->Name="CustomerCode"; //存储过程的参数1
pParamCustomerCode->Type=adChar; //
pParamCustomerCode->Size=50; //
pParamCustomerCode->Direction=adParamInput;//表明是输入参数
pParamCustomerCode->Value=_variant_t(m_CustomerInfo.m_strCustomerCode);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamCustomerCode);
//Descriptions
pParamDescriptions.CreateInstance("ADODB.Parameter");
pParamDescriptions->Name="Descriptions"; //存储过程的参数1
pParamDescriptions->Type=adChar; //
pParamDescriptions->Size=50; //
pParamDescriptions->Direction=adParamInput;//表明是输入参数
pParamDescriptions->Value=_variant_t(m_Descriptions);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamDescriptions);
//DateRegist
pParamDateRegist.CreateInstance("ADODB.Parameter");
pParamDateRegist->Name="DateCustomerAsk"; //存储过程的参数1
pParamDateRegist->Type=adChar; //
pParamDateRegist->Size=50; //
pParamDateRegist->Direction=adParamInput;//表明是输入参数
pParamDateRegist->Value=_variant_t(strTimeLimit);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamDateRegist);
//PlanRepairDate
pParamPlanRepairDate.CreateInstance("ADODB.Parameter");
pParamPlanRepairDate->Name="PlanRepairDate"; //存储过程的参数1
pParamPlanRepairDate->Type=adChar; //
pParamPlanRepairDate->Size=50; //
pParamPlanRepairDate->Direction=adParamInput;//表明是输入参数
pParamPlanRepairDate->Value=_variant_t(m_strPlanRepairDate);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamPlanRepairDate);
//Memo
pParamMemo.CreateInstance("ADODB.Parameter");
pParamMemo->Name="Memo"; //存储过程的参数1
pParamMemo->Type=adChar; //
pParamMemo->Size=50; //
pParamMemo->Direction=adParamInput;//表明是输入参数
pParamMemo->Value=_variant_t(m_strMemo);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamMemo);
//IdIndex
pParamIdIndex.CreateInstance("ADODB.Parameter");
pParamIdIndex->Name="IdIndex"; //存储过程的参数1
pParamIdIndex->Type=adChar; //
pParamIdIndex->Size=50; //
pParamIdIndex->Direction=adParamOutput;//表明是输出参数
OperDb.pCommand->Parameters->Append(pParamIdIndex);
OperDb.pCommand->ActiveConnection = OperDb.pConn;
OperDb.pCommand->CommandText="sp_AddRepair"; //存储过程的名字
OperDb.pCommand->CommandType=adCmdStoredProc;//表示为存储过程adCmdStoredProc
//执行,获得结果
OperDb.pCommand->Execute(NULL, NULL, adCmdStoredProc);
//将值返回
CString strResult = (char *)_bstr_t(pParamIdIndex->Value);
int nResult =_ttoi(strResult);
if (nResult == 0)
{
MessageBox("保存失败");
return ;
}
else
MessageBox("保存成功");
while(OperDb.pCommand->Parameters->GetCount()!=0)
{
_variant_t id = (long)0;
OperDb.pCommand->Parameters->Delete(id);
}
/*
增加由
m_strProductCode ->m_strMSN 的过程
*/
CString m_strMSN = _T("0");
//产品型号\最迟修复(年月)\最迟修复(日)\工序状态\客户\维修ID号\序列号\故障现象
CString strBuf;
strBuf.Format("%04X%02X%02X%04X%04X%08X%08X\08X", _ttoi(m_strProductTypeCode), nYM,nDay,40,atoi(m_CustomerInfo.m_strIdIndex),nResult,atoi(m_strMSN),0);
//写卡
//从ini配置文件中获取通讯参数
CIniFile iniFile("System.ini") ;
CString strComType = iniFile.GetKeyValue("CardReader","ComType");
LPTSTR pComType = strComType.GetBuffer(0);
int iComType = atoi(pComType);
strComType.ReleaseBuffer();
CString strParam = iniFile.GetKeyValue("CardReader","Param");
LPTSTR pParam = strParam.GetBuffer(0);
strParam.ReleaseBuffer();
long hConnect = OpenConnect(iComType,pParam);
// long hConnect = OpenConnect(0, "1/19200/8/NO/1/0");
if(hConnect <= 0)
{
OperDb.DelRec("tb_Repair","RepairID",strResult);
MessageBox("串口未打开!请检查串口");
return ;
}
char chUID[100], chRecUID[100];
BYTE byAFI, byDSFID, byIC_Ref;
int nBlockSize, nBlocks;
int lRet = Prm_8152Lib_ReadTagSystemInfo(hConnect, 0x00, 0x00, chUID, chRecUID, byAFI, byDSFID,
nBlockSize, nBlocks, byIC_Ref);
if(lRet > 0)
{
//产品型号\最迟修复(年月)\最迟修复(日)\工序状态\客户\维修ID号\序列号\故障现象
BYTE byBeginBlock = 0x01, byBlocks = 0x05, byDBSize = 0x04, byDataFormat = 0x00;
BOOL lWrite = Prm_8152Lib_WriteMultiBlocks(hConnect, 0x00, 0x00, chRecUID, byBeginBlock,
byBlocks, byDBSize, strBuf.GetBuffer(0), byDataFormat);
strBuf.ReleaseBuffer();
if (lWrite)
{
ClearInput();
MessageBox("写卡成功");
}
else
{
OperDb.DelRec("tb_Repair","RepairID",strResult);
MessageBox("写卡失败");
}
}
else
{
OperDb.DelRec("tb_Repair","RepairID",strResult);
MessageBox("此卡片未初始化,请查看卡片中是否还有有用数据。");
CloseConnect(hConnect);
}
}
void CNewDlg::GetProductInfo(CString strProductCode)
{
_ParameterPtr pParamProductCode;//ProductCode
_ParameterPtr pParamProductClassName;//ProductClassName
_ParameterPtr pParamProductName ;//ProductName
_ParameterPtr pParamProductTypeName;//ProductTypeName
_ParameterPtr pParamDateTimeSale; //DateTimeSale
_ParameterPtr pParamResult;//Result
// ProductCode
pParamProductCode.CreateInstance("ADODB.Parameter");
pParamProductCode->Name="ProductCode"; //存储过程的参数1
pParamProductCode->Type=adChar; //
pParamProductCode->Size=50; //
pParamProductCode->Direction=adParamInput;//表明是输入参数
pParamProductCode->Value=_variant_t(strProductCode);//CString->_variant_t后赋值
OperDb.pCommand->Parameters->Append(pParamProductCode);
//ProductClassName
pParamProductClassName.CreateInstance("ADODB.Parameter");
pParamProductClassName->Name="ProductClassName"; //存储过程的参数1
pParamProductClassName->Type=adChar; //
pParamProductClassName->Size=50; //
pParamProductClassName->Direction=adParamOutput;//表明是输入参数
OperDb.pCommand->Parameters->Append(pParamProductClassName);
//ProductName
pParamProductName.CreateInstance("ADODB.Parameter");
pParamProductName->Name="ProductName"; //存储过程的参数1
pParamProductName->Type=adChar; //
pParamProductName->Size=50; //
pParamProductName->Direction=adParamOutput;//表明是输入参数
OperDb.pCommand->Parameters->Append(pParamProductName);
//ProductTypeName
pParamProductTypeName.CreateInstance("ADODB.Parameter");
pParamProductTypeName->Name="ProductTypeName"; //存储过程的参数1
pParamProductTypeName->Type=adChar; //
pParamProductTypeName->Size=50; //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -