Ejemplo n.º 1
0
        public async Task Test_4_Add_PublisherEntityAsync()
        {
            var tContext = await database.BeginTransactionAsync <PublisherEntity>(isolationLevel);

            try
            {
                for (int i = 0; i < 10; ++i)
                {
                    PublisherEntity entity = Mocker.MockOne();

                    DatabaseResult result = await database.AddAsync(entity, tContext);

                    if (!result.IsSucceeded())
                    {
                        output.WriteLine(result.Exception?.Message);
                        throw new Exception();
                    }

                    Assert.True(result.IsSucceeded());
                }

                await database.CommitAsync(tContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                await database.RollbackAsync(tContext);

                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task <DatabaseResult> DeleteOneAsync(Expression <Func <TEntity, bool> > predicate)
        {
            var dbResult = new DatabaseResult();

            try
            {
                var dbSet = _applicationDbContext.Set <TEntity>();

                IEnumerable <TEntity> objects = dbSet.Where <TEntity>(predicate).AsEnumerable();

                foreach (TEntity obj in objects)
                {
                    dbSet.Remove(obj);
                    break;
                }

                await _applicationDbContext.SaveChangesAsync();

                dbResult.Success = true;
                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Exception = ex;
                dbResult.Message   = "Exception DeleteManyAsync " + typeof(TEntity).Name;
                return(dbResult);
            }
        }
Ejemplo n.º 3
0
        public DatabaseResult Add(CreateProblem createProblem)
        {
            var databaseResult = new DatabaseResult
            {
                Success = false
            };

            var result = _problemRepository.Add(createProblem);

            if (result != 0)
            {
                databaseResult.Key     = result;
                databaseResult.Success = true;
                if (createProblem.Tags != null && createProblem.Tags.Any())
                {
                    var tags = createProblem.Tags.Select(x => new CreateTagDto {
                        Name = x
                    });
                    foreach (var createTagDto in tags)
                    {
                        _tagRepository.AddProblemTag(createTagDto, result);
                    }
                }

                if (!string.IsNullOrEmpty(createProblem.AssignedUser))
                {
                    _notificationService.SendNotification(createProblem.AssignedUser, result, $"Jums priskirta problema: {createProblem.Name}");
                }
            }

            return(databaseResult);
        }
Ejemplo n.º 4
0
        static async Task Main(string[] args)
        {
            AssemblyLoadContext
            IDatabase database = GetDatabase();

            IList <BookEntity> books = MokeData.GetBooks();

            TransactionContext tContext = await database.BeginTransactionAsync <BookEntity>();

            DatabaseResult databaseResult = await database.BatchAddAsync(books, "", tContext);

            if (!databaseResult.IsSucceeded())
            {
                await database.RollbackAsync(tContext);
            }

            await database.CommitAsync(tContext);

            IEnumerable <BookEntity> retrieveResult = await database.RetrieveAllAsync <BookEntity>(null);

            foreach (BookEntity bookEntity in retrieveResult)
            {
                Console.WriteLine($"{bookEntity.Name}");
            }
        }
Ejemplo n.º 5
0
        public void Test_1_Batch_Add_PublisherEntity()
        {
            IList <PublisherEntity> publishers = Mocker.GetPublishers();

            var transactionContext = database.BeginTransaction <PublisherEntity>(isolationLevel);

            DatabaseResult result = DatabaseResult.Failed();

            try
            {
                result = database.BatchAdd <PublisherEntity>(publishers, "tester", transactionContext);

                if (!result.IsSucceeded())
                {
                    output.WriteLine(result.Exception?.Message);
                    throw new Exception();
                }

                database.Commit(transactionContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                database.Rollback(transactionContext);
                throw ex;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 6
0
        public void AddRole()
        {
            TransactionContext transContext = database.BeginTransaction <Role>();
            DatabaseResult     result       = DatabaseResult.Succeeded();

            foreach (Role item in _roleList)
            {
                long count = _db.Count <Role>(r => r.Name == item.Name, transContext);

                if (count != 0)
                {
                    continue;
                }

                result = _db.AddAsync(item, transContext).Result;

                if (!result.IsSucceeded())
                {
                    database.Rollback(transContext);
                    break;
                }
            }

            database.Commit(transContext);

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 7
0
        public void Test_3_Batch_Delete_PublisherEntity()
        {
            TransactionContext transactionContext = database.BeginTransaction <PublisherEntity>(isolationLevel);

            try
            {
                IList <PublisherEntity> lst = database.Page <PublisherEntity>(2, 100, transactionContext);

                if (lst.Count != 0)
                {
                    DatabaseResult result = database.BatchDelete <PublisherEntity>(lst, "deleter", transactionContext);

                    if (!result.IsSucceeded())
                    {
                        output.WriteLine(result.Exception?.Message);
                        throw new Exception();
                    }

                    Assert.True(result.IsSucceeded());
                }

                database.Commit(transactionContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                database.Rollback(transactionContext);
                throw ex;
            }
        }
Ejemplo n.º 8
0
        public void Test_6_Delete_PublisherEntity()
        {
            var tContext = database.BeginTransaction <PublisherEntity>(isolationLevel);

            try
            {
                IList <PublisherEntity> testEntities = database.RetrieveAll <PublisherEntity>(tContext);

                testEntities.ForEach(entity => {
                    DatabaseResult result = database.Delete(entity, tContext);

                    if (!result.IsSucceeded())
                    {
                        output.WriteLine(result.Exception?.Message);
                        throw new Exception();
                    }

                    Assert.True(result.IsSucceeded());
                });

                long count = database.Count <PublisherEntity>(tContext);

                database.Commit(tContext);

                output.WriteLine($"count: {count}");

                Assert.True(count == 0);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public async Task <DatabaseResult> InsertManyAsync(List <TEntity> entities)
        {
            var dbResult = new DatabaseResult();

            try
            {
                _applicationDbContext.Configuration.AutoDetectChangesEnabled = false;
                _applicationDbContext.Configuration.ValidateOnSaveEnabled    = false;

                foreach (TEntity entity in entities)
                {
                    _applicationDbContext.Entry(entity).State = EntityState.Added;
                }
                await _applicationDbContext.SaveChangesAsync();

                _applicationDbContext.Configuration.AutoDetectChangesEnabled = true;
                _applicationDbContext.Configuration.ValidateOnSaveEnabled    = true;

                dbResult.Success = true;
                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Exception = ex;
                dbResult.Message   = "Exception InsertManyAsync " + typeof(TEntity).Name;
                return(dbResult);
            }
        }
Ejemplo n.º 10
0
        public virtual async Task <DatabaseResult> ReplaceOneAsync(string id, TEntity entity)
        {
            var dbResult = new DatabaseResult();

            try
            {
                var updateRes = await collection.ReplaceOneAsync(new BsonDocument("_id", new ObjectId(id)), entity);

                if (updateRes.MatchedCount < 1)
                {
                    dbResult.Type    = Entities.Enums.DatabaseResultType.NotMatch;
                    dbResult.Message = "ERROR: updateRes.ModifiedCount < 1 for entity: " + typeof(TEntity).Name;
                    dbResult.Success = false;
                }
                else if (updateRes.MatchedCount > 0 && updateRes.ModifiedCount != updateRes.MatchedCount)
                {
                    dbResult.Type    = Entities.Enums.DatabaseResultType.NotModified;
                    dbResult.Success = false;
                }
                else
                {
                    dbResult.Success = true;
                }

                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Message   = "Exception updating entity: " + typeof(TEntity).Name;
                dbResult.Exception = ex;
                return(dbResult);
            }
        }
Ejemplo n.º 11
0
        async void BtnSave_Clicked(object sender, EventArgs e)
        {
            IList <PublisherEntity> publisherEntities = Mocker.GetPublishers();

            TransactionContext transactionContext = await App.Database.BeginTransactionAsync <PublisherEntity>();

            try
            {
                DatabaseResult databaseResult = await App.Database.BatchAddAsync <PublisherEntity>(publisherEntities, "", transactionContext);

                if (!databaseResult.IsSucceeded())
                {
                    throw new Exception(databaseResult.Exception?.Message, databaseResult.Exception);
                }

                await App.Database.CommitAsync(transactionContext);

                await DisplayList();
            }

            catch (Exception ex)
            {
                await App.Database.RollbackAsync(transactionContext);
                await DisplayAlert("Error", ex.Message, "Close");
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            TransactionContext tContext = await database.BeginTransactionAsync <PublisherEntity>();

            try
            {
                IList <PublisherEntity> lst = Mocker.GetPublishers();

                DatabaseResult databaseResult = await database.BatchAddAsync(lst, "", tContext);

                //new id can be found in databaseResult.Ids

                if (!databaseResult.IsSucceeded())
                {
                    await database.RollbackAsync(tContext);

                    throw new Exception("did not work.");
                }

                await database.CommitAsync(tContext);
            }
            catch (Exception ex)
            {
                await database.RollbackAsync(tContext);

                throw ex;
            }

            return(RedirectToPage("/Index"));
        }
Ejemplo n.º 13
0
        public async Task Test_1_Batch_Add_PublisherEntityAsync()
        {
            IList <PublisherEntity> publishers = Mocker.GetPublishers();

            var transactionContext = await database.BeginTransactionAsync <PublisherEntity>(isolationLevel).ConfigureAwait(false);

            DatabaseResult result = DatabaseResult.Failed();

            try
            {
                result = await database.BatchAddAsync <PublisherEntity>(publishers, "tester", transactionContext);

                if (!result.IsSucceeded())
                {
                    output.WriteLine(result.Exception?.Message);
                    throw new Exception();
                }

                await database.CommitAsync(transactionContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                await database.RollbackAsync(transactionContext);

                throw ex;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 14
0
        public void TestDispose()
        {
            var result = new DatabaseResult <TestEntity>(DummyEnumerator(), 5);

            result.Dispose();
            try
            {
                var a = result.Current;
                Assert.Fail("This should've failed!");
            }
            catch (ObjectDisposedException) { }

            try
            {
                result.MoveNext();
                Assert.Fail("This should've failed!");
            }
            catch (ObjectDisposedException) { }

            try
            {
                var enumerator = result.GetEnumerator();
                enumerator.MoveNext();
                Assert.Fail("This should've failed!");
            }
            catch (ObjectDisposedException) { }
        }
Ejemplo n.º 15
0
        public void Test_4_Add_PublisherEntity()
        {
            TransactionContext tContext = database.BeginTransaction <PublisherEntity>(isolationLevel);

            try
            {
                for (int i = 0; i < 10; ++i)
                {
                    PublisherEntity entity = Mocker.MockOne();

                    DatabaseResult result = database.Add(entity, tContext);

                    if (!result.IsSucceeded())
                    {
                        output.WriteLine(result.Exception?.Message);
                        throw new Exception();
                    }

                    Assert.True(result.IsSucceeded());
                }

                database.Commit(tContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                database.Rollback(tContext);
                throw ex;
            }
        }
Ejemplo n.º 16
0
        public void RandomDeleteSomeUserAsync()
        {
            TransactionContext transContext = database.BeginTransaction <User>();

            List <long> ids = new List <long>();

            DatabaseResult result = null;

            try
            {
                long userCount = _db.Count <User>(transContext);

                for (int i = 0; i < userCount; i += 10)
                {
                    int userId = i;

                    User user = _db.ScalarAsync <User>(i, transContext).Result;

                    if (user == null)
                    {
                        continue;
                    }

                    ids.Add(userId);

                    result = _db.DeleteAsync <User>(user, transContext).Result;

                    Assert.True(result.IsSucceeded());

                    if (!result.IsSucceeded())
                    {
                        database.Rollback(transContext);
                        break;
                    }
                }

                database.Commit(transContext);

                Assert.True(transContext.Status == TransactionStatus.Commited);

                if (transContext.Status == TransactionStatus.Commited)
                {
                    IList <User> updatedUsers = _db.Retrieve <User>(u => SQLUtil.In(u.Id, false, ids), null);

                    if (updatedUsers.Count == 0)
                    {
                        result = DatabaseResult.Succeeded();
                    }

                    result = DatabaseResult.Failed();
                }

                result = DatabaseResult.Failed();
            }
            catch (Exception)
            {
                database.Rollback(transContext);
            }
        }
Ejemplo n.º 17
0
        public async Task <T> First()
        {
            string             query    = GenerateQuery(typeof(T));
            DatabaseResult <T> dbResult = await Database.Query <T>(query);

            List <T> list = dbResult.ToList();

            return(list.Count > 0 ? list[0] : default);
Ejemplo n.º 18
0
        public void TestMethod_calculateAreaNumber()
        {
            //Test calculateAreaNumber
            DatabaseResult dbResult = new DatabaseResult(0, 20, 15, false);

            Assert.IsTrue(dbResult.TooManyInArea);

            dbResult = new DatabaseResult(0, 380, 560, false);

            Assert.IsFalse(dbResult.TooManyInArea);
        }
Ejemplo n.º 19
0
        public async Task Test_2_Batch_Update_PublisherEntityAsync()
        {
            TransactionContext transContext = await database.BeginTransactionAsync <PublisherEntity>(isolationLevel);

            try
            {
                IList <PublisherEntity> lst = await database.RetrieveAllAsync <PublisherEntity>(transContext);

                for (int i = 0; i < lst.Count; i += 2)
                {
                    PublisherEntity entity = lst[i];
                    //entity.Guid = Guid.NewGuid().ToString();
                    entity.Type  = PublisherType.Online;
                    entity.Name  = "ÖÐsfasfafÎÄÃû×Ö";
                    entity.Books = new List <string>()
                    {
                        "xxx", "tttt"
                    };
                    entity.BookAuthors = new Dictionary <string, Author>()
                    {
                        { "Cat", new Author()
                          {
                              Mobile = "111", Name = "BB"
                          } },
                        { "Dog", new Author()
                          {
                              Mobile = "222", Name = "sx"
                          } }
                    };
                }

                DatabaseResult result = await database.BatchUpdateAsync <PublisherEntity>(lst, "tester", transContext);

                Assert.True(result.IsSucceeded());

                if (!result.IsSucceeded())
                {
                    output.WriteLine(result.Exception?.Message);
                    await database.RollbackAsync(transContext);

                    throw new Exception();
                }

                await database.CommitAsync(transContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                await database.RollbackAsync(transContext);

                throw ex;
            }
        }
Ejemplo n.º 20
0
        public void TestEnumerable()
        {
            var result = new DatabaseResult <TestEntity>(DummyEnumerator(), 5);
            int i      = 0;

            foreach (var r in result)
            {
                Assert.AreEqual(i, r.Age);
                Assert.AreEqual("FN" + i, r.FirstName);
                Assert.AreEqual("LN" + i, r.LastName);
                i++;
            }
        }
Ejemplo n.º 21
0
        public void TestReset()
        {
            var result = new DatabaseResult <TestEntity>(DummyEnumerator(), 5);

            try
            {
                result.Reset();
                Assert.Fail("This should've failed!");
            }
            catch (NotSupportedException)
            {
                Debug.Log("Caught NotSupportedException.");
            }
        }
Ejemplo n.º 22
0
        private DatabaseResult <T> ExecuteFunc <T>(string commandText, CommandType commandType, Guid?transactionId, IEnumerable <SimpleDbParam> parameters,
                                                   Func <IDbCommand, T> func)
        {
            IDbConnection connection = GetConnection(transactionId);

            try
            {
                DatabaseResult <T> databaseResult = new DatabaseResult <T>();

                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                using (IDbCommand command = connection.CreateCommand())
                {
                    PrepareCommand(commandText, commandType, parameters, command, BeforePrepareCommand);
                    databaseResult.FunctionReturnValue = func(command);

                    for (int i = command.Parameters.Count - 1; i >= 0; i--)
                    {
                        DbParameter dbParameter = ((DbParameter)command.Parameters[i]);

                        if (dbParameter.ParameterName.ToUpper() == "@RETURN_VALUE")
                        {
                            databaseResult.SqlReturnValue = dbParameter.Value;
                            break;
                        }
                    }

                    RewireParameterResults(command, parameters);
                }

                return(databaseResult);
            }
            finally
            {
                if (!transactionId.HasValue)
                {
                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }

                    connection.Dispose();
                }
            }
        }
Ejemplo n.º 23
0
        public DatabaseResult Add(CreateTimeSpent timeSpent)
        {
            var result         = _timeSpentRepository.CreateTimeSpent(timeSpent);
            var databaseResult = new DatabaseResult
            {
                Success = false
            };

            if (result != 0)
            {
                databaseResult.Key     = result;
                databaseResult.Success = true;
                return(databaseResult);
            }
            return(databaseResult);
        }
Ejemplo n.º 24
0
        public void AddSomeUserClaims()
        {
            int            userCount = _userList.Count;
            DatabaseResult result    = DatabaseResult.Failed();

            for (int i = 1; i < userCount; i += 39)
            {
                UserClaim uc = new UserClaim()
                {
                    UserGuid = i.ToString(), ClaimValue = "Nothing", ClaimType = "HB.Nothing"
                };
                result = _db.AddAsync(uc, null).Result;
            }

            Assert.True(result.IsSucceeded());
        }
Ejemplo n.º 25
0
        public void TestMethod_buildDatabaseResault()
        {
            DatabaseManager dbMan     = new DatabaseManager();
            PrivateObject   testDbMan = new PrivateObject(dbMan);

            //dummy data
            int  UID = 374651249, current = 90, max = 130;
            bool checkedIn = false;

            DatabaseResult dbr = (DatabaseResult)testDbMan.Invoke("buildDatabaseResault", UID, current, max, checkedIn);

            Assert.AreEqual(dbr.CardUID, UID);
            Assert.AreEqual(dbr.CurrentAreaNumber, current);
            Assert.AreEqual(dbr.MaxAreaNumber, max);
            Assert.IsFalse(dbr.CardIsCheckedIn);
        }
Ejemplo n.º 26
0
        public async Task Test_5_Update_PublisherEntityAsync()
        {
            var tContext = await database.BeginTransactionAsync <PublisherEntity>(isolationLevel);

            try
            {
                IList <PublisherEntity> testEntities = await database.PageAsync <PublisherEntity>(1, 1, tContext);

                if (testEntities.Count == 0)
                {
                    return;
                }

                PublisherEntity entity = testEntities[0];

                entity.Books.Add("New Book2");
                entity.BookAuthors.Add("New Book2", new Author()
                {
                    Mobile = "15190208956", Name = "Yuzhaobai"
                });

                DatabaseResult result = await database.UpdateAsync(entity, tContext);

                if (!result.IsSucceeded())
                {
                    output.WriteLine(result.Exception?.Message);
                    throw new Exception();
                }

                Assert.True(result.IsSucceeded());

                PublisherEntity stored = await database.ScalarAsync <PublisherEntity>(entity.Id, tContext);

                Assert.True(stored.Books.Contains("New Book2"));
                Assert.True(stored.BookAuthors["New Book2"].Mobile == "15190208956");

                await database.CommitAsync(tContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                await database.RollbackAsync(tContext);

                throw ex;
            }
        }
Ejemplo n.º 27
0
        public async Task <DatabaseResult> SqlQueryAsync(string query)
        {
            var dbResult = new DatabaseResult();

            try
            {
                var result = await _applicationDbContext.Database.ExecuteSqlCommandAsync(query);

                dbResult.Success = result >= 0;
                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Exception = ex;
                dbResult.Message   = "Exception SqlQueryAsync " + typeof(int).Name;
                return(dbResult);
            }
        }
Ejemplo n.º 28
0
        public virtual async Task <DatabaseResult> InsertManyAsync(List <TEntity> entities)
        {
            var dbResult = new DatabaseResult();

            try
            {
                await collection.InsertManyAsync(entities);

                dbResult.Success = true;
                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Message   = "Exception InsertManyAsync " + typeof(TEntity).Name;
                dbResult.Exception = ex;
                return(dbResult);
            }
        }
Ejemplo n.º 29
0
        public async Task <DatabaseResult> DeleteAsync(string id, string employerId)
        {
            var employee = await _employeeRepository.GetOneAsync(id);

            DatabaseResult result = new DatabaseResult();

            if (employee.EmployerId == employerId)
            {
                result = await _employeeRepository.DeleteOneAsync(x => x.Id == id);
            }
            else
            {
                result.Success = false;
                result.Message = "Access denied.";
            }

            return(result);
        }
Ejemplo n.º 30
0
        public async Task <DatabaseResult <int> > SqlQueryIntAsync(string query)
        {
            var dbResult = new DatabaseResult <int>();

            try
            {
                var result = await _applicationDbContext.Database.SqlQuery <int>(query).FirstOrDefaultAsync();

                dbResult.Success = true;
                dbResult.Entity  = result;
                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Exception = ex;
                dbResult.Message   = "Exception SqlQueryIntAsync " + typeof(int).Name;
                return(dbResult);
            }
        }
Ejemplo n.º 31
0
            public ClaimDonationsGump(int page, int x, int y, DatabaseResult result)
                : base(x, y)
            {
                this.m_Result = result;
                this.m_Page = page;
                this.Closable = true;
                this.Disposable = true;
                this.Dragable = true;
                this.Resizable = false;
                this.AddPage(0);

                this.AddBackground(0, 0, 400, 400, 9380);

                this.AddLabel(100, 5, 1259, @"Welcome to Defiance Donation");

                if (m_Result.Status == ResultStatus.Unresolved)
                {
                    this.AddLabel(100, 100, 1259, @"An unresolved error occured trying");
                    this.AddLabel(100, 120, 1259, @"to claim your rewards. If you keep");
                    this.AddLabel(100, 140, 1259, @"getting this message, please contact");
                    this.AddLabel(100, 160, 1259, @"an administrator.");
                    this.AddLabel(100, 200, 1259, @"Sorry for the inconvenience");
                    this.AddButton(170, 340, 241, 242, (int)Buttons.Cancel, GumpButtonType.Reply, 0);
                }
                else if (m_Result.Status == ResultStatus.DatabaseError)
                {
                    this.AddLabel(100, 100, 1259, @"A database error occured trying");
                    this.AddLabel(100, 120, 1259, @"to claim your rewards. If you keep");
                    this.AddLabel(100, 140, 1259, @"getting this message, please contact");
                    this.AddLabel(100, 160, 1259, @"an administrator.");
                    this.AddLabel(100, 200, 1259, @"Sorry for the inconvenience");
                    this.AddButton(170, 340, 241, 242, (int)Buttons.Cancel, GumpButtonType.Reply, 0);
                }
                else if (m_Result.Status == ResultStatus.NoDonationsFound)
                {
                    this.AddLabel(100, 60, 1259, @"The database could not find any");
                    this.AddLabel(100, 80, 1259, @"donations tied to this account.");
                    this.AddLabel(100, 100, 1259, @"If you believe this is a mistake,");
                    this.AddLabel(100, 120, 1259, @"please contact an administrator.");
                    this.AddLabel(100, 140, 1259, @"Remember that orders are tied to");
                    this.AddLabel(100, 160, 1259, @"the account specified in the cart-");
                    this.AddLabel(100, 180, 1259, @"system profile, at order time.");
                    this.AddLabel(100, 200, 1259, @"If you have changed the account");
                    this.AddLabel(100, 220, 1259, @"in your profile since your last");
                    this.AddLabel(100, 240, 1259, @"order, it will not be claimable");
                    this.AddLabel(100, 260, 1259, @"from this account.");

                    this.AddLabel(100, 300, 1259, @"Sorry for the inconvenience");
                    this.AddButton(170, 340, 241, 242, (int)Buttons.Cancel, GumpButtonType.Reply, 0);
                }
                else if (m_Result.Status == ResultStatus.NoUndeliveredDonationsFound)
                {
                    this.AddLabel(100, 60, 1259, @"No unclaimed donations rewards");
                    this.AddLabel(100, 80, 1259, @"could be found for this account.");
                    this.AddLabel(100, 100, 1259, @"If you believe this is a mistake,");
                    this.AddLabel(100, 120, 1259, @"please contact an administrator.");
                    this.AddLabel(100, 140, 1259, @"Remember that orders are tied to");
                    this.AddLabel(100, 160, 1259, @"the account specified in the cart-");
                    this.AddLabel(100, 180, 1259, @"system profile, at order time.");
                    this.AddLabel(100, 200, 1259, @"If you have changed the account");
                    this.AddLabel(100, 220, 1259, @"in your profile since your last");
                    this.AddLabel(100, 240, 1259, @"order, it will not be claimable");
                    this.AddLabel(100, 260, 1259, @"from this account.");

                    this.AddLabel(100, 300, 1259, @"Sorry for the inconvenience");
                    this.AddButton(170, 340, 241, 242, (int)Buttons.Cancel, GumpButtonType.Reply, 0);
                }
                else if (m_Result.Status == ResultStatus.OK && page >= 0)
                {
                    if (page > 0)
                    {
                        this.AddLabel(60, 375, 1149, @"Prev page");
                        this.AddButton(40, 380, 9706, 9707, (int)Buttons.Previous, GumpButtonType.Reply, 0);
                    }
                    if (m_Result.DataItems.Count > page * 10 + 10)
                    {
                        this.AddLabel(270, 375, 1149, @"Next page");
                        this.AddButton(330, 380, 9702, 9703, (int)Buttons.Next, GumpButtonType.Reply, 0);
                    }

                    this.AddLabel(40, 40, 1259, @"Congratulations, you have unclaimed donation rewards!!");
                    this.AddLabel(40, 80, 1259, @"OrderID:");
                    this.AddLabel(100, 80, 1259, @"Item Description:");
                    this.AddLabel(320, 80, 1259, @"Amount:");

                    int j = 0;
                    for (int i = page * 10; i < m_Result.DataItems.Count && j < 10; i++)
                    {
                        int productID = ((DataItem)m_Result.DataItems[i]).ProductID;
                        int orderID = ((DataItem)m_Result.DataItems[i]).OrderID;
                        int amount = ((DataItem)m_Result.DataItems[i]).Amount;

                        this.AddLabel(50, 100 + j * 20, 1149, @"" + orderID);
                        this.AddLabel(100, 100 + j * 20, 1149, @"" + GetDescription(productID));
                        this.AddLabel(320, 100 + j * 20, 1149, @"" + amount);

                        j++;
                    }
                    this.AddLabel(80, 320, 1259, @"Claim these rewards with this character?");

                    this.AddButton(120, 340, 247, 248, (int)Buttons.OK, GumpButtonType.Reply, 0);
                    this.AddButton(220, 340, 241, 242, (int)Buttons.Cancel, GumpButtonType.Reply, 0);
                }
            }
Ejemplo n.º 32
0
            //SELECT s1 FROM t1 WHERE s1 IN    (SELECT s1 FROM t2);
            // SELECT order_id, product_id, amount FROM xlite_order_items WHERE order_id IN (SELECT order_id FROM xlite_orders WHERE profile_id = BAH)
            public void BeginCheck()
            {
                Console.WriteLine("Beginning of thread function");

                if (m_Mobile == null)
                    return;

                DatabaseResult result = new DatabaseResult(m_Mobile);
                result.Status = ResultStatus.Unresolved;
                string accountName = (m_Mobile.Account as Account).Username;
                con = null;
                command = null;
                reader = null;

                try
                {

                    string query = "SELECT DISTINCT xlite_order_items.order_id, xlite_order_items.product_id, xlite_order_items.amount " +
                                        "FROM xlite_order_items, xlite_orders, xlite_profiles " +
                                        "WHERE xlite_order_items.order_id = xlite_orders.order_id " +
                                        "AND xlite_orders.profile_id = xlite_profiles.profile_id " +
                                        "AND xlite_profiles.shipping_firstname = '" + accountName + "' " +
                                        "AND xlite_orders.status = 'P' " +
                                        "ORDER BY xlite_order_items.order_id";

                    con = new MySqlConnection(m_ConString);
                    con.Open();
                    command = con.CreateCommand();
                    command.CommandText = query;
                    reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        DataItem item = new DataItem(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2));
                        Console.WriteLine("Order ID: {0}, ProductID: {1}, Amount: {2}", item.OrderID, item.ProductID, item.Amount);
                        result.DataItems.Add(item);
                    }
                    reader.Close();
                    if (result.DataItems.Count > 0)
                        result.Status = ResultStatus.OK;
                    else
                        result.Status = ResultStatus.NoDonationsFound;

                    /*
                    string query = "SELECT profile_id FROM xlite_profiles WHERE shipping_firstname = '"+m_AccountName+"'";

                    con = new OdbcConnection(m_ConString);
                    command= new OdbcCommand(query,con);
                    command.Connection.Open();
                    reader = command.ExecuteReader();

                    int profileID;
                    if (reader.Read())
                    {
                        profileID = reader.GetInt32(0);
                        reader.Close();

                        string subQuery =	"SELECT DISTINCT xlite_order_items.order_id, xlite_order_items.product_id, xlite_order_items.amount " +
                                            "FROM xlite_order_items, xlite_orders " +
                                            "WHERE xlite_order_items.order_id = xlite_orders.order_id " +
                                            "AND xlite_orders.profile_id = " + profileID;

                        command = new OdbcCommand(subQuery, con);
                        reader = command.ExecuteReader();

                        while (reader.Read())
                        {
                            DataItem item = new DataItem(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2));
                            Console.WriteLine("Order ID: {0}, ProductID: {1}, Amount: {2}", item.OrderID, item.ProductID, item.Amount);
                            result.DataItems.Add(item);

                        }
                        reader.Close();
                        if(result.DataItems.Count > 0)
                            result.Status = ResultStatus.OK;
                        else
                            result.Status = ResultStatus.NoDonationsFound;
                    }
                    else
                    {
                        result.Status = ResultStatus.ProfileNotFound;
                    }

                */
                }
                catch (Exception e)
                {
                    result.Status = ResultStatus.DatabaseError;
                    Console.WriteLine("Error in class DonationChecker : {0}", e.Message);
                }
                finally
                {
                    if (con != null)
                        con.Close();
                }

                Monitor.Enter(m_ResultQueue);
                m_ResultQueue.Enqueue(result);
                Monitor.Exit(m_ResultQueue);

                Console.WriteLine("End of thread function");
            }
Ejemplo n.º 33
0
 public DatabaseResult runQuery(string query)
 {
     if (!isConnected)
         throw new Exception("Database is disconnected - unable to run query");
     MySqlCommand command = new MySqlCommand(query, this.sqlConn);
     DatabaseResult dbresult = new DatabaseResult();
     try
     {
         //command.ExecuteNonQuery();
         MySqlDataReader reader = command.ExecuteReader();
         for (int i = 0; i < reader.FieldCount; i++)
         {
             dbresult.addColumn(reader.GetName(i));
         }
         while (reader.Read() != false)
         {
             string[] values = new string[reader.FieldCount];
             for (int i = 0; i < reader.FieldCount; i++)
             {
                 if (reader.IsDBNull(i))
                     values[i] = null;
                 else
                     values[i] = reader.GetString(i);
             }
             dbresult.insertRow(values);
         }
         reader.Close();
     }
     catch (Exception excp)
     {
         Exception myExcp = new Exception("Could not verify user. Error: " +
             excp.Message, excp);
         throw (myExcp);
     }
     return dbresult;
 }