private void clearPasswords()
        {
            DataTable dt = (DataTable)dataGridView1.DataSource;

            if (dt != null)
            {
                dt.Clear();
            }
            dataGridView1.DataSource = dt;
            Passwords.Clear();
        }
        private async Task LoadAsync()
        {
            Passwords.Clear();
            try
            {
                var json = await SecureStorage.GetAsync("passwords");

                var passwords = StorageService.Get(json);
                foreach (var password in passwords)
                {
                    Passwords.Add(password);
                }
            }
            catch
            {
                await DisplayAlert(
                    "Ops!",
                    "This device does not support secure storage",
                    "OK");
            }
        }
        private void generatePasswords(string doc, string duration, string country, int n)
        {
            stopWatch.Start();
            //List<string> passwords = new List<string> { };
            progressBar1.Value   = 0;
            progressBar1.Maximum = n;
            string psw;

            DataTable dt;

            if (dataGridView1.DataSource == null)
            {
                dt = new DataTable();
                dt.Columns.Add("#");
                dt.Columns.Add("Document");
                dt.Columns.Add("Password");
                dt.Columns.Add("Duration");
            }
            else
            {
                dt = (DataTable)dataGridView1.DataSource;
            }

            dataGridView1.UseWaitCursor = true;

            if (!ActualRow.ContainsKey(doc))
            {
                ActualRow.Add(doc, 0);
            }

            int db_row     = db.Count(doc);
            int actual_row = (ActualRow[doc] > db_row) ? ActualRow[doc] : db_row;

            int i;

            for (i = actual_row + 1; i <= actual_row + n; i++)
            {
                psw = sc.Generate(doc, duration, i);
                Passwords.Add(new Code(psw, country, doc, duration));
                // Update gridview
                DataRow dr = dt.NewRow();
                dr[0] = i.ToString();
                dr[1] = doc;
                dr[2] = psw;
                dr[3] = duration.ToString();
                dt.Rows.Add(dr);
                // update progress bar+
                progressBar1.Value = i - actual_row - 1;
            }
            ActualRow[doc]              = i - 1;
            dataGridView1.DataSource    = dt;
            dataGridView1.UseWaitCursor = false;

            stopWatch.Stop();

            TimeSpan ts = stopWatch.Elapsed;

            txtTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                          ts.Hours, ts.Minutes, ts.Seconds,
                                          ts.Milliseconds / 10);

            // NOW WE INSERT INTO THE DB
            DialogResult dialogResult = MessageBox.Show("Insert into the database?", "DB Conneciton", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                String creation_code = db.InsertCode(Passwords);
                if (!String.IsNullOrEmpty(creation_code))
                {
                    if (db.InsertJob(doc, country, n, creation_code))
                    {
                        MessageBox.Show("Serial codes inserted correctly");
                        // Clear the passwords
                        Passwords.Clear();
                        string title = bookComboBox.Text;
                        // And update the total number of codes generated for the book
                        countTextBox.Text      = db.Count(title).ToString() + " codes generated";
                        totalCountTextBox.Text = db.Count().ToString() + " codes generated";
                    }
                    else
                    {
                        MessageBox.Show("Error during the insertion of the serial codes");
                    }
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                //do something else
            }

            return;
        }