示例#1
0
        protected void gvMasterDataUser_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            string response = string.Empty;

            try
            {
                //initialize control
                BootstrapGridView     gv                      = (BootstrapGridView)sender;
                BootstrapTextBox      txtusername             = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtUserName");
                BootstrapTextBox      txtpassword             = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtPassword");
                BootstrapTextBox      txtpasswordconfirmation = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtPasswordConfirmation");
                BootstrapTextBox      txtemail                = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtEmail");
                BootstrapTextBox      txttelephone            = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtTelephone");
                BootstrapCheckBoxList chkrole                 = (BootstrapCheckBoxList)gv.FindEditFormTemplateControl("chkRole");

                //validation input
                if (txtusername.IsValid == false ||
                    txtpassword.IsValid == false ||
                    txtpasswordconfirmation.IsValid == false ||
                    txtemail.IsValid == false ||
                    chkrole.IsValid == false)
                {
                    return;
                }

                if (txtpassword.Text != txtpasswordconfirmation.Text)
                {
                    response = "Password Confirmation is not valid";
                    return;
                }

                //set roles
                string roles = string.Empty;
                if (chkrole.SelectedValues.Count > 0)
                {
                    foreach (string item in chkrole.SelectedValues)
                    {
                        roles = roles + ";" + item;
                    }
                    roles = roles.Substring(1);
                }

                //execute query
                response = DbTransaction.DbToString("dbo.sp_AddMasterDataUser", new
                {
                    username  = txtusername.Text,
                    password  = Encryption.Encrypt(txtpassword.Text),
                    email     = txtemail.Text,
                    telephone = txttelephone.Text,
                    roles     = roles,
                    userlogin = UserProfile.Username
                }, true);
            }
            catch (Exception ex)
            {
                response = ex.Message;
            }
            finally
            {
                gvMasterDataUser.JSProperties["cpRes"] = response;
                e.Cancel = true;
                if (response.Contains("Success"))
                {
                    gvMasterDataUser.CancelEdit();
                }
            }
        }
示例#2
0
        protected void gvMasterDataUser_HtmlEditFormCreated(object sender, DevExpress.Web.ASPxGridViewEditFormEventArgs e)
        {
            string param = Request.Params.Get("__CALLBACKPARAM");

            if (!String.IsNullOrEmpty(param))
            {
                if (!param.Contains("CANCELEDIT"))
                {
                    BootstrapGridView     gv                      = (BootstrapGridView)sender;
                    BootstrapTextBox      txtusername             = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtUserName");
                    BootstrapTextBox      txtpassword             = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtPassword");
                    BootstrapTextBox      txtpasswordconfirmation = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtPasswordConfirmation");
                    BootstrapTextBox      txtemail                = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtEmail");
                    BootstrapTextBox      txttelephone            = (BootstrapTextBox)gv.FindEditFormTemplateControl("txtTelephone");
                    BootstrapCheckBoxList chkrole                 = (BootstrapCheckBoxList)gv.FindEditFormTemplateControl("chkRole");
                    BootstrapGridView     gridAuth                = (BootstrapGridView)gv.FindEditFormTemplateControl("gvAuthParameter");


                    string username  = gv.GetRowValues(gv.EditingRowVisibleIndex, "Username") == null ? string.Empty : gv.GetRowValues(gv.EditingRowVisibleIndex, "Username").ToString();
                    string password  = gv.GetRowValues(gv.EditingRowVisibleIndex, "Password") == null ? string.Empty : gv.GetRowValues(gv.EditingRowVisibleIndex, "Password").ToString();
                    string email     = gv.GetRowValues(gv.EditingRowVisibleIndex, "Email") == null ? string.Empty : gv.GetRowValues(gv.EditingRowVisibleIndex, "Email").ToString();
                    string telephone = gv.GetRowValues(gv.EditingRowVisibleIndex, "Telephone") == null ? string.Empty : gv.GetRowValues(gv.EditingRowVisibleIndex, "Telephone").ToString();
                    string roles     = gv.GetRowValues(gv.EditingRowVisibleIndex, "RoleName") == null ? string.Empty : gv.GetRowValues(gv.EditingRowVisibleIndex, "RoleName").ToString();

                    //set textbox username
                    if (!String.IsNullOrWhiteSpace(username))
                    {
                        txtusername.Text = username;
                    }
                    txtusername.ValidationSettings.RequiredField.IsRequired = true;
                    txtusername.ValidationSettings.RequiredField.ErrorText  = "Field is Required";

                    //set textbox password
                    if (!string.IsNullOrEmpty(password))
                    {
                        txtpassword.Text             = Encryption.Decrypt(password);
                        txtpasswordconfirmation.Text = Encryption.Decrypt(password);
                    }
                    txtpassword.ValidationSettings.RequiredField.IsRequired             = true;
                    txtpassword.ValidationSettings.RequiredField.ErrorText              = "Field is Required";
                    txtpasswordconfirmation.ValidationSettings.RequiredField.IsRequired = true;
                    txtpasswordconfirmation.ValidationSettings.RequiredField.ErrorText  = "Field is Required";

                    //set textbox email
                    if (!String.IsNullOrWhiteSpace(email))
                    {
                        txtemail.Text = email;
                    }
                    txtemail.ValidationSettings.RequiredField.IsRequired = true;
                    txtemail.ValidationSettings.RequiredField.ErrorText  = "Field is Required";
                    txtemail.ValidationSettings.RegularExpression.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
                    txtemail.ValidationSettings.RegularExpression.ErrorText            = "Invalid Email Format";

                    //set textbox telephone
                    if (!String.IsNullOrWhiteSpace(telephone))
                    {
                        txttelephone.Text = telephone;
                    }
                    //txttelephone.ValidationSettings.RequiredField.IsRequired = true;
                    //txttelephone.ValidationSettings.RequiredField.ErrorText = "Field is Required";
                    txttelephone.MaskSettings.Mask = "99999999999999";

                    //set checkbox list role
                    //chkrole.DataSource = ListRole();
                    //chkrole.DataBind();
                    //chkrole.ValueField = "RoleID";
                    //chkrole.TextField = "RoleName";
                    chkrole.ValidationSettings.RequiredField.IsRequired = true;
                    chkrole.ValidationSettings.RequiredField.ErrorText  = "Field is Required";
                    if (!string.IsNullOrEmpty(roles))
                    {
                        string[] rolesid = roles.Split(';');
                        foreach (string item in rolesid)
                        {
                            foreach (BootstrapListEditItem i in chkrole.Items)
                            {
                                if (i.Value.ToString() == item.ToString())
                                {
                                    i.Selected = true;
                                }
                            }
                        }
                    }

                    // set grid auth parameter
                    if (ListAuthParameter(username).Count > 0)
                    {
                        gridAuth.DataBind();
                    }
                }
            }
        }