【发布时间】:2013-02-16 20:01:25
【问题描述】:
这里我通过序列化将详细信息从 form1 保存到 data.xml。
现在,我想通过在表格 2 中搜索患者 ID 来获取详细信息,并在单击表格 2 中的恢复按钮时恢复到表格 1 的文本框中。
public class PatientData { public long Patient_ID; public string Name; public string Address; public long Mobile; } private void Patient_clear() { Patient_ID.Text = ""; Mobile.Text = ""; Address.Text = ""; Name.Text = ""; } private List<PatientData> GetPatients(string filename) { if (!File.Exists(filename)) return new List<PatientData>(); XmlSerializer xs = new XmlSerializer(typeof(List<PatientData>)); using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate)) return (List<PatientData>)xs.Deserialize(fs); } public void SavePatients(string filename, List<PatientData> Patients) { XmlSerializer xs = new XmlSerializer(typeof(List<PatientData>)); using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate)) xs.Serialize(fs, Patients); } private void load_Click(object sender, EventArgs e) { System.Windows.Forms.Form Form2 = new Form2(); Form2.Show(); } private void save_Click(object sender, EventArgs e) { List<PatientData> Patients = GetPatients(@"D:\PatientD.xml"); PatientData patient = new PatientData(); patient.Patient_ID = Patient_ID.MaxLength; patient.Name = Name.Text; patient.Address = Address.Text; patient.Mobile = Mobile.MaxLength; Patients.Add(patient); SavePatients(@"D:\Sarath\Project\XML\curarisd\PatientD.xml", Patients); MessageBox.Show("Inserted"); Patient_clear(); }
坦率地说,我没有尝试恢复数据,我不知道 xml 是大学的 ma 项目。请帮助我学习。现在我的问题是我想通过在 form2 中搜索患者 ID 并在 form1 中显示来从 PatientD.xml 恢复数据
注意:一个项目有两种形式
【问题讨论】:
-
好的,你已经说了你想要达到的目标。不过,您还没有提出问题,也没有展示您迄今为止尝试过的内容。请阅读tinyurl.com/so-list和tinyurl.com/so-hints
-
不确定您到底想做什么?这些是单独的程序吗?我假设当您按下保存时,您会保存到 XML 输出。然后在该表单2中,当您按下恢复时,您可以选择 XML 文件并导入数据。我对么?另外,您使用 ISerializable 还是 IXmlSerializable?
-
至少表格看起来漂亮漂亮..lol
where is the code that you are using on the Save as well as the Restore button Click
标签: c# xml winforms visual-studio xml-deserialization