コード例 #1
0
ファイル: AttComm.cs プロジェクト: korentec/KttLogsService
        public int GetDeviceStatus(EStatus statusRequest)
        {
            if (_bIsConnected == false)
            {
                throw new Exception("Please connect the att device first");
            }

            if (!_axCZKEM1.EnableDevice(_iMachineNumber, false))//disable the device
            {
                throw new Exception("Unable to disable device");
            }

            int status = 0;

            if (!_axCZKEM1.GetDeviceStatus(_iMachineNumber, (int)statusRequest, ref status))
            {
                int errCode = 0;
                _axCZKEM1.GetLastError(ref errCode);

                if (errCode != 0)
                {
                    throw new Exception("Reading data from terminal failed, ErrorCode: " + errCode.ToString());
                }
            }

            if (!_axCZKEM1.EnableDevice(_iMachineNumber, true))//enable the device
            {
                throw new Exception("Unable to enable device");
            }

            return(status);
        }
コード例 #2
0
        private static int GetNumOfRecords(CZKEMClass axCZKEM1, int iMachineNumber, int idwErrorCode)
        {
            int num = 0;

            axCZKEM1.EnableDevice(iMachineNumber, false);
            if (!axCZKEM1.GetDeviceStatus(iMachineNumber, 6, ref num))
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                Console.WriteLine(string.Concat("Operation failed,ErrorCode=", idwErrorCode.ToString()), "Error");
            }
            else
            {
                Console.WriteLine(string.Concat("The count of the AttLogs in the device is ", num.ToString()), "Success");
            }
            axCZKEM1.EnableDevice(iMachineNumber, true);
            return(idwErrorCode);
        }
