前台
1 function BMSure() { 2 var DanWeiName = $("[id$='BusinessName']").val(); 3 var Address = $("[id$='Address']").val(); 4 if ((DanWeiName != "") && (Address != "")) { 5 var planGuid = $("[id$='hid_planGuid']").val(); 6 //var displayname = $("[id$='hid_displayName']").val(); 7 var num = $("[id$='hid_sum']").val(); 8 $.ajax({ 9 type: "POST", 10 contentType: "application/json;charset=utf-8", 11 12 url: "../Ashx/SaveBMInfo.ashx?PlanGuid=" + planGuid, 13 data: JSON.stringify(GetJsonData()), 14 dataType: "json", 15 success: function (message) { 16 if (message == 1) { 17 18 ConfirmBM(); 19 //ReturnLogin(DanWeiName); 20 21 } 22 }, 23 error: function (message) { 24 if (message == 0) { 25 layer.msg("保存失敗"); 26 } 27 } 28 }) 29 } 30 else { 31 layer.msg("請將單位信息填寫完整"); 32 return false; 33 } 34 }; 35 36 function ReturnLogin(DanWeiName) {//返回登錄名密碼 37 layer.open({ 38 type: 2, 39 title: "提示信息", 40 area: ['400px', '220px'], 41 content: ['LoginID_PassWord.aspx?DanWeiName=' + DanWeiName], 42 skin: 'layer-ext-iframe', 43 //關閉按鈕刷新父頁面 44 cancel: function () { 45 window.location.reload(); 46 } 47 }); 48 } 49 50 function ConfirmBM() { 51 //是否繼續報名 52 layer.confirm('報名成功,是否繼續報名?', 53 { 54 skin: 'layui-layer-molv', btn: ['繼續報名', '關閉'] //按鈕 55 }, function (index) { 56 layer.close(index); 57 window.location.reload(); 58 }, function (index) { 59 layer.close(index); 60 61 var index2 = parent.layer.getFrameIndex(window.name); 62 parent.layer.close(index2);//關閉彈出層 63 }); 64 65 } 66 67 function GetJsonData() { 68 var temp = $("[id$='hid_sum'").val();//添加人員的數量 69 var json_person = ''; 70 for (var i = 1; i <= temp; i++) { 71 var text = ""; 72 $("[id$='addPerson" + i + "']").find("td").children("input").each(function () { 73 text += $(this).val() + ","; 74 }) 75 var a = new Array(); 76 a = text.split(','); 77 if (a != "" && a != null) { 78 var json_persontemp = { 79 "Name": a[0], 80 "Sex": a[1], 81 "Identity": a[2], 82 "Brithday": a[3], 83 "Phone": a[4] 84 } 85 } 86 if (i == temp) 87 json_person += JSON.stringify(json_persontemp); 88 else 89 json_person += JSON.stringify(json_persontemp) + ','; 90 91 }; 92 93 94 var persontemp = eval('[' + json_person + ']'); 95 96 var json = { 97 "DanWeiName": $("[id$='BusinessName']").val(), 98 "DetailAddress": $("[id$='Address']").val(), 99 "BelongFenJu": $("[id$='BelongFenJu']").val(), 100 "PersonData": 101 //JSON.parse(json_person) 102 persontemp 103 104 }; 105 106 107 108 return json; 109 }
后台(此處 使用SaveBMInfo 一般處理程序,后台直接寫也一樣)
1 public class SaveBMInfo : IHttpHandler 2 { 3 Epoint.KSPXBase.Bizlogic.BLL.B_PK_Unit b_unit = new Epoint.KSPXBase.Bizlogic.BLL.B_PK_Unit(); 4 Epoint.KSPXBase.Bizlogic.BLL.B_PK_User b_user = new Epoint.KSPXBase.Bizlogic.BLL.B_PK_User(); 5 Epoint.PeiXun.Bizlogic.BLL.PXBaoM.B_PX_BaoM b_baom = new Epoint.PeiXun.Bizlogic.BLL.PXBaoM.B_PX_BaoM(); 6 M_PK_Unit m_unit = new M_PK_Unit(); 7 M_PK_User m_user = new M_PK_User(); 8 M_PX_BaoM m_baom = new M_PX_BaoM(); 9 10 List<PersonDataJSON> list_PersonData = new List<PersonDataJSON>(); 11 public void ProcessRequest(HttpContext context) 12 { 13 string result = ""; 14 context.Response.ContentType = "application/json"; 15 string PlanGuid = context.Request.QueryString["PlanGuid"].ToString(); 16 17 var data = context.Request; 18 var sr = new StreamReader(data.InputStream); 19 var stream = sr.ReadToEnd(); 20 var javaScriptSerializer = new JavaScriptSerializer(); 21 var PostedData = javaScriptSerializer.Deserialize<RequestDataJSON>(stream); 22 23 try 24 { 25 #region 26 if (PostedData != null) 27 { 28 m_unit.RowGuid = Guid.NewGuid().ToString();//單位唯一標識 29 m_unit.DanWeiName = PostedData.DanWeiName;//單位名稱 30 m_unit.DetailAddress = PostedData.DetailAddress;//單位地址 31 m_unit.BelongFenJu = PostedData.BelongFenJu;//所屬分局 --報名點 32 m_unit.LoginID = ConvertToPY(PostedData.DanWeiName);//登錄名 33 m_unit.Password = common.authPassword("111111");//密碼 34 m_unit.AddType = "1";//報名方式 1-前台報名 2-后台添加 3-接口獲取 35 m_unit.UserType = "1";//會員類別 0-個人 1-企業 2-學校 3-培訓機構 36 m_unit.IsEnable = "1"; 37 m_unit.DelFlag = "0"; 38 m_unit.Status = "2";//會員狀態 39 b_unit.Insert(m_unit); 40 41 42 var peopleInfo = PostedData.PersonData; 43 for (int i = 0; i < peopleInfo.Count; i++) 44 { 45 m_user.RowGuid = Guid.NewGuid().ToString();//人員唯一標識 46 m_user.LoginID = PostedData.PersonData[i].Identity;//登錄名為身份證號碼 47 m_user.Password = common.authPassword("111111");//密碼 48 m_user.DanWeiGuid = m_unit.RowGuid;//單位Guid 49 m_user.DanWeiName = m_unit.DanWeiName;//單位名稱 50 m_user.Name = PostedData.PersonData[i].Name;//人員姓名 51 if (PostedData.PersonData[i].Sex == "男")//性別 52 m_user.Sex = "0"; 53 else 54 m_user.Sex = "1"; 55 m_user.IdentityNum = PostedData.PersonData[i].Identity;//身份證號 56 m_user.BirthDay =Convert.ToDateTime(PostedData.PersonData[i].Brithday);//出生日期 57 m_user.MobilePhone = PostedData.PersonData[i].Phone;//手機號 58 m_user.AddType = "2";//帳號添加方式 1-注冊 2-企業添加 3-后台添加 59 m_user.UserType = "0";//會員類別 0-個人 1-企業 2-學校 3-培訓機構 60 m_user.IsEnable = "1"; 61 m_user.DelFlag = "0"; 62 m_user.Status = "2";//會員狀態 63 m_user.IdentityType = "111";//身份證 64 b_user.Insert(m_user); 65 66 m_baom.RowGuid = Guid.NewGuid().ToString();//報名唯一標識 67 m_baom.BMType = "2";//報名類別 68 m_baom.AddDate = m_baom.OperateDate = DateTime.Now;//報名日期 69 m_baom.Name = m_user.Name;//姓名 70 m_baom.LoginID = m_user.LoginID;//登錄名 71 m_baom.UserGuid = m_user.RowGuid;//人員Guid 72 m_baom.PlanGuid = PlanGuid;//計划Guid 73 m_baom.DanWeiGuid = m_unit.RowGuid;//單位Guid 74 m_baom.DanWeiName = m_unit.DanWeiName;//單位名稱 75 m_baom.BaoMDNum = m_unit.BelongFenJu;//報名點 --所屬分局 76 b_baom.Insert(m_baom); 77 } 78 } 79 #endregion 80 result = "1"; 81 } 82 catch (Exception ex) 83 { 84 result = "0"; 85 } 86 context.Response.ContentType = "text/plain"; 87 context.Response.Write(result); 88 } 89 90 public bool IsReusable 91 { 92 get 93 { 94 return false; 95 } 96 } 97 98 public string ConvertToPY(string Text) 99 { 100 char[] chText = Text.ToCharArray(); 101 string pyText = ""; 102 foreach (char ch in chText) 103 { 104 pyText += new ChineseChar(ch).Pinyins[0].Substring(0, 1); 105 } 106 return pyText; 107 } 108 109 public class RequestDataJSON 110 { 111 public string DanWeiName { get; set; } 112 public string DetailAddress { get; set; } 113 public string BelongFenJu { get; set; } 114 public List<PersonDataJSON> PersonData; 115 116 } 117 public class PersonDataJSON 118 {//人員 119 public string Name { get; set; } 120 public string Sex { get; set; } 121 public string Identity { get; set; } 122 public string Brithday { get; set; } 123 public string Phone { get; set; } 124 } 125 }
