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

📄 fuzzy2004view.cpp

📁 自动化节水灌溉模糊控制系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// fuzzy2004View.cpp : implementation of the CFuzzy2004View class
//

#include "stdafx.h"
#include "fuzzy2004.h"

#include "fuzzy2004Set.h"
#include "fuzzy2004Doc.h"
#include "fuzzy2004View.h"
//数据库头文件
#include "Rain.h"
#include "Provide.h"
#include "Despoit.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFuzzy2004View

IMPLEMENT_DYNCREATE(CFuzzy2004View, CRecordView)

BEGIN_MESSAGE_MAP(CFuzzy2004View, CRecordView)
	//{{AFX_MSG_MAP(CFuzzy2004View)
	ON_BN_CLICKED(IDC_BUTTON_GET1, OnButtonGet1)
	ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
	ON_BN_CLICKED(IDC_BUTTON_COUNT, OnButtonCount)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_TIMER()
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFuzzy2004View construction/destruction

CFuzzy2004View::CFuzzy2004View()
	: CRecordView(CFuzzy2004View::IDD)
{
	//{{AFX_DATA_INIT(CFuzzy2004View)
		// NOTE: the ClassWizard will add member initialization here
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CFuzzy2004View::~CFuzzy2004View()
{
}

void CFuzzy2004View::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFuzzy2004View)
	DDX_Control(pDX, IDC_BUTTON_COUNT, m_count);
	DDX_Control(pDX, IDC_BUTTON_GET1, m_get);
	DDX_Control(pDX, IDC_BUTTON_READ, m_read);
	//}}AFX_DATA_MAP
}

BOOL CFuzzy2004View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRecordView::PreCreateWindow(cs);
}

void CFuzzy2004View::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_fuzzy2004Set;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	//先失效以下三个按钮
	this->m_read.EnableWindow(FALSE);
	this->m_count.EnableWindow(FALSE);
	SetTimer(1, 750, NULL);
}

/////////////////////////////////////////////////////////////////////////////
// CFuzzy2004View printing

BOOL CFuzzy2004View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CFuzzy2004View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CFuzzy2004View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CFuzzy2004View diagnostics

#ifdef _DEBUG
void CFuzzy2004View::AssertValid() const
{
	CRecordView::AssertValid();
}

void CFuzzy2004View::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

