예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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();
                }
            }
        }