Exemplo n.º 1
0
 public BadgeReaderArgs(string deviceSerial, UserClassTemplate userTemplate, AccessBagerReaderType accessType)
 {
     DeviceSerial = deviceSerial;
     UserTemplate = userTemplate;
     AccessType   = accessType;
     IsMaster     = true;
 }
Exemplo n.º 2
0
        private void UserMngtForm_Load(object sender, EventArgs e)
        {
            if (_myFinger != null)
            {
                _myFinger.ReleaseFingerprint();
                _myFinger = null;
            }


            _dtUserGrant = new DataTable();
            _dtUserGrant.Columns.Add("UserGrantID", typeof(int));
            _dtUserGrant.Columns.Add("UserGrantName", typeof(string));
            _dtUserGrant.Rows.Add(0, getEnumDesc.GetEnumDescription(UserGrant.UG_NONE));
            _dtUserGrant.Rows.Add(1, getEnumDesc.GetEnumDescription(UserGrant.UG_MASTER));
            _dtUserGrant.Rows.Add(2, getEnumDesc.GetEnumDescription(UserGrant.UG_SLAVE));
            _dtUserGrant.Rows.Add(3, getEnumDesc.GetEnumDescription(UserGrant.UG_MASTER_AND_SLAVE));



            DataGridViewComboBoxColumn dgc = (DataGridViewComboBoxColumn)dataGridViewGrant.Columns[0];

            dgc.DataSource       = _dtUserGrant;
            dgc.DisplayMember    = "UserGrantName";
            dgc.ValueMember      = "UserGrantID";
            dgc.DataPropertyName = "UserGrantID";


            _myFinger = new FingerPrintClass();

            comboBoxFinger.SelectedIndex = 0;
            _db.OpenDB();
            _userInEnroll = new UserClassTemplate();
            UpdateListBoxUser();
            CreateGrantTable();
        }
 public InputData(AlertType alertType, DeviceInfo device, UserClassTemplate utc, string spareData, bool bShowWindowBox)
 {
     this.Alert          = alertType;
     this.Device         = device;
     this.UTC            = utc;
     this.BShowWindowBox = bShowWindowBox;
     this.SpareData      = spareData;
 }
Exemplo n.º 4
0
        public bool DeleteUserGrant(UserClassTemplate UserToStore, string SerialRFID)
        {
            switch (useDb)
            {
            case dbUsedType.db_SqlLite: return(sqliteProvider.DeleteUserGrant(UserToStore, SerialRFID));

            case dbUsedType.db_SqlServer: return(sqlServerProvider.DeleteUserGrant(UserToStore, SerialRFID));
            }
            return(false);
        }
Exemplo n.º 5
0
        public bool StoreGrant(UserClassTemplate UserToStore, string SerialRFID, string BelongTo, UserGrant userGrant)
        {
            switch (useDb)
            {
            case dbUsedType.db_SqlLite: return(sqliteProvider.StoreGrant(UserToStore, SerialRFID, BelongTo, userGrant));

            case dbUsedType.db_SqlServer: return(sqlServerProvider.StoreGrant(UserToStore, SerialRFID, BelongTo, userGrant));
            }
            return(false);
        }
Exemplo n.º 6
0
        public DeviceGrant[] recoverUserGrantFull(UserClassTemplate User)
        {
            switch (useDb)
            {
            case dbUsedType.db_SqlLite: return(sqliteProvider.recoverUserGrantFull(User));

            case dbUsedType.db_SqlServer: return(sqlServerProvider.recoverUserGrantFull(User));
            }
            return(null);
        }
Exemplo n.º 7
0
        public bool StoreUser(UserClassTemplate UserToStore)
        {
            switch (useDb)
            {
            case dbUsedType.db_SqlLite: return(sqliteProvider.StoreUser(UserToStore));

            case dbUsedType.db_SqlServer: return(sqlServerProvider.StoreUser(UserToStore));
            }
            return(false);
        }
Exemplo n.º 8
0
        public bool storeAlert(AlertType alertType, DeviceInfo di, UserClassTemplate utc, string alertData)
        {
            switch (useDb)
            {
            case dbUsedType.db_SqlLite: return(sqliteProvider.storeAlert(alertType, di, utc, alertData));

            case dbUsedType.db_SqlServer: return(sqlServerProvider.storeAlert(alertType, di, utc, alertData));
            }
            return(false);
        }
