예제 #1
0
        private async void Button_Click_Save(object sender, RoutedEventArgs e)
        {
            //depthsUpdate
            string query = "";

            if (depthsUpdate.Count == 0)
            {
                return;
            }
            foreach (Depth d in depthsUpdate)
            {
                //query += $"UPDATE Depth SET Paid = '{d.Paid}' WHERE DepthID = '{d.DepthID}'; ";
                query += $"UPDATE Depth SET RepaidAmount = '{d.RepaidAmount}' WHERE DepthID = '{d.DepthID}';";
                if (d.Amount == d.RepaidAmount)
                {
                    query += $"UPDATE Depth SET Paid = '' WHERE DepthID = '{d.DepthID}'; ";
                    //Create Income's
                    if (true)
                    {
                    }
                }
                else
                {
                    query += $"UPDATE Depth SET Paid = NULL WHERE DepthID = '{d.DepthID}'; ";
                }
            }

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

            string   none    = "none";
            DateTime todayyo = DateTime.Today;

            //Create Income's
            depthsAll = await sqlexec.SQLGetDepth(Properties.Settings.Default.DBName, 0, 0, none, todayyo, null, none, 0, none, 0, none, false);

            depthsAllPaid = await sqlexec.SQLGetDepth(Properties.Settings.Default.DBName, 0, 0, none, todayyo, "", none, 0, none, 0, none, false);
            await refreshAll();
        }
        private async void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            //Create Shift Object
            Shift newshift = new Shift();

            try
            {
                newshift.PersonID = Int32.Parse(cmbDriver.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("You Must select a Driver");
                return;
            }
            try
            {
                newshift.TaxiID = Int32.Parse(cmbTaxi.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("You Must select a Taxi");
                return;
            }

            if (!DatePicker1.Value.HasValue)
            {
                newshift.ShiftDate = DateTime.Today;
            }
            else
            {
                newshift.ShiftDate = DatePicker1.Value.Value;
            }
            if (TxtXZ.Text != "")
            {
                newshift.XZ = Convert.ToDecimal(TxtXZ.Text);
            }
            if (TxtOil.Text != "")
            {
                newshift.Oil = Convert.ToDecimal(TxtOil.Text);
            }
            if (TxtXZFpa.Text != "")
            {
                newshift.XZFPA = Convert.ToDecimal(TxtXZFpa.Text);
            }
            if (TxtOilFpa.Text != "")
            {
                newshift.OilFPA = Convert.ToDecimal(TxtOilFpa.Text);
            }
            if (TxtShift.Text != "")
            {
                newshift.ShiftPayment = Convert.ToDecimal(TxtShift.Text);
            }
            if (TxtIka.Text != "")
            {
                newshift.Insurance = Convert.ToDecimal(TxtIka.Text);
            }
            if (TxtFpa.Text != "")
            {
                newshift.FPA = Convert.ToDecimal(TxtFpa.Text);
            }
            if (TxtComment.Text != "")
            {
                newshift.Comment = TxtComment.Text;
            }

            shifts.Add(newshift);
            //Create kilometer object
            Kilometer newkilometer = new Kilometer();

            if (TxtKmlFrom.Text != "")
            {
                newkilometer.KlmStart = Int32.Parse(TxtKmlFrom.Text);
            }
            if (TxtKmlTo.Text != "")
            {
                newkilometer.KlmFinish = Int32.Parse(TxtKmlTo.Text);
            }
            if (TxtKmlDifference.Text != "")
            {
                newkilometer.KlmShift = Int32.Parse(TxtKmlDifference.Text);
            }

            if (!DatePicker1.Value.HasValue)
            {
                newkilometer.ShiftDate = DateTime.Today;
            }
            else
            {
                newkilometer.ShiftDate = DatePicker1.Value.Value;
            }
            try
            {
                newkilometer.PersonID = Int32.Parse(cmbDriver.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("You Must select a Driver");
                return;
            }
            try
            {
                newkilometer.TaxiID = Int32.Parse(cmbTaxi.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("You Must select a Taxi");
                return;
            }
            kilometers.Add(newkilometer);
            //Create Depth object
            Depth newdepth = new Depth();

            try
            {
                newdepth.Amount = Convert.ToDecimal(TxtAmount.Text);
            }
            catch
            {
                MessageBox.Show("The Total must be a decimal xxxx.xx ");
                return;
            }
            if (TxtComment.Text != "")
            {
                newdepth.Comment = TxtComment.Text;
            }
            newdepth.RepaidAmount = 0;
            newdepth.Paid         = null;
            if (!DatePicker1.Value.HasValue)
            {
                newdepth.DepthDate = DateTime.Today;
            }
            else
            {
                newdepth.DepthDate = DatePicker1.Value.Value;
            }
            try
            {
                newdepth.PersonID = Int32.Parse(cmbDriver.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("You Must select a Driver");
                return;
            }
            try
            {
                newdepth.TaxiID = Int32.Parse(cmbTaxi.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("You Must select a Taxi");
                return;
            }
            List <PrimaryDriver> primedr = new List <PrimaryDriver>();

            primedr.Add(new PrimaryDriver {
                TaxiID = Int32.Parse(cmbTaxi.SelectedValue.ToString()), PersonID = Int32.Parse(cmbDriver.SelectedValue.ToString())
            });
            depths.Add(newdepth);



            CreateDatatableStrings strings = new CreateDatatableStrings();
            SQLExecute             sqlexec = new SQLExecute();
            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, strings.FOREIGN_KEY(0));

            await Task.Run(() => SaveKilometer());

            await Task.Run(() => SaveShift());

            await Task.Run(() => SaveDepth());

            await Task.Run(() => SaveIfPrimaryDriver(primedr));

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, strings.FOREIGN_KEY(1));

            ClearAll();
        }
        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();
        }
예제 #4
0
        public async Task CreateDatabaseAsync()
        {
            CreateDatatableStrings str = new CreateDatatableStrings();

            sqlexec.SQLCommandKey(Properties.Settings.Default.DBName, str.FOREIGN_KEY(0));
            //await SQLCommand(Properties.Settings.Default.DBName, str.FOREIGN_KEY(0));
            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.PersonType());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Person());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Taxi());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Expense());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Income());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.TypeExpense());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.TypeIncome());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.TaxiPayment());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.PrimaryDriver());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Kilometer());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Shift());

            await sqlexec.SQLCommand(Properties.Settings.Default.DBName, str.Depth());

            //await SQLCommand(Properties.Settings.Default.DBName, str.FOREIGN_KEY(1));
            sqlexec.SQLCommandKey(Properties.Settings.Default.DBName, str.FOREIGN_KEY(1));
        }