📄 dlgnccode.cpp
字号:
// DLGNCCODE.cpp : implementation file
//
#include "stdafx.h"
#include "RT.h"
#include "DLGNCCODE.h"
#include "AdoClass.h"
#include "string.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDLGNCCODE dialog
CDLGNCCODE::CDLGNCCODE(CWnd* pParent /*=NULL*/)
: CDialog(CDLGNCCODE::IDD, pParent)
{
//{{AFX_DATA_INIT(CDLGNCCODE)
m_COM_F = _T("1.05");
m_COM_S = _T("1000");
m_COM_T = _T("2");
m_TiShi = _T("从下拉选择相关参数,如果没有这个值,你可以在空白处写入你的值.并可以通过点击旁边的添加按钮,把你自己的值写入数据库.");
//}}AFX_DATA_INIT
}
void CDLGNCCODE::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDLGNCCODE)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_CANCEL);
DDX_Control(pDX, IDC_BUTTON3, m_BUT_T);
DDX_Control(pDX, IDC_BUTTON2, m_BUT_S);
DDX_Control(pDX, IDC_BUTTON1, m_BUT_F);
DDX_CBString(pDX, IDC_COMBO1, m_COM_F);
DDX_CBString(pDX, IDC_COMBO2, m_COM_S);
DDX_CBString(pDX, IDC_COMBO3, m_COM_T);
DDX_Text(pDX, IDC_TiShi, m_TiShi);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDLGNCCODE, CDialog)
//{{AFX_MSG_MAP(CDLGNCCODE)
ON_BN_CLICKED(IDC_BUTTON1, OnButAdd)
ON_BN_CLICKED(IDC_BUTTON2, OnButAdd2)
ON_BN_CLICKED(IDC_BUTTON3, OnButAdd3)
ON_CBN_DROPDOWN(IDC_COMBO1, OnDropdownCombo1)
ON_CBN_DROPDOWN(IDC_COMBO2, OnDropdownCombo2)
ON_CBN_DROPDOWN(IDC_COMBO3, OnDropdownCombo3)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDLGNCCODE message handlers
void CDLGNCCODE::OnButAdd()
{
// TODO: Add your control notification handler code here
::CoInitialize(NULL); //初始化com
try
{
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_COMBO1);
CString str;
pCombo->GetWindowText(str);
_variant_t hoder;
_RecordsetPtr pRs("ADODB.Recordset");
pRs->Open("SELECT * from f","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
pRs->MoveLast();
pRs->AddNew();
pRs->PutCollect("value_f",_variant_t(str));
pRs->Update();
AfxMessageBox("添加进给速度成功");
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}
}
void CDLGNCCODE::OnButAdd2()
{
// TODO: Add your control notification handler code here
::CoInitialize(NULL); //初始化com
try
{
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_COMBO2);
CString str;
pCombo->GetWindowText(str);
_variant_t hoder;
_RecordsetPtr pRs("ADODB.Recordset");
pRs->Open("SELECT * from s","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
pRs->MoveLast();
pRs->AddNew();
pRs->PutCollect("value_s",_variant_t(str));
pRs->Update();
AfxMessageBox("添加主轴转速成功");
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}
}
void CDLGNCCODE::OnButAdd3()
{
// TODO: Add your control notification handler code here
::CoInitialize(NULL); //初始化com
try
{
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_COMBO3);
CString str;
pCombo->GetWindowText(str);
_variant_t hoder;
_RecordsetPtr pRs("ADODB.Recordset");
pRs->Open("SELECT * from t","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
pRs->MoveLast();
pRs->AddNew();
pRs->PutCollect("value_t",_variant_t(str));
pRs->Update();
AfxMessageBox("添加刀具成功");
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}
}
void CDLGNCCODE::OnDropdownCombo1()
{
// TODO: Add your control notification handler code here
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_COMBO1);
pCombo->ResetContent();
::CoInitialize(NULL); //初始化COM对象
try
{
_variant_t str;
// char temp[200];
int i=0;
//typedef _com_ptr_t<_Recordset, __uuidof(_Recordset)> _RecordsetPtr:指向一个_Recordset的智能指针
_RecordsetPtr pRs("ADODB.Recordset");
//调用_Recordset的Open方法取得Recordset对象
pRs->Open("SELECT * from f", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
_variant_t hoder;
//大家注意,这里的EndOfFile对应上文import语句中的rename("EOF", "EndOfFile"),其实就是EOF。rename的作用为了防止命名冲突。
while (!pRs->EndOfFile)
{
// Process data in the CCustomRs C++ instance variables.
// Move to the next row of the Recordset.
// Fields in the new row will automatically be
// placed in the CCustomRs C++ instance variables.
hoder=pRs->GetCollect("value_f");
pCombo->AddString((char*) _bstr_t(hoder));
// pCombo->AddString((_bstr_t) pRs->Fields->GetItem("value_f")->Value);
if(!pRs->EndOfFile)
{ pRs->MoveNext();}
// pCombo->AddString(strName);
// MessageBox((_bstr_t) pRs->Fields->GetItem("value_f")->Value,"Warning!",MB_ICONSTOP);
}
}
catch (_com_error &e )
{
// pCombo->AddString(e.Source());
// pCombo->AddString(e.Description());
MessageBox(e.Description(),"Warning!",MB_ICONSTOP);
}
//清除COM对象实例
::CoUninitialize();
}
void CDLGNCCODE::OnDropdownCombo2()
{
// TODO: Add your control notification handler code here
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_COMBO2);
pCombo->ResetContent();
::CoInitialize(NULL); //初始化COM对象
try
{
// char temp[200];
//typedef _com_ptr_t<_Recordset, __uuidof(_Recordset)> _RecordsetPtr:指向一个_Recordset的智能指针
_RecordsetPtr pRs("ADODB.Recordset");
//定义一个CCustomRS: public CADORecordBinding类的实例
CCustomRs rs;
//把IADORecordBindingPtr接口类型对象picRs指定到pRs对象,从而实现接口和对象之间的关联
IADORecordBindingPtr picRs(pRs);
//调用_Recordset的Open方法取得Recordset对象
pRs->Open("SELECT * from s", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
//大家注意,这里的EndOfFile对应上文import语句中的rename("EOF", "EndOfFile"),其实就是EOF。rename的作用为了防止命名冲突。
while (!pRs->EndOfFile)
{
// Process data in the CCustomRs C++ instance variables.
// Move to the next row of the Recordset.
// Fields in the new row will automatically be
// placed in the CCustomRs C++ instance variables.
pCombo->AddString((_bstr_t) pRs->Fields->GetItem("value_s")->Value);
if(!pRs->EndOfFile)
{ pRs->MoveNext();}
// pCombo->AddString(strName);
// MessageBox((_bstr_t) pRs->Fields->GetItem("value_f")->Value,"Warning!",MB_ICONSTOP);
}
}
catch (_com_error &e )
{
// pCombo->AddString(e.Source());
// pCombo->AddString(e.Description());
MessageBox(e.Description(),"Warning!",MB_ICONSTOP);
}
//清除COM对象实例
::CoUninitialize();
}
void CDLGNCCODE::OnDropdownCombo3()
{
// TODO: Add your control notification handler code here
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_COMBO3);
pCombo->ResetContent();
::CoInitialize(NULL); //初始化COM对象
try
{
CString str;
// char temp[200];
//typedef _com_ptr_t<_Recordset, __uuidof(_Recordset)> _RecordsetPtr:指向一个_Recordset的智能指针
_RecordsetPtr pRs("ADODB.Recordset");
//定义一个CCustomRS: public CADORecordBinding类的实例
CCustomRs rs;
//把IADORecordBindingPtr接口类型对象picRs指定到pRs对象,从而实现接口和对象之间的关联
IADORecordBindingPtr picRs(pRs);
//调用_Recordset的Open方法取得Recordset对象
pRs->Open("SELECT * from t", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
//大家注意,这里的EndOfFile对应上文import语句中的rename("EOF", "EndOfFile"),其实就是EOF。rename的作用为了防止命名冲突。
while (!pRs->EndOfFile)
{
// Process data inthe CCustomRs C++ instance variables.
// Move to the next row of the Recordset.
// Fields in the new row will automatically be
// placed in the CCustomRs C++ instance variables.
pCombo->AddString((_bstr_t) pRs->Fields->GetItem("value_t")->Value);
if(!pRs->EndOfFile)
{
pRs->MoveNext();
}
// pCombo->AddString(strName);
// MessageBox((_bstr_t) pRs->Fields->GetItem("value_f")->Value,"Warning!",MB_ICONSTOP);
}
}
catch (_com_error &e )
{
// pCombo->AddString(e.Source());
// pCombo->AddString(e.Description());
MessageBox(e.Description(),"Warning!",MB_ICONSTOP);
}
//清除COM对象实例
::CoUninitialize();
// int i;
// CString str;
// str="";
// TODO: Add your control notification handler code here
// for(i=0;i<10;i++)
// {
// str=str+"1";
// pCombo->AddString(str);
// }
// pCombo->SelectString(-1,m_COM_F);
}
void CDLGNCCODE::OnOK()
{
// TODO: Add extra validation here
//定义三个实例
CComboBox *pCombo1=(CComboBox *)GetDlgItem(IDC_COMBO1);
CComboBox *pCombo2=(CComboBox *)GetDlgItem(IDC_COMBO2);
CComboBox *pCombo3=(CComboBox *)GetDlgItem(IDC_COMBO3);
//定义变量
CString str1,str2,str3,temp;
//取得变量
pCombo1->GetWindowText(str1);
pCombo2->GetWindowText(str2);
pCombo3->GetWindowText(str3);
//去除空白
str1.TrimLeft();
str1.TrimRight();
str2.TrimLeft();
str2.TrimRight();
str3.TrimLeft();
str3.TrimRight();
try
{
::CoInitialize(NULL); //初始化com
_RecordsetPtr pRs("ADODB.Recordset");
pRs->Open("SELECT top 1 * from current_value","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\nccode\\ncdata.mdb", adOpenStatic, adLockOptimistic, adCmdText);
if (str1!="")
{
pRs->PutCollect("current_f",_variant_t(str1));
// AfxMessageBox("进给速度已经更新");
}
if (str2!="")
{
pRs->PutCollect("current_s",_variant_t(str2));
// AfxMessageBox("转轴速度已经更新");
}
if (str3!="")
{
pRs->PutCollect("current_t",_variant_t(str3));
// AfxMessageBox("刀具代号已经更新");
}
pRs->Update();
}
catch(_com_error &e)
{
AfxMessageBox("出错误了");
AfxMessageBox(e.Description());
}
//关闭对话框
CDialog::OnOK();
}
void CDLGNCCODE::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
CComboBox *pCombo=(CComboBox*)GetDlgItem(IDC_COMBO1);
CString pComboText;
int i=pCombo->GetCurSel();
pCombo->GetLBText(i,pComboText);
// MessageBox("你的选择是"+pComboText,"Warning!",MB_ICONSTOP);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -