Ejemplo n.º 1
0
        private void buttonFind_Click(object sender, EventArgs e)
        {
            listBoxResultFound.Items.Clear();
            using (var db = new UsersData())
            {

                var subQuerry1 = (from c in db.Certificates
                                where c.Name==listBoxCertificateFound.Text
                                select c.ID).ToList()[0];

                var subQuerry2 = (from r in db.Relations
                                  where r.CertificateID == subQuerry1
                                  select r.UserID).ToList();
                if (subQuerry2.Count == 0)
                {
                    MessageBox.Show("Працівників з таким сертифікатом не знайдено.");
                }
                else
                {
                    for (int i = 0; i < subQuerry2.Count; i++)
                    {
                        var temp = subQuerry2[i];
                        var query = from u in db.Users
                                    where u.ID == temp
                                    select u.Name;

                        foreach (var item2 in query)
                        {
                            this.listBoxResultFound.Items.Add(item2);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void AddCertificates()
 {
     string line = "";
     using (var database = new UsersData())
     {
         StreamReader reader = new StreamReader(@"c:\users\mykola\documents\visual studio 2012\Projects\Task4\Task4\in.txt");
         while ((line = reader.ReadLine()) != null)
         {
             Certificate certificate = new Certificate { Name = line };
             database.Certificates.Add(certificate);
             database.SaveChanges();
         }
         reader.Close();
     }
 }
Ejemplo n.º 3
0
 public Form2()
 {
     InitializeComponent();
     using (var db = new UsersData())
     {
         var query = from c in db.Certificates
                     select c.Name;
         foreach (var item in query)
         {
             listBoxCertificateFound.Items.Add(item);
         }
         listBoxCertificateFound.Width = 80;
         listBoxCertificateFound.Height = 80;
         listBoxResultFound.Width = 80;
         listBoxResultFound.Height = 80;
     }
 }
Ejemplo n.º 4
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            using (var db = new UsersData())
            {
                for (int i = 0; i < amount; i++)
                {
                    var user = new User { Name = this.dataGridViewUsersInfo.Rows[i].Cells[0].Value.ToString(), Post = this.dataGridViewUsersInfo.Rows[i].Cells[1].Value.ToString() };
                    db.Users.Add(user);
                    db.SaveChanges();
                    string[] arr = this.dataGridViewUsersInfo.Rows[i].Cells[2].Value.ToString().Split(new char[] {' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

                    for (int j = 0; j < arr.Length; j++)
                    {
                        var temp = arr[j];
                        var query = (from c in db.Certificates
                                    where c.Name == temp
                                    select c.ID).ToList()[0];

                        var relation = new Relation { UserID = user.ID, CertificateID = query};
                        db.Relations.Add(relation);
                        db.SaveChanges();
                    }
                }
            }
            this.dataGridViewUsersInfo.Rows.Clear();
            this.dataGridViewUsersInfo.Columns.Clear();
            DataGridInit();
        }
Ejemplo n.º 5
0
        private void textBoxCertificate_TextChanged(object sender, EventArgs e)
        {
            if (this.textBoxCertificate.Text != string.Empty)
            {
                for (int i = 0; i < listListsBox.Count; i++)
                {
                    this.Controls.Remove(listListsBox[i]);
                }
                listListsBox.Clear();

                int x = 20;
                int y = 200;
                int inter = 0;
                for (int i = 0; i < Convert.ToInt32(this.textBoxCertificate.Text); i++)
                {
                    ListBox newListBox = new ListBox();

                    if (inter == 5)
                    {
                        y += 80;
                        x = 20;
                        inter = 0;
                    }
                    newListBox.Location = new Point(x + inter * 150, y);
                    inter++;
                    using (var db = new UsersData())
                    {
                        var query = from c in db.Certificates
                                    select c.Name;
                        foreach (var item in query)
                        {
                            newListBox.Items.Add(item);
                        }
                    }
                    newListBox.Width = 80;
                    newListBox.Height = 80;
                    listListsBox.Add(newListBox);
                    this.Controls.Add(newListBox);
                }
            }
        }