public PcidAssociationViewModel(int groupID) { _groupID = groupID; AssociateCommand = new DelegateCommand(associateFunction); DisassociateCommand = new DelegateCommand <PCIDViewModel>(disassociateFunction); NewPcid = new PCIDViewModel(_groupID, true, false); populateAssociations(); }
private void associateFunction() { ActivityLogService.Logger.LogFunctionCall(); try { if (NewPcid.BranchNo == -1) { MessageBox.Show("אנא בחר סניף"); } else if (NewPcid.IsDatesLimited && (NewPcid.DateTo < NewPcid.DateFrom || NewPcid.DateTo < DateTime.Now)) { MessageBox.Show("טווח התאריכים אינו תקין"); } else if (NewPcid.IsHoursLimited && NewPcid.ToTime <= NewPcid.FromTime) { MessageBox.Show("טווח השעות אינו תקין"); } else { if (NewPcid.FromTime == null || NewPcid.ToTime == null) { NewPcid.IsHoursLimited = false; } DateTime?to = NewPcid.IsDatesLimited ? NewPcid.DateTo : (DateTime?)null; bool added; if (NewPcid.IsHoursLimited) { added = DBService.GetService().AssociatePcid2SaleM(_groupID, NewPcid.BranchNo, NewPcid.DateFrom, to, (TimeSpan)NewPcid.FromTime, (TimeSpan)NewPcid.ToTime); } else { added = DBService.GetService().AssociatePcid2SaleM(_groupID, NewPcid.BranchNo, NewPcid.DateFrom, to); } if (!added) { throw new SalesException(""); } NewPcid = new PCIDViewModel(_groupID, true, false); populateAssociations(); } } catch (Exception ex) { ActivityLogService.Logger.LogError(ex); MessageBox.Show("אירעה שגיאה בעת הוספת המבצע לסניף, אנא בדוק את הערכים שהוכנסו."); } }
private void disassociateFunction(PCIDViewModel pcid) { ActivityLogService.Logger.LogFunctionCall(); try { if (!DBService.GetService().DisassociatePcidfromSaleM(_groupID, pcid.BranchNo)) { throw new SalesException("מחיקת סניף נכשלה"); } Associations.Remove(pcid); OnPropertyChanged("Associations"); NewPcid = new PCIDViewModel(_groupID, true, false); } catch (Exception ex) { ActivityLogService.Logger.LogError(ex); MessageBox.Show("אירעה שגיאה בעת מחיקת המבצע מהסניף, אנא פנה אל מרכז התמיכה.\nבינתיים - בטל את הסניף."); } }
private void populateAssociations() { Associations = new ObservableCollection <PCIDViewModel>(); var dt = DBService.GetService().GetSalesBranches(_groupID); foreach (DataRow r in dt.Rows) { var ass = new PCIDViewModel(_groupID, bool.Parse(r["isEnabled"].ToString()), true); ass.BranchNo = int.Parse(r["pcid"].ToString()); ass.BranchName = r["bhname"].ToString(); ass.DateFrom = DateTime.Parse(r["dateFrom"].ToString()); ass.IsDatesLimited = r["dateTo"] != DBNull.Value; ass.DateTo = ass.IsDatesLimited ? DateTime.Parse(r["dateTo"].ToString()) : (DateTime?)null; ass.IsHoursLimited = r["HourFrom"] != DBNull.Value; ass.FromTime = ass.IsHoursLimited ? TimeSpan.Parse(r["HourFrom"].ToString()) : (TimeSpan?)null; ass.ToTime = ass.IsHoursLimited ? TimeSpan.Parse(r["HourTo"].ToString()) : (TimeSpan?)null; Associations.Add(ass); } OnPropertyChanged("Associations"); }