Beispiel #1
0
        static string TABLE_NAME = "NameRuleConfig"; //table name

        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(NameRuleConfig model)
        {
            // Open database (or create if not exits)
            using (var db = new LiteDatabase(LocalConfig.SettingDataFileName))
            {
                // Get DbConnection collection
                var col = db.GetCollection <NameRuleConfig>(TABLE_NAME);

                var value = col.Insert(model);
                return(value.AsInt32);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 按照规则格式化名字
        /// </summary>
        /// <param name="obj">规则对象</param>
        /// <param name="val">结果名字</param>
        /// <returns></returns>
        public static String FormatName(NameRuleConfig obj, String val)
        {
            if (obj == null || String.IsNullOrEmpty(val))
            {
                return(val);
            }

            // 前缀处理
            var prefix = String.Empty;

            if (obj.PrefixList != null && obj.PrefixList.Count > 0)
            {
                foreach (var item in obj.PrefixList)
                {
                    if (val.StartsWith(item.OriginValue))
                    {
                        prefix = item.NewValue;
                        val    = val.Substring(item.OriginValue.Length);
                        break;
                    }
                }
            }

            // 后缀处理
            var stuffix = String.Empty;

            if (obj.StuffixList != null && obj.StuffixList.Count > 0)
            {
                foreach (var item in obj.StuffixList)
                {
                    if (val.EndsWith(item.OriginValue))
                    {
                        stuffix = item.NewValue;
                        val     = val.Substring(0, val.Length - item.OriginValue.Length);
                        break;
                    }
                }
            }

            // 转换为正式的名字
            if (String.IsNullOrWhiteSpace(obj.Seperator) == false)
            {
                val = StringUtil.ToPascalName(val, obj.Seperator);
            }
            val = $"{prefix.FirstUpper()}{val}{stuffix.FirstUpper()}";

            //// 首字母大小写处理
            if (String.IsNullOrWhiteSpace(val) == false)
            {
                switch (obj.FirstCharHandleType)
                {
                case FirstCharHandleType.FirstCharLower:
                    val = StringUtil.FirstLower(val);
                    break;

                case FirstCharHandleType.FirstCharUp:
                    val = StringUtil.FirstUpper(val);
                    break;
                }
            }

            return(val);
        }
Beispiel #3
0
 /// <summary>
 /// 保存数据
 /// </summary>
 public void Insert(NameRuleConfig model)
 {
     dalObj.Insert(model);
     this.data.Add(model);
 }
Beispiel #4
0
 /// <summary>
 /// 保存数据
 /// </summary>
 public void Save(NameRuleConfig model)
 {
     dalObj.Update(model);
 }
Beispiel #5
0
 /// <summary>
 /// Update
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(NameRuleConfig model)
 {
     return(LiteDBHelper <NameRuleConfig> .Update(LocalConfig.SettingDataFileName, model, TABLE_NAME));
 }