Exemple #1
0
        public ActionResult Drag(int caId, int delta, DateTime?end)
        {
            Base_CatalogArticle ca = _schedule.Article.GetById(caId);

            if (ca.Article.State == ScheduleEvent.OptionReadOnly)
            {
                return(JsonTips("error", SStr.CantChangeReadonlySchedule));
            }
            DateTime startTime = CommOp.ToDateTime(ca.GetExt(ScheduleEvent.Root.StartTime));
            DateTime endTime   = CommOp.ToDateTime(ca.GetExt(ScheduleEvent.Root.EndTime));

            if (end.IsEmpty())
            {
                //表示是拖动整个日程,同时改变起止时间
                startTime = startTime.AddMinutes(delta);
                ca.SetExt(ScheduleEvent.Root.StartTime, startTime);
                if (endTime != default(DateTime))
                {
                    endTime = endTime.AddMinutes(delta);
                    ca.SetExt(ScheduleEvent.Root.EndTime, endTime);
                }
            }
            else
            {
                ca.SetExt(ScheduleEvent.Root.EndTime, end);
            }
            ca.Article.EditorId = CurrentUserId.ToInt();
            ca.Article.State    = ArticleState.Published;
            _schedule.Article.Save(ca);
            return(JsonTips());
        }
Exemple #2
0
        private void SetCellValue(ICell cell, object obj)
        {
            if (obj == null)
            {
                cell.SetCellValue("");
                return;
            }
            Type type = obj.GetType();

            if (type == typeof(bool) || type == typeof(bool?))
            {
                cell.SetCellValue(CommOp.ToBool(obj));
            }
            else if (CommOp.ToDecimal(obj).ToString() == obj.ToString())
            {
                cell.SetCellValue(CommOp.ToDouble(obj));
            }
            else if (type == typeof(DateTime))
            {
                cell.SetCellValue(CommOp.ToDateTime(obj));
            }
            else
            {
                cell.SetCellValue(CommOp.ToStr(obj));
            }
        }
Exemple #3
0
        /// <summary>
        /// 根据传过来的地址栏filter参数来获取查询条件
        /// 与服务端配置的filter合并
        /// </summary>
        /// <param name="tableMeta"></param>
        /// <param name="ps"></param>
        /// <returns></returns>
        private void CreateFilterStr(DataGateKey gkey, TableMeta tableMeta, IDictionary <string, object> ps)
        {
            if (!ps.ContainsKey(Consts.FilterKey))
            {
                return;
            }
            var filterStr = CommOp.ToStr(ps[Consts.FilterKey]);
            var requests  = JsonConvert.DeserializeObject <FilterRequest[]>(filterStr);

            ps.Remove(Consts.FilterKey);

            filterStr = string.Join(" and ", requests.Select(r =>
            {
                var field = tableMeta.Fields.FirstOrDefault(f => f.Name.Equals(r.Name, StringComparison.OrdinalIgnoreCase));
                if (field == null)
                {
                    return(null);
                }
                string left = field.ForeignField.IsEmpty() ? (gkey.TableJoins[0].Alias ?? tableMeta.Name) + "." + field.Name : field.ForeignField;

                //当有sql语句并且有模型定义时
                if (!gkey.Sql.IsEmpty() && gkey.TableJoins.Count > 0)
                {
                    left = field.Name;
                }

                string pName = r.Name + "_f"; //加后缀以免和未知的key冲突
                ps[pName]    = r.Value;
                switch (r.Operator)
                {
                case "e":
                    return($"{left}=@{pName}");

                //判断日期相等,日期相等比较特殊,很难精确相等,
                //因此转成只判断是否在当天
                case "de":
                    var date      = CommOp.ToDateTime(r.Value).Date;
                    var date1     = date.AddDays(1).AddTicks(-1);
                    ps[pName]     = date;
                    ps[pName + 1] = date1;
                    return($"{left} between @{pName} and @{pName}1");

                case "ne":
                    return($"{left}!=@{pName}");

                case "in":
                    ps[pName] = CommOp.ToStr(ps[pName]).Split(',');
                    return($"{left} in (@{pName})");

                case "nin":
                    ps[pName] = CommOp.ToStr(ps[pName]).Split(',');
                    return($"{left} not in (@{pName})");

                case "i":
                    ps[pName] = "%" + r.Value + '%';
                    return($"{left} like @{pName}");

                case "ni":
                    ps[pName] = "%" + r.Value + '%';
                    return($"{left} not like @{pName}");

                case "lte":
                    return($"{left} <= @{pName}");

                case "gte":
                    return($"{left} >= @{pName}");

                case "bt":
                    if (r.Value1.IsDefault())
                    {
                        return($"{left} >= @{pName}");
                    }
                    if (field.DataType == "Date" || field.DataType == "DateTime")
                    {
                        r.Value1 = CommOp.ToDateTime(r.Value1).Date.AddDays(1).AddTicks(-1);
                    }
                    ps[pName + 1] = r.Value1;
                    return($"{left} between @{pName} and @{pName}1");

                case "n":
                    return($"{left} is null");

                case "nn":
                    return($"{left} is not null");

                default:
                    return(null);
                    //throw new ArgumentException("非法的查询请求:" + r.Operator);
                }
            }).Where(r => r != null));

            //与原有的gkey.Filter合并得到一个and条件
            if (!filterStr.IsEmpty())
            {
                gkey.Filter = gkey.Filter.IsEmpty() ? filterStr : $"({gkey.Filter}) and {filterStr}";
            }
        }
 /// <summary>
 /// 获取日期时间扩展属性
 /// </summary>
 /// <param name="ca"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static DateTime GetExtDateTime(this Base_CatalogArticle ca, string name)
 {
     return(CommOp.ToDateTime(ca.GetExt(name)));
 }
