Пример #1
0
        public Form1()
        {
            if (!File.Exists("C:\\blank.htm"))
            {
                File.WriteAllText("C:\\blank.htm", "<html><head>blank></head><body></body></html>");
            }
            InitializeComponent();
            zedallprobes.GraphPane.Title.Text = "各探头阻值()";
            zedallprobes.IsShowPointValues = true;
            btn_start.Enabled = true;
            saveFileDialog1.AddExtension = true;
            saveFileDialog1.CheckPathExists = true;
            saveFileDialog1.OverwritePrompt = true;
            saveFileDialog1.ValidateNames = true;
            saveFileDialog1.DefaultExt = ".rec";
            saveFileDialog1.Filter = "Record File(*.rec)|*.rec|All Files(*.*)|*.*";
            saveFileDialog1.FileName = "";

            openFileDialog1.CheckFileExists = true;
            openFileDialog1.Multiselect = false;
            openFileDialog1.ValidateNames = true;
            openFileDialog1.Filter = "Record File(*.rec)|*.rec|All Files(*.*)|*.*";
            openFileDialog1.DefaultExt = ".rec";
            openFileDialog1.FileName = "";

            cb_probetype.SelectedIndex = 0;
            cb_probetype.SelectedValueChanged += new EventHandler(cb_temprange_SelectedValueChanged);

            
            this.webBrowser1.IsWebBrowserContextMenuEnabled = false;
            this.webBrowser1.AllowWebBrowserDrop = false;
            //this.webBrowser1.ScrollBarsEnabled = false;
            this.webBrowser1.WebBrowserShortcutsEnabled = false;
            try
            {
                this.webBrowser1.ObjectForScripting = this;
                
            }
            catch
            {
            }
            this.Text = this.Text + "(" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ")";
            LoadDefaultRecordPage();

            test = new TestDocument();
            process = new TestProcess(this);
            input_dlg = new Input();
            
            msg_dlg = new MsgDlg();
            NewToolStripMenuItem_Click(null, null);
            this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker1.WorkerSupportsCancellation = true;
            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
        }
