Exemplo n.º 1
0
void main(void)

{
	// open with datasource name.
	MyDB.Open("WoofBase");
	
	// creation of the record set must happen AFTER the Database open!
	CMyRecordset	MyRecordset("SELECT Text1,Key1,Number1 FROM WOOFTABLE WHERE Number1 = 2",
								&MyDB);


	// open as a static snapshot
	MyRecordset.Open(CRecordset::snapshot);

	while(!MyRecordset.IsEOF())
	{
		MyRecordset.PrintRecord();
		MyRecordset.MoveNext();
	}

	MyRecordset.Close();
	MyDB.Close();

	cout << endl;
	cout << "the select was: " << MyRecordset.GetDefaultSQL() << endl;
}
Exemplo n.º 2
0
bool EVUtil::ODBCCmdSQL( CString szDBName,CString sql )
{
	CDatabase db;
	CString strConnect;
	strConnect.Format(_T("ODBC;DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)};UID=sa;PWD=;DBQ=%s"), szDBName);

	db.Open(NULL, FALSE, FALSE, strConnect,FALSE);
	if(db.IsOpen())
	{
		//连接数据库成功
		CRecordset rs(&db);   //SQL语句
		try
		{
			db.ExecuteSQL(sql);
		}
		catch (...)
		{
			db.Close();
			return false;
		}
		db.Close();
		return true;
	}
	return false;
}
Exemplo n.º 3
0
void Regist::OnKillfocusEditRegistEmail()
{
    UpdateData(TRUE);
    CDatabase db;
    db.Open("bankmanagement");
    CString sqlstr;
    sqlstr.Format(_T("select count(*) from user where user_email='%s'"), m_RegEmail);
    CRecordset rs(&db);
    rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr));
    CString	count;
    rs.GetFieldValue(_T("count(*)"), count);
    //MessageBox(count);
    if (count == '1')
    {
        GetDlgItem(IDC_EMAIL_NOTICE)->SetWindowTextA((CString)"×邮箱已被注册!");
        GetDlgItem(IDC_REGIST_REGIST)->EnableWindow(false);
    }//MessageBox("用户名已存在,请重新输入。", "输入有误");
    else
    {
        GetDlgItem(IDC_EMAIL_NOTICE)->SetWindowTextA((CString)"√可以使用");
        GetDlgItem(IDC_REGIST_REGIST)->EnableWindow(true);
    }
    rs.Close();
    db.Close();
    // TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 4
0
void AccountDeposit::OnClickedAccountDepositComfirm()
{
	CDatabase db;
	db.Open("bankmanagement");
	CString sqlstr,sqlstraccount;//,username,idcard,pwd,address,email,number;
	
	UpdateData(true);
	if (m_DepositAmount<1 || m_DepositAmount>10000);
	else{
		CString timestr;//////获取系统时间
		CTime tm; tm = CTime::GetCurrentTime();
		timestr = tm.Format("%Y年%m月%d日 %X");
		sqlstr.Format(_T("insert into operate_deposit(card_number,money_value,operate_time) values('%s','%f','%s')"), m_DepositCardnumber, m_DepositAmount,timestr);
		sqlstraccount.Format(_T("update card set money_balance=money_balance+'%f'where card_number='%s'"), m_DepositAmount, m_DepositCardnumber);
		MessageBox("确定吗?");
		db.ExecuteSQL(sqlstr);
		db.ExecuteSQL(sqlstraccount);
		db.Close();
		MessageBox("存款成功!");
		m_DepositCardnumber = "";
		m_DepositUsername = "";
		m_DepositAmount = 0;
		UpdateData(FALSE);
	}
	// TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 5
0
void AccountDeposit::OnKillfocusEditDepositCard()
{
	UpdateData(TRUE);
	CDatabase db;
	db.Open("bankmanagement");
	CString sqlstrconfirm,foundflag;
	sqlstrconfirm.Format(_T("select count(user_name) from user where user_id=(select user_id from card where card_number='%s')"), m_DepositCardnumber);
	CRecordset rs(&db);
	rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstrconfirm));
	rs.GetFieldValue(_T("count(user_name)"), foundflag);
	if (foundflag == '0'){
		MessageBox("这张卡不存在");
		GetDlgItem(IDC_ACCOUNT_DEPOSIT_COMFIRM)->EnableWindow(false);
	}
	else
	{
		GetDlgItem(IDC_ACCOUNT_DEPOSIT_COMFIRM)->EnableWindow(true);
		CString sqlstr;
		sqlstr.Format(_T("select user_name from user where user_id=(select user_id from card where card_number='%s')"), m_DepositCardnumber);
		CRecordset rss(&db);
		rss.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr));
		rss.GetFieldValue(_T("user_name"), m_DepositUsername);
		//MessageBox(m_DepositUsername);
		UpdateData(FALSE);
		rss.Close();
	}
	rs.Close();
	db.Close();
	// TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 6
0
//定义的向数据库存储新的基本信息的函数
_declspec(dllexport) int WINAPI putmsg(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	whichtab=0;
	bmsg  bt;
	if(res==NULL)
		return 1;	//error
	memset((void*)&bt,0,sizeof(bt));
	memcpy((void*)&bt,res,sizeof(bt));
	CString str;
	crt_conn(str);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,str);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll",0);
		return 1;
	}
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,"SELECT * FROM base_msg");}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll",0);
		return 1;
	}
	mrd.AddNew();
//	memset((void*)&mrd.bsd,0,sizeof(mrd.bsd));
//	memcpy((void*)&mrd.bsd,bt,sizeof(mrd.bsd));
/*2015-6-15 不使用整个结构拷贝,而是逐个字段赋值的方法可以避免自动增量字段的人为改变。
这里还有一个微软认可的bug,就是在调试模式时,就会出现一个CRecordset的成员地址改变的傻逼断言,
该断言好像在dbrfx.cpp文件中(line560),通过查看dbrfx.cpp文件发现,这个断言是在#ifdef _DEBUG的判断下
执行的,所以在release版本下不会有错误,但是在调式模式下会出现断言错误。
*/
	mrd.bsd.code=bt.code;
	mrd.bsd.gmax=bt.gmax;
	mrd.bsd.gstd=bt.gstd;
	mrd.bsd.gtimes=bt.gtimes;
	mrd.bsd.gtype=bt.gtype;
	mrd.bsd.gwatch=bt.gwatch;
	memcpy((void *)&(mrd.bsd.name),(void*)&(bt.name),60);
	mrd.bsd.gcycle=bt.gcycle;
	mrd.bsd.gdecay=bt.gdecay;
	mrd.Update();
	mrd.Close();
	db.Close();

	return 0;
};
Exemplo n.º 7
0
void AccountDetail::OnClickedCardWithdraw()
{
	CDatabase db;
	db.Open("bankmanagement");
	CString sqlstr;//,username,idcard,pwd,address,email,number;
	sqlstr.Format(_T("update card set card_status='申请注销' where card_number='%s'"), m_DetailCard);
	db.ExecuteSQL(sqlstr);
	db.Close();
	MessageBox("管理员会在10个工作日内处理");
	// TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 8
0
void ManagerProperty::OnClickedInterestFee()
{
	CDatabase db;
	db.Open("bankmanagement");
	CString sqlstr,sqlstrcardnumber,sqlstrafteramount,sqlstrupdate,updatenumber;
	int cardnumber;
	
	sqlstr.Format(_T("update card set money_balance=money_balance-2 where card_status='正常'"));//////扣费
	db.ExecuteSQL(sqlstr);

	sqlstr.Format(_T("select count(*) from card where card_status='正常'"));/////查出卡片数
	CRecordset rss(&db);
	rss.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr));
	rss.GetFieldValue(_T("count(*)"), sqlstrcardnumber);
	cardnumber = _ttoi(sqlstrcardnumber);
	UpdateData(FALSE);
	rss.Close();
	
	sqlstr.Format(_T("select card_number from card where card_status='正常'"));/////记录收费数据
	CRecordset r(&db);
	r.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr));
	CString timestr;///////////get system time
	CTime tm;
	while (!r.IsEOF())
	{
		tm = CTime::GetCurrentTime();
		timestr = tm.Format("%Y年%m月%d日 %X");
		r.GetFieldValue(_T("card_number"), updatenumber);
		sqlstrupdate.Format(_T("insert into operate_bank(card_number,money_amount,operate_type,operate_time) values('%s',2,'卡管理费','%s')"), updatenumber,timestr);
		db.ExecuteSQL(sqlstrupdate);
		r.MoveNext();
	}
	
	r.Close();

	float fee = cardnumber*2.0;//////转入银行账户
	sqlstr.Format(_T("update bank_account set money_amount=money_amount+'%f'"), fee);
	db.ExecuteSQL(sqlstr);

	sqlstr.Format(_T("select money_amount from bank_account"));////更新现实银行账户余额
	CRecordset rs(&db);
	rs.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr));
	CString	stramount;
	rs.GetFieldValue(_T("money_amount"), stramount);
	m_ManagerPropertyamount = _tstof(stramount);
	UpdateData(FALSE);
	rs.Close();

	db.Close();
	MessageBox("手续费处理成功!");
	// TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 9
0
void ManageAccount::OnClickedManageModifyModify()
{
	UpdateData(true);
	CString sqlstr;
	sqlstr.Format(_T("update user set user_name='%s',user_idcard='%s',user_address='%s',user_email='%s',phone_number='%s' where user_id ='%d'"), m_ManageaccountUsername, m_ManageaccountIdcard, m_ManageaccountAddress, m_ManageaccountEmail, m_ManageaccountPhone,dealid);
	CDatabase db;
	db.Open("bankmanagement");
	db.ExecuteSQL(sqlstr);
	db.Close();
	MessageBox("更新成功,点击返回。");
	OnOK();
	// TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 10
0
//定义的删除数据的函数
_declspec(dllexport) int WINAPI deldata(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(res==NULL)
		return 1;
	whichtab=1;
	CString str,conn;
	crt_conn(conn);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,conn);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll-008",0);
		return 1;
	}
	str.Format("%s",(char*)res);
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,str);}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll-010",0);
		return 1;
	}
	if(mrd.IsEOF() || !mrd.CanUpdate() || !mrd.CanTransact())
	{
		MessageBox(NULL,"delete result error!","from dll-009",0);
		mrd.Close();
		db.Close();
		return 1;
	}
/*	mrd.MoveFirst();
	while(!mrd.IsEOF())
	{
		mrd.Delete();
		mrd.MoveNext();
	}
*/
	mrd.Delete();
	db.CommitTrans();
	mrd.Close();
	db.Close();
	return 0;
};
Exemplo n.º 11
0
/*2015-6-21修改,修改为按查询条件取得记录,条件查询语句直接在函数外构造,并直接通过参数传入
在本函数直接使用。*/
_declspec(dllexport) int WINAPI get_dt(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(res==NULL)
		return 1;
	whichtab=3;
	dldt.RemoveAll();
	CString str;
	crt_conn(str);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,str);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll-1007",0);
		return 1;
	}
	str.Format("%s",(char*)res,strlen((char*)res));
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,str,0);}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll-1008",0);
		return 1;
	}
	if(mrd.IsEOF())
	{
		mrd.Close();
		db.Close();
		return 0;
	}
	mrd.MoveFirst();
	while(!mrd.IsEOF())
	{
		dldt.Add(mrd.dt);
		mrd.MoveNext();
	}
	mrd.Close();
	db.Close();
	return 0;
};
Exemplo n.º 12
0
//定义的从数据库读出的基本信息的函数
_declspec(dllexport) int WINAPI getmsg(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
//	if(res==NULL)
//		return 1;
	whichtab=0;
	dlmsg.RemoveAll();
	CString str,s1;
	crt_conn(str);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,str);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll",0);
		return 1;
	}
	s1.Format("SELECT * FROM base_msg");
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,s1);}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll-001",0);
		return 1;
	}
	if(mrd.IsEOF())
	{
		mrd.Close();
		db.Close();
		return 0;
	}
	mrd.MoveFirst();
	while(!mrd.IsEOF())
	{
		dlmsg.Add(mrd.bsd);
		mrd.MoveNext();
	}
	mrd.Close();
	db.Close();
	return 0;
};
Exemplo n.º 13
0
BOOL ManagerChartNew::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	///////////////////////////////产生图表
	CSeries0 lineSeries = (CSeries0)m_chartnew.Series(0);
	lineSeries.Clear();




	CString sqlstr;
	sqlstr.Format(_T("CREATE OR REPLACE VIEW `view_day_property`AS SELECT * FROM day_property ORDER BY day_property.dayproperty_id DESC LIMIT 10;"));
	CDatabase db;
	db.Open("bankmanagement");
	db.ExecuteSQL(sqlstr);
	sqlstr.Format(_T("select day_time,bank_balance from view_day_property  ORDER BY dayproperty_id ASC;"));
	CRecordset rs(&db);
	rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr));
	CString strx, strbalance;
	double daybalance;


	for (int i = 0; i<10; i++)
	{

		CString varDayTime;
		rs.GetFieldValue(_T("day_time"), varDayTime);
		strx.Format(_T("%s"), varDayTime);

		CString varBankBalance;
		rs.GetFieldValue(_T("bank_balance"), varBankBalance);
		strbalance.Format(_T("%s"), varBankBalance);
		daybalance = _ttof(strbalance);

		lineSeries.AddXY((double)i, daybalance, strx, 0);
		rs.MoveNext();
	}

	rs.Close();


	db.Close();


	return true;
}
Exemplo n.º 14
0
// CDatabaseDlg2 消息处理程序
void CDatabaseDlg2::ShowDatabase(CString cmdStr)
{
	m_list.DeleteAllItems();
	//打开数据库
	CDatabase db;
	db.Open(NULL,FALSE,FALSE,"ODBC;DSN=face;UID=root;PWD=root");
	//创建查询结果接收集
	CRecordset rs(&db);
	rs.Open(CRecordset::forwardOnly,(L"%s",cmdStr));
	int i = 0;
	//操作查询结果
	while(!rs.IsEOF())
	{
		CString id;
		rs.GetFieldValue("ID",id);
		m_list.InsertItem(i,id);

		CString simg;
		rs.GetFieldValue("SourceImg",simg);
		m_list.SetItemText(i,1,simg);

		CString spath;
		rs.GetFieldValue("SourcePath",spath);
		m_list.SetItemText(i,2,spath);

		CString fimg;
		rs.GetFieldValue("FaceName",fimg);
		m_list.SetItemText(i,3,fimg);

		CString fpath;
		rs.GetFieldValue("FacePath",fpath);
		m_list.SetItemText(i,4,fpath);

		CString date;
		rs.GetFieldValue("Time",date);
		m_list.SetItemText(i,5,date);
		i++;

		rs.MoveNext();
		
	}
	m_list.SetExtendedStyle(LVS_EX_FLATSB | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	//关闭数据库
	rs.Close();
	db.Close();
}
Exemplo n.º 15
0
//定义的表格4 data_tab的存储函数,该函数也用于记录的批量处理
_declspec(dllexport) int WINAPI put_dt(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(res==NULL)
		return 1;
	whichtab=3;
	CArray<data_tab,data_tab&> *ca;
	ca=(CArray<data_tab,data_tab&> *)res;
	CString str;
	int i,j;
	crt_conn(str);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,str);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll-1003",0);
		return 1;
	}
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,"SELECT * FROM data_tab",0);}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll-1004",0);
		return 1;
	}
	i=ca->GetCount();
	for(j=0;j<i;j++)
	{
		mrd.AddNew();
		memset((void*)&(mrd.dt),0,sizeof(mrd.dt));
		mrd.dt=ca->GetAt(j);
		mrd.Update();
	}
	mrd.Close();
	db.Close();
	return 0;
};
Exemplo n.º 16
0
void CDatabaseDlg2::OnBnClickedDeleteFace()
{
	// TODO: 在此添加控件通知处理程序代码
	int nIndex;
	CString id,fpath;
	CDatabase db;
	db.Open(NULL, FALSE, FALSE, _T("ODBC;DSN=face;UID=root;PWD=root"));
	nIndex = m_list.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
	//if(-1 == nIndex)
	//    nIndex = 0;
	if(-1 != nIndex)
	{
		id = m_list.GetItemText(nIndex,0);
		fpath = m_list.GetItemText(nIndex,4);
	}
	else     
	{   
		MessageBox("请选择要删除人脸!");
		db.Close();
		return;
	}

	//删除文件
	CFileFind finder;
	if(finder.FindFile(fpath))
	{
		CFile TempFile; 
		TempFile.Remove(fpath);
	}


	CString sql;
	sql.Format("delete from face where ID=%s", id);
	db.ExecuteSQL(sql);
	db.Close();
	
	CString cmdStr = "Select * from face order by ID";
	m_sname.SetWindowText("");
	m_spath.SetWindowText("");
	m_fname.SetWindowText("");
	m_fpath.SetWindowText("");
	ShowDatabase(cmdStr);
	MessageBox("删除成功");
}
Exemplo n.º 17
0
/*2015-6-21修改,该函数无需批量处理,所以传入的参数不是队列而是一个结构指针*/
_declspec(dllexport) int WINAPI put_ct(void *res)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(res==NULL)
		return 1;
	whichtab=2;
	CString str;
	crt_conn(str);
	CDatabase db;
	if(db.IsOpen())
		db.Close();
	try
	{db.Open(NULL,false,false,str);}
	catch(CDBException *ep)
	{
		MessageBox(NULL,ep->m_strError,"from dll-1001",0);
		return 1;
	}
	myrecord mrd(&db);
	if(mrd.IsOpen())
		mrd.Close();
	try
	{mrd.Open(AFX_DB_USE_DEFAULT_TYPE,"SELECT * FROM code_tab");}
	catch(CDBException *ep)
	{
		db.Close();
		MessageBox(NULL,ep->m_strError,"from dll-1002",0);
		return 1;
	}
/*	mrd.AddNew();
	memset((void*)&(mrd.ct),0,sizeof(mrd.ct));
	memcpy((void*)&(mrd.ct),res,sizeof(mrd.ct)); */
	mrd.MoveFirst();
	mrd.Edit();
	memcpy((void*)&(mrd.ct),res,sizeof(mrd.ct));
	mrd.Update();
	mrd.Close();
	db.Close();
	return 0;
};
Exemplo n.º 18
0
BOOL ManageAccount::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CString sqlstr;
	sqlstr.Format(_T("select user_name,user_idcard,user_address,user_email,phone_number from user where user_id ='%d'"), dealid);
	
	CDatabase db;
	db.Open("bankmanagement");
	CRecordset rs(&db);
	rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr));
	rs.GetFieldValue(_T("user_name"), m_ManageaccountUsername);
	rs.GetFieldValue(_T("user_idcard"), m_ManageaccountIdcard);
	rs.GetFieldValue(_T("user_address"), m_ManageaccountAddress);
	rs.GetFieldValue(_T("user_email"), m_ManageaccountEmail);
	rs.GetFieldValue(_T("phone_number"), m_ManageaccountPhone);
	

	rs.Close();
	db.Close();
	UpdateData(false);
	if (modifyflag == 0)
	{
		GetDlgItem(IDC_MANAGE_ACCOUNT_USERNAME)->EnableWindow(false);
		GetDlgItem(IDC_MANAGE_ACCOUNT_IDCARD)->EnableWindow(false);
		GetDlgItem(IDC_MANAGE_ACCOUNT_ADDRESS)->EnableWindow(false);
		GetDlgItem(IDC_MANAGE_ACCOUNT_EMAIL)->EnableWindow(false);
		GetDlgItem(IDC_MANAGE_ACCOUNT_PHONE)->EnableWindow(false);
		GetDlgItem(IDC_MANAGE_MODIFY_MODIFY)->ShowWindow(SW_HIDE);
	}
	else
	{
		GetDlgItem(IDC_MANAGE_ACCOUNT_USERNAME)->EnableWindow(false);
		GetDlgItem(IDC_MANAGE_ACCOUNT_IDCARD)->EnableWindow(true);
		GetDlgItem(IDC_MANAGE_ACCOUNT_ADDRESS)->EnableWindow(true);
		GetDlgItem(IDC_MANAGE_ACCOUNT_EMAIL)->EnableWindow(true);
		GetDlgItem(IDC_MANAGE_ACCOUNT_PHONE)->EnableWindow(true);
		GetDlgItem(IDC_MANAGE_MODIFY_MODIFY)->ShowWindow(SW_SHOW);
	}
	return true;
}
Exemplo n.º 19
0
void Regist::OnClickedRegistRegist()
{
    CDatabase db;
    db.Open("bankmanagement");
    CString sqlstr;//,username,idcard,pwd,address,email,number;
    UpdateData(TRUE);//更新文本框变量
    //MessageBox(m_RegUsername);

    sqlstr.Format(_T("insert into user(user_name,user_idcard,user_pwd,user_address,user_email,phone_number) values('%s','%s','%s','%s','%s','%s')"), m_RegUsername, m_RegIdcard, m_RegPwd, m_RegAddress, m_RegEmail, m_RegPhone);
    if (m_RegUsername.IsEmpty() || m_RegPwd.IsEmpty() || m_RegPwdConfirm.IsEmpty() || m_RegIdcard.IsEmpty() || m_RegAddress.IsEmpty() || m_RegEmail.IsEmpty())
    {
        MessageBox("带*为必填项", "输入有误");
    }
    else if (m_RegUsername == "用户名为字母与数字组合")
    {
        MessageBox("用户名未修改");
    }
    else if (m_RegPwd.GetLength() < 6)
    {
        MessageBox("密码太短!","输入有误");
    }
    else if (m_RegPwd != m_RegPwdConfirm)
    {
        MessageBox("输入密码不一致", "输入有误");
    }
    else
    {
        db.ExecuteSQL(sqlstr);
        db.Close();
        MessageBox("注册成功!返回登录。");
        //this->GetParent()->SendMessage(WM_CLOSE);//关闭父对话框
        Hello dlg;
        fatherflag = 1;
        ShowWindow(SW_HIDE);
        dlg.DoModal();
        ShowWindow(SW_SHOW);
    }
    // TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 20
0
BOOL ManagerPropertyFeeDetail::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	
	FeeDetailList.InsertColumn(1, _T("银行卡号"), LVCFMT_LEFT, 80);
	FeeDetailList.InsertColumn(2, _T("操作金额"), LVCFMT_LEFT, 80);
	FeeDetailList.InsertColumn(3, _T("操作类型"), LVCFMT_LEFT, 80);
	FeeDetailList.InsertColumn(4, _T("操作时间"), LVCFMT_LEFT, 200);
	
	CString sqlstr;
	sqlstr.Format(_T("select card_number,money_amount,operate_type,operate_time from operate_bank"));

	FeeDetailList.DeleteAllItems();
	CDatabase db;
	db.Open("bankmanagement");
	CRecordset rs(&db);
	rs.Open(CRecordset::forwardOnly, (_T("%s"), sqlstr));
	while (!rs.IsEOF())
	{
		CString varCardNumber;
		rs.GetFieldValue(_T("card_number"), varCardNumber);
		FeeDetailList.InsertItem(0, varCardNumber);
		CString varMoneyAmount;
		rs.GetFieldValue(_T("money_amount"), varMoneyAmount);
		FeeDetailList.SetItemText(0, 1, varMoneyAmount);
		CString varOperateType;
		rs.GetFieldValue(_T("operate_type"), varOperateType);
		FeeDetailList.SetItemText(0, 2, varOperateType);
		CString varOperateTime;
		rs.GetFieldValue(_T("operate_time"), varOperateTime);
		FeeDetailList.SetItemText(0, 3, varOperateTime);
		rs.MoveNext();
	}
	FeeDetailList.SetExtendedStyle(LVS_EX_FLATSB | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	rs.Close();
	db.Close();
	return true;
}
Exemplo n.º 21
0
void CDatabaseDlg2::OnBnClickedAlterFace()
{
	// TODO: 在此添加控件通知处理程序代码
	int nIndex;
	CString sname,spath,fname,fpath,id;
	CDatabase db;
	db.Open(NULL, FALSE, FALSE, _T("ODBC;DSN=face;UID=root;PWD=root"));
	nIndex = m_list.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
	//if(-1 == nIndex)
	//    nIndex = 0;
	if(-1 == nIndex)
	{
		MessageBox("请选择要修改的列");
		db.Close();
		return;
	}
	else     
	{  
		id = m_list.GetItemText(nIndex,0);
		m_sname.GetWindowText(sname);
		m_spath.GetWindowText(spath);
		m_fname.GetWindowText(fname);
		m_fpath.GetWindowText(fpath);
	}
	spath.Replace("\\","\\\\");
	fpath.Replace("\\","\\\\");
	CString sql;
	sql.Format("update face set SourceImg='%s' , SourcePath='%s' ,FaceName='%s',FacePath='%s' where ID=%s", sname, spath,fname,fpath,id);
	db.ExecuteSQL(sql);
	db.Close();
	CString cmdStr = "Select * from face order by ID";
	m_sname.SetWindowText("");
	m_spath.SetWindowText("");
	m_fname.SetWindowText("");
	m_fpath.SetWindowText("");
	ShowDatabase(cmdStr);
	MessageBox("修改成功");
}
Exemplo n.º 22
0
void ManagerProperty::OnClickedAddPropertyInfo()
{
	CDatabase db;
	db.Open("bankmanagement");
	CString sqlstr,strbankbalance;
	float bankbalance;
	CString timestr;//////获取系统时间
	CTime tm; tm = CTime::GetCurrentTime();
	timestr = tm.Format("%Y-%m-%d");
	
	sqlstr.Format(_T("select sum(money_balance) from card"));
	CRecordset rsss(&db);
	rsss.Open(CRecordset::forwardOnly, (_T("%f"), sqlstr));
	rsss.GetFieldValue(_T("sum(money_balance)"), strbankbalance);
	bankbalance = _ttof(strbankbalance);
	sqlstr.Format(_T("insert into day_property(bank_balance,day_time)values('%f','%s')"), bankbalance,timestr);
	
	db.ExecuteSQL(sqlstr);
	db.Close();
	MessageBox("处理成功!");
	ManagerProperty::OnInitDialog();
	// TODO:  在此添加控件通知处理程序代码
}
Exemplo n.º 23
0
BOOL CFoulerDoc::OpenXLS(CString sFile)
{
	int i;
	double dData;
	CDatabase db;
	CString sSql;
	CString sItem;
	CString sDsn;
	CODBCFieldInfo fieldinfo;
	CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
	if( pFrame->m_strExcelDriver.IsEmpty() ) return FALSE;
	sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",pFrame->m_strExcelDriver,sFile);
	TRY
	{
		db.Open(NULL,FALSE,TRUE,sDsn);// Open the db using the former created pseudo DSN
		CRecordset rs( &db );// Allocate the recordset
		sSql = "SELECT * FROM Data";// Build the SQL string
		rs.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);// Execute that query (implicitly by opening the recordset)
		CFieldSelect dlg(&rs);
		if( dlg.DoModal() == IDCANCEL )
		{
			rs.Close();
			db.Close();
			return FALSE;
		}
		BeginWaitCursor();
		while( !rs.IsEOF() ) rs.MoveNext();
		int iRecCount = (int)(rs.GetRecordCount());
		rs.Close();
		rs.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);

		CProgressBar* pBar = new CProgressBar();
		ClearData();
		InsertData( iRecCount );
		for( i=0 ; i<iRecCount ; i++ )
		{
			rs.GetFieldValue(dlg.m_sField0,sItem);
			dData = atof(sItem)+dlg.m_dCo0;
			if( dlg.m_sField1 >= 0 && dlg.m_dCo1 != 0)
			{
				rs.GetFieldValue(dlg.m_sField1,sItem);
				dData += atof(sItem)*dlg.m_dCo1;
			}
			if( dlg.m_sField2 >= 0 && dlg.m_dCo2 != 0)
			{
				rs.GetFieldValue(dlg.m_sField2,sItem);
				dData += atof(sItem)*dlg.m_dCo2;
			}
			if( dlg.m_sField3 >= 0 && dlg.m_dCo3 != 0)
			{
				rs.GetFieldValue(dlg.m_sField3,sItem);
				dData += atof(sItem)*dlg.m_dCo3;
			}
			
			m_pOrgData[i]->SetItem( dData );
			m_iSubGroupIndex++;
			if( m_iSubGroupIndex >= m_iSubGroupSize )
			{
				m_iSubGroupIndex = 0;
				dData = 0;
				for( int j=i+1-m_iSubGroupSize ; j<i+1 ; j++ )
				{
					dData += m_pOrgData[j]->GetItem();
				}
				m_pData[i/m_iSubGroupSize]->SetItem(dData/m_iSubGroupSize);
			}
			rs.MoveNext();
			pBar->SetPos( (i<<8)/iRecCount );
		}
		delete pBar;
		rs.Close();
		db.Close();
		EndWaitCursor();
		return TRUE;
	}
	CATCH(CDBException, e)
	{
		return FALSE;// A db exception occured. Pop out the details...
	}
	END_CATCH;
}
Exemplo n.º 24
0
//---------------
//---功能:该函数实现对患者就诊信息数据库进行添加修改---
//---完成人:张政桢---
//---完成时间:2012-12-27---
//---修改时间:---
//---------------
BOOL CDlgPatientInfo::ModifyDatabase()
{
	// 因为要更新所以需要保存原先主键值

	UpdateData(TRUE);
	CDatabase db;
	if (!db.Open(_T("患者就诊数据库")))
	{
		MessageBox(_T("连接数据库时错误"), _T("提示"), MB_OK);
		return FALSE;
	}

	CString strSQL;
	// 更新患者信息(先删除后插入,可避免原先表中无数据)
	if (m_flagOperate = 1)	// 如果为修改的话
	{
		strSQL.Format(_T("DELETE FROM 患者信息 WHERE idNumber = '%s'"), m_strOldPId);
		db.ExecuteSQL(strSQL);
	}
	if (m_flagOperate != 3)	// 如果不是添加就诊信息
	{
		strSQL.Format(_T("INSERT INTO 患者信息 VALUES ")
			_T("('%s','%s','%s','%d','%s','%s','%s','%s','%s')"),
			m_strPId, m_strPName, m_strPSex, m_strPAge, m_strPPhone,
			m_strPAddr, m_strPNum, m_strPAllergy, m_strPRemark);
		db.ExecuteSQL(strSQL);
	}
	// 更新就诊信息
	CString strTmp;
	GetDlgItem(IDC_STATIC_TIME)->GetWindowText(strTmp);

	if (1 == m_flagOperate)
	{
		strSQL.Format(_T("DELETE FROM 就诊信息 WHERE diagNum = '%s'"), m_strOldDNum);
		db.ExecuteSQL(strSQL);
		if ("" != m_strOldDNum)
			strTmp = m_strOldDNum;	// 如果是修改的话,不修改时间
	}
	strSQL.Format(_T("INSERT INTO 就诊信息 VALUES ")
		_T("('%s','%s','%s','%s','%s','%s','%s','%s', '%s', '%s')"),
		strTmp, m_strPId, strTmp, m_strDDId, m_strDDeclare, m_strDInitCheck,
		m_strDInstruCheck, m_strDResult, m_strDScheme,m_strDRemark);
	db.ExecuteSQL(strSQL);

	// 更新费用信息(先计算总价格)
	m_floatTotalFee = m_floatFDrug+m_floatFDiag+m_floatFCheck
		+ m_floatFConsum+m_floatFTrans+m_floatFRadiate;
	if (1 == m_flagOperate)
	{
		strSQL.Format(_T("DELETE FROM 费用信息 WHERE diagNum = '%s'"), m_strOldDNum);
		db.ExecuteSQL(strSQL);
	}
	strSQL.Format(_T("INSERT INTO 费用信息 VALUES ")
		_T("('%s','%f','%f','%f','%f','%f','%f','%f')"),
		strTmp, m_floatFDrug, m_floatFDiag, m_floatFTrans,
		m_floatFCheck, m_floatFConsum, m_floatFRadiate, m_floatTotalFee);
	db.ExecuteSQL(strSQL);

	// 更新反馈信息
	if (1 == m_flagOperate)
	{
		strSQL.Format(_T("DELETE FROM 诊后恢复结果信息 WHERE diagNum = '%s'"), m_strOldDNum);
		db.ExecuteSQL(strSQL);
	}
	strSQL.Format(_T("INSERT INTO 诊后恢复结果信息 VALUES ")
		_T("('%s','%s')"), strTmp, m_strFeedBack);
	db.ExecuteSQL(strSQL);

	db.Close();

	m_ifModify = 1;	// 标记为已修改状态

	return TRUE;
}
Exemplo n.º 25
0
void CTrainDlg::OnBnClickedTraining()
{
	// TODO: 在此添加控件通知处理程序代码
	CString exePath = "..\\haartraining\\Debug\\haartraining.exe";

	CString value;

	m_iSplits = 2;
	m_iStages = 4;

	value.Format("-data %s -vec %s -bg %s -npos %d -nneg %d -nsplits %d -nstages %d  -nonsym -mem 512 -w %d -h %d -mode all",
		m_data,m_vec,m_bg,m_iPositiveNum,m_iNegetiveNum,m_iSplits,m_iStages,m_iImgWidth,m_iImgHeight);
	ShellExecute((HWND)AfxGetMainWnd(),"open",exePath,value,NULL,SW_SHOW );
 
	CFileFind filefinder;
 
	CString SourcePath;
	//SourcePath.Format("E:\\训练分类器\\result.xml");
	SourcePath.Format("%s\\result.xml",m_data.Mid(0,m_positive.ReverseFind('\\')));
 
	CString filename;
 
	BOOL bfind = filefinder.FindFile(SourcePath);
 
	CString DisPath;
 
	if (bfind)
 
	{
 
	   bfind = filefinder.FindNextFile();
 
	   //filename = filefinder.GetFileName();
 
	   DisPath = "..\\classifier\\result.xml";
 
	   CopyFile(SourcePath,DisPath,1);

	    CDatabase db;

		 db.Open(NULL, FALSE, FALSE, _T("ODBC;DSN=face;UID=root;PWD=root"));
		 CString name, path, desc,str;
		 name = "result.xml";
		 path = "classifier\\\\result.xml";
		 desc = "训练分类器";

		 if(name == "" || path == "" || desc == "")
		 {
			 MessageBox("所有属性不能为空");
			 db.Close();
			 return;
		 }
	 
		 //判断该目录下分类器是否存在
		 CFileFind finder;
		 if( !finder.FindFile("..\\"+path))
		 {
			 MessageBox("该分类器不存在");
			 db.Close();
			 return;
		 }

		 str.Format("insert into classifier(cname,cpath,cdescribe)  values('%s','%s','%s')", name, path, desc);
		 db.ExecuteSQL(str);
		 db.Close();
		 MessageBox("添加成功");
 
	}
 
	filefinder.Close();

}
Exemplo n.º 26
0
//也是导入
bool CXlsCtrolClass::ImportEx(CString strFile,vector<ExpressStr> &vecStr)
{
	CDatabase database;
	CString sSql;
	CString sItem1, sItem2;
	CString sDriver;
	CString sDsn;
	CString sFile = strFile;             // 将被读取的Excel文件名
	vecStr.clear();
	// 检索是否安装有Excel驱动 "Microsoft Excel Driver (*.xls)" 
	sDriver = GetExcelDriver();
	if (sDriver.IsEmpty())
	{
		return false;
	}
	sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", sDriver, sFile);
	TRY
	{
		// 打开数据库(既Excel文件)
		database.Open(NULL, false, false, sDsn);
		int iSheetCount =1;
		while (true)
		{
			CRecordset adoRst(&database);

			// 设置读取的查询语句.
			sSql = "SELECT * from ";
			sSql.Format("SELECT * from [Sheet%d$]",iSheetCount);
			// 执行查询语句
			try
			{
				adoRst.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);
			}			
			catch (CException* e)
			{
				int ii = 0;
				char strMessage[MAX_PATH];
				e->GetErrorMessage(strMessage, sizeof(strMessage) - 1);
				e->Delete();
				CString strError = CString(strMessage);
				if (strError.Find("不是一个有效名称。请确认它不包含无效的字符或标点") >=0 )
				{
					//所有列已经遍历完
					break;
				}
			}

			if (adoRst.IsEOF())		//已经为空了
			{
				break;
			}
			ExpressStr ExpressInfo;
			BookStr bookStr;
			CString strTemp = "";
			//CString strColumnName = adoRst.GetFieldName(0);
			bool bColumnFlag = false;//是否已经读取了列名
			bool bNewStruInfo = false;
			bool bInfoEnd = false;
			bool bReadBookInfo = false;
			while (!adoRst.IsEOF())
			{
				if (bInfoEnd)
				{
					vecStr.push_back(ExpressInfo);
					bNewStruInfo = false;
					bInfoEnd = false;
					ExpressInfo.vecBookInfo.clear();
					bReadBookInfo = false;
				}
				adoRst.GetFieldValue((short)0,strTemp);
				if (strTemp != "")			//OrderNo
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strOrderNo);
					bNewStruInfo = true;
					adoRst.MoveNext();
					continue;
				}
				strTemp = "";
				adoRst.GetFieldValue((short)1,strTemp);		
				if (strTemp == "")		//One Record End
				{
					bInfoEnd = true;
					adoRst.MoveNext();
					continue;
				}
				else if (strTemp == "ISBN")	//Book Info
				{
					bReadBookInfo = true;
					adoRst.MoveNext();
					continue;
				}
				else if (bReadBookInfo)		// add book info 
				{
					bookStr.strISBN = strTemp;
					adoRst.GetFieldValue((short)2,bookStr.strName);
					adoRst.GetFieldValue((short)3,bookStr.strPress);
					adoRst.GetFieldValue((short)4,bookStr.strPrice);
					adoRst.GetFieldValue((short)5,bookStr.strNum);
					adoRst.GetFieldValue((short)6,bookStr.strSellPrice);
					ExpressInfo.vecBookInfo.push_back(bookStr);
				}
				else if (strTemp == "发货地址")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strAddr);
				}
				else if (strTemp == "联 系 人")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strRecver);
				}
				else if (strTemp == "联系方式")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strPhone);
				}
				else if (strTemp == "备    注")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strMemo);
				}
				else if (strTemp == "付款时间")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strPayTime);
				}
				else if (strTemp == "快递名称")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strExpressCompany);
				}
				else if (strTemp == "快递单号")
				{
					adoRst.GetFieldValue((short)2,ExpressInfo.strExpressNo);
				}
				adoRst.MoveNext();
			}
			if (ExpressInfo.vecBookInfo.size()>0)
			{
				vecStr.push_back(ExpressInfo);
			}
			iSheetCount++;
		}		
		// 关闭数据库
		database.Close();
	}
	CATCH(CDBException, e)
	{
		// 数据库操作产生异常时...
		AfxMessageBox("数据库错误: " + e->m_strError);
	}
Exemplo n.º 27
0
///////////////////////////////////////////////////////////////////////////////
//	void GetExcelDriver(CListCtrl* pList, CString strTitle)
//	參數:
//		pList		需要導出的List控件指针
//		strTitle	導出的數據表標題
//	說明:\
//      導出CListCtrl控件的全部數據到Excel文件。Excel文件名由用戶通過"另存為"
//      對話框輸入指定。創建名為strTitle的工作表,將List控件內的所有數據(包括列
//      名和數據項)以文本的形式保存到Excel工作表中。保持行列關係。
///////////////////////////////////////////////////////////////////////////////
void ExportExcelToList(CListCtrl* pList, CString strTitle)
{
    CString warningStr;
    CDatabase database;
    CString sDriver;
    CString sExcelFile;
    CString sSql;
    CString tableName = strTitle;

    // 檢查是否有安裝Excel驅動 "Microsoft Excel Driver (*.xls)" 
    sDriver = GetExcelDriver();
    if (sDriver.IsEmpty())
    {
        //沒有發現Excel驅動
        AfxMessageBox(L"沒有安装Excel!\n請先安裝Excel軟件才能使用Excel導出功能!!");
        return;
    }

    //默認文件名(獲得文件名)
    if (!LoadGetDefaultXlsFileName(sExcelFile))
        return;

    //創建進行存取的字符串
    sSql.Format(L"ODBC;DRIVER={%s};DSN='''';DBQ=%s",sDriver, sExcelFile);

    // 創建數據庫 (既Excel表格文件)
    if (database.Open(NULL,false,false,sSql)) //開啟資料庫
    {
        pList->DeleteAllItems();
        //創建結構表
        CString sItem;
        CString columnName;
        LVCOLUMN columnData;
        columnData.mask = LVCF_TEXT;
        columnData.cchTextMax = 100;
        columnData.pszText = columnName.GetBuffer(100);
        int ListCount = 0;
        CRecordset recset(&database);
        /*****************修改SQL語法在這**************************/
        sSql = L"";
        for (int j = 0; pList->GetColumn(j, &columnData); j++)
        {
            if (j != 0)
            {
                sSql = sSql + L", ";
            }
            sSql = sSql + columnData.pszText;
        }
        columnName.ReleaseBuffer();
        
        sSql = L"SELECT " + sSql + L" FROM " + tableName;
        AfxMessageBox(sSql);
        recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);
        while (!recset.IsEOF())
        {
            pList->InsertItem(ListCount, NULL);
            for (int i = 0; pList->GetColumn(i, &columnData); i++)
            {
                pList->GetColumn(i, &columnData);
                recset.GetFieldValue(columnData.pszText, sItem);
                LONG Value = _ttol(sItem);
                sItem.Format(L"%d", Value);
                pList->SetItemText(ListCount, i, sItem);
            }
            //next
            ListCount++;
            recset.MoveNext();
        }
    }
    //關閉數據庫
    database.Close();
    warningStr.Format(L"%s檔案導入成功!", sExcelFile);
    AfxMessageBox(warningStr);
}
Exemplo n.º 28
0
BOOL CLDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	 m_hYellowBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);

	 m_hRedBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);


	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	
///////////////////////// initializations ///////////////////////////////////

pt1[0].x=0;
pt1[0].y=0;
pt2[0].x=1;
pt2[0].y=1; 
pt1[1].x=0;
pt1[1].y=3;
pt2[1].x=0;
pt2[1].y=3; 
pt1[2].x=8;
pt1[2].y=7;
pt2[2].x=9;
pt2[2].y=9; 
pt1[3].x=8;
pt1[3].y=5;
pt2[3].x=9;
pt2[3].y=6; 
pt1[4].x=4;
pt1[4].y=4;
pt2[4].x=5;
pt2[4].y=5; 

cmpt[0].x=0;
cmpt[0].y=0;
cmpt[1].x=0;
cmpt[1].y=4;
cmpt[2].x=5;
cmpt[2].y=5;
cmpt[3].x=5;
cmpt[3].y=7;
cmpt[4].x=8;
cmpt[4].y=8;

///////////////////////// initializations ///////////////////////////////////



///////////////////////////////database read from floortab/////////////////////////////////////////////
    CDatabase xx;

	xx.Open("ODBC;DSN=geoinfo");
	CRecordset dbSQL(&xx);
	dbSQL.Open(CRecordset::forwardOnly,"select * from floortab");
	cnt=0;
	while(!dbSQL.IsEOF()) 
	{
	CString xy;
	dbSQL.GetFieldValue("fid",xy);
	flid[cnt]=atoi(xy);
	dbSQL.GetFieldValue("frows",xy);
	flrows[cnt]=atoi(xy);
	dbSQL.GetFieldValue("fclmns",xy);
	flclmns[cnt++]=atoi(xy);
	dbSQL.MoveNext();	
	}

///////////////////////////////database read from floortab//////////////////////////////////////////////

///////////////////////////////database read from labtab//////////////////////////////////////////////
	CRecordset dblab(&xx);
	dblab.Open(CRecordset::forwardOnly,"select * from labtab");
	labcount=0;
	while(!dblab.IsEOF()) 
	{
	CString xy;
	dblab.GetFieldValue("labid",xy);
	labid[labcount]=atoi(xy);

	dblab.GetFieldValue("fid",xy);
	labfl[labcount]=atoi(xy);
	
	dblab.GetFieldValue("labname",xy);
	strcpy(labname[labcount],xy);
	
	dblab.GetFieldValue("labrow1",xy);
	pt1[labcount].x=atoi(xy);
	
	dblab.GetFieldValue("labclmn1",xy);
	pt1[labcount].y=atoi(xy);
	
	dblab.GetFieldValue("labrow2",xy);
	pt2[labcount].x=atoi(xy);
	
	dblab.GetFieldValue("labclmn2",xy);
	pt2[labcount].y=atoi(xy);

	dblab.GetFieldValue("labrows",xy);
	labrows[labcount]=atoi(xy);

	dblab.GetFieldValue("labclmns",xy);
	labclmns[labcount++]=atoi(xy);

	
	dblab.MoveNext();	
	}
	
///////////////////////////////database read from labtab//////////////////////////////////////////////
	
///////////////////////////////database read from labtab//////////////////////////////////////////////
	CRecordset dbcmp(&xx);
	dbcmp.Open(CRecordset::forwardOnly,"select * from comptab");
	cmcount=0;
	while(!dbcmp.IsEOF()) 
	{
	CString xy;
	dbcmp.GetFieldValue("cmid",xy);
	cmid[cmcount]=atoi(xy);
	dbcmp.GetFieldValue("labid",xy);
	cmlabid[cmcount]=atoi(xy);
	dbcmp.GetFieldValue("ptx",xy);
	cmpt[cmcount].x =atoi(xy);
	dbcmp.GetFieldValue("pty",xy);
	cmpt[cmcount].y =atoi(xy);

	dbcmp.GetFieldValue("cmip1",xy);
	cmip[cmcount][0] =atoi(xy);

	dbcmp.GetFieldValue("cmip2",xy);
	cmip[cmcount][1] =atoi(xy);

	dbcmp.GetFieldValue("cmip3",xy);
	cmip[cmcount][2] =atoi(xy);

	dbcmp.GetFieldValue("cmip4",xy);
	cmip[cmcount][3] =atoi(xy);

	cmcount++;
	dbcmp.MoveNext();	
	}
	
	
///////////////////////////////database read from labtab//////////////////////////////////////////////
return TRUE;  // return TRUE  unless you set the focus to a control
}
Exemplo n.º 29
0
BOOL CSourceODBC::PrepareOpen()
{
    CDatabase db;
    try
    {
        //if ( !db.Open(GetDefaultConnect()) )
        if (!db.Open(L"ToolDB"))
        {
            AfxMessageBox( _T("Не удалось соедениться с базой данных.") );
            return FALSE;
        }
    }
    catch ( CDBException *pException)
    {
        CString msg = _T("Не удалось соедениться с базой данных.\n") + pException->m_strError;
        AfxMessageBox( msg );
        pException->Delete();    // Удаляем структуру из памяти!
        return FALSE;
    }

    CRecordset rs(&db);
    try
    {
        if ( !rs.Open(CRecordset::dynaset, CString( _T("SELECT * FROM ") ) + GetDefaultSQL()) ) // читаем всю таблицу из БД в РН
        {
            AfxMessageBox( _T("Не удалось прочесть базу данных.") );
            rs.Close();
            db.Close();
            return FALSE;
        }
    }
    catch ( CDBException *pException )
    {
        CString msg = _T("Не удалось прочесть базу данных.\n") + pException->m_strError;
        AfxMessageBox( msg );
        pException->Delete();    // Удаляем структуру из памяти!
        return FALSE;
    }

    short nFields = rs.GetODBCFieldCount();			// число полей в записи РН

    for ( short index = 0; index < nFields; index++ ) // цикл по всем полям записи рабочего набора
    {

        SDBField *field = new SDBField;						// создаём новый описатель поля
        CODBCFieldInfo info;											// структура с информацией о полях в источнике ODBC
        rs.GetODBCFieldInfo( index, info );				// заполнить структуру с информацией о поле

        field->FieldName = CString( _T("[") ) + info.m_strName + CString( _T("]") );
        field->FieldCaption = info.m_strName;

        switch (info.m_nSQLType)
        {
        case SQL_INTEGER:
            field->ID_TYPE = LONG;
            break;

        case SQL_DOUBLE:
            field->ID_TYPE = DOUBLE;
            break;

        case -9: /// String
            field->ID_TYPE = STRING;
            break;

        case -10: /// Memo
            field->ID_TYPE = STRING;
            break;

        case -4:  /// Ole
            field->ID_TYPE = BLOB;
            break;

        case 11:
            field->ID_TYPE = TIME;
            break;
        } // end switch

        m_database.m_fields.Add(field); // добавить заполненный описатель в массив
    } // end for

    rs.Close();
    db.Close();
    return TRUE;
}
Exemplo n.º 30
0
void CXls2LuaMgr::ReadFromExcel() 
{
	CDatabase database;
	string sSql;
	string sItem1, sItem2;
	string sDriver;
	string sDsn;
	string sFile = "npc.xls"; // 将被读取的Excel文件名
	char buf[2048];
	TCHAR tBuf[1024];

	// 检索是否安装有Excel驱动 "Microsoft Excel Driver (*.xls)" 
	sDriver = GetExcelDriver();
	if (sDriver.size() <= 0)
	{
		// 没有发现Excel驱动
		//MessageBox(NULL,"提示","发现Exel驱动",MB_OK);
		return;
	}

	// 创建进行存取的字符串
	sprintf(buf,"ODBC;DRIVER={%s};DSN='';DBQ=%s", sDriver.c_str(), sFile.c_str());
	
	
	MultiByteToWideChar(CP_ACP,0,buf,strlen(buf),tBuf,strlen(buf) + 1);
	
	TRY
	{
		// 打开数据库(既Excel文件)
		database.Open(NULL, false, false, tBuf);

		CRecordset recset(&database);

		// 设置读取的查询语句.
		//sSql = "SELECT Name, Age " 
		//	"FROM demo " 
		//	"ORDER BY Name ";

		// 执行查询语句
		//recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);

		// 获取查询结果
		int nRecord = recset.GetRecordCount();
		for (int i = 0; i < nRecord; i++)
		{
			//CString strTemp;
			//recset.GetFieldValue(i,strTemp);
			//printf("%s ",strTemp.GetString());
		}
		//while (!recset.IsEOF())
		//{
		//	//读取Excel内部数值
		//	recset.GetFieldValue("Name ", sItem1);
		//	recset.GetFieldValue("Age", sItem2);

		//	// 移到下一行
		//	recset.MoveNext();
		//}

		// 关闭数据库
		database.Close();

	}
	CATCH(CDBException, e)
	{
		// 数据库操作产生异常时...
		//MessageBox(NULL,"提示","提示",MB_OK);
	}
	END_CATCH;
}