コード例 #1
0
 private void ButtonDefination_Click(object sender, RoutedEventArgs e)
 {
     Ac.AnimateButton(new ColumnDefinition[] { GridColReport }, new Button[] { ButtonReport }, false);
     Ac.SelectButtonRed(sender, ref PrvButton, this);
     Ac.AnimateButton(new ColumnDefinition[] { }, new Button[] { }, true);
     Ac.AnimateRowGrid(GridRowSearch, GridRowNew, GridSearch, GridNew, ref PrevHeight);
     FirstControl.Focus();
     TextBoxSubScriptionId.SelectAll();
 }
        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();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
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.SaveMessageTitleSingleBilling, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                    Vd.Value.Control.Focus();
                }
                else
                {
                    SubscriptionsTb MySubscription = CurrentSubscriptionBilling.SubScription;
                    if (string.Compare(TextBoxCurrentReadDate.Text.Trim(), Commons.GetCurrentPersianDate()) <= 0)
                    {
                        long NewNumber     = Convert.ToInt64(TextBoxCurrentRead.Text);
                        long MyConsumption = NewNumber - MySubscription.CurrentNumber;
                        int  ChkDate       = 0;
                        if (MyConsumption >= 0)
                        {
                            ChkDate = Commons.CheckDateFromTo(MySubscription.CurrentReadDate, TextBoxCurrentReadDate.Text.Trim());
                            int DistMonth = 0;
                            if (ChkDate == 0)
                            {
                                DistMonth = Commons.DistanceBetweenMonthsForBilling(MySubscription.CurrentReadDate, TextBoxCurrentReadDate.Text.Trim());
                                if (DistMonth > 0)
                                {
                                    long[] Result = Commons.Consumption(MyConsumption, CurrentSubscriptionBilling.AccountTypeFormula, DistMonth);
                                    if (Result != null)
                                    {
                                        Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.SaveMessageSingleBilling, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                                        Msg.Owner = Window.GetWindow(this);
                                        if (Msg.ShowDialog() == true)
                                        {
                                            try
                                            {
                                                BillsTb NewBill = Commons.Db.Bills.Add(new DomainClasses.BillsTb
                                                {
                                                    SubscriptionId              = MySubscription.Id,
                                                    SubscriptionYear            = Commons.CurrentYear,
                                                    Status                      = BillsStatus.Billing,
                                                    PrevNumber                  = MySubscription.CurrentNumber,
                                                    PrevReadDate                = MySubscription.CurrentReadDate,
                                                    CurrentNumber               = NewNumber,
                                                    CurrentReadDate             = TextBoxCurrentReadDate.Text.Trim(),
                                                    Consumption                 = MyConsumption,
                                                    AllowableConsumption        = Result[0],
                                                    ExtraConsumption            = Result[1],
                                                    PriceOfConsumption          = Result[4],
                                                    PriceOfAllowableConsumption = Result[2],
                                                    PriceOfExtraConsumption     = Result[3],
                                                    Vat = Result[5],
                                                    SubscriptionCost = Commons.Subscription * DistMonth,
                                                    Year             = Commons.CurrentYear,
                                                    CurrentPeriod    = Commons.CPeriod.Id,
                                                    PrevDebt         = MySubscription.Debt,
                                                    Prevdeficit1000  = MySubscription.deficit1000,
                                                    PrevPrevNumber   = MySubscription.PrevNumber,
                                                    PrevPrevReadDate = MySubscription.PrevReadDate,
                                                    WaterMeterId     = MySubscription.WaterMeter.Id,
                                                    WaterMeterYear   = Commons.CurrentYear,
                                                    AccountTypeId    = MySubscription.AccountTypeId,
                                                    AccountTypeYear  = Commons.CurrentYear,
                                                    PreventTypeId    = MySubscription.PreventTypeId,
                                                    PreventTypeYear  = Commons.CurrentYear,
                                                    ReceivableDate   = "",
                                                    CancelDate       = ""
                                                });
                                                long AllPrices  = Result[4] + Result[5] + MySubscription.Debt + MySubscription.deficit1000 + (Commons.Subscription * DistMonth);
                                                long NewDeficit = Commons.GetDeficit1000(AllPrices);
                                                MySubscription.Debt        = AllPrices - NewDeficit;
                                                MySubscription.deficit1000 = NewDeficit;

                                                MySubscription.PrevNumber      = MySubscription.CurrentNumber;
                                                MySubscription.PrevReadDate    = MySubscription.CurrentReadDate;
                                                MySubscription.CurrentReadDate = TextBoxCurrentReadDate.Text.Trim();
                                                MySubscription.CurrentNumber   = NewNumber;
                                                MySubscription.BillingInPeriod = Commons.CPeriod.Id;
                                                //به روز رسانی آخرین قرائت با کنتور فعلی
                                                MySubscription.WaterMeter.ReadEnd     = NewNumber;
                                                MySubscription.WaterMeter.ReadDateEnd = TextBoxCurrentReadDate.Text.Trim();

                                                Commons.Db.SaveChanges();
                                                SearchAgain = true;
                                                Msg         = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.SaveMessageSuccessSingleBilling, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                                                Msg.Owner   = Window.GetWindow(this);
                                                Msg.ShowDialog();
                                                EmptyControl();
                                                TextBoxSubScriptionId.Text  = "";
                                                TextBoxCurrentRead.Text     = "";
                                                TextBoxCurrentReadDate.Text = Commons.GetCurrentPersianDate().Trim();
                                                TextBoxSubScriptionId.Focus();
                                                TextBoxSubScriptionId.SelectAll();
                                            }
                                            catch
                                            {
                                                Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                                                Msg.Owner = Window.GetWindow(this);
                                                Msg.ShowDialog();
                                                TextBoxCurrentRead.SelectAll();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.FormulaIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                        Msg.Owner = Window.GetWindow(this);
                                        Msg.ShowDialog();
                                        TextBoxCurrentRead.SelectAll();
                                    }
                                }
                                else
                                {
                                    Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.ToDateIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                    Msg.Owner = Window.GetWindow(this);
                                    Msg.ShowDialog();
                                    TextBoxCurrentReadDate.Focus();
                                    TextBoxCurrentReadDate.SelectAll();
                                }
                            }
                            else
                            {
                                if (ChkDate == -1)
                                {
                                    Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.ToDateIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                    Msg.Owner = Window.GetWindow(this);
                                    Msg.ShowDialog();
                                    TextBoxCurrentReadDate.Focus();
                                    TextBoxCurrentReadDate.SelectAll();
                                }
                                else
                                {
                                    Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.DateIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                    Msg.Owner = Window.GetWindow(this);
                                    Msg.ShowDialog();
                                    TextBoxCurrentReadDate.Focus();
                                    TextBoxCurrentReadDate.SelectAll();
                                }
                            }
                        }
                        else
                        {
                            Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.NumberIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            TextBoxCurrentRead.SelectAll();
                        }
                    }
                    else
                    {
                        Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.DateIsNotAllowedBiggarThanCurrentDate, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                        TextBoxCurrentReadDate.Focus();
                        TextBoxCurrentReadDate.SelectAll();
                    }
                }
            }
        }