コード例 #3
0
        private void bwPosting_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            bool bIsConnected = false;
            int  idwErrorCode = 0;

            lblProses.Invoke(new Action(() => lblProses.Text = "Mengambil data mesin"));
            var mesin  = fp.mesins.ToList();
            int no     = 1;
            int jumlah = 0;

            foreach (var msn in mesin)
            {
                progressBar.Value = 0;
                bwDownload.ReportProgress(0);
                lblProses.Invoke(new Action(() => lblProses.Text = "Melakukan koneksi ke mesin " + msn.mesin_nama + ", IP " + msn.mesin_ip + ", port " + msn.mesin_key));
                bIsConnected = axCZKEM1.Connect_Net(msn.mesin_ip.Trim(), Convert.ToInt32(msn.mesin_key.Trim()));

                if (bIsConnected == false)
                {
                    axCZKEM1.GetLastError(ref idwErrorCode);
                    lblProses.Invoke(new Action(() => lblProses.Text = "Koneksi ke mesin " + msn.mesin_nama + ", IP " + msn.mesin_ip + ", port " + msn.mesin_key + " GAGAL " + idwErrorCode.ToString()));
                    gagal.Add("gagal");
                }
                else
                {
                    iMachineNumber = no;
                    axCZKEM1.RegEvent(iMachineNumber, 65535);

                    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 iValue = 400;

                    axCZKEM1.EnableDevice(iMachineNumber, false);
                    lblProses.Invoke(new Action(() => lblProses.Text = "Menghitung jumlah data absensi"));
                    if (!axCZKEM1.GetDeviceStatus(iMachineNumber, 6, ref iValue))
                    {
                        axCZKEM1.GetLastError(ref idwErrorCode);
                        lblProses.Invoke(new Action(() => lblProses.Text = "Operation failed,ErrorCode=" + idwErrorCode.ToString()));
                        e.Cancel = true;
                        return;
                    }
                    lblProses.Invoke(new Action(() => lblProses.Text = "Mendownload " + iValue.ToString() + " data absensi"));
                    if (axCZKEM1.ReadAllGLogData(iMachineNumber))
                    {
                        var pegawai = fp.pegawais.ToList();
                        int nomor   = 1;
                        while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out sdwEnrollNumber, out idwVerifyMode,
                                                              out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))
                        {
                            try
                            {
                                if (pegawai.Where(s => s.pegawai_id.Equals(sdwEnrollNumber)).Count() > 0)
                                {
                                    log data = new log();
                                    data.pegawai_id  = sdwEnrollNumber;
                                    data.log_tanggal = DateTime.Parse(idwYear + "-" + idwMonth + "-" + idwDay);
                                    data.log_jam     = TimeSpan.Parse(idwHour + ":" + idwMinute + ":" + idwSecond);
                                    data.log_kode    = idwVerifyMode.ToString();
                                    data.log_status  = idwInOutMode.ToString();
                                    fp.logs.Add(data);
                                    lblProses.Invoke(new Action(() => lblProses.Text = "Menyimpan data ke " + nomor + "/" + iValue + " ID " + sdwEnrollNumber + ", tanggal " + idwYear + "-" + idwMonth + "-" + idwDay + ", waktu " + idwHour + ":" + idwMinute + ":" + idwSecond + " status " + idwInOutMode.ToString() + ", BERHASIL"));
                                    jumlah += 1;
                                }
                            }
                            catch (Exception ex)
                            {
                                gagal.Add("ID " + sdwEnrollNumber + ", tanggal " + idwYear + "-" + idwMonth + "-" + idwDay + ", waktu " + idwHour + ":" + idwMinute + ":" + idwSecond + " status " + idwInOutMode.ToString() + " ke " + nomor + "/" + iValue);
                                lblProses.Invoke(new Action(() => lblProses.Text = "Menyimpan data ke " + nomor + "/" + iValue + " ID " + sdwEnrollNumber + ", tanggal " + idwYear + "-" + idwMonth + "-" + idwDay + ", waktu " + idwHour + ":" + idwMinute + ":" + idwSecond + " status " + idwInOutMode.ToString() + ", GAGAL " + ex.Message));
                            }
                            fp.SaveChanges();
                            int percentage = nomor * 100 / iValue;
                            nomor++;
                            bwDownload.ReportProgress(percentage);
                        }
                        if (axCZKEM1.ClearGLog(iMachineNumber))
                        {
                            axCZKEM1.RefreshData(iMachineNumber);
                            lblProses.Invoke(new Action(() => lblProses.Text = "Menghapus Data absen di mesin"));
                        }
                        else
                        {
                            axCZKEM1.GetLastError(ref idwErrorCode);
                            lblProses.Invoke(new Action(() => lblProses.Text = "Operation failed,ErrorCode=" + idwErrorCode.ToString()));
                        }
                    }
                    else
                    {
                        Cursor = Cursors.Default;
                        axCZKEM1.GetLastError(ref idwErrorCode);

                        if (idwErrorCode != 0)
                        {
                            lblProses.Invoke(new Action(() => lblProses.Text = "Reading data from terminal failed,ErrorCode: " + idwErrorCode.ToString().ToString()));
                        }
                        else
                        {
                            lblProses.Invoke(new Action(() => lblProses.Text = "No data from terminal returns!"));
                        }
                    }
                    no += 1;
                    axCZKEM1.EnableDevice(iMachineNumber, true);
                    axCZKEM1.Disconnect();
                }
            }
            if (gagal.Count > 0)
            {
                lblProses.Invoke(new Action(() => lblProses.Text = "Gagal mendownload " + gagal.Count + " data absensi"));
                MessageBox.Show("Gagal mendownload " + gagal.Count + " data absensi");
                e.Cancel = true;
            }
            else
            {
                lblProses.Invoke(new Action(() => lblProses.Text = "Berhasil mendownload " + jumlah.ToString() + " data absensi dari mesin"));
                MessageBox.Show("Berhasil mendownload " + jumlah.ToString() + " data absensi dari mesin");
            }
        }
