void LocalRunProcess() { foreach (DataRow dr in dt.Rows) { ZKAccess FG = new ZKAccess(Convert.ToInt32(dr["SerialPort"]), Convert.ToInt32(dr["Port"]), Convert.ToInt32(dr["MachineNumber"]), Convert.ToInt32(dr["Baudrate"]), dr["IP"].ToString()); if (FG.Connect_Net()) { DBLinker.Linker.ExecuteNonQuery("UPDATE d_machines SET ConnectType = 1 WHERE ID=" + dr["ID"].ToString()); FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false); int idwErrorCode = 0; string sdwEnrollNumber = ""; int idwVerifyMode = 0; int idwInOutMode = 0; int idwYear = 0; int idwMonth = 0; int idwDay = 0; int idwHour = 0; int idwMinute = 0; int idwSecond = 0; int idwWorkcode = 0; int y = 0; FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false); //disable the device if (FG.m_CZKEMClass.ReadGeneralLogData(FG.COM_MACHINENUMBER)) //read all the attendance records to the memory { while (FG.m_CZKEMClass.SSR_GetGeneralLogData(FG.COM_MACHINENUMBER, out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory { string t = idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString(); DataRow sqlDt = DBLinker.Linker.GetDataRow("SELECT * FROM d_atttransaction where EnrollNumber='" + sdwEnrollNumber + "' and date='" + t + "'"); if (sqlDt == null) { string sql = "INSERT INTO d_atttransaction (EnrollNumber ,VerifyMethod ,InOutMode ,date ,WorkCode,MachineID) VALUES ('" + sdwEnrollNumber + "'," + idwVerifyMode + "," + idwInOutMode + ",'" + t + "'," + idwWorkcode + "," + FG.COM_MACHINENUMBER.ToString() + ")"; DBLinker.Linker.ExecuteNonQuery(sql); y++; } } DBLinker.Linker.ExecuteNonQuery("INSERT INTO d_machinesstate (sn,zt ,sj) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','下载完成',getdate())"); FG.m_CZKEMClass.ClearGLog(FG.COM_MACHINENUMBER); FG.m_CZKEMClass.RefreshData(FG.COM_MACHINENUMBER); } else { FG.m_CZKEMClass.GetLastError(ref idwErrorCode); DBLinker.Linker.ExecuteNonQuery("INSERT INTO d_machinesstate (sn,zt ,sj) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','下载失败',getdate())"); } FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true); } else { FG.m_CZKEMClass.Disconnect(); DBLinker.Linker.ExecuteNonQuery("INSERT INTO d_machinesstate (sn,zt ,sj) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','连接失败',getdate())"); DBLinker.Linker.ExecuteNonQuery("UPDATE d_machines SET ConnectType = 0 WHERE ID=" + dr["ID"].ToString()); } } }
private void CmnLookData(DataRow dr, out DataTable dt, out string st) { //dt = (DataTable)RTable.Clone(); dt = (DataTable)userdata.Clone(); ZKAccess FG = new ZKAccess(ConvertUtil.GetDBInt(dr["SerialPort"]), ConvertUtil.GetDBInt(dr["Port"]), ConvertUtil.GetDBInt(dr["MachineNumber"]), ConvertUtil.GetDBInt(dr["Baudrate"]), dr["IP"].ToString()); if (FG.Connect_Net()) { st = "连接成功!"; string sdwEnrollNumber = ""; string sName = ""; string sPassword = ""; int iPrivilege = 0; bool bEnabled = false; //int idwFingerIndex; //string sTmpData = ""; //int iTmpLength = 0; //int iFlag = 0; //string sFaceData = ""; //int iFaceLength = 0; //int iFaceIndex = 50; FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false); //Cursor = Cursors.WaitCursor; FG.m_CZKEMClass.ReadAllUserID(FG.COM_MACHINENUMBER); //read all the user information to the memory FG.m_CZKEMClass.ReadAllTemplate(FG.COM_MACHINENUMBER); //read all the users' fingerprint templates to the memory while (FG.m_CZKEMClass.SSR_GetAllUserInfo(FG.COM_MACHINENUMBER, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled)) //get all the users' information from the memory { DataRow newdr = dt.NewRow(); newdr["EnrollNumber"] = sdwEnrollNumber.ToString(); newdr["UserName"] = sName.ToString(); newdr["Privilege"] = iPrivilege; newdr["MPassword"] = sPassword; newdr["IsEnabled"] = bEnabled; dt.Rows.Add(newdr); } FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true); } else { st = dr["MachineNumber"].ToString() + "指纹机连接失败"; } }
/// <summary> /// 指定下载 /// </summary> /// <param name="dr"></param> /// <param name="dt"></param> public void ZDCmnDownLoadData(DataRow dv, out DataTable dt, out string callback) { dt = (DataTable)attdt.Clone(); callback = ""; ZKAccess FG = new ZKAccess(Convert.ToInt32(dv["SerialPort"]), Convert.ToInt32(dv["Port"]), Convert.ToInt32(dv["MachineNumber"]), Convert.ToInt32(dv["Baudrate"]), dv["IP"].ToString()); if (FG.Connect_Net()) { int idwErrorCode = 0; string sdwEnrollNumber = ""; int idwVerifyMode = 0; int idwInOutMode = 0; int idwYear = 0; int idwMonth = 0; int idwDay = 0; int idwHour = 0; int idwMinute = 0; int idwSecond = 0; int idwWorkcode = 0; FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false); //disable the device if (FG.m_CZKEMClass.ReadGeneralLogData(FG.COM_MACHINENUMBER)) //read all the attendance records to the memory { while (FG.m_CZKEMClass.SSR_GetGeneralLogData(FG.COM_MACHINENUMBER, out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory { string t = idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString(); string sql = "SELECT * FROM d_atttransaction where [EnrollNumber]='" + sdwEnrollNumber + "' and [date]='" + t + "'"; DataRow ds = DBLinker.Linker.GetDataRow(sql); //DataRow sqlDr =SQLHelper.GetDataSet(SQLHelper.Conn, CommandType.Text,sql,null).Tables[0].DefaultView[0].Row; if (ds == null) { //DataRow ndr = dt.NewRow(); //ndr["EnrollNumber"] = sdwEnrollNumber; //ndr["VerifyMethod"] = idwVerifyMode; //ndr["InOutMode"] = idwInOutMode; //ndr["date"] = t; //ndr["WorkCode"] = idwWorkcode; //dt.Rows.Add(ndr); sql = "INSERT INTO d_atttransaction (EnrollNumber,VerifyMethod ,InOutMode ,date ,WorkCode,MachineID) VALUES ('" + sdwEnrollNumber + "'," + idwVerifyMode + "," + idwInOutMode + ",'" + t + "'," + idwWorkcode + "," + FG.COM_MACHINENUMBER.ToString() + ")"; DBLinker.Linker.ExecuteNonQuery(sql); } } //DBLinker.Linker.ExecuteNonQuery("INSERT INTO d_machinesstate (sn,zt ,sj) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','下载完成',getdate())"); string sql2 = "INSERT INTO [d_MachinesState] ([sn],[zt] ,[sj]) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','下载完成',getdate())"; DBLinker.Linker.ExecuteNonQuery(sql2); } else { //Cursor = Cursors.Default; FG.m_CZKEMClass.GetLastError(ref idwErrorCode); if (idwErrorCode != 0) { MessageBox.Show("读取终端数据错误,代码:" + idwErrorCode.ToString()); callback = ("读取终端数据错误,代码:" + idwErrorCode.ToString()); //listBox1.Items.Add("读取终端数据错误,代码:" + idwErrorCode.ToString()); } else { MessageBox.Show("终端没有任何数据"); callback = "终端没有任何数据"; //listBox1.Items.Add("终端没有任何数据"); } DBLinker.Linker.ExecuteNonQuery("INSERT INTO [d_MachinesState] ([sn],[zt] ,[sj]) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','下载失败',getdate())"); } FG.m_CZKEMClass.ClearGLog(FG.COM_MACHINENUMBER); FG.m_CZKEMClass.RefreshData(FG.COM_MACHINENUMBER); FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true); } else { MessageBox.Show("连接机器失败"); callback = ("连接机器失败"); FG.m_CZKEMClass.Disconnect(); DBLinker.Linker.ExecuteNonQuery("INSERT INTO [d_MachinesState] ([sn],[zt] ,[sj]) VALUES ('" + FG.COM_MACHINENUMBER.ToString() + "','连接失败',getdate())"); //SQLHelper.ExecuteNonQuery("UPDATE [d_Machines] SET [ConnectType] = 0 WHERE ID=" + dr["ID"].ToString()); } }
/// <summary> /// 下载更新数据库的用户数据 /// </summary> /// <param name="dr"></param> /// <param name="b"></param> protected void CmnDownLoadData(DataRow dr, out string b) { int count = 0; int sumcount = 0; string rtstr = ""; b = ""; ZKAccess FG = new ZKAccess(ConvertUtil.GetDBInt(dr["SerialPort"]), ConvertUtil.GetDBInt(dr["Port"]), ConvertUtil.GetDBInt(dr["MachineNumber"]), ConvertUtil.GetDBInt(dr["Baudrate"]), dr["IP"].ToString()); if (FG.Connect_Net()) { b = dr["MachineNumber"].ToString() + "指纹机连接成功"; string sdwEnrollNumber = ""; string sName = ""; string sPassword = ""; int iPrivilege = 0; bool bEnabled = false; int idwFingerIndex; string sTmpData = ""; int iTmpLength = 0; int iFlag = 0; int iFaceLength = 128 * 1024; int iFaceIndex = 50; byte[] sFaceData = new byte[iFaceLength]; FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false); //Cursor = Cursors.WaitCursor; FG.m_CZKEMClass.ReadAllUserID(FG.COM_MACHINENUMBER); //read all the user information to the memory FG.m_CZKEMClass.ReadAllTemplate(FG.COM_MACHINENUMBER); //read all the users' fingerprint templates to the memory while (FG.m_CZKEMClass.SSR_GetAllUserInfo(FG.COM_MACHINENUMBER, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled)) //get all the users' information from the memory { sumcount = sumcount + 1; //if (FG.m_CZKEMClass.GetUserFaceStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, iFaceIndex, ref sFaceData, ref iFaceLength))//get the face templates from the memory //{ //} if (FG.m_CZKEMClass.GetUserFace(FG.COM_MACHINENUMBER, sdwEnrollNumber, iFaceIndex, ref sFaceData[0], ref iFaceLength)) { } for (idwFingerIndex = 0; idwFingerIndex < 10; idwFingerIndex++) { if (FG.m_CZKEMClass.GetUserTmpExStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, idwFingerIndex, out iFlag, out sTmpData, out iTmpLength))//get the corresponding templates string and length from the memory { if (DBLinker.Linker.GetDataRow("select 1 from d_user where EnrollNumber='" + sdwEnrollNumber.ToString() + "'") == null) { string sql = "insert into [d_user] ([LoginName],[UserName],[UserPassword] ,[AllowLogin],[MachineNumber] ,[EnrollNumber] ,[FingerIndex] ,[FaceIndex],[Finger] ,[photo],[Flag] ,[MPassword] ,[Privilege] ,[IsEnabled],FingerLength,FaceLength) VALUES ('" + sdwEnrollNumber + "','" + sName + "','r3B6n6Eq5z8=' ,1," + FG.COM_MACHINENUMBER.ToString() + " ,'" + sdwEnrollNumber + "' ," + idwFingerIndex + " ," + iFaceIndex + ",'" + sTmpData + "','" + sFaceData + "'," + iFlag.ToString() + " ,'" + sPassword + "' ," + iPrivilege.ToString() + " ,'" + bEnabled + "'," + iTmpLength + "," + iFaceLength + ")"; if (DBLinker.Linker.ExecuteNonQuery(sql) != -1) { count = count + 1; } else { rtstr = rtstr + sql + "\r\n"; } } else { string sql = "UPDATE [d_user] SET [MachineNumber] =" + FG.COM_MACHINENUMBER.ToString() + ",[FingerIndex] = " + idwFingerIndex + ",[FaceIndex] = " + iFaceIndex + " ,[Finger] = '" + sTmpData + "',[photo] = '" + sFaceData + "' ,[Flag] = " + iFlag.ToString() + " ,[MPassword] ='" + sPassword + "' ,[Privilege] =" + iPrivilege.ToString() + " ,[IsEnabled] = '" + bEnabled + "',[FingerLength] = " + iTmpLength + " ,[FaceLength] = " + iFaceLength + " where [EnrollNumber]='" + sdwEnrollNumber + "'"; if (DBLinker.Linker.ExecuteNonQuery(sql) != -1) { count = count + 1; } else { rtstr = rtstr + sql + "\r\n"; } } } } } FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true); b = ("下载或更新用户信息" + count.ToString() + "条,合计" + sumcount.ToString() + "条,错误提示:\r\n " + rtstr); } else { b = dr["MachineNumber"].ToString() + "指纹机连接失败"; } }
/// 上传用户数据到机器 private void CmnUpLoadData(DataRow dr, out string b) { b = ""; ZKAccess FG = new ZKAccess(ConvertUtil.GetDBInt(dr["SerialPort"]), ConvertUtil.GetDBInt(dr["Port"]), ConvertUtil.GetDBInt(dr["MachineNumber"]), ConvertUtil.GetDBInt(dr["Baudrate"]), dr["IP"].ToString()); if (FG.Connect_Net()) { int idwErrorCode = 0; string sdwEnrollNumber = ""; string sName = ""; int idwFingerIndex = 0; string sTmpData = ""; ///权限级别0:一般用户1:登记员2:管理员3:超级管理员 int iPrivilege = 0; string sPassword = ""; string sEnabled = ""; bool bEnabled = true; int iFlag = 1; int iFaceLength = 128 * 1024; int iFaceIndex = 50; byte[] sFaceData = new byte[iFaceLength]; int iUpdateFlag = 1; FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false); // if (FG.m_CZKEMClass.BeginBatchUpdate(FG.COM_MACHINENUMBER, iUpdateFlag))//create memory space for batching data // { // string sLastEnrollNumber = "";//the former enrollnumber you have upload(define original value as 0) // for (int i = 0; i < gridView.RowCount; i++) // { // DataRow newdr = gridView.GetDataRow(i); // if (newdr["uploaded"].ToString() == "1") // { // sdwEnrollNumber = newdr["EnrollNumber"].ToString(); // sName = newdr["UserName"].ToString(); // idwFingerIndex = ConvertUtil.GetDBInt(newdr["FingerIndex"]); // sTmpData = newdr["Finger"].ToString(); // iPrivilege = ConvertUtil.GetDBInt(newdr["Privilege"]); // sPassword = newdr["MPassword"].ToString(); // sEnabled = newdr["IsEnabled"].ToString(); // iFlag = ConvertUtil.GetDBInt(newdr["Flag"]); // iFaceLength = ConvertUtil.GetDBInt(newdr["FingerLength"]); // sFaceData = (byte[])newdr["photo"]; // if (sEnabled == "true") // { // bEnabled = true; // } // else // { // bEnabled = false; // } // if (sdwEnrollNumber != sLastEnrollNumber)//identify whether the user information(except fingerprint templates) has been uploaded // { // if (FG.m_CZKEMClass.SSR_SetUserInfo(FG.COM_MACHINENUMBER, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled))//upload user information to the memory // { // FG.m_CZKEMClass.SetUserTmpExStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData);//upload templates information to the memory // } // else // { // FG.m_CZKEMClass.GetLastError(ref idwErrorCode); // FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true); // return; // } // } // else//the current fingerprint and the former one belongs the same user,that is ,one user has more than one template // { // FG.m_CZKEMClass.SetUserTmpExStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData); // } // //更新照片模版。先不要用,免得出错,丢失数据。试验能够成功再使用。 // //FG.m_CZKEMClass.SetUserFace(FG.COM_MACHINENUMBER, sdwEnrollNumber, 50,ref sFaceData[0], iFaceLength); // sLastEnrollNumber = sdwEnrollNumber;//change the value of iLastEnrollNumber dynamicly // } // } // } // FG.m_CZKEMClass.BatchUpdate(FG.COM_MACHINENUMBER);//upload all the information in the memory // FG.m_CZKEMClass.RefreshData(FG.COM_MACHINENUMBER);//the data in the device should be refreshed // FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true); // b = "上传完成"; } else { listBox1.Items.Add(dr["MachineNumber"].ToString() + "指纹机无法连机"); } }