private void BtSql_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                context = TbSql.Text;

                var accessDb = new DBContextFactory();

                List <string> listedData = accessDb.getData(context);

                int count = listedData.Count;

                string record1 = listedData[0].ToString();

                string record2 = listedData[1].ToString();

                Panel.AppendText("\r\n" + record1.ToString() + "\r\n" + record2);
            }
            catch (Exception err)
            {
                if (err != null)
                {
                    Panel.Text = err.ToString();
                }
            }
        }
        public void SaveAuthModelInDB(string connectionString, string clientName, string publicToken, string secretToken, string storeAddress /*AuthParameters authParams*/)
        {
            //string nonQuery = @"insert into web_api_credentials (client_id,client_secret,access_token,refresh_token,redirect_url,server_url) values
            //    ('{0}','{1}','{2}','{3}','{4}','{5}')";
            //SqlCommand command = new SqlCommand(String.Format(nonQuery, authParams.ClientId, authParams.ClientSecret,
            //    authParams.authModel.AccessToken, authParams.authModel.RefreshToken, authParams.RedirectUrl, authParams.ServerUrl));

            DBContextFactory.SetConnection(connectionString);

            string     nonQuery = @"insert into web_api_credentials (clientName,publicToken,secretToken,storeaddress) values
                ('{0}','{1}','{2}','{3}')";
            SqlCommand command  = new SqlCommand(String.Format(nonQuery, clientName, publicToken, secretToken, storeAddress));

            DBContextFactory.DBContext.BeginTransaction();

            int result = DBContextFactory.DBContext.NonQuery(command);

            if (result < 0)
            {
                DBContextFactory.DBContext.RollbackTransaction();
            }
            else
            {
                DBContextFactory.DBContext.CommitTransaction();
            }
        }
Exemplo n.º 3
0
        public static BaseViewModel GetOverviewViewModel(MainViewModel parent)
        {
            var dbContext = DBContextFactory.GetAdoDatabaseContext();

            return(new OverviewViewModel(ref parent,
                                         new GenreLogic(dbContext),
                                         new ScheduleLogic(dbContext)));
        }
Exemplo n.º 4
0
 public SubscriptionsModule(DBContextFactory factory, EmbedService embedService, Config config, CNNService cnnService, RedditService redditService, MathService mathService) : base(mathService)
 {
     DBFactory     = factory;
     EmbedService  = embedService;
     Config        = config;
     CNNService    = cnnService;
     RedditService = redditService;
 }
Exemplo n.º 5
0
 public CNNService(IServiceProvider provider) : base(provider)
 {
     TextChannnels  = new List <SocketTextChannel>();
     Config         = provider.GetService <Config>();
     HttpService    = provider.GetService <HttpService>();
     Factory        = provider.GetService <DBContextFactory>();
     CheckTimer     = null;
     PostedArticles = new List <string>();
 }
Exemplo n.º 6
0
 public StatsModule(EmbedService embedService, Config config, TrackingService trackingService, MathService mathService, ImageService imageService, DBContextFactory dbFactory) : base(mathService)
 {
     EmbedService    = embedService;
     Config          = config;
     TrackingService = trackingService;
     MathService     = mathService;
     ImageService    = imageService;
     DBFactory       = dbFactory;
 }
Exemplo n.º 7
0
 public DataModule(HttpService httpService, EmbedService embedService, TrackingService trackingService, ImageService imageService, DBContextFactory dbFactory, Config config, MathService mathService) : base(mathService)
 {
     HttpService     = httpService;
     EmbedService    = embedService;
     TrackingService = trackingService;
     ImageService    = imageService;
     DBFactory       = dbFactory;
     Config          = config;
 }
Exemplo n.º 8
0
 public static BaseViewModel GetPaymentViewModel(MainViewModel parent,
                                                 Schedule selectedSchedule,
                                                 IList <SelectionViewModel <TakenSeatViewModel> > selectedSeats)
 {
     return(new PaymentViewModel(ref parent,
                                 selectedSchedule,
                                 selectedSeats,
                                 new PaymentLogic(),
                                 new ReservationLogic(DBContextFactory.GetAdoDatabaseContext())));
 }
Exemplo n.º 9
0
        public static BaseViewModel GetDetailViewModel(MainViewModel parent, Movie selectedMovie)
        {
            var dbContext = DBContextFactory.GetAdoDatabaseContext();

            return(new DetailViewModel(ref parent,
                                       selectedMovie,
                                       new ScheduleLogic(dbContext),
                                       new ReservationLogic(dbContext),
                                       new SeatLogic(dbContext)));
        }
Exemplo n.º 10
0
        public static DataSettings DatabaseIsInstalled()
        {
            var settings = DatabaseManager.LoadSettings();

            if (settings != null && !String.IsNullOrEmpty(settings.DataConnectionString))
            {
                DBContextFactory.SetConnection(settings.DataConnectionString);
            }
            return(settings);
        }
Exemplo n.º 11
0
        public static async Task PopulateDummyCars(int NumberOfCars)
        {
            // Ask the DBContextFactory to create the desired DbContext object for use for database access
            DSuiteContext db = DBContextFactory.GetDbContext <DSuiteContext>();

            for (int i = 0; i < NumberOfCars; ++i)
            {
                Car NewCar = GenerateCar();
                await EFCrud.Create(db, NewCar);
            }
        }
Exemplo n.º 12
0
        //public string GetGuid()
        //{
        //    return _context.Guid.ToString();
        //}

        /// <summary>
        /// 会报错
        /// </summary>
        /// <returns></returns>
        public string GetGuidAsync()
        {
            Task <string> task = new Task <string>(() =>
            {
                DBContext context = DBContextFactory.GetDBContext();
                return(context.Guid.ToString());
            });

            task.Start();
            return(task.Result);
        }
 public virtual bool Add(T instance)
 {
     try
     {
         DBContextFactory.GetDbContextInstance().Set <T>().Add(instance);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 14
0
        public async Task CRUDUsingHelperClass()
        {
            Car newCar = GenerateCar();

            // Demonstrate basic CRUD
            DSuiteContext db = DBContextFactory.GetDbContext <DSuiteContext>();
            await EFCrud.Create(db, newCar);

            Car found = await EFCrud.GetByKey(db, newCar);

            EFCrud.Delete(db, found);
        }
        private void LoadEvents()
        {
            if (this.Events != null)
            {
                this.Events.Clear();
            }

            DBContextFactory factory      = new DBContextFactory();
            var eventRepository           = new EventRepository(factory);
            IEnumerable <event_detail> ed = eventRepository.GetAll();

            this.Events = new ObservableCollection <event_detail>(ed.ToList <event_detail>());
        }
        public GeometryEditViewModel(DBContextFactory contextFactory)
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                ContextFactory = contextFactory;
            }

            SaveChangesCommand  = new RelayCommand(SaveChanges);
            RestoreShapeCommand = new RelayCommand(RestoreShape);
        }
Exemplo n.º 17
0
        public void FindMultipleUsingLINQ()
        {
            DSuiteContext dSuiteContext = DBContextFactory.GetDbContext <DSuiteContext>();

            // Demonstrate the deferred execution POWER of IQueryable!
            // Find a small list of cars that we don't need to page through.
            IQueryable <Car> linqFordBunnies = (from c in dSuiteContext.Cars where c.Make == "Ford" && c.Model == "Bunny" && c.Year < 2006 select c);

            // But I DO want to sort them too. Still no DB call here!
            linqFordBunnies = linqFordBunnies.OrderBy(bunny => bunny.Mileage);

            // NOW, go ahead and execute the query against the database
            linqFordBunnies.DumpData("\r\n\r\n==============FindMultipleUsingLINQ==============================");
        }
