Explorar o código

Предрелиз формы охранника

Вячеслав Терешенко %!s(int64=2) %!d(string=hai) anos
pai
achega
7905d36e3a

+ 27 - 26
ImpulseVision/FormGuard.Designer.cs

@@ -51,12 +51,12 @@
             this.BtnReject = new System.Windows.Forms.Button();
             this.PbxSourceImage = new System.Windows.Forms.PictureBox();
             this.DgbInput = new System.Windows.Forms.DataGridView();
+            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.RPanelForButton = new ImpulseVision.RPanel();
             this.DgbOutput = new System.Windows.Forms.DataGridView();
+            this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.SplitContainer = new System.Windows.Forms.SplitContainer();
             this.SplitContainerForPbxEtherAndDgb = new System.Windows.Forms.SplitContainer();
-            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.rPanel1 = new ImpulseVision.RPanel();
             this.rPanel2 = new ImpulseVision.RPanel();
             ((System.ComponentModel.ISupportInitialize)(this.PbxEther)).BeginInit();
@@ -230,11 +230,12 @@
             this.BtnReject.TabIndex = 21;
             this.BtnReject.Text = "Отклонить";
             this.BtnReject.UseVisualStyleBackColor = false;
+            this.BtnReject.Click += new System.EventHandler(this.BtnReject_Click);
             // 
             // PbxSourceImage
             // 
             this.PbxSourceImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.PbxSourceImage.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(255)))), ((int)(((byte)(252)))));
+            this.PbxSourceImage.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
             this.PbxSourceImage.Location = new System.Drawing.Point(430, 0);
             this.PbxSourceImage.Name = "PbxSourceImage";
             this.PbxSourceImage.Size = new System.Drawing.Size(100, 90);
@@ -267,6 +268,17 @@
             this.DgbInput.Size = new System.Drawing.Size(201, 155);
             this.DgbInput.TabIndex = 15;
             // 
+            // Column1
+            // 
+            this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter;
+            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
+            this.Column1.HeaderText = "Вход";
+            this.Column1.Name = "Column1";
+            this.Column1.ReadOnly = true;
+            this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
+            // 
             // RPanelForButton
             // 
             this.RPanelForButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
@@ -313,7 +325,7 @@
             this.DgbOutput.Name = "DgbOutput";
             this.DgbOutput.ReadOnly = true;
             this.DgbOutput.RowHeadersVisible = false;
-            this.DgbOutput.RowTemplate.DefaultCellStyle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(229)))), ((int)(((byte)(233)))));
+            this.DgbOutput.RowTemplate.DefaultCellStyle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(104)))), ((int)(((byte)(112)))));
             this.DgbOutput.RowTemplate.DefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(229)))), ((int)(((byte)(233)))));
             this.DgbOutput.RowTemplate.DefaultCellStyle.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(43)))));
             this.DgbOutput.RowTemplate.Height = 25;
@@ -322,6 +334,17 @@
             this.DgbOutput.TabIndex = 15;
             this.DgbOutput.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DgbOutput_CellContentClick);
             // 
+            // dataGridViewTextBoxColumn1
+            // 
+            this.dataGridViewTextBoxColumn1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter;
+            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle2;
+            this.dataGridViewTextBoxColumn1.HeaderText = "Выход";
+            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
+            this.dataGridViewTextBoxColumn1.ReadOnly = true;
+            this.dataGridViewTextBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
+            // 
             // SplitContainer
             // 
             this.SplitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -360,28 +383,6 @@
             this.SplitContainerForPbxEtherAndDgb.SplitterDistance = 530;
             this.SplitContainerForPbxEtherAndDgb.TabIndex = 25;
             // 
-            // Column1
-            // 
-            this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
-            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter;
-            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
-            this.Column1.HeaderText = "Вход";
-            this.Column1.Name = "Column1";
-            this.Column1.ReadOnly = true;
-            this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
-            // 
-            // dataGridViewTextBoxColumn1
-            // 
-            this.dataGridViewTextBoxColumn1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
-            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter;
-            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle2;
-            this.dataGridViewTextBoxColumn1.HeaderText = "Выход";
-            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
-            this.dataGridViewTextBoxColumn1.ReadOnly = true;
-            this.dataGridViewTextBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
-            // 
             // rPanel1
             // 
             this.rPanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(185)))), ((int)(((byte)(187)))), ((int)(((byte)(210)))));

+ 65 - 9
ImpulseVision/FormGuard.cs

@@ -65,7 +65,7 @@ namespace ImpulseVision
 
         public struct VisitInput
         {
-            public string FIO, TimeEntrance, TimeExit;
+            public string FIO, TimeEntrance, TimeExit, Identification;
         }
         List<VisitInput> LstVisitInput = new List<VisitInput>();
 
@@ -696,9 +696,16 @@ namespace ImpulseVision
         /// <summary>
         /// добавление в БД информации о входе
         /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
         private void BtnSkip_Click(object sender, EventArgs e)
