Esempio n. 1
0
        protected override Exemplar InitEntryByReader(System.Data.SQLite.SQLiteDataReader reader)
        {
            Exemplar exemplar = new Exemplar();

            ulong id = System.Convert.ToUInt64(reader.GetInt32(reader.GetOrdinal("id")));

            string   loanPeriodAsString = reader.GetString(reader.GetOrdinal("loanPeriod"));
            DateTime loanPeriod         = new DateTime();

            if (loanPeriodAsString != null || loanPeriodAsString != "")
            {
                loanPeriod = DateTime.Parse(loanPeriodAsString);
            }

            string     stateString = reader.GetString(reader.GetOrdinal("state"));
            BookStates state       = (BookStates)Enum.Parse(typeof(BookStates), stateString, true);

            string signatur   = reader.GetString(reader.GetOrdinal("signatur"));
            ulong  customerId = System.Convert.ToUInt64(reader.GetInt32(reader.GetOrdinal("customerID")));
            ulong  bookId     = System.Convert.ToUInt64(reader.GetInt32(reader.GetOrdinal("bookID")));

            exemplar.ExemplarId = id;
            exemplar.LoanPeriod = loanPeriod;
            exemplar.State      = state;
            exemplar.Signatur   = signatur;
            exemplar.BookId     = bookId;

            return(exemplar);
        }
Esempio n. 2
0
        static Card ReadCard(SQLiteDataReader reader,bool reNewLine)
        {
            Card c = new Card(0);
            c.id = reader.GetInt64(reader.GetOrdinal("id"));
            c.ot = reader.GetInt32(reader.GetOrdinal("ot"));
            c.alias = reader.GetInt64(reader.GetOrdinal("alias"));
            c.setcode = reader.GetInt64(reader.GetOrdinal("setcode"));
            c.type = reader.GetInt64(reader.GetOrdinal("type"));
            c.atk = reader.GetInt32(reader.GetOrdinal("atk"));
            c.def = reader.GetInt32(reader.GetOrdinal("def"));
            c.level = reader.GetInt64(reader.GetOrdinal("level"));
            c.race = reader.GetInt64(reader.GetOrdinal("race"));
            c.attribute = reader.GetInt32(reader.GetOrdinal("attribute"));
            c.category = reader.GetInt64(reader.GetOrdinal("category"));
            c.name = reader.GetString(reader.GetOrdinal("name"));

            c.desc = reader.GetString(reader.GetOrdinal("desc"));
            if(reNewLine)
                c.desc=Retext(c.desc);
            string temp = null;
            for ( int i = 0; i < 0x10; i++ )
            {
                temp = reader.GetString(reader.GetOrdinal("str"+(i+1).ToString()));
                c.Str[i]= ( temp == null ) ? "":temp;
            }
            return c;
        }
