private void pozycjeZwrotuGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1 && e.RowIndex < pozycjeZwrotuGrid.Rows.Count) { if (e.ColumnIndex == 2) { Zwrot.PrzeliczWartosc(); } } }
private void zformularzaButton_Click(object sender, EventArgs e) { var form = new ZwrotFormularzForm(); if (Zwrot.Kontrahent != null) { Enova.Business.Old.DB.Web.Kontrahent kontrahent = Zwrot.Kontrahent; form.KontrahentId = Enova.Business.Old.Core.ContextManager.DataContext.Kontrahenci.Where(k => k.Guid == kontrahent.Guid).Select(k => k.ID).FirstOrDefault(); } DialogResult result = form.ShowDialog(); if (result == DialogResult.OK && form.DataSource != null) { var pozycje = form.DataSource.Where(p => p.IloscZam != null && p.IloscZam.Value > 0).OrderBy(p => p.Kod); if (pozycje.Count() > 0) { PozycjaAdding(); } foreach (var p in pozycje) { var produkt = webProdukt(p.TowarGuid.Value); if (produkt != null) { Zwrot zwrot = (Zwrot)this.DataSource; zwrot.Pozycje.Add(new PozycjaZwrotu() { Cena = produkt.Cena == null ? 0 : produkt.Cena.Value, Deleted = false, Guid = Guid.NewGuid(), Ident = Zwrot.GetMaxIdent() + 1, Ilosc = p.IloscZam.Value, Synchronizacja = (int)Enova.Business.Old.Types.RowSynchronizeOld.NotsynchronizedNew, Towar = produkt, TowarNazwa = produkt.Nazwa }); } } loadPozycje(); Zwrot.PrzeliczWartosc(); goToLastRow(); } }
private void dodajPozycje(Enova.Business.Old.DB.Towar towar = null) { Produkt local = null; if (towar == null) { var form = WyborForm; form.ShowDialog(); this.Activate(); local = (Produkt)form.SelectedItem; } else { local = (Produkt)towar; } if (local != null && checkObrot(local)) { PozycjaAdding(); var pozycja = new Enova.Business.Old.DB.Web.PozycjaZwrotu() { Towar = local, Guid = Guid.NewGuid(), Ident = Zwrot.GetMaxIdent() + 1, TowarNazwa = local.Kod + " - " + local.Nazwa, Cena = local.Cena == null ? 0 : local.Cena.Value, Ilosc = 1, Deleted = false, Synchronizacja = (int)Enova.Business.Old.Types.RowSynchronizeOld.NotsynchronizedNew }; Zwrot.Pozycje.Add(pozycja); pozycjeZwrotuGrid.Focus(); loadPozycje(); Zwrot.PrzeliczWartosc(); goToLastRow(); } }
private void generujZwrotButton_Click(object sender, EventArgs e) { if (MessageBox.Show("Czy napewno chcesz wygenerować zwrot", "AbakTools", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { this.Cursor = Cursors.WaitCursor; this.Enabled = false; var dc = Enova.Business.Old.Core.ContextManager.WebContext; Zwrot nowyZwrot = new Zwrot() { Guid = Guid.NewGuid(), DataDodania = DateTime.Now, DataModyfikacji = DateTime.Now, Deleted = false, IloscPaczek = 0, SkorygowanyWCalosci = false, Synchronizacja = (int)RowSynchronizeOld.NotsynchronizedNew, Kontrahent = this.Zwrot.Kontrahent, Opis = "Zwrot z pozycji nieskorygowanych ze zwrotu " + this.Zwrot.ID, OstatniStatus = dc.StatusyZwrotow.Where(sz => sz.Typ == (int)TypStatusuZwrotu.ZwrotZNieskorygowanych).FirstOrDefault() }; nowyZwrot.HistoriaZwrotu.Add(new HistoriaZwrotu() { Data = DateTime.Now, Deleted = false, Guid = Guid.NewGuid(), Status = dc.StatusyZwrotow.Where(sz => sz.Typ == (int)TypStatusuZwrotu.ZwrotZNieskorygowanych).FirstOrDefault(), Synchronize = (int)RowSynchronizeOld.NotsynchronizedNew, Uzytkownik = User.LoginedUser }); dc.OptimisticSaveChanges(); dc.Refresh(System.Data.Objects.RefreshMode.StoreWins, nowyZwrot); var pozycje = this.Zwrot.Pozycje.Where(p => p.Deleted == false && p.Synchronizacja != (int)RowSynchronizeOld.NotsynchronizedDelete && (p.IloscSkorygowana == null || p.IloscSkorygowana < p.Ilosc)).ToList(); foreach (var poz in pozycje) { var nowaPozycja = new PozycjaZwrotu() { Cena = poz.Cena, Guid = Guid.NewGuid(), Deleted = false, Ilosc = poz.IloscPozostaloDoSkorygowania, IloscOrg = poz.IloscPozostaloDoSkorygowania, IloscSkorygowana = 0, Opis = poz.Opis, Synchronizacja = (int)RowSynchronizeOld.NotsynchronizedNew, Towar = poz.Towar, TowarNazwa = poz.TowarNazwa }; nowyZwrot.Pozycje.Add(nowaPozycja); if (poz.IloscOrg == null) { poz.IloscOrg = poz.Ilosc; } poz.Ilosc -= nowaPozycja.Ilosc; } this.Zwrot.SkorygowanyWCalosci = true; this.Zwrot.PrzeliczWartosc(); nowyZwrot.ReIdentPozycje(); nowyZwrot.PrzeliczWartosc(); dc.OptimisticSaveChanges(); dc.Refresh(System.Data.Objects.RefreshMode.StoreWins, this.Zwrot); dc.Refresh(System.Data.Objects.RefreshMode.StoreWins, nowyZwrot); this.Enabled = true; this.Cursor = Cursors.Default; this.Close(); MessageBox.Show("Wygenerowano nowy zwrot o numerze " + nowyZwrot.ID); } }
private void rozdzielButton_Click(object sender, EventArgs e) { if (this.pozycjeZwrotuGrid.SelectedRows.Count > 0 && MessageBox.Show("Czy napewno chcesz rozdzielić zwrot?", "EnovaTools", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes) { List <PozycjaZwrotu> pozycje = new List <PozycjaZwrotu>(); foreach (DataGridViewRow row in this.pozycjeZwrotuGrid.SelectedRows) { if (row.DataBoundItem != null) { pozycje.Add((PozycjaZwrotu)row.DataBoundItem); } } Zwrot nowyZwrot = new Zwrot() { DataDodania = DateTime.Now, DataModyfikacji = DateTime.Now, Deleted = false, Guid = Guid.NewGuid(), IloscPaczek = 0, Kontrahent = this.Zwrot.Kontrahent, Synchronizacja = (int)RowSynchronizeOld.NotsynchronizedNew, }; DbContext.SaveChanges(); DbContext.Refresh(RefreshMode.StoreWins, nowyZwrot); nowyZwrot.HistoriaZwrotu.Add(new HistoriaZwrotu() { Data = DateTime.Now, Deleted = false, Guid = Guid.NewGuid(), Status = this.Zwrot.OstHistoriaZwrotu.Status, Synchronize = (int)RowSynchronizeOld.NotsynchronizedNew, Uzytkownik = User.LoginedUser, }); foreach (var pozycja in pozycje) { nowyZwrot.Pozycje.Add(new PozycjaZwrotu() { Cena = pozycja.Cena, Deleted = false, Guid = Guid.NewGuid(), Ident = nowyZwrot.GetMaxIdent() + 1, Ilosc = pozycja.Ilosc, Opis = pozycja.Opis, IlocsDeklarowana = pozycja.IlocsDeklarowana, Synchronizacja = (int)RowSynchronizeOld.NotsynchronizedNew, Towar = pozycja.Towar, TowarNazwa = pozycja.TowarNazwa }); pozycja.Deleted = true; } this.Zwrot.ReIdentPozycje(); this.Zwrot.PrzeliczWartosc(); nowyZwrot.ReIdentPozycje(); nowyZwrot.PrzeliczWartosc(); DbContext.SaveChanges(); DbContext.Refresh(RefreshMode.StoreWins, nowyZwrot); this.loadPozycje(); MessageBox.Show("Stworzono nowy zwrot o numerze " + nowyZwrot.ID); } }
private void połaczButton_Click(object sender, EventArgs e) { if (this.DataGrid.SelectedRows.Count > 1 && MessageBox.Show("czy napewno chcesz połaczyć zwroty?", "EnovaTools", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { Kontrahent kontrahent = null; StatusZwrotu status = null; List <Zwrot> zwroty = new List <Zwrot>(); foreach (DataGridViewRow row in this.DataGrid.SelectedRows) { if (row.DataBoundItem != null) { Zwrot zwrot = (Zwrot)row.DataBoundItem; if (kontrahent == null) { kontrahent = zwrot.Kontrahent; } else if (kontrahent.ID != zwrot.KontrahentID) { MessageBox.Show("Nie można łaczyć zwrotów dla różnych kontrahentów"); return; } if (status == null) { status = zwrot.OstHistoriaZwrotu.Status; } else if (status.ID != zwrot.OstHistoriaZwrotu.StatusID) { MessageBox.Show("Nie można łaczyć zwrotów o różnym statusie"); return; } zwroty.Add(zwrot); } } if (zwroty.Count > 1) { string opis = "Połączone zwroty: "; Zwrot nowyZwrot = new Zwrot() { DataDodania = DateTime.Now, DataModyfikacji = DateTime.Now, Deleted = false, Guid = Guid.NewGuid(), IloscPaczek = zwroty.Sum(z => z.IloscPaczek), Kontrahent = kontrahent, Synchronizacja = (int)RowSynchronizeOld.NotsynchronizedNew }; nowyZwrot.HistoriaZwrotu.Add(new HistoriaZwrotu() { Data = DateTime.Now, Deleted = false, Guid = Guid.NewGuid(), Status = status, Synchronize = (int)RowSynchronizeOld.NotsynchronizedNew, Uzytkownik = User.LoginedUser }); foreach (var zwrot in zwroty) { opis += zwrot.ID + ", "; if (!string.IsNullOrEmpty(zwrot.Opis)) { if (nowyZwrot.Opis == null) { nowyZwrot.Opis = ""; } if (nowyZwrot.Opis != "") { nowyZwrot.Opis += "\r\n"; } nowyZwrot.Opis += zwrot.Opis; } foreach (var poz in zwrot.Pozycje.Where(p => p.Deleted == false && p.Synchronizacja != (int)RowSynchronizeOld.NotsynchronizedDelete).ToList()) { nowyZwrot.Pozycje.Add(new PozycjaZwrotu() { Cena = poz.Cena, Deleted = false, Guid = Guid.NewGuid(), Ident = nowyZwrot.GetMaxIdent() + 1, IlocsDeklarowana = poz.IlocsDeklarowana, Ilosc = poz.Ilosc, Opis = poz.Opis, Synchronizacja = (int)RowSynchronizeOld.NotsynchronizedNew, Towar = poz.Towar, TowarNazwa = poz.TowarNazwa }); poz.Deleted = true; } zwrot.Deleted = true; } if (!string.IsNullOrEmpty(nowyZwrot.Opis)) { nowyZwrot.Opis += "\r\n"; } nowyZwrot.Opis += opis; nowyZwrot.PrzeliczWartosc(); Enova.Business.Old.Core.ContextManager.WebContext.SaveChanges(); Enova.Business.Old.Core.ContextManager.WebContext.Refresh(RefreshMode.StoreWins, nowyZwrot); MessageBox.Show("Został stworzony nowy zwrot o numerze " + nowyZwrot.ID); this.Reload(); } } }