コード例 #1
0
 /// <summary>
 /// 使用多语言版本显示信息
 /// </summary>
 /// <param name="type">error,warning,success中的一个</param>
 /// <param name="message">信息内容的多语言Key</param>
 /// <param name="returnValue">附加的对象数据</param>
 /// <param name="formatArgs">以messageKey作为格式化字符串的格式化参数</param>
 /// <returns>Json序列化后的ReturnValueWithTips对象</returns>
 protected JsonResult JsonTipsLang(string type, string messageKey, object returnValue = null, params string[] formatArgs)
 {
     Tips.Type        = type;
     Tips.Message    += String.Format(ResHelper.GetStr(messageKey), formatArgs);
     Tips.ReturnValue = returnValue;
     return(Json(Tips));
 }
コード例 #2
0
        public virtual ActionResult Copy(TKey id)
        {
            var t = GetCurrentModel(id);

            t.Id = default(TKey);
            BeforeShowing(t);
            Session[_modelSessionKey] = t;
            return(JsonTips("success", ResHelper.GetStr("Copy_Success"), (object)JsonHelper.ToJson(t, true)));
        }
コード例 #3
0
        /// <summary>
        /// 获取系统所有定义过的语言Key供Menu菜单选择它的Name
        /// </summary>
        /// <returns></returns>
        public JsonResult GetResKeys()
        {
            var keys = ResHelper.GetAllResourceKeys();

            return(Json(keys.OrderBy(k => k)
                        .Select(k => new
            {
                id = k,
                text = ResHelper.GetStr(k)
            }), JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
 private WidgetModel ConvertToWidget(AppFunction func, WidgetModel userWidget)
 {
     userWidget.Id    = func.Id;
     userWidget.Title = ResHelper.GetStr(func.Name);
     //将参数赋值给其他可能的属性
     foreach (var p in func.Arguments)
     {
         RefHelper.SetValue(userWidget, p.Key, p.Value);
     }
     return(userWidget);
 }
コード例 #5
0
        /// <summary>
        /// 返回列表页视图,一般情况下不需要重写此方法
        /// </summary>
        /// <returns></returns>
        public virtual ActionResult Index()
        {
            ViewBag.QueryType       = typeof(TModel);
            ViewBag.SearchEmptyText = ResHelper.GetStr("Enter_Keyword");

            if (!Function.HasChildren() && !Function.Id.IsEmpty())
            {
                //当没有为Index或Edit配置按钮时,添加一些默认按钮
                CreateDefaultChildren();
                ViewBag.ReloadMenu = true;
            }
            return(View(typeof(TModel)));
        }
コード例 #6
0
        public virtual ActionResult Edit(TModel t)
        {
            if (Strict && !ModelState.IsValid)
            {
                return(JsonTips());
            }
            var modelRule = ModelRule.Get <TModel>();

            if (!t.Id.IsDefault()) //在修改操作时,复制原有对象集合到新对象的集合
            {
                var oldt = GetCurrentModel(t.Id);
                foreach (var collrule in modelRule.CollectionRules)
                {
                    collrule.Attr.Property.SetValue(t, modelRule.GetCollectionValue(oldt, collrule.Name), null);
                }
            }
            MethodInfo mi = this.GetType().GetMethod("SaveDetails", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod);

            foreach (ModelRule rule in modelRule.CollectionRules)
            {
                var gmi = mi.MakeGenericMethod(rule.ModelType);
                gmi.Invoke(this, new object[] { t, rule.Name });
            }
            if (!BeforeSaving(t))
            {
                return(JsonTips());
            }

            if (t.Id.IsDefault())
            {
                DataService.Add(t);
                AfterSaved(t);
                t = DataService.GetByKey(t.Id);
                BeforeShowing(t);
                Session[_modelSessionKey] = t;
                return(JsonTips("success", ResHelper.GetStr("Create_Success"), (object)JsonHelper.ToJson(t, true)));
            }
            else
            {
                var id = DataService.Change(t);
                AfterSaved(t);
                t = DataService.GetByKey(t.Id);
                BeforeShowing(t);
                Session[_modelSessionKey] = t;
                return(JsonTips("success", ResHelper.GetStr("Update_Success"), (object)JsonHelper.ToJson(t, true)));
            }
        }
コード例 #7
0
        /// <summary>
        /// 将对象型数据导入到excel中, wang
        /// </summary>
        /// <param name="data">要导入的数据</param>
        /// <param name="isColumnWritten">DataTable的列名是否要导入</param>
        /// <param name="sheetName">要导入的excel的sheet的名称</param>
        /// <returns>导入数据行数(包含列名那一行)</returns>
        public int ObjectToExcel <T>(IEnumerable <T> data, string sheetName, bool isColumnWritten)
        {
            int    i     = 0;
            int    j     = 0;
            int    count = 0;
            ISheet sheet = null;

            sheet = workbook.GetSheet(sheetName) ?? workbook.CreateSheet(sheetName);
            var props = RefHelper.GetElementType(data).GetProperties();

            if (isColumnWritten == true) //写入DataTable的列名
            {
                IRow row = sheet.CreateRow(0);
                for (j = 0; j < props.Length; ++j)
                {
                    row.CreateCell(j).SetCellValue(ResHelper.GetStr(props[j].Name));
                }
                count = 1;
            }
            else
            {
                count = 0;
            }

            for (j = 0; j < data.Count(); ++j)
            {
                var  element = data.ElementAt(j);
                IRow row     = sheet.CreateRow(count);
                for (i = 0; i < props.Length; ++i)
                {
                    ICell  cell = row.CreateCell(i);
                    object val  = props[i].GetValue(element, null);
                    SetCellValue(cell, val);
                }
                count++;
            }
            workbook.Write(_innerStream); //写入到excel
            _innerStream.Close();
            _innerStream = null;

            return(count);
        }
コード例 #8
0
        public virtual JsonResult GetUserMenu()
        {
            var userMenu = CurrentUser == null ? null : new
            {
                UserMenu = AppManager.Instance.GetUserMenus(User.Identity.Name)
                           .Select(func => new
                {
                    Id           = func.Id,
                    ParentId     = func.ParentId,
                    Name         = ResHelper.GetStr(func.Name),
                    IconLocation = func.IconLocation,
                    IconClass    = func.IconClass,
                    Location     = func.Location.IsEmpty() ? null : Url.Content(func.Location),
                    Method       = func.Method,
                    Visible      = func.Visible
                }),
                ForbiddenIds = User.Identity.GetForbiddenIds()
            };

            return(Json(userMenu, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public virtual LoginState SendPasswordResetMessage(string userName, string email, string resetUrl)
        {
            var _context = new ModelContext();

            MemberShip member = _context.Set <MemberShip>().FirstOrDefault(m => m.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) && m.IsConfirmed == true);

            if (member == null)
            {
                return(LoginState.UserNotExist);
            }
            if (!member.Email.Equals(email, StringComparison.OrdinalIgnoreCase))
            {
                return(LoginState.EmailError);
            }
            member.ConfirmationToken = CommOp.NewId();
            string url     = resetUrl + "?username="******"&confirmToken=" + member.ConfirmationToken;
            string subject = ResHelper.GetStr("Password+Reset");
            string body    = "<p>" + ResHelper.GetStr("Click the link below to reset your password") + "</p>"
                             + "<p>" + "<a href='" + url + "' target='_blank'>" + url + "</a></p>";
            SMTPMail mail = new SMTPMail(member.Email, subject, body);

            _context.SaveChanges();
            mail.Send();
            if (mail.ErrorMessage.IsEmpty())
            {
                return(LoginState.OK);
            }
            else
            {
#if DEBUG
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Session["ResetPasswordEmailBody"] = body;
                }
#endif
                return(LoginState.EmailSendError);
            }
        }
コード例 #10
0
 public virtual ActionResult Delete(string ids)
 {
     string[] idArr = ids.Split(',');
     DataService.DeleteByKeys(idArr);
     return(JsonTips("success", ResHelper.GetStr("Delete_Success")));
 }
コード例 #11
0
 /// <summary>
 /// 输出有HTML标记的资源字符串
 /// </summary>
 /// <param name="htmlHelper">HTMLhelper 帮助类实例.</param>
 /// <param name="name">资源名称</param>
 /// <param name="defaultValue">没有此资源的默认值</param>
 /// <returns>带HTML标记的资源字符串</returns>
 public static MvcHtmlString RawStr(this HtmlHelper htmlHelper, string name, string defaultValue = null)
 {
     return(new MvcHtmlString(ResHelper.GetStr(name, defaultValue)));
 }
コード例 #12
0
 /// <summary>
 /// 获取某个枚举类型的枚举名称对应的多语言Key值
 /// </summary>
 /// <param name="enumType">枚举类型</param>
 /// <param name="valueName">该类型上的枚举名称</param>
 /// <returns>Key值: Enum.枚举类型名称.值名称</returns>
 public static string GetEnumResKey(this Type enumType, string valueName)
 {
     return(ResHelper.GetStr("Enum." + enumType.Name + "." + valueName, valueName));
 }
コード例 #13
0
 /// <summary>
 /// 编码输出资源字符串
 /// </summary>
 /// <param name="htmlHelper">HTMLhelper 帮助类实例.</param>
 /// <param name="name">资源名称</param>
 /// <param name="defaultValue">没有此资源的默认值</param>
 /// <returns>资源字符串</returns>
 public static String Str(this HtmlHelper htmlHelper, string name, string defaultValue = null)
 {
     return(ResHelper.GetStr(name, defaultValue));
 }
コード例 #14
0
 public JException(string message)
     : base(ResHelper.GetStr(message))
 {
 }
コード例 #15
0
 public JException(Exception ex)
     : base(ResHelper.GetStr(ex.Message), ex)
 {
 }