Пример #1
0
        private void textToGridView(String inText, ref GridTabClass inGridView)
        {
            if (inText.Trim() == "")
            {
                return;
            }
            inGridView.EnableCellEnter(false);
            try
            {
                String[] lines = inText.Split('\n');
                String[] cells;
                inGridView.TabGrid.Rows.Clear();
                lines = lines.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                inGridView.TabGrid.Rows.Add(lines.Length);

                for (int x = 0; x <= lines.Length - 1; x++)
                {
                    cells = lines[x].Split('\a');
                    for (int y = 0; y <= cells.Length - 1; y++)
                    {
                        inGridView.TabGrid.Rows[x].Cells[y].Value = cells[y];
                    }
                }
            }
            finally
            {
                inGridView.EnableCellEnter(true);
            }
        }
Пример #2
0
        private GridTabClass AddNewTab(string inTabName)
        {
            inTabName = inTabName.Trim();
            if (inTabName == "")
            {
                return(null);
            }
            GridTabClass newTab = new GridTabClass(this, tabControl1, inTabName);

            gridTabs.Add(newTab);
            listBox1.Items.Add(inTabName);
            listBox1.SetSelected(listBox1.Items.Count - 1, true);
            assignAllClicks(newTab.Controls);
            return(newTab);
        }
Пример #3
0
        private String gridViewToText(GridTabClass inGridView)
        {
            String result = "";

            for (int x = 0; x <= inGridView.TabGrid.Rows.Count - 1; x++)
            {
                if (!inGridView.TabGrid.Rows[x].IsNewRow)
                {
                    for (int y = 0; y <= inGridView.TabGrid.Rows[x].Cells.Count - 1; y++)
                    {
                        result += (y > 0 ? "\a" : "") + inGridView.TabGrid.Rows[x].Cells[y].Value;
                    }
                    result += '\n';
                }
            }
            return(result);
        }
Пример #4
0
        private void DeleteTab(string inTabName)
        {
            GridTabClass tabToDelete = null;

            foreach (GridTabClass gtb in gridTabs)
            {
                if (gtb.gridTabName == inTabName)
                {
                    tabToDelete = gtb;
                    break;
                }
            }
            if (tabToDelete != null)
            {
                gridTabs.Remove(tabToDelete);
                tabControl1.TabPages.Remove(tabToDelete);
            }
        }
Пример #5
0
 private bool loadFromFile(bool askForPIN = true)
 {
     String[] textLines;
     try
     {
         textLines = File.ReadAllLines(currentDATFile, Encoding.Default);
         if (textLines.Length != 0)
         {
             if (textLines[0] != "PKeeperV2")
             {
                 throw new System.ArgumentException("The file \"" + currentDATFile + "\" is invalid!");
             }
             validFile = TValidFile.validFileSelected;
             if (askForPIN)
             {
                 PinForm      pinForm = new PinForm(this, true);
                 DialogResult dr;
                 dr = pinForm.ShowDialog();
                 if (dr == DialogResult.Cancel)
                 {
                     MessageBox.Show("Password verification canceled by user.\nThe program will exit!", "Aborting", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     Environment.Exit(0);
                 }
                 if ((dr != DialogResult.OK) || (textLines[1] != pinForm.maskedPIN.Text))
                 {
                     validFile = TValidFile.validFileWrongPassword;
                     throw new System.ArgumentException("Wrong password!");
                 }
                 else
                 {
                     PIN = textLines[1];
                 }
             }
             validFile = TValidFile.validFileSelected;
             String[] Sections = textLines[2].Split('\a');
             textLines = textLines.Skip(3).ToArray();
             string[] gridData = String.Join("\n", textLines).Split('\0');
             for (int x = 0; x <= listBox1.Items.Count - 1; x++)
             {
                 DeleteTab(listBox1.Items[x].ToString());
             }
             listBox1.Items.Clear();
             for (int x = 0; x <= Sections.Length - 1; x++)
             {
                 GridTabClass tmpGtb = AddNewTab(Sections[x]);
                 if (x < gridData.Count())
                 {
                     textToGridView(gridData[x], ref tmpGtb);
                 }
             }
             if (listBox1.Items.Count > 0)
             {
                 listBox1.SelectedIndex = 0;
             }
             DoKeys();
         }
         else // Empty file
         {
             throw new System.ArgumentException("The passwords file is empty!");
         }
         validFile = TValidFile.validFileSelected;
         btn_reloadFile.Enabled = true;
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }