Exemplo n.º 1
0
        public void InsertsUser()
        {
            command.Execute(entity: user);

            sqlExecutor
            .Verify(x => x.ExecuteNonQuery(It.Is <string>(y => y.Contains("INSERT INTO Users"))));
        }
Exemplo n.º 2
0
        public void Using_Insert_Command_Multiple_Times_Works()
        {
            using (_Connection)
            {
                List <Person> people = new List <Person>()
                {
                    new Person()
                    {
                        Id = 101, Name = "InsertTest-1", IsMarried = false, DateOfBirth = new DateTime(1985, 2, 17)
                    },
                    new Person()
                    {
                        Id = 102, Name = "InsertTest-2", IsMarried = true, DateOfBirth = new DateTime(1972, 11, 2)
                    },
                };

                List <Person> people2 = new List <Person>()
                {
                    new Person()
                    {
                        Id = 103, Name = "InsertTest-3", IsMarried = true, DateOfBirth = new DateTime(1953, 8, 15)
                    },
                    new Person()
                    {
                        Id = 104, Name = "InsertTest-4", IsMarried = false, DateOfBirth = new DateTime(1962, 4, 2)
                    },
                };

                InsertCommand <Person> cmd = new InsertCommand <Person>(_Connection, "People");
                cmd.Map("Name", p => p.Name);
                cmd.Map("IsMarried", p => p.IsMarried);
                cmd.Map("DateOfBirth", p => p.DateOfBirth);

                // execute with the first collection
                cmd.Execute(people);

                // execute with the second collection
                cmd.Execute(people2);

                // check
                var checkCmd = _Connection.CreateCommand();
                checkCmd.CommandText = @"
SELECT COUNT(*) 
FROM People 
WHERE (Name = 'InsertTest-1' AND IsMarried = 0) 
OR (Name = 'InsertTest-2' AND IsMarried = 1) 
OR (Name = 'InsertTest-3' AND IsMarried = 1)
OR (Name = 'InsertTest-4' AND IsMarried = 0)";

                Assert.AreEqual(4, checkCmd.ExecuteScalar());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Inserts character in database.
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="character"></param>
        /// <returns></returns>
        public void CreateCharacter(long accountId, Character character)
        {
            using (var conn = this.GetConnection())
                using (var cmd = new InsertCommand("INSERT INTO `characters` {0}", conn))
                {
                    cmd.Set("accountId", accountId);
                    cmd.Set("name", character.Name);
                    cmd.Set("job", character.Job);
                    cmd.Set("gender", character.Gender);
                    cmd.Set("hair", character.Hair);

                    cmd.Set("zone", character.MapId);
                    cmd.Set("x", character.Position.X);
                    cmd.Set("y", character.Position.Y);
                    cmd.Set("z", character.Position.Z);
                    cmd.Set("bx", character.BarrackPosition.X);
                    cmd.Set("by", character.BarrackPosition.Y);
                    cmd.Set("bz", character.BarrackPosition.Z);

                    cmd.Set("hp", character.Hp);
                    cmd.Set("maxHp", character.MaxHp);
                    cmd.Set("sp", character.Sp);
                    cmd.Set("maxSp", character.MaxSp);
                    cmd.Set("stamina", character.Stamina);
                    cmd.Set("maxStamina", character.MaxStamina);
                    cmd.Set("str", character.Str);
                    cmd.Set("con", character.Con);
                    cmd.Set("int", character.Int);
                    cmd.Set("spr", character.Spr);
                    cmd.Set("dex", character.Dex);

                    cmd.Execute();
                    character.Id = cmd.LastId;
                }
        }
Exemplo n.º 4
0
            public void then_it_inserts_multiple_entities_and_outputs_ids()
            {
                int insertCount = 15;
                var entities    = new List <SampleEntity>();

                for (int i = 0; i < insertCount; i++)
                {
                    entities.Add(new SampleEntity
                    {
                        GuidNullableProperty = null,
                        DateProperty         = DateTime.UtcNow,
                        GuidProperty         = Guid.NewGuid()
                    });
                }

                InsertCommand <SampleEntity> command = SUT.Insert <SampleEntity>();

                command.Insert.ExcludeProperty(x => x.Id);
                command.Output.IncludeProperty(x => x.Id);
                int changes = command.Execute(entities);

                changes.ShouldEqual(insertCount);
                entities.ForEach(
                    (entity) => entity.Id.ShouldNotEqual(0));
            }
Exemplo n.º 5
0
        public void Not_Specified_Field_Mappings_Throws_Exception()
        {
            using (_Connection)
            {
                List <Person> people = new List <Person>()
                {
                    new Person()
                    {
                        Id = 101, Name = "InsertTest-1", IsMarried = false, DateOfBirth = new DateTime(1985, 2, 17)
                    },
                    new Person()
                    {
                        Id = 102, Name = "InsertTest-2", IsMarried = true, DateOfBirth = new DateTime(1972, 11, 2)
                    },
                    new Person()
                    {
                        Id = 103, Name = "InsertTest-3", IsMarried = false, DateOfBirth = new DateTime(1953, 8, 15)
                    },
                };

                InsertCommand <Person> cmd = new InsertCommand <Person>(_Connection, "People");

                Exception ex = Assert.Throws <Exception>(delegate { cmd.Execute(people); });
                Assert.AreEqual("No field mappings are specified.", ex.Message);
            }
        }
Exemplo n.º 6
0
            public void then_it_inserts_complex_property()
            {
                var entities = new List <ParentEntity>
                {
                    new ParentEntity
                    {
                        CreatedTime = DateTime.Now,
                        Embedded    = new EmbeddedEntity
                        {
                            Address  = "address1",
                            IsActive = true
                        }
                    },
                    new ParentEntity
                    {
                        CreatedTime = DateTime.Now.AddDays(1),
                        Embedded    = new EmbeddedEntity
                        {
                            Address  = "address2",
                            IsActive = true
                        }
                    }
                };

                InsertCommand <ParentEntity> command = SUT.Insert <ParentEntity>();

                command.Insert.ExcludeProperty(x => x.ParentEntityId);
                int changes = command.Execute(entities);

                changes.ShouldEqual(entities.Count);
            }
Exemplo n.º 7
0
        public static bool AddByName(MySqlConnection dbconn, ulong userActiveCharacterId, string charName,
                                     char state = 'F')
        {
            // TODO: Check for duplicates
            var command = new MySqlCommand("SELECT CID FROM Characters WHERE Name=@cName", dbconn);

            command.Parameters.AddWithValue("@cName", charName);

            ulong friendId;

            using (DbDataReader reader = command.ExecuteReader())
            {
                if (!reader.HasRows || !reader.Read())
                {
                    return(false);
                }
                // TODO: Add serverid
                friendId = Convert.ToUInt64(reader["CID"]);
            }

            using (var cmd = new InsertCommand("INSERT INTO `friends` {0}", dbconn))
            {
                cmd.Set("CID", userActiveCharacterId);
                cmd.Set("FCID", friendId);
                cmd.Set("FSTATE", state);
                cmd.Execute();
            }

            return(true);
        }
Exemplo n.º 8
0
        public void Inserting_Large_Data_Works()
        {
            using (_Connection)
            {
                List <Person> people = new List <Person>();

                for (int i = 0; i < 10000; i++)
                {
                    people.Add(new Person()
                    {
                        Id = i + 100, Name = "InsertTest-" + i, IsMarried = false, DateOfBirth = new DateTime(1985, 2, 17)
                    });
                }

                InsertCommand <Person> cmd = new InsertCommand <Person>(_Connection, "People");
                cmd.Map("Name", p => p.Name);
                cmd.Map("IsMarried", p => p.IsMarried);
                cmd.Map("DateOfBirth", p => p.DateOfBirth);
                cmd.Execute(people);

                // check
                var checkCmd = _Connection.CreateCommand();
                checkCmd.CommandText = @"
SELECT COUNT(*) 
FROM People 
WHERE Name LIKE 'InsertTest%'
";

                Assert.AreEqual(10000, checkCmd.ExecuteScalar());
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Persists the account's chat macros to the database.
        /// </summary>
        /// <param name="account"></param>
        private void SaveChatMacros(Account account)
        {
            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    using (var mc = new MySqlCommand("DELETE FROM `chatMacros` WHERE `accountId` = @accountId", conn, trans))
                    {
                        mc.Parameters.AddWithValue("@accountId", account.Id);
                        mc.ExecuteNonQuery();
                    }

                    foreach (var macro in account.GetChatMacros().OrderBy(x => x.Index))
                    {
                        using (var cmd = new InsertCommand("INSERT INTO `chatMacros` {0}", conn))
                        {
                            cmd.Set("accountId", account.Id);
                            cmd.Set("index", macro.Index);
                            cmd.Set("message", macro.Message);
                            cmd.Set("pose", macro.Pose);

                            cmd.Execute();
                        }
                    }

                    trans.Commit();
                }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates friend entries for user and friend with status inviting/invited.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="friendId"></param>
        public void InviteFriend(int userId, int friendId)
        {
            using (var conn = this.Connection)
                using (var transaction = conn.BeginTransaction())
                {
                    using (var cmd = new InsertCommand("INSERT INTO `friends` {0}", conn, transaction))
                    {
                        cmd.Set("userId1", userId);
                        cmd.Set("userId2", friendId);
                        cmd.Set("groupId", -1);
                        cmd.Set("status", (byte)FriendshipStatus.Inviting);

                        cmd.Execute();
                    }

                    using (var cmd = new InsertCommand("INSERT INTO `friends` {0}", conn, transaction))
                    {
                        cmd.Set("userId1", friendId);
                        cmd.Set("userId2", userId);
                        cmd.Set("groupId", -1);
                        cmd.Set("status", (byte)FriendshipStatus.Invited);

                        cmd.Execute();
                    }

                    transaction.Commit();
                }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adds trade item and points of card to character.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="targetCharacter"></param>
        /// <param name="charCard"></param>
        public void TradeCard(Account account, Character targetCharacter, CharCardData charCard)
        {
            // Add item
            using (var conn = this.Connection)
                using (var cmd = new InsertCommand("INSERT INTO `items` {0}", conn))
                {
                    cmd.Set("creatureId", targetCharacter.CreatureId);
                    cmd.Set("itemId", charCard.TradeItem);
                    cmd.Set("pocket", Pocket.Temporary);
                    cmd.Set("color1", 0x808080);
                    cmd.Set("color2", 0x808080);
                    cmd.Set("color3", 0x808080);

                    cmd.Execute();
                }

            // Add points
            using (var conn = this.Connection)
                using (var cmd = new InsertCommand("UPDATE `accounts` SET `points` = `points` + @points WHERE `accountId` = @accountId", conn))
                {
                    cmd.Set("accountId", account.Name);
                    cmd.Set("points", charCard.TradePoints);

                    cmd.Execute();
                }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Executes SQL update file.
        /// </summary>
        /// <param name="updateFile"></param>
        public void RunUpdate(string updateFile)
        {
            try
            {
                using (var conn = this.GetConnection())
                {
                    // Run update
                    using (var cmd = new MySqlCommand(File.ReadAllText(Path.Combine("sql", updateFile)), conn))
                        cmd.ExecuteNonQuery();

                    // Log update
                    using (var cmd = new InsertCommand("INSERT INTO `updates` {0}", conn))
                    {
                        cmd.Set("path", updateFile);
                        cmd.Execute();
                    }

                    Log.Info("Successfully applied '{0}'.", updateFile);
                }
            }
            catch (Exception ex)
            {
                Log.Error("RunUpdate: Failed to run '{0}': {1}", updateFile, ex.Message);
                CliUtil.Exit(1);
            }
        }
Exemplo n.º 13
0
        public void Inserting_Data_Works()
        {
            using (_Connection)
            {
                List <Person> people = new List <Person>()
                {
                    new Person()
                    {
                        Id = 101, Name = "InsertTest-1", IsMarried = false, DateOfBirth = new DateTime(1985, 2, 17), PlaceOfBirth = "Zurich",
                    },
                    new Person()
                    {
                        Id = 102, Name = "InsertTest-2", IsMarried = true, DateOfBirth = new DateTime(1972, 11, 2), PlaceOfBirth = "London",
                    },
                    new Person()
                    {
                        Id = 103, Name = "InsertTest-3", IsMarried = false, DateOfBirth = new DateTime(1953, 8, 15), PlaceOfBirth = "New York",
                    },
                };

                // check
                var checkCmd = _Connection.CreateCommand();
                checkCmd.CommandText = @"SELECT MAX(Id) FROM People ";
                int maxId = (int)checkCmd.ExecuteScalar();

                InsertCommand <Person> cmd = new InsertCommand <Person>(_Connection, "People");
                cmd.CreateDynamicMappings(new string[] { "Id" });
                cmd.MapIdentity((p, val) => p.Id = Convert.ToInt32(val));
                cmd.Execute(people);

                Assert.AreEqual(maxId + 1, people[0].Id);
                Assert.AreEqual(maxId + 2, people[1].Id);
                Assert.AreEqual(maxId + 3, people[2].Id);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Saves character's skills.
        /// </summary>
        /// <param name="character"></param>
        private void SaveSkills(Character character)
        {
            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    using (var cmd = new MySqlCommand("DELETE FROM `skills` WHERE `characterId` = @characterId", conn, trans))
                    {
                        cmd.Parameters.AddWithValue("@characterId", character.Id);
                        cmd.ExecuteNonQuery();
                    }

                    var skills = character.Skills.GetList();
                    foreach (var skill in skills)
                    {
                        using (var cmd = new InsertCommand("INSERT INTO `skills` {0}", conn, trans))
                        {
                            cmd.Set("characterId", character.Id);
                            cmd.Set("id", skill.Id);
                            cmd.Set("level", skill.Level);
                            cmd.Execute();
                        }

                        // Properties?
                    }

                    trans.Commit();
                }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Executes SQL update file.
        /// </summary>
        /// <param name="updateFile"></param>
        public void RunUpdate(string updateFile)
        {
            try
            {
                using (var conn = GetConnection())
                {
                    // Run update
                    using (var cmd = new MySqlCommand(File.ReadAllText(Path.Combine("sql", updateFile)), conn))
                    {
                        cmd.ExecuteNonQuery();
                    }

                    // Log update
                    using (var cmd = new InsertCommand("INSERT INTO `updates` {0}", conn))
                    {
                        cmd.Set("path", updateFile);
                        cmd.Execute();
                    }

                    Logger.Trace("Successfully applied '{0}'.", updateFile);
                }
            }
            catch (Exception ex)
            {
                Logger.Trace("RunUpdate: Failed to run '{0}': {1}", updateFile, ex.Message);
                Program.Shutdown();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Saves character's jobs to the database.
        /// </summary>
        /// <param name="character"></param>
        private void SaveJobs(Character character)
        {
            var jobs = character.Jobs.GetList();

            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    using (var cmd = new MySqlCommand("DELETE FROM `jobs` WHERE `characterId` = @characterId", conn, trans))
                    {
                        cmd.Parameters.AddWithValue("@characterId", character.Id);
                        cmd.ExecuteNonQuery();
                    }

                    foreach (var job in jobs)
                    {
                        using (var cmd = new InsertCommand("INSERT INTO `jobs` {0}", conn, trans))
                        {
                            cmd.Set("characterId", character.Id);
                            cmd.Set("jobId", job.Id);
                            cmd.Set("circle", job.Circle);
                            cmd.Set("skillPoints", job.SkillPoints);

                            cmd.Execute();
                        }
                    }

                    trans.Commit();
                }
        }
Exemplo n.º 17
0
        public static void CreateCharacter(MySqlConnection dbconn, ref Character character

                                           /*ulong uid, string characterName, short avatar,
                                            * uint carType, uint carColor*/)
        {
            using (var cmd = new InsertCommand("INSERT INTO `Characters` {0}", dbconn))
            {
                cmd.Set("UID", character.Uid);
                cmd.Set("Name", character.Name);
                cmd.Set("Avatar", character.Avatar);
                // The CarId will be updated once we have inserted the car into the db
                cmd.Set("CurrentCarId", -1);
                cmd.Set("City", character.City);
                cmd.Set("CreationDate", DateTimeOffset.Now.ToUnixTimeSeconds());
                cmd.Set("Level", character.Level);
                cmd.Set("GarageLevel", character.GarageLevel);
                cmd.Set("InventoryLevel", character.InventoryLevel);
                cmd.Set("posState", character.PosState);
                cmd.Set("channelId", character.LastChannel);
                cmd.Set("Mito", character.MitoMoney);
                cmd.Set("Hancoin", character.Hancoin);

                cmd.Execute();
                character.Id = (ulong)cmd.LastId;
            }
        }
Exemplo n.º 18
0
            protected override void Given()
            {
                var entities = new List <SampleEntity>();

                for (int i = 0; i < _entitiesCount; i++)
                {
                    entities.Add(new SampleEntity
                    {
                        GuidNullableProperty = null,
                        DateProperty         = DateTime.UtcNow,
                        GuidProperty         = _commonGuidValue
                    });
                }

                InsertCommand <SampleEntity> command = SUT.Insert <SampleEntity>();

                command.Insert.ExcludeProperty(x => x.Id);
                int changes = command.Execute(entities);


                //execute limited Update
                UpdateCommand <SampleEntity> updateOp = SUT
                                                        .UpdateMany <SampleEntity>(x => x.GuidProperty == _commonGuidValue)
                                                        .Assign(x => x.IntProperty, x => 5)
                                                        .SetLimit(_limit);

                _updateChanges = updateOp.Execute();
            }
Exemplo n.º 19
0
        /// <summary>
        /// Executes SQL update file.
        /// </summary>
        /// <param name="updateFile"></param>
        public void RunUpdate(string updateFile)
        {
            try
            {
                using (var conn = GetConnection())
                {
                    // Run update
                    using (var cmd = new MySqlCommand(File.ReadAllText(Path.Combine("sql", updateFile)), conn))
                    {
                        Logger.Trace("We are waiting for a long download of large SQL files!\nIt is necessary to wait for loading of SQL and only then to start GameServer!\nAdditional: Set parameter max_allowed_packet=16M in c:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini");
                        cmd.CommandTimeout = 3600; //ждем долгой загрузки больших SQL файлов. Обычно, это значение 30 секунд.
                        cmd.ExecuteNonQuery();
                    }

                    // Log update
                    using (var cmd = new InsertCommand("INSERT INTO `updates` {0}", conn))
                    {
                        cmd.Set("path", updateFile);
                        cmd.Execute();
                    }

                    Logger.Trace("Successfully applied '{0}'.", updateFile);
                }
            }
            catch (Exception ex)
            {
                Logger.Trace("RunUpdate: Failed to run '{0}': {1}", updateFile, ex.Message);
                Program.Shutdown();
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Persists the account's revealed maps to the database.
        /// </summary>
        /// <param name="account"></param>
        private void SaveRevealedMaps(Account account)
        {
            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    using (var mc = new MySqlCommand("DELETE FROM `revealedMaps` WHERE `accountId` = @accountId", conn, trans))
                    {
                        mc.Parameters.AddWithValue("@accountId", account.Id);
                        mc.ExecuteNonQuery();
                    }

                    foreach (var revealedMap in account.GetRevealedMaps())
                    {
                        using (var cmd = new InsertCommand("INSERT INTO `revealedMaps` {0}", conn))
                        {
                            cmd.Set("accountId", account.Id);
                            cmd.Set("map", revealedMap.MapId);
                            cmd.Set("explored", revealedMap.Explored);
                            cmd.Set("percentage", revealedMap.Percentage);

                            cmd.Execute();
                        }
                    }

                    trans.Commit();
                }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Updates explored maps for an account.
        /// </summary>
        /// <param name="account"></param>
        public void SaveMapVisibility(Account account)
        {
            using (var conn = this.GetConnection())
                using (var trans = conn.BeginTransaction())
                {
                    foreach (var pair in account.MapVisibility)
                    {
                        using (var mc = new MySqlCommand("DELETE FROM `MapVisibility` WHERE `accountId` = @accountId AND `map` = @map", conn, trans))
                        {
                            mc.Parameters.AddWithValue("@accountId", account.Id);
                            mc.Parameters.AddWithValue("@map", pair.Key);
                            mc.ExecuteNonQuery();
                        }

                        using (var cmd = new InsertCommand("INSERT INTO `MapVisibility` {0}", conn))
                        {
                            cmd.Set("accountId", account.Id);
                            cmd.Set("map", pair.Key);
                            cmd.Set("explored", pair.Value);
                            cmd.Execute();
                        }
                    }
                    trans.Commit();
                }
        }
Exemplo n.º 22
0
        public void WhenPositionSet_ThenSet(int position, string expected)
        {
            var sut = new InsertCommand(position, "Peter").SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(expected));
        }
Exemplo n.º 23
0
        public void WhenValueIsNullOrEmpty_ThenSetToInsertValue(string value)
        {
            var sut = new InsertCommand(10, "Peter").SetValue(value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo("Peter"));
        }
Exemplo n.º 24
0
        public void WhenInsertValueIsNullOrEmpty_ThenSetToValue(string insertValue)
        {
            var sut = new InsertCommand(0, insertValue).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(Value));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Executes SQL update file.
        /// </summary>
        /// <param name="updateFile"></param>
        public void RunUpdate(string updateFile)
        {
            string[] result = Regex.Split(File.ReadAllText(Path.Combine("sql", updateFile)), @"([^\\];)");
            try
            {
                using (var connection = MySQL.CreateConnection())
                {
                    //stop autocommit
                    using (var cmd = connection.CreateCommand())
                    {
                        cmd.CommandText = "SET AUTOCOMMIT = 0";
                        cmd.ExecuteNonQuery();
                    }
                    //Run update
                    using (var cmd = new MySqlCommand(File.ReadAllText(Path.Combine("sql", updateFile)), connection))
                    {
                        //_log.Info("GameServer need to connect only after loading all SQL! We are waiting for a long download of large SQL files!");
                        cmd.CommandTimeout = 120; //3600; //ждем долгой загрузки больших SQL файлов. Обычно, это значение - десятки секунд.
                        cmd.ExecuteNonQuery();
                    }

                    // Log update
                    using (var cmd = new InsertCommand("INSERT INTO `updates` {0}", connection))
                    {
                        cmd.Set("path", updateFile);
                        cmd.Execute();
                    }

                    // recovery autocommit
                    using (var cmd = connection.CreateCommand())
                    {
                        cmd.CommandText = "SET AUTOCOMMIT = 1";
                        cmd.ExecuteNonQuery();
                    }

                    _log.Info("Successfully applied '{0}'.", updateFile);
                }
            }
            catch (Exception ex)
            {
                using (var connection = MySQL.CreateConnection())
                {
                    MySqlTransaction transaction = connection.BeginTransaction();

                    // recovery autocommit
                    using (var cmd = connection.CreateCommand())
                    {
                        cmd.CommandText = "SET AUTOCOMMIT = 1";
                        cmd.ExecuteNonQuery();
                    }
                }

                _log.Error("RunUpdate: Failed to run '{0}': {1}", updateFile, ex.Message);
                CliUtil.Exit(1);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Returns a user for the given values, either from the db,
        /// or by creating a new one.
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="characterEntityId"></param>
        /// <param name="characterName"></param>
        /// <param name="server"></param>
        /// <param name="channelName"></param>
        /// <returns></returns>
        public User GetOrCreateContact(string accountId, long characterEntityId, string characterName, string server, string channelName)
        {
            using (var conn = this.Connection)
            {
                var user = new User();
                user.AccountId   = accountId;
                user.Name        = characterName;
                user.Server      = server;
                user.ChannelName = channelName;
                user.Status      = ContactStatus.Online;
                user.ChatOptions = ChatOptions.NotifyOnFriendLogIn;

                // Try to get contact from db
                using (var mc = new MySqlCommand("SELECT * FROM `contacts` WHERE `characterEntityId` = @characterEntityId", conn))
                {
                    mc.Parameters.AddWithValue("@characterEntityId", characterEntityId);

                    using (var reader = mc.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            user.Id          = reader.GetInt32("contactId");
                            user.Status      = (ContactStatus)reader.GetByte("status");
                            user.ChatOptions = (ChatOptions)reader.GetUInt32("chatOptions");
                            user.Nickname    = reader.GetStringSafe("nickname") ?? "";

                            if (!Enum.IsDefined(typeof(ContactStatus), user.Status) || user.Status == ContactStatus.None)
                            {
                                user.Status = ContactStatus.Online;
                            }

                            return(user);
                        }
                    }
                }

                // Create new contact
                using (var cmd = new InsertCommand("INSERT INTO `contacts` {0}", conn))
                {
                    cmd.Set("accountId", accountId);
                    cmd.Set("characterEntityId", characterEntityId);
                    cmd.Set("characterName", characterName);
                    cmd.Set("server", server);
                    cmd.Set("status", (byte)user.Status);
                    cmd.Set("chatOptions", (uint)user.ChatOptions);
                    cmd.Set("nickname", "");

                    cmd.Execute();

                    user.Id = (int)cmd.LastId;

                    return(user);
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Adds group to database.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="groupId"></param>
        /// <param name="groupName"></param>
        public void AddGroup(User user, Group group)
        {
            using (var conn = this.Connection)
                using (var cmd = new InsertCommand("INSERT INTO `groups` {0}", conn))
                {
                    cmd.Set("groupId", group.Id);
                    cmd.Set("contactId", user.Id);
                    cmd.Set("name", group.Name);

                    cmd.Execute();
                }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates friend entry for contact on user with the blacklist status.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="contactId"></param>
        public void Blacklist(int userId, int contactId)
        {
            using (var conn = this.Connection)
                using (var cmd = new InsertCommand("INSERT INTO `friends` {0}", conn))
                {
                    cmd.Set("userId1", userId);
                    cmd.Set("userId2", contactId);
                    cmd.Set("groupId", -4);
                    cmd.Set("status", (byte)FriendshipStatus.Blacklist);

                    cmd.Execute();
                }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Adds note to database.
        /// </summary>
        /// <param name="noteId"></param>
        public void AddNote(string sender, string receiver, string message)
        {
            using (var conn = this.Connection)
                using (var cmd = new InsertCommand("INSERT INTO `notes` {0}", conn))
                {
                    cmd.Set("sender", sender);
                    cmd.Set("receiver", receiver);
                    cmd.Set("message", message);
                    cmd.Set("time", DateTime.Now);

                    cmd.Execute();
                }
        }
Exemplo n.º 30
0
        public static bool Create(MySqlConnection dbconn, InventoryItem item)
        {
            if (item.CharacterId == 0 || item.CarId == 0 || item.StackNum == 0)
            {
                return(false);
            }

            using (var cmd = new InsertCommand("INSERT INTO `items` {0}", dbconn))
            {
                var insertCommand = cmd;
                item.WriteToDb(ref insertCommand);
                return(cmd.Execute() == 1);
            }
        }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           Transaction pTransaction,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            bool lLocalTransaction = (pTransaction == null);

            if (lLocalTransaction)
                lTransaction = new Transaction(Instance.CreateDatabase(pInfo));
            else
                lTransaction = pTransaction;

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaDocumentoQD.TableName, PessoaDocumentoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaDocumentoQD.TableName);

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "PDOC_ID");
                    lInsert.Fields.Add(PessoaDocumentoQD._PDOC_ID.Name, lSequence, (ItemType)PessoaDocumentoQD._PDOC_ID.DBType);
                    lReturn.SequenceControl = lSequence;

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 32
0
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(TriagemQD.TableName, TriagemQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(TriagemQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "TRG_ID");
                    lInsert.Fields.Add(TriagemQD._TRG_ID.Name, lSequence, (ItemType)TriagemQD._TRG_ID.DBType);
                    lReturn.SequenceControl = lSequence;
                    decimal lSequenceSenha;

                    if (pValues[TriagemQD._ASTTRG_ID].ToString() == "1")
                    {
                        lSequenceSenha = DataBaseSequenceControl.GetNext(lTransaction, TriagemQD.TableName, "TRG_SENHA", " NUC_ID = " + pValues[TriagemQD._NUC_ID] + " AND TO_CHAR(TRG_REGDATE,'dd/MM/yyyy') = TO_CHAR(SYSDATE,'dd/MM/yyyy') AND ASTTRG_ID = 1 AND TRG_PRIORIDADE = " + pValues[TriagemQD._TRG_PRIORIDADE]);
                        lInsert.Fields.Add(TriagemQD._TRG_SENHA.Name, lSequenceSenha, (ItemType)TriagemQD._TRG_SENHA.DBType);
                    }
                    else if (pValues[TriagemQD._ASTTRG_ID].ToString() == "4")
                    {
                        lSequenceSenha = DataBaseSequenceControl.GetNext(lTransaction, TriagemQD.TableName, "TRG_SENHA", " NUC_ID = " + pValues[TriagemQD._NUC_ID] + " AND TO_CHAR(TRG_REGDATE,'dd/MM/yyyy') = TO_CHAR(SYSDATE,'dd/MM/yyyy') AND ASTTRG_ID = 4 AND TRG_PRIORIDADE = " + pValues[TriagemQD._TRG_PRIORIDADE]);
                        lInsert.Fields.Add(TriagemQD._TRG_SENHA.Name, lSequenceSenha, (ItemType)TriagemQD._TRG_SENHA.DBType);
                    }
                    else if (pValues[TriagemQD._ASTTRG_ID].ToString() == "7")
                    {
                        lSequenceSenha = DataBaseSequenceControl.GetNext(lTransaction, TriagemQD.TableName, "TRG_SENHA", " NUC_ID = " + pValues[TriagemQD._NUC_ID] + " AND TO_CHAR(TRG_REGDATE,'dd/MM/yyyy') = TO_CHAR(SYSDATE,'dd/MM/yyyy') AND ASTTRG_ID = 7 AND TRG_PRIORIDADE = " + pValues[TriagemQD._TRG_PRIORIDADE]);
                        lInsert.Fields.Add(TriagemQD._TRG_SENHA.Name, lSequenceSenha, (ItemType)TriagemQD._TRG_SENHA.DBType);
                    }

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 33
0
        public static OperationResult InsertProcesso(
                DataFieldCollection pValuesAgendamentoDefensor,
                DataFieldCollection pValuesAtendimento,
                List<DataFieldCollection> pListDocumentoMovimentoAtendimento,
                DataFieldCollection pValuesProcesso,
                List<DataFieldCollection> pListAssuntoProcessual,
                List<DataFieldCollection> pListInteressado,
                DataFieldCollection pValuesDocMovTramitacao,
                List<DataFieldCollection> pListDocumentoMovimentoProcesso,
                DataFieldCollection pValuesTramitacao,
                DataFieldCollection pValuesDocMovAnexo,
                DataFieldCollection pValuesAnexoExterno,
                DataFieldCollection pValuesDocMovApf,
                DataFieldCollection pValuesAnexoApf,
                DataFieldCollection pValuesDocMovSiscop,
                DataFieldCollection pValuesAnexoSiscop,
                DataFieldCollection pValuesCriminalDatas,
             ConnectionInfo pInfo
         )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(DocumentoQD.TableName, DocumentoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(DocumentoQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValuesProcesso.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesProcesso[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "DOC_ID");
                    lInsert.Fields.Add(DocumentoQD._DOC_ID.Name, lSequence, (ItemType)DocumentoQD._DOC_ID.DBType);

                    lReturn.SequenceControl = lSequence;

                    decimal lDocNumero = 0;
                    string lNumeroDocumento = "";

                    if (pValuesProcesso[DocumentoQD._TDOC_ID].DBToDecimal() == 1)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_ATENDIMENTO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "A" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "T" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }
                    else if (pValuesProcesso[DocumentoQD._TDOC_ID].DBToDecimal() == 2)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_NUMERO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "P" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "R" + pValuesProcesso[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }

                    lInsert.Fields.Add(DocumentoQD._DOC_NUMERO.Name, lNumeroDocumento, (ItemType)DocumentoQD._DOC_NUMERO.DBType);

                    lReturn.Trace("Executando o Insert Documento");

                    lInsert.Execute(lTransaction, false);

                    if (!lReturn.HasError)
                    {

                        lReturn = AgendamentoDefensorDo.Update(pValuesAgendamentoDefensor, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        lReturn = DocumentoDo.Update(pValuesAtendimento, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pListDocumentoMovimentoAtendimento.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListDocumentoMovimentoAtendimento)
                            {
                                lReturn = DocumentoMovimentoDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListAssuntoProcessual.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListAssuntoProcessual)
                            {
                                lFields.Add(AssuntoProcessualQD._DOC_ID, lSequence);

                                lReturn = AssuntoProcessualDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListInteressado.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListInteressado)
                            {
                                lFields.Add(InteressadoQD._DOC_ID, lSequence);

                                lReturn = InteressadoDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListDocumentoMovimentoProcesso.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListDocumentoMovimentoProcesso)
                            {
                                lFields.Add(DocumentoMovimentoQD._DOC_ID, lSequence);

                                lReturn = DocumentoMovimentoDo.Insert(lFields, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        pValuesDocMovTramitacao.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                        lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovTramitacao, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        decimal lDocMov = 0;
                        lDocMov = lReturn.SequenceControl;

                        pValuesTramitacao.Add(DocumentoTramitacaoQD._DOCMOV_ID, lDocMov);
                        lReturn = DocumentoTramitacaoDo.Insert(pValuesTramitacao, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pValuesAnexoExterno.Count > 0)
                        {
                            pValuesDocMovAnexo.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                            lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovAnexo, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            lDocMov = lReturn.SequenceControl;
                            pValuesAnexoExterno.Add(DocumentoAnexoQD._DOCMOV_ID, lDocMov);
                            lReturn = DocumentoAnexoDo.Insert(pValuesAnexoExterno, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesAnexoApf.Count > 0)
                        {
                            pValuesDocMovApf.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                            lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovApf, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            lDocMov = lReturn.SequenceControl;
                            pValuesAnexoApf.Add(DocumentoAnexoQD._DOCMOV_ID, lDocMov);
                            lReturn = DocumentoAnexoDo.Insert(pValuesAnexoApf, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesAnexoSiscop.Count > 0)
                        {
                            pValuesDocMovSiscop.Add(DocumentoMovimentoQD._DOC_ID, lSequence);
                            lReturn = DocumentoMovimentoDo.Insert(pValuesDocMovSiscop, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            lDocMov = lReturn.SequenceControl;
                            pValuesAnexoSiscop.Add(DocumentoAnexoQD._DOCMOV_ID, lDocMov);
                            lReturn = DocumentoAnexoDo.Insert(pValuesAnexoSiscop, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCriminalDatas.Count > 0)
                        {
                            pValuesCriminalDatas.Add(CriminalDatasQD._DOC_ID, lSequence);
                            lReturn = CriminalDatasDo.Insert(pValuesCriminalDatas, lTransaction, pInfo);

                        }

                        if (!lReturn.HasError)
                        {
                            lReturn.SequenceControl = lSequence;
                            lReturn.Trace("Insert finalizado, executando commit");
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 34
0
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(DocumentoQD.TableName, DocumentoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(DocumentoQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "DOC_ID");
                    lInsert.Fields.Add(DocumentoQD._DOC_ID.Name, lSequence, (ItemType)DocumentoQD._DOC_ID.DBType);

                    lReturn.SequenceControl = lSequence;

                    decimal lDocNumero = 0;
                    string lNumeroDocumento = "";

                    if (pValues[DocumentoQD._TDOC_ID].DBToDecimal() == 1)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_ATENDIMENTO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "A" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2,'0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "T" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }
                    else if (pValues[DocumentoQD._TDOC_ID].DBToDecimal() == 2)
                    {
                        lDocNumero = DataBaseSequenceControl.GetNext(pInfo, "DOC_NUMERO");

                        if (System.Configuration.ConfigurationManager.AppSettings["ApplicationMode"].ToString() == "OnLine")
                            lNumeroDocumento = "P" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                        else
                            lNumeroDocumento = "R" + pValues[DocumentoQD._NUC_ID].ToString().PadLeft(2, '0') + lDocNumero.ToString().PadLeft(5, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    }

                    lInsert.Fields.Add(DocumentoQD._DOC_NUMERO.Name, lNumeroDocumento, (ItemType)DocumentoQD._DOC_NUMERO.DBType);

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction, false);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 35
0
        public static OperationResult Insert(
             DataFieldCollection pValuesPessoa,
             DataFieldCollection pValuesPai,
             DataFieldCollection pValuesMae,
             DataFieldCollection pValuesRequerente,
             DataFieldCollection pValuesPFamilia,
             DataFieldCollection pValuesSituacaoEscolar,
             DataFieldCollection pValuesEnderecoPai,
             DataFieldCollection pValuesPessoaEnderecoPai,
             DataFieldCollection pValuesEnderecoMae,
             DataFieldCollection pValuesPessoaEnderecoMae,
             DataFieldCollection pValuesEnderecoRequerente,
             DataFieldCollection pValuesPessoaEnderecoRequerente,
             DataFieldCollection pValuesRG,
             DataFieldCollection pValuesCPF,
             DataFieldCollection pValuesRGPai,
             DataFieldCollection pValuesCPFPai,
             DataFieldCollection pValuesRGMae,
             DataFieldCollection pValuesCPFMae,
             DataFieldCollection pValuesRGRequerente,
             DataFieldCollection pValuesCPFRequerente,
             ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaQD.TableName, PessoaQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaQD.TableName);

                    foreach (DataField lField in pValuesPessoa.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPessoa[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePessoa;
                    decimal lSequencePai = 0;
                    decimal lSequenceMae = 0;
                    decimal lSequenceRequerente = 0;
                    lSequencePessoa = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                    lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequencePessoa, (ItemType)PessoaQD._PES_ID.DBType);

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (pValuesRG.Count > 0)
                        {
                            pValuesRG.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesRG, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCPF.Count > 0)
                        {
                            pValuesCPF.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesCPF, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesSituacaoEscolar.Count > 0)
                        {
                            pValuesSituacaoEscolar.Add(SituacaoEscolarQD._PES_ID, lSequencePessoa);
                            lReturn = SituacaoEscolarDo.Insert(pValuesSituacaoEscolar, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        #region Pai
                        if (pValuesPai.Count > 0)
                        {
                            lInsert = new InsertCommand(PessoaQD.TableName);

                            foreach (DataField lField in pValuesPai.Keys)
                            {
                                lInsert.Fields.Add(lField.Name, pValuesPai[lField], (ItemType)lField.DBType);
                            }

                            lSequencePai = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                            lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequencePai, (ItemType)PessoaQD._PES_ID.DBType);

                            lInsert.Execute(lTransaction);

                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            if (pValuesEnderecoPai.Count > 0)
                            {
                                lReturn = EnderecoDo.Insert(pValuesEnderecoPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }

                                decimal lSequenceEndereco = lReturn.SequenceControl;

                                DataFieldCollection lFieldsPE = new DataFieldCollection();
                                pValuesPessoaEnderecoPai.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                                pValuesPessoaEnderecoPai.Add(PessoaEnderecoQD._PES_ID, lSequencePai);

                                lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEnderecoPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesRGPai.Count > 0)
                            {
                                pValuesRGPai.Add(PessoaDocumentoQD._PES_ID, lSequencePai);
                                lReturn = PessoaDocumentoDo.Insert(pValuesRGPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesCPFPai.Count > 0)
                            {
                                pValuesCPFPai.Add(PessoaDocumentoQD._PES_ID, lSequencePai);
                                lReturn = PessoaDocumentoDo.Insert(pValuesCPFPai, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }
                        #endregion

                        #region Mae
                        if (pValuesMae.Count > 0)
                        {
                            lInsert = new InsertCommand(PessoaQD.TableName);

                            foreach (DataField lField in pValuesMae.Keys)
                            {
                                lInsert.Fields.Add(lField.Name, pValuesMae[lField], (ItemType)lField.DBType);
                            }

                            lSequenceMae = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                            lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequenceMae, (ItemType)PessoaQD._PES_ID.DBType);

                            lInsert.Execute(lTransaction);

                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            if (pValuesEnderecoMae.Count > 0)
                            {
                                lReturn = EnderecoDo.Insert(pValuesEnderecoMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }

                                decimal lSequenceEndereco = lReturn.SequenceControl;

                                DataFieldCollection lFieldsPE = new DataFieldCollection();
                                pValuesPessoaEnderecoMae.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                                pValuesPessoaEnderecoMae.Add(PessoaEnderecoQD._PES_ID, lSequenceMae);

                                lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEnderecoMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesRGMae.Count > 0)
                            {
                                pValuesRGMae.Add(PessoaDocumentoQD._PES_ID, lSequenceMae);
                                lReturn = PessoaDocumentoDo.Insert(pValuesRGMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesCPFMae.Count > 0)
                            {
                                pValuesCPFMae.Add(PessoaDocumentoQD._PES_ID, lSequenceMae);
                                lReturn = PessoaDocumentoDo.Insert(pValuesCPFMae, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }
                        #endregion

                        #region Requerente
                        if (pValuesRequerente.Count > 0)
                        {
                            lInsert = new InsertCommand(PessoaQD.TableName);

                            foreach (DataField lField in pValuesRequerente.Keys)
                            {
                                lInsert.Fields.Add(lField.Name, pValuesRequerente[lField], (ItemType)lField.DBType);
                            }

                            lSequenceRequerente = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                            lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequenceRequerente, (ItemType)PessoaQD._PES_ID.DBType);

                            lInsert.Execute(lTransaction);

                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            if (pValuesEnderecoRequerente.Count > 0)
                            {
                                lReturn = EnderecoDo.Insert(pValuesEnderecoRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }

                                decimal lSequenceEndereco = lReturn.SequenceControl;

                                DataFieldCollection lFieldsPE = new DataFieldCollection();
                                pValuesPessoaEnderecoRequerente.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                                pValuesPessoaEnderecoRequerente.Add(PessoaEnderecoQD._PES_ID, lSequenceRequerente);

                                lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEnderecoRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesRGRequerente.Count > 0)
                            {
                                pValuesRGRequerente.Add(PessoaDocumentoQD._PES_ID, lSequenceRequerente);
                                lReturn = PessoaDocumentoDo.Insert(pValuesRGRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }

                            if (pValuesCPFRequerente.Count > 0)
                            {
                                pValuesCPFRequerente.Add(PessoaDocumentoQD._PES_ID, lSequenceRequerente);
                                lReturn = PessoaDocumentoDo.Insert(pValuesCPFRequerente, lTransaction, pInfo);
                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        #endregion

                        #region PessoaFamilia
                        if (pValuesPFamilia.Count > 0)
                        {
                            pValuesPFamilia.Add(PessoaFamiliaQD._PES_ID, lSequencePessoa);

                            if(lSequencePai != 0)
                                pValuesPFamilia.Add(PessoaFamiliaQD._PFAM_PAI, lSequencePai);
                            if (lSequenceMae != 0)
                                pValuesPFamilia.Add(PessoaFamiliaQD._PFAM_MAE, lSequenceMae);
                            if (lSequenceRequerente != 0)
                                pValuesPFamilia.Add(PessoaFamiliaQD._PFAM_REQUERENTE, lSequenceRequerente);

                            lReturn = PessoaFamiliaDo.Insert(pValuesPFamilia, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                        }
                        #endregion
                        if (!lReturn.HasError)
                        {
                            lReturn.SequenceControl = lSequencePessoa;
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 36
0
        public static OperationResult Insert(
           DataFieldCollection pValuesPessoa,
           DataFieldCollection pValuesEndereco,
           DataFieldCollection pValuesPessoaEndereco,
           DataFieldCollection pValuesRG,
           DataFieldCollection pValuesCPF,
           DataFieldCollection pValuesCNPJ,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaQD.TableName, PessoaQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaQD.TableName);

                    foreach (DataField lField in pValuesPessoa.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPessoa[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePessoa;
                    lSequencePessoa = DataBaseSequenceControl.GetNext(pInfo, "PES_ID");
                    lInsert.Fields.Add(PessoaQD._PES_ID.Name, lSequencePessoa, (ItemType)PessoaQD._PES_ID.DBType);

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (pValuesEndereco.Count > 0)
                        {
                            lReturn = EnderecoDo.Insert(pValuesEndereco, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }

                            decimal lSequenceEndereco = lReturn.SequenceControl;

                            DataFieldCollection lFieldsPE = new DataFieldCollection();
                            pValuesPessoaEndereco.Add(PessoaEnderecoQD._ENDE_ID, lSequenceEndereco);
                            pValuesPessoaEndereco.Add(PessoaEnderecoQD._PES_ID, lSequencePessoa);

                            lReturn = PessoaEnderecoDo.Insert(pValuesPessoaEndereco, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesRG.Count > 0)
                        {
                            pValuesRG.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesRG, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCPF.Count > 0)
                        {
                            pValuesCPF.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesCPF, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pValuesCNPJ.Count > 0)
                        {
                            pValuesCNPJ.Add(PessoaDocumentoQD._PES_ID, lSequencePessoa);
                            lReturn = PessoaDocumentoDo.Insert(pValuesCNPJ, lTransaction, pInfo);
                            if (lReturn.HasError)
                            {
                                lTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (!lReturn.HasError)
                        {
                            lReturn.SequenceControl = lSequencePessoa;
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 37
0
        public static OperationResult Insert(
           DataFieldCollection pValuesPESF,
           List<DataFieldCollection> pListValuesATUA,
           DataFieldCollection pValuesSUSR,
           List<DataFieldCollection> pListValuesPERMISSAO,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaFuncaoQD.TableName, PessoaFuncaoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaFuncaoQD.TableName);

                    foreach (DataField lField in pValuesPESF.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPESF[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePESF_ID;
                    lSequencePESF_ID = DataBaseSequenceControl.GetNext(pInfo, "PESF_ID");
                    lInsert.Fields.Add(PessoaFuncaoQD._PESF_ID.Name, lSequencePESF_ID, (ItemType)PessoaFuncaoQD._PESF_ID.DBType);

                    lReturn.SequenceControl = lSequencePESF_ID;

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {

                        if (pListValuesATUA.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesATUA)
                            {
                                lFields.Add(AtuacaoQD._PESF_ID, lSequencePESF_ID);

                                lReturn = AtuacaoDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        lReturn = SystemUserDo.Insert(pValuesSUSR, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pListValuesPERMISSAO.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesPERMISSAO)
                            {
                                lFields.Add(SecurityUsersDtQD._SU_ID, lSequencePESF_ID);

                                lReturn = SecurityUsersDtDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (!lReturn.HasError)
                        {
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 38
0
        public static OperationResult Insert(
           List<DataFieldCollection> pListValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(TrmxIrmQD.TableName, TrmxIrmQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {

                    foreach (DataFieldCollection pValues in pListValues)
                    {
                        lInsert = new InsertCommand(TrmxIrmQD.TableName);

                        foreach (DataField lField in pValues.Keys)
                        {
                            lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                        }
                        decimal lSequence;
                        lSequence = DataBaseSequenceControl.GetNext(pInfo, "TRMIRM_ID");
                        lInsert.Fields.Add(TrmxIrmQD._TRMIRM_ID.Name, lSequence, (ItemType)TrmxIrmQD._TRMIRM_ID.DBType);

                        lInsert.Execute(lTransaction);

                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                        }
                    }

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 39
0
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(OficioQD.TableName, OficioQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(OficioQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "OFC_ID");
                    lInsert.Fields.Add(OficioQD._OFC_ID.Name, lSequence, (ItemType)OficioQD._OFC_ID.DBType);

                    string lNumeroOficio = "OFC" + lSequence.ToString().PadLeft(7, '0') + "/" + DateTime.Now.Date.Year.ToString();
                    lInsert.Fields.Add(OficioQD._OFC_NUMERO.Name, lNumeroOficio, (ItemType)OficioQD._OFC_NUMERO.DBType);

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction, false);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
        public static OperationResult Insert(
    DataFieldCollection pValues,
    List<DataFieldCollection> pListInterrupcao,
    ConnectionInfo pInfo                                                                       
 )
        {
            Transaction lTransaction;

             lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

             bool lLocalTransaction = (lTransaction != null);

             InsertCommand lInsert;

             OperationResult lReturn = new OperationResult(DCALC_CONDENACAOQD.TableName, DCALC_CONDENACAOQD.TableName);

             if (!lReturn.HasError)
             {
             try
             {
             if (lLocalTransaction)
             {
                 lReturn.Trace("Transação local, instanciando banco...");
             }

             lInsert = new InsertCommand(DCALC_CONDENACAOQD.TableName);

             lReturn.Trace("Adicionando campos ao objeto de insert");

             foreach (DataField lField in pValues.Keys)
             {
                 lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
             }
             decimal lSequence;
             lSequence = DataBaseSequenceControl.GetNext(pInfo, "COND_ID");
             lInsert.Fields.Add(DCALC_CONDENACAOQD._COND_ID.Name, lSequence, (ItemType)DCALC_CONDENACAOQD._COND_ID.DBType);

             decimal lCOND_ID = 0;
             lCOND_ID = lReturn.SequenceControl;

             lReturn.Trace("Executando o Insert");

             lInsert.Execute(lTransaction);

             if (!lReturn.HasError)
             {
                 if (pListInterrupcao.Count > 0)
                 {
                     foreach (DataFieldCollection lFields in pListInterrupcao)
                     {
                         lFields.Add(DCALC_INTERRUPCAOQD._COD_CONDENACAO, lSequence);

                         lReturn = DCALC_INTERRUPCAODo.Insert(lFields, lTransaction, pInfo);
                         if (lReturn.HasError)
                         {
                             lTransaction.Rollback();
                             return lReturn;
                         }
                     }
                 }

                 if (!lReturn.HasError)
                 {
                     lReturn.SequenceControl = lSequence;
                     lReturn.Trace("Insert finalizado, executando commit");
                     lTransaction.Commit();
                 }
                 else
                 {
                     lTransaction.Rollback();
                 }
             }
             else
             {
                 if (lLocalTransaction)
                     lTransaction.Rollback();
             }
             }
             catch (Exception ex)
             {
             lReturn.OperationException = new SerializableException(ex);

             if (lLocalTransaction)
                 lTransaction.Rollback();
             }
             }

             return lReturn;
        }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           List<DataFieldCollection> pListValuesSFR,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(SituacaoFamiliarQD.TableName, SituacaoFamiliarQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {

                    lInsert = new InsertCommand(SituacaoFamiliarQD.TableName);

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "STFAM_ID");
                    lInsert.Fields.Add(SituacaoFamiliarQD._STFAM_ID.Name, lSequence, (ItemType)SituacaoFamiliarQD._STFAM_ID.DBType);

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (pListValuesSFR.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesSFR)
                            {
                                lFields.Add(SituacaoFamiliarResideQD._STFAM_ID, lSequence);

                                lReturn = SituacaoFamiliarResideDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.SequenceControl = lSequence;
                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PLANOINTERNOQD.TableName, PLANOINTERNOQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(PLANOINTERNOQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "PLANI_ID");
                    lInsert.Fields.Add(PLANOINTERNOQD._PLANI_ID.Name, lSequence, (ItemType)PLANOINTERNOQD._PLANI_ID.DBType);

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
Exemplo n.º 43
0
        public static OperationResult Insert(
           DataFieldCollection pValues,
           Transaction pTransaction,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            bool lLocalTransaction = (pTransaction == null);

            if (lLocalTransaction)
                lTransaction = new Transaction(Instance.CreateDatabase(pInfo));
            else
                lTransaction = pTransaction;

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(AtuacaoQD.TableName, AtuacaoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    //lReturn.Trace("Excluído Atuações...");
                    //lReturn = UpdateInativo(pValues[AtuacaoQD._PESF_ID].DBToDecimal(), pValues[AtuacaoQD._ATUA_STATUS].ToString(), pInfo);

                    //if (lReturn.HasError)
                    //{
                    //    return lReturn;
                    //}

                    lInsert = new InsertCommand(AtuacaoQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequence;
                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "ATUA_ID");
                    lInsert.Fields.Add(AtuacaoQD._ATUA_ID.Name, lSequence, (ItemType)AtuacaoQD._ATUA_ID.DBType);
                    lReturn.SequenceControl = lSequence;

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }