Example #1
0
        internal void FillInRawData(string tofile)
        {
            bool   docopen = false;
            string tmpl    = "原始记录单";

            try
            {
                string src = Path.Combine(Util.basedir, "报告模板\\" + tmpl + ".doc");
                File.Copy(src, tofile, true);
                doctool.PrepareWord(tofile);
                docopen = true;

                doctool.FillInField(tofile, data_record.Properties());

                doctool.FillInHeader(tofile, data_record.Properties(), Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader);
                doctool.FillInHeader(tofile, data_record.Properties(), Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader);

                doctool.SaveWord(tofile);
                MessageBox.Show("导出" + tmpl + "成功");
                docopen = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("导出报告失败: " + ex.Message);
                if (docopen)
                {
                    doctool.SaveWord(tofile);
                }
                docopen = false;
            }
        }
Example #2
0
        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;
            }
        }