⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagesetting.cpp

📁 485通讯接口模块的编程应用
💻 CPP
字号:
// PageSetting.cpp : implementation file
//

#include "stdafx.h"
#include "DK20DieselizeDynamotor.h"
#include "PageSetting.h"
#include "WraningControl.h"
#include "RecordSetting.h"
#include "Meter.h"
#include "PagePWD.h"
#include "Thermometer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPageSetting dialog
extern BOOL bChinese;
extern CWraningControl m_Warningcontrol[12] ;
extern CMeter m_meter[6];
extern CThermometer m_thermoneter[3];

CPageSetting::CPageSetting(CWnd* pParent /*=NULL*/)
	: CDialog(CPageSetting::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPageSetting)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPageSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageSetting)
	DDX_Control(pDX, IDC_BUTTON_SAVE, m_btnSave);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageSetting, CDialog)
	//{{AFX_MSG_MAP(CPageSetting)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

#define  WM_USER2 5020

/////////////////////////////////////////////////////////////////////////////
// CPageSetting message handlers

BOOL CPageSetting::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	bPass = false;

	VERIFY(m_fontS.CreateFont(
		24,                        // nHeight
		0,                         // nWidth
		0,                         // nEscapement
		0,                         // nOrientation
		FW_BOLD,                 // nWeight
		FALSE,                     // bItalic
		FALSE,                     // bUnderline
		0,                         // cStrikeOut
		ANSI_CHARSET,              // nCharSet
		OUT_DEFAULT_PRECIS,        // nOutPrecision
		CLIP_DEFAULT_PRECIS,       // nClipPrecision
		DEFAULT_QUALITY,           
		DEFAULT_PITCH | FF_SWISS, 
		_T("Arial")));

	m_btnSave.MoveWindow(CRect(150,450,250,485));//(1150,450,1250,485)

	int iTop = 50 ; 
	int iLeft = 10 ; 
	int iHeight = 35 ; 
	int iHSpace = 5 ; 
	int iWidth =  160 ; 
	int iWSpace = 160; 
	
    int iIndex = 0 ; 

	for (int j = 0 ; j< 4 ; j++)
	{
		for (int i = 0 ; i <  10 ; i++)
		{																																											
			CRect rc1  , rc2 , rc3 , rc4; 
			CRect   rc5 , rc6 ; 
 			//文字部分
			rc1=CRect(iLeft+iWidth*j+ iWSpace* j ,iTop +i*iHSpace + i *iHeight , iLeft+iWidth*(j+1)+ iWSpace* j ,iTop +i*iHSpace +i	*iHeight+ iHeight) ; 
			
			 
	 		ownControl[j].ownstatic[i].Create(m_Warningcontrol[j].m_Ownstatic[i].strTextleft,
	 										WS_CHILD|WS_VISIBLE|WS_BORDER|TRANSPARENT ,	rc1 ,this , WM_USER2+0x10+ j)  ; 

			
			//关键报警项
			

 			//上限
			rc2 = rc1 ; 
			rc2.left = rc1.right +1 ; 
			rc2.right = rc2.left + 50 ; 
		  	ownControl[j].ownEdit1[i].Create(WS_CHILD|WS_VISIBLE|WS_BORDER ,rc2 , this ,WM_USER2+0x30+ j*i) ; 
 			//下限
			rc5 = rc2 ;			
			rc5.left = rc2.right +1 ; 
			rc5.right = rc5.left + 50 ; 
	     	ownControl[j].ownEdit2[i].Create(WS_CHILD|WS_VISIBLE|WS_BORDER  ,rc5 , this ,WM_USER2+0x90+ j*i) ; 
			//时间
			rc6 = rc5 ; 
			rc6.left = rc5.right +1 ; 
			rc6.right = rc6.left + 50 ; 
		  	ownControl[j].ownEdit3[i].Create(WS_CHILD|WS_VISIBLE|WS_BORDER  ,rc6 , this ,WM_USER2+0x140+ j*i) ; 
			
			//移动标签控件
			if (i ==0 )
			{ 
				rc2.DeflateRect(-15,-20,0,37) ;
				rc5.DeflateRect(-15,-20,0,37) ; 
				rc6.DeflateRect(-15,-20,0,37) ; 
				rc2.left+=15;
				rc5.left+=15;
				rc6.left+=15;
				if (bChinese)
				{
					ownStatic[iIndex].Create(_T("上限:"),WS_VISIBLE|WS_CHILD|TRANSPARENT ,rc2 , this, WM_USER2+0x180+i*j) ; 
					iIndex++ ; 
					ownStatic[iIndex].Create(_T("下限:"),WS_VISIBLE|WS_CHILD|TRANSPARENT ,rc5 , this, WM_USER2+0x210+i*j) ; 
					iIndex++ ; 
					ownStatic[iIndex].Create(_T("时间:"),WS_VISIBLE|WS_CHILD|TRANSPARENT ,rc6 , this, WM_USER2+0x230+i*j) ; 
					iIndex++ ; 
				}
				else
				{
					ownStatic[iIndex].Create(_T("UpLimit"),WS_VISIBLE|WS_CHILD|TRANSPARENT ,rc2 , this, WM_USER2+0x180+i*j) ; 
					iIndex++ ; 
					ownStatic[iIndex].Create(_T("LoLimit"),WS_VISIBLE|WS_CHILD|TRANSPARENT ,rc5 , this, WM_USER2+0x210+i*j) ; 
					iIndex++ ; 
					ownStatic[iIndex].Create(_T("Delay"),WS_VISIBLE|WS_CHILD|TRANSPARENT ,rc6 , this, WM_USER2+0x230+i*j) ; 
					iIndex++ ; 
				}	
			}

			for (int i1 = 0 ; i1<3 ;i1++)
			{
				strInitialValue[j][i][i1] = "";
			}
	   
		}
        
	} 
	
	if (!bChinese)
		m_btnSave.SetWindowText("SETTING");
		
	GetSettingValue();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPageSetting::OnPaint() 
{
	CPaintDC dc(this); 
	CRect rcClient ;   
	GetClientRect(&rcClient)  ; 
	
	CDC memDc ; 
	memDc.CreateCompatibleDC(&dc)  ; 
	CBitmap bitmap1 ; 
	bitmap1.CreateCompatibleBitmap(&dc , rcClient.Width(),rcClient.Height())  ; 
	
	CBitmap *oldBitmp1 = memDc.SelectObject(&bitmap1)  ; 
	
	memDc.FillSolidRect(&rcClient , RGB(173,211,198)) ; 
    
	CRect rc2(0 , 0 , 1280, 20) ;
	DrawGradientFill(&memDc , &rc2 , RGB(198,255,249) ,RGB(244,198,255),5) ;

	memDc.SetTextColor(RGB(0,0,0)) ; 
	memDc.SetBkMode(TRANSPARENT)   ; 
	if (bChinese)
		memDc.DrawText(_T("柴油机发电机组报警值设置"), &rc2 , DT_CENTER |DT_VCENTER	);
	else
		memDc.DrawText(_T("DYNAMOTOR WRANINGVALUE SETTING"), &rc2 , DT_CENTER |DT_VCENTER	);
	dc.BitBlt(0,0,rcClient.Width() , rcClient.Height() , &memDc , 0,0,SRCCOPY) ; 
	memDc.SelectObject(oldBitmp1)  ; 
	bitmap1.DeleteObject() ; 
	memDc.DeleteDC() ; 
		
	DeleteObject(oldBitmp1)  ; oldBitmp1 =NULL ; 
	ReleaseDC(&dc) ; 
}