Пример #2
0
        public void StartProcess(BackgroundWorker formworker)
        {
            worker = formworker;

            FormAction("show_status", "测试进行中...");

            List<TEMPRDG> trdgs = new List<TEMPRDG>();

            for(int ipoint = 1; ipoint <= TestDocument.MAX_PT_1PAGE;ipoint++) //check every ipoint
            {
                string pkey = "m_1_" + ipoint.ToString(); //all pages should have same setpoint
                Decimal setpoint;
                if(!testdoc.IsValueAvailable(new string[]{pkey + "wdd"}))
                    continue;
                if (!Decimal.TryParse(testdoc.StrValue(pkey + "wdd"), out setpoint))
                    continue;

                SetTemperature(setpoint);
                FormAction("clear_graph","");
                CheckCancel(2);
                trdgs.Clear();
#region wait temp stable
                double tempnow;
                double period = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PERIOD"));
                double pplimit = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PPLIMIT"));

                while (true)
                {
                    DateTime st = DateTime.Now;
                    while (!wd1529.HasReading(1))
                    {
                        FormAction("show_status", "读取标准温度计温度....");
                        CheckCancel(1);
                        if(DateTime.Now.Subtract(st).TotalSeconds > 10)
                        {
                            MessageBox.Show("读取标准温度计读数失败,请检查FLUKE 1529 连接和设置.(PRINT ON, 波特率9600).");
                            st = DateTime.Now;
                        }
                    }
                    
                        TEMPRDG rdg = wd1529.GetTemperature(1);
                        tempnow = Convert.ToDouble(rdg.reading);
                        //convert to temperature
                        trdgs.Add(new TEMPRDG(rdg.reading, DateTime.Now));
                        FormGraphAction(0, tempnow, "c");
                        FormAction("show_status", String.Format("等待温度稳定....{0} ℃", tempnow.ToString("F03")));

                          while ((trdgs.Count > 0) && trdgs[0].time < DateTime.Now.AddMinutes(-period)) 
                            trdgs.RemoveAt(0);
                        
                        
                        if ((trdgs.Count > 10) && 
                            (trdgs[trdgs.Count - 1].time.Subtract(trdgs[0].time).TotalMinutes > (period-0.1))&&
                            ((Util.my_max(trdgs, 0) - Util.my_min(trdgs, 0)) < pplimit) && 
                            IsDiffSmall(trdgs[trdgs.Count - 1].reading, setpoint, 2))
                        {
                            break;
                        }
                    
                    CheckCancel(1);
                }
                #endregion
                FormAction("clear_graph","");
#region start to collect const temp data
                Decimal rnow = 0;
                for (int round = 1; round <= 4; round++)
                {
                    while (!wd1529.HasReading(1))
                    {
                        CheckCancel(1);
                    }
                    Decimal stdnow = wd1529.GetTemperature(1).reading;
                    FormGraphAction(0, Convert.ToDouble(stdnow), "c");
                    for (int sch = 1; sch < TestDocument.MAX_BC; sch++)
                    {
                        if (!testdoc.IsValueAvailable(new string[] { "m_" + sch.ToString() + "_fdz"}))
                            continue;
                        this["c_" + sch.ToString() + "_" + ipoint.ToString() + "wd_" + round.ToString()] = stdnow;
                        int retry = 0;
                        Input askdlg = new Input();
                askdlg.Message = String.Format("请输入控温仪{0} 示值数据...", sch);

                        while (true)
                        {
                            if (askdlg.ShowDialog() == DialogResult.OK)
                            {
                                if (Decimal.TryParse(askdlg.result, out rnow))
                                    break;
                            }

                            if(retry++ > 3)
                                throw new Exception("测试被中止.");
                        }
                        this["c_" + sch.ToString() + "_" + ipoint.ToString() + "bc_" + round.ToString()] = rnow;
                        FormGraphAction(sch, Convert.ToDouble(rnow),"ohm");
                    }
                }
#endregion
                testdoc.AutoCaculation();
            }
            FormAction("clear_graph", "");
            //start qie huan data test
            for (int ipoint = 1; ipoint <= TestDocument.MAX_PT_1PAGE; ipoint++) //check every ipoint
            {
                string pkey = "m_1_" + ipoint.ToString(); //all pages should have same setpoint
                Decimal setpoint;
                if (!testdoc.IsValueAvailable(new string[] { pkey + "qhwd" }))
                    continue;
                if (!Decimal.TryParse(testdoc.StrValue(pkey + "qhwd"), out setpoint))
                    continue;

                SetTemperature(setpoint);
                #region wait temp stable
                double tempnow;
                double period = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PERIOD"));
                double pplimit = Double.Parse(Util.ConstIni.StringValue("CONDITION", "PPLIMIT"));
                while (true)
                {
                    while (!wd1529.HasReading(1))
                    {
                        CheckCancel(1);
                    }

                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    tempnow = Convert.ToDouble(rdg.reading);
                    //convert to temperature
                    trdgs.Add(new TEMPRDG(rdg.reading, DateTime.Now));
                    FormGraphAction(0, tempnow,"c");
                    FormAction("show_status", String.Format("准备测量切换温度,等待温度稳定....{0} ℃", tempnow.ToString("F03")));

                    while ((trdgs.Count > 0) && trdgs[0].time < DateTime.Now.AddMinutes(-period))
                        trdgs.RemoveAt(0);
                    if ((trdgs.Count > 10) && (trdgs[trdgs.Count - 1].time.Subtract(trdgs[0].time).TotalMinutes > (period-0.1)) && 
                        (Util.my_max(trdgs, 0) - Util.my_min(trdgs, 0)) < pplimit && 
                        IsDiffSmall(trdgs[trdgs.Count - 1].reading, setpoint, 2)) //sojo
                    {
                        break;
                    }
                    CheckCancel(1);
                }
                #endregion

                string lastio = GetCurrentIO();
                FormAction("clear_graph", "");
                #region collect up switch temperature
                
                decimal uprange =  Decimal.Parse(Util.ConstIni.StringValue("CONDITION", "UPRANGE"));
                SetTemperature(setpoint + uprange);
                FormAction("show_status", String.Format("上切换值测量中...."));
                while (true)
                {
                    if (!wd1529.HasReading(1))
                    {
                        CheckCancel();
                        continue;
                    }
                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    FormGraphAction(0, Convert.ToDouble(rdg.reading),"c");
                    
                    string newio = GetCurrentIO();
                    bool alldone = true;
                    for (int ibc = 1; ibc <= TestDocument.MAX_BC; ibc++)
                    {
                        if (!testdoc.IsValueAvailable(new string[] { "m_" + ibc.ToString() + "_fdz" }))
                            continue;
                        if (newio[ibc - 1] == lastio[ibc - 1])
                        {
                            alldone = false;
                            continue;
                        }
                        string ckey;
                        ckey= "c_" + ibc.ToString() + "_" + ipoint.ToString() + "sqh_1";
                        if (!testdoc.IsValueAvailable(new string[] { ckey }))
                        {
                            this[ckey] = rdg.reading;
                            Thread.Sleep(200);
                            while(!wd1529.HasReading(1))
                                Thread.Sleep(200);
                            rdg = wd1529.GetTemperature(1);
                            ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "sqh_2";
                            if (!testdoc.IsValueAvailable(new string[] { ckey }))
                                this[ckey] = rdg.reading;
                        }
                    }
                    if (alldone || IsDiffSmall(rdg.reading, setpoint + uprange+2, 2))
                        break;
                }
                testdoc.AutoCaculation();
                #endregion

                #region collect down switch temperature
                lastio = GetCurrentIO();
                decimal dnrange = Decimal.Parse(Util.ConstIni.StringValue("CONDITION", "DNRANGE"));
                SetTemperature(setpoint + dnrange);
                FormAction("show_status", String.Format("下切换值测量中...."));
                while (true)
                {
                    if (!wd1529.HasReading(1))
                    {
                        CheckCancel();
                        continue;
                    }
                    TEMPRDG rdg = wd1529.GetTemperature(1);
                    FormGraphAction(0, Convert.ToDouble(rdg.reading),"c");

                    string newio = GetCurrentIO();
                    bool alldone = true;
                    for (int ibc = 1; ibc <= TestDocument.MAX_BC; ibc++)
                    {
                        if (!testdoc.IsValueAvailable(new string[] { "m_" + ibc.ToString() + "_fdz" }))
                            continue;
                        if (newio[ibc - 1] == lastio[ibc - 1])
                        {
                            alldone = false;
                            continue;
                        }
                        string ckey;
                        ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "xqh_1";
                        if (!testdoc.IsValueAvailable(new string[] { ckey }))
                        {
                            this[ckey] = rdg.reading;
                            Thread.Sleep(200);
                            while (!wd1529.HasReading(1))
                                Thread.Sleep(200);
                            rdg = wd1529.GetTemperature(1); ckey = "c_" + ibc.ToString() + "_" + ipoint.ToString() + "xqh_2";
                            if (!testdoc.IsValueAvailable(new string[] { ckey }))
                                this[ckey] = rdg.reading;
                        }
                    }
                    if (alldone || IsDiffSmall(rdg.reading, setpoint + dnrange - 2, 2))
                        break;
                }
                testdoc.AutoCaculation();
                #endregion
            }
            Thread.Sleep(1000);
        }
