Example #1
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!isExternalCall)
         {
             IEnumerable <DbEntityValidationResult> validationresult = _entity.db.GetValidationErrors();
             if (validationresult.Count() == 0)
             {
                 _entity.SaveChanges();
                 btnCancel_Click(sender, null);
             }
         }
         else
         {
             IEnumerable <DbEntityValidationResult> validationresult = mydb.db.GetValidationErrors();
             if (validationresult.Count() == 0)
             {
                 if (operationMode == Class.clsCommon.Mode.Add)
                 {
                     mydb.SaveChanges();
                     entity.app_vat_group app_vat_group = myViewSource.View.CurrentItem as entity.app_vat_group;
                     mydb.db.Entry(app_vat_group).State = EntityState.Detached;
                     _entity.db.app_vat_group.Attach(app_vat_group);
                     app_vat_groupViewSource.View.Refresh();
                     app_vat_groupViewSource.View.MoveCurrentTo(app_vat_group);
                     MainViewSource.View.Refresh();
                     MainViewSource.View.MoveCurrentTo(curObject);
                     btnCancel_Click(sender, null);
                 }
                 else if (operationMode == Class.clsCommon.Mode.Edit)
                 {
                     btnCancel_Click(sender, null);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
                {
                    app_vatViewSource        = this.FindResource("app_vatViewSource") as CollectionViewSource;
                    app_vatViewSource.Source = _entity.db.app_vat.Where(a => a.is_active == true && a.id_company == CurrentSession.Id_Company).OrderBy(a => a.name).ToList();

                    if (!isExternalCall)
                    {
                        stackMain.DataContext = app_vat_groupViewSource;
                    }
                    else
                    {
                        MainViewSource.View.MoveCurrentTo(curObject);
                        if (operationMode == Class.clsCommon.Mode.Add)
                        {
                            entity.app_vat_group newvat_group = new entity.app_vat_group();
                            mydb.db.app_vat_group.Add(newvat_group);
                            myViewSource.Source = mydb.db.app_vat_group.Local;
                            myViewSource.View.Refresh();
                            myViewSource.View.MoveCurrentTo(newvat_group);
                            stackMain.DataContext = myViewSource;
                            btnDelete.Visibility  = System.Windows.Visibility.Collapsed;
                        }
                        else if (operationMode == Class.clsCommon.Mode.Edit)
                        {
                            app_vat_groupViewSource.View.MoveCurrentTo(vat_groupObject);
                            stackMain.DataContext = app_vat_groupViewSource;
                        }
                    }
                }
            }
            catch
            {}
        }