/// <summary> /// 线路关联区域 /// </summary> /// <param name="nodeKey">线路nodeKey</param> /// <param name="areaID">选择后的AREAID</param> /// <param name="chkID">已选择的AREAID </param> private void AddAreaInfo(string nodeKey, string areaID, string chkID) { string res = ""; string oRes = ""; string iRes = ""; string info = ""; bool flag = false; string[] aID = null; //选择后的AREAID数组 string[] cID = null; //已选择的AREAID数组 string[] iArea = null; //添加数组 string[] oArea = null; //删除数组 if (areaID == "" && chkID == "") { info = "请选择在点保存!"; } else { if (areaID.Contains(',')) { res = areaID.TrimEnd(','); if (res.Contains(',')) { aID = res.Split(','); } else { aID = new string[1]; aID[0] = res; } } if (chkID.Contains(',')) { res = chkID.TrimEnd(','); if (res.Contains(',')) { cID = res.Split(','); } else { cID = new string[1]; cID[0] = res; } } if (aID == null) { oArea = cID; } //选择后AREAID为null,要删除所有已选择区域 else if (cID == null) { iArea = aID; } //选择前AREAID为null,要添加所有已选择区域 else { for (int i = 0; i < cID.Length; i++) { int con = 0; for (int j = 0; j < aID.Length; j++) { if (cID[i] == aID[j]) { con = 1; break; } } if (con == 0) { oRes += cID[i] + ','; //需要删除的记录 } } for (int j = 0; j < aID.Length; j++) { int con = 0; for (int i = 0; i < cID.Length; i++) { if (aID[j] == cID[i]) { con = 1; break; } } if (con == 0) { iRes += aID[j] + ','; //需要添加的记录 } } if (oRes != "") { oRes = oRes.TrimEnd(','); if (oRes.Contains(',')) { oArea = oRes.Split(','); } else { oArea = new string[1]; oArea[0] = oRes; } } if (iRes != "") { iRes = iRes.TrimEnd(','); if (iRes.Contains(',')) { iArea = iRes.Split(','); } else { iArea = new string[1]; iArea[0] = iRes; } } } flag = bmr.AddLineAndAreaRealtion(nodeKey, oArea, iArea, "QY", out errMsg); if (errMsg == "") { if (flag == true) { info = "添加成功!"; } else { info = "添加失败!"; } } else { info = errMsg; } obj = new { msg = info }; string result = JsonConvert.SerializeObject(obj); Response.Write(result); Response.End(); } }