private void SnimiButton_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { List <GPProizvod> gppList = new List <GPProizvod>(); try { foreach (DataGridViewRow row in sastojciDataGridView.Rows) { if (row.Cells[1].Value.ToBool()) { if (row.Cells[4].Value.ToInt() == 0) { throw new Exception("MjernaJedinicaID:" + row.Cells[2].Value.ToString()); } gppList.Add(new GPProizvod() { GotoviProizvodID = gotoviProizvod.GotoviProizvodID, ProizvodID = row.Cells[0].Value.ToInt(), KolicinaUtroska = row.Cells[3].Value.ToDecimal(), MjernaJedinicaID = row.Cells[4].Value.ToInt(), }); } } if (gppList.Count == 0) { throw new Exception("NijeOdabranoNista"); } gotoviProizvod.KategorijaID = kategorijaComboBox.SelectedValue.ToInt(); gotoviProizvod.Naziv = nazivInput.Text; gotoviProizvod.Opis = opisInput.Text; gotoviProizvod.VrijemePripreme = vrijemePripremeInput.Text.ToInt(); gotoviProizvod.Cijena = cijenaInput.Text.ToDecimal(); gotoviProizvod.VidljivostMobile = VidljivodstMobile.Checked; if (string.IsNullOrEmpty(slikaPath.Text)) { // NE MIJENJAT STARU SLIKU //gotoviProizvod.Slika = UIHelper.AddDefaultPictureFull(); //gotoviProizvod.SlikaUmanjeno = UIHelper.AddDefaultPictureResized(); } else { gotoviProizvod.Slika = UIHelper.AddFromFileFull(slikaPath.Text); gotoviProizvod.SlikaUmanjeno = UIHelper.AddFromFileResized(slikaPath.Text); } HttpResponseMessage responseGP = gotoviProizvodiService.PutResponse(gotoviProizvod.GotoviProizvodID, gotoviProizvod); HttpResponseMessage responseGPP = gpproizvodService.PutActionResponse("GPProizvodListEdit", gotoviProizvod.GotoviProizvodID, gppList); if (responseGP.IsSuccessStatusCode && responseGPP.IsSuccessStatusCode) { DialogResult = DialogResult.OK; this.Close(); MessageBox.Show(Messages.success_edited, Messages.success, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (!responseGP.IsSuccessStatusCode) { MessageBox.Show(Messages.error, Messages.error + ": " + responseGP.ReasonPhrase, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!responseGPP.IsSuccessStatusCode) { MessageBox.Show(Messages.error, Messages.error + ": " + responseGPP.ReasonPhrase, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception k) { if (k.Message.Split(':')[0] == "MjernaJedinicaID") { MessageBox.Show(Messages.mj_not_selected + k.Message.Split(':')[1], Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (k.Message == "NijeOdabranoNista") { MessageBox.Show(Messages.nothing_selected_product, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void DodajButton_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { List <GPProizvod> gppList = new List <GPProizvod>(); try { foreach (DataGridViewRow row in sastojciDataGridView.Rows) { if (row.Cells[1].Value.ToBool()) { if (row.Cells[4].Value.ToInt() == 0) { throw new Exception("MjernaJedinicaID:" + row.Cells[2].Value.ToString()); } gppList.Add(new GPProizvod() { ProizvodID = row.Cells[0].Value.ToInt(), KolicinaUtroska = row.Cells[3].Value.ToDecimal(), MjernaJedinicaID = row.Cells[4].Value.ToInt(), }); } } if (gppList.Count == 0) { throw new Exception("NijeOdabranoNista"); } gp.Cijena = cijenaInput.Text.ToDecimal(); gp.KategorijaID = kategorijaComboBox.SelectedValue.ToInt(); gp.Opis = opisInput.Text; gp.VrijemePripreme = vrijemePripremeInput.Text.ToInt(); gp.Naziv = nazivInput.Text; gp.Opis = opisInput.Text; if (string.IsNullOrEmpty(slikaInput.Text)) { gp.Slika = UIHelper.AddDefaultPictureFull(); gp.SlikaUmanjeno = UIHelper.AddDefaultPictureResized(); } else { gp.Slika = UIHelper.AddFromFileFull(slikaInput.Text); gp.SlikaUmanjeno = UIHelper.AddFromFileResized(slikaInput.Text); } HttpResponseMessage responseGP = gotoviProizvodiService.PostResponse(gp); if (responseGP.IsSuccessStatusCode) { gp = responseGP.Content.ReadAsAsync <GotoviProizvod>().Result; gppList.ForEach(x => x.GotoviProizvodID = gp.GotoviProizvodID); HttpResponseMessage responseGPP = gpProizvodService.PostActionResponse("GPProizvodList", gppList); if (responseGPP.IsSuccessStatusCode) { DialogResult = DialogResult.OK; this.Close(); MessageBox.Show(Messages.success_add, Messages.success, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(Messages.error + ": " + responseGPP.ReasonPhrase, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(Messages.error + ": " + responseGP.ReasonPhrase, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception k) { if (k.Message.Split(':')[0] == "MjernaJedinicaID") { MessageBox.Show(Messages.mj_not_selected + " za " + k.Message.Split(':')[1], Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (k.Message == "NijeOdabranoNista") { MessageBox.Show(Messages.nothing_selected_product, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }