Example #1
0
        /// <summary>
        /// 保存点检项和设备关系
        /// </summary>
        /// <param name="sbNodeKey"></param>
        /// <param name="item_ID_KEY"></param>
        private void SaveRelation(string sbNodeKey, string id_key_new, string id_key_old)
        {
            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 (id_key_new != "")
            {
                if (id_key_new.Contains(','))
                {
                    res = id_key_new.TrimEnd(',');

                    if (res.Contains(','))
                    {
                        aID = res.Split(',');
                    }
                    else
                    {
                        aID    = new string[1];
                        aID[0] = res;
                    }
                }
            }

            if (id_key_old != "")
            {
                if (id_key_old.Contains(','))
                {
                    res = id_key_old.TrimEnd(',');

                    if (res.Contains(','))
                    {
                        cID = res.Split(',');
                    }
                    else
                    {
                        cID    = new string[1];
                        cID[0] = res;
                    }
                }
            }

            if (cID != null)
            {
                for (int i = 0; i < cID.Length; i++)
                {
                    if (aID != null)
                    {
                        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] + ',';    //需要删除的记录
                        }
                    }
                    else
                    {
                        oRes += cID[i] + ',';
                    }
                }
            }

            if (aID != null)
            {
                for (int j = 0; j < aID.Length; j++)
                {
                    if (cID != null)
                    {
                        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] + ',';    //需要添加的记录
                        }
                    }
                    else
                    {
                        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.AddDeviceAndItemRealtion(sbNodeKey, oArea, iArea, out errMsg);

            if (oRes != "" || iRes != "")
            {
                if (errMsg == "")
                {
                    if (flag == true)
                    {
                        info = "添加成功!";
                    }
                    else
                    {
                        info = "添加失败!";
                    }
                }
                else
                {
                    info = errMsg;
                }
            }
            else
            {
                info = "请先选择设备,然后在操作!";
            }

            obj = new
            {
                msg = info
            };
            string result = Newtonsoft.Json.JsonConvert.SerializeObject(obj);

            Response.Write(result);
            Response.End();
        }