/// <summary>
 /// returns "" (empty string) if field is null
 /// </summary>
 /// <param name="rdr"></param>
 /// <param name="idx"></param>
 /// <returns></returns>
 private string GetNullableString(SQLiteDataReader rdr, int idx)
 {
     if (!rdr.IsDBNull(idx))
     {
         return rdr.GetString(idx);
     }
     else
     {
         return "";
     }
 }
        public string printToConsole(SQLiteDataReader readerDB, int index)
        {
            if (readerDB.IsDBNull(index))
            {
                //return "NULL";
                return "";
            }
            else
            {
                String dataObject = readerDB.GetFieldType(index).ToString();
                switch (dataObject)
                {
                    case "System.Int32":
                        return readerDB.GetInt32(index).ToString();
                    case "System.DateTime":
                        DateTime date = readerDB.GetDateTime(index);
                        return Convert.ToString(date);
                    case "System.String":
                        return readerDB.GetString(index);
                    default:
                        return "Unknown";
                }
            }

        }
Esempio n. 3
0
 protected void ReadDvbData(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, Dictionary<long, string> providers)
 {
     this.ShortName = DbSerializer.ReadUtf16(r, 16);
       this.RecordOrder = r.GetInt32(field["major"]);
       int serviceType = r.GetInt32(field["srvType"]);
       this.ServiceType = serviceType;
       this.SignalSource |= LookupData.Instance.IsRadioOrTv(serviceType);
       this.OriginalNetworkId = r.GetInt32(field["onid"]);
       this.TransportStreamId = r.GetInt32(field["tsid"]);
       this.ServiceId = r.GetInt32(field["progNum"]);
       this.VideoPid = r.GetInt32(field["vidPid"]);
       if (!r.IsDBNull(field["provId"]))
     this.Provider = providers.TryGet(r.GetInt64(field["provId"]));
 }
Esempio n. 4
0
 public static object ReadBoolean(SQLiteDataReader reader, int idx)
 {
     try
     {
         if (reader.IsDBNull(idx))
             return false;
         else
             return reader.GetBoolean(idx);
     }
     catch (Exception)
     {
         return false;
     }
 }
Esempio n. 5
0
 public static object ReadFloat(SQLiteDataReader reader, int idx)
 {
     try
     {
         if (reader.IsDBNull(idx))
             return 0;
         else
             return reader.GetFloat(idx);
     }
     catch (Exception)
     {
         return 0;
     }
 }
Esempio n. 6
0
        public static object ReadDateTime(SQLiteDataReader reader, int idx)
        {
            try
            {
                if (!reader.IsDBNull(idx))
                {
                    string val = reader.GetString(idx);
                    if(val.Length != 0)
                    {
                        return DateTime.Parse(val);
                    }
                }

                return new DateTime(1970, 1, 1);
            }
            catch (Exception)
            {
                return new DateTime(1970, 1, 1);
            }
        }
 private string SafeStr(SQLiteDataReader reader, int idx)
 {
     try
       {
     if (reader.IsDBNull(idx))
       return "";
     else
       return reader.GetString(idx);
       }
       catch (Exception)
       {
     return "";
       }
 }
Esempio n. 8
0
 private Int32 GetInt32(SQLiteDataReader reader, int col)
 {
     return reader.IsDBNull(col) ? 0 : reader.GetInt32(col);
 }
Esempio n. 9
0
        private static Mount createMount(SQLiteDataReader reader)
        {
            if (!reader.Read()) {
                return null;
            }

            Mount mount = new Mount();
            mount.permanent = true;
            mount.id = reader.GetInt32(0);
            mount.title = reader.GetString(1);
            mount.name = reader.GetString(2);

            int tameitem = reader.IsDBNull(3) ? DATABASE_NULL : reader.GetInt32(3);
            if (tameitem > 0) mount.tameitemid = tameitem;
            else mount.tameitemid = -1;
            int tamecreature = reader.IsDBNull(4) ? DATABASE_NULL : reader.GetInt32(4);
            if (tamecreature > 0) mount.tamecreatureid = tamecreature;
            else mount.tamecreatureid = -1;
            mount.speed = reader.GetInt32(5);
            mount.tibiastore = reader.GetBoolean(6);
            mount.image = Image.FromStream(reader.GetStream(7));

            return mount;
        }
Esempio n. 10
0
 public static List<WebExternalId> ExternalIdReader(SQLiteDataReader reader, int idx, object param)
 {
     ExternalSiteReaderParameters args = (ExternalSiteReaderParameters)param;
     List<WebExternalId> list = new List<WebExternalId>();
     if (!reader.IsDBNull(idx))
     {
         string val = (string)args.Reader.Invoke(reader, idx);
         if (!String.IsNullOrEmpty(val) && val != "0")
         {
             list.Add(new WebExternalId()
             {
                 Site = args.Site,
                 Id = val
             });
         }
     }
     return list;
 }
Esempio n. 11
0
        private static Spell createSpell(SQLiteDataReader reader)
        {
            SQLiteCommand command;

            if (!reader.Read()) {
                return null;
            }

            Spell spell = new Spell();
            spell.permanent = true;
            spell.id = reader.GetInt32(0);
            spell.name = reader["name"].ToString();
            spell.words = reader["words"].ToString();
            spell.element = reader.IsDBNull(3) ? "Unknown" : reader.GetString(3);
            spell.cooldown = reader.IsDBNull(4) ? DATABASE_NULL : reader.GetInt32(4);
            spell.premium = reader.GetBoolean(5);
            spell.promotion = reader.GetBoolean(6);
            spell.levelrequired = reader.GetInt32(7);
            spell.goldcost = reader.GetInt32(8);
            spell.manacost = reader.GetInt32(9);
            spell.knight = reader.GetBoolean(10);
            spell.paladin = reader.GetBoolean(11);
            spell.sorcerer = reader.GetBoolean(12);
            spell.druid = reader.GetBoolean(13);
            spell.image = Image.FromStream(reader.GetStream(14));

            command = new SQLiteCommand(String.Format("SELECT npcid, knight, druid, paladin, sorcerer FROM SpellNPCs WHERE spellid={0}", spell.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                SpellTaught t = new SpellTaught();
                t.npcid = reader.GetInt32(0);
                t.spellid = spell.id;
                t.knight = reader.GetBoolean(1);
                t.druid = reader.GetBoolean(2);
                t.paladin = reader.GetBoolean(3);
                t.sorcerer = reader.GetBoolean(4);
                spell.teachNPCs.Add(t);
            }
            return spell;
        }
Esempio n. 12
0
        private static HuntingPlace createHunt(SQLiteDataReader reader)
        {
            SQLiteCommand command;

            if (!reader.Read()) {
                return null;
            }

            HuntingPlace huntingPlace = new HuntingPlace();
            huntingPlace.permanent = true;
            huntingPlace.id = reader.GetInt32(0);
            huntingPlace.name = reader["name"].ToString();
            huntingPlace.level = reader.IsDBNull(2) ? DATABASE_NULL : reader.GetInt32(2);
            huntingPlace.exp_quality = reader.IsDBNull(3) ? DATABASE_NULL : reader.GetInt32(3);
            huntingPlace.loot_quality = reader.IsDBNull(4) ? DATABASE_NULL : reader.GetInt32(4);
            string imageName = reader.GetString(5).ToLower();
            Creature cr = getCreature(imageName);
            if (cr != null) {
                huntingPlace.image = cr.GetImage();
            } else {
                NPC npc = getNPC(imageName);
                if (npc != null) {
                    huntingPlace.image = npc.GetImage();
                } else {
                    throw new Exception("Unrecognized npc or creature image.");
                }
            }
            huntingPlace.city = reader["city"].ToString();

            // Hunting place coordinates
            command = new SQLiteCommand(String.Format("SELECT x, y, z FROM HuntingPlaceCoordinates WHERE huntingplaceid={0}", huntingPlace.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Coordinate c = new Coordinate();
                c.x = reader.IsDBNull(0) ? DATABASE_NULL : reader.GetInt32(0);
                c.y = reader.IsDBNull(1) ? DATABASE_NULL : reader.GetInt32(1);
                c.z = reader.IsDBNull(2) ? DATABASE_NULL : reader.GetInt32(2);
                huntingPlace.coordinates.Add(c);
            }
            // Hunting place directions
            command = new SQLiteCommand(String.Format("SELECT beginx, beginy, beginz,endx, endy, endz, ordering, description, settings FROM HuntDirections WHERE huntingplaceid={0} ORDER BY ordering", huntingPlace.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Directions d = new Directions();
                d.huntingplaceid = huntingPlace.id;
                d.begin = new Coordinate(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2));
                d.end = new Coordinate(reader.GetInt32(3), reader.GetInt32(4), reader.GetInt32(5));
                d.ordering = reader.GetInt32(6);
                d.description = reader["description"].ToString();
                d.settings = reader.GetString(8);
                huntingPlace.directions.Add(d);
            }

            // Hunting place creatures
            command = new SQLiteCommand(String.Format("SELECT creatureid FROM HuntingPlaceCreatures WHERE huntingplaceid={0}", huntingPlace.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                int creatureid = reader.GetInt32(0);
                huntingPlace.creatures.Add(creatureid);
            }
            // Hunting place requirements
            command = new SQLiteCommand(String.Format("SELECT questid, requirementtext FROM HuntRequirements WHERE huntingplaceid={0}", huntingPlace.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Requirements r = new Requirements();
                r.huntingplaceid = huntingPlace.id;
                int questid = reader.IsDBNull(0) ? DATABASE_NULL : reader.GetInt32(0);
                r.quest = questIdMap[questid];
                r.notes = reader["requirementtext"].ToString();
                huntingPlace.requirements.Add(r);
            }
            return huntingPlace;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            // TODO: Exporta txt
            dlgExportar.Filter = "Textos (*.txt)|*.txt";

            // Cria conteudo do texto
            string texto = "DA - Skype Grab Message/Contact List - V1.0 - Betha - Desenvolvimento Aberto\r\n\r\n" +
                           "Computador: " + Convert.ToString(Environment.MachineName) + "\r\n" +
                           "Usuário: " + Environment.UserName + "\r\n" +
                           "Sistema: " + Convert.ToString(Environment.OSVersion) + "\r\n" +
                           "Versão: " + Convert.ToString(Environment.Version) + "\r\n\r\n";

            // Lista de contatos
            texto += "****************************\r\n";
            texto += "**   Lista de Contatos:   **\r\n";
            texto += "****************************\r\n\r\n";

            // Retorna contatos

            try
            {
                contatos = new SQLiteCommand(sql2, conn);
                rcontatos = contatos.ExecuteReader();

               // Exibe retorno
               if (rcontatos.HasRows)
               {
                   while (rcontatos.Read())
                   {
                       string nskype = String.Empty;
                       string cnome =  String.Empty;

                       if (!rcontatos.IsDBNull(rcontatos.GetOrdinal("Skype"))) nskype = rcontatos.GetString(rcontatos.GetOrdinal("Skype"));
                       if (!rcontatos.IsDBNull(rcontatos.GetOrdinal("Nome"))) cnome = rcontatos.GetString(rcontatos.GetOrdinal("Nome"));

                       texto += Convert.ToString(rcontatos.GetInt32(0)) + "\r\n";
                       texto += "Nome Skype: " +  nskype  + "\r\n";
                       texto += "Nome Completo: " + cnome + "\r\n\r\n";
                   }
               }

               // Lista de menssagens
               texto += "********************\r\n";
               texto += "**   Menssagens:  **\r\n";
               texto += "********************\r\n\r\n";
            }
            catch
            {
                MessageBox.Show("Primeiro você precisa verificar os dados da conta.", "Atenção!!!",
                                 MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // Retorna Menssagens
            try
            {
                menssagem = new SQLiteCommand(sql1, conn);
                rmenssagem = menssagem.ExecuteReader();

                // Exibe retorno
                if (rmenssagem.HasRows)
                {
                    while (rmenssagem.Read())
                    {
                        string mde = String.Empty;
                        string mpara = String.Empty;
                        string mmsg = String.Empty;

                        if (!rmenssagem.IsDBNull(rmenssagem.GetOrdinal("De"))) mde = rmenssagem.GetString(rmenssagem.GetOrdinal("De"));
                        if (!rmenssagem.IsDBNull(rmenssagem.GetOrdinal("Para"))) mpara = rmenssagem.GetString(rmenssagem.GetOrdinal("Para"));
                        if (!rmenssagem.IsDBNull(rmenssagem.GetOrdinal("Menssagem"))) mmsg = rmenssagem.GetString(rmenssagem.GetOrdinal("Menssagem"));

                        texto += Convert.ToString(rmenssagem.GetInt32(0)) + " \r\n";
                        texto += mde + " : " + mpara + " \r\n\r\n";
                        texto += Convert.ToString(rmenssagem.GetString(4)) + "  >>>>> " + mmsg + " \r\n";
                        texto += "----------------------------------------------------------------------------\r\n\r\n";
                    }
                }
                // Exibe dialogo para salvar arquivo
                if (dlgExportar.ShowDialog() == DialogResult.OK)
                {
                    // Grava um arquivo baseado na area de texto
                    using (StreamWriter gravar = new StreamWriter(dlgExportar.OpenFile()))
                    {
                        gravar.Write(texto);
                    }
                }
            }
            catch
            {
                //
            }
        }
Esempio n. 14
0
        private Entry ReadEntryAuthor(SQLiteDataReader reader)
        {
            Entry entry = new Entry();
            entry.ID = reader.GetInt32(0);
            if (!reader.IsDBNull(1))
            {
                entry.ParentID = reader.GetInt32(1);
            }
            else
            {
                entry.ParentID = null;
            }
            entry.AccountID = reader.GetInt32(2);
            entry.Title = reader.GetString(3);
            entry.Contents = reader.GetString(4);
            entry.Timestamp = reader.GetDateTime(5);

            entry.Author = new Account();
            entry.Author.ID = entry.AccountID;
            entry.Author.Name = reader.GetString(6);
            entry.Author.Email = reader.GetString(7);

            return entry;
        }
Esempio n. 15
0
        public List <Magazyn> GetSearchMagazyn(String searchTxt)
        {
            string sql = @"SELECT KopertaGUID,
                       NrKoperty,
                       NrPlomby,
                       DataOdbioru,
                       GodzinaOdbioru,
                       DataKopii,
                       KopertaNrPro,
                       Przekazal,
                       Zwrocil,
                       NazwaKlienta,
                       NIP,
                       AdresKlienta,
                       KodPocztowy,
                       Miasto,
                       KonwojentImie,
                       KonwojentNazwisko,
                       DataZwrotu,
                       CompanyGUID
                  FROM Magazyn
                  WHERE CompanyGUID = @CompanyGUID
                      AND
                    (NrKoperty LIKE @searchTxt   OR
                    NrPlomby LIKE @searchTxt OR
                    DataOdbioru LIKE @searchTxt  OR
                    GodzinaOdbioru LIKE @searchTxt   OR
                    DataKopii LIKE @searchTxt    OR
                    KopertaNrPro LIKE @searchTxt OR
                    Przekazal LIKE @searchTxt    OR
                    Zwrocil LIKE @searchTxt  OR
                    NazwaKlienta LIKE @searchTxt OR
                    NIP LIKE @searchTxt  OR
                    AdresKlienta LIKE @searchTxt OR
                    KodPocztowy LIKE @searchTxt  OR
                    Miasto LIKE @searchTxt   OR
                    KonwojentImie LIKE @searchTxt    OR
                    KonwojentNazwisko LIKE @searchTxt OR
                    DataZwrotu LIKE @searchTxt)
                    "
            ;


            List <Magazyn> retList = new List <Magazyn>();

            List <System.Data.SQLite.SQLiteParameter> paramList = new List <System.Data.SQLite.SQLiteParameter>();

            paramList.Add(new SQLiteParameter("@CompanyGUID", GlobalVariables.CurrentCompany.CompanyGUID));
            paramList.Add(new SQLiteParameter("@searchTxt", "%" + searchTxt + "%"));


            NGSConnector connector = new NGSConnector();

            System.Data.SQLite.SQLiteDataReader reader = connector.execSQLWithResult(sql, paramList);

            while (reader.Read())
            {
                Magazyn m = new Magazyn();
                m.FillData(
                    reader.IsDBNull(0) ? "" : reader.GetString(0),
                    reader.IsDBNull(1) ? "" : reader.GetString(1),
                    reader.IsDBNull(2) ? "" : reader.GetString(2),
                    reader.IsDBNull(3) ? "" : reader.GetString(3),
                    reader.IsDBNull(4) ? "" : reader.GetString(4),
                    reader.IsDBNull(5) ? "" : reader.GetString(5),
                    reader.IsDBNull(6) ? "" : reader.GetString(6),
                    reader.IsDBNull(7) ? "" : reader.GetString(7),
                    reader.IsDBNull(8) ? "" : reader.GetString(8),
                    reader.IsDBNull(9) ? "" : reader.GetString(9),
                    reader.IsDBNull(10) ? "" : reader.GetString(10),
                    reader.IsDBNull(11) ? "" : reader.GetString(11),
                    reader.IsDBNull(12) ? "" : reader.GetString(12),
                    reader.IsDBNull(13) ? "" : reader.GetString(13),
                    reader.IsDBNull(14) ? "" : reader.GetString(14),
                    reader.IsDBNull(15) ? "" : reader.GetString(15),
                    reader.IsDBNull(16) ? "" : reader.GetString(16),
                    reader.IsDBNull(17) ? "" : reader.GetString(17)
                    );

                retList.Add(m);
            }

            reader = null;

            return(retList);
        }
 /// <summary>
 /// returns -1 if field is null
 /// </summary>
 /// <param name="rdr"></param>
 /// <param name="idx"></param>
 /// <returns></returns>
 private int GetNullableInt32(SQLiteDataReader rdr, int idx)
 {
     if (!rdr.IsDBNull(idx))
     {
         return rdr.GetInt32(idx);
     }
     else
     {
         return -1;
     }
 }
Esempio n. 17
0
        private Way ReadWay(SQLiteDataReader reader)
        {
            var way = new Way();

            way.Id = reader.GetInt64(0);

            // evaluate name
            if (!reader.IsDBNull(1))
            {
                var name = reader.GetString(1);
                EvaluateName(name, way);
            }

            return way;
        }
Esempio n. 18
0
        private Relation ReadRelation(SQLiteDataReader reader)
        {
            var relation = new Relation();

            relation.Id = reader.GetInt64(0);

            // evaluate name
            if (!reader.IsDBNull(1))
            {
                var name = reader.GetString(1);
                EvaluateName(name, relation);
            }

            return relation;
        }
Esempio n. 19
0
        private Node ReadNode(SQLiteDataReader reader)
        {
            var node = new Node();

            node.Id = reader.GetInt64(0);
            node.Latitude = SQLiteSchemaTools.DBToGeo(reader.GetInt32(1));
            node.Longitude = SQLiteSchemaTools.DBToGeo(reader.GetInt32(2));

            // evaluate name
            if (!reader.IsDBNull(3))
            {
                var name = reader.GetString(3);
                EvaluateName(name, node);
            }

            return node;
        }
Esempio n. 20
0
        private Entry ReadEntryAuthorVote(SQLiteDataReader reader)
        {
            Entry entry = new Entry();
            entry.ID = reader.GetInt32(0);
            if (!reader.IsDBNull(1))
            {
                entry.ID = reader.GetInt32(1);
            }
            else
            {
                entry.ParentID = null;
            }
            entry.AccountID = reader.GetInt32(2);
            entry.Title = reader.GetString(3);
            entry.Contents = reader.GetString(4);
            entry.Timestamp = reader.GetDateTime(5);

            entry.Author = new Account();
            entry.Author.ID = entry.AccountID;
            entry.Author.Name = reader.GetString(6);
            entry.Author.Email = reader.GetString(7);

            if (reader.IsDBNull(9))
            {
                entry.Vote = 0;
                entry.AuthorVote = false;
                entry.AuthorVoteUp = false;
                entry.AuthorVoteDown = false;
            }
            else
            {
                int vote = reader.GetInt32(9);
                entry.AuthorVote = true;
                if (vote > 0)
                {
                    entry.AuthorVoteUp = true;
                    entry.AuthorVoteDown = false;
                }
                else
                {
                    entry.AuthorVoteUp = false;
                    entry.AuthorVoteDown = true;
                }
            }

            return entry;
        }
 /// <summary>
 /// Reads the specified reader.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns></returns>
 private IEnumerable<IEnumerable<object>> Read(SQLiteDataReader reader)
 {
     while (reader.Read())
     {
         var row = new object[reader.FieldCount];
         for (var i = 0; i < reader.FieldCount; i++)
         {
             row[i] = reader.GetValue(i);
             if (reader.IsDBNull(i))
                 row[i] = "";
         }
         yield return row;
     }
 }
Esempio n. 22
0
        private static Creature createCreature(SQLiteDataReader reader)
        {
            SQLiteCommand command;

            if (!reader.Read()) {
                return null;
            }

            Creature cr = new Creature();
            cr.permanent = true;
            cr.id = reader.GetInt32(0);
            cr.displayname = reader["name"].ToString();
            cr.health = reader.IsDBNull(2) ? DATABASE_NULL : reader.GetInt32(2);
            cr.experience = reader.IsDBNull(3) ? DATABASE_NULL : reader.GetInt32(3);
            cr.maxdamage = reader.IsDBNull(4) ? DATABASE_NULL : reader.GetInt32(4);
            cr.summoncost = reader.IsDBNull(5) ? DATABASE_NULL : reader.GetInt32(5);
            cr.illusionable = reader.GetBoolean(6);
            cr.pushable = reader.GetBoolean(7);
            cr.pushes = reader.GetBoolean(8);
            cr.res_phys = reader.IsDBNull(9) ? 100 : reader.GetInt32(9);
            cr.res_holy = reader.IsDBNull(10) ? 100 : reader.GetInt32(10);
            cr.res_death = reader.IsDBNull(11) ? 100 : reader.GetInt32(11);
            cr.res_fire = reader.IsDBNull(12) ? 100 : reader.GetInt32(12);
            cr.res_energy = reader.IsDBNull(13) ? 100 : reader.GetInt32(13);
            cr.res_ice = reader.IsDBNull(14) ? 100 : reader.GetInt32(14);
            cr.res_earth = reader.IsDBNull(15) ? 100 : reader.GetInt32(15);
            cr.res_drown = reader.IsDBNull(16) ? 100 : reader.GetInt32(16);
            cr.res_lifedrain = reader.IsDBNull(17) ? 100 : reader.GetInt32(17);
            cr.paralysable = reader.GetBoolean(18);
            cr.senseinvis = reader.GetBoolean(19);
            cr.abilities = reader.IsDBNull(20) ? DATABASE_STRING_NULL : reader["abilities"].ToString();
            cr.title = reader[21].ToString();
            cr.speed = reader.IsDBNull(22) ? DATABASE_NULL : reader.GetInt32(22);
            cr.armor = reader.IsDBNull(23) ? DATABASE_NULL : reader.GetInt32(23);
            cr.boss = reader.GetInt32(24) > 0;
            if (reader.IsDBNull(25)) {
                return null;
            }
            cr.image = Image.FromStream(reader.GetStream(25));

            command = new SQLiteCommand(String.Format("SELECT skinitemid, knifeitemid, percentage FROM Skins WHERE creatureid={0}", cr.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Skin skin = new Skin();
                skin.dropitemid = reader.GetInt32(0);
                skin.skinitemid = reader.GetInt32(1);
                skin.percentage = reader.IsDBNull(2) ? DATABASE_NULL : reader.GetFloat(2);
                cr.skin = skin;
            }

            command = new SQLiteCommand(String.Format("SELECT itemid, percentage, min, max FROM CreatureDrops WHERE creatureid={0}", cr.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemDrop itemDrop = new ItemDrop();
                itemDrop.creatureid = cr.id;
                itemDrop.itemid = reader.GetInt32(0);
                itemDrop.percentage = reader.IsDBNull(1) ? DATABASE_NULL : reader.GetFloat(1);
                if (itemDrop.percentage > 100) {
                    itemDrop.min = 1;
                    itemDrop.max = (int)(itemDrop.percentage / 100.0 * 2.0);
                    itemDrop.percentage = 100;
                } else {
                    itemDrop.min = Math.Max(reader.GetInt32(2), 1);
                    itemDrop.max = Math.Max(reader.GetInt32(3), itemDrop.min);
                }
                cr.itemdrops.Add(itemDrop);
            }

            return cr;
        }
Esempio n. 23
0
 internal static string ReadUtf16(SQLiteDataReader r, int fieldIndex)
 {
   if (r.IsDBNull(fieldIndex))
     return null;
   byte[] nameBytes = new byte[200];
   int nameLen = (int)r.GetBytes(fieldIndex, 0, nameBytes, 0, nameBytes.Length);
   return Encoding.BigEndianUnicode.GetString(nameBytes, 0, nameLen);
 }
Esempio n. 24
0
        private static Item createItem(SQLiteDataReader reader)
        {
            SQLiteCommand command;

            if (!reader.Read()) {
                return null;
            }

            Item item = new Item();
            item.permanent = true;
            item.id = reader.GetInt32(0);
            item.displayname = reader.GetString(1);
            item.actual_value = reader.IsDBNull(2) ? DATABASE_NULL : reader.GetInt64(2);
            item.vendor_value = reader.IsDBNull(3) ? DATABASE_NULL : reader.GetInt64(3);
            item.stackable = reader.GetBoolean(4);
            item.capacity = reader.IsDBNull(5) ? DATABASE_NULL : reader.GetFloat(5);
            item.category = reader.IsDBNull(6) ? "Unknown" : reader.GetString(6);
            item.discard = reader.GetBoolean(7);
            item.convert_to_gold = reader.GetBoolean(8);
            item.look_text = reader.IsDBNull(9) ? String.Format("You see a {0}.", item.displayname) : reader.GetString(9);
            item.title = reader.GetString(10);
            item.currency = reader.IsDBNull(11) ? DATABASE_NULL : reader.GetInt32(11);
            item.image = Image.FromStream(reader.GetStream(12));
            if (item.image.RawFormat.Guid == ImageFormat.Gif.Guid) {
                int frames = item.image.GetFrameCount(FrameDimension.Time);
                if (frames == 1) {
                    Bitmap new_bitmap = new Bitmap(item.image);
                    new_bitmap.MakeTransparent();
                    item.image.Dispose();
                    item.image = new_bitmap;
                }
            }

            command = new SQLiteCommand(String.Format("SELECT vendorid, value FROM SellItems WHERE itemid={0}", item.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemSold sellItem = new ItemSold();
                sellItem.itemid = item.id;
                sellItem.npcid = reader.GetInt32(0);
                sellItem.price = reader.GetInt32(1);
                item.sellItems.Add(sellItem);
            }
            command = new SQLiteCommand(String.Format("SELECT vendorid, value FROM BuyItems WHERE itemid={0}", item.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemSold buyItem = new ItemSold();
                buyItem.itemid = item.id;
                buyItem.npcid = reader.GetInt32(0);
                buyItem.price = reader.GetInt32(1);
                item.buyItems.Add(buyItem);
            }
            command = new SQLiteCommand(String.Format("SELECT creatureid, percentage, min, max FROM CreatureDrops WHERE itemid={0}", item.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemDrop itemDrop = new ItemDrop();
                itemDrop.itemid = item.id;
                itemDrop.creatureid = reader.GetInt32(0);
                itemDrop.percentage = reader.IsDBNull(1) ? DATABASE_NULL : reader.GetFloat(1);
                if (itemDrop.percentage > 100) {
                    itemDrop.min = 1;
                    itemDrop.max = (int)(itemDrop.percentage / 100.0 * 2.0);
                    itemDrop.percentage = 100;
                } else {
                    itemDrop.min = Math.Max(reader.GetInt32(2), 1);
                    itemDrop.max = Math.Max(reader.GetInt32(3), itemDrop.min);
                }

                item.itemdrops.Add(itemDrop);
            }
            command = new SQLiteCommand(String.Format("SELECT questid FROM QuestRewards WHERE itemid={0}", item.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                item.rewardedBy.Add(getQuest(reader.GetInt32(0)));
            }
            command = new SQLiteCommand(String.Format("SELECT property, value FROM ItemProperties WHERE itemid={0}", item.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                string property = reader.GetString(0);
                switch(property) {
                    case "Voc":
                        item.vocation = reader.GetString(1);
                        break;
                    case "Level":
                        item.level = reader.GetInt32(1);
                        break;
                    case "Def":
                        item.defensestr = reader["value"].ToString();
                        if (!int.TryParse(item.defensestr, out item.defense)) {
                            item.defense = int.Parse(item.defensestr.Split(' ')[0]);
                        }
                        break;
                    case "Attrib":
                        item.attrib = reader.GetString(1);
                        break;
                    case "Atk":
                        item.attack = reader.GetInt32(1);
                        break;
                    case "Atk+":
                        item.atkmod = reader.GetInt32(1);
                        break;
                    case "Hit+":
                        string str = reader["value"].ToString();
                        int.TryParse(str, out item.hitmod);
                        break;
                    case "Arm":
                        item.armor = reader.GetInt32(1);
                        break;
                    case "Range":
                        item.range = reader.GetInt32(1);
                        break;
                    case "Type":
                        item.type = reader.GetString(1);
                        break;
                }
            }

            return item;
        }
Esempio n. 25
0
        // 输出 RML 格式的表格
        // 本函数负责写入 <table> 元素
        // parameters:
        //      nTopLines   顶部预留多少行
        public void OutputRmlTable(
            Report report,
            SQLiteDataReader table,
            XmlTextWriter writer,
            int nMaxLines = -1)
        {
            // StringBuilder strResult = new StringBuilder(4096);
            int i, j;

#if NO
            if (nMaxLines == -1)
                nMaxLines = table.Count;
#endif

            writer.WriteStartElement("table");
            writer.WriteAttributeString("class", "table");

            writer.WriteStartElement("thead");
            writer.WriteStartElement("tr");

            int nEvalCount = 0; // 具有 eval 的栏目个数
            for (j = 0; j < report.Count; j++)
            {
                PrintColumn column = (PrintColumn)report[j];
                if (column.Colspan == 0)
                    continue;

                if (string.IsNullOrEmpty(column.Eval) == false)
                    nEvalCount++;

                writer.WriteStartElement("th");
                if (string.IsNullOrEmpty(column.CssClass) == false)
                    writer.WriteAttributeString("class", column.CssClass);
                if (column.Colspan > 1)
                    writer.WriteAttributeString("colspan", column.Colspan.ToString());

                writer.WriteString(column.Title);
                writer.WriteEndElement();   // </th>
            }

            writer.WriteEndElement();   // </tr>
            writer.WriteEndElement();   // </thead>


            // 合计数组
            object[] sums = null;   // 2008/12/1 new changed

            if (report.SumLine)
            {
                sums = new object[report.Count];
                for (i = 0; i < sums.Length; i++)
                {
                    sums[i] = null;
                }
            }

            NumberFormatInfo nfi = new CultureInfo("zh-CN", false).NumberFormat;
            nfi.NumberDecimalDigits = 2;

            writer.WriteStartElement("tbody");

            // Jurassic.ScriptEngine engine = null;
            if (nEvalCount > 0 && engine == null)
            {
                engine = new Jurassic.ScriptEngine();
                engine.EnableExposedClrTypes = true;
            }

            // 内容行循环
            for (i = 0; ; i++)  // i < Math.Min(nMaxLines, table.Count)
            {
                if (table.HasRows == false)
                    break;
                // Line line = table[i];

                if (engine != null)
                    engine.SetGlobalValue("reader", table);

                string strLineCssClass = "content";
#if NO
                if (report.OutputLine != null)
                {
                    OutputLineEventArgs e = new OutputLineEventArgs();
                    e.Line = line;
                    e.Index = i;
                    e.LineCssClass = strLineCssClass;
                    report.OutputLine(this, e);
                    if (e.Output == false)
                        continue;

                    strLineCssClass = e.LineCssClass;
                }
#endif

                // strResult.Append("<tr class='" + strLineCssClass + "'>\r\n");
                writer.WriteStartElement("tr");
                writer.WriteAttributeString("class", strLineCssClass);

                // 列循环
                for (j = 0; j < report.Count; j++)
                {
                    PrintColumn column = (PrintColumn)report[j];

                    if (column.ColumnNumber < -1)
                    {
                        throw (new Exception("PrintColumn对象ColumnNumber列尚未初始化,位置" + Convert.ToString(j)));
                    }

                    string strText = "";
                    if (column.ColumnNumber != -1)
                    {
                        if (string.IsNullOrEmpty(column.Eval) == false)
                        {
                            // engine.SetGlobalValue("cell", line.GetObject(column.ColumnNumber));
                            strText = engine.Evaluate(column.Eval).ToString();
                        }
                        else if (column.DataType == DataType.PriceDouble)
                        {
                            if (table.IsDBNull(column.ColumnNumber /**/) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                double v = table.GetDouble(column.ColumnNumber);
                                /*
                                NumberFormatInfo provider = new NumberFormatInfo();
                                provider.NumberDecimalDigits = 2;
                                provider.NumberGroupSeparator = ".";
                                provider.NumberGroupSizes = new int[] { 3 };
                                strText = Convert.ToString(v, provider);
                                 * */
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == DataType.PriceDecimal)
                        {
                            if (table.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                decimal v = table.GetDecimal(column.ColumnNumber);
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == DataType.PriceDecimal)
                        {
                            if (table.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                decimal v = table.GetDecimal(column.ColumnNumber);
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == DataType.Price)
                        {
                            // Debug.Assert(false, "");
                            if (table.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;	// 2005/5/26
                            else
                                strText = table.GetString(column.ColumnNumber);    // 
                        }
                        else
                            strText = table.GetString(column.ColumnNumber/*, column.DefaultValue*/);
                    }
                    else
                    {
                        strText = table.GetString(0);   // line.Entry;
                    }

                    writer.WriteStartElement(j == 0 ? "th" : "td");
                    if (string.IsNullOrEmpty(column.CssClass) == false)
                        writer.WriteAttributeString("class", column.CssClass);
                    writer.WriteString(strText);
                    writer.WriteEndElement();   // </td>

                    if (report.SumLine == true
                        && column.Sum == true
                        && column.ColumnNumber != -1)
                    {
                        try
                        {
                            // if (column.DataType != DataType.Currency)
                            {
                                object v = table.GetValue(column.ColumnNumber);
#if NO
                                if (report.SumCell != null)
                                {
                                    SumCellEventArgs e = new SumCellEventArgs();
                                    e.DataType = column.DataType;
                                    e.ColumnNumber = column.ColumnNumber;
                                    e.LineIndex = i;
                                    e.Line = line;
                                    e.Value = v;
                                    report.SumCell(this, e);
                                    if (e.Value == null)
                                        continue;

                                    v = e.Value;
                                }
#endif

                                if (sums[j] == null)
                                    sums[j] = v;
                                else
                                {
                                    sums[j] = AddValue(column.DataType,
            sums[j],
            v);
                                    // sums[j] = ((decimal)sums[j]) + v;
                                }
                            }
                        }
                        catch (Exception ex)	// 俘获可能因字符串转换为整数抛出的异常
                        {
                            throw new Exception("在累加 行 " + i.ToString() + " 列 " + column.ColumnNumber.ToString() + " 值的时候,抛出异常: " + ex.Message);
                        }
                    }
                }

                // strResult.Append("</tr>\r\n");
                writer.WriteEndElement();   // </tr>
            }
Esempio n. 26
0
        private static NPC createNPC(SQLiteDataReader reader)
        {
            SQLiteCommand command;

            if (!reader.Read()) {
                return null;
            }

            NPC npc = new NPC();
            npc.permanent = true;
            npc.id = reader.GetInt32(0);
            npc.name = reader["name"].ToString();
            npc.city = reader["city"].ToString();
            if (!reader.IsDBNull(3) && !reader.IsDBNull(4) && !reader.IsDBNull(5)) {
                npc.pos.x = reader.GetInt32(3);
                npc.pos.y = reader.GetInt32(4);
                npc.pos.z = reader.GetInt32(5);
            }
            npc.image = Image.FromStream(reader.GetStream(6));
            npc.job = reader.IsDBNull(7) ? "" : reader.GetString(7);
            if (npc.image.RawFormat.Guid == ImageFormat.Gif.Guid) {
                int frames = npc.image.GetFrameCount(FrameDimension.Time);
                if (frames == 1) {
                    Bitmap new_bitmap = new Bitmap(npc.image);
                    new_bitmap.MakeTransparent();
                    npc.image.Dispose();
                    npc.image = new_bitmap;
                }
            }

            // special case for rashid: change location based on day of the week
            if (npc != null && npc.name == "Rashid") {
                command = new SQLiteCommand(String.Format("SELECT city, x, y, z FROM RashidPositions WHERE day='{0}'", DateTime.Now.DayOfWeek.ToString()), mainForm.conn);
                reader = command.ExecuteReader();
                if (reader.Read()) {
                    npc.city = reader["city"].ToString();
                    npc.pos.x = reader.GetInt32(1);
                    npc.pos.y = reader.GetInt32(2);
                    npc.pos.z = reader.GetInt32(3);
                }
            }
            command = new SQLiteCommand(String.Format("SELECT itemid, value FROM SellItems WHERE vendorid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemSold sellItem = new ItemSold();
                sellItem.itemid = reader.GetInt32(0);
                sellItem.npcid = npc.id;
                sellItem.price = reader.GetInt32(1);
                npc.sellItems.Add(sellItem);
            }
            command = new SQLiteCommand(String.Format("SELECT itemid, value FROM BuyItems WHERE vendorid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                ItemSold buyItem = new ItemSold();
                buyItem.itemid = reader.GetInt32(0);
                buyItem.npcid = npc.id;
                buyItem.price = reader.GetInt32(1);
                npc.buyItems.Add(buyItem);
            }
            command = new SQLiteCommand(String.Format("SELECT spellid,knight,druid,paladin,sorcerer FROM SpellNPCs WHERE npcid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                SpellTaught t = new SpellTaught();
                t.npcid = npc.id;
                t.spellid = reader.GetInt32(0);
                t.knight = reader.GetBoolean(1);
                t.druid = reader.GetBoolean(2);
                t.paladin = reader.GetBoolean(3);
                t.sorcerer = reader.GetBoolean(4);
                npc.spellsTaught.Add(t);
            }

            command = new SQLiteCommand(String.Format("SELECT DISTINCT questid FROM QuestNPCs WHERE npcid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Quest q = getQuest(reader.GetInt32(0));
                npc.involvedQuests.Add(q);
            }

            command = new SQLiteCommand(String.Format("SELECT destination,cost,notes FROM NPCDestinations WHERE npcid={0}", npc.id), mainForm.conn);
            reader = command.ExecuteReader();
            while (reader.Read()) {
                Transport t = new Transport();
                t.destination = reader.GetString(0);
                t.cost = reader.GetInt32(1);
                t.notes = reader.GetString(2);
                npc.transportOffered.Add(t);
            }
            return npc;
        }
Esempio n. 27
0
        private static Achievement createAchievement(SQLiteDataReader reader)
        {
            if (!reader.Read()) {
                return null;
            }

            Achievement achievement = new Achievement();
            achievement.id = reader.GetInt32(0);
            achievement.name = reader.GetString(1);
            achievement.grade = reader.IsDBNull(2) ? 1 : reader.GetInt32(2);
            achievement.points = reader.IsDBNull(3) ? 1 : reader.GetInt32(3);
            achievement.description = reader.IsDBNull(4) ? " " : reader.GetString(4);
            achievement.spoiler = reader.IsDBNull(5)  ? " " : reader.GetString(5);
            achievement.image = reader.IsDBNull(6) ? -1 : reader.GetInt32(6);
            achievement.imagetype = reader.IsDBNull(7) ? -1 : reader.GetInt32(7);

            return achievement;
        }
 private Int32 SafeInt32(SQLiteDataReader reader, int idx)
 {
     try
       {
     if (reader.IsDBNull(idx))
       return 0;
     else
       return reader.GetInt32(idx);
       }
       catch (Exception)
       {
     return 0;
       }
 }
Esempio n. 29
0
 public static object ReadString(SQLiteDataReader reader, int idx)
 {
     try
     {
         if (reader.IsDBNull(idx))
             return "";
         else
             return reader.GetString(idx);
     }
     catch (InvalidCastException)
     {
         // This is a workaround for the weird bug that for some reason numeric values throw an InvalidCastException.
         // See for example http://forum.team-mediaportal.com/webservice-mobile-access-537/webservice-general-media-access-webservice-89956/index7.html#post748640
         return ReadInt32(reader, idx).ToString();
     }
     catch (Exception)
     {
         return "";
     }
 }
Esempio n. 30
0
 private void ReadAnalogData(SQLiteDataReader r, IDictionary<string, int> field)
 {
   this.FreqInMhz = r.IsDBNull(field["freq"]) ? 0 : (decimal)r.GetInt32(field["freq"]) / 1000;
   this.ChannelOrTransponder = Tools.GetAnalogChannelNumber((int)this.FreqInMhz);
 }
Esempio n. 31
0
 private string GetString(SQLiteDataReader reader, int col)
 {
     return reader.IsDBNull(col) ? string.Empty : reader.GetString(col);
 }