📄 electromotordlg.cpp
字号:
e.Error(),
e.ErrorMessage(),
(LPCSTR) e.Source(),
(LPCSTR) e.Description());
AfxMessageBox(strComError);
}
}
int CElectromotorDlg::Hex2Dec(CString data)
{
int len=data.GetLength();
int decDat=0;
const char* dat=(LPCTSTR)data;
for (int k=0;k<len;k++)
{
decDat+=(int)(HexChar(dat[k]))*((int)pow(16,(len-k-1)));
}
// decDat=atoi(data.Mid(0,3));
return decDat;
}
void CElectromotorDlg::OnButtonHisRec()
{
// TODO: Add your control notification handler code here
OnBtnSto();
AddLine();
if ((m_Pconn->State)&&m_Precord==NULL)
{
m_Precord.CreateInstance(__uuidof(Recordset));
CString sqlQuery="",startDat="",sqlQueryDat="";
GetDlgItemText(IDC_EDIT_HISTIM,startDat);
if (startDat!=""&&startDat.GetLength()==6)
{
sqlQuery.Format("2008-%d-%d %s:00:00",atoi(startDat.Mid(0,2)),atoi(startDat.Mid(2,2)),startDat.Mid(4,5));
sqlQuery="select * from "+m_table+" where 时间 between #"+sqlQuery+"# and now() order by 时间 asc";
}
else
sqlQuery.Format(_T("select * from %s order by 时间 asc"),m_table);
try
{
m_Precord=m_Pconn->Execute(_bstr_t(sqlQuery),NULL,adCmdText);
}
catch(_com_error e)
{
CString strComError;
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(),
e.ErrorMessage(),
(LPCSTR) e.Source(),
(LPCSTR) e.Description());
// MessageBox(strComError,"提示",MB_OK);
MessageBox("请选择表名","提示",MB_OK);
// if (m_Precord->State)
// {
m_Precord.Release();
// m_Precord=NULL;
// m_Precord->Close();
// }
return;
}
m_addrTemp=m_addr;
}
m_hisRecord=TRUE;
SetTimer(0,100,NULL);
}
void CElectromotorDlg::OnBtnClear()
{
// TODO: Add your control notification handler code here
// if (m_lineNo1)
// {
m_curPushGraph.RemoveLine(0);
m_volPushGraph.RemoveLine(0);
m_tawPushGraph.RemoveLine(0);
m_trwPushGraph.RemoveLine(0);
SetDlgItemText(IDC_EDIT_CUR1,"");
SetDlgItemText(IDC_EDIT_VOL1,"");
SetDlgItemText(IDC_EDIT_FRE1,"");
SetDlgItemText(IDC_EDIT_CUR_TOP1,"");
SetDlgItemText(IDC_EDIT_VOL_TOP1,"");
// }
// if (m_lineNo2)
// {
m_curPushGraph.RemoveLine(1);
m_volPushGraph.RemoveLine(1);
m_tawPushGraph.RemoveLine(1);
m_trwPushGraph.RemoveLine(1);
SetDlgItemText(IDC_EDIT_CUR2,"");
SetDlgItemText(IDC_EDIT_VOL2,"");
SetDlgItemText(IDC_EDIT_FRE2,"");
SetDlgItemText(IDC_EDIT_CUR_TOP2,"");
SetDlgItemText(IDC_EDIT_VOL_TOP2,"");
// }
// if (m_lineNo3)
// {
m_curPushGraph.RemoveLine(2);
m_volPushGraph.RemoveLine(2);
m_tawPushGraph.RemoveLine(2);
m_trwPushGraph.RemoveLine(2);
SetDlgItemText(IDC_EDIT_CUR3,"");
SetDlgItemText(IDC_EDIT_VOL3,"");
SetDlgItemText(IDC_EDIT_FRE3,"");
SetDlgItemText(IDC_EDIT_CUR_TOP3,"");
SetDlgItemText(IDC_EDIT_VOL_TOP3,"");
// }
m_curPushGraph.Update();
m_volPushGraph.Update();
m_tawPushGraph.Update();
m_trwPushGraph.Update();
m_value.volAVal=0;
m_value.curAVal=0;
m_value.volBVal=0;
m_value.curBVal=0;
m_value.volCVal=0;
m_value.curCVal=0;
m_value.freVal=0;
m_value.tpqVal=0;
m_value.trwVal=0;
m_value.TacVal=0;
m_value.TracVal=0;
m_value.TfacVal=0;
m_value.TfracVal=0;
m_line=FALSE;
m_Precord.Release();
m_Precord=NULL;
// UpdateData(FALSE);
//第二次
}
void CElectromotorDlg::AddLine()
{
if(!m_line)
{
// if (!m_lineNo1)
// {
m_curPushGraph.AddLine( 0, m_color1);
m_volPushGraph.AddLine( 0, m_color1);
m_tawPushGraph.AddLine(0,m_color1);
m_trwPushGraph.AddLine(0, m_color1);
// }
// if (!m_lineNo2)
// {
m_curPushGraph.AddLine( 1, m_color2);
m_volPushGraph.AddLine( 1, m_color2);
m_tawPushGraph.AddLine(1,m_color2);
m_trwPushGraph.AddLine(1,m_color2);
// }
// if (!m_lineNo3)
// {
m_curPushGraph.AddLine( 2, m_color3);
m_volPushGraph.AddLine( 2, m_color3);
m_tawPushGraph.AddLine(2,m_color3);
m_trwPushGraph.AddLine(2,m_color3);
// }
m_line=TRUE;
}
}
void CElectromotorDlg::OnBtnHissto()
{
// TODO: Add your control notification handler code here
m_hisRecord=FALSE;
KillTimer(0);
}
/*用于检测用户是否选择了数据库*/
BOOL CElectromotorDlg::DataSource()
{
int index=m_ctrDataSource.GetCurSel();
if (!(index<0))
{
// CString m_strDataSource="";
// m_ctrDataSource.GetLBText(index,m_strDataSource);
return TRUE;
}
else
return FALSE;
}
BOOL CElectromotorDlg::InitDataSource()
{
if (m_Pconn!=NULL)
{
m_Pconn=NULL;
// m_Pconn->Close();
CoUninitialize();
}
if(m_Pconn==NULL)
{
CoInitialize(NULL);
m_Pconn.CreateInstance(__uuidof(Connection));
CString connStr="",strDataSource="",productivity="",plac="";
// m_ctrDataSource.GetLBText(m_ctrDataSource.GetCurSel(),strDataSource);
strDataSource="hjpok";
connStr.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=./%s.mdb;Persist Security Info=False",strDataSource);
m_Pconn->ConnectionString = (_bstr_t)connStr;
try
{
m_Pconn->Open("","","",-1);
}
catch(...)
{
AfxMessageBox("数据库连接错误",0,0);
return FALSE;
}
}
return TRUE;
}
void CElectromotorDlg::OnSelendokDatsou()
{
// TODO: Add your control notification handler code here
OnBtnClear();
KillTimer(0);
InitDataSource();
}
void CElectromotorDlg::OnCheckNo1()
{
// TODO: Add your control notification handler code here
if (m_line&&m_checkNo1.GetCheck())
{
m_checkNo1.SetCheck(FALSE);
// UpdateData(FALSE);
MessageBox("请先清屏,再选择1号机!","提示",MB_OK);
return;
}
if (m_line&&!m_checkNo1.GetCheck())
{
m_checkNo1.SetCheck(TRUE);
// UpdateData(FALSE);
MessageBox("请先清屏,再取消1号机!","提示",MB_OK);
}
}
void CElectromotorDlg::OnCheckNo2()
{
// TODO: Add your control notification handler code here
if (m_line&&m_checkNo2.GetCheck())
{
m_checkNo2.SetCheck(FALSE);
MessageBox("请先清屏,再选择2号机!","提示",MB_OK);
return;
}
if (m_line&&!m_checkNo2.GetCheck())
{
m_checkNo2.SetCheck(TRUE);
MessageBox("请先清屏,再取消2号机!","提示",MB_OK);
}
}
void CElectromotorDlg::OnCheckNo3()
{
// TODO: Add your control notification handler code here
if (m_line&&m_checkNo3.GetCheck())
{
m_checkNo3.SetCheck(FALSE);
MessageBox("请先清屏,再选择3号机!","提示",MB_OK);
return;
}
if (m_line&&!m_checkNo3.GetCheck())
{
m_checkNo3.SetCheck(TRUE);
MessageBox("请先清屏,再取消3号机!","提示",MB_OK);
}
}
void CElectromotorDlg::OnSelendokDevicecount()
{
// TODO: Add your control notification handler code here
m_deviceCount=m_ctrDeviceCount.GetCurSel()+2;
}
BOOL CElectromotorDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch (pMsg->message)
{
case WM_COMM_CTS_DETECTED:
MessageBox("CTS_DETECTED");
break;
case WM_COMM_BREAK_DETECTED:
MessageBox("BREAK_DETECTED");
break;
case WM_COMM_ERR_DETECTED:
MessageBox("ERR_DETECTED");
break;
case WM_COMM_RING_DETECTED:
MessageBox("RING_DETECTED");
break;
case WM_COMM_RXFLAG_DETECTED:
MessageBox("RXFLAG_DETECTED");
break;
case WM_COMM_RXCHAR:
MessageBox("RXCHAR");
break;
default:
break;
}
// if (pMsg->message==WM_KEYDOWN)
// {
// if (pMsg->wParam==VK_RETURN)
// {
// MessageBox("OK");
// return TRUE;
// }
// }
return CDialog::PreTranslateMessage(pMsg);
}
void CElectromotorDlg::OnSelendokComboTable()
{
// TODO: Add your control notification handler code here
int sel=-1;
sel=m_ctrTable.GetCurSel();
m_ctrTable.GetLBText(sel,m_table);
}
void CElectromotorDlg::ReadTableName()
{
//读取表名
if ((m_Pconn->State)&&m_Precord==NULL)
{
m_Precord.CreateInstance(__uuidof(Recordset));
CString sqlQuery="",tableName="";
sqlQuery.Format(_T("select Name from MSysObjects"));
try
{
m_Precord=m_Pconn->Execute(_bstr_t(sqlQuery),NULL,adCmdText);
}
catch(_com_error e)
{
CString strComError;
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(),
e.ErrorMessage(),
(LPCSTR) e.Source(),
(LPCSTR) e.Description());
MessageBox(strComError,"提示",MB_OK);
m_Precord.Release();
return;
}
while(!m_Precord->adoEOF)
{
tableName=m_Precord->GetCollect("Name").bstrVal;
if (!tableName.Find("t_"))
{
m_ctrTable.AddString(tableName);
}
m_Precord->MoveNext();
}
m_Precord.Release();
}
}
BOOL CElectromotorDlg::CreatTable()
{
CString sqlOrder="",tableName="",productivity="",plac="",deviceCount="";
GetDlgItemText(IDC_EDIT_PRO,productivity);
GetDlgItemText(IDC_EDIT_PLAC,plac);
deviceCount.Format("t_%d",m_deviceCount);
if (productivity==""||plac=="")
{
CString error="您记录的是空载情况吗?如果是,请选择是;如果不是,请选择否,然后请填入生产率和取料机位置!";
if (MessageBox(error,"提示",MB_YESNO)==IDYES)
{
productivity="空载";
plac="";
}
else
return FALSE;
}
if (productivity!="空载")
{
tableName=deviceCount+productivity+"_"+plac;
}
else tableName=deviceCount+productivity;
m_tableWrit=tableName;
sqlOrder.Format(_T("Create table [%s](电压A text(20),电压B text(20),电压C text(20),电流A text(20),电流B text(20),电流C text(20),功率因数 text(20),频率 text(20),有用功 text(20),无用功 text(20),正向总有功电度 text(20),正向总无功电度 text(20),反向总有功电度 text(20),反向总无功电度 text(20),电机号 text(20),时间 date)"),tableName);
// sqlCreat.Format(_T("create table [%s](电压A text(20),电压b date)"),tableName);
try
{
m_Pconn->Execute(_bstr_t(sqlOrder),NULL,adCmdText);
}
catch(_com_error e)
{
// CString strComError;
// strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
// e.Error(),
// e.ErrorMessage(),
// (LPCSTR) e.Source(),
// (LPCSTR) e.Description());
// AfxMessageBox(strComError);
CString error="";
error=m_tableWrit+"表已经存在,是否删除重建?";
if (MessageBox(error,"提示",MB_YESNO)==IDYES)
{
CString sqlOrder="";
sqlOrder.Format("drop table [%s]",m_tableWrit);
try
{
m_Pconn->Execute(_bstr_t(sqlOrder),NULL,adCmdText);
}
catch(_com_error e)
{
CString strComError;
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(),
e.ErrorMessage(),
(LPCSTR) e.Source(),
(LPCSTR) e.Description());
AfxMessageBox(strComError);
return FALSE;
}
sqlOrder.Format(_T("Create table [%s](电压A text(20),电压B text(20),电压C text(20),电流A text(20),电流B text(20),电流C text(20),功率因数 text(20),频率 text(20),有用功 text(20),无用功 text(20),正向总有功电度 text(20),正向总无功电度 text(20),反向总有功电度 text(20),反向总无功电度 text(20),电机号 text(20),时间 date)"),m_tableWrit);
try
{
m_Pconn->Execute(_bstr_t(sqlOrder),NULL,adCmdText);
}
catch(_com_error e)
{
CString strComError;
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(),
e.ErrorMessage(),
(LPCSTR) e.Source(),
(LPCSTR) e.Description());
AfxMessageBox(strComError);
return FALSE;
}
}
}
return TRUE;
}
BOOL CElectromotorDlg::CancleTable()
{
return TRUE;
}
void CElectromotorDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CElectromotorDlg::OnSelendokCom()
{
// TODO: Add your control notification handler code here
int index=m_ctrCom.GetCurSel();
CString nCom="";
m_ctrCom.GetLBText(index,nCom);
m_nCom=atoi(nCom);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -