Exemplo n.º 1
0
 public static void DumpTsxSym(this tsEntities db, string fileName)
 {
     foreach (var r in db.t_s.OrderBy(a => a.root__ticker))
     {
         if (r.Name.Trim() != string.Empty)
         {
             File.AppendAllText(fileName, r.root__ticker + "-T,");
         }
     }
 }
Exemplo n.º 2
0
 public static void DumpSym(this tsEntities db, string fileName)
 {
     foreach (var r in db.prs.OrderBy(a => a.ex).ThenBy(a => a.rt))
     {
         if (r.rt.Trim() != string.Empty)
         {
             File.AppendAllText(fileName, r.rt.Trim() + "-" + r.ex_short.Trim() + ",");
         }
     }
     Debug.WriteLine("Done!.");
 }
Exemplo n.º 3
0
        /// <summary>
        /// 加载包厢与订单关系
        /// </summary>
        /// <param name="ctx"></param>
        private void LoadRoomsOrders(tsEntities ctx)
        {
            Resources.GetRes().ROOMS_Model = new List <RoomModel>();

            long time = long.Parse(DateTime.Now.AddYears(-1).ToString("yyyyMMddHHmmss"));

            //加载订单及订单详细

            foreach (var item in Resources.GetRes().ROOMS.Where(x => x.HideType == 0))
            {
                Resources.GetRes().ROOMS_Model.Add(new RoomModel()
                {
                    HideType = item.HideType, Order = item.Order, RoomId = item.RoomId, RoomNo = item.RoomNo, PayOrder = ctx.Orders.Include("tb_orderdetail").Include("tb_orderpay").Where(x => x.AddTime > time && x.RoomId == item.RoomId && x.State == 0).FirstOrDefault(), OrderSession = Guid.NewGuid().ToString()
                });
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 记录
        /// </summary>
        /// <param name="IsAuto"></param>
        internal void RecordAll(bool IsAuto = false)
        {
            try
            {
                lock (AccessLogs)
                {
                    if (AccessLogs.Count > 0 && DBOperate.GetDBOperate().IsDataReady)
                    {
                        int successSaveCount = 0;
                        using (tsEntities ctx = new tsEntities(DBOperate.GetDBOperate().CONS, false))
                        {
                            ctx.Configuration.ProxyCreationEnabled = false;
                            ((IObjectContextAdapter)ctx).ObjectContext.CommandTimeout = Resources.GetRes().TIME_OUT_SHORT;//无用

                            TransactionOptions option = new TransactionOptions();
                            option.Timeout = TimeSpan.FromSeconds(Resources.GetRes().TIME_OUT_SHORT);//无用
                            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option, EnterpriseServicesInteropOption.Automatic))
                            {
                                ctx.Configuration.AutoDetectChangesEnabled = false;
                                ctx.Configuration.ValidateOnSaveEnabled    = false;

                                foreach (var item in AccessLogs)
                                {
                                    ctx.Logs.Add(item);
                                }

                                successSaveCount = ctx.SaveChanges();
                                scope.Complete();
                            }

                            AccessLogs.Clear();
                        }
                    }

                    NextCheck = DateTime.Now.AddMinutes(5);
                }
            }
            catch (Exception ex)
            {
                ExceptionPro.ExpLog(ex);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 加载供应商
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadSupplier(tsEntities ctx)
 {
     Resources.GetRes().SUPPLIERS = ctx.Suppliers.ToList();
 }
Exemplo n.º 6
0
 /// <summary>
 /// 加载会员
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadMember(tsEntities ctx)
 {
     Resources.GetRes().MEMBERS = ctx.Members.ToList();
 }
Exemplo n.º 7
0
 /// <summary>
 /// 加载管理员
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadAdmin(tsEntities ctx)
 {
     Resources.GetRes().ADMINS = ctx.Admins.ToList();
 }
Exemplo n.º 8
0
        /// <summary>
        /// 加载余额
        /// </summary>
        /// <param name="ctx"></param>
        private void LoadBalance(tsEntities ctx)
        {
            Resources.GetRes().BALANCES = ctx.Balances.ToList();

            OperateLog.Instance.RefreshBalanceHash();
        }
Exemplo n.º 9
0
 /// <summary>
 /// 加载请求
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadRequests(tsEntities ctx)
 {
     Resources.GetRes().REQUESTS = ctx.Requests.ToList();
 }
Exemplo n.º 10
0
        /// <summary>
        /// 加载缓存
        /// </summary>
        internal void LoadCache(bool LazyLoadingEnabled = true, bool PrepareData = true)
        {
            try
            {
                // 先获取Database表并升级
                Database database = null;
                using (var ctx = new tsEntities(CONS, false))
                {
                    ctx.Configuration.ProxyCreationEnabled = false;
                    ctx.Configuration.LazyLoadingEnabled   = false;
                    database = ctx.Databases.FirstOrDefault();
                }

                // 升级数据库
                DBUpdate.Instance.UpdateDatabase(database);


                // 获取数据
                using (var ctx = new tsEntities(CONS, false))
                {
                    ctx.Configuration.ProxyCreationEnabled = false;
                    ctx.Configuration.LazyLoadingEnabled   = false;


                    //加载包厢
                    LoadRooms(ctx);
                    //加载包厢(用来控制) 和 菜单(如果开启了菜单)
                    LoadRoomsOrders(ctx);

                    //加载外卖
                    LoadTakeouts(ctx);

                    // 加载产品和产品类型
                    LoadProductTypes(ctx);
                    LoadProducts(ctx);

                    // 加载管理员
                    LoadAdmin(ctx);
                    // 加载会员
                    LoadMember(ctx);
                    // 加载供应商
                    LoadSupplier(ctx);
                    // 加载设备
                    LoadDevices(ctx);
                    // 加载请求
                    LoadRequests(ctx);

                    // 加载打印机和打印机绑定
                    LoadPrinters(ctx);
                    LoadPprs(ctx, PrepareData);

                    // 加载余额
                    LoadBalance(ctx);
                }

                IsDataReady = true;
            }
            catch (Exception ex)
            {
                IsNotSuccessLoadData = true;
                throw new OybabException("Exception_LoadCacheError: ", ex);
            }
        }
Exemplo n.º 11
0
        public static bool PopulateNewFromFile(this tsEntities db, string fileName)
        {
            try
            {
                string[] lines = File.ReadAllLines(fileName);

                Debug.WriteLine(fileName);
                for (int i = 0; i < lines.Length; i++)
                {
                    Debug.WriteLine(i.ToString() + lines[i]);
                    if (lines[i].Trim().Contains("-"))
                    {
                        pr       a  = new pr();
                        string[] sy = lines[i].Split('-');
                        a.rt = sy[0].Trim();

                        if (a.rt.Trim() == string.Empty)
                        {
                            int lll = 0;
                        }
                        a.ex = sy[1].Trim();
                        i++; i++;

                        double pr = 0;
                        if (!double.TryParse(lines[i], out pr))
                        {
                            pr = 0;
                        }
                        a.price = pr;
                        i++;

                        double daily_ch = 0;
                        if (!double.TryParse(lines[i], out daily_ch))
                        {
                            daily_ch = 0;
                        }
                        a.daily_change = daily_ch;
                        i++;

                        double lt     = 0;
                        string newVal = lines[i].Replace('%', ' ').Trim();
                        if (!double.TryParse(newVal, out lt))
                        {
                            lt = 0;
                        }
                        a.per_dayly_change = lt;
                        i++;

                        if (!lines[i].Contains('.'))
                        {
                            double v = 0;
                            if (!double.TryParse(lines[i], out v))
                            {
                                v = 0;
                            }
                            a.vol = (long)v;
                            i++;
                        }
                        else
                        {
                            Debug.WriteLine("no vol");
                        }

                        double high = 0;
                        if (!double.TryParse(lines[i], out high))
                        {
                            high = 0;
                        }
                        a.week_52_h = high;
                        i++;

                        double low = 0;
                        if (!double.TryParse(lines[i], out low))
                        {
                            low = 0;
                        }
                        a.week_52_l = low;
                        i++;

                        a.timestamp = DateTime.UtcNow;

                        if (i < lines.Length && lines[i].Contains("-") && !lines[i].Contains('|'))
                        {
                            i--;
                        }

                        // a.mdt = mdt;
                        try
                        {
                            pr ad = db.prs.SingleOrDefault(p1 => (p1.rt.Trim() == a.rt.Trim() && p1.ex.Trim() == a.ex.Trim()));
                            if (ad == null)
                            {
                                db.prs.Add(a);
                                db.SaveChanges();
                                db.RefreshDatabase(a);
                                Debug.WriteLine(">> " + a.rt + " - " + a.ex);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }



            return(true);
        }
Exemplo n.º 12
0
        public static bool PopulatePerFromFile(this tsEntities db, string fileName)
        {
            try
            {
                string[] lines = File.ReadAllLines(fileName);

                Debug.WriteLine(fileName);
                for (int i = 0; i < lines.Length; i++)
                {
                    Debug.WriteLine(i.ToString() + lines[i]);
                    if (lines[i].Trim().Contains("-"))
                    {
                        per      a  = new per();
                        string[] sy = lines[i].Split('-');
                        a.rt = sy[0].Trim();
                        a.ex = sy[1].Trim();
                        i++; i++;

                        if (a.rt.Trim().ToLower() == "")
                        {
                            int iii = 0;
                        }

                        bool   skipPr = false;
                        double pr     = 0;
                        if (!double.TryParse(lines[i], out pr))
                        {
                            pr = 0;
                            i--;
                            skipPr = true;
                        }
                        i++;

                        pr p = new pr();
                        p.rt    = a.rt;
                        p.ex    = a.ex;
                        p.price = pr;

                        if (skipPr)
                        {
                            try
                            {
                                pr pd = db.prs.SingleOrDefault(p1 => (p1.rt.Trim() == p.rt.Trim() && p1.ex.Trim() == p.ex.Trim()));
                                if (pd == null)
                                {
                                    db.prs.Add(p);
                                    db.SaveChanges();
                                    db.RefreshDatabase(p);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.ToString());
                            }
                        }

                        double ht = 0;
                        lines[i] = lines[i].Replace("%", "0");
                        if (!double.TryParse(lines[i], out ht))
                        {
                            ht = 0;
                        }
                        i++;
                        a.ytd = ht;

                        double lt = 0;
                        lines[i] = lines[i].Replace("%", "0");
                        if (!double.TryParse(lines[i], out lt))
                        {
                            lt = 0;
                        }
                        i++;
                        a.five_day = lt;

                        double oneM = 0;
                        lines[i] = lines[i].Replace("%", "0");
                        if (!double.TryParse(lines[i], out oneM))
                        {
                            oneM = 0;
                        }
                        i++;
                        a.one_month = oneM;

                        double threeM = 0;
                        lines[i] = lines[i].Replace("%", "0");
                        if (!double.TryParse(lines[i], out threeM))
                        {
                            threeM = 0;
                        }
                        i++;
                        a.three_month = threeM;

                        double oneY = 0;
                        lines[i] = lines[i].Replace("%", "0");
                        if (!double.TryParse(lines[i], out oneY))
                        {
                            oneY = 0;
                        }
                        a.one_year = oneY;

                        try
                        {
                            per ad = db.pers.SingleOrDefault(p1 => (p1.rt.Trim() == p.rt.Trim() && p1.ex.Trim() == p.ex.Trim()));
                            if (ad == null)
                            {
                                db.pers.Add(a);
                                db.SaveChanges();
                                db.RefreshDatabase(a);
                            }
                            else
                            {
                                ad.ytd         = a.ytd;
                                ad.five_day    = a.five_day;
                                ad.one_month   = a.one_month;
                                ad.three_month = a.three_month;
                                ad.one_year    = a.one_year;
                                db.SaveChanges();
                                db.RefreshDatabase(ad);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return(true);
        }
Exemplo n.º 13
0
        public static void TransferVxToT(this tsEntities db)
        {
            foreach (var r in db.t_x.OrderBy(a => a.Root_Ticker).ToList())
            {
                try
                {
                    t_s tt = new t_s();
                    tt.AFRICA                = r.AFRICA;
                    tt.asia_region           = r.Asia_Region;
                    tt.AUS_NZ_PNG            = r.AUS_NZ_PNG;
                    tt.base__precious_metals = r.base__precious_metals;
                    tt.CANADA                = r.CANADA;
                    tt.CHINA__ASIA           = r.CHINA__ASIA;
                    tt.clean_tech_primary    = r.clean_tech_primary;
                    tt.clean_tech_sub_sector = r.clean_tech_sub_sector;
                    tt.Coal   = r.Coal;
                    tt.Copper = r.Copper;
                    tt.Co_ID  = r.Co_ID;
                    tt.cps    = r.cps;
                    tt.date_of_amalgamation = r.Date_of_amalgamation;
                    tt.date_of_listing      = r.date_of_listing;
                    tt.Diamond                   = r.Diamond;
                    tt.Exchange                  = r.Exchange;
                    tt.former_cpc                = r.formar_cpc_or_cpc;
                    tt.Gold                      = r.Gold;
                    tt.hq_location               = r.hq_location;
                    tt.hq_region                 = r.hq_region;
                    tt.Index                     = r.Index;
                    tt.interlisted               = r.Interlisted;
                    tt.Iron                      = r.Iron;
                    tt.LATIN_AMERICA             = r.LATIN_AMERICA;
                    tt.Lead                      = r.Lead;
                    tt.Lithium                   = r.Lithium;
                    tt.mineral_properties        = r.mineral_properties;
                    tt.Molybdenum                = r.Molybdenum;
                    tt.Name                      = r.Name;
                    tt.Nickel                    = r.Nickel;
                    tt.num_of_month_trading_data = r.num_of_month_trading_data;
                    tt.num_traded_share_ytd      = r.num_traded_share_ytd;
                    tt.Oil_Gas                   = r.Oil_Gas;
                    tt.OS_Shares                 = r.OS_Shares;
                    tt.OTHER                     = r.OTHER;
                    tt.other_properties          = r.other_properties;
                    tt.Platinum_PGM              = r.Platinum_PGM;
                    tt.Potash                    = r.Potash;
                    tt.QMV                   = r.qmv;
                    tt.qt_date               = r.QT_Date;
                    tt.Rare_Earths           = r.Rare_Earths;
                    tt.re                    = r.re;
                    tt.root__ticker          = r.Root_Ticker;
                    tt.rto_date              = r.RTO_Date;
                    tt.section               = r.Section;
                    tt.Sector                = r.Sector;
                    tt.Silver                = r.Silver;
                    tt.Sub_Sector            = r.Sub_Sector;
                    tt.technology_sub_sector = r.tech_sub_sec;
                    tt.trust                 = r.trust;
                    tt.Tungsten              = r.Tungsten;
                    tt.type_of_listing       = r.type_of_listing;
                    tt.UK_EUROPE             = r.UK_EUROPE;
                    tt.Uranium               = r.Uranium;
                    tt.USA                   = r.USA;
                    tt.usa_city              = r.usa_city;
                    tt.USA_State             = r.USA_State;
                    tt.value__ytd            = r.value__ytd;
                    tt.ven_50_2018           = r.Ven_50_2018;
                    tt.volume_ytd            = r.volume_ytd;
                    tt.Zinc                  = r.Zinc;

                    db.t_s.Add(tt);
                    db.SaveChanges();
                    db.RefreshDatabase(tt);

                    Debug.WriteLine(">> " + tt.root__ticker + " - " + tt.Name);
                }
                catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
            }
        }
Exemplo n.º 14
0
 public static void RefreshDatabase(this tsEntities db, Object entity)
 {
     ((IObjectContextAdapter)db)
     .ObjectContext
     .Refresh(RefreshMode.StoreWins, entity);
 }
Exemplo n.º 15
0
        public static void ImportNYSESymbols(this tsEntities db, string v, string Ex, long seedValue, char deli = ',')
        {
            string[] stLines = File.ReadAllLines(v);
            long     pKey    = seedValue;

            foreach (string st in stLines)
            {
                string[] stl = st.Split(deli);
                t_s      ts  = new t_s();
                ts.pKey         = pKey++;
                ts.root__ticker = stl[0].Trim();
                ts.Name         = stl[1].Trim();
                ts.Exchange     = Ex;

                double price = 0;
                if (!double.TryParse(stl[2], out price))
                {
                    price = 0;
                }

                pr p = new pr();
                p.rt    = stl[0].Trim();
                p.ex    = Ex.Trim();
                p.price = price;

                try
                {
                    pr pd = db.prs.SingleOrDefault(p1 => (p1.rt.Trim() == p.rt.Trim() && p1.ex.Trim() == p.ex.Trim()));
                    if (pd == null)
                    {
                        db.prs.Add(p);
                        db.SaveChanges();
                        db.RefreshDatabase(p);
                    }
                    else
                    {
                        pd.price = p.price;
                        db.SaveChanges();
                        db.RefreshDatabase(pd);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }

                ts.QMV        = stl[3].Trim();
                ts.Sector     = stl[6].Trim();
                ts.Sub_Sector = stl[7].Trim();

                try
                {
                    t_s ad = db.t_s.SingleOrDefault(p1 => (p1.root__ticker.Trim() == ts.root__ticker.Trim() && p1.Exchange.Trim() == ts.Exchange.Trim()));
                    if (ad == null)
                    {
                        ts.Co_ID = ts.pKey.ToString();
                        db.t_s.Add(ts);
                        db.SaveChanges();
                        db.RefreshDatabase(ts);
                        Debug.WriteLine(ts.root__ticker.ToString() + " - " + ts.Name.ToString());
                    }
                    else
                    {
                        ad.Name       = ts.Name;
                        ad.QMV        = ts.QMV;
                        ad.Sector     = ts.Sector;
                        ad.Sub_Sector = ts.Sub_Sector;
                        db.SaveChanges();
                        db.RefreshDatabase(ad);
                        Debug.WriteLine("update >>> " + ts.root__ticker.ToString() + " - " + ts.Name.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// 加载设备
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadDevices(tsEntities ctx)
 {
     Resources.GetRes().DEVICES = ctx.Devices.ToList();
 }
Exemplo n.º 17
0
 /// <summary>
 /// 加载打印机
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadPrinters(tsEntities ctx)
 {
     Resources.GetRes().PRINTERS = ctx.Printers.ToList();
 }
Exemplo n.º 18
0
 /// <summary>
 /// 加载包厢
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadRooms(tsEntities ctx)
 {
     Resources.GetRes().ROOMS = ctx.Rooms.ToList();
 }
Exemplo n.º 19
0
 /// <summary>
 /// 加载打印机和产品打印绑定
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadPprs(tsEntities ctx, bool PrepareData)
 {
     Resources.GetRes().PPRS = ctx.Pprs.ToList();
 }
Exemplo n.º 20
0
 /// <summary>
 /// 获取外卖
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadTakeouts(tsEntities ctx)
 {
     Resources.GetRes().TAKEOUT_Model = new List <TakeoutModel>();
 }
Exemplo n.º 21
0
 /// <summary>
 /// 加载产品
 /// </summary>
 /// <param name="ctx"></param>
 private void LoadProducts(tsEntities ctx)
 {
     Resources.GetRes().PRODUCTS = ctx.Products.ToList();
 }
Exemplo n.º 22
0
        public static bool PopulateArFromFile(this tsEntities db, string fileName)
        {
            try
            {
                string[] lines = File.ReadAllLines(fileName);

                Debug.WriteLine(fileName);
                for (int i = 0; i < lines.Length; i++)
                {
                    Debug.WriteLine(i.ToString() + lines[i]);
                    if (lines[i].Trim().Contains("-"))
                    {
                        ar       a  = new ar();
                        string[] sy = lines[i].Split('-');
                        a.rt = sy[0].Trim();

                        if (a.rt.Trim() == string.Empty)
                        {
                            int lll = 0;
                        }
                        a.ex = sy[1].Trim();
                        i++; i++;

                        double pr = 0;
                        if (!double.TryParse(lines[i], out pr))
                        {
                            pr = 0;
                        }
                        i++;

                        pr p = new pr();
                        p.rt    = a.rt;
                        p.ex    = a.ex;
                        p.price = pr;

                        try
                        {
                            pr pd = db.prs.SingleOrDefault(p1 => (p1.rt.Trim() == p.rt.Trim() && p1.ex.Trim() == p.ex.Trim()));
                            if (pd == null)
                            {
                                db.prs.Add(p);
                                db.SaveChanges();
                                db.RefreshDatabase(p);
                            }
                            else
                            {
                                //pd.price = p.price;
                                //db.SaveChanges();
                                //db.RefreshDatabase(pd);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }

                        double ht = 0;
                        if (!double.TryParse(lines[i], out ht))
                        {
                            ht = 0;
                        }
                        i++;
                        a.ht = ht;

                        double lt = 0;
                        if (!double.TryParse(lines[i], out lt))
                        {
                            lt = 0;
                        }
                        i++;
                        a.lt = lt;

                        double met = 0;
                        if (!double.TryParse(lines[i], out met))
                        {
                            met = 0;
                        }
                        i++;
                        a.met = met;

                        double mdt = 0;
                        if (!double.TryParse(lines[i], out mdt))
                        {
                            mdt = 0;
                        }

                        a.mdt = mdt;
                        try
                        {
                            ar ad = db.ars.SingleOrDefault(p1 => (p1.rt.Trim() == p.rt.Trim() && p1.ex.Trim() == p.ex.Trim()));
                            if (ad == null)
                            {
                                db.ars.Add(a);
                                db.SaveChanges();
                                db.RefreshDatabase(a);
                            }
                            else
                            {
                                ad.ht  = a.ht;
                                ad.lt  = a.lt;
                                ad.met = a.met;
                                ad.mdt = a.mdt;
                                db.SaveChanges();
                                db.RefreshDatabase(ad);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }



            return(true);
        }