Esempio n. 1
0
        ///Создание нового пользователя через меню регистрации
        public void CreateNewDbUser(String new_username, String new_pass, String new_name, String new_familyname, 
            String new_secondname, DateTime new_birthdate, Int16 new_otdel, Int16 new_status, String new_mail, int Role)
        {
            try
              {

                  MD5 md5h = MD5.Create();
                  byte[] PassHash = md5h.ComputeHash(Encoding.Default.GetBytes(new_pass));
                  StringBuilder crHash = new StringBuilder();
                  foreach (byte hashByte in PassHash)
                  {
                      crHash.Append(String.Format("{0:x2}", hashByte));
                  }
                  string dBPassHash = crHash.ToString();
                  string _group = "postgres";
                  switch (Role)
                  {
                      case 0:
                          _group = "doc_group";
                          break;
                      case 1:
                          _group = "audit_group";
                          break;

                      case 2:
                          _group = "adm_group";
                          break;

                  }

                  NpgsqlCommand WriteNewDbUser = new NpgsqlCommand("CREATE USER " + new_username + " WITH PASSWORD '" + dBPassHash + "' IN GROUP "+_group+"", connectDb);
                  WriteNewDbUser.ExecuteNonQuery();

                  NpgsqlCommand WriteNewDbUserInfo = new NpgsqlCommand("INSERT INTO doctors (family_name, first_name, last_name, status, user_name, otdel, u_mail, birth, special) VALUES ('"
                      + new_familyname + "','" + new_name + "','" + new_secondname + "','" + new_status + "','" + new_username + "','" + new_otdel + "','" + new_mail + "','" + new_birthdate + "', '1' );", connectDb);
                  WriteNewDbUserInfo.ExecuteNonQuery();

                  MessageBox.Show("Пользователь создан", "Спасибо за регистрацию",
                       MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                  RegisterForm.ActiveForm.Close();
                  RegisterForm FormRegisterDbUser = new RegisterForm();
                  FormRegisterDbUser.ShowDialog();

              }
              catch (Exception exception)
              {
                   Warnings.WarnLog log = new Warnings.WarnLog();    log.writeLog(MethodBase.GetCurrentMethod().Name, exception.Message.ToString(), exception.StackTrace.ToString());
              }
              finally
              {

              }
        }
Esempio n. 2
0
 private void RegisterDbUser(object sender, EventArgs e)
 {
     RegisterForm FormRegisterDbUser = new RegisterForm();
     FormRegisterDbUser.ShowDialog();
 }