Exemplo n.º 1
0
        //INSERTAR CHUEQUE
        public int insertarCheque(int codPago, string banco, int nroCuenta, string fecha, int montoCh, int fkCliente)
        {
            NpgsqlConnection conn = DAOCheque.getInstanceDAO();

            conn.Open();

            String sql = "INSERT INTO \"Cheque\" (\"COD\", \"Banco\", \"NroCuenta\", \"Fecha\", \"Monto\", \"FK-ClienteM\") " +
                         "VALUES ((SELECT NEXTVAL('seq')), '" + banco + "', " + nroCuenta + ", TO_DATE('" + fecha + "', 'YYYY-MM-DD'), " +
                         "" + montoCh + ", " + fkCliente + ")";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

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

                String sql2 = "SELECT  e.\"COD\" " +
                              "FROM \"Cheque\" 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\", \"CODCheque\") " +
                      "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);
            }
        }
Exemplo n.º 2
0
 public static DAOCheque getInstance()
 {
     if (DAOCheque.r != null)
     {
         return(r);
     }
     else
     {
         r = new DAOCheque();
         return(r);
     }
 }