private Data GetDataFromControl(Item item, Control control) { Data newData=new Data (); newData.ItemCode=item.Code; switch (item.Type.ToString().ToLower()) { case "list": ListCtrl listControl = (ListCtrl)control; newData.Value = listControl.Text; break; case "int": newData.Value = control.Text; break; case "decimal": newData.Value = control.Text; break; case "class": ComboBox cboObject = (ComboBox)control; newData.Value = cboObject.SelectedValue.ToString(); break; case "enum": ComboBox cboEnum = (ComboBox)control; newData.Value = cboEnum.SelectedValue.ToString(); break; case "text": newData.Value = control.Text; break; case "date": DateTimePicker dtp = (DateTimePicker)control; newData.Value = dtp.Value.ToString(); break; case "path": newData.Value = control.Text; break; default: newData.Value = control.Text; break; } return newData; }
public void Load(string fileName) { _filename = fileName; if (!File.Exists(_filename)) throw new Exception("未找到数据文件!"); try { _xmlDoc.Load(_filename); this.Name = _xmlDoc.SelectSingleNode("ConfigData/Name").InnerText; this.Code = _xmlDoc.SelectSingleNode("ConfigData/Code").InnerText; this.Order = int.Parse(_xmlDoc.SelectSingleNode("ConfigData/Order").InnerText); this.TemplateCode = _xmlDoc.SelectSingleNode("ConfigData/TemplateCode").InnerText; this.ProjectId = _xmlDoc.SelectSingleNode("ConfigData/ProjectId").InnerText; foreach (XmlNode itemNode in _xmlDoc.SelectNodes("ConfigData/Data")) { if (itemNode.NodeType == XmlNodeType.Element) { Data data = new Data(); data.ItemCode = itemNode.SelectSingleNode("ItemCode").InnerText; data.Value = itemNode.SelectSingleNode("Value").InnerText; this.DataList.Add(data); } } } catch(Exception ex) { throw new Exception("数据文件加载失败!"); } }