void CPageSetting::DrawGradientFill(CDC *pDC, CRect *pRect, COLORREF crStart, COLORREF crEnd, int nSegments)
{
	COLORREF cr;
	int nR = GetRValue(crStart);
	int nG = GetGValue(crStart);
	int nB = GetBValue(crStart);
	
	int neB = GetBValue(crEnd);
	int neG = GetGValue(crEnd);
	int neR = GetRValue(crEnd);
	
	if(nSegments > pRect->Height())
		nSegments = pRect->Height();
	
	int nDiffR = (neR - nR);
	int nDiffG = (neG - nG);
	int nDiffB = (neB - nB);
	
	int ndR = 256 * (nDiffR) / (max(nSegments,1));
	int ndG = 256 * (nDiffG) / (max(nSegments,1));
	int ndB = 256 * (nDiffB) / (max(nSegments,1));
	
	nR *= 256;
	nG *= 256;
	nB *= 256;
	
	neR *= 256;
	neG *= 256;
	neB *= 256;
	
	int nCY = pRect->Height() / max(nSegments,1),  nTop = pRect->top , nBottom =nTop;
	
	CPen *hpen =(CPen*) pDC->SelectStockObject(NULL_PEN);
	for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
	{
		if (i == (nSegments - 1))
			nTop = pRect->bottom;
		else
			nTop +=  nCY;
		
		cr = RGB(nR / 256, nG / 256, nB / 256);
		
		CBrush br(cr);
		CBrush* pbrOld = pDC->SelectObject(&br);
		
		pDC->Rectangle(pRect->left, nTop+1, pRect->right , nBottom);
		pDC->SelectObject(pbrOld);
		br.DeleteObject() ; 
		DeleteObject(pbrOld)  ; 
		pbrOld =NULL ; 
		
		
		nBottom = nTop ; 
		
	}
	pDC->SelectObject(hpen)  ; 
	DeleteObject(hpen)  ; 
	hpen = NULL ; 
}

