private void downloadCard(int device_id, string device_ip, string employees) { List <string> employees_list = JsonConvert.DeserializeObject <List <string> >(employees); DBConnection db_connection = new DBConnection(); AnvizNew.PERSONINFO person = new AnvizNew.PERSONINFO(); DataTable employee_details = new DataTable(); string enroll_id = string.Empty; string employee_name = string.Empty; string employee_id = string.Empty; string password = string.Empty; string card_id = string.Empty; string query = string.Empty; int RecordCount = new int(); int RetCount = new int(); int pPersons = new int(); int pLongRun = new int(); int cardcount = 0; long Cardlong = 0; int i = 0; int status = 0; int ptemp; if (AnvizNew.CKT_ListPersonInfoEx(device_id, ref pLongRun) == 1) { while (true) { status = AnvizNew.CKT_ListPersonProgress(pLongRun, ref RecordCount, ref RetCount, ref pPersons); if (status != 0) { //if (RecordCount > 0) ProgressBar1.Maximum = RetCount; ptemp = Marshal.SizeOf(person); for (i = 0; i < RetCount; i++) { RtlMoveMemory(ref person, pPersons, ptemp); pPersons = pPersons + ptemp; string[] hu = { i.ToString(), person.PersonID.ToString(), Encoding.Default.GetString(person.Name).ToString(), Encoding.Default.GetString(person.Password).ToString(), person.CardNo.ToString() }; enroll_id = person.PersonID.ToString(); if (employees_list.Exists(element => element == enroll_id)) { employee_name = Encoding.Default.GetString(person.Name).ToString(); password = Encoding.Default.GetString(person.Password).ToString(); password = System.Text.RegularExpressions.Regex.Replace(password, "[^0-9_.]+", "", System.Text.RegularExpressions.RegexOptions.Compiled); password = password.TrimEnd('0'); card_id = person.CardNo.ToString(); Cardlong = Convert.ToInt64(card_id); if (Cardlong < -1) { Cardlong = Cardlong + 4294967296; card_id = Convert.ToString(Cardlong); } if (card_id == "-1") { card_id = ""; } if (employee_name.StartsWith("\0")) { employee_name = ""; } cardcount = cardcount + 1; if (db_connection.RecordExist("select count(emp_card_no) from employeemaster where emp_card_no='" + enroll_id + "' ")) { query = "select emp_code,emp_name as Name from Employeemaster where emp_card_no='" + enroll_id + "'"; employee_details.Rows.Clear(); employee_details = db_connection.ReturnDataTable(query); employee_id = employee_details.Rows[0]["emp_code"].ToString(); employee_name = employee_details.Rows[0]["Name"].ToString(); } if (db_connection.RecordExist("select count(*) from Enrollmaster where enrollid='" + enroll_id + "'")) { query = "update Enrollmaster set cardid='" + card_id + "',pin='" + password + "',empid='" + employee_id + "',name='" + employee_name + "' where enrollid='" + enroll_id + "'"; db_connection.ExecuteQuery_WithOutReturnValue(query); } else { if (password == "\0\0\0\0\0\0\0\0") { password = ""; } query = "Insert into Enrollmaster(enrollid,cardid,pin,empid,name) values('" + enroll_id + "','" + card_id + "','" + password + "','" + employee_id + "','" + employee_name + "')"; db_connection.ExecuteQuery_WithOutReturnValue(query); } } } if (status == 1) { break; } } else { // Add logic for logging error to log file. } } } }
private DataTable getEnrollment(int device_id) { AnvizNew.PERSONINFO person = new AnvizNew.PERSONINFO(); DBConnection db_connection = new DBConnection(); DataTable employee_details = new DataTable(); DataTable enrollments = new DataTable(); string query = string.Empty; string employee_name = string.Empty; int i = 0; int RecordCount = new int(); int RetCount = new int(); int pPersons = new int(); int pLongRun = new int(); int ptemp = 0; int status = AnvizNew.CKT_ListPersonInfoEx(device_id, ref pLongRun); enrollments.Columns.Add("status"); enrollments.Columns.Add("EnrollId"); enrollments.Columns.Add("Employeename"); query = "truncate table exportenrollid"; db_connection.ExecuteQuery_WithReturnValueString(query); if (status == 1) { while (true) { status = AnvizNew.CKT_ListPersonProgress(pLongRun, ref RecordCount, ref RetCount, ref pPersons); if (status != 0) { ptemp = Marshal.SizeOf(person); for (i = 0; i < RetCount; i++) { RtlMoveMemory(ref person, pPersons, ptemp); pPersons = pPersons + ptemp; query = "select emp_name from Employeemaster where emp_card_no = '" + person.PersonID.ToString() + "'"; employee_details = db_connection.ReturnDataTable(query); if (employee_details.Rows.Count > 0) { employee_name = employee_details.Rows[0]["emp_name"].ToString(); } string[] hu = { "", person.PersonID.ToString(), employee_name }; query = "insert into exportenrollid(enrollid, empname)values('" + person.PersonID.ToString() + "','" + employee_name + "')"; db_connection.ExecuteQuery_WithReturnValueString(query); enrollments.Rows.Add(hu); } // end of for loop } // end of if condition if (status == 1) { break; } } // end of while } return(enrollments); }