private WeiSha.Data.Entity _entityFillSingle(System.Web.UI.Control c, WeiSha.Data.Entity entity, string piName) { string value = ""; //下拉菜单,多选列表,单选列表 if (c is DropDownList || c is CheckBoxList || c is RadioButtonList) { ListControl ddl = c as ListControl; value = ddl.SelectedValue; } //输入框 if (c is TextBox) { TextBox tb = c as TextBox; value = tb.Text; } //单选与多选 if (c is CheckBox || c is RadioButton) { CheckBox cb = c as CheckBox; value = cb.Checked.ToString(); } //获取值,转的成属性的数据类型,并赋值 var property = entity.GetType().GetProperty(piName); object tm = string.IsNullOrEmpty(value) ? null : WeiSha.Common.DataConvert.ChangeType(value, property.PropertyType); property.SetValue(entity, tm, null); return(entity); }
private WeiSha.Data.Entity _entityFill(System.Web.UI.Control control, WeiSha.Data.Entity entity) { foreach (Control c in control.Controls) { if (string.IsNullOrWhiteSpace(c.ID)) { continue; } //遍历实体属性 Type info = entity.GetType(); PropertyInfo[] properties = info.GetProperties(); for (int j = 0; j < properties.Length; j++) { PropertyInfo pi = properties[j]; if (pi.Name == c.ID) { entity = _entityFillSingle(c, entity, pi.Name); break; } } } foreach (Control c in control.Controls) { entity = _entityFill(c, entity); } return(entity); }
/// <summary> /// 通过实体,生成二维码 /// </summary> /// <param name="entity"></param> /// <param name="template">二维码内容模板</param> /// <param name="wh">宽高</param> /// <param name="qrcodeImgPath">二维码文件路径</param> /// <returns></returns> public static string Creat4Entity(WeiSha.Data.Entity entity, string template, string qrcodeImgPath, int wh) { Type info = entity.GetType(); //获取对象的属性列表 PropertyInfo[] properties = info.GetProperties(); for (int i = 0; i < properties.Length; i++) { PropertyInfo pi = properties[i]; //当前属性的值 object obj = info.GetProperty(pi.Name).GetValue(entity, null); string patt = @"{\#\s*{0}\s*}"; patt = patt.Replace("{0}", pi.Name); Regex re = new Regex(patt, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline); template = re.Replace(template, obj == null ? "" : obj.ToString()); } template = QrCode.tranUrl(template); //是否生成中心logo bool isCenterImg = Business.Do <ISystemPara>()["IsQrConterImage"].Boolean ?? true; string color = Business.Do <ISystemPara>()["QrColor"].String; System.Drawing.Image image = null; if (isCenterImg) { string centerImg = Upload.Get["Org"].Physics + "QrCodeLogo.png"; image = WeiSha.Common.QrcodeHepler.Encode(template, wh, centerImg, color, null); } else { image = WeiSha.Common.QrcodeHepler.Encode(template, wh, color, null); } image.Save(qrcodeImgPath); return(qrcodeImgPath); }
/// <summary> /// 向单个控件绑定 /// </summary> /// <param name="control"></param> /// <param name="entity"></param> private void _entityBindSingle(System.Web.UI.Control c, WeiSha.Data.Entity entity) { //遍历实体属性 Type info = entity.GetType(); PropertyInfo[] properties = info.GetProperties(); for (int j = 0; j < properties.Length; j++) { PropertyInfo pi = properties[j]; if (c.ID.Equals(pi.Name, StringComparison.CurrentCultureIgnoreCase)) { //当前属性的值 object obj = info.GetProperty(pi.Name).GetValue(entity, null); if (obj != null) { _controlBindFunc(c, obj); } break; } } }