コード例 #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     textBox1.Enabled  = false;
     textBox2.Enabled  = false;
     textBox3.Enabled  = false;
     comboBox2.Enabled = false;
     if (!string.IsNullOrWhiteSpace(textBox1.Text) && !string.IsNullOrWhiteSpace(textBox2.Text) &&
         !string.IsNullOrWhiteSpace(textBox3.Text))
     {
         try
         {
             using (var context = new FRModel())
             {
                 var genreId = Convert.ToInt32(comboBox2.SelectedValue);
                 var gender  = context.Genders.Single(g => g.Id == genreId);
                 var visitor = new Visitor
                 {
                     Name    = textBox1.Text,
                     Surname = textBox2.Text,
                     CardId  = textBox3.Text,
                     Gender  = gender
                 };
                 context.Visitors.Add(visitor);
                 context.SaveChanges();
             }
         }
         catch (SqlException)
         {
             MessageBox.Show(@"Failed saving a visitor. Check your connection or try again.", @"Error",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show(@"You need to enter obligatory fields in order to add a visitor.", @"Warning",
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     textBox1.Enabled  = true;
     textBox2.Enabled  = true;
     textBox3.Enabled  = true;
     comboBox2.Enabled = true;
     textBox1.Text     = "";
     textBox2.Text     = "";
     textBox3.Text     = "";
 }
コード例 #2
0
        public void Displayer()
        {
            var result = RecognizedLabels.GroupBy(x => x)
                         .ToDictionary(y => y.Key, y => y.Count())
                         .OrderByDescending(z => z.Value);

            foreach (var x in result)
            {
                if (x.Value < 3)
                {
                    continue;
                }
                using (var context = new FRModel())
                {
                    var    person = context.Users.First(u => u.PersonalNumber == x.Key);
                    Bitmap bmp;
                    using (var stream = new MemoryStream(person.Avatar))
                    {
                        bmp = new Bitmap(stream);
                    }
                    var resizedBmp = new Bitmap(bmp, new Size(64, 64));
                    var employee   = new Employee(person.PersonalNumber)
                    {
                        LabelText = $"{person.Name} {person.Surname}",
                        Image     = resizedBmp
                    };
                    flowLayoutPanel1.Controls.Add(employee);
                    var entrance = new EntranceRegister
                    {
                        Time   = DateTime.Now,
                        UserId = x.Key
                    };
                    context.EntranceRegisters.Add(entrance);
                    context.SaveChanges();
                }
            }
            RecognizedLabels.Clear();
        }
コード例 #3
0
ファイル: AddUser.cs プロジェクト: nainauy/FRDesktop
        private void button2_Click(object sender, EventArgs e)
        {
            var numbers = new List <int>();

            using (var con = new FRModel())
            {
                var users = con.Users.ToList();
                numbers.AddRange(users.Select(user => user.PersonalNumber));
            }
            textBox1.Enabled    = false;
            textBox2.Enabled    = false;
            textBox3.Enabled    = false;
            comboBox1.Enabled   = false;
            comboBox2.Enabled   = false;
            pictureBox6.Enabled = false;
            if (GrayFaces.Count < 12)
            {
                MessageBox.Show(@"Please wait until the data set is ready", @"Wait a bit",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(textBox1.Text) && !string.IsNullOrWhiteSpace(textBox2.Text) &&
                    !string.IsNullOrWhiteSpace(textBox3.Text) && Avatar != null)
                {
                    var exist = false;
                    foreach (var number in numbers)
                    {
                        if (number == Convert.ToInt32(textBox3.Text))
                        {
                            exist = true;
                        }
                    }
                    if (!exist)
                    {
                        try
                        {
                            using (var context = new FRModel())
                            {
                                var genreId        = Convert.ToInt32(comboBox2.SelectedValue);
                                var sectorId       = Convert.ToInt32(comboBox1.SelectedValue);
                                var personalNumber = Convert.ToInt32(textBox3.Text);
                                var gender         = context.Genders.Single(g => g.Id == genreId);
                                var sector         = context.Sectors.Single(s => s.Id == sectorId);
                                var user           = new User
                                {
                                    Name           = textBox1.Text,
                                    Surname        = textBox2.Text,
                                    PersonalNumber = personalNumber,
                                    Gender         = gender,
                                    Sector         = sector,
                                    Avatar         = Avatar
                                };
                                context.Users.Add(user);
                                context.SaveChanges();
                                foreach (var grayFace in GrayFaces)
                                {
                                    var converter = new ImageConverter();
                                    var image     = (byte[])converter.ConvertTo(grayFace.ToBitmap(), typeof(byte[]));
                                    context.Images.Add(new Image
                                    {
                                        Face   = image,
                                        UserId = Convert.ToInt32(textBox3.Text)
                                    });
                                    context.SaveChanges();
                                }
                            }
                        }
                        catch (SqlException)
                        {
                            MessageBox.Show(@"Failed saving a user. Check your connection or try again.", @"Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        var recognizer = new RecognizerEngine("C:\\FRClient\\TrainingData.yaml");
                        recognizer.TrainRecognizer();
                    }
                    else
                    {
                        MessageBox.Show(@"User with the same personal number already exists.", @"Warning",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show(@"You need to enter obligatory fields in order to add a user.", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            textBox1.Enabled    = true;
            textBox2.Enabled    = true;
            textBox3.Enabled    = true;
            comboBox1.Enabled   = true;
            comboBox2.Enabled   = true;
            pictureBox6.Enabled = true;
            textBox1.Text       = "";
            textBox2.Text       = "";
            textBox3.Text       = "";
            GrayFaces.Clear();
        }