Ejemplo n.º 1
0
        /// <summary>
        /// 获取所有资源的DataTable
        /// 修改时间:2017-01-04,修改人:汪敏
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAll(string key = null)
        {
            //查询关键字放入Session
            Session["LanguageQueryKey"] = !key.IsEmpty() ? key : "";

            DataView dv = ResHelper.MakeDataTable().AsDataView();

            try
            {
                if (!key.IsEmpty())
                {
                    //语言key的过滤条件
                    string condition = String.Format("Key LIKE '%{0}%'", key);

                    //增加每一个语种的过滤
                    foreach (string culture in ResHelper.GetUsedCultureNames())
                    {
                        condition = condition + " or " + String.Format("[" + culture + "] LIKE '%{0}%'", key);
                    }

                    dv.RowFilter = condition;
                }
            }
            catch (Exception ex)
            {
                string errinfo = ex.ToString();
            }

            return(JsonNT(dv.ToTable()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存多语言的文本信息
        /// </summary>
        /// <param name="dataService">当前的数据服务</param>
        /// <param name="e">数据实体对象</param>
        /// <param name="t">业务实体对象</param>
        public void SaveLanguages(EFAuditDataService <TEntity> dataService, TEntity e, TModel t)
        {
            var me = e as IMultiLanguage;

            if (me == null)
            {
                return;
            }
            ModelRule modelRule  = ModelRule.Get <TModel>();
            string    entityType = typeof(TEntity).Name;
            var       langs      = ResHelper.GetUsedCultureNames().Select(l => l.ToLower()).ToArray();

            if (me.LangTexts == null)
            {
                me.LangTexts = dataService.GetContext().Set <Sys_DataLanguage>().Where(d => d.BillId == e.Id && d.BillType == entityType).ToList();
            }
            var sysLangs = me.LangTexts;

            foreach (var rule in modelRule.SingleRules.Where(r => r.DataType == ExtDataType.MultiLanguage))
            {
                //先处理主文本框name不带语言后缀的表单值,表示是当前语言
                string langVal     = HttpContext.Current.Request.Form[rule.Name];
                string currentLang = ResHelper.CurrentCultureName.ToLower();
                var    langEntity  = sysLangs.FirstOrDefault(l => l.Language == currentLang);
                if (langEntity == null)
                {
                    langEntity = new Sys_DataLanguage
                    {
                        BillId   = e.Id,
                        BillType = entityType,
                        Language = currentLang,
                        Name     = rule.Name,
                        Text     = langVal
                    };
                    dataService.MarkState(langEntity, EntityState.Added);
                }

                else if (langVal != langEntity.Text)
                {
                    langEntity.Text = langVal;
                    dataService.MarkState(langEntity, EntityState.Modified);
                }

                RefHelper.SetValue(e, rule.Name, langVal);

                //再处理下拉列表中的文本框name带语言后缀的表单值
                foreach (var lang in langs.Where(l => l != currentLang))
                {
                    langVal    = HttpContext.Current.Request.Form[rule.Name + "-" + lang];
                    langEntity = sysLangs.FirstOrDefault(l => l.Language == lang);
                    if (langEntity == null)
                    {
                        langEntity = new Sys_DataLanguage
                        {
                            BillId   = e.Id,
                            BillType = entityType,
                            Language = lang,
                            Name     = rule.Name,
                            Text     = langVal
                        };
                        dataService.MarkState(langEntity, EntityState.Added);
                    }
                    else if (langVal != langEntity.Text)
                    {
                        langEntity.Text = langVal;
                        dataService.MarkState(langEntity, EntityState.Modified);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult Index(FormCollection form)
        {
            if (ModelState.IsValid)
            {
                //整体提交的数据
                var       data = Request.Form["data"];
                DataTable dt   = JsonHelper.FromJson <DataTable>(data);
                RestoreDataTable(dt);

                //提交的数据要判断key是否空字符串
                bool isKeyNull = true;
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["Key"] == null)
                    {
                        isKeyNull = false;
                        break;
                    }
                    if (dr["Key"].ToString().Trim().Count() == 0)
                    {
                        isKeyNull = false;
                        break;
                    }
                }
                if (isKeyNull == false)
                {
                    return(JsonTipsLang("error", "Language_Key_IsNull"));
                }

                //提交的数据要判断每一个语种数据列是否存在,如果不存在,需要补上
                if (!dt.Columns.Contains("Key"))
                {
                    dt.Columns.Add("Key", typeof(String));
                }
                foreach (string culture in ResHelper.GetUsedCultureNames())
                {
                    if (!dt.Columns.Contains(culture))
                    {
                        dt.Columns.Add(culture, typeof(String));
                    }
                }

                //从Session取查询关键字
                var queryKey = Session["LanguageQueryKey"] as string;
                if (!queryKey.IsEmpty())
                {
                    DataView dv = ResHelper.MakeDataTable().AsDataView();

                    //语言key的过滤条件
                    string condition = String.Format("Key NOT LIKE '%{0}%'", queryKey);
                    //增加每一个语种的过滤
                    foreach (string culture in ResHelper.GetUsedCultureNames())
                    {
                        condition = condition + " and " + String.Format("[" + culture + "] NOT LIKE '%{0}%'", queryKey);
                    }
                    dv.RowFilter = condition;

                    DataTable existeddt = dv.ToTable();
                    //与提交的数据合并
                    foreach (DataRow dr in existeddt.Rows)
                    {
                        dt.Rows.Add(dr.ItemArray);
                    }
                }

                //保存数据
                ResHelper.SaveDataTable(dt);
                return(JsonTipsLang("success", "Resources_Saved"));
            }
            return(JsonTips());
        }
Ejemplo n.º 4
0
        //
        // GET: /AppCenter/Res/

        /// <summary>
        /// 资源管理的首页
        /// </summary>
        /// <returns>首页</returns>
        public ActionResult Index()
        {
            var keys = ResHelper.GetUsedCultureNames();

            return(View(keys));
        }