internal void FillInDocument(REPORT_TYPE rule, string tofile) { bool docopen = false; try { Input askdlg = new Input(); askdlg.Message = "请输入被测控温仪的样品编号"; if (askdlg.ShowDialog() != DialogResult.OK) { return; } string ibcid = ""; string ypbh = askdlg.result; List <string> rows = new List <string>(); //search the corresponding page id and ibc ids for (int ibc = 1; ibc <= 4; ibc++) { if (!IsValueAvailable(new string[] { "m_" + (ibc + 1).ToString() + "_ypbh" })) { continue; } if (StrValue("m_" + (ibc + 1).ToString() + "_ypbh") == ypbh) { ibcid = ibc.ToString(); break; } } if (ibcid == "") { MessageBox.Show("未找到样品编号为" + ypbh + "的控温仪,请检查后再试"); return; } for (int iwd = 1; iwd <= 5; iwd++) { string wdkey = "m_" + ibcid + "_" + iwd.ToString() + "wdd"; string bckey = "c_" + ibcid + "_" + iwd.ToString() + "bc"; if (!IsValueAvailable(new string[] { wdkey, bckey })) { continue; } string wdd = StrValue(wdkey).Trim(); if (wdd == "") { continue; } //search for qiehua string qid = ""; string qhprefix = ""; string cqhprefix = ""; for (int iqhwd = 1; iqhwd <= 3; iqhwd++) { qhprefix = "m_" + ibcid + "_" + iqhwd.ToString(); cqhprefix = "c_" + ibcid + "_" + iqhwd.ToString(); string key = qhprefix + "qhwd"; if (IsValueAvailable(new string[] { key }) && StrValue(key) == wdd) { qid = iqhwd.ToString(); break; } } if (qid == "") { rows.Add(String.Format("{0}\t{1}\t/\t/\t/\t/", FormatValue(data_record.Property(wdkey), false), FormatValue(data_record.Property(bckey), false))); } else { rows.Add(String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", FormatValue(data_record.Property(wdkey), false), FormatValue(data_record.Property(bckey), false), FormatValue(data_record.Property(cqhprefix + "sqh"), false), FormatValue(data_record.Property(cqhprefix + "xqh"), false), FormatValue(data_record.Property(cqhprefix + "qhc"), false), FormatValue(data_record.Property(cqhprefix + "qhwc"), false))); } } string tmpl = ""; if (rule == REPORT_TYPE.CALI_REPORT) { tmpl = "检测报告"; } string src = Path.Combine(Util.basedir, "报告模板\\" + tmpl + ".doc"); File.Copy(src, tofile, true); doctool.PrepareWord(tofile); docopen = true; doctool.FillInField(tofile, data_record.Properties(), ibcid); doctool.FillInTableByBookMarks("ITEMS", rows); doctool.FillInHeader(tofile, data_record.Properties(), ibcid, Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader); doctool.FillInHeader(tofile, data_record.Properties(), ibcid, Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader); doctool.SaveWord(tofile); MessageBox.Show("导出" + tmpl + "成功"); docopen = false; return; } catch (Exception ex) { MessageBox.Show("导出报告失败: " + ex.Message); if (docopen) { doctool.SaveWord(tofile); } docopen = false; } }
internal void FillInFendu(SaveFileDialog saveFileDialog1) { bool docopen = false; Input askdlg = new Input(); decimal t_start; decimal t_end; Dictionary <Decimal, Decimal> points = new Dictionary <Decimal, Decimal>(); /*points[-55] = 78.2953M; * points[-40] = 84.2496M; * points[-20] = 92.1416M; * points[0] = 99.9841M; * points[50] = 119.4089M; * points[100] = 138.5204M; * points[125] = 147.9672M; */ #region input askdlg.Message = "请输入铂电阻的出厂编号"; if (askdlg.ShowDialog() != DialogResult.OK) { return; } string ccbh = askdlg.result; string ibcid = ""; string pageid = ""; //search the corresponding page id and ibc ids for (int ibc = 0; ibc < 12; ibc++) { pageid = "abcdef"[ibc / 4].ToString(); if (!IsValueAvailable(new string[] { "m_" + (ibc + 1).ToString() + "_ccbh" })) { continue; } if (StrValue("m_" + (ibc + 1).ToString() + "_ccbh") == ccbh) { ibcid = (ibc + 1).ToString(); for (int iwd = 1; iwd <= 3; iwd++) { if (!IsValueAvailable(new string[] { "m_" + pageid + "_" + iwd.ToString() + "jddwd", "c_" + (ibc + 1).ToString() + "_" + iwd.ToString() + "bc" })) { continue; } string wdd = StrValue("m_" + pageid + "_" + iwd.ToString() + "jddwd").Trim(); if (wdd == "") { continue; } string sjz = FormatValue(data_record.Property("c_" + (ibc + 1).ToString() + "_" + iwd.ToString() + "sjzbc"), false); points[Decimal.Parse(wdd)] = Decimal.Parse(sjz); } } } if (points.Count <= 0) { MessageBox.Show("未找到出厂编号为" + ccbh + "的铂电阻,请检查后再试"); return; } #endregion double r0 = 999; if (points.ContainsKey(0)) { r0 = Convert.ToDouble(points[0]); } else { MessageBox.Show("未发现0℃温度点实际值,无法计算分度表"); return; } double[][] mn = new double[3][]; double[] yn = new double[3]; decimal ptn1, ptn2, ptn3; ptn1 = 1000; ptn2 = 0; ptn3 = -1000; mn[0] = new double[3]; mn[1] = new double[3]; mn[2] = new double[3]; decimal ptp1, ptp2; ptp1 = 1000; ptp2 = -1000; double[][] mp = new double[2][]; mp[0] = new double[2]; mp[1] = new double[2]; double[] yp = new double[2]; //count points for range int np = 0; int nn = 0; foreach (Decimal d in points.Keys) { double dv; if ((d < 0) && (d >= -200)) { if (d < ptn1) { ptn2 = ptn1; ptn1 = d; } if (d > ptn3) { ptn2 = ptn3; ptn3 = d; } if (points.ContainsKey(ptn1)) { dv = Convert.ToDouble(ptn1); mn[0][0] = dv; mn[0][1] = dv * dv; mn[0][2] = (dv - 100) * dv * dv * dv; yn[0] = Convert.ToDouble(points[ptn1]) / r0 - 1; } if (points.ContainsKey(ptn2)) { dv = Convert.ToDouble(ptn2); mn[1][0] = dv; mn[1][1] = dv * dv; mn[1][2] = (dv - 100) * dv * dv * dv; yn[1] = Convert.ToDouble(points[ptn2]) / r0 - 1; } if (points.ContainsKey(ptn3)) { dv = Convert.ToDouble(ptn3); mn[2][0] = dv; mn[2][1] = dv * dv; mn[2][2] = (dv - 100) * dv * dv * dv; yn[2] = Convert.ToDouble(points[ptn3]) / r0 - 1; } nn++; } if ((d > 0) && (d <= 850)) { if (d < ptp1) { ptp1 = d; dv = Convert.ToDouble(ptp1); mp[0][0] = dv; mp[0][1] = dv * dv; yp[0] = Convert.ToDouble(points[ptp1]) / r0 - 1; } if (d > ptp2) { ptp2 = d; dv = Convert.ToDouble(ptp2); mp[1][0] = dv; mp[1][1] = dv * dv; yp[1] = Convert.ToDouble(points[ptp2]) / r0 - 1; } np++; } } if (ptn1 > 0) { ptn1 = 0; } if (ptp2 < 0) { ptp2 = 0; } askdlg.Message = "请输入分度表起始温度"; if (askdlg.ShowDialog() != DialogResult.OK) { return; } if (!Decimal.TryParse(askdlg.result, out t_start) || (t_start < ptn1)) { MessageBox.Show("无效的起始温度,分度表不能外插"); return; } askdlg.Message = "请输入分度表结束温度"; if (askdlg.ShowDialog() != DialogResult.OK) { return; } if (!Decimal.TryParse(askdlg.result, out t_end) || (t_end > ptp2)) { MessageBox.Show("无效的结束温度,分度表不能外插"); return; } Decimal s = t_start; Decimal e = t_end; if ((s < 0) && (nn < 3)) { MessageBox.Show("检定点不足。-200℃ ~ 0 ℃的分度表计算至少有需要3个检定点."); return; } if ((e > 0) && (np < 2)) { MessageBox.Show("检定点不足。0℃ ~ 850 ℃的分度表计算至少有需要2个检定点."); return; } double[] xn = new double[3]; //A,B,C double[] xp = new double[2]; //A,B GeneralMatrix gxn; GeneralMatrix gxp; if (nn >= 3) { GeneralMatrix gm = new GeneralMatrix(mn); gxn = gm.Solve(new GeneralMatrix(yn, yn.Length)); xn[0] = gxn.GetElement(0, 0); xn[1] = gxn.GetElement(1, 0); xn[2] = gxn.GetElement(2, 0); } if (np >= 2) { GeneralMatrix gm = new GeneralMatrix(mp); gxp = gm.Solve(new GeneralMatrix(yp, yp.Length)); xp[0] = gxp.GetElement(0, 0); xp[1] = gxp.GetElement(1, 0); } List <string> rows = new List <string>(); while (s <= e) { double sv = Convert.ToDouble(s); if (s < 0) { rows.Add(String.Format("{0}\t{1:F4}", s.ToString(), r0 * (1 + xn[0] * sv + xn[1] * sv * sv + xn[2] * (sv - 100) * sv * sv * sv))); } else { rows.Add(String.Format("{0}\t{1:F4}", s.ToString(), r0 * (1 + xp[0] * sv + xp[1] * sv * sv))); } s = s + 1; } saveFileDialog1.DefaultExt = ".doc"; saveFileDialog1.Filter = "DOC File(*.doc)|*.doc|All Files(*.*)|*.*"; saveFileDialog1.FileName = DateTime.Now.ToString("yyyy-MM-dd") + "分度表证书.doc"; if (saveFileDialog1.ShowDialog() != DialogResult.OK) { return; } string tofile = saveFileDialog1.FileName; try { string tmpl = "分度表"; string src = Path.Combine(Util.basedir, "报告模板\\" + tmpl + ".doc"); File.Copy(src, tofile, true); doctool.PrepareWord(tofile); docopen = true; doctool.FillInTableByBookMarks("ITEMS", rows); doctool.FillInHeader(tofile, data_record.Properties(), ibcid, Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader); doctool.FillInHeader(tofile, data_record.Properties(), ibcid, Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader); doctool.SaveWord(tofile); MessageBox.Show("导出" + tmpl + "成功"); docopen = false; return; } catch (Exception ex) { MessageBox.Show("导出报告失败: " + ex.Message); if (docopen) { doctool.SaveWord(tofile); } docopen = false; } }