Example #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentCell.ColumnIndex == 4)
            {
                person personForm = new person();
                personForm.button1.Hide();
                personForm.textBox1.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                personForm.textBox2.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                personForm.textBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
                personForm.textBox4.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();

                w_client.OperationChangesRef.Person p = new w_client.OperationChangesRef.Person();
                p.ID_person = Convert.ToInt16(this.dataGridView1.CurrentRow.Cells[0].Value);
                p.tableName = "data_base.persons";
                List <object> pn = GetL(p);
                p = (w_client.OperationChangesRef.Person)pn[0];

                Dictionary <int, string> id_namegr = new Dictionary <int, string>();
                Dictionary <string, int> namegr_id = new Dictionary <string, int>();
                Group_ gr = new Group_();
                gr.tableName = "data_base.groups";
                List <object> g = GetL(gr);
                foreach (object g_ in g)
                {
                    Group_ group = (Group_)g_;
                    personForm.comboBox1.Items.Add(group.name.ToString());
                    id_namegr.Add(group.ID_group, group.name);
                    try
                    {
                        namegr_id.Add(group.name, group.ID_group);
                    }
                    catch { }
                }
                personForm.comboBox1.SelectedIndex = personForm.comboBox1.FindStringExact(id_namegr[p.Groups_ID_Group]);

                Dictionary <int, string> id_privname      = new Dictionary <int, string>();
                w_client.OperationChangesRef.Privilege pg = new w_client.OperationChangesRef.Privilege(); // все существующие привилегии
                pg.tableName = "data_base.privileges";
                List <object> up = GetL(pg);
                List <w_client.OperationChangesRef.Privilege> pl = new List <w_client.OperationChangesRef.Privilege>();
                foreach (object u in up)
                {
                    w_client.OperationChangesRef.Privilege u_ = (w_client.OperationChangesRef.Privilege)u;
                    id_privname.Add(u_.ID_privilege, u_.name_func);
                    pl.Add(u_);
                }

                w_client.OperationChangesRef.Group_Privileges gp = new w_client.OperationChangesRef.Group_Privileges();
                gp.Groups_ID_group = namegr_id[personForm.comboBox1.SelectedItem.ToString()];
                gp.tableName       = "data_base.groups_privileges";
                List <object> grp = GetL(gp);
                List <w_client.OperationChangesRef.Group_Privileges> r = new List <w_client.OperationChangesRef.Group_Privileges>();
                foreach (object g_ in grp)
                {
                    r.Add((w_client.OperationChangesRef.Group_Privileges)g_);
                }


                w_client.OperationChangesRef.Persons_Privileges pp = new w_client.OperationChangesRef.Persons_Privileges();
                pp.Persons_ID_person = Convert.ToInt32(personForm.textBox1.Text);
                pp.tableName         = "data_base.persons_privileges";
                List <object> j = GetL(pp);
                List <w_client.OperationChangesRef.Persons_Privileges> pi = new List <w_client.OperationChangesRef.Persons_Privileges>();
                foreach (object j_ in j)
                {
                    w_client.OperationChangesRef.Persons_Privileges j0 = (w_client.OperationChangesRef.Persons_Privileges)j_;
                    pi.Add(j0);
                }

                foreach (w_client.OperationChangesRef.Persons_Privileges p_p in pi)
                {
                    personForm.dataGridView2.Rows.Add(p_p.Privileges_ID_privilege, id_privname[p_p.Privileges_ID_privilege], true);
                }

                foreach (w_client.OperationChangesRef.Privilege pt in pl)
                {
                    int flag = 0;
                    for (int i = 0; i <= personForm.dataGridView1.RowCount - 1; i++)
                    {
                        if (pt.ID_privilege.ToString() == personForm.dataGridView1.Rows[i].Cells[0].Value.ToString())
                        {
                            flag = 1;
                        }
                    }

                    for (int i = 0; i <= personForm.dataGridView2.RowCount - 1; i++)
                    {
                        if (pt.ID_privilege.ToString() == personForm.dataGridView2.Rows[i].Cells[0].Value.ToString())
                        {
                            flag = 1;
                        }
                    }

                    if (flag == 0)
                    {
                        personForm.dataGridView2.Rows.Add(pt.ID_privilege, id_privname[pt.ID_privilege]);
                    }
                }
                personForm.ShowDialog();
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            person p = new person();

            p.dataGridView1.Rows.Clear();
            p.dataGridView2.Hide();
            p.label7.Text = "*Дополнительные привилегии будут доступны после создания человека.";
            Dictionary <string, int> namegr_id = new Dictionary <string, int>();
            Group_ gr = new Group_();

            gr.tableName = "data_base.groups";
            List <object> g = GetL(gr);

            foreach (object g_ in g)
            {
                Group_ group = (Group_)g_;
                p.comboBox1.Items.Add(group.name.ToString());
                try
                { namegr_id.Add(group.name, group.ID_group); }
                catch { }
            }
            p.comboBox1.SelectedIndex = 1;

            Dictionary <int, string> id_privname = new Dictionary <int, string>();

            w_client.OperationChangesRef.Privilege pg = new w_client.OperationChangesRef.Privilege(); // все существующие привилегии
            pg.tableName = "data_base.privileges";
            List <object> up = GetL(pg);

            foreach (object u in up)
            {
                w_client.OperationChangesRef.Privilege u_ = (w_client.OperationChangesRef.Privilege)u;
                id_privname.Add(u_.ID_privilege, u_.name_func);
            }

            w_client.OperationChangesRef.Group_Privileges gp = new w_client.OperationChangesRef.Group_Privileges();
            gp.Groups_ID_group = namegr_id[p.comboBox1.SelectedItem.ToString()];
            gp.tableName       = "data_base.groups_privileges";
            List <object> grp = GetL(gp);
            List <w_client.OperationChangesRef.Group_Privileges> r = new List <w_client.OperationChangesRef.Group_Privileges>();

            foreach (object g_ in grp)
            {
                r.Add((w_client.OperationChangesRef.Group_Privileges)g_);
            }

            foreach (object u in up)
            {
                int flag = 0;
                w_client.OperationChangesRef.Privilege u_ = (w_client.OperationChangesRef.Privilege)u;
                for (int i = 0; i <= p.dataGridView1.RowCount - 1; i++)
                {
                    if (u_.ID_privilege.ToString() == p.dataGridView1.Rows[i].Cells[0].Value.ToString())
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    p.dataGridView2.Rows.Add(u_.ID_privilege, u_.name_func);
                }
            }

            p.button1.Show();
            p.button2.Show();
            p.button3.Hide();
            p.ShowDialog();
        }