コード例 #1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            accounting_templateViewSource = ((CollectionViewSource)(FindResource("accounting_templateViewSource")));
            entity.db.accounting_template.Where(a => a.id_company == CurrentSession.Id_Company && a.is_active == true).Include("accounting_template_detail").OrderBy(a => a.name).Load();
            accounting_templateViewSource.Source = entity.db.accounting_template.Local;

            CollectionViewSource accounting_chartViewSource = ((CollectionViewSource)(FindResource("accounting_chartViewSource")));

            accounting_chartViewSource.Source = entity.db.accounting_chart.Where(x => x.id_company == CurrentSession.Id_Company).OrderBy(b => b.name).ToList();

            if (operationMode == Class.clsCommon.Mode.Add)
            {
                accounting_template accounting_template = new accounting_template();
                accounting_template.name      = "Template";
                accounting_template.is_active = true;
                entity.db.accounting_template.Add(accounting_template);
                //  entity.db.SaveChanges();

                accounting_templateViewSource.View.Refresh();
                accounting_templateViewSource.View.MoveCurrentToLast();
            }
            else
            {
                accounting_templateViewSource.View.MoveCurrentTo(entity.db.accounting_template.Where(x => x.id_template == accounting_templateobject.id_template).FirstOrDefault());
                btnDelete.Visibility = System.Windows.Visibility.Visible;
            }
            //stackMainAc.DataContext = accounting_templateViewSource;
            //stpsub.DataContext = accounting_templateaccounting_template_detailViewSource;
        }
コード例 #2
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         accounting_template accounting_template = accounting_templateViewSource.View.CurrentItem as accounting_template;
         if (accounting_template.accounting_template_detail.Sum(x => x.coefficeint) == 100)
         {
             IEnumerable <DbEntityValidationResult> validationresult = entity.db.GetValidationErrors();
             if (validationresult.Count() == 0)
             {
                 entity.db.SaveChanges();
                 Grid parentGrid = (Grid)this.Parent;
                 parentGrid.Children.Clear();
                 parentGrid.Visibility = System.Windows.Visibility.Hidden;
             }
         }
         else
         {
             MessageBox.Show("CoEfficient is Equal to 100%");
         }
     }
     catch (Exception ex)
     { throw ex; }
 }