Exemplo n.º 18
0
 public ReferenceViewModel(DBContextFactory contextFactory)
 {
     if (IsInDesignMode)
     {
         // Code runs in Blend --> create design time data.
     }
     else
     {
         ContextDb = contextFactory.Create();
         LoadDataAsync();
     }
     //Инициализация комманд
     SaveChangesCommand = new RelayCommand(SaveChanges);
     UndoChangesCommand = new RelayCommand(UndoChanges);
 }
 public override bool Delete(int key)
 {
     try
     {
         DBContextFactory.GetDbContextInstance()
         .TicketMasterUsers.Remove(
             DBContextFactory.GetDbContextInstance().TicketMasterUsers.SingleOrDefault(k => k.UserId == key));
         _unitOfWork.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 20
0
 public override bool Delete(int key)
 {
     try
     {
         DBContextFactory.GetDbContextInstance()
         .EntertainmentAddresses.Remove(
             DBContextFactory.GetDbContextInstance().EntertainmentAddresses.SingleOrDefault(k => k.AddressId == key));
         _unitOfWork.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 21
0
        public MapViewModel(DBContextFactory contextFactory)
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                ContextDbFactory = contextFactory;
                LoadDataAsync();
            }

            //Инициализация комманд
            FindParcelCommand           = new RelayCommand <string>(FindParcelAsync, (o) => FindParcelCommandCanExecute);
            FindParcelCommandCanExecute = true;
            ClearFindedParcelCommand    = new RelayCommand(ClearFindedParcel);
        }
 public override bool Update(TicketMasterUser instance)
 {
     try
     {
         var user =
             DBContextFactory.GetDbContextInstance()
             .TicketMasterUsers.SingleOrDefault(k => k.UserId == instance.UserId);
         user.UserName = instance.UserName;
         user.Email    = instance.Email;
         _unitOfWork.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 23
0
 public override bool Update(Booking instance)
 {
     try
     {
         var booking =
             DBContextFactory.GetDbContextInstance()
             .Bookings.SingleOrDefault(k => k.BookingId == instance.BookingId);
         booking.BookingDate     = instance.BookingDate;
         booking.EventId         = instance.EventId;
         booking.NumberOfTickets = instance.NumberOfTickets;
         _unitOfWork.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 24
0
 public override bool Update(Ticket instance)
 {
     try
     {
         var ticket =
             DBContextFactory.GetDbContextInstance()
             .Tickets.SingleOrDefault(k => k.TicketId == instance.TicketId);
         ticket.EventId    = instance.EventId;
         ticket.Price      = instance.Price;
         ticket.TicketGUID = instance.TicketGUID;
         _unitOfWork.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 25
0
        public virtual BookingTicketInfo[] GetTicketsForUserVerified()
        {
            var DBContext      = DBContextFactory.GetDbContextInstance();
            var userRepository = new TicketMasterUserRepository(new UnitOfWork.UnitOfWork());
            var tickets        = from t in DBContext.Tickets
                                 from b in DBContext.Bookings
                                 from u in DBContext.TicketMasterUsers
                                 where t.TicketId == b.TicketId && b.IsVerifiedPayment == true && u.UserId == b.UserId
                                 select new BookingTicketInfo
            {
                BookingId         = b.BookingId,
                EventName         = b.Ticket.Event.EventName,
                IsVerifiedPayment = true,
                NumberOfTickets   = (int)b.NumberOfTickets,
                Username          = u.UserName
            };

            return(tickets.ToArray());
        }
Exemplo n.º 26
0
        public virtual EntertainmentAddress GetEntertainmentAddressByUsername(string username)
        {
            try
            {
                var user =
                    DBContextFactory.GetDbContextInstance()
                    .TicketMasterUsers.SingleOrDefault(p => p.UserName == username);

                if (user != null)
                {
                    var EntertainmentAddress = DBContextFactory.GetDbContextInstance().EntertainmentAddresses.SingleOrDefault(p => p.UserId == user.UserId);
                    return(EntertainmentAddress);
                }
            }
            catch (Exception e)
            {
            }
            return(null);
        }
Exemplo n.º 27
0
        public virtual BookingStats[] GetStatsByMonth(DateTime fro, DateTime to)
        {
            var DBContext = DBContextFactory.GetDbContextInstance();

            var results = from b in DBContext.Bookings
                          from t in DBContext.Tickets
                          where b.EventId == t.EventId && b.BookingDate >= fro && b.BookingDate <= to
                          orderby b.Ticket.Event.EventName
                          group t by b.BookingDate.Value.Month
                          into gr
                          select
                          new BookingStats
            {
                NumberOfTickets = (int)gr.Count(),
                TotalAmount     = (decimal)gr.Select(p => p.Price * gr.Count()).FirstOrDefault(),
                BookingDate     = gr.Key
            };

            return(results.ToArray());
        }
Exemplo n.º 28
0
 public override bool Update(EntertainmentAddress instance)
 {
     try
     {
         var EntertainmentAddress =
             DBContextFactory.GetDbContextInstance()
             .EntertainmentAddresses.SingleOrDefault(k => k.UserId == instance.UserId);
         EntertainmentAddress.AddressLine1 = instance.AddressLine1;
         EntertainmentAddress.AddressLine2 = instance.AddressLine2;
         EntertainmentAddress.Town         = instance.Town;
         EntertainmentAddress.Country      = instance.Country;
         EntertainmentAddress.PostCode     = instance.PostCode;
         _unitOfWork.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 29
0
        public static bool CheckTableExistence(string connectionString, string tableName)
        {
            bool exists;

            try
            {
                exists = true;
                DBContextFactory.SetConnection(connectionString);
                DBContextFactory.DBContext.OpenConnection();
                DBContextFactory.DBContext.NonQuery("select 1 from " + tableName + " where 1 = 0");
                DBContextFactory.DBContext.CloseConnection();
            }
            catch (Exception e)
            {
                exists = false;
                DBContextFactory.DBContext.CloseConnection();
            }

            return(exists);
        }
Exemplo n.º 30
0
        public virtual GroupedBooking[] GetBookingsByEvent(DateTime fro, DateTime to)
        {
            var DBContext = DBContextFactory.GetDbContextInstance();

            var results = from b in DBContext.Bookings
                          from t in DBContext.Tickets where b.EventId == t.EventId && b.BookingDate >= fro && b.BookingDate <= to
                          orderby b.Ticket.Event.EventName
                          group t by b
                          into gr
                          select
                          new GroupedBooking
            {
                BookingId       = (int)gr.Key.BookingId,
                EventName       = gr.Key.Ticket.Event.EventName,
                NumberOfTickets = (int)gr.Key.NumberOfTickets,
                TotalAmount     = (decimal)gr.Where(q => q.TicketId == gr.Key.TicketId).Select(p => p.Price * gr.Key.NumberOfTickets).FirstOrDefault(),
                BookingDate     = (DateTime)gr.Key.BookingDate
            };

            return(results.ToArray());
        }