CFuzzy2004Doc* CFuzzy2004View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFuzzy2004Doc)));
	return (CFuzzy2004Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFuzzy2004View database support
CRecordset* CFuzzy2004View::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CFuzzy2004View message handlers

void CFuzzy2004View::OnButtonGet1() 
{
	// TODO: Add your control notification handler code here
	SYSTEMTIME st;
	GetLocalTime(&st);
	WORD entmonth,entday;
    //entmonth.Format("%d",st.wMonth);
	//entday.Format("%d",st.wDay);
	//将年份和日期转换为整数xxkwh
	CString data1;
	data1.Format("%u年%u月%u日 %u:%u:%u",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
	CEdit* data2=(CEdit*)GetDlgItem(IDC_EDITDATA);
	data2->SetWindowText(data1);
	entmonth=st.wMonth;
	entday=st.wDay;
	//进入返青期控制
		if(entmonth==6)
		{
			//注意判断语句的括号不能少,否则条件判断不对
			//此语句有问题!!xxkwh2004.8.15
			if(((entday>=22)&&(entday<=28)))
			{
				//MessageBox("现在进入返青期节水控制!");
				CEdit* time1=(CEdit*)GetDlgItem(IDC_EDIT1);
				CEdit* haoshui1=(CEdit*)GetDlgItem(IDC_EDIT2);
				CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
				shuiwei1->SetWindowText("-0.02mm");
				time1->SetWindowText("返青期");
				haoshui1->SetWindowText("47.8mm(毫米)");
				//设置田间标准水位
				m_biaozhun=-0.02;
				//设置水稻生长时期
				 timeorder=0;
				 this->m_read.EnableWindow(TRUE);
			}
			else
				if(((entday>=29)&&(entday<=30)))
				{
				CEdit* time2=(CEdit*)GetDlgItem(IDC_EDIT1);
			    CEdit* haoshui2=(CEdit*)GetDlgItem(IDC_EDIT2);
				CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
				shuiwei1->SetWindowText("-0.02mm");
			    time2->SetWindowText("分蘖期");
			    haoshui2->SetWindowText("230.2mm(毫米)");
				//设置田间标准水位
				m_biaozhun=-0.02;
				//设置水稻生长时期
				 timeorder=1;
				 this->m_read.EnableWindow(TRUE);
				}
				else
				{
					MessageBox("对不起!现在不在节水控制!");
					//先失效以下三个按钮
					this->m_read.EnableWindow(FALSE);
					this->m_count.EnableWindow(FALSE);
				}

		}
	//进入分蘖期判断
		if((entmonth>6)&&(entmonth<8))
		{
			MessageBox("现在进入分蘖期节水控制");
			CEdit* time2=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui2=(CEdit*)GetDlgItem(IDC_EDIT2);
			CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.33mm");
			time2->SetWindowText("分蘖期");
			haoshui2->SetWindowText("230.2mm(毫米)");
			//设置田间标准水位
				m_biaozhun=0.33;
				//设置水稻生长时期
				 timeorder=1;
				 this->m_read.EnableWindow(TRUE);
		}
	//进入拔节期和抽惠开花期
		if(entmonth==8)
		{
			if(((entday>=1)&&(entday<=14)))
			{
			CEdit* time3=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui3=(CEdit*)GetDlgItem(IDC_EDIT2);
			CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.33mm");
			time3->SetWindowText("拔节期");
			haoshui3->SetWindowText("106.8mm(毫米)");
			//设置田间标准水位
				m_biaozhun=0.33;
				//设置水稻生长时期
				 timeorder=2;
				 this->m_read.EnableWindow(TRUE);
			}
			else
			{
			CEdit* time4=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui4=(CEdit*)GetDlgItem(IDC_EDIT2);
			CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.78mm");
			time4->SetWindowText("抽惠开花期");
			haoshui4->SetWindowText("186.9mm(毫米)");
			//设置田间标准水位
				m_biaozhun=0.78;
				//设置水稻生长时期
				 timeorder=3;
				 this->m_read.EnableWindow(TRUE);
			}
		}
	//进入抽惠开花期和乳熟期
		if(entmonth==9)
		{
			if(((entday>=1)&&(entday<=4)))
			{
			CEdit* time4=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui4=(CEdit*)GetDlgItem(IDC_EDIT2);
            CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.78mm");
			time4->SetWindowText("抽惠开花期");
			haoshui4->SetWindowText("186.9mm(毫米)");
			//设置田间标准水位
				m_biaozhun=0.78;
				//设置水稻生长时期
				 timeorder=3;
				 this->m_read.EnableWindow(TRUE);
			}
			else
				if(((entday>=15)&&(entday<=26)))
				{
			CEdit* time5=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui5=(CEdit*)GetDlgItem(IDC_EDIT2);
			CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.63mm");
			//me5->Clear;
			time5->SetWindowText("乳熟期");
			haoshui5->SetWindowText("137.1mm(毫米)");
			//设置田间标准水位
				m_biaozhun=0.63;
				//设置水稻生长时期
				 timeorder=4;
				 this->m_read.EnableWindow(TRUE);
				}
				else
				{
			CEdit* time6=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui6=(CEdit*)GetDlgItem(IDC_EDIT2);
			CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.63mm");
			time6->SetWindowText("黄熟期");
			haoshui6->SetWindowText("74.6mm(毫米)");
			//设置田间标准水位
				m_biaozhun=0.63;
				//设置水稻生长时期
				 timeorder=5;
				 this->m_read.EnableWindow(TRUE);
				}
		}
		if(entmonth==10)
		{
			if(((entday>=1)&&(entday<=16)))
			{
			CEdit* time6=(CEdit*)GetDlgItem(IDC_EDIT1);
			CEdit* haoshui6=(CEdit*)GetDlgItem(IDC_EDIT2);
			CEdit* shuiwei1=(CEdit*)GetDlgItem(IDC_EDIT3);
			shuiwei1->SetWindowText("0.63mm");
			time6->SetWindowText("黄熟期");
			haoshui6->SetWindowText("74.6mm(毫米)");
			//设置田间标准水位
			m_biaozhun=0.63;
			//设置水稻生长时期
			timeorder=5;
			this->m_read.EnableWindow(TRUE);
			}
			else
			{
				MessageBox("对不起,现在不在水位控制期!");
			    //先失效以下三个按钮
				this->m_read.EnableWindow(FALSE);
				this->m_count.EnableWindow(FALSE);
			}

		}
		if((entmonth<6)||(entmonth>10))
	//if (entmonth==5)
	MessageBox("对不起,现在不在水位控制期!");
			//先显示按钮
//	this->m_read.EnableWindow(TRUE);
//	this->m_count.EnableWindow(TRUE);
}

void CFuzzy2004View::OnButtonRead() 
{
	// TODO: Add your control notification handler code here
	//读取田间水位和降雨量信息,并根据读取的水位信息进行比较提示要供水还是排水警告信息。
	//访问本地数据库利用ODBC连接
	//xxkwh2004.8.15
	//<=0.22
	//0.26
	//0.30
	//0.34
	//>=0.38
	//
	//
	//if(m_shuiwei<=0.22);
	id=2;
	//////////////////////////////////////////////////////////////////
		//先失效以下三个按钮
//	this->m_read.EnableWindow(FALSE);
	this->m_count.EnableWindow(TRUE);
}

void CFuzzy2004View::OnButtonCount() 
{
	// TODO: Add your control notification handler code here
	//根据求得的模糊矩阵和当前田间水位进行计算,得到当前最佳供水量
	////////////////////////////////////////////////////////////
	//数据库中读取数据到数组中
	float rarry[5][3],darry[5][5],parry[5][3];
	//循环变量
	int i,j,k,m,p;
	//存放第一次计算的模糊矩阵,用三维数组存放15个5行5列的矩阵
	float res1[5][5][15];
	///存放第二次计算的模糊矩阵和最后取大处理后的模糊矩阵
	float result[5][5][15],temp,reslast[5][5];
	float putout,sum;
	CString str1;//存放最后结果
	CString strout;


	///////////////////////////////////////////
	//从数据库中获取数据存放到数组中
	//降雨量
	CRain m_rain;

	CDespoit m_despoit;
	//////////////////////////////////////////
	m_rain.Open();
	m_rain.MoveFirst();
	rarry[0][0]=m_rain.m_rainneg2min;
	rarry[0][1]=m_rain.m_rainpos2mid;
	rarry[0][2]=m_rain.m_rainneg2max;
	rarry[1][0]=m_rain.m_rainneg1min;
	rarry[1][1]=m_rain.m_rainneg1mid;
	rarry[1][2]=m_rain.m_rainneg1max;
	rarry[2][0]=m_rain.m_rainzeromin;
	rarry[2][1]=m_rain.m_rainzeromid;
	rarry[2][2]=m_rain.m_rainzeromax;
	rarry[3][0]=m_rain.m_rainpos1min;
	rarry[3][1]=m_rain.m_rainpos1mid;
	rarry[3][2]=m_rain.m_rainpos1max;

⌨️ 快捷键说明

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