コード例 #1
0
        private async void Button_Click_Save(object sender, RoutedEventArgs e)
        {
            _busyIndicator.IsBusy = true;

            // check if it is time to save
            decimal sum        = GetSum();        // sum = all in decimalUpDown
            decimal totaldepth = GetTotalDepth(); // TotalDepth = all depth remain
            bool    askedOnce  = false;


            //This never happens


            //vazi arnitika
            if (sum < TotalPaid && sum != totaldepth)
            {
                MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show($"Περισσεύουν {TotalPaid - sum } ευρώ που δεν έχουν τοποθετηθεί σε κάποιο χρέος. Θέλετε να τα τοποθετήσετε στο αποθεματικό παρόλο που υπάρχουν ανοιχτοί λογαριασμοί;", "ΠΡΟΣΟΧΗ", MessageBoxButton.YesNo);
                // if (result == MessageBoxResult.Yes) reserveNEW += TotalPaid - sum;
                if (result == MessageBoxResult.No)
                {
                    _busyIndicator.IsBusy = false;
                    return;
                }
            }
            if (comentbox.Text == "")
            {
                MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show($"Δεν έχετε συμπληρώσει κάποιο σχόλιο, Θέλετε να δημιουργηθεί αυτόματα;", "ΠΡΟΣΟΧΗ", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    CreateComment();
                    askedOnce = true;
                    //ask to add to comment
                }
                else if (result == MessageBoxResult.Cancel)
                {
                    _busyIndicator.IsBusy = false; return;
                }
                else if (result == MessageBoxResult.No)
                {
                    askedOnce = true;
                }
            }
            if (!askedOnce)
            {
                MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show($"Είστε σίγουροι ότι θέλετε να κάνετε αποθήκευση των αλλαγών;", "ΠΡΟΣΟΧΗ", MessageBoxButton.YesNo, MessageBoxImage.Information);

                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            SQLExecute sqlexec = new SQLExecute();
            //start
            string query = "";

            foreach (Depth d in depths)
            {
                int tempID = d.DepthID;

                string stDif    = "D" + tempID;
                string stPaid   = "P" + tempID;
                string stCheck  = "C" + tempID;
                string stRepaid = "R" + tempID;

                TextBlock     repaid = (TextBlock)DynamicGrid.FindName(stRepaid);
                DecimalUpDown paid   = (DecimalUpDown)DynamicGrid.FindName(stPaid);
                TextBlock     dif    = (TextBlock)DynamicGrid.FindName(stDif);
                CheckBox      check  = (CheckBox)DynamicGrid.FindName(stCheck);

                if (paid.Value != 0.0m)
                {
                    query += $"UPDATE Depth SET RepaidAmount = '{paid.Value + decimal.Parse(repaid.Text)}' WHERE DepthID = '{tempID}';";
                    if (dif.Text == paid.Value.ToString())
                    {
                        query += $"UPDATE Depth SET Paid = '' WHERE DepthID = '{tempID}'; ";
                    }
                    else
                    {
                        query += $"UPDATE Depth SET Paid = NULL WHERE DepthID = '{d.DepthID}'; ";
                    }
                }
            }

            //if ( reserveNEW+ reserveOLD!= Currentperson.Reserve)


            decimal reserveNEW = reserveOLD + (TotalPaid - sum);

            query += $"UPDATE Person SET Reserve = {reserveNEW} WHERE PersonID = '{Currentperson.PersonID}'; ";

            /*
             * if (sum != TotalPaid)
             * {
             *  decimal reserveNEW = 0.0m;
             *
             *
             *  if (sum < TotalPaid) reserveNEW = reserveOLD + (TotalPaid - sum);
             *  if (sum > TotalPaid) reserveNEW = reserveOLD - (sum - TotalPaid);
             *
             *  decimal test = reserveOLD + (TotalPaid - sum);
             *
             *  query += $"UPDATE Person SET Reserve = {reserveNEW} WHERE PersonID = '{Currentperson.PersonID}'; ";
             *
             *  //string temp = comentbox.Text;
             *  //decimal difRes = reserveNEW + reserveOLD - Currentperson.Reserve;
             *  //if(difRes > 0)
             *  //{
             *  //    temp += $" / Πρόσθετο αποθεματικό : {difRes}. ";
             *  //    comentbox.Text = temp;
             *  //}
             * }
             */
            List <Income> IncomeList = new List <Income>();

            IncomeList.Add(new Income {
                PersonID = (int)ComboBoxDepthPerson.SelectedValue, Amount = TotalPaid, Comment = comentbox.Text, Date = DatePicker1.Value ?? DateTime.Today, TypeIncomeID = 1
            });
            await Task.Run(() => sqlexec.SqlInsertIncome(Properties.Settings.Default.DBName, IncomeList));


            await Task.Run(() => sqlexec.SQLCommand(Properties.Settings.Default.DBName, query));


            int tempindex = ComboBoxDepthPerson.SelectedIndex;

            FillCombos(1);
            ResetData();
            await refreshAll();

            _busyIndicator.IsBusy             = false;
            ComboBoxDepthPerson.SelectedIndex = tempindex;
            //DrawInfos();
        }
コード例 #2
0
        private async Task FillFakeDatabase(int i)
        {
            DateTime da = DateTime.Now.AddDays(-i);
            CreateDatatableStrings str  = new CreateDatatableStrings();
            List <Taxi>            taxi = new List <Taxi>();
            //List<Owner> owner = new List<Owner>();
            //List<Driver> driver = new List<Driver>();
            List <Person>        person        = new List <Person>();
            List <PersonType>    personType    = new List <PersonType>();
            List <Expense>       expense       = new List <Expense>();
            List <Income>        income        = new List <Income>();
            List <TypeExpense>   typeExpense   = new List <TypeExpense>();
            List <TypeIncome>    typeIncome    = new List <TypeIncome>();
            List <TaxiPayment>   taxiPayment   = new List <TaxiPayment>();
            List <PrimaryDriver> primaryDriver = new List <PrimaryDriver>();
            List <Kilometer>     kilometer     = new List <Kilometer>();
            List <Shift>         shift         = new List <Shift>();
            List <Depth>         depth         = new List <Depth>();


            taxiPayment.Add(new TaxiPayment {
                TaxiID = 1, PersonID = 2, RentPrice = 100, PaymentsPerMonth = 1
            });
            primaryDriver.Add(new PrimaryDriver {
                TaxiID = i - 1, PersonID = i - 1
            });
            kilometer.Add(new Kilometer {
                TaxiID = 1, PersonID = 1, ShiftDate = da, KlmStart = 200000, KlmFinish = 200000, KlmShift = 200000
            });
            shift.Add(new Shift {
                TaxiID = 1, PersonID = 1, ShiftDate = da, XZ = 10.25m, Oil = 10.25m, XZFPA = 10.25m, OilFPA = 10.25m, ShiftPayment = 10.25m, Insurance = 10.25m, FPA = 10.25m, Comment = "comment"
            });
            depth.Add(new Depth {
                TaxiID = 1, PersonID = 1, DepthDate = da, Paid = null, Amount = 15.25m, RepaidAmount = 5.25m, Comment = "comment"
            });

            typeIncome.Add(new TypeIncome {
                Name = "MR test"
            });
            typeExpense.Add(new TypeExpense {
                Name = "MR test"
            });
            income.Add(new Income {
                PersonID = 1, Amount = 2105873695.25m, Comment = "Dis is a comment  ", Date = da, TypeIncomeID = 1
            });
            expense.Add(new Expense {
                PersonID = 1, Amount = 2105873695.25m, Comment = "Dis is a comment  ", Date = da, TypeExpenseID = 1
            });
            //driver.Add(new Driver { IdCard = "AA 15"+i, Name = "MR test"+i, Surname = "Smith", PhoneNumber1 = 2105873695, PhoneNumber2 = 251855512, Email = "*****@*****.**", AFM = 123456789, BirthDate = da });
            //owner.Add(new Owner { IdCard = "AA 15"+i, Name = "MR test" + i, Surname = "Smith", PhoneNumber1 = 2105873695, PhoneNumber2 = 251855512, Email = "*****@*****.**", AFM = 123456789, BirthDate = da });
            person.Add(new Person {
                IdCard = "AA 15" + i, Reserve = 0.0m, Name = "Αλέξανδρος" + i, Surname = "Ανδρικόπουλος driver", PhoneNumber1 = 2105873695, PhoneNumber2 = 251855512, Email = "*****@*****.**", AFM = 123456789, BirthDate = da, PersonTypeID = 1
            });
            person.Add(new Person {
                IdCard = "AA 15" + i, Reserve = 0.0m, Name = "Αλέξανδρος" + i, Surname = "Ανδρικόπουλος", PhoneNumber1 = 2105873695, PhoneNumber2 = 251855512, Email = "*****@*****.**", AFM = 123456789, BirthDate = da, PersonTypeID = 2
            });

            //personType.Add(new PersonType { Name = "Driver"});
            taxi.Add(new Taxi {
                LicensePlate = "taa" + i, Make = "BMW", Model = "i14", MakeDate = 2004, InsuranceCompany = "URair", InsurancePrice = 300.14m, reg_date = da, PersonID = 1
            });

            personType = await sqlexec.SQLGetPersonType(Properties.Settings.Default.DBName, 0, "none", true);

            if (personType.Count != 2)
            {
                personType.Clear();
                personType.Add(new PersonType {
                    Name = "Driver"
                });
                personType.Add(new PersonType {
                    Name = "Owner"
                });
                await sqlexec.SqlInsertPersonType(Properties.Settings.Default.DBName, personType);
            }
            personType.Clear();

            List <Task> tasks = new List <Task>();

            tasks.Add(Task.Run(() => sqlexec.SqlInsertTypeIncome(Properties.Settings.Default.DBName, typeIncome)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertTypeExpense(Properties.Settings.Default.DBName, typeExpense)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertIncome(Properties.Settings.Default.DBName, income)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertExpense(Properties.Settings.Default.DBName, expense)));
            //tasks.Add(Task.Run(() => sqlexec.SqlInsertDriver(Properties.Settings.Default.DBName, driver)));
            //tasks.Add(Task.Run(() => sqlexec.SqlInsertOwner(Properties.Settings.Default.DBName, owner)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertPerson(Properties.Settings.Default.DBName, person)));
            //tasks.Add(Task.Run(() => sqlexec.SqlInsertPersonType(Properties.Settings.Default.DBName, personType)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertTaxi(Properties.Settings.Default.DBName, taxi)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertTaxiPayment(Properties.Settings.Default.DBName, taxiPayment)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertPrimaryDriver(Properties.Settings.Default.DBName, primaryDriver)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertKilometer(Properties.Settings.Default.DBName, kilometer)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertShift(Properties.Settings.Default.DBName, shift)));
            tasks.Add(Task.Run(() => sqlexec.SqlInsertDepth(Properties.Settings.Default.DBName, depth)));


            await Task.WhenAll(tasks);
        }