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

📄 login.cpp

📁 使用短信猫可以实现短信的群发
💻 CPP
字号:
// Login.cpp : implementation file
//

#include "stdafx.h"
#include "SMS.h"
#include "Login.h"

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

extern CSMSApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CLogin dialog

CLogin::CLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CLogin::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLogin)
	m_UserName = _T("");
	m_Password = _T("");
	m_OracleUser = _T("");
	m_OraclePassword = _T("");
	m_OracleInstance = _T("");
	//}}AFX_DATA_INIT
}


void CLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLogin)
	DDX_Control(pDX, IDC_SERVE_CENTER, m_ServeCenter);
	DDX_Control(pDX, IDC_COMPORT, m_ComPort);
	DDX_CBString(pDX, IDC_USER_NAME, m_UserName);
	DDX_Text(pDX, IDC_PASSWORD, m_Password);
	DDX_Text(pDX, IDC_ORACLE_USER, m_OracleUser);
	DDX_Text(pDX, IDC_ORACLE_PASSWORD, m_OraclePassword);
	DDX_Text(pDX, IDC_ORACLE_INSTANCE, m_OracleInstance);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLogin, CDialog)
	//{{AFX_MSG_MAP(CLogin)
	ON_BN_CLICKED(IDC_SETTING, OnSetting)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogin message handlers

void CLogin::OnSetting() 
{
	// TODO: Add your control notification handler code here
	CString str;
	GetDlgItemText(IDC_SETTING,str);
	TRACE(str);
	if(str=="设置↑")//↓↑
	{
		SetDlgItemText(IDC_SETTING,"设置↓");
	}
	else
	{
		SetDlgItemText(IDC_SETTING,"设置↑");
	}
	
	//static CRect rectLarge;
	//static CRect rectSmall;

	if(rectLarge.IsRectNull())
	{
		CRect rectSeparator;
		GetWindowRect(&rectLarge);//取得窗口的最大宽度跟高度 
		GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);//取得分离线的位置
		rectSmall.left=rectLarge.left;
		rectSmall.top=rectLarge.top;
		rectSmall.right=rectLarge.right;
		rectSmall.bottom=rectSeparator.bottom;
	}
	if(str=="设置↑")
	{
		SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),
			SWP_NOMOVE | SWP_NOZORDER);
	}
	else
	{
		SetWindowPos(NULL,0,0,rectLarge.Width(),rectLarge.Height(),
			SWP_NOMOVE | SWP_NOZORDER);
	}


}

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

	//////////////////////////////////////////////////////////////////////////
	//取出所有的COM端口并添加进下进拉列表框中
	vector<CString> vecCStr;
	CSerialPort::GetCOMList(vecCStr);
	size_t length=vecCStr.size();
	int i=0;
	for(;i<length;i++)
	{
		m_ComPort.InsertString(i,vecCStr[i]);
	}
	m_ComPort.SetCurSel(0);//设置当前选择的项,即默认选项

	//////////////////////////////////////////////////////////////////////////
	//添加服务中心
	m_ServeCenter.InsertString(0,"中国移动");
	m_ServeCenter.InsertString(1,"中国联通");
	m_ServeCenter.SetCurSel(0);
	
	m_OracleUser="cn0705";
	m_OraclePassword="cn0705";
	m_OracleInstance="oracle";
	UpdateData(FALSE);

	OnSetting();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//DEL void CLogin::OnLogging() 
//DEL {
//DEL 	UpdateData();
//DEL 	if(m_UserName.IsEmpty())
//DEL 	{
//DEL 		MessageBox("用户名不能为空!");
//DEL 		return;
//DEL 	}else if(m_Password.IsEmpty())
//DEL 	{
//DEL 		MessageBox("用户密码不能为空!");
//DEL 		return;
//DEL 	}else if(m_OracleUser.IsEmpty())
//DEL 	{
//DEL 		MessageBox("Oracle用户名不能为空!");
//DEL 		return;
//DEL 	}else if(m_OraclePassword.IsEmpty())
//DEL 	{
//DEL 		MessageBox("Oracle密码不能为空!");
//DEL 		return;
//DEL 	}else if(m_OracleInstance.IsEmpty())
//DEL 	{
//DEL 		MessageBox("Oracle实例不能为空!");
//DEL 		return;
//DEL 	}
//DEL 
//DEL 	//用户输入合法的情况下连接数据库
//DEL 	
//DEL 	CSMSApp * pCSMSApp=(CSMSApp *)AfxGetApp();//取得App类对象的指针
//DEL 	CSMSADO &Ado=pCSMSApp->m_SMSAdo;
//DEL 
//DEL 	Ado.ConnectServer(m_OracleInstance,m_OracleUser,m_OraclePassword);
//DEL 	if(!Ado.IsConnection())
//DEL 	{
//DEL 		MessageBox("连接数据库出错\n请重新设置Oracle相关信息");
//DEL 		return;
//DEL 	}
//DEL 	else
//DEL 	{
//DEL 		MessageBox("连接成功");
//DEL 
//DEL 	}
//DEL 	//SQLRECORDSET rs=Ado.ExecuteWithRecordset("SELECT content FROM orders");
//DEL 	//CString test=Ado.GetTextFieldVal(rs,"content");
//DEL 	SQLRECORDSET rs=Ado.ExecuteWithRecordset("SELECT * FROM Users");
//DEL 	CString test=Ado.GetDateTimeFeildVal(rs,"createTime");
//DEL 
//DEL 	TRACE(test);
//DEL 	EndDialog(IDOK);//销毁DoModal()函数创建模式对话框,并返回IDOK值,代表成功登入
//DEL 	// TODO: Add your control notification handler code here
//DEL }

void CLogin::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	if(m_UserName.IsEmpty())
	{
		MessageBox("用户名不能为空!");
		this->GetDlgItem(IDC_USER_NAME)->SetFocus();
		return;
	}else if(m_Password.IsEmpty())
	{
		MessageBox("用户密码不能为空!");
		this->GetDlgItem(IDC_PASSWORD)->SetFocus();
		return;
	}else if(m_OracleUser.IsEmpty())
	{
		MessageBox("Oracle用户名不能为空!");
		OnSetting();
		this->GetDlgItem(IDC_ORACLE_USER)->SetFocus();
		return;
	}else if(m_OraclePassword.IsEmpty())
	{
		MessageBox("Oracle密码不能为空!");
		OnSetting();
		this->GetDlgItem(IDC_ORACLE_PASSWORD)->SetFocus();
		return;
	}else if(m_OracleInstance.IsEmpty())
	{
		MessageBox("Oracle实例不能为空!");
		OnSetting();
		this->GetDlgItem(IDC_SERVE_CENTER)->SetFocus();
		return;
	}

// 	//////////////////////////////////////////////////////////////////////////
// 	//连接数据库部分
// 
	//用户输入合法的情况下连接数据库
	
	CSMSApp * pCSMSApp=(CSMSApp *)AfxGetApp();//取得App类对象的指针
	CSMSADO &Ado=pCSMSApp->m_SMSAdo;

	//这里先进行判断是否跟数据库已创建连接,以连接就不再连接数据库,没连接就进行连接

	if(!Ado.IsConnection())
	{
		Ado.ConnectServer(m_OracleInstance,m_OracleUser,m_OraclePassword);

	}
	
	//这里判断数据连接是否连接成功
	if(!Ado.IsConnection())
	{
		MessageBox("连接数据库出错\n请重新设置Oracle相关信息");
		return;
	}
	else
	{
		//MessageBox("连接成功");
	}
	
	CString sql;
	//long isRecordSet; //判断是否查询到记录
	sql.Format("SELECT authority FROM Users where username='%s' and passwd='%s'",m_UserName,m_Password);
	//isRecordSet=Ado.ExecuteWithoutRecordset(sql);
	SQLRECORDSET rs=Ado.ExecuteWithRecordset(sql);
	
	//这里要先判断是否有记录
	if(	rs->BOF)
	{
		MessageBox("登入的用户名跟密码无效\n请重新输入");
		return;
	} 	

	int authority=Ado.GetIntegerFieldVal(rs,"authority");


	((CSMSApp*)AfxGetApp())->m_UserName=m_UserName;//将用户名保存到全局对象中去
	((CSMSApp*)AfxGetApp())->IsAdministrators=authority;//将用户名保存到全局对象中去


// 	SQLRECORDSET rs=Ado.ExecuteWithRecordset("SELECT * FROM Users");
// 	CString test=Ado.GetDateTimeFeildVal(rs,"createTime");
	
	//////////////////////////////////////////////////////////////////////////
	//保存通讯端口
	CString comName;
	m_ComPort.GetWindowText(comName);
	theApp.m_ComPortName=comName;

	//////////////////////////////////////////////////////////////////////////
	//保存服务中心
	CString serveCenter;
	m_ServeCenter.GetWindowText(serveCenter);
	if(serveCenter=="中国移动")
	{
		theApp.m_ServeCenterNumber="8613800591500";
	}
	else
	{
		theApp.m_ServeCenterNumber="8613010381500";
	}

	TRACE(m_UserName);
	EndDialog(IDOK);//销毁DoModal()函数创建模式对话框,并返回IDOK值,代表成功登入
	// TODO: Add your control notification handler code here
	//CDialog::OnOK();
}

⌨️ 快捷键说明

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