Exemplo n.º 9
0
        public InventoryData[] GetInventory(DeviceInfo di, UserClassTemplate uct, int nbData = 100)
        {
            switch (useDb)
            {
            case dbUsedType.db_SqlLite: return(sqliteProvider.GetInventory(di, uct, nbData));

            case dbUsedType.db_SqlServer: return(sqlServerProvider.GetInventory(di, uct, nbData));
            }
            return(null);
        }
Exemplo n.º 10
0
        private void ProcessData()
        {
            InitReaderScanTable();

            UserClassTemplate uct = null;
            DeviceInfo        di  = null;

            if (toolStripComboBoxReader.SelectedIndex > 0)
            {
                di = _deviceArray[toolStripComboBoxReader.SelectedIndex - 1];
            }

            if (toolStripComboBoxUser.SelectedIndex > 0)
            {
                uct = _userArray[toolStripComboBoxUser.SelectedIndex - 1];
            }

            InventoryData[] invData = _db.GetInventory(di, uct);
            if (invData == null)
            {
                return;
            }
            _inventoryArray = new InventoryData[invData.Length];
            //invData.CopyTo(_inventoryArray, 0);
            int nIndex = 0;

            foreach (InventoryData dt in invData)
            {
                try
                {
                    DeviceInfo tmpdi = _db.RecoverDevice(dt.serialNumberDevice);
                    if (tmpdi != null)
                    {
                        _tbReaderScan.Rows.Add(dt.eventDate.ToString("G"), dt.serialNumberDevice, tmpdi.DeviceName,
                                               Convert.ToInt32(dt.bUserScan), dt.userDoor.ToString(), dt.userFirstName, dt.userLastName,
                                               dt.nbTagAll, dt.nbTagPresent, dt.nbTagAdded, dt.nbTagRemoved);

                        _inventoryArray[nIndex++] = dt;
                    }
                }
                catch (Exception exp)
                {
                    // On affiche l'erreur.
                    ExceptionMessageBox.Show(exp);
                }
            }
            dataGridViewScan.DataSource = null;
            dataGridViewScan.DataSource = _tbReaderScan.DefaultView;
            if (dataGridViewScan.Rows.Count > 0)
            {
                dataGridViewScan.Rows[0].Selected = true;
            }

            bProcessed = true;
        }
Exemplo n.º 11
0
        private void listBoxUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxUser.SelectedIndex >= 0)
            {
                _bComeFromListBox        = true;
                groupBoxUserCtrl.Enabled = true;
                toolStripButtonEnrollFingerprint.Enabled = true;
                gpBx.Enabled = true;
                toolStripButtonDelete.Enabled = true;
                int rowSelected = listBoxUser.SelectedIndex;
                _userInEnroll = new UserClassTemplate();
                _userInEnroll = _userArray[rowSelected];

                textBoxFirstName.ReadOnly = true;
                textBoxLastName.ReadOnly  = true;
                textBoxFirstName.Text     = _userInEnroll.firstName;
                textBoxLastName.Text      = _userInEnroll.lastName;
                textBoxReaderCard.Text    = _userInEnroll.BadgeReaderID;
                UpdateGridFinger();

                UpdateGrantTable(_userInEnroll);

                _fingerAlert = _db.getUserFingerAlert(textBoxFirstName.Text, textBoxLastName.Text);
                comboBoxFinger.SelectedIndex = _fingerAlert + 1;

                _maxItem = _db.getUserMaxRemovedItem(textBoxFirstName.Text, textBoxLastName.Text);
                if (_maxItem >= 0)
                {
                    textBoxRemoveItem.Text = _maxItem.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    textBoxRemoveItem.Text = null;
                }

                _maxValue = _db.getUserMaxRemoveValue(textBoxFirstName.Text, textBoxLastName.Text);
                if (_maxValue >= 0)
                {
                    textBoxRemoveValue.Text = _maxValue.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    textBoxRemoveValue.Text = null;
                }
            }
        }
Exemplo n.º 12
0
        private void UpdateGrantTable(UserClassTemplate uct)
        {
            for (int i = 0; i < dataGridViewGrant.RowCount; i++)
            {
                //dataGridViewGrant.Rows[i].Cells["Master"].Value = false;
                dataGridViewGrant.Rows[i].Cells["DoorGranted"].Value = 0;
            }
            if (uct == null)
            {
                return;
            }

            /*
             * string[] allowedSerialMaster = db.recoverUserGrant(uct);
             * if (allowedSerialMaster == null) return;
             * foreach (string serial in allowedSerialMaster)
             * {
             *  for (int i = 0; i < dataGridViewGrant.RowCount; i++)
             *  {
             *      if (dataGridViewGrant.Rows[i].Cells["Device Serial"].Value.Equals(serial))
             *      {
             *          dataGridViewGrant.Rows[i].Cells["Master"].Value = true;
             *          break;
             *      }
             *  }
             * } */

            DeviceGrant[] allowedSerialMaster = _db.recoverUserGrantFull(uct);
            if (allowedSerialMaster == null)
            {
                return;
            }

            foreach (DeviceGrant dg in allowedSerialMaster)
            {
                for (int i = 0; i < dataGridViewGrant.RowCount; i++)
                {
                    if (dataGridViewGrant.Rows[i].Cells["Device Serial"].Value.Equals(dg.serialRFID))
                    {
                        dataGridViewGrant.Rows[i].Cells["DoorGranted"].Value = (int)dg.userGrant;
                        break;
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void Reset()
        {
            _bSaved                   = true;
            _bComeFromListBox         = false;
            listBoxUser.SelectedIndex = -1;
            listBoxUser.Enabled       = true;
            groupBoxUserCtrl.Enabled  = false;
            _userInEnroll             = new UserClassTemplate();
            textBoxFirstName.Text     = null;
            textBoxLastName.Text      = null;
            toolStripButtonEnrollFingerprint.Enabled = false;
            gpBx.Enabled = false;
            toolStripButtonDelete.Enabled = false;
            toolStripButtonApply.Enabled  = false;
            textBoxFirstName.ReadOnly     = false;
            textBoxLastName.ReadOnly      = false;
            textBoxReaderCard.Text        = null;
            textBoxRemoveItem.Text        = null;
            textBoxRemoveValue.Text       = null;
            comboBoxFinger.SelectedIndex  = 0;

            UpdateGridFinger();
        }
Exemplo n.º 14
0
        private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            switch (rdType)
            {
            case AccessBagerReaderType.RT_HF:

                while (true)
                {
                    inboundBuffer += serialPort.ReadExisting();
                    int frameEnd = inboundBuffer.IndexOf(CHAR_EndOfFrameHF, 0);
                    if (frameEnd < 0)
                    {
                        break;
                    }
                    // A full message is available.
                    string message = inboundBuffer.Substring(0, frameEnd - 2);
                    inboundBuffer = inboundBuffer.Substring(frameEnd + 1);
                    strBadgeRead  = message.Substring(0, 10);
                    if ((listeBadge.Contains(strBadgeRead)) || bNotifyAll)
                    {
                        if (NotifyBadgeReaderEvent != null)
                        {
                            NotifyBadgeReaderEvent(this, strBadgeRead, deviceSerial);
                        }

                        // new event type, for badge readers integrated to class "RFID_Device".
                        if (_userTemplates != null)     // users have been loaded
                        {
                            UserClassTemplate currentUser = GetUserTemplateByBadgeId(strBadgeRead);

                            if (currentUser != null)     // corresponding user has been found
                            {
                                BadgeReaderArgs brEventArgs = new BadgeReaderArgs(deviceSerial, currentUser,
                                                                                  AccessBagerReaderType.RT_HF);
                                NotifyEvent(this, brEventArgs);
                            }
                        }
                    }
                }

                break;

            case AccessBagerReaderType.RT_LF:
                while (true)
                {
                    inboundBuffer += serialPort.ReadExisting();
                    int length     = inboundBuffer.Length;
                    int frameStart = inboundBuffer.IndexOf(CHAR_StartOfFrameLF);
                    if (frameStart != 0)
                    {
                        if (frameStart < 0)
                        {
                            inboundBuffer = "";
                            break;
                        }
                        inboundBuffer = inboundBuffer.Substring(frameStart);
                        frameStart    = 0;
                    }

                    int frameEnd = inboundBuffer.IndexOf(CHAR_EndOfFrameLF, 0);
                    if (frameEnd < 0)
                    {
                        break;
                    }

                    // A full message is available.
                    string message = inboundBuffer.Substring(1, frameEnd - 1);
                    inboundBuffer = inboundBuffer.Substring(frameEnd + 1);

                    strBadgeRead = message.Substring(0, 12);
                    if ((listeBadge.Contains(strBadgeRead)) || bNotifyAll)
                    {
                        if (NotifyBadgeReaderEvent != null)
                        {
                            NotifyBadgeReaderEvent(this, strBadgeRead, deviceSerial);
                        }

                        // new event type, for badge readers integrated to class "RFID_Device".
                        if (_userTemplates != null)     // users have been loaded
                        {
                            UserClassTemplate currentUser = GetUserTemplateByBadgeId(strBadgeRead);

                            if (currentUser != null)     // corresponding user has been found
                            {
                                BadgeReaderArgs brEventArgs = new BadgeReaderArgs(deviceSerial, currentUser,
                                                                                  AccessBagerReaderType.RT_LF);
                                NotifyEvent(this, brEventArgs);
                            }
                        }
                    }
                }
                break;
            }
        }
        private static void createAndSendMail(alertInfo alert, smtpInfo smtp, DeviceInfo device, UserClassTemplate utc, string spareData)
        {
            bool mailcreated = false;
            //create the mail message
            MailMessage mail     = null;
            string      mailbody = null;

            mailcreated = true;
            mail        = new MailMessage();
            //set the addresses
            mail.From = new MailAddress(smtp.sender);

            string[] recpt = alert.RecipientList.Split(';');
            foreach (string str in recpt)
            {
                mail.To.Add(str.Trim());
            }
            if (!string.IsNullOrEmpty(alert.BCCRecipientList))
            {
                string[] bcc = alert.BCCRecipientList.Split(';');
                foreach (string str in bcc)
                {
                    mail.Bcc.Add(str.Trim());
                }
            }
            if (!string.IsNullOrEmpty(alert.CCRecipientList))
            {
                string[] cc = alert.CCRecipientList.Split(';');
                foreach (string str in cc)
                {
                    mail.CC.Add(str.Trim());
                }
            }

            /* mail.Subject = alert.MailSubject + " " + device.DeviceName + " [S/N:" + device.SerialRFID + "]";
             * mailbody = string.Empty;
             *
             * mailbody += "Alert type : <B>" + alert.AlertMessage + "</B><br />";
             * mailbody += "Alert date : <B>" + DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString() + "</B><br />";
             * mailbody += "Alert on device : <B>" + device.DeviceName + " [s/n: " + device.SerialRFID + "]" + "</B><br />";
             *
             * switch (alert.type)
             * {
             *   case AlertType.AT_Door_Open_Too_Long:
             *   case AlertType.AT_Finger_Alert:
             *       mailbody += "Alert generated  by user : <B>" + utc.firstName + " " + utc.lastName + "</B><br />";
             *       break;
             *   case AlertType.AT_Remove_Too_Many_Items:
             *   case AlertType.AT_Limit_Value_Exceed:
             *       mailbody += "Alert generated  by user : <B>" + utc.firstName + " " + utc.lastName + "</B><br />";
             *       mailbody += "User removed <B>" + spareData + "</B><br />";
             *       break;
             * }     */

            string subject = alert.MailSubject;

            subject = subject.Replace("\n", "<br/>");
            if (device != null)
            {
                subject = subject.Replace("[READERNAME]", device.DeviceName);
                subject = subject.Replace("[READERSERIAL]", device.SerialRFID);
            }
            if (utc != null)
            {
                subject = subject.Replace("[USERNAME]", utc.firstName + " " + utc.lastName);
            }
            subject      = subject.Replace("[DATE]", DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString());
            mail.Subject = subject;

            string body = alert.AlertMessage;

            body = body.Replace("\n", "<br/>");
            if (device != null)
            {
                body = body.Replace("[READERNAME]", device.DeviceName);
                body = body.Replace("[READERSERIAL]", device.SerialRFID);
            }
            if (utc != null)
            {
                body = body.Replace("[USERNAME]", utc.firstName + " " + utc.lastName);
            }

            body  = body.Replace("[DATE]", DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString());
            body += "<br />";
            switch (alert.type)
            {
            case AlertType.AT_Remove_Too_Many_Items:
            case AlertType.AT_Limit_Value_Exceed:

                body += "<br />User removed " + spareData + "<br />";
                break;

            case  AlertType.AT_Max_Fridge_Temp:

                body += "<br />" + spareData + "<br />";
                break;

            case AlertType.AT_Remove_Tag_Max_Time:

                string[] dt = spareData.Split(';');

                if (dt != null)
                {
                    int nbTag = dt.Length - 1;
                    body += "<br />All the following " + nbTag + " tag(s) have been removed from device than more " + dt[0] + " Minutes<br />";

                    for (int i = 1; i < dt.Length; i++)
                    {
                        body += " <br /> " + dt[i];
                    }
                }
                break;

            case AlertType.AT_Stock_Limit:

                string[] spData = spareData.Split(';');
                if (spData != null)
                {
                    for (int i = 0; i < spData.Length; i += 2)
                    {
                        body += "<br />Product " + spData[i] + " reach low stock limit : " + spData[i + 1] + " Left";
                    }
                }
                break;

            case AlertType.AT_DLC_Expired:

                /* string[] dt2 = spareData.Split(';');
                 *
                 * if (dt2!= null)
                 * {
                 *   int nbTag = dt2.Length - 1;
                 *   body += "<br />All the following " + nbTag + " product(s) have overtake their date of use<br />";
                 *
                 * for (int i = 1; i < dt2.Length; i++)
                 *   body += " <br /> " + dt2[i];
                 * }
                 */
                break;

            case AlertType.AT_Bad_Blood_Patient:
                string[] dt3 = spareData.Split(';');

                if (dt3 != null)
                {
                    string patient = dt3[0];
                    body += "<br />The following blood bags removed are not for patient " + patient + "<br />";

                    for (int i = 1; i < dt3.Length; i++)
                    {
                        body += " <br /> " + dt3[i];
                    }
                }


                break;
            }
            mailbody = body;

            /*Attachment data = new Attachment(path);
             * mail.Attachments.Add(data);*/

            if (mailcreated)
            {
                //first we create the Plain Text part
                AlternateView plainView = AlternateView.CreateAlternateViewFromString(mailbody, null, "text/plain");

                //then we create the Html part
                //to embed images, we need to use the prefix 'cid' in the img src value
                //the cid value will map to the Content-Id of a Linked resource.
                //thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
                AlternateView htmlView;

                htmlView = AlternateView.CreateAlternateViewFromString(mailbody + "<br />", null, "text/html");

                //add the views
                mail.AlternateViews.Add(plainView);
                mail.AlternateViews.Add(htmlView);


                //send the message
                SmtpClient SmtpServer = new SmtpClient(smtp.smtp);
                SmtpServer.Port = smtp.port;
                if (smtp.bUseSSL)
                {
                    SmtpServer.EnableSsl = true;
                }
                SmtpServer.Credentials = new System.Net.NetworkCredential(smtp.login, smtp.pwd);
                SmtpServer.Send(mail);
            }
        }
        public static void treatAlert(AlertType alertType, DeviceInfo device, UserClassTemplate utc, InventoryData inv, string spareData, bool bShowWindowBox)
        {
            switch (alertType)
            {
            case AlertType.AT_Power_Cut:
                InputData input = new InputData(AlertType.AT_Power_Cut, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatPowerCut), input);
                break;

            case AlertType.AT_Usb_Unplug:
                InputData input2 = new InputData(AlertType.AT_Usb_Unplug, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatUsbUnplug), input2);

                break;

            case AlertType.AT_Door_Open_Too_Long:
                InputData input3 = new InputData(AlertType.AT_Door_Open_Too_Long, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatDoorOpenTooLong), input3);
                break;

            case AlertType.AT_Finger_Alert:
                InputData input4 = new InputData(AlertType.AT_Finger_Alert, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatFingerAlert), input4);
                break;

            case AlertType.AT_Remove_Too_Many_Items:
                InputData input5 = new InputData(AlertType.AT_Remove_Too_Many_Items, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatItemRemoved), input5);
                break;

            case AlertType.AT_Limit_Value_Exceed:
                InputData input6 = new InputData(AlertType.AT_Limit_Value_Exceed, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatValueRemoved), input6);
                break;

            case AlertType.AT_Move_Sensor:
                InputData input7 = new InputData(AlertType.AT_Move_Sensor, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatMoveSensor), input7);
                break;

            case AlertType.AT_Max_Fridge_Temp:
                InputData input8 = new InputData(AlertType.AT_Max_Fridge_Temp, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatMaxFridgeTemp), input8);
                break;

            case AlertType.AT_Remove_Tag_Max_Time:
                InputData input9 = new InputData(AlertType.AT_Max_Fridge_Temp, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatMaxTimeTagRemoved), input9);
                break;

            case AlertType.AT_Stock_Limit:
                InputData input10 = new InputData(AlertType.AT_Stock_Limit, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatStockLimit), input10);
                break;

            case AlertType.AT_DLC_Expired:
                InputData input11 = new InputData(AlertType.AT_DLC_Expired, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatDLCExpired), input11);
                break;

            case AlertType.AT_Bad_Blood_Patient:
                InputData input12 = new InputData(AlertType.AT_Bad_Blood_Patient, device, utc, spareData, bShowWindowBox);
                ThreadPool.QueueUserWorkItem(new WaitCallback(treatBadBloodPatient), input12);
                break;
            }
        }