public static int insertDebtLoan(DebtLoan debtLoan)
        {
            int    status      = 0;
            double amount      = debtLoan.Amount;
            String payer       = debtLoan.Person;
            String description = debtLoan.Description;
            String id          = debtLoan.Id;

            String[] dateArray = debtLoan.Date.ToString().Split(' ');
            String   date      = dateArray[0];

            bool isDebt = debtLoan.Debt;
            int  cond   = 0;

            if (isDebt)
            {
                cond = 1;
            }
            String accID = debtLoan.AccID;

            try
            {
                using (var connection = new SQLitePCL.SQLiteConnection("Storage.db"))
                {
                    using (var statement = connection.Prepare(@"INSERT INTO DebtLoan (Amount, Person, 
                                                                Description, ID, Date, Debt, Acc_ID)
                                    VALUES(?,?,?,?,?,?,?);"))
                    {
                        statement.Bind(1, amount.ToString());
                        statement.Bind(2, payer);
                        statement.Bind(3, description);
                        statement.Bind(4, id);
                        statement.Bind(5, date.ToString());
                        statement.Bind(6, cond);
                        statement.Bind(7, accID);


                        SQLiteResult s = statement.Step();
                        statement.Reset();
                        statement.ClearBindings();
                        if ((s.ToString().Equals("DONE")))
                        {
                            Debug.WriteLine("Step done");
                            status = 1;
                        }
                        else
                        {
                            Debug.WriteLine("Step failed");
                            status = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(status);
        }
Example #2
0
        private async void dAdd_btn_Click(object sender, RoutedEventArgs e)
        {
            double amount = 0.0;

            if (!(dAmount_box.Text.Equals("")))
            {
                amount = Convert.ToDouble(dAmount_box.Text);
            }
            String payer = "default_null";

            if (!(dPerson_box.Text.Equals("")))
            {
                payer = dPerson_box.Text;
            }

            bool debt_radio = (bool)dDebt_radio.IsChecked;
            bool loan_radio = (bool)dLoan_radio.IsChecked;


            String desc = "default_null";

            if (!(dDesc_box.Text.Equals("")))
            {
                desc = dDesc_box.Text;
            }
            String date = dDate_box.Date.ToString();

            if (amount == 0.0)
            {
                MessageDialog msg = new MessageDialog("Amount cannot be 0!");
                await msg.ShowAsync();
            }
            else if (amount < 0)
            {
                MessageDialog msg = new MessageDialog("Amount cannot be less than 0!");
                await msg.ShowAsync();
            }
            else if (!(debt_radio || loan_radio))
            {
                MessageDialog msg = new MessageDialog("Please select the type!");
                await msg.ShowAsync();
            }
            else if (payer.Equals("default_null"))
            {
                MessageDialog msg = new MessageDialog("Please enter a person!");
                await msg.ShowAsync();
            }
            else
            {
                bool debtLoanCond = false;
                if (debt_radio)
                {
                    debtLoanCond = true;
                }
                DebtLoan           debtLoan   = new DebtLoan(amount, payer, desc, "DLID123", date, debtLoanCond, "AC_ID123");
                DebtLoanController controller = new DebtLoanController();
                controller.addDebtLoan(debtLoan);
            }
        }
 public void addDebtLoan(DebtLoan debtLoan)
 {
     DatabaseHandler.insertDebtLoan(debtLoan);
 }