コード例 #1
0
        private void comprar(object sender)
        {
            Button bontoninvoco = (Button)sender;
            //Libro libro = (Libro)bontoninvoco.Tag;

            DialogResult result = MessageBox.Show(this.usuario + " Compraras " + bontoninvoco.Tag.ToString() + " ?", "Confirmacion", MessageBoxButtons.YesNoCancel);

            if (result == DialogResult.Yes)
            {
                foreach (Libro i in LibrosServer)
                {
                    if (i.Nombre.Equals(bontoninvoco.Tag.ToString()))
                    {
                        if (System.IO.File.Exists(@"Descargas\" + i.Nombre + ".pdf"))
                        {
                            try
                            {
                                Enlace.AgregarLibroUsuario(i.Isbn, this.usuario);
                                LibrosUsuario.Add(i);

                                MessageBox.Show("Libro Comprado Con Exito");
                            }
                            catch (System.IO.IOException e)
                            {
                                MessageBox.Show(e.Message);
                                //return;
                            }
                        }
                        else
                        {
                            try
                            {
                                File.WriteAllBytes("Descargas\\" + i.Nombre + ".pdf", i.LibroPDF);
                                Enlace.AgregarLibroUsuario(i.Isbn, this.usuario);
                                LibrosUsuario.Add(i);

                                MessageBox.Show("Libro Comprado Con Exito");
                            }
                            catch (System.IO.IOException e)
                            {
                                MessageBox.Show(e.Message);
                                //return;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void comprar()
        {
            DialogResult result = MessageBox.Show(this.usuario + " Compraras " + listBox1.SelectedItem.ToString() + " ?", "Confirmacion", MessageBoxButtons.YesNoCancel);

            if (result == DialogResult.Yes)
            {
                foreach (Libro i in LibrosServer)
                {
                    if (i.Nombre.Equals(listBox1.SelectedItem.ToString()))
                    {
                        if (System.IO.File.Exists(@"Descargas\" + i.Nombre + ".pdf"))
                        {
                            try
                            {
                                Enlace.AgregarLibroUsuario(i.Isbn, this.usuario);
                                LibrosUsuario.Add(i);
                                MessageBox.Show("Libro Comprado Con Exito");
                                this.Close();
                            }
                            catch (System.IO.IOException e)
                            {
                                MessageBox.Show(e.Message);
                                //return;
                            }
                        }
                        else
                        {
                            try
                            {
                                File.WriteAllBytes("Descargas\\" + i.Nombre + ".pdf", i.LibroPDF);
                                Enlace.AgregarLibroUsuario(i.Isbn, this.usuario);
                                LibrosUsuario.Add(i);
                                MessageBox.Show("Libro Comprado Con Exito,");
                                this.Close();
                            }
                            catch (System.IO.IOException e)
                            {
                                MessageBox.Show(e.Message);
                                //return;
                            }
                        }
                    }
                }
            }
        }