📄 electromotordlg.cpp
字号:
m_volPushGraph.SetLabelForMax( "6/kV" );
m_volPushGraph.SetLabelForMin( "0" );
m_volPushGraph.ShowGrid( TRUE );
m_volPushGraph.ShowLabels( TRUE );
m_volPushGraph.ShowAsBar(0, false );
m_volPushGraph.SetInterval( 4 );
m_volPushGraph.SetGridSize( (USHORT)12 );
m_volPushGraph.SetPeekRange( 0, 100 );
m_tawPushGraph.CreateFromStatic(IDC_STATIC_TAW, this);
m_tawPushGraph.ModifyStyle(0, WS_THICKFRAME);
// m_no1VolPushGraph.AddLine( 0, RGB(0, 255, 0));
m_tawPushGraph.SetLabelForMax( "10/KW" );
m_tawPushGraph.SetLabelForMin( "0" );
m_tawPushGraph.ShowGrid( TRUE );
m_tawPushGraph.ShowLabels( TRUE );
m_tawPushGraph.ShowAsBar(0, false );
m_tawPushGraph.SetInterval( 4 );
m_tawPushGraph.SetGridSize( (USHORT)12 );
m_tawPushGraph.SetPeekRange( 0, 100 );
m_trwPushGraph.CreateFromStatic(IDC_STATIC_TRW, this);
m_trwPushGraph.ModifyStyle(0, WS_THICKFRAME);
// m_no1VolPushGraph.AddLine( 0, RGB(0, 255, 0));
m_trwPushGraph.SetLabelForMax( "10/KVAR" );
m_trwPushGraph.SetLabelForMin( "0" );
m_trwPushGraph.ShowGrid( TRUE );
m_trwPushGraph.ShowLabels( TRUE );
m_trwPushGraph.ShowAsBar(0, false );
m_trwPushGraph.SetInterval( 4 );
m_trwPushGraph.SetGridSize( (USHORT)12 );
m_trwPushGraph.SetPeekRange( 0, 100 );
m_no1.SetBkColor(m_color1);
m_no2.SetBkColor(m_color2);
m_no3.SetBkColor(m_color3);
// AddLine();
}
void CElectromotorDlg::SendOrder(CString strSendData)
{
char data[10];
int len=Str2Hex(strSendData,data);
m_Port.WriteToPort(data,len);
}
void CElectromotorDlg::SaveData(float vol,float cur,float tpq,float fre,float taw,float trw,int no)
{
CString sqlQuery="";
sqlQuery.Format(_T("insert into hjpok(电压,电流,功率因数,频率,有用功,无用功,电机号码,时间) values('%0.1f','%0.2f','%0.4f','%0.1f','%0.4f','%0.4f','%d',now())"),vol,cur,tpq,fre,taw,trw,no);
try
{
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());
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);
// 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.curVal=0.0;
m_value.volVal=0.0;
m_value.freVal=0.0;
m_value.tpqVal=0.0;
m_value.tawVal=0.0;
m_line=FALSE;
// 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;
}
void 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="";
m_ctrDataSource.GetLBText(m_ctrDataSource.GetCurSel(),strDataSource);
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);
}
}
}
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;
}
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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -