Exemplo n.º 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Internet.EmailIsValid(txtEmail.Text) == false)
            {
                lblRequired.Text = MMUtils.GetString("newuserDlg.wrongemail.text"); //wrong email format
            }
            else if (txtEmail.Text == "" || txtLogin.Text == "" || txtName.Text == "" || txtPassword.Text == "")
            {
                lblRequired.Text = MMUtils.GetString("newuserDlg.allfieldsrequired.text");
            }
            else
            {
                aLogin           = txtLogin.Text;
                aPassword        = txtPassword.Text; //TODO crypt password?
                lblRequired.Text = "";

                using (UsersDB dbUsers = new UsersDB())
                {
                    DataTable _dt = dbUsers.ExecuteQuery("select * from USERS");
                    foreach (DataRow _row in _dt.Rows)
                    {
                        if (_row["LOGIN"].ToString() == txtLogin.Text) //this login already exists!
                        {
                            lblRequired.Text = MMUtils.GetString("newuserDlg.loginexists.text");
                            break;
                        }
                        else if (_row["EMAIL"].ToString() == txtEmail.Text) //this email already exists!
                        {
                            lblRequired.Text = MMUtils.GetString("newuserDlg.emailexists.text");
                            break;
                        }
                    }
                }

                if (lblRequired.Text == "")
                {
                    string _role = "";
                    if (rbtnAdmin.Checked)
                    {
                        _role = "Admin";
                    }
                    else if (rbtnAdmin.Checked)
                    {
                        _role = "DAdmin";
                    }
                    else
                    {
                        _role = "Member";
                    }

                    using (UsersDB _db = new UsersDB())
                    {
                        _db.ExecuteNonQuery("INSERT INTO USERS VALUES(" +
                                            "`" + txtName.Text + "`," +
                                            "`" + txtEmail.Text + "`," +
                                            "`" + aLogin + "`," +
                                            "`" + aPassword + "`," +
                                            "`" + _role + "`, ``, ``, 0, 0)");
                    }

                    //TODO может отправить письмо?
                    this.DialogResult = DialogResult.OK;
                }
            }
        }