private void btn_time_Click(object sender, EventArgs e) { if (!checkDevice()) { return; } DateTime dt = DateTime.Now; string t = "SETTIME "; if (dt.Day < 10) { t += "0"; } t += dt.Day; if (dt.Month < 10) { t += "0"; } t += dt.Month; t += dt.Year; if (dt.Hour < 10) { t += "0"; } t += dt.Hour; if (dt.Minute < 10) { t += "0"; } t += dt.Minute; if (dt.Second < 10) { t += "0"; } t += dt.Second; t += "\n"; if (!dc.send(t)) { MetroFramework.MetroMessageBox.Show(this, "Error\nDevice may not be connected", "STOP", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string w = dc.wait(); if (w != "OK") { MetroFramework.MetroMessageBox.Show(this, "Error\n" + w, "STOP !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { t = dc.get(); //MessageBox.Show(t); string[] arr = t.Split('_'); int dif = 1000; try { dif = Convert.ToInt32(Math.Floor(Math.Abs(new DateTime(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), Convert.ToInt32(arr[2]), Convert.ToInt32(arr[3]), Convert.ToInt32(arr[4]), Convert.ToInt32(arr[5])).Subtract(dt).TotalSeconds))); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, "Time Set Error", "ERROR !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); MetroFramework.MetroMessageBox.Show(this, ex.Message, "ERROR !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dif <= 5) { MetroFramework.MetroMessageBox.Show(this, "Time set and checked successfully on the device", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MetroFramework.MetroMessageBox.Show(this, "Error !!!\nDevice took too long to respond", "STOP", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "ERROR !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private bool EnrollProcess() { bool f = dc.send("ENROLL\n"); if (!f) { fid = -100; MetroFramework.MetroMessageBox.Show(this, "Couldn't send command to device\nForm is closing...", "STOP", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return(false); } updateLabel("Waiting..."); while (true) { string ws = dc.wait(); if (ws.Equals("Time Limit")) { fid = -100; MetroFramework.MetroMessageBox.Show(this, "Sorry !!!\nThe device is not responding", "STOP", MessageBoxButtons.OK, MessageBoxIcon.Error); //Close(); return(false); } else if (ws != "OK") { fid = -100; MetroFramework.MetroMessageBox.Show(this, "Exception occured!!!\n" + ws + "\nForm is closing...", "STOP", MessageBoxButtons.OK, MessageBoxIcon.Error); //Close(); return(false); } string line = dc.get(); string[] arr = line.Split(' '); if (arr.Length <= 1) { fid = -100; MetroFramework.MetroMessageBox.Show(this, "Unknown Behaviour !!!", "STOP", MessageBoxButtons.OK, MessageBoxIcon.Error); //Close(); return(false); } if (arr[0].Equals("Success")) { updateLabel("Success: " + arr[1]); fid = Convert.ToInt32(arr[1]); updateLabel(fid.ToString()); Refresh(); return(true); } else if (arr[0].Equals("ERROR")) { updateLabel(arr[1] + " Error\nRetry"); Refresh(); MetroFramework.MetroMessageBox.Show(this, arr[1] + " Error", "ERROR !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (arr[0].Equals("Failed")) { updateLabel("Fingerprint didn't match\nRetry"); Refresh(); MetroFramework.MetroMessageBox.Show(this, "Fingerprint didn't match", "ERROR !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { updateLabel(line); if (!arr[0].Equals("Waiting") && !arr[0].Equals("Free") && !arr[0].Equals("Remove") && !arr[0].Equals("Place")) { ProgressBar.Value += 10; } } Refresh(); } }