+        {
+            RegisterVisit(1);
+            GetVisits();
+        }
+        /// <summary>
+        /// регистрация посещения
+        /// </summary>
+        /// <param name="IsIdentification">успешность идентификации (1-успешно, 0- нет)</param>
+        private void RegisterVisit(int IsIdentification)
         {
             if (!IsRecognized)
             {
@@ -708,9 +715,30 @@ namespace ImpulseVision
 
             if (RbtIn.Checked)
             {
+                if (IsIdentification == 1)
+                {
+                    #region Предупреждение при попытке повторной идентификации пользователя за один день
+                    SCon.Open();
+                    string QueryCheckExistsVisit = $@"select Count(ID) as Cnt
+from UserTraffic
+where UserID = '{CurrentUserID}' and [Date] = CAST(GETDATE() as date)";
+                    SqlCommand CmdCheckVisit = new SqlCommand(QueryCheckExistsVisit, SCon);
+                    SqlDataReader Res = CmdCheckVisit.ExecuteReader();
+                    Res.Read();
+                    int n = int.Parse(Res["Cnt"].ToString());
+                    if (n >= 1)
+                    {
+                        MessageBox.Show("Сегодня данный пользователь уже прошёл идентификацию при входе!", "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+                        SCon.Close();
+                        return;
+                    }
+                    SCon.Close();
+                    #endregion
+                }
+
                 SCon.Open();
                 string QueryAddVisit = $@"set dateformat dmy insert into UserTraffic (UserID,TimeEntrance,Identification,[Date])
-values ('{CurrentUserID}','{DateTime.Now.ToString("HH:mm:ss")}','1','{DateTime.Now.ToString("dd.MM.yyyy")}')";
+values ('{CurrentUserID}','{DateTime.Now.ToString("HH:mm:ss")}','{IsIdentification}','{DateTime.Now.ToString("dd.MM.yyyy")}')";
                 SqlCommand Cmd = new SqlCommand(QueryAddVisit, SCon);
                 Cmd.ExecuteNonQuery();
                 SCon.Close();
@@ -725,23 +753,22 @@ where UserID = '{CurrentUserID}' and [Date] = cast(GETDATE() as date) and TimeEx
 ";
                 SqlCommand CmdCheck = new SqlCommand(QueryCheckRecord, SCon);
                 SqlDataReader Res = CmdCheck.ExecuteReader();
-                if(!Res.HasRows)
+                if (!Res.HasRows)
                 {
                     MessageBox.Show("Нельзя отметить выход пользователя, если он ещё не входил!", "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     SCon.Close();
                     return;
                 }
                 SCon.Close();
-
+                //!!! Выход пользователя, который не прошёл идентификацию не регистрируется
                 SCon.Open();
                 string QueryTimeExit = $@"update UserTraffic
 set TimeExit = '{DateTime.Now.ToString("HH:mm:ss")}'
-where UserID = '{CurrentUserID}' and [Date] = cast(GETDATE() as date)";
+where UserID = '{CurrentUserID}' and [Date] = cast(GETDATE() as date) ";
                 SqlCommand Cmd = new SqlCommand(QueryTimeExit, SCon);
                 Cmd.ExecuteNonQuery();
                 SCon.Close();
             }
-            GetVisits();
         }
         /// <summary>
         /// получение списка посещений за текущую дату
@@ -749,7 +776,7 @@ where UserID = '{CurrentUserID}' and [Date] = cast(GETDATE() as date)";
         private void GetVisits()
         {
             SCon.Open();
-            string QueryGetVisits = $@"select Users.Lastname+' '+Users.Firstname + ' ' + Users.Patronymic as FIO, TimeEntrance,TimeExit
+            string QueryGetVisits = $@"select Users.Lastname+' '+Users.Firstname + ' ' + Users.Patronymic as FIO, TimeEntrance,TimeExit, Identification
 from UserTraffic ut join Users on ut.UserID = Users.ID
 where ut.[Date] = cast(GETDATE() as date)";
 
@@ -764,6 +791,7 @@ where ut.[Date] = cast(GETDATE() as date)";
                     visit.FIO = Res["FIO"].ToString();
                     visit.TimeEntrance = Res["TimeEntrance"].ToString();
                     visit.TimeExit = Res["TimeExit"].ToString();
+                    visit.Identification = Res["Identification"].ToString();
                     LstVisitInput.Add(visit);
                 }
             }
@@ -773,6 +801,11 @@ where ut.[Date] = cast(GETDATE() as date)";
             foreach (VisitInput item in LstVisitInput)
             {
                 DgbInput.Rows.Add(item.FIO + $"  {item.TimeEntrance}");
+                if (item.Identification.ToLower() == "false")
+                {
+                    DgbInput.Rows[DgbInput.RowCount - 1].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#E84855");
+                    DgbInput.Rows[DgbInput.RowCount - 1].DefaultCellStyle.ForeColor = Color.White;
+                }
             }
             DgbOutput.Rows.Clear();
             string STime = string.Empty;
@@ -782,8 +815,31 @@ where ut.[Date] = cast(GETDATE() as date)";
                 if (STime != string.Empty)
                 {
                     DgbOutput.Rows.Add(item.FIO + $"  {STime}");
+                    if (item.Identification.ToLower() == "false")
+                    {
+                        DgbInput.Rows[DgbInput.RowCount - 1].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#E84855");
+                        DgbInput.Rows[DgbInput.RowCount - 1].DefaultCellStyle.ForeColor = Color.White;
+
+                    }
                 }
+
+            }
+        }
+
+        private void BtnReject_Click(object sender, EventArgs e)
+        {
+            RegisterVisit(0);
+            try
+            {
+                Image<Bgr, byte> Img = BgrFrame.Copy();
+                string PathLog = Application.StartupPath + $"\\Source\\log\\{"User_" + CurrentUserID + "_" + DateTime.Now.ToString("HHmmss") + "_" + DateTime.Now.ToString("dd.MM.yyyy") + "_" + Guid.NewGuid().ToString().Substring(0, 4)}.bmp";
+                Img.Save(PathLog);
             }
+            catch(Exception ex) 
+            {
+                MessageBox.Show(ex.Message, "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            GetVisits();
         }
     }
 }

BIN=BIN
ImpulseVision/bin/Debug/ImpulseVision.exe


+ 0 - 0
ImpulseVision/bin/Debug/Source/FaceList.txt