Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {//ADD
            using (booksContext db = new booksContext())
            {
                String bookname        = textBox4.Text.ToString();
                int    bookyear        = Int32.Parse(textBox2.Text);
                String bookdescription = textBox1.Text.ToString();
                // int bookid = Int32.Parse(textBox3.Text);
                String imgstorage = "F:\\serverne web program\\IMAGES\\2.jpg";

                // byte[] bookimage = ImageToByteArray(pictureBoxCompanyLogo.Image, pictureBoxCompanyLogo);

                byte[] bookimage = imageToByteArray(pictureBoxCompanyLogo.Image);



                ///image
                ///
                FileStream   fs;
                BinaryReader br;
                string       FileName = imgtextbox.Text;
                byte[]       ImageData;
                fs        = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                br        = new BinaryReader(fs);
                ImageData = br.ReadBytes((int)fs.Length);
                br.Close();
                fs.Close();
                ///images


                // MessageBox.Show(ImageData.ToString() );
                try
                {
                    books book1 = new books {
                        name = bookname, year = bookyear, description = bookdescription, myimage = bookimage
                    };
                    db.books.Add(book1);

                    db.SaveChanges();
                }
                catch (Exception e11)
                {
                    MessageBox.Show("{0} Exception caught." + e11.ToString());
                }
            }
            this.booksTableAdapter.Fill(this.web_lab1db_resDataSet1.books);
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {//DELETE
            using (booksContext db = new booksContext())
            {
                //видалення по id
                int   bookid = Int32.Parse(textBox3.Text);
                books book1  = new books {
                    id = bookid
                };
                //

                db.books.Attach(book1);
                db.books.Remove(book1);

                db.SaveChanges();
            }
            this.booksTableAdapter.Fill(this.web_lab1db_resDataSet1.books);
        }
Beispiel #3
0
        private void button3_Click(object sender, EventArgs e)
        {//EDITякщо нема по ід то додає
            using (booksContext db = new booksContext())
            {
                int    bookid   = Int32.Parse(textBox3.Text);
                String bookname = textBox4.Text.ToString();

                int bookage = Int32.Parse(textBox2.Text);

                books book1 = new books {
                    name = bookname, year = bookage, id = bookid
                };


                db.books.AddOrUpdate(book1);

                db.SaveChanges();
            }

            this.booksTableAdapter.Fill(this.web_lab1db_resDataSet1.books);
        }