Exemplo n.º 1
0
 private void SimpleDatabaseEditor_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (pnlmon != null)
     {
         pnlmon.Stop();
         pnlmon.presented -= pnlmon_CardPresented;
         pnlmon            = null;
     }
 }
Exemplo n.º 2
0
        public PanelMonitorForm(PanelMonitor pnlmon)
        {
            InitializeComponent();

            this.pnlmon = pnlmon;
        }
Exemplo n.º 3
0
        private void panelConnectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //panel connection option

            if (pnlmon != null)
            {
                pnlmon.Stop();
                pnlmon.presented -= pnlmon_CardPresented;

                ConnectionPropertiesEditor connproped = pnlconnprop == null ? new ConnectionPropertiesEditor() : new ConnectionPropertiesEditor(pnlconnprop);
                if (connproped.ShowDialog(this) == DialogResult.OK)
                {
                    ConnectionProperties new_pnlconnprop = connproped.ConnectionProperties;
                    PanelMonitor         new_pnlmon      = null;
                    try
                    {
                        new_pnlmon            = new PanelMonitor(new_pnlconnprop);
                        new_pnlmon.presented += pnlmon_CardPresented;
                        new_pnlmon.Start();
                    }
                    catch (Exception ex)
                    {
                        if (new_pnlmon != null)
                        {
                            try
                            {
                                new_pnlmon.Stop();
                                new_pnlmon.presented -= pnlmon_CardPresented;
                            }
                            catch (Exception ex2) { }
                        }

                        MessageBox.Show(this, "Error connecting to panel. The settings have been reverted.");

                        pnlmon.presented += pnlmon_CardPresented;
                        pnlmon.Start();
                    }

                    pnlconnprop = new_pnlconnprop;
                    pnlmon      = new_pnlmon;
                }
                else
                {
                    pnlmon.presented += pnlmon_CardPresented;
                    pnlmon.Start();
                }

                connproped.Dispose();
            }
            else
            {
                ConnectionPropertiesEditor connproped = new ConnectionPropertiesEditor();
                if (connproped.ShowDialog(this) == DialogResult.OK)
                {
                    ConnectionProperties new_pnlconnprop = connproped.ConnectionProperties;
                    PanelMonitor         new_pnlmon      = null;
                    try
                    {
                        new_pnlmon            = new PanelMonitor(new_pnlconnprop);
                        new_pnlmon.presented += pnlmon_CardPresented;
                        new_pnlmon.Start();
                    }
                    catch (Exception ex)
                    {
                        if (new_pnlmon != null)
                        {
                            try
                            {
                                new_pnlmon.Stop();
                                new_pnlmon.presented -= pnlmon_CardPresented;
                            }
                            catch (Exception ex2) { }
                        }

                        MessageBox.Show(this, "Error connecting to panel.");
                    }

                    pnlconnprop = new_pnlconnprop;
                    pnlmon      = new_pnlmon;
                }
            }

            RefreshFormTitle();
        }
Exemplo n.º 4
0
        private void NewCardPresented(PanelMonitor pnlmon, PanelEventArgs pnlevargs)
        {
            try
            {
                using (MySqlConnection sqlconn = new MySqlConnection(dbconnprop.ConnectionString))
                {
                    sqlconn.Open();

                    //lookup
                    using (MySqlCommand cmdName = new MySqlCommand("select data from `" + table_name + "` where uid=" + pnlevargs.PanelState.Card.UID, sqlconn))
                        using (MySqlDataReader reader = cmdName.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (reader[0] != DBNull.Value)
                                {
                                    byte[] bytes = (byte[])reader["data"];

                                    AccessProperties accessprop;
                                    using (MemoryStream ms = new MemoryStream())
                                    {
                                        ms.Write(bytes, 0, bytes.Length);
                                        ms.Position = 0;
                                        accessprop  = (AccessProperties)bf.Deserialize(ms);
                                    }

                                    //add to processing queue
                                    if (!accessprop.ForceDisable)
                                    {
                                        if (accessprop.EnabledFrom <= DateTime.Now || accessprop.ForceEnable)
                                        {
                                            if (accessprop.EnabledTo >= DateTime.Now || accessprop.ForceEnable)
                                            {
                                                //card is active; continue verifying

                                                List <ExpanderModificationProperties> temp = accessprop.ProcessActivations();
                                                int associated_car = pnlmon.AssociatedCar;

                                                if (temp.Count > 0)
                                                {
                                                    pnlmon.AnimateLED(PanelCommand.ANIMATION_APPROVAL);

                                                    PanelMonitor      monitor = pnlmon;
                                                    AccessControlCard card    = pnlevargs.PanelState.Card;

                                                    Task.Run(delegate()
                                                    {
                                                        AccessControlLogManager.AddAccessControlLogEntry(card.UID, new AccessControlLogEntry(DateTime.Now, "User Approved Entry", card,
                                                                                                                                             expmon.ToString(), monitor.ToString()));
                                                    });
                                                }
                                                else
                                                {
                                                    pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);

                                                    PanelMonitor      monitor = pnlmon;
                                                    AccessControlCard card    = pnlevargs.PanelState.Card;

                                                    Task.Run(delegate()
                                                    {
                                                        AccessControlLogManager.AddAccessControlLogEntry(card.UID, new AccessControlLogEntry(DateTime.Now, "User Declined Entry", card,
                                                                                                                                             expmon.ToString(), monitor.ToString()));
                                                    });
                                                }

                                                foreach (ExpanderModificationProperties expmodprop in temp)
                                                {
                                                    expmodprop.AssociatedCar = associated_car;
                                                    expmodprops.Add(expmodprop);
                                                }
                                            }
                                            else
                                            {
                                                pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                            }
                                        }
                                        else
                                        {
                                            pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                        }
                                    }
                                    else
                                    {
                                        pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                    }
                                }
                            }
                            else
                            {
                                pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                            }
                        }
                }
            }
            catch (MySqlException mysqlex)
            {
                ErrorLogManager.AppendLog("AltMonitor - MySqlException Occured During Card Lookup", true);
            }
            catch (Exception ex)
            {
                ErrorLogManager.AppendLog("AltMonitor - General Error Occured During Card Lookup", true);
            }
        }