0byt3m1n1
Path:
C:
/
BACKUPS
/
Biometric Backup
/
KELTRON
/
COSEC V14R4.1
/
Setup
/
API Samples
/
CSharp
/
[
Home
]
File: AssignRevokeDeviceTab.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace CSharp { public partial class AssignRevokeDeviceTab : UserControl { public AssignRevokeDeviceTab() { InitializeComponent(); } private void btnARFind_Click(object sender, EventArgs e) { try { MainForm.Instance.ShowMessage("Requesting...", true); string Error = ""; Cosec.apiHelper.UserAPIParameters objUserAPIParams = Cosec.apiHelper.GetUser(nudARID.Text, out Error); if (objUserAPIParams == null) { pnlAssignRevoke.Enabled = false; MainForm.Instance.ShowMessage(Error, false); } else { pnlAssignRevoke.Enabled = true; txtARReferenceCode.Text = objUserAPIParams.reference_code; txtARName.Text = objUserAPIParams.name; MainForm.Instance.ShowMessage("Request Completed", true); } rdAssign_CheckedChanged(null, null); } catch (Exception ex) { MainForm.Instance.ClearMessage(); MessageBox.Show(ex.Message); } } private void FillDeviceList() { Cosec.apiHelper.APIResponse apiResponse = Cosec.apiHelper.GetDevice(Cosec.apiHelper.DeviceListOption.All, Cosec.apiHelper.DataFormat.XML); if (apiResponse != null) { if (string.IsNullOrEmpty(apiResponse.data) == false) { DataSet ds = new DataSet(); ds.ReadXml(apiResponse.dataStream); gridAssignRevokeDevice.DataSource = ds.Tables[0]; } if (apiResponse.isSuccess) { // Success if (string.IsNullOrEmpty(apiResponse.successFailMessage)) MainForm.Instance.ShowMessage("Request completed", true); else MainForm.Instance.ShowMessage(apiResponse.successFailMessage, true); } else { // Failed MainForm.Instance.ShowMessage(apiResponse.successFailMessage, false); } } } internal void Load() { gridAssignRevokeDevice.DataSource = null; txtARReferenceCode.Text = ""; txtARName.Text = ""; nudARID.Text = ""; pnlAssignRevoke.Enabled = false; FillDeviceList(); } private void btnSaveAssignRevoke_Click(object sender, EventArgs e) { if (rdAssign.Checked) { string assigndeviceString = ""; foreach (DataGridViewRow grdrow in gridAssignRevokeDevice.Rows) { if (grdrow.Cells[0].Value != null && grdrow.Cells[0].Value != System.DBNull.Value) { DataRowView dr = grdrow.DataBoundItem as DataRowView; if ((bool)grdrow.Cells[0].Value == true) { assigndeviceString += dr["id"].ToString() + ","; } } } if (!string.IsNullOrEmpty(assigndeviceString) && assigndeviceString.EndsWith(",")) assigndeviceString = assigndeviceString.Substring(0, assigndeviceString.Length - 1); string userstring = ""; userstring = nudARID.Text; Cosec.apiHelper.APIResponse apiResponse = null; if (string.IsNullOrEmpty(assigndeviceString) == false) { apiResponse = Cosec.apiHelper.AssignDevice(assigndeviceString, userstring); if (apiResponse != null) MainForm.Instance.ShowMessage(apiResponse.successFailMessage, apiResponse.isSuccess); } } else { string revokedeviceString = ""; foreach (DataGridViewRow grdrow in gridAssignRevokeDevice.Rows) { if (grdrow.Cells[0].Value != null && grdrow.Cells[0].Value != System.DBNull.Value) { DataRowView dr = grdrow.DataBoundItem as DataRowView; if ((bool)grdrow.Cells[0].Value == true) { revokedeviceString += dr["id"].ToString() + ","; } } } if (!string.IsNullOrEmpty(revokedeviceString) && revokedeviceString.EndsWith(",")) revokedeviceString = revokedeviceString.Substring(0, revokedeviceString.Length - 1); string userstring = ""; userstring = nudARID.Text; Cosec.apiHelper.APIResponse apiResponse = null; if (string.IsNullOrEmpty(revokedeviceString) == false) { apiResponse = Cosec.apiHelper.RevokeDevice(revokedeviceString, userstring); if (apiResponse != null) MainForm.Instance.ShowMessage(apiResponse.successFailMessage, apiResponse.isSuccess); } } } private void rdAssign_CheckedChanged(object sender, EventArgs e) { foreach (DataGridViewRow grdrow in gridAssignRevokeDevice.Rows) { grdrow.Cells[0].Value = false; } } private void rdRevoke_CheckedChanged(object sender, EventArgs e) { foreach (DataGridViewRow grdrow in gridAssignRevokeDevice.Rows) { grdrow.Cells[0].Value = false; } } } }