void CPageSetting::OnButtonSave() 
{
	CPagePWD dlgPWD;

	int iResult=dlgPWD.DoModal();
	if (iResult != IDOK)
	{
		exit(1);
	}

	if (bPass)
	{
		CString strSql;
		CString strName;
		CString strUp;
		CString strLo;
		CString strDe;
		
		bool bChance=false;
		
		if (bOpen==true)
		{
			for (int i=0;i<4;i++)
			{
				for (int j=0;j<10;j++)
				{
					ownControl[i].ownstatic[j].GetWindowText(strName);
					
					if (strName!="")
					{
						TRY
						{
							strSql = "select * from setting where WarningName='"+strName+"'";
							
							CRecordSetting rs1(&m_db);
							rs1.Open(CRecordSetting::snapshot,strSql,CRecordSetting::none);
							rs1.Edit();
							ownControl[i].ownEdit1[j].GetWindowText(strUp);
							rs1.m_WarningUpLimit=strUp;
							strInitialValue[i][j][0] = strUp ;
							ownControl[i].ownEdit2[j].GetWindowText(strLo);
							rs1.m_WarningLoLimit=strLo;
							strInitialValue[i][j][1] = strLo ;
							ownControl[i].ownEdit3[j].GetWindowText(strDe);
							rs1.m_WarningDelay=strDe;
							strInitialValue[i][j][2] = strDe ;
							rs1.Update();
							rs1.Close();
							bChance=true;
						}
						CATCH(CDBException,e)
						{
							AfxMessageBox("Database Error:" + e->m_strError);
							bChance=false;
						}
						END_CATCH;
						
						if (bChance)
						{
							for (int k=0;k<3;k++)
							{
								for (int l=0;l<5;l++)
								{
									for (int l1=0;l1<moudle[5*k+l].vcorValue[0].iTotalCount;l1++)
									{
										if (moudle[5*k+l].vcorValue[l1].strValuename==strName)
										{
											moudle[5*k+l].vcorValue[l1].iWarningvalueuper=(float)atof(strUp);
											moudle[5*k+l].vcorValue[l1].iWarningvaluelower=	(float)atof(strLo);
											moudle[5*k+l].vcorValue[l1].fTimedelay=(float)atof(strDe);
										}
									}
								}
							}
							
							if (strName=="主机转速"||strName=="Host Speed")
							{
								for (int k=0;k<2;k++)
								{
									m_meter[2*k].SetUpperValue((float)atof(strUp));
									m_meter[2*k].SetLowerValue((float)atof(strLo));
								}
							}
							
							if (strName=="高温水出机温度"||strName=="Hot Water-out  Machine  Temperature")
							{
								for (int k=0;k<2;k++)
								{
									m_meter[2*k+1].SetUpperValue((float)atof(strUp));
									m_meter[2*k+1].SetLowerValue((float)atof(strLo));
								}
							}
							/*if (strName=="滑油进机压力"||strName=="Lubricating Oil-in Machine  Pressure")
							{
								for (int k=0;k<2;k++)
								{
									m_meter[2*k+2].SetUpperValue((float)atof(strUp));
									m_meter[2*k+2].SetLowerValue((float)atof(strLo));
								}
							}*/
						}
					}
				}
			}
		}
		//m_db.Close();
		
		if (bChance&&bOpen)
		{
			if (bChinese)
				AfxMessageBox("更新成功");
			else
				AfxMessageBox("Chance Succeed");
		}
	}
	else
	{
		if (bChinese)
			AfxMessageBox("您无权修改!");
		else
			AfxMessageBox("You do not have the right to amend !");

		SetInitialValue();
	}
}

