private void CheckSubScriptionId(bool IsForward)
        {
            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.SaveMessageTitleSingleBilling, 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);
                        if (IsForward)
                        {
                            TextBoxCurrentReadDate.Focus();
                            TextBoxCurrentReadDate.SelectAll();
                        }
                        else
                        {
                            TextBoxCurrentRead.Focus();
                            TextBoxCurrentRead.SelectAll();
                        }
                    }
                    else
                    {
                        Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.NotFoundSubscriptionOrBill, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                        EmptyControl();
                        FirstControl.Focus();
                        FirstControl.SelectAll();
                    }
                }
            }
            catch
            {
                Msg       = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
                FirstControl.Focus();
                FirstControl.SelectAll();
            }
        }
Example #2
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog Msg;

            try
            {
                Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SaveMessageBilling, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                if (Msg.ShowDialog() == true)
                {
                    Commons.Db.SaveChanges();
                    LoadBills();
                    Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SaveMessageSuccessBilling, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                    Msg.ShowDialog();
                    TextBoxCurrentRead.Focus();
                    TextBoxCurrentRead.SelectAll();
                }
            }
            catch
            {
                Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                Msg.ShowDialog();
                TextBoxCurrentRead.Focus();
                TextBoxCurrentRead.SelectAll();
            }
        }
 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[] { GridColSave }, new Button[] { ButtonSave }, true);
     Ac.AnimateRowGrid(GridRowSearch, GridRowNew, GridSearch, GridNew, ref PrevHeight);
     FirstControl.Focus();
     TextBoxCurrentRead.SelectAll();
 }
Example #4
0
 private void UserControlBilling_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (((bool)e.NewValue))
     {
         if (FormLoaded == true || Commons.EditAccountType[1] == true || Commons.EditCustomer[1] == true || Commons.EditSubScription[0] == true || Commons.EditBillPeriod[0] == true)
         {
             Wd = new WaitingDialog(Messages.LoadSubTitle, Messages.WaitingLoadSub, GridHeader.Background);
             Wd.Show();
             LoadThisPeriodBillsList = true;
             if (LoadFirst() == -1)
             {
                 MessageDialog Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.NotExistPeriodBilling, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                 Msg.ShowDialog();
                 TextBoxCurrentRead.SelectAll();
             }
             Commons.EditAccountType[1]  = false;
             Commons.EditCustomer[1]     = false;
             Commons.EditSubScription[0] = false;
             Commons.EditBillPeriod[0]   = false;
             FormLoaded = false;
             Wd.Close();
         }
         else
         {
             if (CurrentPeriodIsFilled)
             {
                 MessageDialog Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SubScriptionNextNotFound, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                 Msg.ShowDialog();
                 TextBoxCurrentRead.SelectAll();
             }
             if (CurentPeriodNotSelectedOrNotCreated)
             {
                 MessageDialog Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.NotExistPeriodBilling, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                 Msg.ShowDialog();
                 TextBoxCurrentRead.SelectAll();
             }
         }
     }
 }
Example #5
0
        private void DoNext()
        {
            MessageDialog Msg;
            int           FeedBack = LoadNextSubScription();

            if (FeedBack == -1)
            {
                Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SubScriptionNextNotFound, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.ShowDialog();
                TextBoxCurrentRead.SelectAll();
            }
            else if (FeedBack == -2)
            {
                Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SubScriptionIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.ShowDialog();
                TextBoxCurrentRead.SelectAll();
            }
            else if (FeedBack == -3)
            {
                Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SubScriptionNotFound, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.ShowDialog();
                TextBoxCurrentRead.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();
            }
        }
        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();
                    }
                }
            }
        }
Example #8
0
        private void PreSave()
        {
            ControlsValidate?Vd   = Commons.ValidateData(FirstControl, ControlsArray);
            MessageDialog    Msg  = null;
            bool             Next = false;

            if (CurrentBillPeriod != null)
            {
                if (Vd != null)
                {
                    Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.ShowDialog();
                    Vd.Value.Control.Focus();
                }
                else
                {
                    if (string.Compare(CurrentBillPeriod.DateTo.Trim(), Commons.GetCurrentPersianDate()) <= 0)
                    {
                        DomainClasses.SubscriptionsTb MySubscription = CurrentSubscriptionBilling.SubScription;
                        long NewNumber = Convert.ToInt64(TextBoxCurrentRead.Text);
                        if (NewNumber == 0)
                        {
                            Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.SaveMessageBillingNext, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                            if (Msg.ShowDialog() == true)
                            {
                                MySubscription.BillingInPeriod = CurrentBillPeriod.Id;
                                //Commons.Db.Entry(MySubscription).CurrentValues.SetValues(MySubscription);
                                //Commons.Db.SaveChanges();
                                Next = true;
                                DoNext();
                            }
                            TextBoxCurrentRead.SelectAll();
                            return;
                        }
                        long MyConsumption = NewNumber - MySubscription.CurrentNumber;
                        int  ChkDate       = 0;
                        if (MyConsumption >= 0)
                        {
                            ChkDate = Commons.CheckDateFromTo(MySubscription.CurrentReadDate, CurrentBillPeriod.DateTo);
                            int DistMonth = 0;
                            if (ChkDate == 0)
                            {
                                DistMonth = Commons.DistanceBetweenMonthsForBilling(MySubscription.CurrentReadDate, CurrentBillPeriod.DateTo);
                                if (DistMonth > 0)
                                {
                                    long[] Result = Commons.Consumption(MyConsumption, CurrentSubscriptionBilling.AccountTypeFormula, DistMonth);
                                    if (Result != null)
                                    {
                                        try
                                        {
                                            BillsTb NewBill = Commons.Db.Bills.Add(new DomainClasses.BillsTb
                                            {
                                                SubscriptionId              = MySubscription.Id,
                                                Status                      = BillsStatus.Billing,
                                                PrevNumber                  = MySubscription.CurrentNumber,
                                                PrevReadDate                = MySubscription.CurrentReadDate,
                                                CurrentNumber               = NewNumber,
                                                CurrentReadDate             = CurrentBillPeriod.DateTo,
                                                Consumption                 = MyConsumption,
                                                AllowableConsumption        = Result[0],
                                                ExtraConsumption            = Result[1],
                                                PriceOfConsumption          = Result[4],
                                                PriceOfAllowableConsumption = Result[2],
                                                PriceOfExtraConsumption     = Result[3],
                                                Vat              = Result[5],
                                                Year             = Commons.GetCurrentYear(),
                                                CurrentPeriod    = CurrentBillPeriod.Id,
                                                PrevDebt         = MySubscription.Debt,
                                                Prevdeficit1000  = MySubscription.deficit1000,
                                                PrevPrevNumber   = MySubscription.PrevNumber,
                                                PrevPrevReadDate = MySubscription.PrevReadDate,
                                                WaterMeterSerial = MySubscription.WaterMeterSerial,
                                                AccountTypeId    = MySubscription.AccountTypeId,
                                                PreventTypeId    = MySubscription.PreventTypeId,
                                                ReceivableDate   = ""
                                            });
                                            long AllPrices  = Result[4] + Result[5] + MySubscription.Debt + MySubscription.deficit1000;
                                            long NewDeficit = Commons.GetDeficit1000(AllPrices);
                                            MySubscription.Debt        = AllPrices - NewDeficit;
                                            MySubscription.deficit1000 = NewDeficit;

                                            MySubscription.PrevNumber      = MySubscription.CurrentNumber;
                                            MySubscription.PrevReadDate    = MySubscription.CurrentReadDate;
                                            MySubscription.CurrentReadDate = CurrentBillPeriod.DateTo;
                                            MySubscription.CurrentNumber   = NewNumber;
                                            MySubscription.BillingInPeriod = CurrentBillPeriod.Id;
                                            Bills.Add(new BillingDetails
                                            {
                                                Id                          = NewBill.Id,
                                                SubId                       = CurrentSubscriptionBilling.SubScription.Id,
                                                CustId                      = CurrentSubscriptionBilling.CustId,
                                                Name                        = CurrentSubscriptionBilling.CustName,
                                                Family                      = CurrentSubscriptionBilling.CustFamily,
                                                Father                      = CurrentSubscriptionBilling.CustFather,
                                                Prevent                     = CurrentSubscriptionBilling.PreventName,
                                                AccounType                  = CurrentSubscriptionBilling.AccountTypeName,
                                                PrevDebt                    = CurrentSubscriptionBilling.SubScription.Debt,
                                                deficit1000                 = NewDeficit,
                                                Prevdeficit1000             = CurrentSubscriptionBilling.SubScription.deficit1000,
                                                CurrentReadDate             = CurrentBillPeriod.DateTo,
                                                CurrentNumber               = NewNumber,
                                                PrevReadDate                = CurrentSubscriptionBilling.SubScription.CurrentReadDate,
                                                PrevNumber                  = CurrentSubscriptionBilling.SubScription.CurrentNumber,
                                                AllowableConsumption        = Result[0],
                                                Consumption                 = MyConsumption,
                                                ExtraConsumption            = Result[1],
                                                PriceOfAllowableConsumption = Result[2],
                                                PriceOfConsumption          = Result[4],
                                                PriceOfExtraConsumption     = Result[3],
                                                Vat                         = Result[5],
                                                SumOfPeriod                 = Result[4] + CurrentSubscriptionBilling.SubScription.Debt + Result[5],
                                                AllPrices                   = AllPrices,
                                                PayablePrice                = AllPrices - NewDeficit
                                            });
                                            Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.PreSaveMessageSuccessBilling, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                                            Msg.ShowDialog();
                                            Next = true;
                                        }
                                        catch
                                        {
                                            Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                                            Msg.ShowDialog();
                                            TextBoxCurrentRead.SelectAll();
                                        }
                                    }
                                    else
                                    {
                                        Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.FormulaIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                        Msg.ShowDialog();
                                        TextBoxCurrentRead.SelectAll();
                                    }
                                }
                                else
                                {
                                    Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.ToDateIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                    Msg.ShowDialog();
                                    TextBoxCurrentRead.SelectAll();
                                }
                            }
                            else
                            {
                                if (ChkDate == -1)
                                {
                                    Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.ToDateIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                    Msg.ShowDialog();
                                    TextBoxCurrentRead.SelectAll();
                                }
                                else
                                {
                                    Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.DateIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                    Msg.ShowDialog();
                                    TextBoxCurrentRead.SelectAll();
                                }
                            }
                        }
                        else
                        {
                            Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.NumberIsWrong, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                            Msg.ShowDialog();
                            TextBoxCurrentRead.SelectAll();
                        }
                    }
                    else
                    {
                        Msg = new MessageDialog(Messages.SaveMessageTitleSingleBilling, Messages.DateIsNotAllowedBiggarThanCurrentDate, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.ShowDialog();
                        TextBoxCurrentRead.SelectAll();
                    }
                }
            }
            else
            {
                Msg = new MessageDialog(Messages.SaveMessageTitleBilling, Messages.NotExistPeriodBilling, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.ShowDialog();
                TextBoxCurrentRead.SelectAll();
            }
            if (Next)
            {
                DoNext();
            }
        }