private void DataGrid_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex > -1 && e.RowIndex < this.DataGrid.Rows.Count) { DataGridViewRow row = DataGrid.Rows[e.RowIndex]; StatusZwrotu s = (StatusZwrotu)row.DataBoundItem; if (s != null) { Color color = ColorTranslator.FromHtml(s.Kolor); row.DefaultCellStyle.BackColor = color; row.HeaderCell.Style.BackColor = color; row.HeaderCell.Style.SelectionBackColor = color; row.HeaderCell.Style.SelectionForeColor = Color.Black; } } }
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(); } } }