Esempio n. 1
0
        public static void UpdateAll(List <MagicNumber> ListInstanceData)
        {
            ListInstanceData = CheckInsertAll(ListInstanceData, true);
            if (ListInstanceData.Count < 1)
            {
                return;
            }

            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;
                    foreach (var item in ListInstanceData)
                    {
                        db.Table_Name.Attach(item);
                        db.Entry(item).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), ListInstanceData.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Esempio n. 2
0
        public static void UpdateByInstance(MagicNumber instanceData)
        {
            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    db.Table_Name.Attach(instanceData);
                    db.Entry(instanceData).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), instanceData.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Esempio n. 3
0
        public static void RemoveAll()
        {
            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;

                var query = from b in db.Table_Name
                            orderby b.Symbol
                            select b;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;
                    foreach (var item in query)
                    {
                        db.Table_Name.Attach(item);
                        db.Entry(item).State = EntityState.Deleted;
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), query.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Esempio n. 4
0
        public static MagicNumber GetByKey(string key)
        {
            MagicNumber magicNumber = new MagicNumber();

            using (var db = new MagicNumberContext())
            {
                magicNumber = db.Table_Name.FirstOrDefault(x => x.Symbol.Equals(key));
            }
            return(magicNumber);
        }
Esempio n. 5
0
 public static void AddInstance(MagicNumber instanceData)
 {
     using (var db = new MagicNumberContext())
     {
         try
         {
             db.Table_Name.Add(instanceData);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             DateTime localDate   = DateTime.Now;
             string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), instanceData.ToString());
             PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
         }
     }
 }
Esempio n. 6
0
        public static List <MagicNumber> GetAll()
        {
            List <MagicNumber> magicNumbers = new List <MagicNumber>();

            using (var db = new MagicNumberContext())
            {
                var query = from b in db.Table_Name
                            orderby b.Symbol
                            select b;

                foreach (var item in query)
                {
                    magicNumbers.Add(item);
                }
            }
            return(magicNumbers);
        }
Esempio n. 7
0
        public static List <MagicNumber> GetSellWaitingTimeList()
        {
            List <MagicNumber> magicNumbers = new List <MagicNumber>();

            using (var db = new MagicNumberContext())
            {
                var query = from b in db.Table_Name
                            where (b.Sell.NumSuccess > 0 || b.Sell.NumUnSuccess > 0)
                            where b.Sell.IsArbitrageSymbol == false
                            select b;

                foreach (var item in query)
                {
                    magicNumbers.Add(item);
                }
            }
            return(magicNumbers);
        }
Esempio n. 8
0
        public static MagicNumber GetByInstance(MagicNumber instanceData)
        {
            using (var db = new MagicNumberContext())
            {
                var query = from b in db.Table_Name
                            orderby b.Symbol
                            select b;

                foreach (var item in query)
                {
                    if (item.Symbol == instanceData.Symbol)
                    {
                        return(item);
                    }
                }
            }
            return(null);
        }
Esempio n. 9
0
        public static void RemoveByInstance(MagicNumber instanceData)
        {
            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    db.Table_Name.Attach(instanceData);
                    db.Entry(instanceData).State = EntityState.Deleted;
                    db.SaveChanges();
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Esempio n. 10
0
        public static List <MagicNumber> CheckInsertAll(List <MagicNumber> ListInstanceData, bool update = false)
        {
            List <MagicNumber> magicNumbers = new List <MagicNumber>();

            using (var db = new MagicNumberContext())
            {
                var query = from b in db.Table_Name
                            orderby b.Symbol
                            select b;

                foreach (var item in query)
                {
                    magicNumbers.Add(item);
                }
            }

            IEnumerable <MagicNumber> resultMagicNumbers = new List <MagicNumber>();

            resultMagicNumbers = from a in ListInstanceData
                                 from b in magicNumbers
                                 where a.Symbol == b.Symbol
                                 select a;

            if (update)
            {
                resultMagicNumbers.Distinct();
                return(resultMagicNumbers.ToList());
            }
            else
            {
                foreach (var item in resultMagicNumbers.ToList())
                {
                    ListInstanceData.Remove(item);
                }
                ListInstanceData.Distinct();
                return(ListInstanceData);
            }
        }
Esempio n. 11
0
        public static void AddAllInstance(List <MagicNumber> ListInstanceData)
        {
            ListInstanceData = CheckInsertAll(ListInstanceData);
            if (ListInstanceData.Count < 1)
            {
                return;
            }

            using (var db = new MagicNumberContext())
            {
                try
                {
                    db.Table_Name.AddRange(ListInstanceData);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), ListInstanceData.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
            }
        }