Пример #1
0
        }//O(1)

        public void checkOrders(ref LinkedList <Order> orders)
        {
            while (orders.Count != 0)
            {
                orders.RemoveFirst();
            }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT DISTINCT \"Order ID\", \"Product Number\", \"Products\".\"Name\", \"Customer ID\", \"First name\" || ' ' || \"Last name\" as \"Customer name\" , \"Quantity\" FROM \"Orderd\" JOIN \"Products\" ON \"Orderd\".\"Product Number\" = \"Products\".\"Product number\" JOIN \"Customers\" ON \"Orderd\".\"Customer ID\" = \"Customers\".\"ID\"", this.con))
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        orders.AddLast(new Order(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetInt32(3), reader.GetString(4), reader.GetInt32(5)));
                    }
            this.sort.sortOrders(ref orders);
        }//O(N)
Пример #2
0
 public static Int32?GetInt32OrNull(this READER reader, int ordinal)
 {
     if (reader.IsDBNull(ordinal))
     {
         return(null);
     }
     else
     {
         return(reader.GetInt32(ordinal));
     }
 }
Пример #3
0
        }//O(N)

        public bool supplierExists(int id)                              //checks if supplier exists and return true if doesn't exists
        {
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT COUNT(*) FROM \"Suppliers\" WHERE \"ID\" = @ID", this.con)) {
                execute.Parameters.AddWithValue("ID", id);
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        id = reader.GetInt32(0);
                    }
            }
            return(id == 0);
        }//O(1)
Пример #4
0
        }//O(1)

        public bool isSupplierGotItems(int id)                          //check is supplier got items, return true if does
        {
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT COUNT(*) FROM \"Products\" WHERE \"Supplier\" = @ID", this.con)) {
                execute.Parameters.AddWithValue("ID", id);
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        id = reader.GetInt32(0);
                    }
            }
            return(id != 0);
        }//O(1)
Пример #5
0
        }//O(1)

        public bool isCustomerOrdered(int id)                   //checks if customer has an open order, if does reuturn true
        {
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT COUNT(*) FROM \"Orderd\" WHERE \"Customer ID\" = @ID", this.con)) {
                execute.Parameters.AddWithValue("ID", id);
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        id = reader.GetInt32(0);
                    }
            }
            return(id != 0);
        }//O(1)
Пример #6
0
        }//O(1)

        public bool isProductExists(int id)     //check if product exists, if doesn't returns true
        {
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT COUNT(*) FROM \"Products\" WHERE \"Product number\" = @ID", this.con)) {
                execute.Parameters.AddWithValue("ID", id);
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        id = reader.GetInt32(0);
                    }
            }
            return(id == 0);
        }//O(1)
Пример #7
0
 public void CarregarAluno(NpgsqlDataReader dr)
 {
     Model.Aluno objAluno = new Model.Aluno();
     if (dr.Read())
     {
         objAluno.Nome = dr.IsDBNull(dr.GetOrdinal("nm_usuario")) ? string.Empty : dr.GetString(dr.GetOrdinal("nm_usuario"));
         objAluno.Email = dr.IsDBNull(dr.GetOrdinal("email_usuario")) ? string.Empty : dr.GetString(dr.GetOrdinal("email_usuario"));
         objAluno.Senha = dr.IsDBNull(dr.GetOrdinal("senha_usuario")) ? string.Empty : dr.GetString(dr.GetOrdinal("senha_usuario"));
         objAluno.Id = dr.IsDBNull(dr.GetOrdinal("id_usuario")) ? 0 : dr.GetInt32(dr.GetOrdinal("id_usuario"));
         Model.Session.Session.Aluno = objAluno;
     }
     else { throw new ExceptionDAL("Não foi possível logar usuário"); }
 }
Пример #8
0
        }//O(1)

        public void checkCustomers(ref LinkedList <Customer> customers)
        {
            while (customers.Count != 0)
            {
                customers.RemoveFirst();
            }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT * FROM \"Customers\"", this.con))
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        customers.AddLast(new Customer(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4)));
                    }
            this.sort.sortCustomers(ref customers);
        }//O(N)
Пример #9
0
        }//O(1)

        public void checkSuppliers(ref LinkedList <Supply> suppliers)                  //get all suppliers
        {
            while (suppliers.Count != 0)
            {
                suppliers.RemoveFirst();
            }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT * FROM \"Suppliers\"", this.con))
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        suppliers.AddLast(new Supply(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3)));
                    }
            this.sort.sortSuppliers(ref suppliers);
        }//O(N)
Пример #10
0
        }//O(1)

        public void checkProducts(ref LinkedList <Product> products)
        {
            while (products.Count != 0)
            {
                products.RemoveFirst();
            }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT \"Product number\", \"Name\", \"First name\" || ' ' || \"Last name\" as \"supplier\", \"ID\", \"Mail\" FROM \"Products\" JOIN \"Suppliers\" ON \"Products\".\"Supplier\" = \"Suppliers\".\"ID\"", this.con))
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        products.AddLast(new Product(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetInt32(3), reader.GetString(4)));
                    }
            this.sort.sortProducts(ref products);
        }//O(N)
Пример #11
0
        }//O(1)

        public void allSupplierItems(ref LinkedList <AllSupplierItems> allSupplierItems, int id)  //shows all products from that seller
        {
            while (allSupplierItems.Count != 0)
            {
                allSupplierItems.RemoveFirst();
            }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT * FROM \"Products\" WHERE \"Supplier\" = @ID", this.con)) {
                execute.Parameters.AddWithValue("ID", id);
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        allSupplierItems.AddLast(new AllSupplierItems(reader.GetInt32(0), reader.GetString(1)));
                    }
            }
            this.sort.sortSupplierItems(ref allSupplierItems);
        }//O(N)
Пример #12
0
        }//O(1)

        public void customerOrder(ref LinkedList <CustomerOrder> allCustomerOrder, int id)  //get all customer orders
        {
            while (allCustomerOrder.Count != 0)
            {
                allCustomerOrder.RemoveFirst();
            }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT \"Order ID\", \"Product Number\", \"Name\", \"Quantity\" FROM \"Orderd\" JOIN \"Products\" ON \"Orderd\".\"Product Number\" = \"Products\".\"Product number\" WHERE \"Customer ID\" = @ID", this.con)) {
                execute.Parameters.AddWithValue("ID", id);
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())
                    {
                        allCustomerOrder.AddLast(new CustomerOrder(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetInt32(3)));
                    }
            }
            this.sort.sortCustomerOrder(ref allCustomerOrder);
        }//O(N)
Пример #13
0
        }//O(1)

        //orders:
        public void addOrder(int product, int customer, int amount)
        {
            int count = 0;                  //auto order pk

            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("SELECT COUNT(*) FROM \"Orderd\"", this.con))
                using (Npgsql.NpgsqlDataReader reader = execute.ExecuteReader())
                    while (reader.Read())   //count query result always 1 row, so it's one iteration
                    {
                        count = reader.GetInt32(0) + 1;
                    }
            using (Npgsql.NpgsqlCommand execute = new NpgsqlCommand("INSERT INTO \"Orderd\"(\"Order ID\", \"Product Number\", \"Customer ID\", \"Quantity\") VALUES (@PK, @ProID, @CusID, @quantity)", this.con)) {
                execute.Parameters.AddWithValue("PK", count);
                execute.Parameters.AddWithValue("ProID", product);
                execute.Parameters.AddWithValue("CusID", customer);
                execute.Parameters.AddWithValue("quantity", amount);
                execute.ExecuteNonQuery();
            }
        }//O(1)
Пример #14
0
 public static T GetEnum <T>(this READER reader, int ordinal) where T : Enum
 {
     return((T)(object)reader.GetInt32(ordinal));
 }
Пример #15
0
 public static Int32 GetInt32OrDefault(this READER reader, int ordinal) => reader.IsDBNull(ordinal) ? default : reader.GetInt32(ordinal);
