private int ModifyPersonInfoUSB(int enroll_id, int device_id) { AnvizNew.PERSONINFO person = new AnvizNew.PERSONINFO(); byte[] nms = Encoding.ASCII.GetBytes(""); byte[] pss = Encoding.Default.GetBytes(""); int final_status = 0, status = 0, i = 0; int pLongRun = new int(); if (AnvizNew.CKT_ChangeConnectionMode(0) != 1) { } status = AnvizNew.CKT_RegisterUSB(device_id, 0); if (status != 0) { person.CardNo = 5216455; person.Name = new byte[12]; for (i = 0; i < 12; i++) { if (i < pss.Length) { person.Name[i] = pss[i]; continue; } person.Name[i] = 0; } person.Password = new byte[8]; for (i = 0; i < 8; i++) { if (i < nms.Length) { person.Password[i] = nms[i]; continue; } person.Password[i] = 0; } person.PersonID = enroll_id; person.KQOption = 6; person.Group = 1; final_status = AnvizNew.CKT_ModifyPersonInfo(device_id, ref person); // NOTE: Below section has been commented on purpose. Please uncomment after adding the code for LOGGING errors. /*switch (final_status) { * * case 1: * case -1: * default: * //TODO: Add logic for LOGGING here. * break; * }*/ } return(final_status); }
private int ModifyPersonInfoLAN(int enroll_id, int device_id, string device_ip, long card_string, string password, string employee_name) { AnvizNew.PERSONINFO person = new AnvizNew.PERSONINFO(); DBConnection db_connection = new DBConnection(); byte[] nms = Encoding.ASCII.GetBytes(password); byte[] pss = Encoding.Default.GetBytes(employee_name); int status = 1, card_number, final_status = 0, i = 0; long card_long = 0; bool is_admin = false; string query = string.Empty; status = AnvizNew.CKT_RegisterNet(device_id, device_ip); if (status == 1) { if (card_string > 0) { card_long = Convert.ToInt64(card_string); } else { card_long = 0; } if (card_long > 2147483647) { card_long = card_long - 4294967296; card_number = Convert.ToInt32(card_long); } else { card_number = Convert.ToInt32(card_long); } person.CardNo = card_number; person.Name = new byte[12]; for (i = 0; i < 12; i++) { if (i < pss.Length) { person.Name[i] = pss[i]; continue; } person.Name[i] = 0; } person.Password = new byte[8]; for (i = 0; i < 8; i++) { if (i < nms.Length) { person.Password[i] = nms[i]; continue; } person.Password[i] = 0; } person.PersonID = enroll_id; person.KQOption = 6; person.Group = 1; query = "select count(*) from Admin where EnrollId = " + enroll_id + " and Deviceid = " + device_id + " "; if (db_connection.RecordExist(query)) { is_admin = true; } if (is_admin == false) { final_status = AnvizNew.CKT_ModifyPersonInfo(device_id, ref person); } // NOTE: Below section has been commented on purpose. Please uncomment after adding the code for LOGGING errors. /*switch (final_status) { * * case 1: * case -1: * default: * //TODO: Add logic for LOGGING here. * break; * }*/ } return(final_status); }
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. } } } }
public static extern bool RtlMoveMemory(ref AnvizNew.PERSONINFO Destination, int Source, int Length);
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); }