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

📄 variableinfodlg.cpp

📁 vc编程实现bp神经网络
💻 CPP
字号:
// VariableInfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "optsoftware.h"
#include "VariableInfoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CVariableInfoDlg dialog


CVariableInfoDlg::CVariableInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVariableInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVariableInfoDlg)
	m_VName = _T("");
	m_VRemarks = _T("");
	//}}AFX_DATA_INIT
}


void CVariableInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVariableInfoDlg)
	DDX_Control(pDX, IDC_VLIST, m_VList);
	DDX_Text(pDX, IDC_EDT_VNAME, m_VName);
	DDX_Text(pDX, IDC_EDT_VREMARKS, m_VRemarks);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CVariableInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CVariableInfoDlg)
	ON_NOTIFY(NM_CLICK, IDC_VLIST, OnClickVlist)
	ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
	ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVariableInfoDlg message handlers

void CVariableInfoDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	if(!m_VName.IsEmpty())
	{ 
		if(!m_VRemarks.IsEmpty())
		{
			//CVariInfoRS *rs_vinfo=new CVariInfoRS(&m_database); 
        	if(!m_database->IsOpen()) return;
	        if(!m_recordset) return;
	        if(m_recordset->IsOpen()) m_recordset->Close();

			CString strSQL;
			strSQL.Format ("select * from tab_VariableInfo where Us_Name='%s' and Variable_Name='%s'",username,m_VName);
	        m_recordset->Open (dbOpenDynaset,strSQL);
   	        if(m_recordset->IsEOF())
			{
                strSQL.Format("insert into tab_VariableInfo(Us_Name,Variable_Name,Variable_Remarks)\
					Values('%s','%s','%s')",username,m_VName,m_VRemarks);
				try
				{
					if(m_database->CanUpdate())
						m_database->Execute(strSQL);
				}
				catch(CDaoException* e)
				{
					e->ReportError();
					e->Delete();
					return;
				}
	            UpdateList();
		        m_VName=_T("");
                m_VRemarks=_T("");
			}
		    else
				AfxMessageBox("此变量名已存在!");
		    m_recordset->Close();
		}
	}
    (CButton*)GetDlgItem(IDC_EDT_VNAME)->EnableWindow(FALSE);
	(CButton*)GetDlgItem(IDC_EDT_VREMARKS)->EnableWindow(FALSE);    
	UpdateData(false);
    AfxMessageBox("您确定退出变量定义窗口?");
	CDialog::OnOK();
}

void CVariableInfoDlg::UpdateList()
{
    int i=0;
	CString strSQL;
	m_VList.DeleteAllItems();
    UpdateData();

	if(!m_database->IsOpen()) return;
	if(!m_recordset) return;
	if(m_recordset->IsOpen()) m_recordset->Close();

	strSQL.Format ("select * from tab_VariableInfo where Us_Name='%s' and Model_Name is null",username);
    m_recordset->Open(dbOpenDynaset,strSQL);
	if (!m_recordset->IsEOF())
	{
		while(!m_recordset->IsEOF())
		{
			m_VList.InsertItem(i,"");
            COleVariant var;
		    m_recordset->GetFieldValue(0,var);
		    m_VList.SetItemText(i,0,(LPCTSTR)var.bstrVal);
			m_recordset->GetFieldValue(2,var);
		    m_VList.SetItemText(i,1,(LPCTSTR)var.bstrVal);
			m_recordset->GetFieldValue(4,var);
		    m_VList.SetItemText(i,2,(LPCTSTR)var.bstrVal);
		    m_recordset->MoveNext();
    		i++;
		}
	}
	m_recordset->Close();
}

BOOL CVariableInfoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	m_VList.InsertColumn(0,"用户名",LVCFMT_LEFT,60);
    m_VList.InsertColumn(1,"变量名",LVCFMT_LEFT,60);
    m_VList.InsertColumn(2,"变量说明",LVCFMT_LEFT,150);
	m_VList.SetExtendedStyle(LVS_EX_FULLROWSELECT);//设置选中一个位置,则改行均高亮
	UpdateList();
	return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}

void CVariableInfoDlg::OnClickVlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int i=m_VList.GetSelectionMark();
	if (i==-1)
		MessageBox("请先选择一条记录!");
	else
	{
		m_VList.SetHotItem(i);
	}
	*pResult = 0;
}

void CVariableInfoDlg::OnBtnDelete() 
{
	// TODO: Add your control notification handler code here
	CString strSQL;
	int ItemSel;
	POSITION pos=m_VList.GetFirstSelectedItemPosition();
	if (pos==NULL)
	{
		AfxMessageBox("没有选择欲删除的记录!");
		return;
	}
	else while (pos)
	{
		ItemSel=m_VList.GetNextSelectedItem(pos);
		strSQL.Format("delete from tab_VariableInfo where Us_Name='%s' and Variable_Name='%s'",m_VList.GetItemText(ItemSel,0),m_VList.GetItemText(ItemSel,1));
		m_database->Execute(strSQL);
	}
	UpdateList();
}

void CVariableInfoDlg::OnBtnNext() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
    if(!m_VName.IsEmpty())
	{ 
		if(!m_VRemarks.IsEmpty())
		{
        	if(!m_database->IsOpen()) return;
	        if(!m_recordset) return;
	        if(m_recordset->IsOpen()) m_recordset->Close();

			CString strSQL;
			strSQL.Format ("select * from tab_VariableInfo where Us_Name='%s' and Variable_Name='%s'",username,m_VName);
	        m_recordset->Open (dbOpenDynaset,strSQL);
   	        if(m_recordset->IsEOF())
			{
                strSQL.Format("insert into tab_VariableInfo(Us_Name,Variable_Name,Variable_Remarks)\
					Values('%s','%s','%s')",username,m_VName,m_VRemarks);
				try
				{
					if(m_database->CanUpdate())
						m_database->Execute(strSQL);
				}
				catch(CDaoException* e)
				{
					e->ReportError();
					e->Delete();
					return;
				}
			}
		    else
			    AfxMessageBox("此变量名已存在!");
			m_recordset->Close();
		}
		else AfxMessageBox("没有输入变量说明!");
	}
	else AfxMessageBox("没有输入变量名!");
	m_VName=_T("");
    m_VRemarks=_T("");
	UpdateData(false);
	UpdateList();
}

void CVariableInfoDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	m_VName=_T("");
    m_VRemarks=_T("");
	UpdateData(false);
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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