private void ShowMsgForNOSave(BOPType bopType) { ObservableCollection <BOPInfo> needUpdateList = null; BOPInfo tempInfo = null; if (CheckedIsNeedSave(ref tempInfo, ref needUpdateList, bopType)) { MessageBoxResult mr = MessageBox.Show("当前列表中存在未保存项,是否保存?", "", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (mr == MessageBoxResult.OK) { string msg = ""; if (Do_Save(ref msg)) { if (!string.IsNullOrEmpty(msg)) { MessageBox.Show(msg); } } else { RestoreBtn_Click(null, new RoutedEventArgs()); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show(msg); } } } else { RestoreBtn_Click(null, new RoutedEventArgs()); } } }
private void DeleteNewBtn_Click(object sender, RoutedEventArgs e) { if (BOPDataGrid.SelectedItem == null) { MessageBox.Show("请先选定要删除的项!"); } BOPInfo info = BOPDataGrid.SelectedItem as BOPInfo; if (info.ID == 0) { switch ((BOPType)(((DictionaryEntry)(BOPTypeList.SelectedValue)).Key)) { case BOPType.P: PaymentBOPList.Remove(info); break; case BOPType.B: BalanceBOPList.Remove(info); break; } } else { MessageBox.Show("只能删除未保存项!"); } }
private void CollectionViewSource_Filter(object sender, FilterEventArgs e) { BOPInfo bopInfo = e.Item as BOPInfo; if (bopInfo == null) { return; } bool IsGeneralTextAccepted = true; if (!string.IsNullOrEmpty(FitterGeneralText.Text.Trim())) { IsGeneralTextAccepted = bopInfo.BOPReason.ToLower().Contains(FitterGeneralText.Text.ToLower()); } bool IsDataTextAccepted = true; if (StartDatePicker.SelectedDate != null && EndDatePicker.SelectedDate != null) { if (StartDatePicker.SelectedDate <= EndDatePicker.SelectedDate) { IsDataTextAccepted = (bopInfo.BOPDate >= StartDatePicker.SelectedDate) && (bopInfo.BOPDate <= EndDatePicker.SelectedDate); } } e.Accepted = IsGeneralTextAccepted && IsDataTextAccepted; }
private bool CheckedIsNeedSave(ref BOPInfo tempInfo, ref ObservableCollection <BOPInfo> needUpdateList, BOPType bopType) { if (dataManager == null) { tempInfo = new BOPInfo(); needUpdateList = new ObservableCollection <BOPInfo>(); return(false); } ObservableCollection <BOPInfo> tempInfoList = null; bool isNeedUpdate = false; //检查新建项 switch (bopType) { case BOPType.P: tempInfo = PaymentBOPList.Where(bop => bop.ID == 0).FirstOrDefault(); tempInfoList = pageManager.ReFreshCurPageCollection( AlgorithmClass.GetBOPListByBOPType(dataManager.AllBOPList, BOPType.P)); break; case BOPType.B: tempInfo = BalanceBOPList.Where(bop => bop.ID == 0).FirstOrDefault(); tempInfoList = pageManager.ReFreshCurPageCollection( AlgorithmClass.GetBOPListByBOPType(dataManager.AllBOPList, BOPType.B)); break; } if (tempInfo != null) { isNeedUpdate = true; } //检查并获取编辑项 needUpdateList = AlgorithmClass.CompareCollectionIsChanged <BOPInfo>(tempInfoList, (FindResource("ViewSource") as CollectionViewSource).Source as ObservableCollection <BOPInfo>, "ID"); if (needUpdateList.Count != 0) { isNeedUpdate = true; } return(isNeedUpdate); }
/// <summary> /// 插入BOP信息 /// </summary> public static int InsertBOP(BOPInfo bopInfo) { ISqlMapper mapper = GetSqlMapper.GetMapper(); int id = 0; try { mapper.BeginTransaction(); id = (int)(mapper.Insert("InsertBOP", bopInfo)); mapper.CommitTransaction(); } catch (Exception ex) { applog.InfoFormat("Access.InsertBOP() Error:{0}", ex.Message); mapper.RollBackTransaction(); } return(id); }
/// <summary> /// 更新BOP信息 /// </summary> public static int UpdateBOPInfo(BOPInfo bopInfo) { ISqlMapper mapper = GetSqlMapper.GetMapper(); int result = 0; try { mapper.BeginTransaction(); result = mapper.Update("UpdateBOPInfo", bopInfo); mapper.CommitTransaction(); } catch (Exception ex) { applog.InfoFormat("Access.UpdateBOPInfo() Error:{0}", ex.Message); mapper.RollBackTransaction(); } return(result); }
private bool CheckBOPInfoIsValid(BOPInfo bopInfo) { if (string.IsNullOrEmpty(bopInfo.BOPReason) || string.IsNullOrEmpty(bopInfo.AccountingSupervisorName) || string.IsNullOrEmpty(bopInfo.CashierName) || string.IsNullOrEmpty(bopInfo.HandlerName)) { return(false); } if (bopInfo.BOP_Type == BOPType.B && string.IsNullOrEmpty(bopInfo.BookKeepingName)) { return(false); } if (bopInfo.BOP_Type == BOPType.P && (string.IsNullOrEmpty(bopInfo.PayeeName) || string.IsNullOrEmpty(bopInfo.DepartmentName))) { return(false); } return(true); }
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 void AddBtn_Click(object sender, RoutedEventArgs e) { BOPInfo tempInfo = null; switch ((BOPType)(((DictionaryEntry)(BOPTypeList.SelectedValue)).Key)) { case BOPType.P: tempInfo = PaymentBOPList.Where(bop => bop.ID == 0).FirstOrDefault(); if (tempInfo == null) { PaymentBOPList.Add(new BOPInfo { BOP_Type = BOPType.P, SelectionEmployeeInfoList = dataManager.AllEmployeeList.ToList(), SelectionDepartmentInfoList = dataManager.AllDepartmentList.ToList() }); } else { MessageBox.Show("请先保存当前新添加项!"); } break; case BOPType.B: tempInfo = BalanceBOPList.Where(bop => bop.ID == 0).FirstOrDefault(); if (tempInfo == null) { BalanceBOPList.Add(new BOPInfo { BOP_Type = BOPType.B, SelectionEmployeeInfoList = dataManager.AllEmployeeList.ToList() }); } else { MessageBox.Show("请先保存当前新添加项!"); } break; } }
public static bool InsertBOPInfo(BOPInfo bopInfo, ref int insertID) { insertID = Access.InsertBOP(bopInfo); return(insertID == 0 ? false : true); }
public static bool UpdateBOPInfo(BOPInfo bopInfo) { return(Access.UpdateBOPInfo(bopInfo) == 1 ? true : false); }
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); }