Exemple #5
0
        /// <summary>
        /// 将value中的值赋给对象的属性或字段
        /// </summary>
        /// <param name="obj">对象</param>
        /// <param name="propName">属性名</param>
        /// <param name="value">值</param>
        /// <param name="actualType">值的类型,为空时自动判断</param>
        public static void SetValue(object obj, string propName, string value, Type actualType = null)
        {
            //if (String.IsNullOrEmpty(value)) return;
            FieldInfo fi = obj.GetType().GetField(propName, bindAttr);

            if (fi != null)
            {
                SetFieldValue(obj, fi, value, actualType);
                return;
            }
            PropertyInfo pi = GetPropertyInfo(obj, propName);

            if (pi == null)
            {
                return;
            }
            if (!pi.CanWrite)
            {
                return;
            }
            if (PraserDict.ContainsKey(pi.PropertyType))
            {
                var pvalue = PraserDict[pi.PropertyType].Prase(value);
                if (pvalue == null)
                {
                    return;
                }
                pi.SetValue(obj, pvalue, null);
                return;
            }
            if (pi.PropertyType == typeof(string) || pi.PropertyType == typeof(object))
            {
                pi.SetValue(obj, value, null);
            }
            else if (pi.PropertyType == typeof(int))
            {
                pi.SetValue(obj, CommOp.ToInt(value), null);
            }
            else if (pi.PropertyType == typeof(Int64))
            {
                pi.SetValue(obj, CommOp.ToLong(value), null);
            }
            else if (pi.PropertyType == typeof(Int16))
            {
                pi.SetValue(obj, (short)CommOp.ToInt(value), null);
            }
            else if (pi.PropertyType == typeof(int?))
            {
                pi.SetValue(obj, CommOp.ToIntNull(value), null);
            }
            else if (pi.PropertyType == typeof(bool))
            {
                pi.SetValue(obj, CommOp.ToBool(value), null);
            }
            else if (pi.PropertyType == typeof(bool?))
            {
                pi.SetValue(obj, CommOp.ToBoolNull(value), null);
            }
            else if (pi.PropertyType == typeof(char))
            {
                pi.SetValue(obj, CommOp.ToChar(value), null);
            }
            else if (pi.PropertyType == typeof(double) || pi.PropertyType == typeof(float))
            {
                pi.SetValue(obj, CommOp.ToDouble(value), null);
            }
            else if (pi.PropertyType == typeof(decimal))
            {
                pi.SetValue(obj, CommOp.ToDecimal(value), null);
            }
            else if (pi.PropertyType.IsEnum)
            {
                if (CommOp.IsNumeric(value))
                {
                    var val = CommOp.ToInt(value);
                    if (pi.PropertyType.IsEnumDefined(val))
                    {
                        pi.SetValue(obj, Enum.Parse(pi.PropertyType, val.ToString()), null);
                    }
                }
                else
                {
                    var val = CommOp.ToStr(value);
                    if (pi.PropertyType.IsEnumDefined(val))
                    {
                        pi.SetValue(obj, Enum.Parse(pi.PropertyType, val), null);
                    }
                }
            }
            else if (pi.PropertyType == typeof(DateTime))
            {
                DateTime dt = CommOp.ToDateTime(value);
                if (dt == default(DateTime))
                {
                    return;
                }
                pi.SetValue(obj, dt, null);
            }
            else if (pi.PropertyType == typeof(DateTime?))
            {
                DateTime?dt = CommOp.ToDateTimeNull(value);
                pi.SetValue(obj, dt, null);
            }
            else
            {
                actualType = actualType ?? pi.PropertyType;
                var p = JsonHelper.FormJson(value, actualType) ?? Activator.CreateInstance(actualType);
                try
                {
                    pi.SetValue(obj, p, null);
                }
                catch
                {
                    throw;
                }
            }
        }