Пример #3
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;
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
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 pageid= "";
                string ccbh = askdlg.result;
                string ibcid = "";
                List<string> rows = new List<string>();
                Hashtable addkeys = new Hashtable();
                //search the corresponding page id and ibc ids
                for (int ibc = 0; ibc < 12; ibc++)
                {
                    if (!IsValueAvailable(new string[] { "m_" + (ibc + 1).ToString() + "_ccbh" }))
                        continue;
                    if (StrValue("m_" + (ibc + 1).ToString() + "_ccbh") == ccbh)
                    {
                        if (pageid == "")
                        {
                            pageid = String.Format("abcdef")[ibc / 4].ToString();
                            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);
                            wdd = ("   " + wdd);
                            wdd = wdd.Remove(0,wdd.Length - 3);
                            rows.Add(String.Format("R({0}℃)\t{1}", wdd, sjz));
                        }
                        string key = "c_" + (ibc + 1).ToString() + "_alphabc";
                        if (!IsValueAvailable(new string[] { key }))
                            continue;
                        string alpha = FormatValue(data_record.Property(key),false);
                        if (alpha != "")
                        {
                            rows.Add(String.Format("α\t{0}", alpha));
                        }
                    }
                }
                if (pageid == "")
                {
                    MessageBox.Show("未找到出厂编号为" + ccbh + "的铂电阻,请检查后再试");
                    return;
                }
                string tmpl = "";
                if (rule == REPORT_TYPE.INFO_REPORT)
                    tmpl = "结果通知书";
                if (rule == REPORT_TYPE.CALI_REPORT)
                    tmpl = "检定证书";
                if (rule == REPORT_TYPE.JIAOZHUN_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(), pageid,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;
            }
        }