Ejemplo n.º 1
0
        private void InitializeMainForm()
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version;

            this.Text        = $"PassBerry {version.Major}.{version.Minor} - Press Shift + F2 to paste username and password";
            this.MinimumSize = new Size(700, 500);

            var dataGrid = this.dataGridViewMain;

            dataGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGrid.BackgroundColor                      = Color.White;
            dataGrid.BorderStyle                          = BorderStyle.None;
            dataGrid.AutoSizeColumnsMode                  = DataGridViewAutoSizeColumnsMode.None;
            dataGrid.AutoSizeRowsMode                     = DataGridViewAutoSizeRowsMode.None;
            dataGrid.AllowDrop                            = false;
            dataGrid.AllowUserToResizeColumns             = false;
            dataGrid.AllowUserToResizeRows                = false;
            dataGrid.SelectionMode                        = DataGridViewSelectionMode.FullRowSelect;
            dataGrid.MultiSelect                          = false;
            dataGrid.RowHeadersVisible                    = false;
            dataGrid.ColumnHeadersBorderStyle             = DataGridViewHeaderBorderStyle.None;
            dataGrid.RowHeadersBorderStyle                = DataGridViewHeaderBorderStyle.None;
            dataGrid.CellBorderStyle                      = DataGridViewCellBorderStyle.None;
            dataGrid.DefaultCellStyle.SelectionBackColor  = Color.Black;
            dataGrid.DefaultCellStyle.SelectionForeColor  = Color.White;
            dataGrid.RowTemplate.Height                   = 50;
            dataGrid.RowTemplate.DefaultCellStyle.Padding = new Padding(10);

            allDataCache = ResourceProcessor.GetInstance().GetAll();
            this.LoadData(allDataCache);
        }
Ejemplo n.º 2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            var result = new Edit(null).ShowDialog();

            if (result == DialogResult.OK)
            {
                allDataCache = ResourceProcessor.GetInstance().GetAll();
                this.LoadData(allDataCache);
            }
        }
Ejemplo n.º 3
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewMain.SelectedRows.Count < 1)
            {
                return;
            }
            var currentSelectedItem = (Guid)this.dataGridViewMain.SelectedRows[0].Cells["Id"].Value;
            var confirmResult       = MessageBox.Show("Are you sure to delete the current item?", "Delete Item", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

            if (confirmResult == DialogResult.Yes)
            {
                ResourceProcessor.GetInstance().Delete(currentSelectedItem);
                allDataCache = ResourceProcessor.GetInstance().GetAll();
                this.LoadData(allDataCache);
            }
        }
Ejemplo n.º 4
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewMain.SelectedRows.Count < 1)
            {
                return;
            }
            var currentSelectedItem = (Guid)this.dataGridViewMain.SelectedRows[0].Cells["Id"].Value;
            var record = allDataCache.Find(i => i.Id == currentSelectedItem);
            var result = new Edit(record).ShowDialog();

            if (result == DialogResult.OK)
            {
                allDataCache = ResourceProcessor.GetInstance().GetAll();
                this.LoadData(allDataCache);
            }
        }
Ejemplo n.º 5
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.textBoxName.Text))
            {
                MessageBox.Show("Please select a valid name for current item.", "Save Item", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Image logo         = null;
            var   logoFilePath = this.textBoxLogoFilePath.Text;

            if (!string.IsNullOrWhiteSpace(logoFilePath))
            {
                try
                {
                    logo = Image.FromFile(logoFilePath);
                    logo = ImageHelper.ZoomPicture(logo, 100, 50);
                }
                catch
                {
                    MessageBox.Show("Please select a valid image for Logo.", "Save Item", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (this.record == null)
            {
                this.record = new RecordForDisplay {
                    Id = Guid.NewGuid()
                };
            }

            this.record.Name = this.textBoxName.Text;
            var image = this.textBoxLogoFilePath.Text;

            this.record.PictureForLogo = logo;
            this.record.Username       = this.textBoxUsername.Text;
            this.record.Password       = SecureStringHelper.GetSecureStringFromString(this.textBoxPassword.Text);
            this.record.Keywords       = this.textBoxKeywords.Text;
            this.record.Remarks        = this.textBoxRemarks.Text;

            ResourceProcessor.GetInstance().Save(this.record);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }