所以我想要做的是使用 C# 将累积数据放在 ListView 对象上,然后获取销售报告的销售记录。如您所见,它非常不稳定,我的代码就是,我主要想删除必须调用两个 MySqlCommands 和 DataReaders。任何建议将不胜感激!
string query = "SELECT * FROM orderlist ol "+
"INNER JOIN orderdb o "+
"ON ol.order_ID = o.order_ID "+
"INNER JOIN menudb m "+
"ON ol.menu_ID = m.menu_ID "+
"WHERE o.order_date >= '"+fromdate.Date()+"' AND "+
"o.order_date <= '"+todate.Date()+"'";
command = new MySqlCommand(query, connection);
dr = command.ExecuteReader();
string[] info = new string[15];
while(dr.Read())
{
string query2 = "SELECT r.*, s.stock_pricePerPiece FROM recipelist r "+
"INNER JOIN stocksdb s ON r.stock_ID = s.stock_ID "+
"WHERE r.menu_ID = '"+(dr["menu_ID"].ToString())+"'";
MySqlCommand cmd2 = new MySqlCommand(query2, connection2);
MySqlDataReader dr2 = cmd2.ExecuteReader();
double menu_cost = 0;
while(dr2.Read())
{
menu_cost += Convert.ToDouble(dr2["stock_pricePerPiece"].ToString());
}
info[1] = (dr["order_ID"].ToString());
info[2] = (dr["order_date"].ToString());
info[3] = (dr["menu_name"].ToString());
info[4] = (menu_cost.ToString("#0.00"));
info[5] = (dr["menu_price"].ToString());
info[6] = (Convert.ToDouble(info[5]) - menu_cost).ToString("#0.00");
this.ReportList.Items.Add(new ListViewItem(new string[] { info[1] , info[2] , info[3] , info[4] , info[5] , info[6] }));
}