private void ButtonSave_Click(object sender, RoutedEventArgs e) { ControlsValidate?Vd = Commons.ValidateData(FirstControl, ControlsArray); MessageDialog Msg = null; if (Commons.CPeriod.Id > 0 && Commons.CPeriod.IsClosed == false) { if (Vd != null) { Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); Vd.Value.Control.Focus(); } else { if (string.Compare(TextBoxCurrentReadDate.Text.Trim(), Commons.GetCurrentPersianDate()) <= 0) { DomainClasses.SubscriptionsTb MySubscription = CurrentSubscriptionBilling.SubScription; long Price = Convert.ToInt64(TextBoxCurrentRead.Text.Trim()); if (Price > 0) { if (string.Compare(TextBoxCurrentReadDate.Text.Trim(), MySubscription.CurrentReadDate) >= 0) { if (Price != MySubscription.Debt) { Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.PriceIsNotEqualWithDebt, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); if (Msg.ShowDialog() == false) { TextBoxCurrentRead.SelectAll(); TextBoxCurrentRead.Focus(); return; } } Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.SaveMessageBillsReceivable, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); if (Msg.ShowDialog() == true) { try { long Deficit1000 = Commons.GetDeficit1000(Price); CurrentSubscriptionBilling.Bill.ReceivableDate = TextBoxCurrentReadDate.Text.Trim(); CurrentSubscriptionBilling.Bill.ReceivablePrice = Price - Deficit1000; CurrentSubscriptionBilling.Bill.ReceivableDefict1000 = Deficit1000; CurrentSubscriptionBilling.Bill.ReceivablePrevDebt = MySubscription.Debt; CurrentSubscriptionBilling.Bill.ReceivablePrevdeficit1000 = MySubscription.deficit1000; if (Price == MySubscription.Debt) { CurrentSubscriptionBilling.Bill.Status = BillsStatus.ReceivableFull; } else { CurrentSubscriptionBilling.Bill.Status = BillsStatus.ReceivableNotMatch; } long OldDebt = MySubscription.Debt, OldDeficit1000 = MySubscription.deficit1000; MySubscription.Debt = MySubscription.Debt - (Price - Deficit1000); MySubscription.deficit1000 = MySubscription.deficit1000 - Deficit1000; Commons.Db.SaveChanges(); SearchAgain = true; Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.SaveMessageSuccessBillsReceivable, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); EmptyControl(); TextBoxSubScriptionId.Text = ""; TextBoxSubScriptionId.Focus(); TextBoxSubScriptionId.SelectAll(); } catch { Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxCurrentRead.SelectAll(); } } } else { Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.CurrentDateIsNotAllowedLowerThanCurrentReadDate, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxCurrentReadDate.Focus(); TextBoxCurrentReadDate.SelectAll(); } } else { Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.PriceIsNotAllowedZeroOrLess, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxCurrentRead.SelectAll(); } } else { Msg = new MessageDialog(Messages.SaveMessageTitleBillsReceivable, Messages.DateIsNotAllowedBiggarThanReceivableDate, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxCurrentReadDate.Focus(); TextBoxCurrentReadDate.SelectAll(); } } } else { Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.NotExistPeriodBilling, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); TextBoxCurrentRead.SelectAll(); } }