コード例 #4
0
        private void bwPosting_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            bool bIsConnected = false;
            int  idwErrorCode = 0;

            lblProses.Invoke(new Action(() => lblProses.Text = "Mengambil data mesin"));
            var mesin  = fp.mesins.ToList();
            int no     = 1;
            int jumlah = 0;

            foreach (var msn in mesin)
            {
                progressBar.Value = 0;
                bwDownload.ReportProgress(0);
                lblProses.Invoke(new Action(() => lblProses.Text = "Melakukan koneksi ke mesin " + msn.mesin_nama + ", IP " + msn.mesin_ip + ", port " + msn.mesin_key));
                bIsConnected = axCZKEM1.Connect_Net(msn.mesin_ip.Trim(), Convert.ToInt32(msn.mesin_key.Trim()));

                if (bIsConnected == false)
                {
                    axCZKEM1.GetLastError(ref idwErrorCode);
                    lblProses.Invoke(new Action(() => lblProses.Text = "Koneksi ke mesin " + msn.mesin_nama + ", IP " + msn.mesin_ip + ", port " + msn.mesin_key + " GAGAL " + idwErrorCode.ToString()));
                    gagal.Add("gagal");
                }
                else
                {
                    iMachineNumber = no;
                    axCZKEM1.RegEvent(iMachineNumber, 65535);

                    string sdwEnrollNumber = "";
                    string sName           = "";
                    string sPassword       = "";
                    int    iPrivilege      = 0;
                    bool   bEnabled        = false;
                    int    iValue          = 0;
                    lblProses.Invoke(new Action(() => lblProses.Text = "Menghitung jumlah data pegawai"));
                    axCZKEM1.EnableDevice(iMachineNumber, false);

                    if (axCZKEM1.GetDeviceStatus(iMachineNumber, 2, ref iValue))
                    {
                        int nomor = 1;
                        axCZKEM1.ReadAllUserID(iMachineNumber);
                        lblProses.Invoke(new Action(() => lblProses.Text = "Mendownload " + iValue.ToString() + " data pegawai"));
                        while (axCZKEM1.SSR_GetAllUserInfo(iMachineNumber, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled))
                        {
                            try
                            {
                                if (fp.pegawais.Where(x => x.pegawai_id.Equals(sdwEnrollNumber)).Count() == 0)
                                {
                                    pegawai data = new pegawai();
                                    data.pegawai_id            = sdwEnrollNumber;
                                    data.pegawai_nip           = "";
                                    data.pegawai_nama          = "";
                                    data.pegawai_panggilan     = sName;
                                    data.pegawai_golongan      = "";
                                    data.pegawai_jenis_kelamin = "";
                                    data.pegawai_izin          = iPrivilege == 3 ? "0" : "1";
                                    data.pegawai_sandi         = sPassword;
                                    data.upload = true;
                                    fp.pegawais.Add(data);
                                    fp.SaveChanges();
                                }
                                else
                                {
                                    var data = fp.pegawais.Where(x => x.pegawai_id.Equals(sdwEnrollNumber)).FirstOrDefault();
                                    data.pegawai_id        = sdwEnrollNumber;
                                    data.pegawai_panggilan = sName;
                                    data.pegawai_izin      = iPrivilege == 3 ? "0" : "1";
                                    data.pegawai_sandi     = sPassword;
                                    data.upload            = true;
                                    fp.SaveChanges();
                                }
                                jumlah += 1;
                                lblProses.Invoke(new Action(() => lblProses.Text = "Menyimpan data ID " + sdwEnrollNumber + ", nama " + sName + ", BERHASIL"));
                            }
                            catch
                            {
                                gagal.Add("ID " + sdwEnrollNumber + ", nama " + sName);
                                lblProses.Invoke(new Action(() => lblProses.Text = "Menyimpan data ID " + sdwEnrollNumber + ", nama " + sName + ", GAGAL"));
                            }
                            int percentage = nomor * 100 / iValue;
                            nomor++;
                            bwDownload.ReportProgress(percentage);
                        }
                        axCZKEM1.EnableDevice(iMachineNumber, true);
                    }
                    else
                    {
                        axCZKEM1.GetLastError(ref idwErrorCode);
                        lblProses.Invoke(new Action(() => lblProses.Text = "Operation failed,ErrorCode=" + idwErrorCode.ToString()));
                    }
                    no += 1;
                    axCZKEM1.EnableDevice(iMachineNumber, true);
                    axCZKEM1.Disconnect();
                }
            }
            if (gagal.Count > 0)
            {
                lblProses.Invoke(new Action(() => lblProses.Text = "Gagal mendownload " + gagal.Count + " data pegawai"));
                MessageBox.Show("Gagal mendownload " + gagal.Count + " data pegawai");
                e.Cancel = true;
            }
            else
            {
                lblProses.Invoke(new Action(() => lblProses.Text = "Berhasil mendownload " + jumlah.ToString() + " data pegawai dari mesin"));
                MessageBox.Show("Berhasil mendownload " + jumlah.ToString() + " data pegawai dari mesin");
            }
        }