Ejemplo n.º 1
0
        private void CheckSubScriptionId()
        {
            CurrentSubscriptionBilling = null;
            BindingOperations.GetBindingExpression(FirstControl, TextBox.TextProperty).UpdateSource();
            MessageDialog Msg = null;

            try
            {
                bool             IsValid = true;
                string           SId     = "";
                ControlsValidate?Vd      = Commons.ValidateData((Control)FirstControl, ControlsArraySubScriptionId);
                if (Vd != null)
                {
                    IsValid   = false;
                    Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.ForceToSubscriptionId, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                    EmptyControl();
                    FirstControl.Focus();
                    FirstControl.SelectAll();
                }
                if (IsValid == true)
                {
                    SId = TextBoxSubScriptionId.Text.Trim();
                    CurrentSubscriptionBilling = LoadSubscriptionForBilling(SId);

                    if (CurrentSubscriptionBilling != null)
                    {
                        FillSubScription(CurrentSubscriptionBilling);
                        ButtonCancel.Focus();
                    }
                    else
                    {
                        Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.NotFoundSubscriptionOrBillForCancelling, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                        EmptyControl();
                        FirstControl.Focus();
                        FirstControl.SelectAll();
                    }
                }
            }
            catch
            {
                Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
                FirstControl.Focus();
                FirstControl.SelectAll();
            }
        }
Ejemplo n.º 2
0
        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.SaveMessageTitleBillsCancelling, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                    Vd.Value.Control.Focus();
                }
                else
                {
                    DomainClasses.SubscriptionsTb MySubscription = CurrentSubscriptionBilling.SubScription;
                    //در صورتی که قبض مربوطه مربوط به کنتور قبلی باشد امکان ابطال آن وجود ندارد
                    if (CurrentSubscriptionBilling.SubScription.WaterMeterId == CurrentSubscriptionBilling.Bill.WaterMeterId && CurrentSubscriptionBilling.SubScription.WaterMeterYear == CurrentSubscriptionBilling.Bill.WaterMeterYear)
                    {
                        Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.SaveMessageBillsCancelling, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        if (Msg.ShowDialog() == true)
                        {
                            try
                            {
                                long   PrevDebt         = CurrentSubscriptionBilling.Bill.PrevDebt;
                                long   PrevDeficit1000  = CurrentSubscriptionBilling.Bill.Prevdeficit1000;
                                string PrevPrevReadDate = CurrentSubscriptionBilling.Bill.PrevPrevReadDate
                                , PrevReadDate          = MySubscription.PrevReadDate;
                                long PrevPrevNumber     = CurrentSubscriptionBilling.Bill.PrevPrevNumber
                                , PrevNumber            = MySubscription.PrevNumber;

                                if (CurrentSubscriptionBilling.Bill.Status == BillsStatus.ReceivableFull || CurrentSubscriptionBilling.Bill.Status == BillsStatus.ReceivableNotMatch)
                                {
                                    PrevDebt        = PrevDebt - CurrentSubscriptionBilling.Bill.ReceivablePrice;
                                    PrevDeficit1000 = PrevDeficit1000 - CurrentSubscriptionBilling.Bill.ReceivableDefict1000;
                                }

                                CurrentSubscriptionBilling.Bill.CancelDate = Commons.GetCurrentPersianDate();
                                CurrentSubscriptionBilling.Bill.Status     = BillsStatus.Cancel;

                                MySubscription.Debt            = PrevDebt;
                                MySubscription.deficit1000     = PrevDeficit1000;
                                MySubscription.PrevReadDate    = PrevPrevReadDate;
                                MySubscription.PrevNumber      = PrevPrevNumber;
                                MySubscription.CurrentReadDate = PrevReadDate;
                                MySubscription.CurrentNumber   = PrevNumber;
                                //به روز رسانی آخرین قرائت با کنتور فعلی
                                MySubscription.WaterMeter.ReadEnd     = PrevNumber;
                                MySubscription.WaterMeter.ReadDateEnd = PrevReadDate;

                                Commons.Db.SaveChanges();

                                Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.SaveMessageSuccessBillsCancelling, 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.SaveMessageTitleBillsCancelling, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                                Msg.Owner = Window.GetWindow(this);
                                Msg.ShowDialog();
                                ButtonCancel.Focus();
                            }
                        }
                    }
                    //در صورتی که قبض مربوطه مربوط به کنتور قبلی باشد امکان ابطال آن وجود ندارد
                    else
                    {
                        Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.CanNotCancelBillBecauseOfWaterMeter, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                        ButtonCancel.Focus();
                    }
                }
            }
            else
            {
                Msg       = new MessageDialog(Messages.SaveMessageTitleBillsCancelling, Messages.NotExistPeriodBilling, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
                TextBoxSubScriptionId.Text = "";
                TextBoxSubScriptionId.Focus();
                TextBoxSubScriptionId.SelectAll();
            }
        }
Ejemplo n.º 3
0
        public DialogWindow(Window parent, string message, string title, MessageBoxButton messageBoxButton, MessageBoxImage messageBoxImage) : base()
        {
            InitializeComponent();

            Closing += new CancelEventHandler(DialogWindow_Closing);

            Owner             = parent;
            Title             = title;
            LabelContent.Text = message;

            if (Owner == null)
            {
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            if (messageBoxButton == MessageBoxButton.OK || messageBoxButton == MessageBoxButton.OKCancel)
            {
                ButtonOk.Visibility = Visibility.Visible;

                ButtonOk.Click += new RoutedEventHandler(ButtonOk_Click);
                ButtonOk.Focus();
            }

            if (messageBoxButton == MessageBoxButton.YesNo || messageBoxButton == MessageBoxButton.YesNoCancel)
            {
                ButtonYes.Visibility = Visibility.Visible;
                ButtonNo.Visibility  = Visibility.Visible;
                ButtonNo.Focus();

                ButtonYes.Click += new RoutedEventHandler(ButtonYes_Click);
                ButtonNo.Click  += new RoutedEventHandler(ButtonNo_Click);
            }

            if (messageBoxButton == MessageBoxButton.OKCancel || messageBoxButton == MessageBoxButton.YesNoCancel)
            {
                ButtonCancel.Visibility = Visibility.Visible;
                ButtonCancel.Focus();

                ButtonCancel.Click += new RoutedEventHandler(ButtonCancel_Click);
            }

            if (messageBoxImage != MessageBoxImage.None)
            {
                Image.Visibility = Visibility.Visible;
                switch (messageBoxImage)
                {
                case MessageBoxImage.Information:
                    Image.Source = Imaging.CreateBitmapSourceFromHIcon(System.Drawing.SystemIcons.Information.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    System.Media.SystemSounds.Asterisk.Play();
                    break;

                case MessageBoxImage.Question:
                    Image.Source = Imaging.CreateBitmapSourceFromHIcon(System.Drawing.SystemIcons.Question.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    System.Media.SystemSounds.Question.Play();
                    break;

                case MessageBoxImage.Exclamation:
                    Image.Source = Imaging.CreateBitmapSourceFromHIcon(System.Drawing.SystemIcons.Exclamation.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    System.Media.SystemSounds.Exclamation.Play();
                    break;

                case MessageBoxImage.Error:
                    Image.Source = Imaging.CreateBitmapSourceFromHIcon(System.Drawing.SystemIcons.Error.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    System.Media.SystemSounds.Hand.Play();
                    break;
                }
            }

            ShowDialog();
        }