Esempio n. 1
0
        //INSERTAR TARJETA
        public int insertarTarjeta(int codPago, string banco, int nroCuenta, string tipo, string fechaV, string marca, int fkCliente)
        {
            NpgsqlConnection conn = DAOEfectivo.getInstanceDAO();

            conn.Open();

            String sql = "INSERT INTO \"Tarjeta\" (\"COD\", \"Banco\", \"NroCuenta\", \"Tipo\", " +
                         "\"FechaVen\", \"Marca\", \"FK-ClienteT\") " +
                         "VALUES ((SELECT NEXTVAL('seq')), '" + banco + "', " + nroCuenta + ", '" + tipo + "', " +
                         " TO_DATE('" + fechaV + "', 'YYYY-MM-DD'), '" + marca + "', " + fkCliente + ")";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            try
            {
                int resp = cmd.ExecuteNonQuery(); //CONTROLAR EXCEPTION DE UNIQUE

                String sql2 = "SELECT  e.\"COD\" " +
                              "FROM \"Tarjeta\" e " +
                              "Order by \"COD\" DESC " +
                              "Limit 1 ";
                NpgsqlCommand    cmd2 = new NpgsqlCommand(sql2, conn);
                NpgsqlDataReader dr   = cmd2.ExecuteReader();

                MetodoPago data = new MetodoPago();

                while (dr.Read())
                {
                    System.Diagnostics.Debug.WriteLine("connection established");
                    data.cod = Int32.Parse(dr[0].ToString());
                }
                dr.Close();

                sql = "INSERT INTO \"Pago-Metodo\" (\"COD\", \"CODPago\", \"CODTarjeta\") " +
                      "VALUES ((SELECT NEXTVAL('seq')), " + codPago + ", " +
                      "" + data.cod + ")";
                cmd = new NpgsqlCommand(sql, conn);
                try
                {
                    resp = cmd.ExecuteNonQuery(); //CONTROLAR EXCEPTION DE UNIQUE
                }
                catch (Exception e)
                {
                    conn.Close();
                    return(0);
                }

                conn.Close();
                return(resp);
            }
            catch (Exception e)
            {
                conn.Close();
                return(0);
            }
        }
Esempio n. 2
0
        //INSERTAR EFECTIVO
        public int insertarEfectivo(int codPago, string moneda, int fkCliente)
        {
            NpgsqlConnection conn = DAOEfectivo.getInstanceDAO();

            conn.Open();

            String sql = "INSERT INTO \"Efectivo\" (\"COD\", \"Moneda\", \"FK-ClienteE\") " +
                         "VALUES ((SELECT NEXTVAL('seq')), '" + moneda + "', " +
                         "" + fkCliente + ")";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            try
            {
                int resp = cmd.ExecuteNonQuery(); //CONTROLAR EXCEPTION DE UNIQUE

                String sql2 = "SELECT  e.\"COD\" " +
                              "FROM \"Efectivo\" e " +
                              "Order by \"COD\" DESC " +
                              "Limit 1 ";
                NpgsqlCommand    cmd2 = new NpgsqlCommand(sql2, conn);
                NpgsqlDataReader dr   = cmd2.ExecuteReader();

                MetodoPago data = new MetodoPago();

                while (dr.Read())
                {
                    System.Diagnostics.Debug.WriteLine("connection established");
                    data.cod = Int32.Parse(dr[0].ToString());
                }
                dr.Close();

                sql = "INSERT INTO \"Pago-Metodo\" (\"COD\", \"CODPago\", \"CODEfect\") " +
                      "VALUES ((SELECT NEXTVAL('seq')), " + codPago + ", " +
                      "" + data.cod + ")";
                cmd = new NpgsqlCommand(sql, conn);
                try
                {
                    resp = cmd.ExecuteNonQuery(); //CONTROLAR EXCEPTION DE UNIQUE
                }
                catch (Exception e)
                {
                    conn.Close();
                    return(0);
                }
                conn.Close();
                return(resp);
            }
            catch (Exception e)
            {
                conn.Close();
                return(0);
            }
        }