private void btnCalc_Click(object sender, EventArgs e) { int allowedError = (int)nudAllowedError.Value; int target = 0; try { target = int.Parse(comboxTargetValue.Text.Trim()); } catch { MessageBox.Show("输入的目标经验值必须是大于零的整数!", "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Wreckage[] wreckages = GetSelectedWreckages(); if (wreckages.Length == 0) { MessageBox.Show("你必须选择至少一种残骸!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List <WreckageResult> results = WreckageCalculator.DoCalc(wreckages, target, allowedError); mLastResult = results; mLastSelectedWreckages = wreckages; mLastTarget = target; mLastAllowedError = allowedError; UpdateResultView(); }
private void UpdateResultView() { if (mLastResult == null) { return; } listViewResult.Items.Clear(); if (mLastResult.Count == 0) { MessageBox.Show("未能找到合适的残骸组合,你可以将\"允许的最大多余经验\"调大后再重新计算。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (radioBtnOrderDelta.Checked) { WreckageCalculator.Sort(mLastResult, ResultOrder.Delta); } else if (readioBtnBodyPoint.Checked) { WreckageCalculator.Sort(mLastResult, ResultOrder.BodyPoint); } else { WreckageCalculator.Sort(mLastResult, ResultOrder.TotalNum); } foreach (WreckageResult result in mLastResult) { AddResultRow(result, mLastSelectedWreckages, mLastTarget); } }
private void AddResultRow(WreckageResult result, Wreckage[] wreckages, int target) { ListViewItem lvi = new ListViewItem(); lvi.SubItems[0].Text = (listViewResult.Items.Count + 1).ToString(); lvi.SubItems.Add((result.Value - target).ToString()); lvi.SubItems.Add(result.GetTotalNumOfWreckage().ToString()); lvi.SubItems.Add(result.EstimateBodyPoint.ToString()); lvi.SubItems.Add(WreckageCalculator.GetResultString(result, wreckages, target)); listViewResult.Items.Add(lvi); }