using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text.RegularExpressions;
using MySystem.PxcModels;
using Library;

namespace MySystem
{
    public class PublicFunction
    {
        public static decimal NumberFormat(decimal number, int floatCount = 2)
        {
            string str = number.ToString();
            if (str.Contains("."))
            {
                string[] list = str.Split('.');
                if (list[1].Length > floatCount)
                {
                    str = list[0] + "." + list[1].Substring(0, floatCount);
                }
            }
            else
            {
                str += ".00";
            }
            return decimal.Parse(str);
        }

        public static string GetPublicParam(WebCMSEntities db, string Key)
        {
            CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == Key);
            if(set != null)
            {
                return set.Contents;
            }
            return "";
        }


        #region 发送分表数据

        public static void SplitTradeRecord(TradeRecord obj, string TradeMonth)
        {
            RedisDbconn.Instance.AddList("AddTradeRecordQueue", Newtonsoft.Json.JsonConvert.SerializeObject(obj) + "#cut#" + TradeMonth);
        }

        public static void SplitUserAccountRecord(UserAccountRecord obj, string TradeMonth)
        {
            RedisDbconn.Instance.AddList("AddUserAccountRecordQueue", Newtonsoft.Json.JsonConvert.SerializeObject(obj) + "#cut#" + TradeMonth);
        }

        #endregion
    }
}
