using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;

namespace Baza_Reklam
{
    public partial class OgloszenieForm : Form
    {
        private readonly string oglConnectionString = "Data Source=sql.ct.com.pl;Initial Catalog=DANE_OGL_SQL;Persist Security Info=True;User ID=wwwadmin;Password=adm1648;Connection Timeout=60000;Application Name=BazaOgl";
        private readonly REKLAMADataSet.REKLAMARow _reklama;
        private int maxChars;
        private int typOgl;
        private int idOgl;
        private int minNrWydania;
        private string[] fotoFileName = new string[5];
        private bool bUpdateFoto;
        private string fotoFolder;
        private SqlConnection conn;

        static private Dictionary<string, List<string>> MarkaModel = new Dictionary<string, List<string>>();

        public OgloszenieForm(REKLAMADataSet.REKLAMARow reklama, string customerData)
        {
            //TODO: sprawdzanie rozdzielczości zdjęć, min
            //TODO: sprawdzanie max rozmiaru plików zdjęć (?)
            //TODO: pobieranie ogłoszeń z otomoto na podstawie id ogłoszenia


            InitializeComponent();
            _reklama = reklama;

            idOgl = 0;

            try
            {
                fotoFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                if (string.IsNullOrEmpty(fotoFolder))
                    fotoFolder = Environment.CurrentDirectory;

                fotoFolder += @"\CT\BazaReklam\OglFoto\";

                if (!Directory.Exists(fotoFolder))
                    Directory.CreateDirectory(fotoFolder);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void OgloszenieForm_Load(object sender, EventArgs e)
        {
            SqlConnection connOgl = null;

            try
            {
                bUpdateFoto = false;
                maxChars = 1;

                switch (_reklama.MOD_TYP)
                {
                    case "billboard":
                        maxChars = 450;
                        typOgl = 18;
                        break;

                    case "space":
                        maxChars = 1200;
                        typOgl = 32;
                        break;

                    case "standard":
                    default:
                        maxChars = 350;
                        typOgl = 33;
                        break;
                }

                this.Text = "Edycja " + _reklama.ID_REKLAMY;

                labelIloscZnakow.Text = string.Format("ilość znaków: {0}/{1}", 0, maxChars);

                connOgl = new SqlConnection(oglConnectionString);
                connOgl.Open();

                conn = new SqlConnection(ConnString.getConnString().Value);
                conn.Open();

                SqlCommand cmdOlg = connOgl.CreateCommand();
                SqlDataReader rdr;

                cmdOlg.CommandText = "SELECT TOP 1 NRW FROM DATA_WYDANIA WHERE TYT=11 AND Zamkniecie>GETDATE() ORDER BY DATA_W";
                minNrWydania = (int)(short)cmdOlg.ExecuteScalar();
                nrWydaniaTextBox.Text = minNrWydania.ToString();

                if (MarkaModel.Count == 0)
                {
                    cmdOlg.CommandText = "select distinct MARKA, TYP from _pojazdy " +
                                "where id_dzial in (select DZIAŁ_NR from OGL_DZIAŁ where TYTUL = 1) " +
                                "order by MARKA, TYP";

                    rdr = cmdOlg.ExecuteReader();
                    while (rdr.Read())
                    {
                        if (!MarkaModel.ContainsKey(rdr["MARKA"].ToString()))
                            MarkaModel.Add(rdr["MARKA"].ToString(), new List<string>());

                        MarkaModel[rdr["MARKA"].ToString()].Add(rdr["TYP"].ToString());
                    }
                    rdr.Close();
                }

                connOgl.Close();

                this.webBrowser1.Navigate("about:blank");

                foreach (string s2 in MarkaModel.Keys)
                    markaComboBox.Items.Add(s2);

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT id, idTytul, nrWydania, typ_ogl, krotnosc, marka, typ, typ_d, rok_prod, cena, tresc, adres, nr_kuponu, status " +
                        "FROM Ogloszenia " +
                        "WHERE idReklamy='" + _reklama.ID_REKLAMY + "'";

                rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    rdr.Read();

                    idOgl = Convert.ToInt32(rdr["id"]);
                    markaComboBox.Text = rdr["marka"].ToString();
                    typComboBox.Text = rdr["typ"].ToString();
                    typdTextBox.Text = rdr["typ_d"].ToString();
                    rokProdTextBox.Text = rdr["rok_prod"].ToString();
                    cenaTextBox.Text = rdr["cena"].ToString();
                    opisTextBox.Text = rdr["tresc"].ToString();
                    klientTextBox.Text = rdr["adres"].ToString();
                    int status = Convert.ToInt32(rdr["status"]);
                    rdr.Close();

                    string fname;
                    PictureBox[] pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5 };
                    string[] extPicture = new string[] { ".jpg", ".jpeg", ".jpe", ".bmp", ".dib", ".gif", ".png", ".tiff", ".tif", ".wmf", ".emf" };
                    int n = 0;
                    for (int i = 0; i < fotoFileName.Length; ++i)
                    {
                        for (int k = 0; k < extPicture.Length; ++k)
                        {
                            fname = fotoFolder + "\\" + _reklama.ID_REKLAMY + (i > 0 ? "_" + (i + 1) : "") + extPicture[k];

                            if (File.Exists(fname))
                            {
                                fotoFileName[i] = fname;
                                pictureBoxes[n].Visible = true;
                                pictureBoxes[n].Load(fname);
                                ++n;
                                break;
                            }
                        }
                    }

                    if (status > 0)
                    {
                        Control[] ctrls = { markaComboBox, typComboBox, typdTextBox, rokProdTextBox, cenaTextBox, opisTextBox, klientTextBox, toolStrip1, btnOk, btnAccept, nrWydaniaTextBox };
                        foreach (Control ctrl in ctrls)
                            ctrl.Enabled = false;

                        btnAnuluj.Text = "Zamknij";

                        if (status == 1)
                        {
                            labelStatus.ForeColor = Color.Red;
                            labelStatus.Text = "status: zaakceptowane (zatwierdzone do realizacji)";
                        }
                        else if (status == 2)
                        {
                            labelStatus.ForeColor = Color.Green;
                            labelStatus.Text = "status: pobrane do produkcji";
                        }
                    }
                    else
                    {
                        labelStatus.Text = "status: otwarte (w trakcie edycji - nie zatwierdzone do realizacji)";
                        labelStatus.ForeColor = Color.Blue;
                    }

                    UpdatePreview();
                }
                else
                    labelStatus.Text = "status: nowe";

                if (typOgl != 32)
                {
                    toolStripBtnAddFoto.Enabled = pictureBox1.Image == null;
                    toolStripBtnClipboard.Enabled = pictureBox1.Image == null;
                }
                else
                {
                    toolStripBtnAddFoto.Enabled = pictureBox5.Image == null;
                    toolStripBtnClipboard.Enabled = pictureBox5.Image == null;
                }

                toolStripBtnDel.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (connOgl != null &&
                    connOgl.State == System.Data.ConnectionState.Open)
                    connOgl.Close();
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (SaveOgl())
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private bool SaveOgl()
        {
            try
            {
                int n = markaComboBox.Text.Length +
                         typComboBox.Text.Length +
                         typdTextBox.Text.Length +
                         rokProdTextBox.Text.Length +
                         cenaTextBox.Text.Length +
                         opisTextBox.Text.Length +
                         klientTextBox.Text.Length + 10;

                if (n > maxChars)
                {
                    MessageBox.Show(string.Format("Przekroczono dopuszczlaną ilość znaków w ogłoszeniu.\nMaksymalna ilość znaków to {0}", maxChars), "Baza reklam", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }

                int nrWydania;
                int.TryParse(nrWydaniaTextBox.Text, out nrWydania);
                if (nrWydania <= 0)
                {
                    MessageBox.Show("Błędny nr wydania!", "Baza reklam", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
                else if (nrWydania < minNrWydania)
                {
                    MessageBox.Show("Błędny nr wydania!\nNr wydania nie może być mniejszy niż " + minNrWydania + ".", "Baza reklam", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }

                // aktualizujemy zdjęcia
                string fnameSrc, fnameDest;
                string pathDest, pathNew1;
                for (int i = 0; i < fotoFileName.Length; ++i)
                {
                    if (string.IsNullOrEmpty(fotoFileName[i]))
                        break;

                    fnameSrc = Path.GetFileNameWithoutExtension(fotoFileName[i]);
                    fnameDest = _reklama.ID_REKLAMY + (i > 0 ? "_" + (i + 1) : "");
                    if (fnameSrc.ToUpper() != fnameDest.ToUpper())
                    {
                        pathDest = Path.GetDirectoryName(fotoFileName[i]) + "\\" + fnameDest + Path.GetExtension(fotoFileName[i]);
                        if (File.Exists(pathDest))
                        {
                            pathNew1 = pathDest + "_tmp_" + Path.GetExtension(fotoFileName[i]);
                            if (File.Exists(pathNew1))
                                File.Delete(pathNew1);

                            File.Move(pathDest, pathNew1);

                            for (int j = i; j < fotoFileName.Length; ++j)
                                if (string.Compare(fotoFileName[j], pathDest, true) == 0)
                                {
                                    fotoFileName[j] = pathNew1;
                                    break;
                                }
                        }

                        File.Move(fotoFileName[i], pathDest);
                        fotoFileName[i] = pathDest;
                    }
                }

                int krotnosc = _reklama.KROTNOŚĆ;


                SqlCommand cmd = conn.CreateCommand();

                if (idOgl > 0)
                {
                    cmd.CommandText = "UPDATE Ogloszenia SET idTytul=@idTytul, nrWydania=@nrWydania, typ_ogl=@typ_ogl, krotnosc=@krotnosc, " +
                            "marka=@marka, typ=@typ, typ_d=@typ_d, rok_prod=@rok_prod, cena=@cena, tresc=@tresc, adres=@adres " +
                            "WHERE id=" + idOgl;
                }
                else
                {
                    cmd.CommandText = "INSERT INTO Ogloszenia(idReklamy, idTytul, nrWydania, typ_ogl, krotnosc, marka, typ, typ_d, rok_prod, cena, tresc, adres) " +
                                      "VALUES(@idReklamy, @idTytul, @nrWydania, @typ_ogl, @krotnosc, @marka, @typ, @typ_d, @rok_prod, @cena, @tresc, @adres)";
                    cmd.Parameters.Add(new SqlParameter("idReklamy", _reklama.ID_REKLAMY));
                }

                cmd.Parameters.Add(new SqlParameter("idTytul", _reklama.TYTUŁ));
                cmd.Parameters.Add(new SqlParameter("nrWydania", nrWydania));
                cmd.Parameters.Add(new SqlParameter("typ_ogl", typOgl));
                cmd.Parameters.Add(new SqlParameter("krotnosc", _reklama.KROTNOŚĆ));
                cmd.Parameters.Add(new SqlParameter("marka", markaComboBox.Text));
                cmd.Parameters.Add(new SqlParameter("typ", typComboBox.Text));
                cmd.Parameters.Add(new SqlParameter("typ_d", typdTextBox.Text));
                cmd.Parameters.Add(new SqlParameter("rok_prod", rokProdTextBox.Text));
                cmd.Parameters.Add(new SqlParameter("cena", cenaTextBox.Text));
                cmd.Parameters.Add(new SqlParameter("tresc", opisTextBox.Text));
                cmd.Parameters.Add(new SqlParameter("adres", klientTextBox.Text));

                cmd.ExecuteNonQuery();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }

        private void btnAnuluj_Click(object sender, EventArgs e)
        {
            if (idOgl > 0 || !bUpdateFoto)
                return;

            foreach (string s1 in fotoFileName)
            {
                try
                {
                    if (File.Exists(s1))
                        File.Delete(s1);
                }
                catch
                {
                    ;
                }
            }
        }

        private void markaComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdatePreview();
        }

        private void typComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdatePreview();
        }

        private void markaComboBox_Leave(object sender, EventArgs e)
        {
            typComboBox.Items.Clear();

            if (!MarkaModel.ContainsKey(markaComboBox.Text))
                return;

            foreach (string s1 in MarkaModel[markaComboBox.Text])
            {
                typComboBox.Items.Add(s1);
            }
        }

        private void UpdatePreview()
        {
            int n = markaComboBox.Text.Length +
                typComboBox.Text.Length +
                typdTextBox.Text.Length +
                rokProdTextBox.Text.Length +
                cenaTextBox.Text.Length +
                opisTextBox.Text.Length +
                klientTextBox.Text.Length + 10;

            labelIloscZnakow.Text = string.Format("ilość znaków: {0}/{1}", n, maxChars);

            if (n > maxChars)
                labelIloscZnakow.ForeColor = System.Drawing.Color.Red;
            else
                labelIloscZnakow.ForeColor = System.Drawing.Color.DarkBlue;

            string sformat;
            switch (_reklama.MOD_TYP)
            {
                case "billboard":
                    sformat = "<html><body>" +
                        "<table style=\"width: 300px; font-size: 10pt; font-family: Tahoma;\">" +
                        " <tr><td colspan=2 align=\"center\">" +
                        "     <img height=\"218\" src=\"{4}\" width=\"290\" alt=\"foto\" /></td></tr>" +
                        " <tr><td bgcolor=\"#eeeeee\" colspan=2><span style=\"font-size: 11pt\"><b>{0}</b> {1}</span></td></tr>" +
                        " <tr><td><b>cena: {2} </b> {3}</td></tr>" +
                        "</table>" +
                        "</body></html>";
                    break;

                case "space":
                    sformat = "<html><body>" +
                        "<table style=\"width: 300px; font-size: 10pt; font-family: Tahoma;\" bgcolor=\"lightyellow\">" +
                        " <tr><td colspan=2><span style=\"font-size: 11pt\"><b>{0}</b> {1}</span></td></tr>" +
                        " <tr><td colspan=2 align=\"center\">" +
                        "     <img height=\"218\" src=\"{4}\" width=\"290\" alt=\"foto\" /></td></tr>" +
                        " <tr><td align=\"center\"><img src=\"{5}\" height=\"109\" width=\"143\" alt=\"foto\" /></td>" +
                        "     <td align=\"center\"><img src=\"{6}\" height=\"109\" width=\"143\" alt=\"foto\" /></td></tr>" +
                        " <tr><td align=\"center\"><img src=\"{7}\" height=\"109\" width=\"143\" alt=\"foto\" /></td>" +
                        "     <td align=\"center\"><img src=\"{8}\" height=\"109\" width=\"143\" alt=\"foto\" /></td></tr>" +
                        " <tr><td colspan=2><b>cena: {2} </b> {3}</td></tr>" +
                        "</table>" +
                        "</body></html>";
                    break;

                case "standard":
                default:
                    sformat = "<html><body>" +
                        "<table style=\"width: 300px; font-size: 10pt; font-family: Tahoma;\">" +
                        " <tr><td bgcolor=\"#eeeeee\" colspan=2><span style=\"font-size: 11pt\"><b>{0}</b> {1}</span></td></tr>" +
                        " <tr valign=\"top\">" +
                        "  <td align=\"center\" style=\"width: 140px\"><img src=\"{4}\" height=\"109\" width=\"143\" alt=\"foto\" /></td>" +
                        "  <td><b>cena: {2} </b> {3}</td>" +
                        " </tr>" +
                        "</table>" +
                        "</body></html>";
                    break;
            }

            this.webBrowser1.DocumentText = string.Format(sformat,
                (markaComboBox.Text + " " + typComboBox.Text + " " + typdTextBox.Text).ToUpper(),
                rokProdTextBox.Text,
                cenaTextBox.Text,
                opisTextBox.Text + ", " + klientTextBox.Text,
                fotoFileName[0],
                fotoFileName[1],
                fotoFileName[2],
                fotoFileName[3],
                fotoFileName[4]);
        }

        private void toolStripBtnAddFoto_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
                return;

            AddFoto(openFileDialog1.FileName, null);
        }

        private void AddFoto(string filename, Image clipboardImg)
        {
            try
            {
                PictureBox[] pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5 };

                int i = 0;
                int n = 0;
                string fname;

                foreach (PictureBox pb in pictureBoxes)
                {
                    if (pb.Image == null)
                    {                        
                        do
                        {
                            fname = fotoFolder + _reklama.ID_REKLAMY;
                            if (i > 0)
                                fname += "_" + (i + 1);

                            if (n > 0)
                                fname += "(" + n + ")";

                            if (!string.IsNullOrEmpty(filename))
                                fname += Path.GetExtension(filename);
                            else
                                fname += ".jpg";

                            ++n;
                        }
                        while (File.Exists(fname));


                        if (!string.IsNullOrEmpty(filename))
                        {
                            pb.Load(filename);
                            File.Copy(filename, fname);
                        }
                        else
                        {
                            pb.Image = clipboardImg;
                            clipboardImg.Save(fname, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }

                        pb.Visible = true;

                        fotoFileName[i] = fname;
                        bUpdateFoto = true;
                        break;
                    }
                    ++i;
                }

                if (typOgl != 32)
                {
                    toolStripBtnAddFoto.Enabled = pictureBox1.Image == null;
                    toolStripBtnClipboard.Enabled = pictureBox1.Image == null;
                }
                else
                {
                    toolStripBtnAddFoto.Enabled = pictureBox5.Image == null;
                    toolStripBtnClipboard.Enabled = pictureBox5.Image == null;
                }

                UpdatePreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Baza reklam", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void pictureBox_Click(object sender, EventArgs e)
        {
            MarkPictureBox((PictureBox)sender);
        }

        private void MarkPictureBox(PictureBox pb)
        {
            PictureBox[] pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5 };

            foreach (PictureBox pb1 in pictureBoxes)
            {
                if (!pb1.Equals(pb))
                    pb1.BorderStyle = BorderStyle.None;

                pb1.Visible = pb1.Image != null;
            }

            pb.BorderStyle = BorderStyle.FixedSingle;

            PictureBox lastFullPb = null;
            foreach (PictureBox pb1 in pictureBoxes)
            {
                if (pb1.Image != null)
                    lastFullPb = pb1;
            }

            toolStripButtonLeft.Enabled = !pb.Equals(pictureBox1);
            toolStripButtonRight.Enabled = lastFullPb != null && !pb.Equals(lastFullPb);
            toolStripBtnDel.Enabled = pb.Image != null;
        }

        private void comboBox_TextUpdate(object sender, EventArgs e)
        {
            UpdatePreview();
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            UpdatePreview();
        }

        private void toolStripBtnDel_Click(object sender, EventArgs e)
        {
            PictureBox[] pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5 };

            for (int i = 0; i < pictureBoxes.Length; ++i)
            {
                if (pictureBoxes[i].Image != null &&
                    pictureBoxes[i].BorderStyle == BorderStyle.FixedSingle)
                {
                    try
                    {
                        File.Delete(fotoFileName[i]);
                    }
                    catch { ; }

                    int n = i;
                    for (; i < pictureBoxes.Length; ++i)
                    {
                        pictureBoxes[i].Image = i < (pictureBoxes.Length - 1) ? pictureBoxes[i + 1].Image : null;
                        fotoFileName[i] = i < (pictureBoxes.Length - 1) ? fotoFileName[i + 1] : "";
                    }

                    MarkPictureBox(pictureBoxes[n]);

                    bUpdateFoto = true;
                    UpdatePreview();

                    break;
                }
            }

            if (typOgl != 32)
            {
                toolStripBtnAddFoto.Enabled = pictureBox1.Image == null;
                toolStripBtnClipboard.Enabled = pictureBox1.Image == null;
            }
            else
            {
                toolStripBtnAddFoto.Enabled = pictureBox5.Image == null;
                toolStripBtnClipboard.Enabled = pictureBox5.Image == null;
            }
        }

        private void toolStripButtonLeft_Click(object sender, EventArgs e)
        {
            PictureBox[] pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5 };

            for (int i = 0; i < pictureBoxes.Length; ++i)
            {
                if (pictureBoxes[i].Image != null &&
                    pictureBoxes[i].BorderStyle == BorderStyle.FixedSingle)
                {
                    if (i > 0)
                    {
                        Image img1 = pictureBoxes[i].Image;
                        pictureBoxes[i].Image = pictureBoxes[i - 1].Image;
                        pictureBoxes[i - 1].Image = img1;
                        MarkPictureBox(pictureBoxes[i - 1]);

                        string s1 = fotoFileName[i];
                        fotoFileName[i] = fotoFileName[i - 1];
                        fotoFileName[i - 1] = s1;

                        bUpdateFoto = true;
                        UpdatePreview();
                    }

                    break;
                }
            }
        }

        private void toolStripButtonRight_Click(object sender, EventArgs e)
        {
            PictureBox[] pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5 };

            for (int i = 0; i < pictureBoxes.Length; ++i)
            {
                if (pictureBoxes[i].Image != null &&
                    pictureBoxes[i].BorderStyle == BorderStyle.FixedSingle)
                {
                    if (i < (pictureBoxes.Length - 1))
                    {
                        Image img1 = pictureBoxes[i].Image;
                        pictureBoxes[i].Image = pictureBoxes[i + 1].Image;
                        pictureBoxes[i + 1].Image = img1;
                        MarkPictureBox(pictureBoxes[i + 1]);

                        string s1 = fotoFileName[i];
                        fotoFileName[i] = fotoFileName[i + 1];
                        fotoFileName[i + 1] = s1;

                        bUpdateFoto = true;
                        UpdatePreview();
                    }

                    break;
                }
            }
        }

        private void OgloszenieForm_Shown(object sender, EventArgs e)
        {
            UpdatePreview();
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Po zaakceptowaniu ogłoszenie zostanie przekazane do produkcji, jego dalsza edycja nie będzie możliwa.\nCzy chcesz kontynuować?",
                            "Baza reklam", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                return;

            if (!SaveOgl())
                return;

            try
            {
                int nrWydania;
                int.TryParse(nrWydaniaTextBox.Text, out nrWydania);

                OgloszenieWaitForm dlgWait = new OgloszenieWaitForm(nrWydania, fotoFileName);
                DialogResult dr1 = dlgWait.ShowDialog();
                if (dr1 == DialogResult.OK)
                {
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "UPDATE Ogloszenia SET status=1 WHERE idReklamy='" + _reklama.ID_REKLAMY + "'";
                    cmd.ExecuteNonQuery();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Akceptacja ogłoszenie nie została zakończona prowidłowo.\n" + ex.Message, "Baza reklam", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {

        }

        private void toolStripBtnClipboard_Click(object sender, EventArgs e)
        {
            if (Clipboard.ContainsImage())
                AddFoto(null, Clipboard.GetImage());

            if (Clipboard.ContainsFileDropList())
            {
                System.Collections.Specialized.StringCollection sa =  Clipboard.GetFileDropList();

                //TODO: dodać obsługę plików zdjęć
            }
        }
    }
}