public static Tuple <bool, string, dynamic> edit(string s_key, string s_item)
        {
            try
            {
                string json = "";

                m_meter m = JsonConvert.DeserializeObject <m_meter>(s_item);

                int index = list.FindIndex(o => o.cus_id == m.cus_id);
                if (index != -1)
                {
                    m_meter u = list[index];



                    u.address      = m.address;
                    u.cus_code     = m.cus_code;
                    u.cus_code_fix = m.cus_code_fix;

                    u.date_down = m.date_down;
                    u.date_up   = m.date_up;
                    u.email     = m.email;
                    u.fullname  = m.fullname;
                    u.meter_id  = m.meter_id;
                    u.name      = m.name;
                    u.note      = m.note;
                    u.phone     = m.phone;
                    u.type      = m.type;

                    if (m.index == 0)
                    {
                        u.index = list.Count + 1;
                    }
                    else
                    {
                        u.index = m.index;
                    }

                    u.type_code = m.type_code;
                    u.phase_id  = m.phase_id;
                    u.dcu_id    = m.dcu_id;
                    lock (lock_list)
                        list[index] = u;

                    update();



                    json = JsonConvert.SerializeObject(u);
                    long   dcu_id = u.dcu_id;
                    string s      = db_dcu.get_ItemJson(dcu_id);
                    json = json.Replace(@"""dcu_id"":" + dcu_id.ToString() + ",", @"""dcu_id"":" + s + ",");

                    return(new Tuple <bool, string, dynamic>(true, json, m));
                }
            }

            catch { }
            return(new Tuple <bool, string, dynamic>(false, "", null));
        }
        public static string edit_ItemChange_meter(string cus_id_string, string msg_default = "")
        {
            string json = msg_default;

            string[] a = cus_id_string.Split('|');

            int pos0 = list.FindIndex(m => m.cus_id == a[0]);
            int pos1 = list.FindIndex(m => m.meter_id == a[1].TryParseToLong());

            if (pos0 != -1 && pos1 != -1)
            {
                m_meter m0 = list[pos0];
                m_meter m1 = list[pos1];

                long mid = m0.meter_id;
                m0.meter_id = m1.meter_id;
                m1.meter_id = mid;

                lock (lock_list)
                {
                    list[pos0] = m0;
                    list[pos1] = m1;
                }

                update();

                json = JsonConvert.SerializeObject(m0);
                long   dcu_id = m0.dcu_id;
                string s      = db_dcu.get_ItemJson(dcu_id);
                json = json.Replace(@"""dcu_id"":" + dcu_id.ToString() + ",", @"""dcu_id"":" + s + ",");
            }

            return(json);
        }
        public static void add_Items(m_meter item)
        {
            int pos = list.FindIndex(x => x.meter_id == item.meter_id);

            if (pos == -1)
            {
                lock (lock_list)
                {
                    list.Add(item);
                    update();
                }
            }
        }
        public static string edit_ItemJsonString(string item_json, string msg_default = "")
        {
            string json = msg_default;

            try
            {
                m_meter m = JsonConvert.DeserializeObject <m_meter>(item_json);

                int index = list.FindIndex(o => o.cus_id == m.cus_id);
                if (index != -1)
                {
                    m_meter u = list[index];


                    u.address      = m.address;
                    u.cus_code     = m.cus_code;
                    u.cus_code_fix = m.cus_code_fix;

                    u.date_down = m.date_down;
                    u.date_up   = m.date_up;
                    u.email     = m.email;
                    u.fullname  = m.fullname;
                    u.index     = m.index;
                    u.meter_id  = m.meter_id;
                    u.name      = m.name;
                    u.note      = m.note;
                    u.phone     = m.phone;
                    u.type      = m.type;
                    u.type_code = m.type_code;

                    lock (lock_list)
                        list[index] = u;

                    update();

                    json = JsonConvert.SerializeObject(u);
                    long   dcu_id = u.dcu_id;
                    string s      = db_dcu.get_ItemJson(dcu_id);
                    json = json.Replace(@"""dcu_id"":" + dcu_id.ToString() + ",", @"""dcu_id"":" + s + ",");
                }
            }
            catch { }

            return(json);
        }
        public static Tuple <bool, string, dynamic> add(string s_key, string s_item)
        {
            try
            {
                string json = "";

                m_meter m = JsonConvert.DeserializeObject <m_meter>(s_item);

                //100000000014

                int index = list.FindIndex(o => o.cus_code == m.cus_code || o.meter_id == m.meter_id);
                if (index == -1)
                {
                    //m.dcu_id = m.dcu_id;
                    //m.meter_id = m.meter_id;

                    m.cus_id    = Guid.NewGuid().ToString();
                    m.date_up   = DateTime.Now.ToString("yyMMdd").TryParseToInt();
                    m.is_online = false;
                    if (m.index == 0)
                    {
                        m.index = list.Count + 1;
                    }
                    m.status = true;

                    lock (lock_list)
                        list.Add(m);

                    //store.f_meter_set_by_dcu(m.dcu_id, m.meter_id);

                    update();



                    json = JsonConvert.SerializeObject(m);
                }

                return(new Tuple <bool, string, dynamic>(true, json, m));
            }

            catch { }

            return(new Tuple <bool, string, dynamic>(false, "", null));
        }
        public static string changeStatus(string key, string msg_default = "")
        {
            string json = msg_default;
            long   id   = key.TryParseToLong();

            if (id > 0)
            {
                try
                {
                    int index = list.FindIndex(o => o.meter_id == id);
                    if (index != -1)
                    {
                        m_meter u      = list[index];
                        bool    status = false;
                        if (u.status)
                        {
                            status = false;
                        }
                        else
                        {
                            status = true;
                        }
                        u.status = status;

                        lock (lock_list)
                            list[index] = u;

                        update();

                        json = JsonConvert.SerializeObject(u);
                        long   dcu_id = u.dcu_id;
                        string s      = db_dcu.get_ItemJson(dcu_id);
                        json = json.Replace(@"""dcu_id"":" + dcu_id.ToString() + ",", @"""dcu_id"":" + s + ",");
                    }
                }
                catch { }
            }
            return(json);
        }
        public static void edit_dcu_id(Dictionary <long, long> dic_meter_dcu)
        {
            long[] a_meter = dic_meter_dcu.Keys.ToArray();
            bool   ok      = false;

            for (int k = 0; k < a_meter.Length; k++)
            {
                long mid = a_meter[k];
                int  pos = list.FindIndex(x => x.meter_id == mid);
                if (pos != -1)
                {
                    ok = true;
                    m_meter m = list[pos];
                    m.dcu_id = dic_meter_dcu[mid];
                    lock (lock_list)
                        list[pos] = m;
                }
            }

            if (ok)
            {
                update();
            }
        }
        public static void edit_dcu_id(Tuple <long, long>[] dic_meter_dcu)
        {
            long[] a_meter = dic_meter_dcu.Select(x => x.Item1).ToArray();
            bool   ok      = false;

            for (int k = 0; k < a_meter.Length; k++)
            {
                long mid = a_meter[k];
                int  pos = list.FindIndex(x => x.meter_id == mid);
                if (pos != -1)
                {
                    ok = true;
                    m_meter m = list[pos];
                    m.dcu_id = dic_meter_dcu[k].Item2;
                    lock (lock_list)
                        list[pos] = m;
                }
            }

            if (ok)
            {
                update();
            }
        }