Esempio n. 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (tboxTitle.Text == String.Empty || tboxNewsText.Text == String.Empty || tboxIconPath.Text == "" || tboxIconPath.Text == "Izaberite ikonu")
     {
         MessageBox.Show("Upišite naslov, tekst i ikonu objave.");
         tboxTitle.Focus();
     }
     else
     {
         Announcement objava = new Announcement();
         try
         {
             objava.Title     = tboxTitle.Text;
             objava.Text      = tboxNewsText.Text;
             objava.Expiry    = dtpExpire.Value;
             objava.Expired   = false;
             objava.IsDeleted = false;
             objava.Created   = DateTime.Now;
             if (dtpExpire.Value <= DateTime.Now)
             {
                 MessageBox.Show("Datum i vrijeme isteka objave mora biti veće od današnjeg!");
             }
             else
             {
                 if (!String.IsNullOrEmpty(tboxImagePath.Text) && tboxImagePath.Text != "Izaberite sliku")
                 {
                     Image img = Image.FromFile(tboxImagePath.Text);
                     //Image img = (Image)(new Bitmap(Image.FromFile(tboxImagePath.Text), new Size(80, 80)));
                     MemoryStream ms = new MemoryStream();
                     img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                     objava.Image = ms.ToArray();
                 }
                 if (!String.IsNullOrEmpty(tboxIconPath.Text) && tboxIconPath.Text != "Izaberite ikonu")
                 {
                     //byte[] img2 = System.IO.File.ReadAllBytes(tboxIconPath.Text);
                     Image        img2 = (Image)(new Bitmap(Image.FromFile(tboxIconPath.Text), new Size(80, 80)));
                     MemoryStream ms   = new MemoryStream();
                     img2.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                     objava.Icon = ms.ToArray();
                 }
                 using (DBBL data = new DBBL())
                 {
                     data.InsertAnnouncement(objava);
                     MessageBox.Show("Uspješno ste dodali objavu.");
                     clearFields();
                 }
             }
         }
         catch (Exception ee)
         {
             MessageBox.Show(ee.ToString());
         }
     }
 }