Exemplo n.º 1
0
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        string userAD;

        if (tb_UserAD.Visible == true)
        {
            if (tb_UserAD.Text.Trim() == "" || !tb_UserAD.Text.ToLower().StartsWith("founderpcb\\"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('域帐号格式有误!');</script>");
                return;
            }
            userAD = tb_UserAD.Text.Trim();
        }
        else
        {
            if (ddl_UserAD.SelectedValue == "-1")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('请选择用户!');</script>");
                return;
            }
            userAD = ddl_UserAD.SelectedItem.Text;
        }

        int           count  = int.Parse(((HiddenField)GridView1.Rows[GridView1.Rows.Count - 1].Cells[2].FindControl("hdf_Index")).Value);
        StringBuilder config = new StringBuilder();

        for (int i = 1; i <= count + 1; i++)
        {
            config.Append("0");
        }
        for (int j = 0; j < GridView1.Rows.Count; j++)
        {
            CheckBox cb = (CheckBox)GridView1.Rows[j].Cells[1].FindControl("ckb_Right");
            if (cb.Checked)
            {
                config.Remove(int.Parse(((HiddenField)GridView1.Rows[j].Cells[2].FindControl("hdf_Index")).Value), 1);
                config.Insert(int.Parse(((HiddenField)GridView1.Rows[j].Cells[2].FindControl("hdf_Index")).Value), "1");
            }
        }

        int a = XmlSource.SetUserConfig(userAD, config.ToString());

        if (a == -1)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存失败!');</script>");
        }
        else if (a == 0)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存成功!');</script>");
        }
    }