コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Saroko-dnd/My_DZ
        public void SaveChanges(BankBranch BranchToSave)
        {
            try
            {
                string Longitude = string.Empty;
                string Latitude = string.Empty;
                if (UseMapCoordinatesCheckBox.IsChecked.Value)
                {
                    Longitude = MainMap.Position.Lng.ToString().Replace(",", ".");
                    Latitude = MainMap.Position.Lat.ToString().Replace(",", ".");
                    if (AddNewBranch)
                    {
                        BranchToSave.MapLocation = DbGeography.FromText(MyResourses.Texts.POINT + "(" + Longitude +
                            " " + Latitude + ")");
                    }
                    else
                    {
                        EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                            MapLocation 
                            = DbGeography.FromText(MyResourses.Texts.POINT + "(" + Longitude +
                            " " + Latitude + ")");
                        EntityConnector.StaticBanksDBContext.SaveChanges();
                    }
                }
                else
                {
                    Longitude = LongitudeTextBox.Text.Replace(",", ".");
                    Latitude = LatitudeTextBox.Text.Replace(",", ".");
                    if (AddNewBranch)
                    {
                        BranchToSave.MapLocation = DbGeography.FromText(MyResourses.Texts.POINT + "(" + Longitude +
                            " " + Latitude + ")");
                    }
                    else
                    {
                        EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                            MapLocation
                            = DbGeography.FromText(MyResourses.Texts.POINT + "(" + Longitude +
                            " " + Latitude + ")");
                        EntityConnector.StaticBanksDBContext.SaveChanges();
                    }
                }
                if (YearTextBox.Text != string.Empty && MonthTextBox.Text != string.Empty &&
                    DayTextBox.Text != string.Empty)
                {
                    if (Int32.Parse(MonthTextBox.Text) > 12 || Int32.Parse(DayTextBox.Text) > 31)
                    {
                        throw new InvalidOperationException();
                    }
                    else
                    {
                        if (AddNewBranch)
                        BranchToSave.OpeningDate = new DateTime(Int32.Parse(YearTextBox.Text), 
                            Int32.Parse(MonthTextBox.Text), Int32.Parse(DayTextBox.Text));
                        else
                        {
                            EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                                OpeningDate = new DateTime(Int32.Parse(YearTextBox.Text),
                            Int32.Parse(MonthTextBox.Text), Int32.Parse(DayTextBox.Text));
                            EntityConnector.StaticBanksDBContext.SaveChanges();
                        }
                    }
                }
                if (WorkHourBeginTextBox.Text != string.Empty && WorkHourEndTextBox.Text != string.Empty &&
                    WorkMinutesBeginTextBox.Text != string.Empty && WorkMinutesEndTextBox.Text != string.Empty)
                {
                    if (Byte.Parse(WorkHourBeginTextBox.Text) > 24 || Byte.Parse(WorkHourEndTextBox.Text) > 24 ||
                        Byte.Parse(WorkMinutesBeginTextBox.Text) > 59 || Byte.Parse(WorkMinutesEndTextBox.Text) > 59)
                        throw new InvalidOperationException();
                    else
                    {
                        if (AddNewBranch)
                        {
                            BranchToSave.WorkingHours = new WorkingHours()
                            {
                                EndHour = Byte.Parse(WorkHourEndTextBox.Text),
                                StartHour = Byte.Parse(WorkHourBeginTextBox.Text),
                                StartMinutes = Byte.Parse(WorkMinutesBeginTextBox.Text),
                                EndMinutes = Byte.Parse(WorkMinutesEndTextBox.Text)
                            };
                        }
                        else
                        {
                            EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                                WorkingHours = new WorkingHours()
                            {
                                EndHour = Byte.Parse(WorkHourEndTextBox.Text),
                                StartHour = Byte.Parse(WorkHourBeginTextBox.Text),
                                StartMinutes = Byte.Parse(WorkMinutesBeginTextBox.Text),
                                EndMinutes = Byte.Parse(WorkMinutesEndTextBox.Text)
                            };
                            EntityConnector.StaticBanksDBContext.SaveChanges();
                        }

                    }
                }
                  
                if (!AddNewBranch && EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BranchName == BranchNameTextBox.Text).
                    Where(res => res.BankBranchID != BranchToSave.BankBranchID).ToList().Count > 0)
                {
                    MessageBox.Show(MyResourses.Texts.BranchAlreadyExists, MyResourses.Texts.Error,
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    throw new InvalidOperationException();
                }
                else if (AddNewBranch && EntityConnector.StaticBanksDBContext.BankBranches.Any(res => res.BranchName == BranchNameTextBox.Text))
                {
                    MessageBox.Show(MyResourses.Texts.BranchAlreadyExists, MyResourses.Texts.Error,
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    throw new InvalidOperationException();
                }
                if (AddNewBranch)
                {
                    BranchToSave.BranchName = BranchNameTextBox.Text;
                    BranchToSave.Address = AddressTextBox.Text;
                    BranchToSave.Phone = PhoneTextBox.Text;
                }
                else
                {
                    EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().BranchName = BranchNameTextBox.Text;
                    EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().Address = AddressTextBox.Text;
                    EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().Phone = PhoneTextBox.Text;
                    EntityConnector.StaticBanksDBContext.SaveChanges();
                }      

                if (FirstNameSelectedTextBox.Text != string.Empty && LastNameSelectedTextBox.Text != string.Empty &&
                    PatronymicSelectedTextBox.Text != string.Empty && CashierPhoneTextBox.Text != string.Empty)
                {
                    if (AddNewBranch)
                    {
                        BranchToSave.RelatedCashier = new Cashier()
                        {
                            FirstName = FirstNameSelectedTextBox.Text,
                            LastName = LastNameSelectedTextBox.Text,
                            Patronymic = PatronymicSelectedTextBox.Text,
                            Phone = CashierPhoneTextBox.Text
                        };
                    }
                    else
                    {
                        EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().RelatedCashier 
                            = new Cashier()
                        {
                            FirstName = FirstNameSelectedTextBox.Text,
                            LastName = LastNameSelectedTextBox.Text,
                            Patronymic = PatronymicSelectedTextBox.Text,
                            Phone = CashierPhoneTextBox.Text
                        };
                        EntityConnector.StaticBanksDBContext.SaveChanges();
                    }
                }

                if (EUROBuyTextBox.Text != string.Empty && EUROSellTextBox.Text != string.Empty &&
                    RUBBuyTextBox.Text != string.Empty && RUBSellTextBox.Text != string.Empty &&
                    USDBuyTextBox.Text != string.Empty && USDSellTextBox.Text != string.Empty)
                {
                    if (AddNewBranch)
                    {
                        BranchToSave.RelatedRates = new ExchangeRates()
                        {
                            EUROBuy = double.Parse(EUROBuyTextBox.Text),
                            EUROSell = double.Parse(EUROSellTextBox.Text),
                            RuBuy = double.Parse(RUBBuyTextBox.Text),
                            RuSell = double.Parse(RUBSellTextBox.Text),
                            USDBuy = double.Parse(USDBuyTextBox.Text),
                            USDSell = double.Parse(USDSellTextBox.Text),
                        };
                    }
                    else
                    {
                        EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                            RelatedRates = new ExchangeRates()
                        {
                            EUROBuy = double.Parse(EUROBuyTextBox.Text),
                            EUROSell = double.Parse(EUROSellTextBox.Text),
                            RuBuy = double.Parse(RUBBuyTextBox.Text),
                            RuSell = double.Parse(RUBSellTextBox.Text),
                            USDBuy = double.Parse(USDBuyTextBox.Text),
                            USDSell = double.Parse(USDSellTextBox.Text),
                        };
                        EntityConnector.StaticBanksDBContext.SaveChanges();
                    }
                }

                if (AddNewBranch)
                {
                    foreach (var CurrentItem in BreakTimesDataGrid.Items)
                    {
                        if ((CurrentItem as BreakTime) != null)
                            BranchToSave.BreakTimes.Add(CurrentItem as BreakTime);
                    }
                    foreach (var CurrentItem in ServicesDataGrid.Items)
                    {
                        if ((CurrentItem as Service) != null)
                        {
                            string ServiceName = (CurrentItem as Service).Servise;
                            if (EntityConnector.StaticBanksDBContext.Services.Any(res => res.Servise == ServiceName))
                                BranchToSave.RelatedServices.Add(EntityConnector.StaticBanksDBContext.Services.Where(res => res.Servise == ServiceName).First());
                            else
                                BranchToSave.RelatedServices.Add(CurrentItem as Service);
                        }
                    }
                    foreach (var CurrentItem in CommentsDataGrid.Items)
                    {
                        if ((CurrentItem as Comment) != null)
                            BranchToSave.RelatedComments.Add(new Comment() { CommentItself = (CurrentItem as Comment).CommentItself });
                    }
                }
                else
                {
                    List<BreakTime> NewBreakTimes = new List<BreakTime>();
                    List<Service> NewServices = new List<Service>();
                    List<Comment> NewComments = new List<Comment>();
                    foreach (var CurrentItem in BreakTimesDataGrid.Items)
                    {
                        if ((CurrentItem as BreakTime) != null)
                        {
                            NewBreakTimes.Add(CurrentItem as BreakTime);
                        }
                    }
                    EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().BreakTimes
                         = NewBreakTimes;
                    EntityConnector.StaticBanksDBContext.SaveChanges();
                    foreach (var CurrentItem in ServicesDataGrid.Items)
                    {
                        if ((CurrentItem as Service) != null)
                        {
                            string ServiceName = (CurrentItem as Service).Servise;
                            if (EntityConnector.StaticBanksDBContext.Services.Any(res => res.Servise == ServiceName))
                                NewServices.Add(EntityConnector.StaticBanksDBContext.Services.Where(res => res.Servise == ServiceName).First());
                            else
                                NewServices.Add(CurrentItem as Service);
                        }
                    }
                    EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                        RelatedServices = NewServices;
                    EntityConnector.StaticBanksDBContext.SaveChanges();
                    foreach (var CurrentItem in CommentsDataGrid.Items)
                    {
                        if ((CurrentItem as Comment) != null)
                            NewComments.Add(CurrentItem as Comment);
                    }
                    foreach (Comment CurComment in NewComments)
                    {
                        CurComment.RelatedBranch = EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First();
                    }
                        EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().
                        RelatedComments = NewComments;
                        EntityConnector.StaticBanksDBContext.SaveChanges();
                }


                EntityConnector.AddNewBankIfNecessary(RelatedBankNameTextBox.Text);
                BranchToSave.RelatedBank = null;
                if (AddNewBranch)
                {
                    EntityConnector.StaticBanksDBContext.Banks.Where(res => res.BankName == RelatedBankNameTextBox.Text).
                        First().RelatedBranches.Add(BranchToSave);
                }
                else
                {
                    EntityConnector.StaticBanksDBContext.BankBranches.Where(res => res.BankBranchID == BranchToSave.BankBranchID).First().RelatedBank = EntityConnector.StaticBanksDBContext.Banks.
                        Where(res => res.BankName == RelatedBankNameTextBox.Text).First();
                }
                EntityConnector.StaticBanksDBContext.SaveChanges();
                LoadObjectsOnMap();
            }
            catch (Exception CurrentException)
            {
                MessageBox.Show(MyResourses.Texts.CheckCharacharsError, MyResourses.Texts.Error,
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Saroko-dnd/My_DZ
 public void StartSearchMapButtonClick(Object Sender, EventArgs CurrentArgs)
 {
     SelectedBranchBuf = EntityConnector.GetNearestBranch(MainMap.Position.Lat, MainMap.Position.Lng);
     ShowBranchInfo(SelectedBranchBuf);
     ChangeMapCenter((double)SelectedBranchBuf.MapLocation.Latitude, (double)SelectedBranchBuf.MapLocation.Longitude);
     SelectedTabItem.IsSelected = true;
     ChangeColorOfSelectedBranch(SelectedBranchBuf.BranchName);
 }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: Saroko-dnd/My_DZ
 public void ShowBranchInfo(BankBranch SelectedBranch)
 {
     ClearDataFromFields();
     if (SelectedBranch.RelatedBank != null)
         RelatedBankNameTextBox.Text = SelectedBranch.RelatedBank.BankName;
     if (SelectedBranch.BranchName != null)
         BranchNameTextBox.Text = SelectedBranch.BranchName;
     if (SelectedBranch.Address != null)
         AddressTextBox.Text = SelectedBranch.Address;
     if (SelectedBranch.Phone != null)
         PhoneTextBox.Text = SelectedBranch.Phone;
     if (SelectedBranch.RelatedCashier != null)
     {
         FirstNameSelectedTextBox.Text = SelectedBranch.RelatedCashier.FirstName;
         LastNameSelectedTextBox.Text = SelectedBranch.RelatedCashier.LastName;
         PatronymicSelectedTextBox.Text = SelectedBranch.RelatedCashier.Patronymic;
         CashierPhoneTextBox.Text = SelectedBranch.RelatedCashier.Phone;
     }
     if (SelectedBranch.RelatedRates != null)
     {
         USDBuyTextBox.Text = SelectedBranch.RelatedRates.USDBuy.ToString();
         EUROBuyTextBox.Text = SelectedBranch.RelatedRates.EUROBuy.ToString();
         RUBBuyTextBox.Text = SelectedBranch.RelatedRates.RuBuy.ToString();
         USDSellTextBox.Text = SelectedBranch.RelatedRates.USDSell.ToString();
         EUROSellTextBox.Text = SelectedBranch.RelatedRates.EUROSell.ToString();
         RUBSellTextBox.Text = SelectedBranch.RelatedRates.RuSell.ToString();
     }
     if (SelectedBranch.RelatedServices != null)
     {
         ItemsSourseServices = SelectedBranch.RelatedServices.ToList();
         ServicesDataGrid.ItemsSource = ItemsSourseServices;
     }
     if (SelectedBranch.WorkingHours != null)
     {
         WorkHourBeginTextBox.Text = SelectedBranch.WorkingHours.StartHour.ToString();
         WorkMinutesBeginTextBox.Text = SelectedBranch.WorkingHours.StartMinutes.ToString();
         WorkHourEndTextBox.Text = SelectedBranch.WorkingHours.EndHour.ToString();
         WorkMinutesEndTextBox.Text = SelectedBranch.WorkingHours.EndMinutes.ToString();
     }
     if (SelectedBranch.BreakTimes != null)
     {
         ItemsSourseBreakTimes = SelectedBranch.BreakTimes.ToList();
         BreakTimesDataGrid.ItemsSource = ItemsSourseBreakTimes;
     }
     if (SelectedBranch.RelatedComments != null)
     {
         ItemsSourceComments = SelectedBranch.RelatedComments.ToList();
         CommentsDataGrid.ItemsSource = ItemsSourceComments;
     }
     if (SelectedBranch.MapLocation != null)
     {
         LongitudeTextBox.Text = SelectedBranch.MapLocation.Longitude.ToString();
         LatitudeTextBox.Text = SelectedBranch.MapLocation.Latitude.ToString();
     }
     if (SelectedBranch.OpeningDate != null)
     {
         YearTextBox.Text = SelectedBranch.OpeningDate.Value.Year.ToString();
         MonthTextBox.Text = SelectedBranch.OpeningDate.Value.Month.ToString();
         DayTextBox.Text = SelectedBranch.OpeningDate.Value.Day.ToString();
     }
 }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: Saroko-dnd/My_DZ
 public void StartSearchRatesButtonClick(Object Sender, EventArgs CurrentArgs)
 {
     try
     {
         if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.EURORadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MinBuyValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.EURO,true,true);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.EURORadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MaxBuyValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.EURO, false, true);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.EURORadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MaxSellValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.EURO, true, false);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.EURORadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MinSellValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.EURO, false, false);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.RUBRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MinBuyValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.RUB, true, true);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.RUBRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MaxBuyValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.RUB, false, true);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.RUBRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MaxSellValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.RUB, true, false);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.RUBRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MinSellValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.RUB, false, false);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.USDRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MinBuyValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.USD, true, true);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.USDRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MaxBuyValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.USD, false, true);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.USDRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MaxSellValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.USD, true, false);
         }
         else if (MoneyTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.USDRadioButton
             && RatesSearchTypeRadioButtons.Where(res => res.IsChecked == true).First().
             Name == MyResourses.Texts.MinSellValueRadioButton)
         {
             SelectedBranchBuf = EntityConnector.GetNecessaryBankRates(MyResourses.Texts.USD, false, false);
         }
         ShowBranchInfo(SelectedBranchBuf);
         ChangeMapCenter((double)SelectedBranchBuf.MapLocation.Latitude, (double)SelectedBranchBuf.MapLocation.Longitude);
         SelectedTabItem.IsSelected = true;
         ChangeColorOfSelectedBranch(SelectedBranchBuf.BranchName);
     }
     catch (Exception CurrentException)
     {
         MessageBox.Show(MyResourses.Texts.CheckRadioButtonsError, MyResourses.Texts.Error, 
             MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: Saroko-dnd/My_DZ
        public void ClickMarkerEvent(Object Sender, EventArgs CurrentArgs)
        {
            foreach (GMapMarker CurrentMarker in MainMap.Markers)
            {
                if (CurrentMarker != null)
                    (CurrentMarker.Shape as Label).Background = Brushes.Black;
            }
            if ((Sender as Label) != null)
            {
                (Sender as Label).Background = Brushes.Blue;

                SelectedBranchBuf = EntityConnector.LoadSelectedObjectData((Sender as Label).Content.ToString());

                ShowBranchInfo(SelectedBranchBuf);
            }
        }