Esempio n. 3
0
 private Qso LoadFromDataReader(SQLiteDataReader dr)
 {
     Qso q = new Qso();
     q.Band = (Band)Enum.Parse(typeof(Band), dr.GetString(dr.GetOrdinal("band")));
     q.Callsign = dr.GetString(dr.GetOrdinal("callsign"));
     q.Mode = (Mode)Enum.Parse(typeof(Mode), dr.GetString(dr.GetOrdinal("mode")));
     q.Operator = dr.GetString(dr.GetOrdinal("operator"));
     q.QsoTime = dr.GetDateTime(dr.GetOrdinal("qsotime"));
     return q;
 }
        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
            {
                //
            }
        }
        //Argument to this function should be changed
        //into the SQLResults object returned from
        //runQuery above (and used in fQR above)
        /// <summary>
        /// A public method allowing the Track Model and external modules to format 
        /// database queries into coherent RouteInfo objects
        /// </summary>
        /// <param name="rr">A SQLiteDataReader object provided by the runQuery method in the DBManager</param>
        /// <returns>A valid RouteInfo object, or null in the case of a database error.</returns>
        public RouteInfo formatRouteQueryResults(SQLiteDataReader rr)
        {
            if (rr == null)
                return null;
            //Temp list used to store blocks, since we dont know
            //ahead of time how many to expect
            var blockList = new List<Block>();
            int nBlocks = 0;

            //We need to get our list of blocks, and the number of blocks
            int bIDFinal = -1, locXFinal = -1, locYFinal = -1;
            double sEFinal = -1.0, gradeFinal = -0.0, bSizeFinal = -1.0;
            int dest1Final = -1, dest2Final = -1, prevFinal = -1;
            int trackCirIDFinal = -1;
            int speedLimitFinal =-1;
            while (rr.Read())
            {
                //Get all fields for a given block
                bIDFinal = rr.GetInt32(rr.GetOrdinal("blockID"));
                string line = rr.GetString(rr.GetOrdinal("line"));
                string infra = rr.GetString(rr.GetOrdinal("infra"));
                string dir = rr.GetString(rr.GetOrdinal("dir"));
                string state = rr.GetString(rr.GetOrdinal("state"));
                sEFinal = rr.GetDouble(rr.GetOrdinal("starting_elev"));
                gradeFinal = rr.GetDouble(rr.GetOrdinal("grade"));
                bSizeFinal = rr.GetDouble(rr.GetOrdinal("bSize"));
                trackCirIDFinal = rr.GetInt32(rr.GetOrdinal("trackCirID"));
                speedLimitFinal = rr.GetInt32(rr.GetOrdinal("speedLimit"));
                locXFinal = rr.GetInt32(rr.GetOrdinal("locX"));
                locYFinal = rr.GetInt32(rr.GetOrdinal("locY"));

                prevFinal = rr.GetInt32(rr.GetOrdinal("prev"));
                dest1Final = rr.GetInt32(rr.GetOrdinal("dest1"));
                dest2Final = rr.GetInt32(rr.GetOrdinal("dest2"));

                //////////////////////////////////////////////////////////////////////
                //Parse fields that must be provided as a different type
                string[] infraFinal = infra.Split(';');
                var dirFinal = (DirEnum) Enum.Parse(typeof (DirEnum), dir, true);
                var stateFinal = (StateEnum) Enum.Parse(typeof (StateEnum), state, true);

                var locFinal = new int[2];
                locFinal[0] = locXFinal;
                locFinal[1] = locYFinal;

                blockList.Add(new Block(bIDFinal, stateFinal, prevFinal, sEFinal, gradeFinal, locFinal, bSizeFinal,
                                        dirFinal, infraFinal, dest1Final, dest2Final, trackCirIDFinal, line,speedLimitFinal));
                nBlocks++;
            }

            //If we didnt find any blocks, give up.
            if (nBlocks == 0)
            {
                //if (_dbCon.State != ConnectionState.Closed)
                  //  _dbCon.Close();
                return null;
            }

            Block[] blocks = blockList.ToArray();
            string rName = blocks[0].Line;
            int rID;
            if (rName.Equals("Red", StringComparison.OrdinalIgnoreCase))
                rID = 0;
            else
                rID = 1;

            //All routes start and end at the yard
            int sID = 0;
            int eID = 0;

            var tempRoute = new RouteInfo(rID, rName, nBlocks, blocks, sID, eID);
            //if (_dbCon.State != ConnectionState.Closed)
              //  _dbCon.Close();
            return tempRoute;
        }
        //Argument to this function shouldbe changed
        //into the SQLResults object returned from
        //runQuery() above
        /// <summary>
        /// A public method allowing the track model and other modules to format 
        /// database query results into coherent Block objects
        /// </summary>
        /// <param name="bR">The SQLiteDataReader containing the results of the query</param>
        /// <returns>A valid Block object, or null in the case of an error</returns>
        public Block formatBlockQueryResults(SQLiteDataReader bR)
        {
            Block tempBlock = null;
            int i = 0;
            if (!bR.IsClosed)
            {
                while (bR.Read())
                {
                    //Get all fields for a given block
                    string line = null, infra = null, dir = null;
                    string state = null;

                    int bIDFinal = -1, locXFinal = -1, locYFinal = -1;
                    double sEFinal = -1.0, gradeFinal = -1.0, bSizeFinal = -1.0;
                    int prevFinal = -1, dest1Final = -1, dest2Final = -1;
                    int trackCirIDFinal = -1;
                    int speedLimitFinal = -1;
                    try
                    {
                        bIDFinal = bR.GetInt32(bR.GetOrdinal("blockID"));
                        line = bR.GetString(bR.GetOrdinal("line"));
                        infra = bR.GetString(bR.GetOrdinal("infra"));
                        dir = bR.GetString(bR.GetOrdinal("dir"));
                        state = bR.GetString(bR.GetOrdinal("state"));
                        if (bIDFinal != 0)
                        {
                            sEFinal = bR.GetDouble(bR.GetOrdinal("starting_elev"));
                            gradeFinal = bR.GetDouble(bR.GetOrdinal("grade"));
                            locXFinal = bR.GetInt32(bR.GetOrdinal("locX"));
                            locYFinal = bR.GetInt32(bR.GetOrdinal("locY"));
                            bSizeFinal = bR.GetDouble(bR.GetOrdinal("bSize"));
                            prevFinal = bR.GetInt32(bR.GetOrdinal("prev"));
                            dest1Final = bR.GetInt32(bR.GetOrdinal("dest1"));
                            dest2Final = bR.GetInt32(bR.GetOrdinal("dest2"));
                            trackCirIDFinal = bR.GetInt32(bR.GetOrdinal("trackCirID"));
                            speedLimitFinal = bR.GetInt32(bR.GetOrdinal("speedLimit"));
                        }
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine("Exception was raised");
                    }
                    //////////////////////////////////////////////////////////////////////
                    //Parse fields that must be provided as a different type
                    string[] infraFinal = infra.Split(';');
                    var dirFinal = (DirEnum) Enum.Parse(typeof (DirEnum), dir, true);
                    var stateFinal = (StateEnum) Enum.Parse(typeof (StateEnum), state, true);

                    var locFinal = new int[2];
                    locFinal[0] = locXFinal;
                    locFinal[1] = locYFinal;

                    tempBlock = new Block(bIDFinal, stateFinal, prevFinal, sEFinal, gradeFinal, locFinal, bSizeFinal,
                                          dirFinal, infraFinal, dest1Final, dest2Final, trackCirIDFinal, line,speedLimitFinal);
                    i++; //Inc counter
                }
            }
            else
            {
                //Console.WriteLine("Reader was closed, this was a mistake.");
            }

            if (i != 1)
                return null;
            else
                return tempBlock;
        }
Esempio n. 7
0
        private static void ReadQueryResult(QueryResolution resolution, SQLiteDataReader reader, List<KeyValuePair<DateTime, decimal>> values)
        {
            switch (resolution)
            {
                case QueryResolution.All:
                    var date = reader.GetDateTime(0);
                    var value = reader.GetDecimal(1);
                    values.Add(new KeyValuePair<DateTime, decimal>(date, value));
                    break;

                default:
                    var rawDate = Convert.ToString(reader["GroupedDate"]);

                    // Partial time resolutions will cause the raw date to have a minute value
                    // of :0 instead of :00, which will cause parsing errors, so try and fix that
                    if (rawDate.EndsWith(":0"))
                        rawDate += "0";

                    var resolutionDate = DateTime.Parse(rawDate);
                    var resolutionValue = reader.GetDecimal(reader.GetOrdinal("Value"));
                    values.Add(new KeyValuePair<DateTime, decimal>(resolutionDate, resolutionValue));
                    break;
            }
        }