Exemplo n.º 1
0
        private void dataGridViewGradovi_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            dataGridViewGradovi.Rows[e.RowIndex].Selected = true;

            if (dataGridViewGradovi.CurrentCell.ColumnIndex.Equals(5) && e.RowIndex != -1)
            {
                int        IdGrada    = Convert.ToInt32(dataGridViewGradovi.Rows[e.RowIndex].Cells[0].Value.ToString());
                FormUpdate formUpdate = new FormUpdate(IdGrada, this);
                formUpdate.lblTrenutniNazivGrada.Text = dataGridViewGradovi.Rows[e.RowIndex].Cells[1].Value.ToString() + ", " + dataGridViewGradovi.Rows[e.RowIndex].Cells[2].Value.ToString();
                formUpdate.ShowDialog();
            }
            if (dataGridViewGradovi.CurrentCell.ColumnIndex.Equals(4) && e.RowIndex != -1)
            {
                int    nIdGrada      = Convert.ToInt32(dataGridViewGradovi.Rows[e.RowIndex].Cells[0].Value.ToString());
                string sImeGrada     = dataGridViewGradovi.Rows[e.RowIndex].Cells[1].Value.ToString();
                string sDrzava       = dataGridViewGradovi.Rows[e.RowIndex].Cells[2].Value.ToString();
                City   oOdabraniGrad = new City {
                    nCityID = nIdGrada, sCityName = sImeGrada, sCountryTag = sDrzava
                };
                var  lVecOdabranihGradova = _CityRepository.DohvatiOdabraneGradoveDb();
                bool bVecPostoji          = true;
                bool bNemaNista           = true;
                foreach (var grad in lVecOdabranihGradova)
                {
                    bNemaNista = false;
                    if (grad.nCityID == nIdGrada)
                    {
                        const string warningMessage = "Grad koji ste odabrali već se nalazi u odabranim gradovima!";
                        const string warningCaption = "Upozorenje";
                        MessageBox.Show(warningMessage, warningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        bVecPostoji = true;
                        break;
                    }
                    else
                    {
                        bVecPostoji = false;
                        bNemaNista  = false;
                    }
                }
                if (bNemaNista)
                {
                    const string message = "Potvrda dodavanja grada za usporedbu\nZa nastavak odaberite Da, za izlazak Ne";
                    const string caption = "Dodavanje grada u odabrane gradove";
                    var          result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        _CityRepository.DodajOdabraneGradove(oOdabraniGrad);
                    }
                }
                if (!bVecPostoji)
                {
                    const string message = "Potvrda dodavanja grada za usporedbu\nZa nastavak odaberite Da, za izlazak Ne";
                    const string caption = "Dodavanje grada u odabrane gradove";
                    var          result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        _CityRepository.DodajOdabraneGradove(oOdabraniGrad);
                    }
                }
            }
            if (dataGridViewGradovi.CurrentCell.ColumnIndex.Equals(3) && e.RowIndex != -1)
            {
                int          IdGradaZaPorgnozu       = Convert.ToInt32(dataGridViewGradovi.Rows[e.RowIndex].Cells[0].Value.ToString());
                string       sNazivGrada             = dataGridViewGradovi.Rows[e.RowIndex].Cells[1].Value.ToString();
                string       sDrzava                 = dataGridViewGradovi.Rows[e.RowIndex].Cells[2].Value.ToString();
                FormPrognoza formPrognoza            = new FormPrognoza(IdGradaZaPorgnozu, sNazivGrada, sDrzava);
                var          lPrognozaZaDane         = _WeatherRepository.PrognozeZaDane(IdGradaZaPorgnozu.ToString());
                var          lPrognozaOdabranigGrada = _WeatherRepository.DajPrognozuZaDanas(IdGradaZaPorgnozu.ToString());
                string       imgUrl;
                formPrognoza.lblForDate.Visible = false;
                foreach (var prognoza in lPrognozaOdabranigGrada)
                {
                    formPrognoza.nazivGradaLbl.Text  = dataGridViewGradovi.Rows[e.RowIndex].Cells[1].Value.ToString() + ", " + dataGridViewGradovi.Rows[e.RowIndex].Cells[2].Value.ToString();
                    formPrognoza.glavnaTempLbl.Text  = GettingRidOfDecimal(prognoza.tempertura) + " °C";
                    formPrognoza.opisVremenaLbl.Text = UppercaseFirst(prognoza.opisVremena);
                    formPrognoza.fealsLikeLbl.Text   = GettingRidOfDecimal(prognoza.ciniSeKao) + " °C";
                    formPrognoza.minTempLbl.Text     = GettingRidOfDecimal(lPrognozaZaDane[0].minTemp) + " °C";
                    formPrognoza.maxTempLbl.Text     = GettingRidOfDecimal(lPrognozaZaDane[0].maxTemp) + " °C";
                    formPrognoza.pressLbl.Text       = prognoza.tlak + " mb";
                    formPrognoza.humadityLbl.Text    = prognoza.vlaga + " %";
                    var VidljivostUkm = Convert.ToInt32(prognoza.vidljiviost) / 1000;
                    formPrognoza.visibilityLbl.Text = VidljivostUkm.ToString() + " km";
                    imgUrl = "http://openweathermap.org/img/wn/" + prognoza.iconId + "@2x.png";
                    formPrognoza.picBoxForWeatherPic.Load(imgUrl);
                    formPrognoza.picBoxForWeatherPic.SizeMode = PictureBoxSizeMode.CenterImage;
                    Console.WriteLine(prognoza.vremenskiParametar);
                }
                //D-1
                formPrognoza.nazivDana1Lbl.Text   = lPrognozaZaDane[0].samoNazivDana;
                formPrognoza.getDay1Lbl.Text      = lPrognozaZaDane[0].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl1.Text = GettingRidOfDecimal(lPrognozaZaDane[0].maxTemp) + " °C";
                formPrognoza.minTempTablLbl1.Text = GettingRidOfDecimal(lPrognozaZaDane[0].minTemp) + " °C";
                formPrognoza.opisTablLbl1.Text    = UppercaseFirst(lPrognozaZaDane[0].opisVremena);
                //D-2
                formPrognoza.nazivDana2Lbl.Text   = lPrognozaZaDane[1].samoNazivDana;
                formPrognoza.getDay2Lbl.Text      = lPrognozaZaDane[1].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl2.Text = GettingRidOfDecimal(lPrognozaZaDane[1].maxTemp) + " °C";
                formPrognoza.minTempTablLbl2.Text = GettingRidOfDecimal(lPrognozaZaDane[1].minTemp) + " °C";
                formPrognoza.opisTablLbl2.Text    = UppercaseFirst(lPrognozaZaDane[1].opisVremena);
                //D-3
                formPrognoza.nazivDana3Lbl.Text   = lPrognozaZaDane[2].samoNazivDana;
                formPrognoza.getDay3Lbl.Text      = lPrognozaZaDane[2].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl3.Text = GettingRidOfDecimal(lPrognozaZaDane[2].maxTemp) + " °C";
                formPrognoza.minTempTablLbl3.Text = GettingRidOfDecimal(lPrognozaZaDane[2].minTemp) + " °C";
                formPrognoza.opisTablLbl3.Text    = UppercaseFirst(lPrognozaZaDane[2].opisVremena);
                //D-4
                formPrognoza.nazivDana4Lbl.Text   = lPrognozaZaDane[3].samoNazivDana;
                formPrognoza.getDay4Lbl.Text      = lPrognozaZaDane[3].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl4.Text = GettingRidOfDecimal(lPrognozaZaDane[3].maxTemp) + " °C";
                formPrognoza.minTempTablLbl4.Text = GettingRidOfDecimal(lPrognozaZaDane[3].minTemp) + " °C";
                formPrognoza.opisTablLbl4.Text    = UppercaseFirst(lPrognozaZaDane[3].opisVremena);
                //D-5
                formPrognoza.nazivDana5Lbl.Text   = lPrognozaZaDane[4].samoNazivDana;
                formPrognoza.getDay5Lbl.Text      = lPrognozaZaDane[4].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl5.Text = GettingRidOfDecimal(lPrognozaZaDane[4].maxTemp) + " °C";
                formPrognoza.minTempTablLbl5.Text = GettingRidOfDecimal(lPrognozaZaDane[4].minTemp) + " °C";
                formPrognoza.opisTablLbl5.Text    = UppercaseFirst(lPrognozaZaDane[4].opisVremena);
                //D-6
                formPrognoza.nazivDana6Lbl.Text   = lPrognozaZaDane[5].samoNazivDana;
                formPrognoza.getDay6Lbl.Text      = lPrognozaZaDane[5].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl6.Text = GettingRidOfDecimal(lPrognozaZaDane[5].maxTemp) + " °C";
                formPrognoza.minTempTablLbl6.Text = GettingRidOfDecimal(lPrognozaZaDane[5].minTemp) + " °C";
                formPrognoza.opisTablLbl6.Text    = UppercaseFirst(lPrognozaZaDane[5].opisVremena);
                //D-7
                formPrognoza.nazivDana7Lbl.Text   = lPrognozaZaDane[6].samoNazivDana;
                formPrognoza.getDay7Lbl.Text      = lPrognozaZaDane[6].samoDanDatum + ".";
                formPrognoza.maxTempTablLbl7.Text = GettingRidOfDecimal(lPrognozaZaDane[6].maxTemp) + " °C";
                formPrognoza.minTempTablLbl7.Text = GettingRidOfDecimal(lPrognozaZaDane[6].minTemp) + " °C";
                formPrognoza.opisTablLbl7.Text    = UppercaseFirst(lPrognozaZaDane[7].opisVremena);
                formPrognoza.ShowDialog();
            }
            if (dataGridViewGradovi.CurrentCell.ColumnIndex.Equals(6) && e.RowIndex != -1)
            {
                int        IdGrada      = Convert.ToInt32(dataGridViewGradovi.Rows[e.RowIndex].Cells[0].Value.ToString());
                FormDelete brisanjeForm = new FormDelete(IdGrada, this);
                brisanjeForm.lblBrisanjeGrada.Text = "Želite li obrisati " + dataGridViewGradovi.Rows[e.RowIndex].Cells[1].Value.ToString();
                brisanjeForm.ShowDialog();
            }
        }