bool CPageSetting::GetSettingToModule()
{
	bool bget=false;

	CString strSql;
	CString strName;
	CString strUp;
	CString strLo;
	CString strDe;

	for (int i = 0 ; i < 5 ; i++)
	{
		for (int j = 0 ; j < moudle[i].vcorValue[0].iTotalCount ; j++)
		{
			TRY
			{
				strSql = "select * from setting where WarningName = '" + moudle[i].vcorValue[j].strValuename + "'";
				
				CRecordSetting rs1(&m_db);
				rs1.Open(CRecordSetting::forwardOnly,strSql,CRecordSetting::none);
				
				
				if (!rs1.IsEOF())
				{
					rs1.GetFieldValue("WarningName",strName);
					rs1.GetFieldValue("WarningUpLimit",strUp);
					rs1.GetFieldValue("WarningLoLimit",strLo);
					rs1.GetFieldValue("WarningDelay",strDe);
					for (int k=0;k<3;k++)
					{
						moudle[5*k+i].vcorValue[j].iWarningvalueuper=(float)atof(strUp);
						moudle[5*k+i].vcorValue[j].iWarningvaluelower=	(float)atof(strLo);
						moudle[5*k+i].vcorValue[j].fTimedelay=(float)atof(strDe);
					}
					
					if (strName=="高温水出机温度"||strName=="Hot Water-out  Machine  Temperature")
					{
						for (int i=0;i<2;i++)
						{
							m_meter[3*i].SetUpperValue((float)atof(strUp));
							m_meter[3*i].SetLowerValue((float)atof(strLo));
						}
					}
					
					if (strName=="滑油进机压力"||strName=="Lubricating Oil-in Machine  Pressure")
					{
						for (int i=0;i<2;i++)
						{
							m_meter[3*i+1].SetUpperValue((float)atof(strUp));
							m_meter[3*i+1].SetLowerValue((float)atof(strLo));
						}
					}
					
					if (strName=="主机转速"||strName=="Host Speed")
					{
						for (int i=0;i<2;i++)
						{
							m_meter[3*i+2].SetUpperValue((float)atof(strUp));
							m_meter[3*i+2].SetLowerValue((float)atof(strLo));
						}
					}
					rs1.MoveNext();
				}
				
				bget=true;
			}
			CATCH(CDBException,e)
			{
				AfxMessageBox("Database Error:" + e->m_strError);
				bget=false;
			}
			END_CATCH;
			
		}
	}
	
	GetInitialValue();
	return bget;
}

bool CPageSetting::GetSettingValue()
{
	bool bget=false;
	

	CString strSql;
	CString strName;
	CString strUp;
	CString strLo;
	CString strDe;

	int ir = 0;
	int il = 0;
	for (int i = 0 ; i < 5 ; i++)
	{
		for (int j = 0 ; j < moudle[i].vcorValue[0].iTotalCount ; j++)
		{
			TRY
			{
				strSql = "select * from setting where WarningName = '" + moudle[i].vcorValue[j].strValuename + "'";
				
				CRecordSetting rs1(&m_db);
				rs1.Open(CRecordSetting::forwardOnly,strSql,CRecordSetting::none);
				
				if (!rs1.IsEOF())
				{
					rs1.GetFieldValue("WarningName",strName);
					ownControl[ir].ownstatic[il].SetWindowText(strName);
					
					rs1.GetFieldValue("WarningUpLimit",strUp);
					ownControl[ir].ownEdit1[il].SetWindowText(strUp);
					rs1.GetFieldValue("WarningLoLimit",strLo);
					ownControl[ir].ownEdit2[il].SetWindowText(strLo);
					rs1.GetFieldValue("WarningDelay",strDe);
					ownControl[ir].ownEdit3[il].SetWindowText(strDe);
					il++;
					if (il==10)
					{
						il=0;
						ir++;
					}
				}
				
				bget=true;
			}
			CATCH(CDBException,e)
			{
				AfxMessageBox("Database Error:" + e->m_strError);
				bget=false;
			}
			END_CATCH;
		}
	}

	return bget;
}

HBRUSH CPageSetting::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	HBRUSH hbr1=CreateSolidBrush(RGB(173,211,198));
  	for (int i=0;i<4;i++)
  	{
  		if	(pWnd->GetDlgCtrlID() == WM_USER2+0x10+ 4*i) 
  			
  			return hbr1; 
 		if	(pWnd->GetDlgCtrlID() == WM_USER2+0x10+ 4*i+1) 
  			
  			return hbr1; 
		if	(pWnd->GetDlgCtrlID() == WM_USER2+0x10+ 4*i+2) 
  			
  			return hbr1; 
 		if	(pWnd->GetDlgCtrlID() == WM_USER2+0x10+ 4*i+3) 
  			
 			return hbr1; 
  		
  		for (int j=0;j<10;j++)
  		{
  			if (pWnd->GetDlgCtrlID()==WM_USER2+0x180+i*j)
  				return hbr1;
  			
  			if (pWnd->GetDlgCtrlID()==WM_USER+0x210+i*j)
  				return hbr1;
  			
  			if (pWnd->GetDlgCtrlID()==WM_USER2+0x230+i*j)
  				return hbr1;
		}
  		
  	}
	switch(pWnd->GetDlgCtrlID()) {
	case CTLCOLOR_STATIC:
		pDC->SetBkMode(TRANSPARENT);
		return hbr1;
		break;
	default:
		break;
	}
	
	return hbr;
}

void CPageSetting::GetInitialValue()
{
	for (int i = 0 ; i < 4 ; i++)
	{
		for (int j = 0 ; j < 10 ; j++ )
		{
			ownControl[i].ownEdit1[j].GetWindowText(strInitialValue[i][j][0]);
			ownControl[i].ownEdit2[j].GetWindowText(strInitialValue[i][j][1]);
			ownControl[i].ownEdit3[j].GetWindowText(strInitialValue[i][j][2]);
		}
	}
}

void CPageSetting::SetInitialValue()
{
	for (int i = 0 ; i < 4 ; i++)
	{
		for (int j = 0 ; j < 10 ; j++ )
		{
			ownControl[i].ownEdit1[j].SetWindowText(strInitialValue[i][j][0]);
			ownControl[i].ownEdit2[j].SetWindowText(strInitialValue[i][j][1]);
			ownControl[i].ownEdit3[j].SetWindowText(strInitialValue[i][j][2]);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -