Example #1
0
ModList::OrderList ModList::readListFile()
{
	OrderList itemList;
	if (m_list_file.isNull() || m_list_file.isEmpty())
		return itemList;

	QFile textFile(m_list_file);
	if (!textFile.open(QIODevice::ReadOnly | QIODevice::Text))
		return OrderList();

	QTextStream textStream;
	textStream.setAutoDetectUnicode(true);
	textStream.setDevice(&textFile);
	while (true)
	{
		QString line = textStream.readLine();
		if (line.isNull() || line.isEmpty())
			break;
		else
		{
			OrderItem it;
			it.enabled = !line.endsWith(".disabled");
			if (!it.enabled)
			{
				line.chop(9);
			}
			it.id = line;
			itemList.append(it);
		}
	}
	textFile.close();
	return itemList;
}
//点菜完成,点击确定按钮将数据存储到数据库中,
void OrderDish::OnButtonOrderdishok()
{
	// TODO:  在此添加命令处理程序代码
	//MessageBox(_T("确定"));
	UpdateData();
	CString sqlCommand;
	int countNumbers = m_recipeOrderedList.GetItemCount();
	if (countNumbers == 0)
	{
		AfxMessageBox(_T("请点菜"));
		return;
	}
	sqlCommand = "update tableUse set tableState='使用' where tableID=";
	sqlCommand += m_tableNumber;
	theApp.m_PConn->Execute((_bstr_t)sqlCommand, NULL, adCmdText);


	CString OrderList(""), dishName(""), dishNumbers(""),unitCost,totalCost;
	//将此单点菜信息添加到数据库表
#pragma region
	for (size_t i = 0; i < countNumbers; i++)
	{
		dishName = m_recipeOrderedList.GetItemText(i,0);  //菜名
		dishNumbers = m_recipeOrderedList.GetItemText(i,1); //数量
		sqlCommand = "select * from caishInfo where 菜名='";
		sqlCommand += dishName;
		sqlCommand += "'";

		m_pRs = theApp.m_PConn->Execute((_bstr_t)sqlCommand,NULL,adCmdText);
		unitCost= m_pRs->GetCollect("菜价");
		
		char * puc = (char *)unitCost.GetBuffer(unitCost.GetLength());
		totalCost =(char *)(_bstr_t)( _ttof(unitCost)*_ttof(dishNumbers));
		//totalCost = (char*)(_bstr_t)(atof(puc)*atof((char *)dishNumbers.GetBuffer(dishNumbers.GetLength())));
		//%%%%%%%%%%%此处编写sql语句应当注意中英文符号的切换
		sqlCommand = "insert into paybill(桌号,菜名,数量,消费) values('";
		sqlCommand += m_tableNumber;
		sqlCommand += "','";
		sqlCommand += dishName; sqlCommand += "','";
		sqlCommand += dishNumbers; sqlCommand += "','";
		sqlCommand += totalCost; sqlCommand += "')";
		//sqlCommand = "insert into paybill(桌号,菜名,数量,消费) values('6601','金银豆腐',1,30)";
		theApp.m_PConn->Execute((_bstr_t)sqlCommand,NULL,adCmdText);
	}

	
#pragma endregion
	MessageBox(_T("此订单已被系统接收,请稍后~"));
	CDialog::OnOK();
}