コード例 #1
0
        public void DeleteButton_OnMouseClick(object sender, MouseEventArgs e)
        {
            if (MessageBox.Show("Do you really want to delete this entry?", "Remove Entry", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                Panel           panel           = (Panel)((Button)sender).Parent;
                GUIEntryCreator guiEntryCreator = userPasswordDictionary.Keys.First(x => x.entryPanel == panel);

                Credential credential;
                userPasswordDictionary.TryGetValue(guiEntryCreator, out credential);
                int entryId = int.Parse(credential.GetData(Credential.UserDataType.Id));

                entryFlowLayoutPanel.Controls.Remove(guiEntryCreator.entryPanel);
                userPasswordDictionary.Remove(guiEntryCreator);

                byte[] command =
                {
                    (byte)SerialCommandLimiter.COMM_BEGIN,
                    (byte)SerialCommand.COMM_REM_ACC,
                    (byte)((entryId & 0xFF00) >> 8),
                    (byte)(entryId & 0xFF),
                    (byte)SerialCommandLimiter.COMM_END
                };
                SerialSafeWrite(command, 5);

                if (userPasswordDictionary.Count == 0)
                {
                    lblPlaceholder.Visible = true;
                }
            }
        }
コード例 #2
0
        public void EditButton_OnMouseClick(object sender, MouseEventArgs e)
        {
            Panel           panel           = (Panel)((Button)sender).Parent;
            GUIEntryCreator guiEntryCreator = userPasswordDictionary.Keys.First(x => x.entryPanel == panel);

            EditEntryDialog editEntryDialog = new EditEntryDialog();

            editEntryDialog.UserCredential = userPasswordDictionary[guiEntryCreator];

            if (editEntryDialog.ShowDialog() == DialogResult.OK)
            {
                Credential credential = new Credential(editEntryDialog.UserCredential);
                userPasswordDictionary.Remove(guiEntryCreator);

                entryFlowLayoutPanel.Controls.Remove(guiEntryCreator.entryPanel);

                userPasswordDictionary.Add(new GUIEntryCreator(
                                               entryFlowLayoutPanel,
                                               credential,
                                               new MouseEventHandler(DeleteButton_OnMouseClick),
                                               new MouseEventHandler(EditButton_OnMouseClick)), credential);

                int    entryId = int.Parse(credential.GetData(Credential.UserDataType.Id));
                byte[] command = new byte[180];
                command[0] = (byte)SerialCommandLimiter.COMM_BEGIN;
                command[1] = (byte)SerialCommand.COMM_EDIT_ACC;
                command[2] = (byte)((entryId & 0xFF00) >> 8);
                command[3] = (byte)(entryId & 0xFF);
                command[4] = (byte)SerialCommandLimiter.US;

                int commandIdx = 5;
                CopyArray(credential.GetData(Credential.UserDataType.Title), ref command, ref commandIdx, 16);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Username), ref command, ref commandIdx, 32);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Email), ref command, ref commandIdx, 64);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Password), ref command, ref commandIdx, 32);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Website), ref command, ref commandIdx, 24);
                command[commandIdx++] = (byte)SerialCommandLimiter.COMM_END;

                SerialSafeWrite(command, commandIdx);
            }
        }