public string GetTitle() { TEntity entity = TType.GetCustomAttribute <TEntity>(); string title = entity != null ? entity.Value : null; return(THelper.Lang(title, TType.Name)); }
public List <SCompare> Class2Search(string tNamespaceClass) { var list = new List <SCompare>(); while (true) { if (string.IsNullOrEmpty(tNamespaceClass)) { break; } Type type = Type.GetType(tNamespaceClass); if (type == null) { break; } var propertyList = type.GetProperties(); foreach (PropertyInfo pro in propertyList) { if (PropertyHelper.HasAttribute <TListSearch>(pro)) { var title = PropertyHelper.GetTFieldValue(pro, TF.title); title = THelper.Lang(title, pro.Name); SCompare compare = new SCompare(pro.Name, null, null, title); list.Add(compare); } } break; } return(list); }
public bool SaveRow(NameValueCollection collection) { if (m_object == null) { return(false); } TEntityUI entityUI = new TEntityUI(m_super); THelper.MergeCollection(collection, PresetDict); var row = entityUI.UI2Row(collection, m_object.TType); var id = collection.Get("id"); bool result = false; if (string.IsNullOrEmpty(id)) { result = m_object.Add(row) != null; } else { m_object.DetachRow(Row); result = m_object.Modify(row); } if (!result) { Errors = m_object.Errors; var err = Errors.First(); Error = err.Key + " " + err.Value;; } return(result); }
public TQueryLogic Condition(string condition) { while (true) { if (m_object == null) { break; } if (string.IsNullOrEmpty(condition)) { break; } CompareDict = THelper.String2CompareDict(condition); foreach (var item in CompareDict) { var compare = item.Value; m_object.TWhere(compare.Key, compare.Value, compare.Operate); } break; } return(this); }
public string Show(string shortPath, string imageSize = null) { string result = null; string sizePath = null; while (true) { if (string.IsNullOrWhiteSpace(shortPath)) { Error = G.L["upload_ShortPath"]; break; } EImageSize imageSizeEnum = THelper.ConvertToEnum(imageSize, EImageSize.middle); int size = Convert.ToInt32(imageSizeEnum); string sizeShortPath = FileHelper.GetSizePath(shortPath, size); string sizePathTrue = m_config.Dir + sizeShortPath + ".true"; if (File.Exists(sizePathTrue)) { result = m_config.OssUrl + sizeShortPath; break; } string path = m_config.Dir + shortPath; sizePath = m_config.Dir + sizeShortPath; if (!PsHelper.Thumb(path, sizePath, size, size)) { Error = G.L["upload_NoLargeFile"]; break; } AliOssLogic aliOss = new AliOssLogic(); if (!aliOss.Add(sizeShortPath, sizePath)) { Error = G.L["upload_OssAdd"]; break; } if (!FileHelper.CreateFile(sizePathTrue)) { Error = G.L["upload_CreateTrue"]; break; } result = m_config.OssUrl + sizeShortPath; break; } FileHelper.DeleteFile(sizePath); return(result); }
T FillRow(T prow = null) { T row = null; bool modeCreate = prow == null; if (modeCreate) { row = (T)Activator.CreateInstance(TType, null); } else { row = prow; } PropertyInfo[] propertys = TType.GetProperties(); foreach (PropertyInfo pro in propertys) { if (pro.Name == "id") { if (PropertyHelper.IsAutoIncrease(pro)) { continue; } else if (!modeCreate) { continue; } } object val = null; if (pro.PropertyType == typeof(Int32?)) { val = THelper.GetRandom(); } else if (pro.PropertyType == typeof(Int64?)) { val = Convert.ToInt64(THelper.GetRandom()); } else if (pro.PropertyType == typeof(String)) { val = pro.Name + " " + THelper.GetRandom(); } else if (pro.PropertyType == typeof(DateTime?)) { val = DateTime.Now; } if (val != null) { pro.SetValue(row, val); } } return(row); }
public QrcodeLogic(string serverDir) { m_serverDir = serverDir; var config = G.Config["Qrcode"]; m_home = config["home"]; m_path = config["path"]; m_width = THelper.StringToInt(config["width"]); c_width = config["c_width"]; c_path = config["c_path"]; var ossConfig = G.Config["AliOss"]; m_ossUrl = string.Format(ossConfig["url"], ossConfig["bucket"], ossConfig["server"]); }
public object UI2Row(NameValueCollection collection, Type type) { var row = Activator.CreateInstance(type, null); PropertyInfo[] propertyList = type.GetProperties(); foreach (PropertyInfo pro in propertyList) { if (PropertyHelper.IsVirtual(pro)) { if (PropertyHelper.HasElement(pro)) { var subRow = UI2Row(collection, pro.PropertyType); pro.SetValue(row, subRow); } } else if (collection.AllKeys.Contains(pro.Name)) { // tsuper var super = PropertyHelper.GetTFieldValueRaw(pro, TF.super); if (super != null && m_super > (TS)super) { continue; } object val = collection[pro.Name]; // refer var refer = PropertyHelper.GetTFieldValue(pro, TF.refer); if (refer != null) { val = collection.AllKeys.Contains(refer) ? collection[refer] : ""; } // parse var parse = PropertyHelper.GetTFieldValue(pro, TF.parse); if (parse != null) { val = JMethod.Run <THelper>(parse, new object[] { val }); } THelper.ConvertToType(pro.PropertyType, ref val); pro.SetValue(row, val); } } return(row); }
public void Row2UI(object row, Action <TFDictionary> act, bool isSub = false) { Type type = THelper.GetBaseType(row); List <PropertyInfo> propertyListVirtual = new List <PropertyInfo>(); // propertyList var propertyList = type.GetProperties(); List <TFDictionary> list = new List <TFDictionary>(); foreach (PropertyInfo pro in propertyList) { if (PropertyHelper.IsVirtual(pro)) { if (PropertyHelper.HasElement(pro)) { propertyListVirtual.Add(pro); } } else { if (isSub && PropertyHelper.IsKey(pro)) { continue; } var value = pro.GetValue(row); var dict = field2UI(pro, value); // action if (dict != null) { act(dict); } } } // propertyListVirtual foreach (PropertyInfo pro in propertyListVirtual) { var value = pro.GetValue(row); if (value == null) { value = Activator.CreateInstance(pro.PropertyType, null); } Row2UI(value, act, true); } }
public bool PostData(string url, Dictionary <string, object> param = null, bool isJson = false) { var result = false; while (true) { if (string.IsNullOrEmpty(url)) { break; } try { // init var request = WebRequest.Create(url); request.Method = "POST"; // param string options = null; if (isJson) { options = JsonConvert.SerializeObject(param); } else { options = THelper.Dict2QueryString(param); request.ContentType = "application/x-www-form-urlencoded"; } byte[] data = Encoding.UTF8.GetBytes(options); request.ContentLength = data.Length; // request Stream streamWriter = request.GetRequestStream(); streamWriter.Write(data, 0, data.Length); // response m_stream = request.GetResponse().GetResponseStream(); result = true; } catch { } break; } return(result); }
// // only the changed field will be validate and update // bool checkModify(ref object row) { if (row == null) { return(false); } bool bResult = false; Type type = THelper.GetBaseType(row); foreach (PropertyInfo pro in type.GetProperties()) { if (PropertyHelper.IsVirtual(pro)) { if (PropertyHelper.HasElement(pro)) { var value = pro.GetValue(row); if (checkModify(ref value)) { // set modify pro.SetValue(row, value); bResult = true; } } } else { if (pro.Name == "id") { continue; } if (pro.GetValue(row) != null) { // set modify DbPropertyEntry proEntry = m_db.Entry(row).Property(pro.Name); proEntry.IsModified = true; bResult = true; } } } return(bResult); }
public bool DetachRow(object row) { var result = false; while (true) { if (row == null) { break;; } if (THelper.GetBaseType(row) != TType) { break; } m_db.Entry(row).State = EntityState.Detached; result = true; break; } return(result); }
public UploadLogic(string serverDir) { var uploadConfig = G.Config["UPLOAD"]; m_config = new SUploadConfig(); var maxSize = THelper.StringToInt(uploadConfig["maxSize"]); m_config.ContentLength = maxSize * 1024 * 1024; m_config.ContentTypeList = new string[] { "image/jpeg", "image/png" }; m_config.ImageFormatList = new ImageFormat[] { ImageFormat.Png, ImageFormat.Jpeg }; m_config.Dir = serverDir + uploadConfig["dir"] + "/"; var ossConfig = G.Config["AliOss"]; m_config.OssUrl = string.Format(ossConfig["url"], ossConfig["bucket"], ossConfig["server"]); }
bool checkAdd(ref object row) { if (row == null) { return(false); } bool bResult = true; Type type = THelper.GetBaseType(row); foreach (PropertyInfo pro in type.GetProperties()) { if (PropertyHelper.IsVirtual(pro)) { if (PropertyHelper.HasElement(pro)) { var value = pro.GetValue(row); if (value == null) { value = Activator.CreateInstance(pro.PropertyType, null); } if (!checkAdd(ref value)) { // set error bResult = false; } } } else if ((row == null || pro.GetValue(row) == null) && PropertyHelper.IsRequired(pro)) { // set error Errors[pro.Name] = "is required"; bResult = false; } } return(bResult); }
public void List2UI(object list, Action rowBegin, Action <object> filedAction, Action <object> rowEnd) { dynamic listDynamic = list; foreach (object row in listDynamic) { // row if (rowBegin != null) { rowBegin(); } PropertyInfo[] propertyList = THelper.GetBaseType(row).GetProperties(); object key = null; foreach (PropertyInfo pro in propertyList) { // field if (PropertyHelper.IsKey(pro)) { key = pro.GetValue(row); } if (PropertyHelper.HasAttribute <TListShow>(pro)) { var dict = field2UI(pro, pro.GetValue(row)); field2UIMore(ref dict, pro); filedAction(dict); } } if (rowEnd != null) { rowEnd(key); } } }
public bool GetData(string url, Dictionary <string, object> param = null) { var result = false; while (true) { if (string.IsNullOrEmpty(url)) { break; } try { url += THelper.Dict2QueryString(param); var request = WebRequest.Create(url); request.Method = "GET"; m_stream = request.GetResponse().GetResponseStream(); result = true; } catch { } break; } return(result); }
protected TFDictionary field2UI(PropertyInfo pro, object value) { if (PropertyHelper.IsVirtual(pro)) { return(null); } TFDictionary dict = pro.GetCustomAttributes <TField>() .ToDictionary(p => p.Key, p => p.Value); // Reserved return if (dict.ContainsKey(TF.reserved)) { return(null); } // begin fill dictionary PropertyHelper.FillTFDictionary(ref dict); // tsuper var super = dict[TF.super]; if (super != null && m_super > (TS)super) { return(null); } // element TElement element = pro.GetCustomAttribute <TElement>(); if (element == null) { TE te = PropertyHelper.IsKey(pro) ? TE.hidden : TE.text; element = new TElement(te); } dict[TF.element] = element.Key; // dataSource dict[TF.dataSource] = element.Value; // widget string widget; switch (element.Key) { case TE.text: case TE.password: case TE.url: case TE.tel: widget = TE.text.ToString(); break; case TE.picture: widget = TE.hidden.ToString(); break; default: widget = element.Key.ToString(); break; } dict[TF.widget] = widget; // title dict[TF.title] = THelper.Lang(dict[TF.title] as string, pro.Name); // name dict[TF.name] = pro.Name; // value THelper.ConvertToUI(element.Key, ref value); dict[TF.value] = value; return(dict); }
dynamic getTList() { Type generic = typeof(TListLogic <>); return(THelper.CreateInstance(generic, FullName)); }
public TListLogic <T> TWhere(string key, object value, string operate = op.eq) { while (true) { // check key input if (string.IsNullOrWhiteSpace(key)) { break; } // check key property PropertyInfo property = TType.GetProperty(key); if (property == null) { break; } // convert type if (value.GetType() != property.PropertyType) { THelper.ConvertToType(property.PropertyType, ref value); } ParameterExpression parameter = Expression.Parameter(TType); Expression left = Expression.Property(parameter, property); Expression right = Expression.Constant(value); if (value.GetType() != property.PropertyType) { right = Expression.Convert(right, property.PropertyType); } Expression condition = null; switch (operate) { case op.gt: condition = Expression.GreaterThan(left, right); break; case op.gte: condition = Expression.GreaterThanOrEqual(left, right); break; case op.lt: condition = Expression.LessThan(left, right); break; case op.lte: condition = Expression.LessThanOrEqual(left, right); break; case op.like: Type stringType = typeof(string); condition = Expression.Call( left, stringType.GetMethod("Contains", new Type[] { stringType }), right); break; case op.eq: default: condition = Expression.Equal(left, right); break; } LambdaExpression lambda = Expression.Lambda(condition, parameter); m_query = Expression.Call( typeof(Queryable), "Where", new Type[] { TType }, m_query, lambda ); break; } return(this); }