public bool createXmlFile(string filename) { try { Configure cfg = null; string cfgfile = System.IO.Path.Combine(Application.StartupPath, "cfg.json"); if (File.Exists(cfgfile)) { cfg = JsonConvert.DeserializeObject <Configure>(File.ReadAllText(cfgfile)); if (cfg != null) { LimsDoc l; l = new LimsDoc(cfg.username, cfg.userpassword, "system"); LimsDocEntity entity = l.createEntity("SAMPLE", "RESULT_ENTRY"); LimsDocEntity entity2 = l.createEntity("TEST", null); LimsDocEntity entity1_time = l.createEntity("RESULT", null); LimsDocEntity entity1_res = l.createEntity("RESULT", null); LimsDocEntity entity2_time = l.createEntity("RESULT", null); LimsDocEntity entity2_res = l.createEntity("RESULT", null); LimsDocEntity entity3_time = l.createEntity("RESULT", null); LimsDocEntity entity3_res = l.createEntity("RESULT", null); LimsDocEntity entity4_time = l.createEntity("RESULT", null); LimsDocEntity entity4_res = l.createEntity("RESULT", null); entity2.addFields("ANALYSIS", "in", textBoxAnalysis.Text); entity.addFields("ID_NUMERIC", "in", textBoxOilID.Text); if (lcfg == null) { entity1_time.addFields("NAME", "in", "一号弹测试时间"); entity1_time.addFields("TEXT", "in", regTextBox1.Text); entity2.addChild(entity1_time.getElement()); entity1_res.addFields("NAME", "in", "一号弹最大压力"); entity1_res.addFields("TEXT", "in", regTextBox2.Text); entity2.addChild(entity1_res.getElement()); entity2_time.addFields("NAME", "in", "二号弹测试时间"); entity2_time.addFields("TEXT", "in", regTextBox3.Text); entity2.addChild(entity2_time.getElement()); entity2_res.addFields("NAME", "in", "二号弹最大压力"); entity2_res.addFields("TEXT", "in", regTextBox4.Text); entity2.addChild(entity2_res.getElement()); entity3_time.addFields("NAME", "in", "三号弹测试时间"); entity3_time.addFields("TEXT", "in", regTextBox5.Text); entity2.addChild(entity3_time.getElement()); entity3_res.addFields("NAME", "in", "三号弹最大压力"); entity3_res.addFields("TEXT", "in", regTextBox6.Text); entity2.addChild(entity3_res.getElement()); entity4_time.addFields("NAME", "in", "四号弹测试时间"); entity4_time.addFields("TEXT", "in", regTextBox7.Text); entity2.addChild(entity4_time.getElement()); entity4_res.addFields("NAME", "in", "四号弹最大压力"); entity4_res.addFields("TEXT", "in", regTextBox8.Text); entity2.addChild(entity4_res.getElement()); } else { entity1_time.addFields("NAME", "in", lcfg.label_1_out); entity1_time.addFields("TEXT", "in", regTextBox1.Text); entity2.addChild(entity1_time.getElement()); entity1_res.addFields("NAME", "in", lcfg.label_2_out); entity1_res.addFields("TEXT", "in", regTextBox2.Text); entity2.addChild(entity1_res.getElement()); entity2_time.addFields("NAME", "in", lcfg.label_3_out); entity2_time.addFields("TEXT", "in", regTextBox3.Text); entity2.addChild(entity2_time.getElement()); entity2_res.addFields("NAME", "in", lcfg.label_4_out); entity2_res.addFields("TEXT", "in", regTextBox4.Text); entity2.addChild(entity2_res.getElement()); entity3_time.addFields("NAME", "in", lcfg.label_5_out); entity3_time.addFields("TEXT", "in", regTextBox5.Text); entity2.addChild(entity3_time.getElement()); entity3_res.addFields("NAME", "in", lcfg.label_6_out); entity3_res.addFields("TEXT", "in", regTextBox6.Text); entity2.addChild(entity3_res.getElement()); entity4_time.addFields("NAME", "in", lcfg.label_7_out); entity4_time.addFields("TEXT", "in", regTextBox7.Text); entity2.addChild(entity4_time.getElement()); entity4_res.addFields("NAME", "in", lcfg.label_8_out); entity4_res.addFields("TEXT", "in", regTextBox8.Text); entity2.addChild(entity4_res.getElement()); } entity.addChild(entity2.getElement()); l.getBody().addEntity(entity.getElement()); return(l.createdoc(filename)); } } } catch (Exception ex) { LogClass.GetInstance().WriteExceptionLog(ex); //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
public LimsDocEntity createEntity(string type, string command) { LimsDocEntity entity = new LimsDocEntity(xmldoc, type, command); return(entity); }