string BuildQuery() { ... if (IsDateFromSpecified) strQuery += "DateFrom >= '" + DateFromValue.ToString() + "'"; ... }
const string MORE_OR_EQUALS_EXPRESSION = "{0} >= '{1}'"; const string DATE_FROM_ATTRIBUTE = "DateFrom"; string BuildQuery() { ... if (IsDateFromSpecified) strQuery += string.Format(MORE_OR_EQUALS_EXPRESSION, DATE_FROM_ATTRIBUTE, DateFromValue.ToString()); ... }
const string MORE_OR_EQUALS_EXPRESSION = "{0} >= '{1}'"; const string DATE_FROM_ATTRIBUTE = "DateFrom"; string BuildQuery() { ... if (IsDateFromSpecified) strQuery += string.Format(MORE_OR_EQUALS_EXPRESSION, DATE_FROM_ATTRIBUTE, DateFromValue.ToString()); ... }
// - predicate.Add(DGA.FlowId.EqualsTo(WorksFlowId)); // predicate.Add(DGA.DogovorOfWorkID.EqualsTo(CurrentDocument.Id)); // if (DateFrom != null) predicate.Add(DGA.WorkEndsAt.MoreOrEqualThan(DateFrom.Value)); if (DateTo != null) predicate.Add(DGA.WorkStartsAt.LessOrEqualThan(DateTo.Value)); // if (OnlyActive) predicate.Add(DGA.WorkState.EqualsTo(WorkState.Planned.ToString()));
// - predicate.Add(DGA.FlowId.EqualsTo(WorksFlowId)); // predicate.Add(DGA.DogovorOfWorkID.EqualsTo(CurrentDocument.Id)); // if (DateFrom != null) predicate.Add(DGA.WorkEndsAt.MoreOrEqualThan(DateFrom.Value)); if (DateTo != null) predicate.Add(DGA.WorkStartsAt.LessOrEqualThan(DateTo.Value)); // if (OnlyActive) predicate.Add(DGA.WorkState.EqualsTo(WorkState.Planned.ToString()));
public enum DGA { [Description("doc_RegCard/rc_Index/date__")] RegDate, [Description("doc_RegCard/rc_Index/text__")] RegNum, [Description("doc_RegCard/rc_Index/text___")] Manager, [Description("doc_RegCard/rc_FlowKey")] FlowId, [Description("doc_RegCard/rc_Index/text__")] Title, [Description("doc_RegCard/rc_Index/text__")] Subject, ... }
public enum DGA { [Description("doc_RegCard/rc_Index/date__")] RegDate, [Description("doc_RegCard/rc_Index/text__")] RegNum, [Description("doc_RegCard/rc_Index/text___")] Manager, [Description("doc_RegCard/rc_FlowKey")] FlowId, [Description("doc_RegCard/rc_Index/text__")] Title, [Description("doc_RegCard/rc_Index/text__")] Subject, ... }
public static string LessOrEqualThan(this DGA attrib, DateTime val) { return attrib.LessOrEqualThan(System.Xml.XmlConvert .ToString(val, System.Xml.XmlDateTimeSerializationMode.Unspecified)); } public static string LessOrEqualThan(this DGA attrib, string val) { return String.Format("{0} <= '{1}'", attrib.GetAttribName(), val); } public static string InList(this DGA attrib, IEnumerable<string> values) { return String.Format("{0} in list({1})", attrib.GetAttribName(), values .Select(x => "'" + x + "'") .Aggregate((x, y) => x + ", " + y)); }
public static string LessOrEqualThan(this DGA attrib, DateTime val) { return attrib.LessOrEqualThan(System.Xml.XmlConvert .ToString(val, System.Xml.XmlDateTimeSerializationMode.Unspecified)); } public static string LessOrEqualThan(this DGA attrib, string val) { return String.Format("{0} <= '{1}'", attrib.GetAttribName(), val); } public static string InList(this DGA attrib, IEnumerable<string> values) { return String.Format("{0} in list({1})", attrib.GetAttribName(), values .Select(x => "'" + x + "'") .Aggregate((x, y) => x + ", " + y)); }
public static class DGAExt { public static string GetAttribName(this DGA attrib) { if (_dgaNames != null) return _dgaNames[attrib]; return EnumHelper.GetDescription(attrib); } } public static class EnumHelper { /// <summary> /// Retrieve the description on the enum, eg /// [Description("Bright Pink")] /// BrightPink = 2, /// Then when you pass in the enum, it will retrieve the description /// </summary> /// <param name="en">The Enumeration</param> /// <returns>A string representing the friendly name</returns> public static string GetDescription(Enum en) { var desc = GetAttribute<DescriptionAttribute>(en); if (desc != null) return desc.Description; return en.ToString(); } public static T GetAttribute<T>(Enum en) where T : System.Attribute { Type type = en.GetType(); MemberInfo[] memInfo = type.GetMember(en.ToString()); if (memInfo.Length > 0) { var attrs = memInfo[0].GetCustomAttributes(typeof(T), false).Cast<T>(); return attrs.FirstOrDefault(); } return null; } }
public static class DGAExt { public static string GetAttribName(this DGA attrib) { if (_dgaNames != null) return _dgaNames[attrib]; return EnumHelper.GetDescription(attrib); } } public static class EnumHelper { /// <summary> /// Retrieve the description on the enum, eg /// [Description("Bright Pink")] /// BrightPink = 2, /// Then when you pass in the enum, it will retrieve the description /// </summary> /// <param name="en">The Enumeration</param> /// <returns>A string representing the friendly name</returns> public static string GetDescription(Enum en) { var desc = GetAttribute<DescriptionAttribute>(en); if (desc != null) return desc.Description; return en.ToString(); } public static T GetAttribute<T>(Enum en) where T : System.Attribute { Type type = en.GetType(); MemberInfo[] memInfo = type.GetMember(en.ToString()); if (memInfo.Length > 0) { var attrs = memInfo[0].GetCustomAttributes(typeof(T), false).Cast<T>(); return attrs.FirstOrDefault(); } return null; } }
Source: https://habr.com/ru/post/139617/
All Articles