Beispiel #1
0
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            if (workersList.SelectedItem != null)
            {
                ContentDialog deleteFileDialog = new ContentDialog()
                {
                    Title               = "Подтверждение действия",
                    Content             = "Вы действительно хотите удалить работника?",
                    PrimaryButtonText   = "ОК",
                    SecondaryButtonText = "Отмена"
                };

                ContentDialogResult result = await deleteFileDialog.ShowAsync();

                if (result == ContentDialogResult.Primary)
                {
                    if (workersList.SelectedItem != null)
                    {
                        Worker worker = workersList.SelectedItem as Worker;
                        if (worker != null)
                        {
                            using (MobileContext db = new MobileContext())
                            {
                                db.Workers.Remove(worker);
                                db.SaveChanges();
                                workersList.ItemsSource = db.Workers.ToList();
                            }
                        }
                    }
                }
                else if (result == ContentDialogResult.Secondary)
                {
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Инициализирует одноэлементный объект приложения.  Это первая выполняемая строка разрабатываемого
        /// кода; поэтому она является логическим эквивалентом main() или WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new MobileContext())
            {
                db.Database.Migrate();
            }
        }
Beispiel #3
0
 private void LoadChartContents()
 {
     using (MobileContext db = new MobileContext())
     {
         List <Worker> wrk = new List <Worker>(db.Workers);
         // wrk.Add(new Worker() { name = "Том",salaryw=5600 });
         (PieChart.Series[0] as PieSeries).ItemsSource       = wrk;
         (ColumnChart.Series[0] as ColumnSeries).ItemsSource = wrk;
         (lineChart.Series[0] as LineSeries).ItemsSource     = wrk;
     }
 }
Beispiel #4
0
        public void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            using (MobileContext db = new MobileContext())
            {
                var z = db.Workers.ToList();
                //  List<Worker> z = l.FindAll(delegate (Worker worker)
                //  { return worker.name.Contains("Петр"); });

                workersList.ItemsSource = z;
                //List<Worker> z = db.Workers.ToList();
            }
        }
Beispiel #5
0
        private void textBoxFamaly_TextChanged(object sender, TextChangedEventArgs e)
        {
            using (MobileContext db = new MobileContext())
            {
                //  List<Worker> z = l.FindAll(delegate (Worker worker)
                //  { return  worker.name.Contains("Петр"); });
                List <Worker> l  = new List <Worker>(db.Workers);
                string        ur = textBoxFamaly.Text;
                List <Worker> p  = l.FindAll(t => t.family.Contains(ur));
                // or

                workersList.ItemsSource = p;
            }
        }
Beispiel #6
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e.Parameter != null)
     {
         int id = (int)e.Parameter;
         using (MobileContext db = new MobileContext())
         {
             worker = db.Workers.FirstOrDefault(c => c.Id == id);
         }
     }
     if (worker != null)
     {
         headerBlock.Text = "Редактирование сотрудника";
         nameBox.Text     = worker.name;
         familyBox.Text   = worker.family;
         hoursBox.Text    = (worker.hours).ToString();
         tarifBox.Text    = Convert.ToString(worker.Tariff);
     }
 }
Beispiel #7
0
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (MobileContext db = new MobileContext())
                {
                    if (worker != null)
                    {
                        if (worker.hours > 144)
                        {
                            worker.name    = nameBox.Text;
                            worker.family  = familyBox.Text;
                            worker.hours   = Convert.ToDouble(hoursBox.Text);
                            worker.Tariff  = Convert.ToDouble(tarifBox.Text);
                            zpp            = worker.hours - 144;
                            worker.salary  = (144 * worker.Tariff) + (zpp * (worker.Tariff) * 2);
                            worker.salaryw = worker.salary * 0.87;
                            db.Workers.Update(worker);
                            var itsok = new MessageDialog("Информация изменена!");
                            await itsok.ShowAsync();
                        }

                        else
                        {
                            worker.name   = nameBox.Text;
                            worker.family = familyBox.Text;
                            worker.hours  = Convert.ToDouble(hoursBox.Text);
                            worker.Tariff = Convert.ToDouble(tarifBox.Text);

                            worker.salary  = worker.hours * worker.Tariff;
                            worker.salaryw = worker.salary * 0.87;
                            db.Workers.Update(worker);
                            var itsok = new MessageDialog("Информация изменена!");
                            await itsok.ShowAsync();
                        }
                    }
                    else
                    {
                        double tar = Convert.ToDouble(tarifBox.Text);
                        double or  = Convert.ToDouble(hoursBox.Text);
                        if (or > 144)
                        {
                            zpp = or - 144;

                            double salary  = (144 * tar) + ((zpp * tar) * 2);
                            double salaryw = salary * 0.87;
                            double lol     = salaryw;
                            db.Workers.Add(new Worker {
                                name = nameBox.Text, family = familyBox.Text, hours = Convert.ToDouble(hoursBox.Text), Tariff = Convert.ToDouble(tarifBox.Text), salary = salary, salaryw = lol
                            });
                            var itsok = new MessageDialog("Информация сохранена!");
                            await itsok.ShowAsync();
                        }

                        else
                        {
                            double z   = Convert.ToDouble(hoursBox.Text);
                            double p   = Convert.ToDouble(tarifBox.Text);
                            double zp0 = z * p;
                            double zp  = (z * p) * 0.87;
                            db.Workers.Add(new Worker {
                                name = nameBox.Text, family = familyBox.Text, hours = Convert.ToDouble(hoursBox.Text), Tariff = Convert.ToDouble(tarifBox.Text), salary = zp0, salaryw = zp
                            });
                            var itsok = new MessageDialog("Информация сохранена!");
                            await itsok.ShowAsync();
                        }
                    }
                    db.SaveChanges();
                }
                GoToMainPage();
            }
            catch (FormatException)
            {
                var dialog = new MessageDialog("Неверные данные");
                await dialog.ShowAsync();
            }
        }