private void buttonWrite_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "Уверен?", "Записать?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) != System.Windows.Forms.DialogResult.Yes) return; try { var connection = new iButtonConnection(Settings.Default.Port); connection.Erase(); for (int i = 0; i < dataGridViewKey.RowCount; i++) connection.Write(((iButtonKey)dataGridViewKey.Rows[i].Tag)); MessageBox.Show(this, "Готово!", "Запись ключей", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void перезагрузитьУстройствоToolStripMenuItem_Click(object sender, EventArgs e) { var connection = new iButtonConnection(Settings.Default.Port); try { connection.Reboot(); MessageBox.Show(this, "Готово", "Перезагрузка", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonRead_Click(object sender, EventArgs e) { try { var connection = new iButtonConnection(Settings.Default.Port); var keys = connection.ReadKeys(); dataGridViewKey.Rows.Clear(); dataGridViewKey.RowCount = keys.Length; for (int i = 0; i < keys.Length; i++) { dataGridViewKey.Rows[i].Tag = keys[i]; dataGridViewKey.Rows[i].Cells["colTypeK"].Value = KeyType(keys[i].Type); dataGridViewKey.Rows[i].Cells["colKeyK"].Value = keys[i].Key; dataGridViewKey.Rows[i].Cells["colCRCK"].Value = (keys[i].Type != 0xFF ? string.Format("{0:X2}", keys[i].CRC) : "--"); bool found = false; foreach (DataGridViewRow keyInDB in dataGridViewDatabase.Rows) { if (((iButtonKey)keyInDB.Tag).ToString() == keys[i].ToString()) { found = true; dataGridViewKey.Rows[i].Cells["colDescriptionK"].Value = keyInDB.Cells["colDescription"].Value; } } if (!found) { var newRow = dataGridViewDatabase.Rows.Add(); dataGridViewDatabase.Rows[newRow].Tag = keys[i]; dataGridViewDatabase.Rows[newRow].Cells["colType"].Value = KeyType(keys[i].Type); dataGridViewDatabase.Rows[newRow].Cells["colKey"].Value = keys[i].Key; dataGridViewDatabase.Rows[newRow].Cells["colCRC"].Value = (keys[i].Type != 0xFF ? string.Format("{0:X2}", keys[i].CRC) : "--"); dataGridViewKey.Rows[i].Cells["colDescriptionK"].Value = dataGridViewDatabase.Rows[newRow].Cells["colDescription"].Value = "Добавлен " + DateTime.Now.ToString(); } } for (int i = 0; i < dataGridViewDatabase.RowCount; i++) dataGridViewDatabase.Rows[i].Cells["colNum"].Value = i + 1; for (int i = 0; i < dataGridViewKey.RowCount; i++) dataGridViewKey.Rows[i].Cells["colNumK"].Value = i + 1; SaveDatabase(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }