Exemplo n.º 1
0
        public DateTime GetDateLastRecord()
        {
            dbConnection.OpenSession();
            var query = String.Format("SELECT * FROM spieniarka_probki order by data_czas desc limit 1");
            var cmd   = new NpgsqlCommand(query, dbConnection.session);

            cmd.ExecuteNonQuery();
            var ds   = new DataSet();
            var dt   = new DataTable();
            var date = new DateTime();

            try
            {
                NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, dbConnection.session);
                da.Fill(ds);
                dt   = ds.Tables[0];
                date = (DateTime)dt.Rows[0].ItemArray[2];
            }
            catch (Exception e)
            {
            }

            dbConnection.session.Close();
            return(date);
        }
Exemplo n.º 2
0
        public DateTime GetDateLastRecord(FileType file)
        {
            dbConnection.OpenSession();

            var query = file == FileType.Batch ? String.Format("SELECT * FROM spieniarka_probki order by data_czas desc limit 1") :
                        String.Format("SELECT * FROM spieniarka_probki_summary order by data_koniec desc limit 1");

            var cmd = new NpgsqlCommand(query, dbConnection.session);

            cmd.ExecuteNonQuery();
            var ds   = new DataSet();
            var dt   = new DataTable();
            var date = new DateTime(2000, 01, 01);

            try
            {
                NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, dbConnection.session);
                Console.WriteLine($"Executed  the query: {query} on connection {dbConnection.session}");

                da.Fill(ds);

                dt = ds.Tables[0];
                if (dt.Rows.Count == 0)
                {
                    Console.WriteLine("The table is empty");
                    return(date);
                }


                date = file == FileType.Batch ? (DateTime)dt.Rows[0].ItemArray[2] : (DateTime)dt.Rows[0].ItemArray[1];
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            dbConnection.session.Close();
            return(date);
        }