private bool GetMedGridViewColumns(string value, out List <MedGridViewColumn> medGridViewColumns) { medGridViewColumns = null; if (string.IsNullOrEmpty(value)) { return(false); } System.IO.Stream stream = Sundries.DecodeWithString(value); object obj = AssemblyHelper.ReadFile(stream); if (obj != null && obj is List <MedGridViewColumn> ) { medGridViewColumns = obj as List <MedGridViewColumn>; if (medGridViewColumns != null) { foreach (MedGridViewColumn item in medGridViewColumns) { item.HeaderText = item.HeaderText.Replace(@"\r\n", "\r\n"); } } return(true); } else { return(false); } }
public static object GetPropertyValue(PropertyInfo propertyInfo, object obj) { object value = propertyInfo.GetValue(obj, null); if (value != null) { if (propertyInfo.PropertyType.Name.Equals("Color")) { value = ((Color)value).Name; } else if (propertyInfo.PropertyType.Name.Equals("Font")) { value = ConvertFontToString((Font)value); } else if (propertyInfo.PropertyType.Name.Equals("Image")) { value = Sundries.EncodeWithString(FileHelper.ImageToStream(value as Image)); } else { value = value.ToString(); } } return(value); }
public static void SetPropertyValue(PropertyInfo propertyInfo, object obj, object newValue) { if (propertyInfo == null) { return; } object value = null; if (newValue != null) { string valueString = newValue.ToString(); if (propertyInfo.PropertyType.Equals(typeof(Color))) { value = ColorFromString(newValue); } else if (propertyInfo.PropertyType.Equals(typeof(Font))) { if (newValue is Font) { value = newValue; } else { value = ConvertStringToFont(valueString); } } else if (propertyInfo.PropertyType.Equals(typeof(Image))) { if (newValue is Image) { value = newValue; } else { value = Image.FromStream(Sundries.DecodeWithString(valueString)); } } else if (propertyInfo.PropertyType.IsEnum) { value = Enum.Parse(propertyInfo.PropertyType, valueString); } else if (propertyInfo.PropertyType.Equals(typeof(string))) { value = valueString; } else { Type type = propertyInfo.PropertyType; MethodInfo method = type.GetMethod("Parse", new Type[] { typeof(string) }); if (method != null) { value = method.Invoke(null, new object[] { valueString }); } } } propertyInfo.SetValue(obj, value, null); }
public static object ReadObject(XmlNode node, ArrayList errors, object myinstance) { XmlAttribute typeAttr = node.Attributes["type"]; if (typeAttr == null) { //errors.Add("<Object> tag is missing required type attribute"); //Logger.Write("<Object> tag is missing required type attribute"); return(null); } Type type = null; if (_typeCache.ContainsKey(typeAttr.Value)) { type = _typeCache[typeAttr.Value]; } else { type = Type.GetType(typeAttr.Value); _typeCache[typeAttr.Value] = type; } if (type == null) { //errors.Add(string.Format("Type {0} could not be loaded.", typeAttr.Value)); //Logger.Write(string.Format("Type {0} could not be loaded.", typeAttr.Value)); return(null); } XmlAttribute nameAttr = node.Attributes["name"]; object instance; if (myinstance != null) { if (myinstance is IDesignerLoaderHost) { if (nameAttr == null) { instance = (myinstance as IDesignerLoaderHost).CreateComponent(type); } else { instance = (myinstance as IDesignerLoaderHost).CreateComponent(type, nameAttr.Value); } } else if (type.Equals(typeof(MedicalSystem.Anes.Document.Designer.ReportViewProperties))) { //instance = Activator.CreateInstance(type); instance = new MedicalSystem.Anes.Document.Designer.ReportViewProperties(); (myinstance as MedReportView).AddComponent(instance as MedicalSystem.Anes.Document.Designer.ReportViewProperties); } else { instance = myinstance; } } //if(type.Equals(typeof(Form))) //{ // instance = this; //} else { instance = Activator.CreateInstance(type); } XmlAttribute childAttr = node.Attributes["children"]; IList childList = null; if (childAttr != null) { PropertyDescriptor childProp = TypeDescriptor.GetProperties(instance)[childAttr.Value]; if (childProp == null) { //Logger.Write(string.Format("The children attribute lists {0} as the child collection but this is not a property on {1}", childAttr.Value, instance.GetType().FullName)); } else { childList = childProp.GetValue(instance) as IList; if (childList == null) { //Logger.Write(string.Format("The property {0} was found but did not return a valid IList", childProp.Name)); //errors.Add(string.Format("The property {0} was found but did not return a valid IList", childProp.Name)); } } } foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name.Equals("Object")) { if (childAttr == null) { //errors.Add("Child object found but there is no children attribute"); //Logger.Write("Child object found but there is no children attribute"); continue; } if (childList != null) { object childInstance; if (myinstance is IDesignerLoaderHost) { childInstance = ReadObject(childNode, errors, myinstance); childList.Add(childInstance); } else { try { //DateTime a = DateTime.Now; childInstance = ReadObject(childNode, errors, null); //DateTime b = DateTime.Now; //TimeSpan d = b - a; //Logger.Write(string.Format("{1} childInstance = ReadObject(childNode, errors, null);; 共用时{0}秒", d.TotalSeconds, childInstance.GetType().FullName)); childList.Add(childInstance); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.StackTrace); } } //DateTime ss = DateTime.Now; if ((instance as Control).Name == "MedReportView") { //DateTime ss1 = DateTime.Now; //MedReportView aa = new MedReportView(); //aa.Controls.Add(childInstance as Control); //DateTime ss2 = DateTime.Now; //TimeSpan s3 = ss2 - ss1; //Form aas = new Form(); //aa.Dock = DockStyle.Fill; //aas.Controls.Add(aa); //aas.WindowState = FormWindowState.Maximized; //aas.ShowDialog(); //Logger.Write(string.Format("{3} {1} {2} aa.Controls.Add(childInstance as Control);; 共用时{0}秒", s3.TotalSeconds, childInstance.GetType().FullName, (childInstance as Control).Name, "MedReportView aa = new MedReportView();")); } //DateTime sss = DateTime.Now; //TimeSpan c = sss - ss; //Logger.Write(string.Format("{3} {1} {2} childList.Add(childInstance); 共用时{0}秒", c.TotalSeconds, childInstance.GetType().FullName, (childInstance as Control).Name,(instance as Control).Name)); } } else if (childNode.Name.Equals("Property")) { ReadProperty(childNode, instance, errors); } else if (childNode.Name.Equals("Binary")) { BinaryFormatter formatter = new BinaryFormatter(); instance = formatter.Deserialize(Sundries.DecodeWithString(childNode.InnerText)); } } return(instance); }