Пример #16
0
 private Resposta carregar(NpgsqlDataReader data_reader)
 {
     Resposta resposta = new Resposta();
     resposta.id_resposta = data_reader.IsDBNull(data_reader.GetOrdinal("ID_RESPOSTA")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_RESPOSTA"));
     resposta.Ds_resposta = data_reader.IsDBNull(data_reader.GetOrdinal("DS_RESPOSTA")) ? "" : data_reader.GetString(data_reader.GetOrdinal("DS_RESPOSTA"));
     resposta.FL_correta = data_reader.IsDBNull(data_reader.GetOrdinal("FL_CORRETA")) ? false : data_reader.GetBoolean(data_reader.GetOrdinal("FL_CORRETA"));
     resposta.Questao_obj.Id_questao = data_reader.IsDBNull(data_reader.GetOrdinal("ID_QUESTAO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_QUESTAO"));
     resposta.Dt_cadastro = data_reader.IsDBNull(data_reader.GetOrdinal("DT_CADASTRO")) ? DateTime.MinValue : data_reader.GetDateTime(data_reader.GetOrdinal("DT_CADASTRO"));
     return resposta;
 }
Пример #17
0
        private Sindico PreencherObjeto(NpgsqlDataReader dataReader)
        {
            int i = 0;
            Sindico obj = new Sindico();
            obj.Id = dataReader.GetInt32(i++);
            obj.Id_endereco = dataReader.GetInt32(i++);
            obj.Id_condominio = dataReader.GetInt32(i++);
            obj.Nome = dataReader.GetString(i++);
            obj.Cpf = dataReader.GetString(i++);
            obj.Rg = dataReader.GetString(i++);

            return obj;
        }
Пример #18
0
        public Usuario carregar(NpgsqlDataReader data_reader)
        {
            Usuario consulta = new Usuario();
            consulta.Id_usuario = data_reader.IsDBNull(data_reader.GetOrdinal("ID_USUARIO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_USUARIO"));
            int id_tipo_usuario = consulta.Id_usuario = data_reader.IsDBNull(data_reader.GetOrdinal("ID_TIPO_USUARIO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_TIPO_USUARIO"));

            if (id_tipo_usuario == (int)Tipo_usuario.ADMINISTRADOR)
            {
                consulta.Tipo = Tipo_usuario.ADMINISTRADOR;
            }
            else if (id_tipo_usuario == (int)Tipo_usuario.ALUNO)
            {
                consulta.Tipo = Tipo_usuario.ALUNO;
            }
            else
            {
                consulta.Tipo = Tipo_usuario.NONE;
            }

            consulta.Nm_usuario = data_reader.IsDBNull(data_reader.GetOrdinal("NM_USUARIO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("NM_USUARIO"));
            consulta.Email_usuario = data_reader.IsDBNull(data_reader.GetOrdinal("EMAIL_USUARIO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("EMAIL_USUARIO"));
            consulta.Senha_usuario = data_reader.IsDBNull(data_reader.GetOrdinal("SENHA_USUARIO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("SENHA_USUARIO"));
            consulta.Link_imagem_usuario = data_reader.IsDBNull(data_reader.GetOrdinal("LINK_IMAGEM_USUARIO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("LINK_IMAGEM_USUARIO"));
            consulta.Dt_cadastro = data_reader.IsDBNull(data_reader.GetOrdinal("DT_CADASTRO")) ? DateTime.MinValue : data_reader.GetDateTime(data_reader.GetOrdinal("DT_CADASTRO"));
            return consulta;
        }
Пример #19
0
        private Morador PreencherObjeto(NpgsqlDataReader dataReader)
        {
            int i = 0;
            Morador obj = new Morador();
            obj.Id = dataReader.GetInt32(i++);
            obj.Id_condominio = dataReader.GetInt32(i++);
            obj.Nome = dataReader.GetString(i++);
            obj.Cpf = dataReader.GetString(i++);
            obj.Rg = dataReader.GetString(i++);
            obj.Numero_apt = dataReader.GetInt32(i++);

            return obj;
        }
Пример #20
0
        private Condominio PreencherObjeto(NpgsqlDataReader dataReader)
        {
            int i = 0;
            Condominio obj = new Condominio();
            obj.Id = dataReader.GetInt32(i++);
            obj.Id_endereco = dataReader.GetInt32(i++);
            obj.Qtd_Apt = dataReader.GetInt32(i++);
            obj.Valor_agua = dataReader.GetFloat(i++);
            obj.Valor_luz = dataReader.GetFloat(i++);
            obj.Valor_gas = dataReader.GetFloat(i++);
            obj.Nome = dataReader.GetString(i++);

            return obj;
        }
Пример #21
0
 private Questao carregar(NpgsqlDataReader data_reader)
 {
     Questao questao = new Questao();
     questao.Id_questao = data_reader.IsDBNull(data_reader.GetOrdinal("ID_QUESTAO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_QUESTAO"));
     questao.Ds_questao = data_reader.IsDBNull(data_reader.GetOrdinal("DS_QUESTAO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("DS_QUESTAO"));
     questao.Curso_obj.Id_curso = data_reader.IsDBNull(data_reader.GetOrdinal("ID_CURSO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_CURSO"));
     questao.Dt_cadastro = data_reader.IsDBNull(data_reader.GetOrdinal("DT_CADASTRO")) ? DateTime.MinValue : data_reader.GetDateTime(data_reader.GetOrdinal("DT_CADASTRO"));
     return questao;
 }
Пример #22
0
        //
        //-------------------------------------------------------------------------------------------------
        //
        public bool ds2browse(string browse_type_in, string browse_category_in, string browse_actor_in,
      string browse_title_in, int batch_size_in, int customerid_out, ref int rows_returned, 
      ref int[] prod_id_out, ref string[] title_out, ref string[] actor_out, ref decimal[] price_out, 
      ref int[] special_out, ref int[] common_prod_id_out, ref double rt)
        {
            // Products table: PROD_ID INT, CATEGORY TINYINT, TITLE VARCHAR(50), ACTOR VARCHAR(50),
              //   PRICE DECIMAL(12,2), SPECIAL TINYINT, COMMON_PROD_ID INT
              int i_row;
              string data_in = null;
              int[] category_out = new int[GlobalConstants.MAX_ROWS];

            #if (USE_WIN32_TIMER)
              long ctr0 = 0, ctr = 0, freq = 0;
            #else
              TimeSpan TS = new TimeSpan();
              DateTime DT0;
            #endif
              switch(browse_type_in)
            {
            case "category":
              Browse_By_Category.Parameters["batch_size_in"].Value = batch_size_in;
              Browse_By_Category.Parameters["category_in"].Value = Convert.ToInt32(browse_category_in);
              data_in = browse_category_in;
              break;
            case "actor":
              Browse_By_Actor.Parameters["batch_size_in"].Value = batch_size_in;
              Browse_By_Actor.Parameters["actor_in"].Value = "\"" + browse_actor_in + "\"";
              data_in = "\"" + browse_actor_in + "\"";
              break;
            case "title":
              Browse_By_Title.Parameters["batch_size_in"].Value = batch_size_in;
              Browse_By_Title.Parameters["title_in"].Value = "\"" + browse_title_in + "\"";
              data_in = "\"" + browse_title_in + "\"";
              break;
            }

            //    Console.WriteLine("Thread {0}: Calling Browse w/ browse_type= {1} batch_size_in= {2}  data_in= {3}",
            //      Thread.CurrentThread.Name, browse_type_in, batch_size_in, data_in);

            #if (USE_WIN32_TIMER)
              QueryPerformanceFrequency(ref freq); // obtain system freq (ticks/sec)
              QueryPerformanceCounter(ref ctr0); // Start response time clock
            #else
              DT0 = DateTime.Now;
            #endif

              try
            {
            switch(browse_type_in)
              {
              case "category":
            Rdr = Browse_By_Category.ExecuteReader();
            break;
              case "actor":
            Rdr = Browse_By_Actor.ExecuteReader();
            break;
              case "title":
            Rdr = Browse_By_Title.ExecuteReader();
            break;
              }

            i_row = 0;
            while (Rdr.Read())
              {
              prod_id_out[i_row] = Rdr.GetInt32(0);
              category_out[i_row] = Rdr.GetInt16(1);
              title_out[i_row] = Rdr.GetString(2);
              actor_out[i_row] = Rdr.GetString(3);
              price_out[i_row] = Rdr.GetDecimal(4);
              special_out[i_row] = Rdr.GetInt16(5);
              common_prod_id_out[i_row] = Rdr.GetInt32(6);
              ++i_row;
              }
            Rdr.Close();
            rows_returned = i_row;
            }
              catch (NpgsqlException e)
            {
            Console.WriteLine("Thread {0}: Error in Browse: {1}", Thread.CurrentThread.Name, e.Message);
            return(false);
            }

            #if (USE_WIN32_TIMER)
              QueryPerformanceCounter(ref ctr); // Stop response time clock
              rt = (ctr - ctr0)/(double) freq; // Calculate response time
            #else
              TS = DateTime.Now - DT0;
              rt = TS.TotalSeconds; // Calculate response time
            #endif

              return(true);
        }
Пример #23
0
        //
        //-------------------------------------------------------------------------------------------------
        //
        public bool ds2purchase(int cart_items, int[] prod_id_in, int[] qty_in, int customerid_out,
      ref int neworderid_out, ref bool IsRollback, ref double rt)
        {
            int i, j;
            #if (USE_WIN32_TIMER)
              long ctr0 = 0, ctr = 0, freq = 0;
            #else
              TimeSpan TS = new TimeSpan();
              DateTime DT0;
            #endif

              //Cap cart_items at 10 for this implementation of stored procedure
              cart_items = System.Math.Min(10, cart_items);

              // Extra, non-stored procedure query to find total cost of purchase
              Decimal netamount_in = 0;
              //Modified by GSK for parameterization of query below - Affects performance in case of Query Caching
              //string cost_query = "select PROD_ID, PRICE from PRODUCTS where PROD_ID in (" + prod_id_in[0];
              //for (i=1; i<cart_items; i++) cost_query = cost_query + "," + prod_id_in[i];
              //cost_query = cost_query + ")";
              ////Console.WriteLine(cost_query);
              //NpgsqlCommand cost_command = new NpgsqlCommand(cost_query, objConn);

              //Parameterized query by GSK
              string cost_query = "select PROD_ID, PRICE from PRODUCTS where PROD_ID in ( @ARG0";
              for ( i = 1 ; i < cart_items ; i++ ) cost_query = cost_query + ", @ARG" + i;
              cost_query = cost_query + ")";
              NpgsqlCommand cost_command = new NpgsqlCommand ( cost_query , objConn );
              string ArgHolder;
              for ( i = 0 ; i < cart_items ; i++ )
              {
              ArgHolder = "@ARG" + i;
              cost_command.Parameters.Add ( ArgHolder , NpgsqlDbType.Integer );
              cost_command.Parameters[ArgHolder].Value = prod_id_in[i];
              //Console.WriteLine (cost_command.Parameters[ArgHolder].Value);
              }

              Rdr = cost_command.ExecuteReader();
              while (Rdr.Read())
            {
            j = 0;
            int prod_id = Rdr.GetInt32(0);
            while (prod_id_in[j] != prod_id) ++j; // Find which product was returned
            netamount_in = netamount_in + qty_in[j] * Rdr.GetDecimal(1);
            //Console.WriteLine(j + " " + prod_id + " " + Rdr.GetDecimal(1));
            }
              Rdr.Close();
              // Can use following code instead if you don't want extra roundtrip to database:
              // Random rr = new Random(DateTime.Now.Millisecond);
              // Decimal netamount_in = (Decimal) (0.01 * (1 + rr.Next(40000)));
              Decimal taxamount_in =  (Decimal) 0.0825 * netamount_in;
              Decimal totalamount_in = netamount_in + taxamount_in;
              //Console.WriteLine(netamount_in);

              Purchase.Parameters["customerid_in"].Value = customerid_out;
              Purchase.Parameters["number_items"].Value = cart_items;
              Purchase.Parameters["netamount_in"].Value = netamount_in;
              Purchase.Parameters["taxamount_in"].Value = taxamount_in;
              Purchase.Parameters["totalamount_in"].Value = totalamount_in;
              Purchase.Parameters["prod_id_in0"].Value = prod_id_in[0]; Purchase.Parameters["qty_in0"].Value = qty_in[0];
              Purchase.Parameters["prod_id_in1"].Value = prod_id_in[1]; Purchase.Parameters["qty_in1"].Value = qty_in[1];
              Purchase.Parameters["prod_id_in2"].Value = prod_id_in[2]; Purchase.Parameters["qty_in2"].Value = qty_in[2];
              Purchase.Parameters["prod_id_in3"].Value = prod_id_in[3]; Purchase.Parameters["qty_in3"].Value = qty_in[3];
              Purchase.Parameters["prod_id_in4"].Value = prod_id_in[4]; Purchase.Parameters["qty_in4"].Value = qty_in[4];
              Purchase.Parameters["prod_id_in5"].Value = prod_id_in[5]; Purchase.Parameters["qty_in5"].Value = qty_in[5];
              Purchase.Parameters["prod_id_in6"].Value = prod_id_in[6]; Purchase.Parameters["qty_in6"].Value = qty_in[6];
              Purchase.Parameters["prod_id_in7"].Value = prod_id_in[7]; Purchase.Parameters["qty_in7"].Value = qty_in[7];
              Purchase.Parameters["prod_id_in8"].Value = prod_id_in[8]; Purchase.Parameters["qty_in8"].Value = qty_in[8];
              Purchase.Parameters["prod_id_in9"].Value = prod_id_in[9]; Purchase.Parameters["qty_in9"].Value = qty_in[9];

            //    Console.WriteLine("Thread {0}: Calling Purchase w/ customerid = {1}  number_items= {2}",
            //      Thread.CurrentThread.Name, customerid_out, cart_items);

            #if (USE_WIN32_TIMER)
              QueryPerformanceFrequency(ref freq); // obtain system freq (ticks/sec)
              QueryPerformanceCounter(ref ctr0); // Start response time clock
            #else
              DT0 = DateTime.Now;
            #endif

              bool deadlocked;
              do
            {
            try
              {
              deadlocked = false;
              neworderid_out = (int) Purchase.ExecuteScalar();
              }
            catch (NpgsqlException e)
              {
              if (e.Code == "40P01")
            {
            deadlocked = true;
            Random r = new Random(DateTime.Now.Millisecond);
            int wait = r.Next(1000);
            Console.WriteLine("Thread {0}: Purchase deadlocked...waiting {1} msec, then will retry",
              Thread.CurrentThread.Name, wait);
            Thread.Sleep(wait); // Wait up to 1 sec, then try again
            }
              else if (e.Code == "P0001")
               {
             deadlocked=false;
             neworderid_out = 0;
               }
              else
            {
            Console.WriteLine("Thread {0}: SQL Error {1} in Purchase: {2}",
              Thread.CurrentThread.Name, e.Code, e.Message);
            return(false);
            }
              }
            } while (deadlocked);

            #if (USE_WIN32_TIMER)
              QueryPerformanceCounter(ref ctr); // Stop response time clock
              rt = (ctr - ctr0)/(double) freq; // Calculate response time
            #else
              TS = DateTime.Now - DT0;
              rt = TS.TotalSeconds; // Calculate response time
            #endif
              if (neworderid_out == 0) IsRollback = true;
              return(true);
        }
Пример #24
0
        private Endereco PreencherObjeto(NpgsqlDataReader dataReader)
        {
            int i = 0;
            Endereco obj = new Endereco();
            obj.Id = dataReader.GetInt32(i++);
            obj.Cidade = dataReader.GetString(i++);
            obj.Estado = dataReader.GetString(i++);
            obj.Cep = dataReader.GetString(i++);
            obj.Bairro = dataReader.GetString(i++);
            obj.Numero = dataReader.GetString(i++);
            obj.Logradouro = dataReader.GetString(i++);
            obj.Complemento = dataReader.GetString(i++);

            return obj;
        }
Пример #25
0
 private void FillBaseEventPropertiesFromRecord(TransactionEvent te, NpgsqlDataReader reader)
 {
     te.LoggedAt = reader.GetDateTime(1);
     te.OccuredAt = reader.GetDateTime(2);
     te.TransactionId = reader.GetInt32(4);
     te.UserId = (reader.IsDBNull(5)) ? null : reader.GetString(5);
     te.Service = reader.GetString(6);
     te.Server = reader.GetString(7);
 }
Пример #26
0
 Aula carregar(NpgsqlDataReader data_reader)
 {
     Aula aula = new Aula();
     aula.Id_aula = data_reader.IsDBNull(data_reader.GetOrdinal("ID_AULA")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_AULA"));
     aula.Tl_aula = data_reader.IsDBNull(data_reader.GetOrdinal("TL_AULA")) ? "" : data_reader.GetString(data_reader.GetOrdinal("TL_AULA"));
     aula.Ds_aula = data_reader.IsDBNull(data_reader.GetOrdinal("DS_AULA")) ? "" : data_reader.GetString(data_reader.GetOrdinal("DS_AULA"));
     aula.Curso_obj.Id_curso = data_reader.IsDBNull(data_reader.GetOrdinal("ID_CURSO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_CURSO"));
     aula.Link_aula = data_reader.IsDBNull(data_reader.GetOrdinal("LINK_AULA")) ? "" : data_reader.GetString(data_reader.GetOrdinal("LINK_AULA"));
     aula.Dt_cadastro = data_reader.IsDBNull(data_reader.GetOrdinal("DT_CADASTRO")) ? DateTime.MinValue : data_reader.GetDateTime(data_reader.GetOrdinal("DT_CADASTRO"));
     return aula;
 }
Пример #27
0
 public Curso carregar(NpgsqlDataReader data_reader)
 {
     Curso curso = new Curso();
     curso.Id_curso = data_reader.IsDBNull(data_reader.GetOrdinal("ID_CURSO")) ? 0 : data_reader.GetInt32(data_reader.GetOrdinal("ID_CURSO"));
     curso.Tl_curso = data_reader.IsDBNull(data_reader.GetOrdinal("TL_CURSO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("TL_CURSO"));
     curso.Ds_curso = data_reader.IsDBNull(data_reader.GetOrdinal("DS_CURSO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("DS_CURSO"));
     curso.Obj_curso = data_reader.IsDBNull(data_reader.GetOrdinal("OBJ_CURSO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("OBJ_CURSO"));
     curso.Topicos_curso = data_reader.IsDBNull(data_reader.GetOrdinal("TOPICOS_CURSO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("TOPICOS_CURSO"));
     curso.Pre_req_curso = data_reader.IsDBNull(data_reader.GetOrdinal("PRE_REQ_CURSO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("PRE_REQ_CURSO"));
     curso.Duracao_curso = data_reader.IsDBNull(data_reader.GetOrdinal("DURACAO_CURSO")) ? "" : data_reader.GetString(data_reader.GetOrdinal("DURACAO_CURSO"));
     curso.Dt_cadastro = data_reader.IsDBNull(data_reader.GetOrdinal("DT_CADASTRO")) ? DateTime.MinValue : data_reader.GetDateTime(data_reader.GetOrdinal("DT_CADASTRO"));
     return curso;
 }
Пример #28
0
        //
        //-------------------------------------------------------------------------------------------------
        //
        public bool ds2login(string username_in, string password_in, ref int customerid_out, ref int rows_returned, 
      ref string[] title_out, ref string[] actor_out, ref string[] related_title_out, ref double rt)
        {
            #if (USE_WIN32_TIMER)
              long ctr0 = 0, ctr = 0, freq = 0;
            #else
              TimeSpan TS = new TimeSpan();
              DateTime DT0;
            #endif
              Login.Parameters["username_in"].Value = username_in;
              Login.Parameters["password_in"].Value = password_in;

            #if (USE_WIN32_TIMER)
              QueryPerformanceFrequency(ref freq); // obtain system freq (ticks/sec)
              QueryPerformanceCounter(ref ctr0); // Start response time clock
            #else
              DT0 = DateTime.Now;
            #endif
               NpgsqlTransaction t ;
              try
            {
            t = objConn.BeginTransaction();
            Rdr = Login.ExecuteReader();
            Rdr.Read();
            customerid_out = Rdr.GetInt32(0);
            }
              catch (NpgsqlException e)
            {
            Console.WriteLine("Thread {0}: Error in Login: {1}", Thread.CurrentThread.Name, e.Message);
            return (false);
            }

              int i_row = 0;
              if ((customerid_out > 0) && Rdr.NextResult())
            {
            while (Rdr.Read())
              {
              title_out[i_row] = Rdr.GetString(0);
              actor_out[i_row] = Rdr.GetString(1);
              related_title_out[i_row] = Rdr.GetString(2);
              ++i_row;
              }
            }
              Rdr.Close();
              t.Commit();
              rows_returned = i_row;

            #if (USE_WIN32_TIMER)
              QueryPerformanceCounter(ref ctr); // Stop response time clock
              rt = (ctr - ctr0)/(double) freq; // Calculate response time
            #else
              TS = DateTime.Now - DT0;
              rt = TS.TotalSeconds; // Calculate response time
            #endif

              return(true);
        }