Esempio n. 1
0
        public int update_per_priv(changes ch) // привилегии человека
        {
            int flag = 0;

            sql(@"SET SQL_SAFE_UPDATES = 0");
            try
            {
                Convert.ToInt32(ch.ID_person);
                sql(@"delete from data_base.persons_privileges where Persons_ID_person='" + ch.ID_person + "'");
                string[] mas = ch.IDs_privch.Split(',');
                foreach (string m in mas)
                {
                    try
                    {
                        Convert.ToInt32(m);
                        sql(@"insert into data_base.persons_privileges set Persons_ID_person='" + ch.ID_person + "', Privileges_ID_privilege ='" + m + "'");
                        flag = 1;
                    }
                    catch
                    {
                        flag = 0;
                    }
                }
                return(flag);
            }
            catch
            {
                flag = 1; //т.к. все принимается пустые привилегии - таблица с этим id очищается
                return(flag);
            }
        }
Esempio n. 2
0
        public int update_groups(changes ch) // привилегии в группах
        {
            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLCon"].ConnectionString))
            {
                sql(@"SET SQL_SAFE_UPDATES = 0");
                try
                {
                    Convert.ToInt32(ch.ID_group);
                    sql(@"delete from data_base.groups_privileges where Groups_ID_group='" + ch.ID_group + "'");

                    sql(@"update data_base.groups set name='" + ch.name_group + "' where ID_group='" + ch.ID_group + "'");

                    string[] mas = ch.IDs_privgr.Split(',');

                    try
                    {
                        foreach (string m in mas)
                        {
                            Convert.ToInt32(m);
                            sql(@"insert into data_base.groups_privileges set Groups_ID_group='" + ch.ID_group + "', Privileges_ID_privilege ='" + m + "'");
                        }
                        return(1);
                    }
                    catch
                    {
                        return(0);
                    }
                }
                catch
                {
                    //тот же принцип, что внизу
                    return(1);
                }
            }
        }
Esempio n. 3
0
        public int update_pers(changes ch)
        {
            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLCon"].ConnectionString))
            {
                try
                {
                    Convert.ToInt32(ch.ID_group);
                    Convert.ToInt32(ch.ID_person);
                    Regex regex = new Regex("^[А-Яа-я]+$");

                    if (regex.IsMatch(ch.surname) && regex.IsMatch(ch.name) && regex.IsMatch(ch.middle_name))
                    {
                        sql(@"SET SQL_SAFE_UPDATES = 0");
                        string sql1 = @"update data_base.persons set Groups_ID_group= '" + ch.ID_group + "' , surname = '" + ch.surname + "', " + "name='" + ch.name + "', middle_name='" + ch.middle_name + "' where ID_person='" + ch.ID_person + "'";
                        con.Open();
                        MySqlCommand cmd = new MySqlCommand(sql1, con);
                        cmd.ExecuteReader();
                        con.Close();
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch
                {
                    return(0);
                }
            }
        }
Esempio n. 4
0
 public int add_priv(changes ch)
 {
     using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLCon"].ConnectionString))
     {
         try
         {
             Regex regex = new Regex("^[А-Яа-я]+$");
             if (regex.IsMatch(ch.name_priv))
             {
                 string sql = @"insert into data_base.privileges (name_func) values ('" + ch.name_priv + "')";
                 con.Open();
                 MySqlCommand cmd = new MySqlCommand(sql, con);
                 cmd.ExecuteReader();
                 con.Close();
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
         catch
         {
             return(0);
         }
     }
 }
Esempio n. 5
0
 public int add_pers(changes ch)
 {
     using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLCon"].ConnectionString))
     {
         try
         {
             Convert.ToInt32(ch.ID_group);
             Regex regex = new Regex("^[А-Яа-я]+$");
             if (regex.IsMatch(ch.surname) && regex.IsMatch(ch.name) && regex.IsMatch(ch.middle_name))
             {
                 string sql = @"insert into data_base.persons (surname, name, middle_name, Groups_ID_group) values ('" + ch.surname + "','" + ch.name + "','" + ch.middle_name + "','" + ch.ID_group + "')";
                 con.Open();
                 MySqlCommand cmd = new MySqlCommand(sql, con);
                 cmd.ExecuteReader();
                 con.Close();
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
         catch
         {
             return(0);
         }
     }
 }