public static void Main(string[] args) { /* either serialized json in a file or as the raw argument */ string fileName = null; string rawJson = null; string outFile = GetThisFolder() + "new_file.docx"; //todo: deal with other extentions later var options = new OptionSet() { { "design-document", "", _ => { THIS_REPORT = REPORT_TYPE.DESIGN_DOCUMENT; } }, { "?|h|help", "", _ => Echo.HelpText() }, { "json=|raw-json=", "", input => { rawJson = input; } }, { "file=|file-path=", "", input => { fileName = input; } }, { "out=|out-file=", "", input => { outFile = input; } }, { "l=|log-level=", "", noise => { Echo.LOG_LEVEL = Convert.ToByte(noise); } }, }; var badInput = options.Parse(args); if (badInput.Count > 0) { Echo.ErrorReport(badInput.ToArray()); Echo.HelpText(); } Echo.WelcomeText(); UseTemplate[THIS_REPORT](GetJson(fileName) ?? rawJson, outFile); Echo.Out("done", 5); }
public void SendReport <T>(REPORT_TYPE _type, T _obj, Model.Header _header, string _eqpID) { try { switch (_type) { case REPORT_TYPE.EqpStatuChangeReport: // Step 1: Check Validation of the object // if (!(_obj is Report.StatuChangeReport)) { throw new ObjectValidationException(); } // Step 2: Convert into JSON // string msg = SemiJSONHelper.GetString(_obj, _header, Model.MESSAGE_TYPE.REQUEST, _eqpID); // step 3: Send to Server // if (!string.IsNullOrEmpty(msg)) { SendAsyn(msg, true); } break; case REPORT_TYPE.EqpAlarmReport: if (!(_obj is Report.AlarmReport)) { throw new ObjectValidationException(); } // TO-DO break; case REPORT_TYPE.EqpEdcReport: if (!(_obj is Report.EdcReport)) { throw new ObjectValidationException(); } // TO-DO break; default: throw new ObjectValidationException("Object type invalid"); } } catch (Exception ex) { throw new Exception(ex.ToString()); } }
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 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 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; } }
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; } }