private void btnQuery_Click(object sender, EventArgs e) { try { int accountYear = Convert.ToInt32(this.cobAccountYear.Text); int accountMonth = Convert.ToInt32(this.cobAccountMonth.Text); decimal balanceFee = 0; orderDt = _accountQuery.QueryOrderAccount(accountYear, accountMonth, _makerDicId, _deptId); if (orderDt.Rows.Count < 1) { MessageBox.Show("该药品在查询时间段内没有明细单据"); return; } dgrdOrderAccount.DataSource = orderDt; int lastIndex = orderDt.Rows.Count - 1; lblBeginNum.Text = orderDt.Rows[0]["OVERNUM"].ToString(); balanceFee = Convert.ToDecimal(orderDt.Rows[0]["BALANCEFEE"]); lblBeginFee.Text = "¥" + balanceFee.ToString("0.00"); int overNum = 0; if (orderDt.Rows[lastIndex]["AccountType"].ToString() == "月结") { overNum = Convert.ToInt32(orderDt.Rows[lastIndex]["Overnum"]); balanceFee = Convert.ToInt32(orderDt.Rows[lastIndex]["BalanceFee"]); } else { overNum = Convert.ToInt32(orderDt.Rows[0]["OVERNUM"]); balanceFee = Convert.ToDecimal(orderDt.Rows[0]["BALANCEFEE"]); for (int index = 1; index <= lastIndex; index++) { overNum += Convert.ToInt32(orderDt.Rows[index]["Lendernum"]); balanceFee += Convert.ToDecimal(orderDt.Rows[index]["LenderFee"]); overNum -= Convert.ToInt32(orderDt.Rows[index]["DebitNum"]); balanceFee -= Convert.ToDecimal(orderDt.Rows[index]["DebitFee"]); } } lblEndNum.Text = overNum.ToString(); lblEndFee.Text = "¥" + balanceFee.ToString("0.00"); } catch (Exception error) { MessageBox.Show(error.Message); } }