📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "ShaoYe.h"
#include "MainFrm.h"
#include "shaoyedoc.h"
#include "flowset.h"
#include "modeldlg.h"
#include "global_fun.h"
#include "querydlg.h"
#include "querydlg1.h"
#include "querydlg2.h"
#include "querydlg3.h"
#include "resultdlg1.h"
#include "resultdlg2.h"
#include "resultdlg3.h"
#include "modelset.h"
#include "modelsel.h"
#include "passworddlg1.h"
#include "passworddlg2.h"
#include "passworddlg3.h"
#include "viewmodifydlg4.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
extern CString model_date;//模型建立日期
extern float model_parameter_tare;//皮重
extern float model_parameter_a;//常数项
extern float model_parameter_b;//一次项系数
extern float model_parameter_c;//二次向系数
extern BOOL m_bStart;
extern BOOL m_bStop;
extern CSampleResult m_sampleresult;
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_TIMER()
ON_COMMAND(ID_MODEL_SELECT, OnModelSelect)
ON_COMMAND(ID_MODELING, OnModeling)
ON_UPDATE_COMMAND_UI(ID_MODELING, OnUpdateModeling)
ON_COMMAND(ID_QUERY_FIRST, OnQueryFirst)
ON_COMMAND(ID_QUERY_SECOND, OnQuerySecond)
ON_COMMAND(ID_QUERY_THIRD, OnQueryThird)
ON_COMMAND(ID_QUERY_FORTH, OnQueryForth)
ON_COMMAND(ID_MODEL_MODIFY, OnModelModify)
ON_COMMAND(ID_VIEW_MODIFY, OnViewModify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,// status line indicator
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
// ID_SEPARATOR,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_bStart=TRUE;
m_bStop=FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
/*
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
*/
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
// m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
// EnableDocking(CBRS_ALIGN_ANY);
// DockControlBar(&m_wndToolBar);
m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(30); //高度
//float Width=rect.right-rect.left; //宽度??
float Width=1000;
m_wndStatusBar.SetPaneInfo(0,0,0,(int)Width/5);
m_wndStatusBar.SetPaneInfo(1,0,0,(int)Width*4/20);
m_wndStatusBar.SetPaneInfo(2,0,0,(int)Width/5);
m_wndStatusBar.SetPaneInfo(3,0,0,(int)Width/5);
m_wndStatusBar.SetPaneInfo(4,0,0,(int)Width/10);
m_wndStatusBar.SetPaneInfo(5,0,0,(int)Width/10);
//初始化模型参数
CModelSet modelset;
modelset.Open();
modelset.MoveFirst();
while(!modelset.IsEOF())
{
if(modelset.m_selected)
{
model_date=modelset.m_date;
model_parameter_a=modelset.m_const;//常数项
model_parameter_b=modelset.m_first;//一次项系数
model_parameter_c=modelset.m_second;//二次项系数
model_parameter_tare=modelset.m_tare;//皮重
break;
}
modelset.MoveNext();
}
modelset.Close();
/*
CString strdate;
CTime time=CTime::GetCurrentTime();
strdate.Format("%4d%02d%02d",time.GetYear(),time.GetMonth(),time.GetDay());
CDaoDatabase m_DB;
m_DB.Open("e:\\shaoye\\test_result.mdb");
CDaoTableDef m_OpenTable1(&m_DB);
try
{
m_OpenTable1.Open(strdate);
}
catch(CDaoException* e)
{
e->Delete();
}
*/
SetTimer(1,1000,NULL);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CShaoYeDoc* pDoc = (CShaoYeDoc* )GetActiveDocument();
CTime time=CTime::GetCurrentTime();
if(m_bStart)
{
Str1.Format(" 系统工作状态:停 止");
m_wndStatusBar.SetPaneText(1,Str1,TRUE);
}
else
{
Str1.Format(" 系统工作状态:运 行");
m_wndStatusBar.SetPaneText(1,Str1,TRUE);
}
if(pDoc->show_flag)
{
pDoc->show_flag=false;
Str3.Format(" 当前流量:%5.2f 吨/班",pDoc->AveFlow);
int current_hour;
current_hour=time.GetHour();
Str4.Format(" %d-%d点累积流量:%10.2f Kg",current_hour,current_hour+1,pDoc->TotalFlow);
m_wndStatusBar.SetPaneText(3,Str4,TRUE);
m_wndStatusBar.SetPaneText(2,Str3,TRUE);
}
Str6=time.Format(" %H:%M:%S");
m_wndStatusBar.SetPaneText(5,Str6,TRUE);
Str5=time.Format(" %Y年%m月%d日");
m_wndStatusBar.SetPaneText(4,Str5,TRUE);
m_wndStatusBar.SetPaneText(0," 欢迎使用锌液流量实时监视系统! ",TRUE);
CString querystr,delstr;
int year,month,day;
year=time.GetYear();
month=time.GetMonth();
day=time.GetDay();
querystr.Format("%4d%02d%02d",year,month,day);
if(month==1||month==2)
{
year=year-1;
month=month+10;
}
else
{
month=month-2;
}
delstr.Format("%4d%02d",year,month);
if(m_bStart==false&&time.GetHour()==0&&time.GetMinute()==0&&time.GetSecond()==0)
{
CDaoDatabase m_DB;
try
{
m_DB.Open("e:\\shaoye\\test_result.mdb");
CDaoTableDefInfo tabledefinfo;
int tb_num=m_DB.GetTableDefCount();//数据库中表的个数
CString tb_name;
for(int i=0;i<tb_num;i++)
{
m_DB.GetTableDefInfo(i,tabledefinfo);
tb_name=tabledefinfo.m_strName;
//删除一个月前的数据表
if(tb_name.Left(6)==delstr)
{
m_DB.DeleteTableDef(tb_name);
i=i-1;
}
}
CDaoTableDef *pTableSet;
pTableSet=new CDaoTableDef(&m_DB);
try
{
querystr.Format("%4d%02d%02d",CTime::GetCurrentTime().GetYear(),CTime::GetCurrentTime().GetMonth(),CTime::GetCurrentTime().GetDay());
pTableSet->Create(querystr);
pTableSet->CreateField("time",dbInteger,dbFixedField);
pTableSet->CreateField("flux",dbSingle,dbFixedField);
pTableSet->Append();
m_sampleresult.Close();
m_sampleresult.Open();
}
catch(CDaoException *e)
{
e->Delete();
MessageBox("无法创建新的数据表","错误",MB_OK);
}
}
catch(CDaoException *e)
{
e->Delete();
MessageBox("无法打开数据库","错误",MB_OK);
}
}
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnModelSelect()
{
// TODO: Add your command handler code here
CPasswordDlg2 Dlg;
Dlg.DoModal();
}
void CMainFrame::OnModeling()
{
// TODO: Add your command handler code here
CPasswordDlg1 dlg;
dlg.DoModal();
}
void CMainFrame::OnUpdateModeling(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bStart);
}
void CMainFrame::OnQueryFirst()
{
// TODO: Add your command handler code here
CQueryDlg dlg;
dlg.DoModal();
}
void CMainFrame::OnQuerySecond()
{
// TODO: Add your command handler code here
CShaoYeDoc* pDoc = (CShaoYeDoc* )GetActiveDocument();
int dd,mm,yy;
CQueryDlg1 dlg;
if(dlg.DoModal()==IDOK)
{
UpdateData();
if(dlg.m_year>2050||dlg.m_year<2000)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -