コード例 #1
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
     {
         if (!isExternalCall)
         {
             stackMain.DataContext = app_propertyViewSource;
         }
         else
         {
             MainViewSource.View.MoveCurrentTo(curObject);
             if (operationMode == Class.clsCommon.Mode.Add)
             {
                 entity.app_property app_property = new entity.app_property();
                 mydb.db.app_property.Add(app_property);
                 myViewSource.Source = mydb.db.app_property.Local;
                 myViewSource.View.Refresh();
                 myViewSource.View.MoveCurrentTo(app_property);
                 stackMain.DataContext = myViewSource;
             }
             else if (operationMode == Class.clsCommon.Mode.Edit)
             {
                 app_propertyViewSource.View.MoveCurrentTo(objapp_property);
                 stackMain.DataContext = app_propertyViewSource;
             }
         }
     }
 }
コード例 #2
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!isExternalCall)
         {
             IEnumerable <DbEntityValidationResult> validationresult = _entity.db.GetValidationErrors();
             if (validationresult.Count() == 0)
             {
                 _entity.db.SaveChanges();
                 btnCancel_Click(sender, e);
             }
         }
         else
         {
             IEnumerable <DbEntityValidationResult> validationresult = mydb.db.GetValidationErrors();
             if (validationresult.Count() == 0)
             {
                 if (operationMode == Class.clsCommon.Mode.Add)
                 {
                     mydb.SaveChanges();
                     entity.app_property app_property = myViewSource.View.CurrentItem as entity.app_property;
                     mydb.db.Entry(app_property).State = EntityState.Detached;
                     _entity.db.app_property.Attach(app_property);
                     app_propertyViewSource.View.Refresh();
                     app_propertyViewSource.View.MoveCurrentTo(app_property);
                     MainViewSource.View.Refresh();
                     MainViewSource.View.MoveCurrentTo(curObject);
                     btnCancel_Click(sender, e);
                 }
                 else if (operationMode == Class.clsCommon.Mode.Edit)
                 {
                     btnCancel_Click(sender, e);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }