예제 #1
0
        public static void InsertTagReg(DeviceTagRegData t)
        {
            string sql = "INSERT INTO RFDEVICE_TAG_REG(DEVICE_IP, DEVICE_PORT, EMPNO, REG_DATE, TAGID) "
                         + " VALUES(:device_ip,:device_port,:empno,:reg_date,:tagid) ";

            OracleParameter[] param = new OracleParameter[]
            {
                new OracleParameter(":device_ip", t.device_ip),
                new OracleParameter(":device_port", t.device_port),
                new OracleParameter(":empno", t.empno),
                new OracleParameter(":reg_date", t.reg_date),
                new OracleParameter(":tagid", t.tagid)
            };

            db.ExecuteNonQuery(sql, CommandType.Text, param);
        }
예제 #2
0
        /// <summary>
        /// 更新设备中的用户
        /// </summary>
        /// <param name="device_ip"></param>
        /// <param name="device_port"></param>
        /// <returns></returns>
        public ResultSet GetAllUser(string device_ip, int device_port)
        {
            try
            {
                if (Connect(device_ip))
                {
                    log.Info(string.Format("Function : GetAllUser Start,{0}:{1}", device_ip, device_port));
                    Common.db.BeginTransaction();

                    int       deleteEffectRow = 0;
                    Hashtable param           = new Hashtable()
                    {
                        { "device_ip", device_ip },
                        { "device_port", device_port }
                    };
                    deleteEffectRow = Common.DelDevice(device_ip);

                    int insertEffectRow = 0;
                    //read all the user information to the memory
                    log.Info(string.Format("ZKSoftware API :  axCZKEM1.ReadAllUserID"));
                    axCZKEM1.ReadAllUserID(iMachineNumber);


                    if (getDeviceType(device_ip) == "accesscontrol")
                    {
                        int dwEnrollNumber = 0;

                        log.Info(string.Format("ZKSoftware API :  axCZKEM1.GetAllUserInfo[accesscontrol]"));
                        while (axCZKEM1.GetAllUserInfo(iMachineNumber
                                                       , ref dwEnrollNumber
                                                       , ref sName
                                                       , ref sPassword
                                                       , ref iPrivilege
                                                       , ref bEnabled)) //get user information from memory
                        {
                            log.Info("ref_empno:" + dwEnrollNumber);

                            var empno = Common.GetUserByRefno(dwEnrollNumber.ToString());

                            if (empno == null)
                            {
                                log.Info(string.Format("ZKSoftware API :  axCZKEM1.GetStrCardNumber"));
                                //get the card number from the memory
                                if (axCZKEM1.GetStrCardNumber(out sCardnumber))
                                {
                                    object empno1 = Common.GetUserByTagid(sCardnumber);

                                    if (empno1 != null)
                                    {
                                        sdwEnrollNumber = empno1.ToString();
                                    }
                                    else
                                    {
                                        sdwEnrollNumber = "NA_" + sCardnumber;
                                    }
                                    log.Info(string.Format("{0},{1},{2}", sdwEnrollNumber, sCardnumber, iPrivilege));
                                    try
                                    {
                                        DeviceTagRegData tagdata = new DeviceTagRegData();
                                        tagdata.device_ip   = device_ip;
                                        tagdata.device_port = 1;
                                        tagdata.empno       = sdwEnrollNumber;
                                        tagdata.tagid       = sCardnumber;
                                        tagdata.reg_date    = DateTime.Now;
                                        Common.InsertTagReg(tagdata);
                                        log.Info(string.Format("{0},{1},{2},{3},{4}", device_ip, device_port, DateTime.Now, sdwEnrollNumber, sCardnumber));
                                        insertEffectRow++;
                                    }
                                    catch (Exception ex)
                                    {
                                        log.Error(ex);
                                    }
                                }
                            }
                            else
                            {
                                try
                                {
                                    DeviceTagRegData tagdata = new DeviceTagRegData();
                                    tagdata.device_ip   = device_ip;
                                    tagdata.device_port = 1;
                                    tagdata.empno       = empno.ToString();
                                    tagdata.tagid       = "";
                                    tagdata.reg_date    = DateTime.Now;
                                    Common.InsertTagReg(tagdata);
                                    log.Info(string.Format("{0},{1},{2},{3},{4}", device_ip, device_port, DateTime.Now, sdwEnrollNumber, ""));
                                    insertEffectRow++;
                                }
                                catch (Exception ex)
                                {
                                    log.Error(ex);
                                }
                            }
                        }
                    }
                    else
                    {
                        string sEnrollNumber;

                        log.Info(string.Format("ZKSoftware API :  axCZKEM1.SSR_GetAllUserInfo"));
                        while (axCZKEM1.SSR_GetAllUserInfo(
                                   iMachineNumber,
                                   out sEnrollNumber,
                                   out sName,
                                   out sPassword,
                                   out iPrivilege,
                                   out bEnabled))          //get user information from memory
                        {
                            log.Info(string.Format("ZKSoftware API :  axCZKEM1.GetStrCardNumber"));
                            log.Info(string.Format("{0},{1},{2}", sEnrollNumber, sName, iPrivilege));

                            var empno = Common.GetUserByRefno(sEnrollNumber.ToString());

                            if (empno == null)
                            {
                                if (axCZKEM1.GetStrCardNumber(out sCardnumber))    //get the card number from the memory
                                {
                                    object empno1 = Common.GetUserByTagid(sCardnumber);

                                    if (empno1 != null)
                                    {
                                        sdwEnrollNumber = empno1.ToString();
                                    }
                                    else
                                    {
                                        sdwEnrollNumber = "NA_" + sCardnumber;
                                    }

                                    try
                                    {
                                        DeviceTagRegData tagdata = new DeviceTagRegData();
                                        tagdata.device_ip   = device_ip;
                                        tagdata.device_port = device_port;
                                        tagdata.empno       = sdwEnrollNumber;
                                        tagdata.tagid       = sCardnumber;
                                        tagdata.reg_date    = DateTime.Now;
                                        Common.InsertTagReg(tagdata);

                                        insertEffectRow++;
                                    }
                                    catch (Exception ex)
                                    {
                                        log.Error(ex);
                                    }
                                }
                            }
                            else
                            {
                                try
                                {
                                    DeviceTagRegData tagdata = new DeviceTagRegData();
                                    tagdata.device_ip   = device_ip;
                                    tagdata.device_port = 1;
                                    tagdata.empno       = empno.ToString();
                                    tagdata.tagid       = "";
                                    tagdata.reg_date    = DateTime.Now;
                                    Common.InsertTagReg(tagdata);
                                    log.Info(string.Format("{0},{1},{2},{3},{4}", device_ip, device_port, DateTime.Now, sdwEnrollNumber, ""));
                                    insertEffectRow++;
                                }
                                catch (Exception ex)
                                {
                                    log.Error(ex);
                                }
                            }
                        }
                    }
                    Common.db.Commit();

                    _resultset = new ResultSet
                    {
                        SeccessFlag = true,
                        Result      = string.Format("Insert : {0} delete : {1}", insertEffectRow, deleteEffectRow)
                    };
                }
                else
                {
                    _resultset = new ResultSet
                    {
                        SeccessFlag = false,
                        Result      = device_ip,
                        Description = string.Format("can not connect to the device. please check it.")
                    };
                }
            }
            catch (Exception ex)
            {
                Common.db.Rollback();
                log.Fatal(ex);
                _resultset = new ResultSet
                {
                    SeccessFlag = false,
                    Result      = ErrorCode.ToString(),
                    Description = string.Format("Try Catched Error {0}", ex.Message)
                };
            }
            finally
            {
                Close();
                log.Info(string.Format("Function : GetAllUser finish ,{0}", _resultset.Result));
            }

            return(_resultset);
        }