private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { if (!isExternalCall) { stackMain.DataContext = item_price_listViewSource; } else { MainViewSource.View.MoveCurrentTo(curMainObject); if (operationMode == Class.clsCommon.Mode.Add) { entity.item_price_list newitem_price_list = new entity.item_price_list(); mydb.db.item_price_list.Add(newitem_price_list); myViewSource.Source = mydb.db.item_price_list.Local; myViewSource.View.Refresh(); myViewSource.View.MoveCurrentTo(newitem_price_list); stackMain.DataContext = myViewSource; btnDelete.Visibility = System.Windows.Visibility.Collapsed; } else if (operationMode == Class.clsCommon.Mode.Edit) { item_price_listViewSource.View.MoveCurrentTo(_price_listobject); stackMain.DataContext = item_price_listViewSource; } } } }
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, e); } } else { IEnumerable <DbEntityValidationResult> validationresult = mydb.db.GetValidationErrors(); if (validationresult.Count() == 0) { if (operationMode == Class.clsCommon.Mode.Add) { mydb.SaveChanges(); entity.item_price_list item_price_list = myViewSource.View.CurrentItem as entity.item_price_list; mydb.db.Entry(item_price_list).State = EntityState.Detached; _entity.db.item_price_list.Attach(item_price_list); item_price_listViewSource.View.Refresh(); item_price_listViewSource.View.MoveCurrentTo(item_price_list); MainViewSource.View.Refresh(); MainViewSource.View.MoveCurrentTo(curMainObject); btnCancel_Click(sender, e); } else if (operationMode == Class.clsCommon.Mode.Edit) { btnCancel_Click(sender, e); } } } } catch (Exception ex) { throw ex; } }