예제 #1
0
 private bool CheckSubscriptionInUse(SubscriptionsTb Sbc)
 {
     if (Commons.Db.Bills.Where(x => x.SubscriptionId == Sbc.Id).FirstOrDefault() == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
예제 #2
0
        private void ButtonShowEdit_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog Msg;

            try
            {
                string          id        = ((TextBlock)DataGridView.Columns[0].GetCellContent(DataGridView.SelectedItem)).Text;
                SubscriptionsTb RowEdited = Commons.Db.Subscriptions.Find(id, Commons.CurrentYear);
                if (RowEdited != null)
                {
                    TextBoxSubScriptionId.Text = id.Trim();
                    TextBoxCustomerId.Text     = RowEdited.CustomerId.ToString();
                    ReturnInfoCustomer(RowEdited.CustomerId);
                    int Id = 0;
                    foreach (object value in ComboBoxAccountType.Items)
                    {
                        Id = (int)((ComboBoxItem)value).Tag;
                        if (Id == RowEdited.AccountTypeId)
                        {
                            ComboBoxAccountType.SelectedItem = value;
                        }
                    }
                    foreach (object value in ComboBoxPreventType.Items)
                    {
                        Id = (int)((ComboBoxItem)value).Tag;
                        if (Id == RowEdited.PreventTypeId)
                        {
                            ComboBoxPreventType.SelectedItem = value;
                        }
                    }
                    TextBoxWaterMeterSerial.Text = RowEdited.WaterMeter.WaterMeterSerial.Trim();
                    TextBoxWaterMeterNumber.Text = RowEdited.PrevNumber.ToString().Trim();
                    TextBoxNumberReadDate.Text   = RowEdited.PrevReadDate.Trim();
                    TextBoxPostalCode.Text       = RowEdited.PostalCode.Trim();
                    TextBoxAddress.Text          = RowEdited.Address.Trim();
                    TextBoxComments.Text         = RowEdited.Description.Trim();


                    TextBlockCurrentNumber.Text   = RowEdited.CurrentNumber.ToString();
                    TextBlockCurrentReadDate.Text = RowEdited.CurrentReadDate.Trim();
                    TextBoxDebt.Text        = Commons.ConvertToMoneyWithSign(RowEdited.Debt);
                    TextBoxDeficit1000.Text = Commons.ConvertToMoneyWithSign(RowEdited.deficit1000);
                    ButtonDefination_Click(ButtonDefination, null);
                }
            }
            catch
            {
                Msg       = new MessageDialog(Messages.EditMessageTitleSubscriptions, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
            }
        }
예제 #3
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog   Msg;
            string          id         = ((TextBlock)DataGridView.Columns[0].GetCellContent(DataGridView.SelectedItem)).Text;
            SubscriptionsTb RowDeleted = Commons.Db.Subscriptions.Find(id, Commons.CurrentYear);

            if (RowDeleted != null)
            {
                try
                {
                    if (CheckSubscriptionInUse(RowDeleted) == false)
                    {
                        Msg       = new MessageDialog(Messages.DeleteMessageTitleSubscriptions, Messages.DeleteMessageSubscriptions, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        if (Msg.ShowDialog() == true)
                        {
                            WaterMetersTb Wd = Commons.Db.WaterMeters.Find(RowDeleted.WaterMeterId, Commons.CurrentYear);
                            if (Wd != null)
                            {
                                Commons.Db.WaterMeters.Remove(Wd);
                            }
                            Commons.Db.Subscriptions.Remove(RowDeleted);
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("SubScriptions");
                            List <SubscriptionsTb> L = (List <SubscriptionsTb>)DataGridView.ItemsSource;
                            if (L != null)
                            {
                                L.Remove(RowDeleted);
                            }
                            SearchAgain = true;
                            DataGridView.Items.Refresh();
                            Msg       = new MessageDialog(Messages.DeleteMessageTitleSubscriptions, Messages.DeleteMessageSuccessSubscriptions, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                    else
                    {
                        Msg       = new MessageDialog(Messages.DeleteMessageTitleSubscriptions, Messages.SubScriptInUseDelete, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                    }
                }
                catch
                {
                    Msg       = new MessageDialog(Messages.DeleteMessageTitleSubscriptions, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                }
            }
        }
예제 #4
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            ControlsValidate?Vd  = Commons.ValidateData(FirstControl, ControlsArray);
            MessageDialog    Msg = null;

            if (Vd != null)
            {
                Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
                Vd.Value.Control.Focus();
            }
            else
            {
                DomainClasses.CustomersTb MyCustomer = Commons.Db.Customers.Find(Convert.ToInt32(TextBoxCustomerId.Text), Commons.CurrentYear);
                if (MyCustomer == null)
                {
                    Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.NotFoundCustomers, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                    return;
                }
                DomainClasses.AccountTypesTb MyAccountType = Commons.Db.AccountTypes.Find(((Int32)((ComboBoxItem)ComboBoxAccountType.SelectedItem).Tag), Commons.CurrentYear);
                if (MyAccountType == null)
                {
                    Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.NotFoundAccountTypes, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                    return;
                }

                DomainClasses.SubscriptionsTb MySubscription = null;
                MySubscription = Commons.Db.Subscriptions.Find(TextBoxSubScriptionId.Text, Commons.CurrentYear);

                if (MySubscription == null)
                {
                    Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.SaveMessageSubscriptions, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    if (Msg.ShowDialog() == true)
                    {
                        try
                        {
                            int?MaxId = Commons.Db.WaterMeters.Where(x => x.Year == Commons.CurrentYear).Max(x => (int?)x.Id);
                            if (MaxId == null)
                            {
                                MaxId = 0;
                            }
                            MaxId++;
                            WaterMetersTb Wm = Commons.Db.WaterMeters.Add(new DomainClasses.WaterMetersTb
                            {
                                Id               = Convert.ToInt32(MaxId),
                                SubId            = TextBoxSubScriptionId.Text.Trim(),
                                Year             = Commons.CurrentYear,
                                ReadStart        = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim()),
                                ReadDateStart    = TextBoxNumberReadDate.Text.Trim(),
                                ReadEnd          = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim()),
                                ReadDateEnd      = TextBoxNumberReadDate.Text.Trim(),
                                WaterMeterSerial = TextBoxWaterMeterSerial.Text.Trim(),
                                Description      = "اولین کنتور آب",
                            });
                            Commons.Db.Subscriptions.Add(new DomainClasses.SubscriptionsTb
                            {
                                Id              = TextBoxSubScriptionId.Text.Trim(),
                                Year            = Commons.CurrentYear,
                                WaterMeter      = Wm,
                                PrevNumber      = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim()),
                                PrevReadDate    = TextBoxNumberReadDate.Text.Trim(),
                                CurrentNumber   = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim()),
                                CurrentReadDate = TextBoxNumberReadDate.Text.Trim(),
                                Debt            = Convert.ToInt64(TextBoxDebt.Text),
                                deficit1000     = Convert.ToInt64(TextBoxDeficit1000.Text),
                                BillingInPeriod = 0,
                                PostalCode      = TextBoxPostalCode.Text.Trim(),
                                Address         = TextBoxAddress.Text.Trim(),
                                CustomerId      = Convert.ToInt32(TextBoxCustomerId.Text.Trim()),
                                CustomerYear    = Commons.CurrentYear,
                                AccountTypeId   = Convert.ToInt32(((ComboBoxItem)ComboBoxAccountType.SelectedItem).Tag),
                                AccountTypeYear = Commons.CurrentYear,
                                PreventTypeId   = Convert.ToInt32(((ComboBoxItem)ComboBoxPreventType.SelectedValue).Tag),
                                PreventTypeYear = Commons.CurrentYear,
                                Description     = TextBoxComments.Text.Trim()
                            });
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("SubScriptions");
                            SearchAgain = true;
                            DataGridView.Items.Refresh();
                            Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.SaveMessageSuccessSubscriptions, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            ButtonNew_Click(null, null);
                        }
                        catch (Exception Ex)
                        {
                            if (Ex.InnerException != null)
                            {
                                if (Ex.InnerException.InnerException != null && Ex.InnerException.InnerException is SqlException)
                                {
                                    SqlException SEx = (SqlException)Ex.InnerException.InnerException;
                                    if (SEx.Message.Contains("IX_Unique_SubscriptionsTbs_PostalCode"))
                                    {
                                        Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.PostalCodeIsRepetitive, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                        Msg.Owner = Window.GetWindow(this);
                                        Msg.ShowDialog();
                                        TextBoxPostalCode.Focus();
                                        TextBoxPostalCode.SelectAll();
                                    }
                                }
                            }
                            else
                            {
                                Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                                Msg.Owner = Window.GetWindow(this);
                                Msg.ShowDialog();
                            }
                        }
                    }
                }
                else
                {
                    Msg       = new MessageDialog(Messages.EditMessageTitleSubscriptions, Messages.EditMessageSubscriptions, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    if (Msg.ShowDialog() == true)
                    {
                        try
                        {
                            if (CheckSubscriptionInUse(MySubscription) == false)
                            {
                                //Save When it doesn't have bill
                                WaterMetersTb WmTb = Commons.Db.WaterMeters.Find(MySubscription.WaterMeterId, Commons.CurrentYear);
                                if (WmTb != null)
                                {
                                    WmTb.ReadDateStart    = TextBoxNumberReadDate.Text.Trim();
                                    WmTb.ReadDateEnd      = TextBoxNumberReadDate.Text.Trim();
                                    WmTb.ReadEnd          = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim());
                                    WmTb.ReadStart        = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim());
                                    WmTb.WaterMeterSerial = TextBoxWaterMeterSerial.Text.Trim();
                                }
                                else
                                {
                                    Msg       = new MessageDialog(Messages.EditMessageTitleSubscriptions, Messages.NotWaterMeterExist, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                                    Msg.Owner = Window.GetWindow(this);
                                    Msg.ShowDialog();
                                }

                                MySubscription.PrevNumber      = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim());
                                MySubscription.PrevReadDate    = TextBoxNumberReadDate.Text.Trim();
                                MySubscription.CurrentNumber   = Convert.ToInt64(TextBoxWaterMeterNumber.Text.Trim());
                                MySubscription.CurrentReadDate = TextBoxNumberReadDate.Text.Trim();
                                //MySubscription.Debt = 0;
                                //MySubscription.deficit1000 = 0;
                            }
                            else
                            {
                                Msg       = new MessageDialog(Messages.EditMessageTitleSubscriptions, Messages.SubScriptInUseEdit, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                                Msg.Owner = Window.GetWindow(this);
                                Msg.ShowDialog();
                            }

                            MySubscription.PostalCode    = TextBoxPostalCode.Text.Trim();
                            MySubscription.Address       = TextBoxAddress.Text.Trim();
                            MySubscription.CustomerId    = Convert.ToInt32(TextBoxCustomerId.Text.Trim());
                            MySubscription.AccountTypeId = Convert.ToInt32(((ComboBoxItem)ComboBoxAccountType.SelectedItem).Tag);
                            MySubscription.PreventTypeId = Convert.ToInt32(((ComboBoxItem)ComboBoxPreventType.SelectedValue).Tag);
                            MySubscription.Description   = TextBoxComments.Text.Trim();
                            MySubscription.Debt          = Convert.ToInt64(TextBoxDebt.Text);
                            MySubscription.deficit1000   = Convert.ToInt64(TextBoxDeficit1000.Text);
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("SubScriptions");

                            List <SubscriptionsTb> Lc = (List <SubscriptionsTb>)DataGridView.ItemsSource;
                            if (Lc != null)
                            {
                                SubscriptionsTb Rc = Lc.Find(x => x.Id.Trim() == MySubscription.Id.Trim() && x.Year == Commons.CurrentYear);
                                if (Rc != null)
                                {
                                    Rc.AccountType     = MySubscription.AccountType;
                                    Rc.AccountType     = MySubscription.AccountType;
                                    Rc.AccountTypeId   = MySubscription.AccountTypeId;
                                    Rc.AccountTypeYear = MySubscription.AccountTypeYear;
                                    Rc.Address         = MySubscription.Address;
                                    Rc.BillingInPeriod = MySubscription.BillingInPeriod;
                                    Rc.CurrentReadDate = MySubscription.CurrentReadDate;
                                    Rc.CustomerId      = MySubscription.CustomerId;
                                    Rc.CustomerYear    = MySubscription.CustomerYear;
                                    Rc.Debt            = MySubscription.Debt;
                                    Rc.deficit1000     = MySubscription.deficit1000;
                                    Rc.Description     = MySubscription.Description;
                                    Rc.PostalCode      = MySubscription.PostalCode;
                                    Rc.PreventTypeId   = MySubscription.PreventTypeId;
                                    Rc.PreventTypeYear = MySubscription.PreventTypeYear;
                                    Rc.PrevNumber      = MySubscription.PrevNumber;
                                    Rc.PrevReadDate    = MySubscription.PrevReadDate;
                                    Rc.RecordDate      = MySubscription.RecordDate;
                                    Rc.WaterMeterId    = MySubscription.WaterMeterId;
                                    Rc.WaterMeterYear  = MySubscription.WaterMeterYear;
                                    Rc.Year            = MySubscription.Year;
                                }
                            }

                            SearchAgain = true;
                            DataGridView.Items.Refresh();
                            Msg       = new MessageDialog(Messages.EditMessageTitleSubscriptions, Messages.EditMessageSuccessSubscriptions, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            ButtonNew_Click(null, null);
                        }
                        catch (Exception Ex)
                        {
                            if (Ex.InnerException != null)
                            {
                                if (Ex.InnerException != null)
                                {
                                    if (Ex.InnerException.InnerException != null && Ex.InnerException.InnerException is SqlException)
                                    {
                                        SqlException SEx = (SqlException)Ex.InnerException.InnerException;
                                        if (SEx.Message.Contains("IX_Unique_SubscriptionsTbs_PostalCode"))
                                        {
                                            Msg       = new MessageDialog(Messages.SaveMessageTitleSubscriptions, Messages.PostalCodeIsRepetitive, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                                            Msg.Owner = Window.GetWindow(this);
                                            Msg.ShowDialog();
                                            TextBoxPostalCode.Focus();
                                            TextBoxPostalCode.SelectAll();
                                            return;
                                        }
                                    }
                                }
                            }
                            Msg       = new MessageDialog(Messages.EditMessageTitleSubscriptions, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }