Exemple #1
0
    public static ReturnObject SetDeviceTime(string current)
    {
        lan_information page_object        = new lan_information();
        ReturnObject    return_object      = new ReturnObject();
        string          communication_type = string.Empty;
        string          device_ip          = string.Empty;
        string          device_type        = string.Empty;
        string          device_time        = string.Empty;
        bool            is_connected       = false;
        int             idwErrorCode       = 0;
        int             idwYear            = 0;
        int             idwMonth           = 0;
        int             idwDay             = 0;
        int             idwHour            = 0;
        int             idwMinute          = 0;
        int             idwSecond          = 0;
        int             device_id          = 0;
        int             status             = 0;

        try {
            JObject current_data = JObject.Parse(current);
            device_ip          = current_data["device_ip"].ToString();
            device_type        = current_data["device_type"].ToString();
            communication_type = current_data["communication_type"].ToString();
            device_id          = Convert.ToInt32(current_data["device_id"]);

            switch (device_type)
            {
            case "Anviz":
                status = page_object.ConnectAnvizDevice(device_id, device_ip, communication_type);

                if (status != 0)
                {
                    //int ReaderNo = Convert.ToInt32(listView1.SelectedItems[0].SubItems[0].Text);
                    AnvizNew.DATETIMEINFO PTime = new AnvizNew.DATETIMEINFO();
                    PTime.Year   = Convert.ToUInt16(DateTime.Now.Year);
                    PTime.Month  = Convert.ToByte(DateTime.Now.Month);
                    PTime.Day    = Convert.ToByte(DateTime.Now.Day);
                    PTime.Hour   = Convert.ToByte(DateTime.Now.Hour);
                    PTime.Minute = Convert.ToByte(DateTime.Now.Minute);
                    PTime.Second = Convert.ToByte(DateTime.Now.Second);
                    if (AnvizNew.CKT_SetDeviceClock(device_id, ref PTime) == 1)
                    {
                        device_time = PTime.Year.ToString() + "-" + (PTime.Month).ToString("00") + "-" + (PTime.Day).ToString("00") + " " + (PTime.Hour).ToString("00") + ":" + (PTime.Minute).ToString("00") + ":" + (PTime.Second).ToString("00");

                        return_object.status      = "success";
                        return_object.return_data = device_time;
                    }
                    else
                    {
                        return_object.status      = "error";
                        return_object.return_data = "Setting Device Clock failed. Please try again.";
                    }
                }
                else
                {
                    return_object.status      = "error";
                    return_object.return_data = "Unable to communicate with the Device. Please try again.";
                }
                break;

            case "BioSecurity":
                is_connected = page_object.axCZKEM1.Connect_Net(device_ip, Convert.ToInt32(4370));
                if (is_connected == true)
                {
                    idwErrorCode = 0;
                    idwYear      = Convert.ToInt32(DateTime.Now.Year);
                    idwMonth     = Convert.ToInt32(DateTime.Now.Month);
                    idwDay       = Convert.ToInt32(DateTime.Now.Day);
                    idwHour      = Convert.ToInt32(DateTime.Now.Hour);
                    idwMinute    = Convert.ToInt32(DateTime.Now.Minute);
                    idwSecond    = Convert.ToInt32(DateTime.Now.Second);

                    //Cursor = Cursors.WaitCursor;
                    if (page_object.axCZKEM1.SetDeviceTime2(device_id, idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond))
                    {
                        page_object.axCZKEM1.RefreshData(device_id);    //the data in the device should be refreshed

                        return_object.status      = "success";
                        return_object.return_data = device_time;
                    }
                    else
                    {
                        return_object.status      = "error";
                        return_object.return_data = "Setting Device Clock failed. Please try again.";
                    }
                }
                else
                {
                    return_object.status      = "error";
                    return_object.return_data = "Unable to communicate with the Device. Please try again.";
                }
                page_object.axCZKEM1.Disconnect();
                break;
            }
        }
        catch (Exception ex) {
            Logger.LogException(ex, page, "SET_DEVICE_TIME");

            return_object.status      = "error";
            return_object.return_data = "An error occurred while Setting Device Clock. Please try again. If the error persists, please contact Support";

            throw;
        }
        finally {
            page_object.Dispose();
        }

        return(return_object);
    }
Exemple #2
0
    public static ReturnObject GetDeviceTime(string current)
    {
        lan_information page_object        = new lan_information();
        ReturnObject    return_object      = new ReturnObject();
        string          communication_type = string.Empty;
        string          device_type        = string.Empty;
        string          device_ip          = string.Empty;
        string          device_time        = string.Empty;
        bool            is_connected       = false;
        int             idwErrorCode       = 0;
        int             idwYear            = 0;
        int             idwMonth           = 0;
        int             idwDay             = 0;
        int             idwHour            = 0;
        int             idwMinute          = 0;
        int             idwSecond          = 0;
        int             device_id          = 0;
        int             status             = 0;

        try {
            JObject current_data = JObject.Parse(current);
            device_id          = Convert.ToInt32(current_data["device_id"]);
            device_ip          = current_data["device_ip"].ToString();
            device_type        = current_data["device_type"].ToString();
            communication_type = current_data["communication_type"].ToString();

            switch (device_type)
            {
            case "Anviz":
                status = 0;
                status = page_object.ConnectAnvizDevice(device_id, device_ip, communication_type);

                if (status != 0)
                {
                    AnvizNew.DATETIMEINFO PTime = new AnvizNew.DATETIMEINFO();
                    if (AnvizNew.CKT_GetDeviceClock(device_id, ref PTime) == 1)
                    {
                        device_time = PTime.Year.ToString() + "-" + (PTime.Month).ToString("00") + "-" + (PTime.Day).ToString("00") + " " + (PTime.Hour).ToString("00") + ":" + (PTime.Minute).ToString("00") + ":" + (PTime.Second).ToString("00");

                        return_object.status      = "success";
                        return_object.return_data = device_time;
                    }
                    else
                    {
                        return_object.status      = "error";
                        return_object.return_data = "Getting Device Time failed. Please try again.";
                    }
                }
                else
                {
                    return_object.status      = "error";
                    return_object.return_data = "Unable to communicate with the Device. Please try again.";
                }
                break;

            case "BioSecurity":
                is_connected = page_object.axCZKEM1.Connect_Net(device_ip, Convert.ToInt32(4370));
                if (is_connected == true)
                {
                    //Cursor = Cursors.WaitCursor;
                    if (page_object.axCZKEM1.GetDeviceTime(device_id, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute, ref idwSecond))
                    {
                        device_time = idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString();

                        return_object.status      = "success";
                        return_object.return_data = device_time;
                    }
                    else
                    {
                        return_object.status      = "error";
                        return_object.return_data = "Set Device Clock failed. Please try again.";
                    }
                }
                else
                {
                    return_object.status      = "error";
                    return_object.return_data = "Unable to communicate with the Device. Please try again.";
                }
                page_object.axCZKEM1.Disconnect();
                //Cursor = Cursors.Default;
                break;
            }
        }
        catch (Exception ex) {
            Logger.LogException(ex, page, "GET_DEVICE_TIME");

            return_object.status      = "error";
            return_object.return_data = "An error occurred when getting Device Time. Please try again. If the error persists, please contact Support";
        }
        finally {
            page_object.Dispose();
        }

        return(return_object);
    }