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

📄 manageuserview.cpp

📁 客户端服务器源码
💻 CPP
字号:
// ManageUserView.cpp : implementation file
//

#include "stdafx.h"
#include "clientmain.h"
#include "ManageUserView.h"

#include "CommPrintDlg.h"
#include <string>

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

using namespace std;
/////////////////////////////////////////////////////////////////////////////
// CManageUserView

IMPLEMENT_DYNCREATE(CManageUserView, CFormView)

CManageUserView::CManageUserView()
	: CFormView(CManageUserView::IDD)
{
	//{{AFX_DATA_INIT(CManageUserView)
	m_strType = _T("");
	m_strIDPsw = _T("");
	m_strName = _T("");
	m_strNewPsw = _T("");
	//}}AFX_DATA_INIT
	m_strSql = L"select * from T_Users";
	m_strVSql = m_strSql;
	m_strPSql = m_strSql;
}

CManageUserView::~CManageUserView()
{
}

void CManageUserView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CManageUserView)
	DDX_Control(pDX, IDC_BTN_PRINT, m_btnPrint);
	DDX_Control(pDX, IDC_BTN_QUERY, m_btnQuery);
	DDX_Control(pDX, IDC_EDIT_NAME, m_UserName);
	DDX_Control(pDX, IDC_COMBO_TYPE, m_cmbType);
	DDX_Control(pDX, IDC_BTN_VIEW, m_btnViewAll);
	DDX_Control(pDX, IDC_BTN_PREVIOUS, m_btnPrev);
	DDX_Control(pDX, IDC_BTN_NEXT, m_btnNext);
	DDX_Control(pDX, IDC_BTN_MODIFY, m_btnModify);
	DDX_Control(pDX, IDC_BTN_LAST, m_btnLast);
	DDX_Control(pDX, IDC_BTN_FIRST, m_btnFirst);
	DDX_Control(pDX, IDC_BTN_FIND, m_btnFind);
	DDX_Control(pDX, IDC_BTN_DELETE, m_btnDel);
	DDX_Control(pDX, IDC_BTN_CANCEL, m_btnCancel);
	DDX_Control(pDX, IDC_BTN_ADD, m_btnAddNew);
	DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
	DDX_Text(pDX, IDC_EDIT_IDPSW, m_strIDPsw);
	DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
	DDX_Text(pDX, IDC_EDIT_NEWPSW, m_strNewPsw);
	DDX_Control(pDX, IDC_GRID_VIEWALL, m_grdViewAll);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CManageUserView, CFormView)
	//{{AFX_MSG_MAP(CManageUserView)
	ON_BN_CLICKED(IDC_BTN_FIND, OnBtnFind)
	ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
	ON_BN_CLICKED(IDC_BTN_MODIFY, OnBtnModify)
	ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
	ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
	ON_BN_CLICKED(IDC_BTN_FIRST, OnBtnFirst)
	ON_BN_CLICKED(IDC_BTN_PREVIOUS, OnBtnPrevious)
	ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
	ON_BN_CLICKED(IDC_BTN_LAST, OnBtnLast)
	ON_BN_CLICKED(IDC_BTN_VIEW, OnBtnView)
	ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
	ON_BN_CLICKED(IDC_BTN_PRINT, OnBtnPrint)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CManageUserView diagnostics

#ifdef _DEBUG
void CManageUserView::AssertValid() const
{
	CFormView::AssertValid();
}

void CManageUserView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CManageUserView message handlers
void CManageUserView::OnBtnFirst() 
{
	// TODO: Add your control notification handler code here
	//g_pAdoServer->OpenRecordset();
	HRESULT hr;
	VARIANT_BOOL bEmpty;
	hr = g_pAdoServer->get_Empty(&bEmpty);

	if(bEmpty)
	{
		MessageBox("当前记录集为空!", "Client Error:", MB_OK);
		return;
	}

	g_pAdoServer->First();

	string strType;
	string strName;
	string strNewPsw;
	
	strType = (_bstr_t)g_pAdoServer->Field["UserType"];
	strName = (_bstr_t)g_pAdoServer->Field["Name"];
	strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

	m_strName = strName.c_str();
	m_strType = strType.c_str();
	m_strNewPsw = strNewPsw.c_str();
	m_strIDPsw = strNewPsw.c_str();

	m_strName.TrimLeft();
	m_strName.TrimRight();	
	if(m_strName == "system")
	{
		m_UserName.EnableWindow(FALSE);
	}
	else
	{
		m_UserName.EnableWindow(TRUE);
	}
	UpdateData(FALSE);
}

void CManageUserView::OnBtnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if((m_strType == "") || (m_strName == ""))
	{
		MessageBox("各个字段值不能为空!", NULL, MB_OK);
		return;
	}

	m_strNewPsw.TrimLeft();
	m_strNewPsw.TrimRight();

	m_strIDPsw.TrimLeft();
	m_strIDPsw.TrimRight();

	if(m_strNewPsw != m_strIDPsw)
	{
		MessageBox("前后密码不一致!", NULL, MB_OK);
		return;
	}

	g_pAdoServer->AddNew();

	g_pAdoServer->Field["Name"] = LPCSTR(m_strName);
	g_pAdoServer->Field["Password"] = LPCSTR(m_strNewPsw);
	g_pAdoServer->Field["UserType"] = LPCSTR(m_strType);
	
	g_pAdoServer->Update();
}

void CManageUserView::OnBtnView() 
{
	// TODO: Add your control notification handler code here
	HRESULT hr;
	IDispatch* pDisp;
	_bstr_t strSql("Select * from T_Users");
	
	hr = g_pAdoServer->raw_GetRs(_variant_t(strSql), &pDisp);

	//g_pAdoServer->GetRs();
	m_grdViewAll.SetRefDataSource(pDisp);
}

void CManageUserView::OnBtnCancel() 
{
	// TODO: Add your control notification handler code here
	g_pAdoServer->CancelUpdate();
}

void CManageUserView::OnBtnFind() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	HRESULT hr;

	if(m_strName == "")
	{
		MessageBox("请输入用户名!", NULL, MB_OK);
		return;
	}

	VARIANT_BOOL bEmpty;
	hr = g_pAdoServer->get_Empty(&bEmpty);
	if(bEmpty)
	{
		MessageBox("当前记录集为空!", "Client Error:", MB_OK);
		return;
	}
	
	g_pAdoServer->First();

	CString strTemp;
	strTemp = "Name = '" + m_strName + "'";

	_bstr_t strFind(strTemp); 
	hr = g_pAdoServer->Find(strFind);
	if(SUCCEEDED(hr))
	{
		hr = g_pAdoServer->get_ADOEOF(&bEmpty);
		if(bEmpty)
		{
			MessageBox("没有找到记录!", NULL, MB_OK);
			return;
		}

		string strType;
		string strName;
		string strNewPsw;
		
		strType = (_bstr_t)g_pAdoServer->Field["UserType"];
		strName = (_bstr_t)g_pAdoServer->Field["Name"];
		strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

		m_strName = strName.c_str();
		m_strType = strType.c_str();
		m_strNewPsw = strNewPsw.c_str();
		m_strIDPsw = strNewPsw.c_str();
	}

	m_strName.TrimLeft();
	m_strName.TrimRight();

	if(m_strName == "system")
	{
		m_UserName.EnableWindow(FALSE);
	}
	else
	{
		m_UserName.EnableWindow(TRUE);
	}

	UpdateData(FALSE);
}

void CManageUserView::OnBtnLast() 
{
	// TODO: Add your control notification handler code here
	HRESULT hr;
	VARIANT_BOOL bEmpty;
	hr = g_pAdoServer->get_Empty(&bEmpty);

	if(bEmpty)
	{
		MessageBox("当前记录集为空!", "Client Error:", MB_OK);
		return;
	}
	g_pAdoServer->Last();

	string strType;
	string strName;
	string strNewPsw;
	
	strType = (_bstr_t)g_pAdoServer->Field["UserType"];
	strName = (_bstr_t)g_pAdoServer->Field["Name"];
	strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

	m_strName = strName.c_str();
	m_strType = strType.c_str();
	m_strNewPsw = strNewPsw.c_str();
	m_strIDPsw = strNewPsw.c_str();

	m_strName.TrimLeft();
	m_strName.TrimRight();
	if(m_strName == "system")
	{
		m_UserName.EnableWindow(FALSE);
	}
	else
	{
		m_UserName.EnableWindow(TRUE);
	}

	UpdateData(FALSE);
}

void CManageUserView::OnBtnPrevious() 
{
	// TODO: Add your control notification handler code here
	HRESULT hr;
	VARIANT_BOOL bEmpty;
	hr = g_pAdoServer->get_Empty(&bEmpty);

	if(bEmpty)
	{
		MessageBox("当前记录集为空!", "Client Error:", MB_OK);
		return;
	}
	
	g_pAdoServer->Prev();
	hr = g_pAdoServer->get_BOF(&bEmpty);
	if(bEmpty)
	{
		MessageBox("已经到记录集头部!", NULL, MB_OK);
		g_pAdoServer->First();
	}

	string strType;
	string strName;
	string strNewPsw;
	
	strType = (_bstr_t)g_pAdoServer->Field["UserType"];
	strName = (_bstr_t)g_pAdoServer->Field["Name"];
	strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

	m_strName = strName.c_str();
	m_strType = strType.c_str();
	m_strNewPsw = strNewPsw.c_str();
	m_strIDPsw = strNewPsw.c_str();

	m_strName.TrimLeft();
	m_strName.TrimRight();
	if(m_strName == "system")
	{
		m_UserName.EnableWindow(FALSE);
	}
	else
	{
		m_UserName.EnableWindow(TRUE);
	}

	UpdateData(FALSE);
}

void CManageUserView::OnBtnNext() 
{
	// TODO: Add your control notification handler code here
	HRESULT hr;
	VARIANT_BOOL bEmpty;
	hr = g_pAdoServer->get_Empty(&bEmpty);

	if(bEmpty)
	{
		MessageBox("当前记录集为空!", "Client Error:", MB_OK);
		return;
	}
	
	g_pAdoServer->Next();
	hr = g_pAdoServer->get_ADOEOF(&bEmpty);
	if(bEmpty)
	{
		MessageBox("已经到记录集尾部!", NULL, MB_OK);
		g_pAdoServer->Last();
	}

	string strType;
	string strName;
	string strNewPsw;
	
	strType = (_bstr_t)g_pAdoServer->Field["UserType"];
	strName = (_bstr_t)g_pAdoServer->Field["Name"];
	strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

	m_strName = strName.c_str();
	m_strType = strType.c_str();
	m_strNewPsw = strNewPsw.c_str();
	m_strIDPsw = strNewPsw.c_str();

	m_strName.TrimLeft();
	m_strName.TrimRight();
	if(m_strName == "system")
	{
		m_UserName.EnableWindow(FALSE);
	}
	else
	{
		m_UserName.EnableWindow(TRUE);
	}

	UpdateData(FALSE);
}

void CManageUserView::OnBtnModify() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if((m_strName == "") || (m_strType == ""))
	{
		MessageBox("各个字段值不能为空!", NULL, MB_OK);
		return;
	}
	
	m_strNewPsw.TrimLeft();
	m_strNewPsw.TrimRight();

	m_strIDPsw.TrimLeft();
	m_strIDPsw.TrimRight();
	
	if(m_strNewPsw != m_strIDPsw)
	{
		MessageBox("前后密码不一致!", NULL, MB_OK);
		return;
	}

	g_pAdoServer->Field["Name"] = LPCSTR(m_strName);
	g_pAdoServer->Field["Password"] = LPCSTR(m_strNewPsw);
	g_pAdoServer->Field["UserType"] = LPCSTR(m_strType);
	
	g_pAdoServer->Update();
}

void CManageUserView::OnBtnDelete() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	HRESULT hr;
	VARIANT_BOOL bEmpty;
	hr = g_pAdoServer->get_Empty(&bEmpty);

	if(bEmpty)
	{
		MessageBox("当前记录集为空!", "Client Error:", MB_OK);
		return;
	}
	
	if(m_strName == "system")
	{
		MessageBox("system用户不能删除!", NULL, MB_OK);
		return;
	}
	g_pAdoServer->Delete();
	g_pAdoServer->Update();

	hr = g_pAdoServer->get_ADOEOF(&bEmpty);
	if(bEmpty)
	{
		MessageBox("已经到记录集尾部!", NULL, MB_OK);
		g_pAdoServer->Last();
	}
	else
	{
		g_pAdoServer->Next();
		hr = g_pAdoServer->get_ADOEOF(&bEmpty);
		if(bEmpty)
		{
			MessageBox("已经到记录集尾部!", NULL, MB_OK);
			g_pAdoServer->Last();
		}
	}
	
	string strType;
	string strName;
	string strNewPsw;
	
	strType = (_bstr_t)g_pAdoServer->Field["UserType"];
	strName = (_bstr_t)g_pAdoServer->Field["Name"];
	strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

	m_strName = strName.c_str();
	m_strType = strType.c_str();
	m_strNewPsw = strNewPsw.c_str();
	m_strIDPsw = strNewPsw.c_str();

	// 判断用户名是否为"system"
	m_strName.TrimLeft();
	m_strName.TrimRight();	
	if(m_strName == "system")
	{
		m_UserName.EnableWindow(FALSE); // 是,则不允许修改
	}
	else
	{
		m_UserName.EnableWindow(TRUE); // 不是,则可以修改用户名
	}

	UpdateData(FALSE);
}


void CManageUserView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(bActivate == FALSE)
	{
		HRESULT hr;
		VARIANT_BOOL bEmpty;
		hr = g_pAdoServer->get_Empty(&bEmpty);

		if(bEmpty)
		{
			return;
		}
		else
		{
			g_pAdoServer->get_BookMark(&m_vBookMark);
			return;
		}
	}
	else
	{
		g_pAdoServer->CloseRecordset();
		g_pAdoServer->OpenRecordset(m_strSql);

		HRESULT hr;
		VARIANT_BOOL bEmpty;
		hr = g_pAdoServer->get_Empty(&bEmpty);

		if(bEmpty)
		{
			return;
		}
		else
		{
			g_pAdoServer->put_BookMark(m_vBookMark);
		}
		string strType;
		string strName;
		string strNewPsw;
		
		strType = (_bstr_t)g_pAdoServer->Field["UserType"];
		strName = (_bstr_t)g_pAdoServer->Field["Name"];
		strNewPsw = (_bstr_t)g_pAdoServer->Field["Password"];

		m_strName = strName.c_str();
		m_strType = strType.c_str();
		m_strNewPsw = strNewPsw.c_str();
		m_strIDPsw = strNewPsw.c_str();

		// system用户不允许编辑和删除
		m_strName.TrimLeft();
		m_strName.TrimRight();
		if(m_strName == "system")
		{
			m_UserName.EnableWindow(FALSE);
		}
		else
		{
			m_UserName.EnableWindow(TRUE);
		}

		UpdateData(FALSE);
	}
	
	CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CManageUserView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CString strTitle ;
	strTitle = "用户信息管理";
	GetParentFrame()->SetWindowText(strTitle);

	m_cmbType.AddString("finance");
	m_cmbType.AddString("material");
	m_cmbType.AddString("sell");
	m_cmbType.AddString("system");
	
	//GetParentFrame()->RecalcLayout();
	//ResizeParentToFit(FALSE);
	//ResizeParentToFit(TRUE);
	// 进行有关界面初始化的工作。为按钮设置图标
	m_btnAddNew.SetIcon(AfxGetApp()->LoadIcon(IDI_ADDNEW));
	m_btnModify.SetIcon(AfxGetApp()->LoadIcon(IDI_MODIFY));
	m_btnDel.SetIcon(AfxGetApp()->LoadIcon(IDI_DELETE));
	m_btnCancel.SetIcon(AfxGetApp()->LoadIcon(IDI_CANCEL));
	m_btnFirst.SetIcon(AfxGetApp()->LoadIcon(IDI_FIRST));
	m_btnPrev.SetIcon(AfxGetApp()->LoadIcon(IDI_PREVIOUS));
	m_btnNext.SetIcon(AfxGetApp()->LoadIcon(IDI_NEXT));
	m_btnLast.SetIcon(AfxGetApp()->LoadIcon(IDI_LAST));
	m_btnViewAll.SetIcon(AfxGetApp()->LoadIcon(IDI_VIEWALL));
	m_btnFind.SetIcon(AfxGetApp()->LoadIcon(IDI_FIND));
	m_btnQuery.SetIcon(AfxGetApp()->LoadIcon(IDI_QUERY));
	m_btnPrint.SetIcon(AfxGetApp()->LoadIcon(IDI_PRINT));

	GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);
}

void CManageUserView::OnBtnQuery() 
{
	// TODO: Add your control notification handler code here
	HRESULT hr;
	IGxp_adoQueryPtr  pQuery;
	MULTI_QI MultiQI;
	
	MultiQI.hr = NOERROR;	MultiQI.pItf = NULL;	
	MultiQI.pIID = &__uuidof(IGxp_adoQuery);	
	

	hr = CoCreateInstanceEx( __uuidof(Gxp_adoQuery), NULL, CLSCTX_LOCAL_SERVER, NULL, 1, &MultiQI);
	
	if(SUCCEEDED(hr))
	{
		pQuery = (IGxp_adoQuery *)MultiQI.pItf;
		//MessageBox(NULL,"CoCreateInstance Successful.",NULL,MB_OK);
	}
	else
	{
		MessageBox("CoCreateInstance Failed","Client Error:",MB_OK);
		return ;
	}
	
	IDispatch* pDisp;

	// 下面是一系列的处理过程,包括了调用通用查询对话框,处理字符串等
	string strSpace = " where ";
	string strSource;
	string strResult;

	hr = g_pAdoServer->raw_GetRs(_variant_t(m_strVSql), &pDisp);
	strResult = pQuery->GetQuery(pDisp);
	
	if(strResult.empty())
	{
		m_strPSql = m_strVSql;
		return;
	}
	strSource = m_strVSql;
	strResult = strSource + strSpace + strResult;
	_bstr_t strDest(strResult.c_str());
	m_strPSql = strDest;
	
	hr = g_pAdoServer->raw_GetRs(_variant_t(strDest), &pDisp);
	m_grdViewAll.SetRefDataSource(pDisp);	
}

void CManageUserView::OnBtnPrint() 
{
	// TODO: Add your control notification handler code here
	CCommPrintDlg  printDlg;
	printDlg.m_strSql = m_strPSql;
	printDlg.DoModal();
}

⌨️ 快捷键说明

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