private void Window_Loaded(object sender, RoutedEventArgs e) { IsEditing = false; IsInserting = false; transTypes = new TransTypesDBDataContext(); LoadDataGrid(); }
private void dgTransTypes_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { if (e.EditAction == DataGridEditAction.Commit) { TransTypesDBDataContext context = new TransTypesDBDataContext(); TransType tType = e.Row.DataContext as TransType; var matchedData = (from tt in context.GetTable <TransType>() where tt.TransTypeID == tType.TransTypeID select tt).SingleOrDefault(); if (matchedData == null) { TransType trans = new TransType(); trans.Description = tType.Description; context.TransTypes.InsertOnSubmit(trans); context.SubmitChanges(); } else { matchedData.Description = tType.Description; context.SubmitChanges(); } } //var _row = e.Row.Item as DataRow; //var _transTypeId = Convert.ToInt32(_row["TransTypeID"]); //var _description = _row["Description"].ToString(); //if (IsInserting) //{ // _transTypeId = -1; // Data.Instance.EditTransTypes(_transTypeId, _description); //} //else if (IsEditing) //{ // Data.Instance.EditTransTypes(_transTypeId, _description); //} //IsEditing = false; //IsInserting = false; LoadDataGrid(); }