批量生成用户,业务需求:
TODO:
1,依据地区信息加载对应组织信息
2,依据组织信息按照分类选择:
(角色类别[1]:一个用户具有多角色 角色类别[2]:多用户单角色)
3,批量生成用户,依据现有风格(这里代指:业务需求)
讲解篇:1,服务端aspx,2,服务端后台3,前端javascript4,webservice返回数据(这里采用一般处理程序:handler.ashx.cs)
1,服务端aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserAdd.aspx.cs" Inherits="HMFW.Web.Pages.UserRoleManage.UserAdd" %> <%@ Register Src="/UserControl/uc_btnSelectArea.ascx" TagName="uc_btnSelectArea" TagPrefix="uc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>用户管理</title> <script src="/Js/jquery-1.2.6.min.js" type="text/javascript"></script> <script src="/Js/jquerytree/jquery.ztree.core-3.1.min.js" type="text/javascript"></script> <link href="/Js/jquerytree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" /> <script src="/Js/jquery.easyui.min.js" type="text/javascript"></script> <script src="/Js/jquery.validate.js" type="text/javascript"></script> <script src="/Js/jquery.form.js" type="text/javascript"></script> <link href="/themes/default/easyui.css" rel="stylesheet" type="text/css" /> <link href="/themes/icon.css" rel="stylesheet" type="text/css" /> <link href="/css/Common.css" rel="stylesheet" type="text/css" /> <script src="/Js/jquery-loadmask-0.4/jquery.loadmask.min.js" type="text/javascript"></script> <link href="/Js/jquery-loadmask-0.4/jquery.loadmask.css" rel="stylesheet" type="text/css" /> <script src="/Js/edit.js" type="text/javascript"></script> <script src="/Js/Common.js" type="text/javascript"></script> <script src="/Js/Pages/UserRoleManage/UserAdd.js" type="text/javascript"></script> <style type="text/css"> .roles tbody tr td { border: none; } </style> </head> <body> <form id="form1" runat="server"> <div> <table id="T_Content" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="content02"> <thead> <tr> <td colspan="5" class="content01bt">用户管理[<span runat="server" id="ActionInfo">新增</span>] </td> </tr> </thead> <tbody> <tr> <td width="5%" align="right" nowrap> <span class="red">*</span>地区: </td> <td align="left" width="40%" colspan="4"> <uc1:uc_btnSelectArea ID="uc_btnSelectArea1" runat="server" CanSelParent="true" SetSearchFunction="linkage()" /> <%--省市县乡镇村网格[用户角色类别]标识含义--%> <div style="font-weight: 600; padding-top: 2px"> <font color="red">(角色类别[1]:一个用户具有多角色 角色类别[2]:多用户单角色) </font> </div> </td> </tr> <%--省--%> <tr> <td align="right" nowrap> <span class="red">*</span>省: <%--省[用户角色类别]辅助功能:[新增]全选反选清除--%> <select id="ddlPro" onchange="return ProQuery('ddlPro','prochk_')"> <option value="0">全选</option> <option value="1">反选</option> <option value="2">清除</option> </select> </td> <td align="right" nowrap colspan="3"> <div class="inlinek"> <ul> <asp:Repeater ID="rptproRoles" runat="server"> <ItemTemplate> <li> <input type="checkbox" id='prochk_<%#Eval("gRoleID")%>' name='procheckbox' /><label for='chk_<%#Eval("gRoleID")%>'><%#Eval("sRoleName")%></label></li> </ItemTemplate> </asp:Repeater> </ul> </div> </td> <td> <table class="roles"> <tbody> <tr> <td> <input type="checkbox" id="protypechk_1" name="protypechk" checked="checked" /> </td> <td align="right" nowrap>省级角色类别[1] </td> <td> <input type="checkbox" id="protypechk_2" name="protypechk" /> </td> <td align="right" nowrap>省级角色类别[2] </td> </tr> </tbody> </table> </td> </tr> <%--市--%> <tr> <td align="right" nowrap> <span class="red">*</span>市: <%--市[用户角色类别]辅助功能:[新增]全选反选清除--%> <select id="ddlCity" onchange="return ProQuery('ddlCity','citychk_')"> <option value="0">全选</option> <option value="1">反选</option> <option value="2">清除</option> </select> </td> <td align="right" nowrap colspan="3"> <div class="inlinek"> <ul> <asp:Repeater ID="rptcityRoles" runat="server"> <ItemTemplate> <li> <input type="checkbox" id='citychk_<%#Eval("gRoleID")%>' name='citycheckbox' /><label for='chk_<%#Eval("gRoleID")%>'><%#Eval("sRoleName")%></label></li> </ItemTemplate> </asp:Repeater> </ul> </div> </td> <td> <table class="roles"> <tbody> <tr> <td> <input type="checkbox" id="citytypechk_1" name="citytypechk" checked="checked" /> </td> <td align="right" nowrap>市级角色类别[1] </td> <td> <input type="checkbox" id="citytypechk_2" name="citytypechk" /> </td> <td align="right" nowrap>市级角色类别[2] </td> </tr> </tbody> </table> </td> </tr> <%--县--%> <tr> <td align="right" nowrap> <span class="red">*</span>县: <%--县[用户角色类别]辅助功能:[新增]全选反选清除--%> <select id="ddlCoun" onchange="return ProQuery('ddlCoun','counchk_')"> <option value="0">全选</option> <option value="1">反选</option> <option value="2">清除</option> </select> </td> <td align="right" nowrap colspan="3"> <div class="inlinek"> <ul> <asp:Repeater ID="rptcounRoles" runat="server"> <ItemTemplate> <li> <input type="checkbox" id='counchk_<%#Eval("gRoleID")%>' name='councheckbox' /><label for='chk_<%#Eval("gRoleID")%>'><%#Eval("sRoleName")%></label></li> </ItemTemplate> </asp:Repeater> </ul> </div> </td> <td> <table class="roles"> <tbody> <tr> <td> <input type="checkbox" id="countypechk_1" name="countypechk" checked="checked" /> </td> <td align="right" nowrap>县级角色类别[1] </td> <td> <input type="checkbox" id="countypechk_2" name="countypechk" /> </td> <td align="right" nowrap>县级角色类别[2] </td> </tr> </tbody> </table> </td> </tr> <%--乡镇--%> <tr> <td align="right" nowrap> <span class="red">*</span>乡镇: <%--乡镇[用户角色类别]辅助功能:[新增]全选反选清除--%> <select id="ddlTown" onchange="return ProQuery('ddlTown','townchk_')"> <option value="0">全选</option> <option value="1">反选</option> <option value="2">清除</option> </select> </td> <td align="right" nowrap colspan="3"> <div class="inlinek"> <ul> <asp:Repeater ID="rpttownRoles" runat="server"> <ItemTemplate> <li> <input type="checkbox" id='townchk_<%#Eval("gRoleID")%>' name='towncheckbox' /><label for='chk_<%#Eval("gRoleID")%>'><%#Eval("sRoleName")%></label></li> </ItemTemplate> </asp:Repeater> </ul> </div> </td> <td> <table class="roles"> <tbody> <tr> <td> <input type="checkbox" id="towntypechk_1" name="towntypechk" checked="checked" /> </td> <td align="right" nowrap>乡镇角色类别[1] </td> <td> <input type="checkbox" id="towntypechk_2" name="towntypechk" /> </td> <td align="right" nowrap>乡镇角色类别[2] </td> </tr> </tbody> </table> </td> </tr> <%--村--%> <tr> <td align="right" nowrap> <span class="red">*</span>村: <%--村[用户角色类别]辅助功能:[新增]全选反选清除--%> <select id="ddlVill" onchange="return ProQuery('ddlVill','villchk_')"> <option value="0">全选</option> <option value="1">反选</option> <option value="2">清除</option> </select> </td> <td align="right" nowrap colspan="3"> <div class="inlinek"> <ul> <asp:Repeater ID="rptvillRoles" runat="server"> <ItemTemplate> <li> <input type="checkbox" id='villchk_<%#Eval("gRoleID")%>' name='villcheckbox' /><label for='chk_<%#Eval("gRoleID")%>'><%#Eval("sRoleName")%></label></li> </ItemTemplate> </asp:Repeater> </ul> </div> </td> <td> <table class="roles"> <tbody> <tr> <td> <input type="checkbox" id="villtypechk_1" name="villtypechk" checked="checked" /> </td> <td align="right" nowrap>村级角色类别[1] </td> <td> <input type="checkbox" id="villtypechk_2" name="villtypechk" /> </td> <td align="right" nowrap>村级角色类别[2] </td> </tr> </tbody> </table> </td> </tr> <%--网格--%> <%-- <tr> <td align="right" nowrap> <span class="red">*</span>网格: <%--网格[用户角色类别]辅助功能:[新增]全选反选清除--%> <%-- <select id="ddlGird" onchange="return ProQuery('ddlGird','girdchk_')"> <option value="0">全选</option> <option value="1">反选</option> <option value="2">清除</option> </select> </td> <td align="right" nowrap colspan="3"> <div class="inlinek"> <ul> <asp:Repeater ID="rptgirdRoles" runat="server"> <ItemTemplate> <li> <input type="checkbox" id='girdchk_<%#Eval("gRoleID")%>' name='girdcheckbox' /><label for='chk_<%#Eval("gRoleID")%>'><%#Eval("sRoleName")%></label></li> </ItemTemplate> </asp:Repeater> </ul> </div> </td> <td> <table class="roles"> <tbody> <tr> <td> <input type="checkbox" id="girdtypechk_1" name="girdtypechk" checked="checked" /> </td> <td align="right" nowrap>网格角色类别[1] </td> <td> <input type="checkbox" id="girdtypechk_2" name="girdtypechk" /> </td> <td align="right" nowrap>网格角色类别[2] </td> </tr> </tbody> </table> </td> </tr>--%> </tbody> </table> <table width="100%" height="36" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"> <xhm:xhmButtionEasyUI ID="btn_Save" runat="server" IconTypeSelected="save" OnClientClick="Save(true);return false;">生成用户</xhm:xhmButtionEasyUI> <xhm:xhmButtionEasyUI ID="btn_Return" runat="server" IconTypeSelected="back" OnClientClick="NBack(infoflag);return false;">返回</xhm:xhmButtionEasyUI> </td> </tr> </table> </div> <input type="hidden" id="hidID" runat="server" /> <input type="hidden" id="hidLoad" runat="server" /> </form> </body> </html>
2,服务端后台
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.MobileControls; using System.Web.UI.WebControls; using HMFW.BLL.UserRoleManage; using HMFW.Model; namespace HMFW.Web.Pages.UserRoleManage { public partial class UserAdd : BasePage { RolesBLL bll = new RolesBLL(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string gUserID = Request.QueryString["gUserID"]; string type = Request.QueryString["type"]; SetPageState(gUserID); LoadRoles(); } } /// <summary> /// 绑定角色 /// </summary> private void LoadRoles() { List<View_UserHaveRoles> lst = bll.GetAllRolesByUserID(GetSessionCurrentUserInfo.gUserID, int.Parse(GetSessionCurrentUserInfo.iType.ToString())); /*[编辑]设置绑定Repeater控件(省市县乡镇村网格)内容 2015/03/19 [方]*/ GetBinding(lst); return; } /// <summary> /// 设置绑定Repeater控件(省市县乡镇村网格)内容 /// </summary> /// <param name="lst">角色类别</param> private void GetBinding(List<View_UserHaveRoles> lst) { string[] arrayBinding = new string[] { "rptproRoles", "rptcityRoles", "rptcounRoles", "rpttownRoles", "rptvillRoles"}; foreach (string item in arrayBinding) { (Page.FindControl(item) as Repeater).DataSource = lst; (Page.FindControl(item) as Repeater).DataBind(); } } #region 设置页面状态,是新增还是编辑 /// <summary> /// 设置页面状态,是新增还是编辑 /// </summary> /// <param name="gUserID"></param> private void SetPageState(string gUserID) { if (!string.IsNullOrEmpty(gUserID)) { hidID.Value = gUserID; ActionInfo.InnerText = "编辑"; } } #endregion } }
3,前端javascript
var infoflag = true; //是否需要给父页面赋值 True 弹出框口 需要 False 打开新页面 不需要 var handleurl = "/Handle/UserRoleManage/UserHandler.ashx"; //一般处理程序路径 var chkProQuery = new Array("ddlPro", "ddlCity", "ddlCoun", "ddlTown", "ddlVill", "ddlGird");//联动select改变对应checkbox控制全选反选 初始化<省市县乡镇村网格[用户角色类别] var chkNameArray = new Array("protypechk", "citytypechk", "countypechk", "towntypechk", "villtypechk", "girdtypechk");//初始化数组<省市县乡镇村网格[用户角色类别]名称name> var chkNameIdArray = new Array(["protypechk", "protypechk_"], ["citytypechk", "citytypechk_"], ["countypechk", "countypechk_"], ["towntypechk", "towntypechk_"], ["villtypechk", "villtypechk_"], ["girdtypechk", "girdtypechk_"]);//初始化数组<省市县乡镇村网格[用户角色类别]名称name,id> //var chkNameAndIdArray = new Array(["procheckbox", "prochk_"], ["citycheckbox", "citychk_"], ["councheckbox", "counchk_"], ["towncheckbox", "townchk_"], ["villcheckbox", "villchk_"], ["girdcheckbox", "girdchk_"]);//初始化数组<省市县乡镇村网格[用户角色]名称name,id> $(function () { $.each(chkNameArray, function (value, idex) { //RequiredCheckbox(idex);//索引 RequiredCheckbox(chkNameArray[value]);//名称 }); }); function ProQuery(ddlName, chkId) { $.each(chkProQuery, function (value, idex) { if (ddlName == idex) { $("[id^=" + chkId + "]").each(function () { if ($("[id=" + ddlName + "]").val() == "2") {//清除 $(this).attr('checked', false); } else if ($("[id=" + ddlName + "]").val() == "0") {//全选 $(this).attr('checked', 'checked'); } else if ($("[id=" + ddlName + "]").val() == "1") {//反选 $(this).attr("checked", !this.checked); } }) } }); } /*地区控件选中后执行的方法*/ function linkage() { clearFields2();//取消禁用 var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) switch (areaLevel) { case 1: $("table tr").eq(2).attr("disabled", "disabled");//禁用省,省级角色类别 break; case 2: $("table tr:lt(6):not(:lt(2))").attr("disabled", "disabled");//禁用省,省级角色类别,禁用市,市级角色类别 break; case 3: $("table tr:lt(8):not(:lt(2))").attr("disabled", "disabled");//禁用省,省级角色类别,禁用市,市级角色类别,县,县级角色类别,乡,乡级角色类别 break; case 4: $("table tr:lt(10):not(:lt(2))").attr("disabled", "disabled");//禁用省,省级角色类别,禁用市,市级角色类别,县,县级角色类别,乡,乡级角色类别,村,村级角色类别 break; case 5: $("table tr:lt(12):not(:lt(2))").attr("disabled", "disabled");//禁用省,省级角色类别,禁用市,市级角色类别,县,县级角色类别,乡,乡级角色类别,村,村级角色类别,网格,网格角色类别 break; default: break; } } /*省市县乡镇村网格[用户角色类别] 2015/2/11 [方]*/ function RequiredNameIdCheckbox(chkName, chkId) {//单选框名称 var typestr = "";//用户角色类别名称[省市县乡镇村网格] 1角色类别[1],2角色类别[2] $("[name=" + chkName + "][checked]").each(function () { var cx = $(this).attr("id"); typestr += cx.replace(chkId, "");//省市县乡镇村网格角色类别名称 }) return typestr; } /*[新增] 省市县乡镇村网格[用户角色][合并] 2015/03/02 [方]*/ /*function RequiredNameAndIdCheckbox(chkName, chkId) { var typestr = "";//省市县乡镇村网格[用户角色] $("[name=" + chkName + "][checked]").each(function () { var cx = $(this).attr("id"); typestr += cx.replace(chkId, "") + "^";//省市县乡镇村网格角色名称 }); typestr = typestr.substr(0, typestr.length - 1); return typestr; }*/ /*省市县乡镇村网格[用户角色类别] 单选[点击不取消勾选] 2015/2/11 [方]*/ function RequiredCheckbox(chkName) {//单选框名称 $(":checkbox[name=" + chkName + "]").each(function () { $(this).click(function () { if ($(this).attr("checked")) { $(":checkbox[name=" + chkName + "]").removeAttr('checked'); $(this).attr('checked', 'checked'); } else { $(this).attr("checked", "checked"); } }); }); } function CheckInput() { var result = $("#form1").validate({ rules: { uc_btnSelectArea1$txtAreaName: { requiredgPID: true }, procheckbox: {//省级角色 requiredproCheck: true }, citycheckbox: {//市级角色 requiredcityCheck: true }, councheckbox: {//县角色 requiredcounCheck: true }, towncheckbox: {//乡镇角色 requiredtownCheck: true }, villcheckbox: {//村级角色 requiredvillCheck: true }, girdcheckbox: {//网格角色 requiredgirdCheck: true } } }); return result.form(); }; //[省]用户角色必选 jQuery.validator.addMethod("requiredproCheck", function (value, element) { var chkvalue = false; var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) if (areaLevel < 1) { $("[name='procheckbox'][checked]").each(function () { chkvalue = true; }); } else { chkvalue = true; } return chkvalue; }, "*至少选择一个省级用户角色") //[市]用户角色必选 jQuery.validator.addMethod("requiredcityCheck", function (value, element) { var chkvalue = false; var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) if (areaLevel < 2) { $("[name='citycheckbox'][checked]").each(function () { chkvalue = true; }); } else { chkvalue = true; } return chkvalue; }, "*至少选择一个市级用户角色") //[县]用户角色必选 jQuery.validator.addMethod("requiredcounCheck", function (value, element) { var chkvalue = false; var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) if (areaLevel < 3) { $("[name='councheckbox'][checked]").each(function () { chkvalue = true; }); } else { chkvalue = true; } return chkvalue; }, "*至少选择一个县级用户角色") //[乡镇]用户角色必选 jQuery.validator.addMethod("requiredtownCheck", function (value, element) { var chkvalue = false; var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) if (areaLevel < 4) { $("[name='towncheckbox'][checked]").each(function () { chkvalue = true; }); } else { chkvalue = true; } return chkvalue; }, "*至少选择一个乡镇级用户角色") //[村]用户角色必选 jQuery.validator.addMethod("requiredvillCheck", function (value, element) { var chkvalue = false; var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) if (areaLevel < 5) { $("[name='villcheckbox'][checked]").each(function () { chkvalue = true; }); } else { chkvalue = true; } return chkvalue; }, "*至少选择一个村级用户角色") //[网格]用户角色必选 jQuery.validator.addMethod("requiredgirdCheck", function (value, element) { var chkvalue = false; var areacode = $("#uc_btnSelectArea1_hidAreaCode").val(); var areaLevel = GetJbByCode(areacode);//勾选的当前地区级别(0:省级1:市级2:县级3:乡镇级4:村级) if (areaLevel < 6) { $("[name='girdcheckbox'][checked]").each(function () { chkvalue = true; }); } else { chkvalue = true; } return chkvalue; }, "*至少选择一个网格用户角色") jQuery.validator.addMethod("requiredgPID", function (value, element) { return value != ""; }, "*地区不能为空!"); function Save(flag) { if (!CheckInput()) return; var action = "padd"; /*省市县乡镇村网格[用户角色]*/ var chkprostr = "";//省 $("[name='procheckbox'][checked]").each(function () { var cx = $(this).attr("id"); chkprostr += cx.replace("prochk_", "") + "^"; }); var chkcitystr = "";//市 $("[name='citycheckbox'][checked]").each(function () { var cx = $(this).attr("id"); chkcitystr += cx.replace("citychk_", "") + "^"; }); var chkcounstr = "";//县 $("[name='councheckbox'][checked]").each(function () { var cx = $(this).attr("id"); chkcounstr += cx.replace("counchk_", "") + "^"; }); var chktownstr = "";//乡镇 $("[name='towncheckbox'][checked]").each(function () { var cx = $(this).attr("id"); chktownstr += cx.replace("townchk_", "") + "^"; }); var chkvillstr = "";//村 $("[name='villcheckbox'][checked]").each(function () { var cx = $(this).attr("id"); chkvillstr += cx.replace("villchk_", "") + "^"; }); var chkgirdstr = "";//网格 $("[name='girdcheckbox'][checked]").each(function () { var cx = $(this).attr("id"); chkgirdstr += cx.replace("girdchk_", "") + "^"; }); /*[新增] 省市县乡镇村网格[用户角色][合并] 2015/03/02 [方]*/ /*TODO: 1、省市县乡镇村网格合并格式:以","隔开 2、其中每一单项<省市县乡镇村网格>,以"^"隔开,去除最后一个空字符 3、最终合并格式如: b3cff5e4-d7c4-473f-8a80-1f8681562677^8a5baa20-fe3a-4005-8c3b-718eb64d7281, 4cfd5cb4-d04b-46c0-8738-c8119d2a9fbb^d35979ad-96c7-4dd5-a4c2-c832ac0b56d8, fd33d69e-ac6e-4c62-99cc-c8e69718b97b^a81d3ab7-aba0-4b6f-a730-d2aa5eaa512f, 352b986b-7c44-48e4-a088-b7f4d56c8201^b8775c0a-fcdd-4aa6-bef5-b9e6ea895ebe, ebbeb3ad-11c1-48d7-9268-ee14abfa5c89^ee839f4f-1daf-45ca-bd8e-67fd0ba264f0, ea2d104b-c77e-4875-b703-bbf52a5f2978^091a04db-0af2-4cb1-8af8-eb14d6173c8b, 4、暂时注释 */ /*var typenameidStr = ""; $.each(chkNameAndIdArray, function (value, idex) { var typeNameIdArray = idex; var sArray = ""; $.each(typeNameIdArray, function (value, idex) { sArray += idex + ","; }); sArray = sArray.substr(0, sArray.length - 1).split(','); typenameidStr += RequiredNameAndIdCheckbox(sArray[0], sArray[1]) + ","; }); typenameidStr = typenameidStr.substr(0, typenameidStr.length - 1); return typenameidStr;*/ /*省市县乡镇村网格[用户角色类别]*/ var typestr = ""; $.each(chkNameIdArray, function (value, idex) { var typeArray = idex; var sArray = ""; $.each(typeArray, function (value, idex) { sArray += idex + ","; }); sArray = sArray.substr(0, sArray.length - 1).split(','); typestr += RequiredNameIdCheckbox(sArray[0], sArray[1]) + "^"; }); /*地区编码 用户角色[省、市、县、乡镇、村、网格] 用户角色[省、市、县、乡镇、村、网格]类别 */ var data = "action=" + action + "&sAreaCode=" + $("#uc_btnSelectArea1_hidAreaCode").val() + "&chkprostr=" + chkprostr + "&chkcitystr=" + chkcitystr + "&chkcounstr=" + chkcounstr + "&chktownstr=" + chktownstr + "&chkvillstr=" + chkvillstr + "&chkgirdstr=" + chkgirdstr + "&typestr=" + typestr; $.ajax({ type: "POST", //用POST方式传输 dataType: "json", //数据格式:JSON url: handleurl, //目标地址 data: data, cache: false, success: function (data) { window.parent.document.getElementById("hidIsChange").value = "1"; $.messager.alert('信息', data.data, 'info'); clearFields1(); //清空界面和隐藏域ID }, error: function (XmlHttpRequest, textStatus, errorThrown) { $.messager.alert('错误', errorThrown, 'error'); }, beforeSend: function () { if (flag) $("body").mask(); else parent.$("body").mask(); }, complete: function () { if (flag) $("body").unmask(); else parent.$("body").unmask(); } }); } //设置界面属性值 function clearFields1() { $("#T_Content tr").attr("disabled", false);// 取消禁用 //$("#T_Content :input:not('.roles')").clearFields(); //清空界面 } function clearFields2() { $("#T_Content tr").attr("disabled", false);// 取消禁用 }
4,webservice返回数据(这里采用一般处理程序:handler.ashx.cs)
/*[新增] 批量生成用户<测试> 关联机构信息 实现用户和用户角色关联的批量添加 2015/2/11 [方]*/ private void PAdd() { var sAreaCode = GetParam("sAreaCode"); var typestr = GetParam("typestr");//用户角色[省、市、县、乡镇、村、网格]类别 var pwd = GlobalSettings.Instance.DefaultPassword; var gCreateId = GetSessionCurrentUserInfo.gUserID; var gCreateName = GetSessionCurrentUserInfo.sRealName; /*省市县乡镇村网格[用户角色]*/ //chkprostr chkcitystr chkcounstr chktownstr chkvillstr chkgirdstr var lstAll = bllrole.GetAllRoles(); #region 用户角色类别 var lstproroles = GetParam("chkprostr").Split('^');//省级角色 var lstpro = lstAll.Where(p => lstproroles.Contains(p.gRoleID.ToString())).ToList(); // lstproroles;//.Where(s => s.Trim() != "").Select(s => lstAll.FirstOrDefault(p => p.gRoleID == new Guid(s))).ToList(); var lstcityroles = GetParam("chkcitystr").Split('^');//市级角色 var lstcity = lstAll.Where(p => lstcityroles.Contains(p.gRoleID.ToString())).ToList(); //.Where(s => s.Trim() != "").Select(s => lstAll.FirstOrDefault(p => p.gRoleID == new Guid(s))).Where(role => role != null).ToList(); var lstcounroles = GetParam("chkcounstr").Split('^');//县级角色 var lstcoun = lstAll.Where(p => lstcounroles.Contains(p.gRoleID.ToString())).ToList();//.Where(s => s.Trim() != "").Select(s => lstAll.FirstOrDefault(p => p.gRoleID == new Guid(s))).Where(role => role != null).ToList(); var lsttownroles = GetParam("chktownstr").Split('^');//乡镇角色 var lsttown = lstAll.Where(p => lsttownroles.Contains(p.gRoleID.ToString())).ToList();//.Where(s => s.Trim() != "").Select(s => lstAll.FirstOrDefault(p => p.gRoleID == new Guid(s))).Where(role => role != null).ToList(); var lstvillroles = GetParam("chkvillstr").Split('^');//村级角色 var lstvill = lstAll.Where(p => lstvillroles.Contains(p.gRoleID.ToString())).ToList();//.Where(s => s.Trim() != "").Select(s => lstAll.FirstOrDefault(p => p.gRoleID == new Guid(s))).Where(role => role != null).ToList(); var lstgirdroles = GetParam("chkgirdstr").Split('^');//网格角色 var lstgird = lstAll.Where(p => lstgirdroles.Contains(p.gRoleID.ToString())).ToList();//.Where(s => s.Trim() != "").Select(s => lstAll.FirstOrDefault(p => p.gRoleID == new Guid(s))).Where(role => role != null).ToList(); #endregion var resul = true; var mes = "生成成功!"; try { /*地区编码 用户角色[省、市、县、乡镇、村、网格] 用户角色[省、市、县、乡镇、村、网格]类别 */ if (!bll.PAdd(sAreaCode, pwd, gCreateId, gCreateName, lstpro, lstcity, lstcoun, lsttown, lstvill, lstgird, typestr)) { resul = false; mes = "生成失败!"; } } catch (Exception ex) { resul = false; mes = ex.Message; XHMLog.WriteLogToFile(new LogInfo(GetSessionCurrentUserInfo, ex)); } OutputResult(resul, mes); }
TODO:(ashx.cs)
其中关于存取数据,采用原始三层+ef机制,这里略
涉及到技术点包含:
javascript,ashx,ajax,三层+ef等
时间: 2024-11-09 03:09:00