private void btnCalculate_Click(object sender, EventArgs e) { try { double weight, w1, w2, thereticaldensity; //当所有的textbox都转换成功的时候,才可以进行计算 CommonOperate.ConvertStringToDouble(txtWeight, out weight); CommonOperate.ConvertStringToDouble(txtW1, out w1); CommonOperate.ConvertStringToDouble(txtW2, out w2); CommonOperate.ConvertStringToDouble(txtTheoreticalDensity, out thereticaldensity); CalculateTargetDensity tdc = new CalculateTargetDensity(); tdc.CalculateArchimedeTargetDensity(weight, w1, w2, thereticaldensity); txtRealDensity.Text = tdc.RealDensity.ToString("N3"); txtRelativeDensity.Text = (tdc.RelativeDensity * 100).ToString("N2"); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCalculate_Click(object sender, EventArgs e) { try { double weight, diameter, h1, h2, h3, h4, h,paperWeight, paperThickness, theoreticalDensity; CommonOperate.ConvertStringToDouble(txtWeight, out weight); CommonOperate.ConvertStringToDouble(txtDiameter, out diameter); CommonOperate.ConvertStringToDouble(txtThickness1, out h1); CommonOperate.ConvertStringToDouble(txtThickness2, out h2); CommonOperate.ConvertStringToDouble(txtThickness3, out h3); CommonOperate.ConvertStringToDouble(txtThickness4, out h4); CommonOperate.ConvertStringToDouble(txtTheoreticalDensity, out theoreticalDensity); h= (h1 + h2 + h3 + h4) / 4; this.txtThickness.Text = h.ToString("N2"); //如果需要减去石墨纸的重量和厚度 if (chkIncludeCarbonPaper.Checked == true) { CommonOperate.ConvertStringToDouble(txtPaperThickness, out paperThickness); CommonOperate.ConvertStringToDouble(txtPapterWeight, out paperWeight); h = h - paperThickness; this.txtMovePaperThickness.Text = h.ToString("N2"); weight = weight - paperWeight; this.txtMovePaperWeight.Text = weight.ToString("N2"); } CalculateTargetDensity tdc = new CalculateTargetDensity(); tdc.CalculateCirlcleTargetDensity(weight, diameter, h, theoreticalDensity); txtRealDensity.Text = tdc.RealDensity.ToString("N3"); txtRelativeDensity.Text = (tdc.RelativeDensity * 100).ToString("N2"); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }