private void DGM_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { try { if (DGM.SelectedCells.Count > 0 && EXPEVAL.IsExpanded) { if (DGM.SelectedCells.Count == 1) { if (Func.names_months.Contains(DGM.CurrentColumn.Header.ToString()) && ((MicroFilling)e.AddedCells[0].Item).Головний_розпорядник != null && ((MicroFilling)e.AddedCells[0].Item).КФБ != null && ((MicroFilling)e.AddedCells[0].Item).КДБ != null && ((MicroFilling)e.AddedCells[0].Item).КЕКВ != null && ((MicroFilling)e.AddedCells[0].Item).КФК != null && ((MicroFilling)e.AddedCells[0].Item).Мікрофонд != null) { #region "Fiels of Cell" DateTime date = ((MicroFilling)DGM.CurrentItem).Проведено; KFK KFK = ((MicroFilling)DGM.CurrentItem).КФК; Main_manager Main_manager = ((MicroFilling)DGM.CurrentItem).Головний_розпорядник; KFB KFB = ((MicroFilling)DGM.CurrentItem).КФБ; KDB KDB = ((MicroFilling)DGM.CurrentItem).КДБ; KEKB KEKB = ((MicroFilling)DGM.CurrentItem).КЕКВ; MicroFoundation MicroFond = ((MicroFilling)DGM.CurrentItem).Мікрофонд; #endregion DBSolom.Db mdb = new Db(Func.GetConnectionString); #region "Current" //Заполнение//////////////////////////////////////////////////////////////////////////////////// List <DBSolom.Filling> qfill = mdb.Fillings .Include(i => i.Головний_розпорядник) .Include(i => i.КФБ) .Include(i => i.КДБ) .Include(i => i.КЕКВ) .Include(i => i.КФК) .Include(i => i.Фонд) .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.КФБ.Код == KFB.Код && w.КДБ.Код == KDB.Код && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Фонд.Код == MicroFond.Фонд.Код && w.Проведено.Year == date.Year).ToList(); double fill = qfill.Select(s => (double)(s.GetType().GetProperty(DGM.CurrentColumn.Header.ToString()).GetValue(s))).Sum(); //////////////////////////////////////////////////////////////////////////////////////////////// //Мікрозаполнение/////////////////////////////////////////////////////////////////////////////// List <MicroFilling> qcurr = mdb.Microfillings .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КФБ.Код == KFB.Код && w.КДБ.Код == KDB.Код && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == MicroFond.Фонд.Код).ToList(); db.Microfillings.Local .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КФБ.Код == KFB.Код && w.КДБ.Код == KDB.Код && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == MicroFond.Фонд.Код) .ToList() .ForEach(item => { if (db.Entry(item).State != EntityState.Unchanged) { qcurr.Add(item); } }); double curr = qcurr.Select(s => (double)(s.GetType().GetProperty(DGM.CurrentColumn.Header.ToString()).GetValue(s))).Sum(); //////////////////////////////////////////////////////////////////////////////////////////////// GRPBCurr.Content = (fill - curr).ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); #endregion mdb = new Db(Func.GetConnectionString); #region "All" //Заполнение//////////////////////////////////////////////////////////////////////////////////// qfill = mdb.Fillings .Include(i => i.Головний_розпорядник) .Include(i => i.КФК) .Include(i => i.Фонд) .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.КФК.Код == KFK.Код && w.Фонд.Код == MicroFond.Фонд.Код && w.Проведено.Year == date.Year) .ToList(); fill = qfill.Select(s => (double)(s.GetType().GetProperty(DGM.CurrentColumn.Header.ToString()).GetValue(s))).Sum(); //////////////////////////////////////////////////////////////////////////////////////////////// //Мікрозаполнение/////////////////////////////////////////////////////////////////////////////// qcurr = mdb.Microfillings .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == MicroFond.Фонд.Код).ToList(); db.Microfillings.Local .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == MicroFond.Фонд.Код) .ToList() .ForEach(item => { if (db.Entry(item).State != EntityState.Unchanged) { qcurr.Add(item); } }); curr = qcurr.Select(s => (double)(s.GetType().GetProperty(DGM.CurrentColumn.Header.ToString()).GetValue(s))).Sum(); //////////////////////////////////////////////////////////////////////////////////////////////// GRPBAll.Content = (fill - curr).ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); #endregion double d; double.TryParse(DGM.CurrentItem.GetType().GetProperty(DGM.CurrentColumn.Header.ToString()).GetValue(DGM.CurrentItem).ToString(), out d); GRPBElm.Content = "1"; GRPBSum.Content = d.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBSred.Content = ""; GRPBMin.Content = ""; GRPBMax.Content = ""; } } else { double sum = 0; int counter = 0; double min = double.MaxValue; double max = 0; foreach (var item in DGM.SelectedCells) { double d; if (double.TryParse(item.Item.GetType().GetProperty(item.Column.Header.ToString()).GetValue(item.Item)?.ToString(), out d)) { if (d > max) { max = d; } if (d < min) { min = d; } counter++; sum += d; } } GRPBAll.Content = "Лише 1 комірка"; GRPBCurr.Content = "Лише 1 комірка"; GRPBElm.Content = counter.ToString("N0", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBSum.Content = sum.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBSred.Content = (sum == 0 ? 0 : sum / counter).ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBMin.Content = min.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBMax.Content = max.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); } } } catch (Exception) { } }
private void DGM_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { if (DGM.CurrentItem != null) { ItemIndexInDGM = DGM.Items.IndexOf(DGM.CurrentItem); } try { if (DGM.SelectedCells.Count > 0 && EXPCALC.IsExpanded) { if (DGM.SelectedCells.Count == 1) { if (DGM.CurrentColumn.Header.ToString() == "Сума" && ((DBSolom.Financing)e.AddedCells[0].Item).Проведено != null && ((DBSolom.Financing)e.AddedCells[0].Item).Головний_розпорядник != null && ((DBSolom.Financing)e.AddedCells[0].Item).КЕКВ != null && ((DBSolom.Financing)e.AddedCells[0].Item).КФК != null && ((DBSolom.Financing)e.AddedCells[0].Item).Мікрофонд != null) { List <string> vs = Func.names_months; double yearSumFilling = 0; double yearSumCorrection = 0; double yearSumFinancing = 0; double periodSumFilling = 0; double periodSumCorrection = 0; double periodSumFinancing = 0; #region "Fiels of Cell" DateTime date = ((DBSolom.Financing)e.AddedCells[0].Item).Проведено; KFK KFK = ((DBSolom.Financing)e.AddedCells[0].Item).КФК; Main_manager Main_manager = ((DBSolom.Financing)e.AddedCells[0].Item).Головний_розпорядник; KEKB KEKB = ((DBSolom.Financing)e.AddedCells[0].Item).КЕКВ; Foundation FOND = ((DBSolom.Financing)e.AddedCells[0].Item).Мікрофонд.Фонд; MicroFoundation MicroFond = ((DBSolom.Financing)e.AddedCells[0].Item).Мікрофонд; #endregion DBSolom.Db mdb = new Db(Func.GetConnectionString); #region "Foundation" #region "Filling" List <DBSolom.Filling> qfil = mdb.Fillings .Include(i => i.Головний_розпорядник) .Include(i => i.КФБ) .Include(i => i.КДБ) .Include(i => i.КЕКВ) .Include(i => i.КФК) .Include(i => i.Фонд) .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Фонд.Код == FOND.Код).ToList(); for (int j = 0; j < date.Month; j++) { periodSumFilling += qfil.Select(s => (double)s.GetType().GetProperty(vs[j]).GetValue(s)).Sum(); } for (int j = 0; j < 11; j++) { yearSumFilling += qfil.Select(s => (double)s.GetType().GetProperty(vs[j]).GetValue(s)).Sum(); } #endregion #region "Correction" List <DBSolom.Correction> qcorr = mdb.Corrections .Include(i => i.Головний_розпорядник) .Include(i => i.КФБ) .Include(i => i.КДБ) .Include(i => i.КЕКВ) .Include(i => i.КФК) .Include(i => i.Мікрофонд) .Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == FOND.Код).ToList(); for (int j = 0; j < date.Month; j++) { periodSumCorrection += qcorr.Select(s => (double)s.GetType().GetProperty(vs[j]).GetValue(s)).Sum(); } for (int j = 0; j < 11; j++) { yearSumCorrection += qcorr.Select(s => (double)s.GetType().GetProperty(vs[j]).GetValue(s)).Sum(); } #endregion #region "Financing" List <DBSolom.Financing> qfin = mdb.Financings.Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == FOND.Код).ToList(); db.Financings.Local.Where(w => w.Видалено == false && w.Головний_розпорядник.Найменування == Main_manager.Найменування && w.Проведено.Year == date.Year && w.КЕКВ.Код == KEKB.Код && w.КФК.Код == KFK.Код && w.Мікрофонд.Фонд.Код == FOND.Код) .ToList() .ForEach(item => { if (db.Entry(item).State != EntityState.Unchanged) { qfin.Add(item); } }); yearSumFinancing = qfin.Select(s => s.Сума).Sum(); periodSumFinancing = qfin.Where(w => w.Проведено <= date).Select(s => s.Сума).Sum(); #endregion GRPBYearFond.Content = (yearSumFilling + yearSumCorrection - yearSumFinancing).ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBPeriodFond.Content = (periodSumFilling + periodSumCorrection - periodSumFinancing).ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); #endregion } double d; if (double.TryParse(DGM.SelectedCells.First().Item.GetType().GetProperty(DGM.SelectedCells.FirstOrDefault().Column.Header.ToString()).GetValue(DGM.SelectedCells.First().Item).ToString(), out d)) { GRPBElm.Content = "1"; GRPBSum.Content = d.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBSred.Content = ""; GRPBMin.Content = ""; GRPBMax.Content = ""; } } else { double sum = 0; int counter = 0; double min = double.MaxValue; double max = 0; foreach (var item in DGM.SelectedCells) { double d; if (double.TryParse(item.Item.GetType().GetProperty(item.Column.Header.ToString()).GetValue(item.Item).ToString(), out d)) { if (d > max) { max = d; } if (d < min) { min = d; } counter++; sum += d; } } GRPBElm.Content = counter.ToString("N0", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBSum.Content = sum.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBSred.Content = (sum == 0 ? 0 : sum / counter).ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBMin.Content = min.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); GRPBMax.Content = max.ToString("N2", CultureInfo.CreateSpecificCulture("ru-RU")); } } } catch (Exception) { } }