private void DeleteBtn_Click(object sender, RoutedEventArgs e) { if (BOPDataGrid.SelectedItem == null) { return; } MessageBoxResult mr = MessageBox.Show("删除该记录后不可恢复,确认删除?", "删除记录", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (mr == MessageBoxResult.OK) { BOPInfo info = BOPDataGrid.SelectedItem as BOPInfo; if (BOPDeal.DeleteBOPInfo(info.ID)) { int index = dataManager.AllBOPList.ToList().FindIndex(sheet => sheet.ID == info.ID); if (index > -1) { dataManager.AllBOPList.RemoveAt(index); } switch ((BOPType)(((DictionaryEntry)(BOPTypeList.SelectedValue)).Key)) { case BOPType.P: index = PaymentBOPList.ToList().FindIndex(sheet => sheet.ID == info.ID); if (index > -1) { PaymentBOPList.RemoveAt(index); } break; case BOPType.B: index = BalanceBOPList.ToList().FindIndex(sheet => sheet.ID == info.ID); if (index > -1) { BalanceBOPList.RemoveAt(index); } break; } MessageBox.Show("删除完成!"); } } }
private bool Do_Save(ref string msg) { ObservableCollection <BOPInfo> needUpdateList = null; BOPInfo tempInfo = null; bool isNeedUpdate = CheckedIsNeedSave(ref tempInfo, ref needUpdateList, (BOPType)(((DictionaryEntry)(BOPTypeList.SelectedValue)).Key)); if (tempInfo != null) { if (!CheckBOPInfoIsValid(tempInfo)) { msg = "新增项或被编辑项的信息不完整,保存失败。"; return(false); } //插入操作 int newID = 0; if (BOPDeal.InsertBOPInfo(tempInfo, ref newID)) { tempInfo.ID = newID; dataManager.AllBOPList.Add(tempInfo); } else { msg = "数据创建失败,请重试!"; return(false); } } if (needUpdateList.Count != 0) { //更新操作 foreach (BOPInfo info in needUpdateList) { if (!CheckBOPInfoIsValid(tempInfo)) { msg = "新增项或被编辑项的信息不完整,保存失败。"; return(false); } if (BOPDeal.UpdateBOPInfo(info)) { int index = dataManager.AllBOPList.ToList().FindIndex(bop => bop.ID == info.ID); if (index > -1) { dataManager.AllBOPList.RemoveAt(index); dataManager.AllBOPList.Insert(index, AlgorithmClass.DeepClone <BOPInfo>(info)); } } else { msg = "数据更新失败,请重试!"; return(false); } } } if (isNeedUpdate) { msg = "数据保存完成!"; } else { msg = "不存在需要保存项!"; } return(true); }