示例#1
0
        private void Reload()
        {
            Context = new PaySysContext();
            Context.MainGroups.Load();
            DataContext = Context.MainGroups.Local;
            foreach (var control in GridMain.FindVisualChildren <UcTextPair>())
            {
                control.UpdateTarget();
            }

            Context.ContractFields.Load();
            SmpUcContractFieldTitlesMng.ContractFieldsAll = Context.ContractFields.Local.ToList();
        }
示例#2
0
        private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
        {
//			foreach( var control in GridMain.FindVisualChildren<Control>() )
//				control.GetBindingExpression( UcTextPair.TextOfLabelProperty )?.UpdateSource();
            foreach (var control in GridMain.FindVisualChildren <UcTextPair>())
            {
                control.UpdateSource();
            }

            SmpUcSubGroupEdit.UpdateSource();

            #region Contract Fields
            var expChangedContractFields = Context.ContractFields.Local
                                           .Where(c => c.CurrentExpenseArticle?.Code != c.TempCurrentExpenseArticleCode).ToList();

            foreach (var cnt in expChangedContractFields)
            {
                var exp = Context.ExpenseArticles.FirstOrDefault(x => x.Code == cnt.TempCurrentExpenseArticleCode) ??
                          Context.ExpenseArticles.Add(new ExpenseArticle
                {
                    Code     = cnt.TempCurrentExpenseArticleCode,
                    IsActive = true
                });

                cnt.CurrentExpenseArticle = exp;
//                cnt.TempCurrentExpenseArticleCode = exp.Code;
            }
            #endregion

            #region Miscs
            var expChangedMiscs = Context.Miscs.Local.Where(c => c.ExpenseArticle?.Code != c.TempExpenseArticleCode)
                                  .ToList();

            foreach (var msc in expChangedMiscs)
            {
                var exp = Context.ExpenseArticles.FirstOrDefault(x => x.Code == msc.TempExpenseArticleCode);
                if (exp == null)
                {
                    msc.ExpenseArticle = Context.ExpenseArticles.Add(new ExpenseArticle
                    {
                        Code     = msc.TempExpenseArticleCode,
                        IsActive = true
                    });
                }
                else
                {
                    msc.ExpenseArticle = exp;
                }
            }
            #endregion

            var currentSubGroup = DataGridSubGroups.SelectedItem as SubGroup;


            #region TaxTable
            SmpUcTaxTableMng.UpdateSource();
            currentSubGroup?.CurrenTaxTable.CommitTempToValues();
            #endregion


            #region HandselFormula
            Context.HandselFormulas.AddOrUpdate(currentSubGroup?.CurrentOrNewHandselFormula);
            #endregion

            #region MissionFormula
            // Investigating user's checked or not checked ContractFields one by one:
            foreach (var cf in currentSubGroup.CurrentOrNewMissionFormula.TempMissionFormulaInvolvedContractFieldsLeftJoined)
            {
                //User has checked this ContractField but it doesn't exist in involved contract fields list:
                if (cf.Value && !currentSubGroup.CurrentOrNewMissionFormula.MissionFormulaInvolvedContractFields.Select(f => f.ContractField).Contains(cf.Key))
                {
                    currentSubGroup.CurrentOrNewMissionFormula.MissionFormulaInvolvedContractFields.Add(new MissionFormulaInvolvedContractField
                    {
                        ContractField = cf.Key,
//                        MissionFormula = currentSubGroup.CurrentOrNewMissionFormula,
                    });
                }

                //User has unchecked this ContractField but it exists in involved contract fields list:
                if (!cf.Value && currentSubGroup.CurrentOrNewMissionFormula.MissionFormulaInvolvedContractFields.Select(f => f.ContractField).Contains(cf.Key))
                {
                    currentSubGroup.CurrentOrNewMissionFormula.MissionFormulaInvolvedContractFields.Remove(currentSubGroup.CurrentOrNewMissionFormula.MissionFormulaInvolvedContractFields.First(f => f.ContractField == cf.Key));
                }
            }

            Context.MissionFormulas.AddOrUpdate(currentSubGroup.CurrentOrNewMissionFormula);
            #endregion

            Context.SaveChanges();
            SmpUcFormStateLabel.CurrentState = FormCurrentState.Select;
            SmpUcParameterMng.Refresh();
            SmpUcContractFieldTitlesMng.Refresh();
            SmpUcMiscMng.Refresh();
            CollectionViewSource.GetDefaultView(DataGridSubGroups.ItemsSource)?.Refresh();
        }