public bool Update(SystemDictionary model, List <string> fileds, string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.AppendFormat("update {0} set ", model.GetType().Name);
            List <string>       filedsList   = new List <string>();
            List <SqlParameter> sqlParameter = new List <SqlParameter>();
            SqlParameter        Param        = new SqlParameter("@ID", SqlDbType.Int, 4);

            if (string.IsNullOrEmpty(sqlWhere))
            {
                Param.Value = model.ID;
                sqlParameter.Add(Param);
            }
            foreach (string filed in fileds)
            {
                filedsList.Add(string.Format("{0}=@{0}", filed));
                Param = new SqlParameter(string.Format("@{0}", filed), model.GetType().GetProperty(filed).GetValue(model, null));
                sqlParameter.Add(Param);
            }
            strSql.AppendFormat("{0}", string.Join(",", filedsList.ToArray()));
            if (string.IsNullOrEmpty(sqlWhere))
            {
                strSql.Append(" where ID=@ID ");
            }
            else
            {
                strSql.AppendFormat(" where 1=1 and {0} ", sqlWhere);
            }
            SqlParameter[] parameters = sqlParameter.ToArray();
            return(sqlhelper.ExecNon(strSql.ToString(), parameters) > 0 ? true : false);
        }
Beispiel #2
0
        private int DoConvert(string sourceFile, string destFile)
        {
            string source = File.ReadAllText(sourceFile);

            string[] lines = source.Split('\n');

            SystemDictionary dict = new SystemDictionary();

            dict.Id = "АДА";

            foreach (string line in lines)
            {
                string[] parts = line.Split('\t');
                if (parts.Length < 2)
                {
                    continue;
                }

                Word w = new Word {
                    TextEn = parts[0], TextRu = parts[1]
                };
                dict.Add(w);
            }

            string jsonData = (dict as ISimpleJsonSerializable).ToJsonString();

            File.WriteAllText(destFile, jsonData);

            return(dict.Count);
        }
        public JsonResult addEditSystemDic(SystemDictionary model, int opType)
        {
            JsonResult result = null;

            try
            {
                BaseResultDto <string> resultDto = new BaseResultDto <string>();
                //添加或者修改
                if (opType == 1)
                {
                    //修改
                    resultDto = HttpHelper.CreatHelper().DoPostObject <BaseResultDto <string> >(string.Format("{0}SysSetting/UpdateDic", this.WebApiUrl), model);
                }
                else if (opType == 2)
                {
                    //添加
                    resultDto = HttpHelper.CreatHelper().DoPostObject <BaseResultDto <string> >(string.Format("{0}SysSetting/AddDic", this.WebApiUrl), model);
                }
                result = Json(new { status = resultDto.ErrorCode, message = resultDto.ErrorMsg }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                result = Json(new { status = -1, message = ex.Message }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }
Beispiel #4
0
        public IEnumerable <SystemDictionary> Query()
        {
            string sql = "SELECT [TYPE],[ID],[NAME],[VALUE],[REMARK] FROM [T_SystemDictionary] ORDER BY TYPE";

            using (var dbOperator = new DbOperator(Provider, ConnectionString)) {
                using (var reader = dbOperator.ExecuteReader(sql)) {
                    var result = new List <SystemDictionary>();
                    SystemDictionary dictionary = null;
                    while (reader.Read())
                    {
                        SystemDictionaryType currentType = (SystemDictionaryType)reader.GetInt32(0);
                        if (null == dictionary || dictionary.Type != currentType)
                        {
                            dictionary = new SystemDictionary(currentType);
                            result.Add(dictionary);
                        }
                        dictionary.AddItem(new SystemDictionaryItem(
                                               reader.GetGuid(1),
                                               reader.IsDBNull(2) ? string.Empty : reader.GetString(2),
                                               reader.IsDBNull(3) ? string.Empty : reader.GetString(3),
                                               reader.IsDBNull(4) ? string.Empty : reader.GetString(4)));
                    }
                    return(result);
                }
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(NullableIdInput input)
        {
            SystemDictionary dictionary = new SystemDictionary();

            if (!input.Id.IsNullOrEmptyGuid())
            {
                dictionary = await _systemDictionaryLogic.GetById(input.Id);
            }
            return(View(dictionary));
        }
        public BaseResultDto <string> AddDic(SystemDictionary model)
        {
            BaseResultDto <string> resultDto = new BaseResultDto <string>();

            try
            {
                resultDto.ErrorCode = helper.Add <SystemDictionary>(model);
                resultDto.ErrorMsg  = "添加成功";
            }
            catch (Exception ex)
            {
                resultDto.ErrorCode = -1;
                resultDto.ErrorMsg  = ex.Message;
            }
            return(resultDto);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SystemDictionary GetModel(string where)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ID, DicKey, DicValue, DicType  ");
            strSql.Append("  from SystemDictionary ");
            strSql.Append(" where ");
            strSql.Append(where);



            var dt = sqlhelper.GetTable(strSql.ToString());
            SystemDictionary model = null;

            if (dt.Rows.Count > 0)
            {
                model = Mapper.DynamicMap <IDataReader, List <SystemDictionary> >(dt.CreateDataReader()).FirstOrDefault();
            }
            return(model);
        }
Beispiel #8
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public BusinessBaseViewModel <string> Insert(AddSystemDictionaryRequestModel requestModel)
        {
            var res = new BusinessBaseViewModel <string>()
            {
                Status = ResponseStatus.Fail
            };

            if (requestModel.IsNull())
            {
                res.ErrorMessage = "参数错误";
                return(res);
            }
            if (requestModel.Name.IsNullOrWhiteSpace())
            {
                res.ErrorMessage = "字典名称不能为空";
                return(res);
            }
            var entity = _systemDictionaryRepository.FirstOrDefault(x => x.ParentId == requestModel.ParentId && x.Name == requestModel.Name);

            if (entity != null)
            {
                res.ErrorMessage = $"字典名称[{requestModel.Name}]已存在,不能重复添加";
                return(res);
            }
            var model = new SystemDictionary()
            {
                Name       = requestModel.Name,
                Value      = requestModel.Value,
                ParentId   = requestModel.ParentId,
                Sort       = requestModel.Sort,
                Remark     = requestModel.Remark,
                CreateTime = DateTime.Now,
                ModifyTime = DateTime.Now
            };

            _systemDictionaryRepository.Insert(model);
            _systemDictionaryRepository.SaveChanges();

            res.Status = ResponseStatus.Success;
            return(res);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SystemDictionary model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SystemDictionary(");
            strSql.Append("DicKey,DicValue,DicType");
            strSql.Append(") values (");
            strSql.Append("@DicKey,@DicValue,@DicType");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@DicKey",   SqlDbType.VarChar,  200),
                new SqlParameter("@DicValue", SqlDbType.VarChar, 8000),
                new SqlParameter("@DicType",  SqlDbType.VarChar, 20)
            };

            parameters[0].Value = model.DicKey;
            parameters[1].Value = model.DicValue;
            parameters[2].Value = model.DicType; return(sqlhelper.ExecNon(strSql.ToString(), parameters));
        }
        public BaseResultDto <string> UpdateDic(SystemDictionary model)
        {
            BaseResultDto <string> resultDto = new BaseResultDto <string>();

            try
            {
                //要修改的字段数据
                List <string> fileds = new List <string>();
                fileds.Add("DicKey");
                fileds.Add("DicValue");
                fileds.Add("DicType");
                resultDto.ErrorCode = helper.Update <SystemDictionary>(model, fileds) ? 1 : 0;
                resultDto.ErrorMsg  = "修改成功";
            }
            catch (Exception ex)
            {
                resultDto.ErrorCode = -1;
                resultDto.ErrorMsg  = ex.Message;
            }
            return(resultDto);
        }
Beispiel #11
0
        public IActionResult SaveKeyvalue(int?id, string key, string value)
        {
            var recode = new  SystemDictionary();

            if (id == null)
            {
                recode = new SystemDictionary()
                {
                    AddTime = DateTime.Now, IsSystem = false, KeyName = key, Value = value, SystemDictionarytype = SystemDictionarytype.String
                };
                APPCommon.AppConfig.SystemDictionaries.Add(recode);
                var result = m_codeService.InsertCode <SystemDictionary>(recode);
            }
            else
            {
                //var sd = new SystemDictionary();// { AddTime = DateTime.Now, IsSystem = false, KeyName = key, Value = value, SystemDictionarytype = SystemDictionarytype.String };
                recode = m_codeService.GetSimpleCode <SystemDictionary>(new { Id = id }).FirstOrDefault();
                if (recode == null)
                {
                    recode = new  SystemDictionary()
                    {
                        AddTime = DateTime.Now, IsSystem = false, KeyName = key, Value = value, SystemDictionarytype = SystemDictionarytype.String
                    };
                    APPCommon.AppConfig.SystemDictionaries.Add(recode);
                    var result = m_codeService.InsertCode <SystemDictionary>(recode);
                }
                else
                {
                    recode.KeyName = key;
                    recode.Value   = value;
                    m_codeService.UpdateSimpleCode(recode);
                    var sindex = APPCommon.AppConfig.SystemDictionaries.FindIndex(p => p.Id == recode.Id);
                    APPCommon.AppConfig.SystemDictionaries[sindex].KeyName = key;
                    APPCommon.AppConfig.SystemDictionaries[sindex].Value   = value;
                }
            }


            return(new JsonResult(new { result = recode }));
        }
Beispiel #12
0
        public override ActionResult Index()
        {
            var model = SystemDictionary.GetAll().Select(r => new Tuple <Guid, string, string>(r.Id, r.Key, r.Value)).ToList();

            return(PartialView("_Index", model));
        }
 public async Task <JsonResult> SaveDictionary(SystemDictionary dictionary)
 {
     return(Json(await _dictionaryLogic.SaveDictionary(dictionary)));
 }
Beispiel #14
0
 public async Task <JsonResult> SaveSystemDictionary(SystemDictionary input)
 {
     return(Json(await _systemDictionaryLogic.SaveSystemDictionary(input)));
 }
Beispiel #15
0
 public async Task <JsonResult> SaveDictionary(SystemDictionary dictionary)
 {
     dictionary.CreateUserId   = _currentUser.UserId;
     dictionary.CreateUserName = _currentUser.Name;
     return(Json(await _dictionaryLogic.SaveDictionary(dictionary)));
 }
Beispiel #16
0
 public static IEnumerable <SystemDictionaryKV> Get(string type)
 {
     return(SystemDictionary.Get(type));
 }
Beispiel #17
0
 public static Dictionary <string, List <SystemDictionaryKV> > GetMany(string types)
 {
     return(SystemDictionary.GetMany(types.Split(',', '|', ' ')));
 }