コード例 #1
0
    protected void BtnUserInfoSave_Click(object sender, EventArgs e)
    {
        TxtLogin.BorderColor = Color.Empty;
        if (string.IsNullOrEmpty(TxtLogin.Text))
        {
            TxtLogin.BorderColor = Color.Red;
            return;
        }
        DataTable DtCheckLogin = DALC.CheckLoginExist(TxtLogin.Text);

        if (DtCheckLogin == null)
        {
            Config.MsgBoxAjax(Config._DefaultErrorMessages);
            return;
        }
        if (DtCheckLogin.Rows.Count > 0)
        {
            if (DtCheckLogin._Rows("UsersID") != BtnUserInfoSave.CommandArgument)
            {
                Config.MsgBoxAjax("Bu istifadəçi adı artıq mövcuddur.");
                return;
            }
        }

        if (BtnUserInfoSave.CommandName == "Add")
        {
            if (string.IsNullOrEmpty(TxtPassword.Text))
            {
                TxtPassword.BorderColor = Color.Red;
                return;
            }
            if (string.IsNullOrEmpty(TxtPasswordRepeat.Text))
            {
                TxtPasswordRepeat.BorderColor = Color.Red;
                return;
            }
            if (TxtPassword.Text != TxtPasswordRepeat.Text)
            {
                TxtPassword.BorderColor = TxtPasswordRepeat.BorderColor = Color.Red;
                Config.MsgBoxAjax("Şifrə ilə şifrə təkrarı uyğun deyil.");
                return;
            }

            Dictionary <string, object> Dictionary = new Dictionary <string, object>()
            {
                { "UsersID", BtnUserInfoSave.CommandArgument },
                { "Login", TxtLogin.Text },
                { "Password", Config.SHA1Special(TxtPassword.Text) },
                { "UsersPermissionsModules", DBNull.Value },
                { "PermissionsIP", "*" },
                { "IsActive", true },
                { "Add_Dt", DateTime.Now },
                { "Add_Ip", Request.UserHostAddress.IPToInteger() },
            };

            int Check = 0;
            Check = DALC.InsertDatabase(Tools.Table.UsersAccounts, Dictionary);
            if (Check < 1)
            {
                Config.MsgBoxAjax(Config._DefaultErrorMessages);
                return;
            }
        }
        else if (BtnUserInfoSave.CommandName == "Edit")
        {
            Dictionary <string, object> Dictionary = new Dictionary <string, object>()
            {
                { "Login", TxtLogin.Text },
                { "IsActive", !CheckIsActive.Checked },
                { "WhereUsersID", int.Parse(BtnUserInfoSave.CommandArgument) }
            };

            int Check = DALC.UpdateDatabase(Tools.Table.UsersAccounts, Dictionary);
            if (Check < 1)
            {
                Config.MsgBoxAjax(Config._DefaultErrorMessages);
                return;
            }
        }

        Config.MsgBoxAjax(Config._DefaultSuccessMessages, Request.RawUrl);
    }