//Обновление инф в таб контроле private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { TabControl control = (sender as TabControl); try { if (control.SelectedTab.Text == "Остатки на складе") { #region Good[] goods = shop.GetGoodsBalance(); dgv4.Rows.Clear(); foreach (Good g in goods) { DataGridViewRow row = new DataGridViewRow(); DataGridViewCell cel = new DataGridViewTextBoxCell(); cel.Value = g.Barcode; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = g.Name; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = g.PriceOut; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = g.Count; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = g.Category; row.Cells.Add(cel); dgv4.Rows.Add(row); } #endregion } if (control.SelectedTab.Text == "Операции с деньгами за текущий день") { #region dgv3.Rows.Clear(); CashOperation[] saleToday = shop.GetToDayOperations(); foreach (CashOperation CO in saleToday) { DataGridViewRow row = new DataGridViewRow(); DataGridViewCell cel = new DataGridViewTextBoxCell(); DataGridViewButtonCell Bcel = new DataGridViewButtonCell(); Color color = new Color(); if (CO.TypeOperation.Equals("Инкасация", StringComparison.InvariantCultureIgnoreCase)) { color = Color.Red; } if (CO.TypeOperation.Equals("Пополнение", StringComparison.InvariantCultureIgnoreCase)) { color = Color.Green; } if (CO.TypeOperation.Equals("Продажа", StringComparison.InvariantCultureIgnoreCase)) { color = Color.White; } cel.Value = CO.PriceOperation; cel.Style.BackColor = color; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = CO.TimeOpertion; cel.Style.BackColor = color; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = CO.TypeOperation; cel.Style.BackColor = color; row.Cells.Add(cel); cel = new DataGridViewTextBoxCell(); cel.Value = CO.CashBalance; cel.Style.BackColor = color; row.Cells.Add(cel); Bcel.Style.BackColor = color; Bcel.Value = "Подробности"; row.Cells.Add(Bcel); row.Tag = CO.ID; dgv3.Rows.Add(row); } tbBalanceDayStart.Text = shop.GetStartBalance().ToString(); if (saleToday.Count() != 0) { //Находим максимальное значение id в коллекции saleToday int id = saleToday.Max(x => x.ID); //Инициализируем структуру CashOperation с найденным максимальным id CashOperation c = saleToday.First(x => x.ID == id); //Заносим текущий баланс в текстовое поле tbBalanceReal.Text = c.CashBalance.ToString(); } else { tbBalanceReal.Text = shop.GetStartBalance().ToString(); } #endregion } } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }