Beispiel #1
0
        public static string edit_ItemJsonString(string item_json, string msg_default = "")
        {
            string json = msg_default;

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

                int index = list_DCU.FindIndex(o => o.dcu_id == m.dcu_id);
                if (index != -1)
                {
                    m_dcu u = list_DCU[index];
                    u.name    = m.name;
                    u.note    = m.note;
                    u.address = m.address;

                    lock (lock_list)
                        list_DCU[index] = u;

                    update();

                    json = JsonConvert.SerializeObject(u);
                }
            }
            catch { }

            return(json);
        }
Beispiel #2
0
        public static Tuple <bool, string, dynamic> edit(string s_key, string s_item)
        {
            string json = "";

            try
            {
                m_dcu m = JsonConvert.DeserializeObject <m_dcu>(s_item);

                int index = list_DCU.FindIndex(o => o.dcu_id == m.dcu_id);
                if (index != -1)
                {
                    m_dcu u = list_DCU[index];
                    u.name    = m.name;
                    u.note    = m.note;
                    u.address = m.address;

                    lock (lock_list)
                        list_DCU[index] = u;

                    update();

                    json = JsonConvert.SerializeObject(u);
                }

                return(new Tuple <bool, string, dynamic>(true, json, m));
            }
            catch { }
            return(new Tuple <bool, string, dynamic>(false, "", null));
        }
Beispiel #3
0
        public static Tuple <int, string> get_ItemJsonBy_search(string keyword, int page_number, int page_size)
        {
            var ls = list_DCU.Where(o => o.status == true).Where(x =>
                                                                 (x.dcu_id.ToString().Contains(keyword)) ||
                                                                 (x.name != null && x.name.Contains(keyword)) ||
                                                                 (x.note != null && x.note.Contains(keyword)) ||
                                                                 (x.address != null && x.address.Contains(keyword))
                                                                 ).ToList();

            dynamic dt;

            if (ls.Count > page_size)
            {
                int startRowIndex = page_size * (page_number - 1);
                dt = ls.Skip(startRowIndex).Take(page_size).ToList();
            }
            else
            {
                dt = ls;
            }

            for (int k = 0; k < dt.Count; k++)
            {
                m_dcu item = dt[k];
                //item.itemsub_count = store.f_dcu_meter_count(list[k].dcu_id);
                dt[k] = item;
            }

            string json = JsonConvert.SerializeObject(dt);

            return(new Tuple <int, string>(ls.Count, json));
        }
Beispiel #4
0
        public static string add_ItemJson(long dcu_id, string name, string msg_default = "")
        {
            string json = msg_default;

            int index = list_DCU.FindIndex(o => o.dcu_id == dcu_id);

            if (index == -1)
            {
                m_dcu item = new m_dcu()
                {
                    dcu_id    = dcu_id,
                    name      = name,
                    status    = false,
                    is_online = true
                };

                lock (lock_list)
                    list_DCU.Add(item);

                update();

                json = JsonConvert.SerializeObject(list_DCU);
            }

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

                var json_obj = JsonConvert.DeserializeObject <m_dcu>(s_item);

                int index = list_DCU.FindIndex(o => o.dcu_id == json_obj.dcu_id);
                if (index == -1)
                {
                    m_dcu item = new m_dcu()
                    {
                        dcu_id    = json_obj.dcu_id,
                        name      = json_obj.name,
                        status    = true,
                        is_online = true
                    };

                    lock (lock_list)
                        list_DCU.Add(item);

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

            catch { }

            return(new Tuple <bool, string, dynamic>(false, "", null));
        }
Beispiel #6
0
        public static void load()
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string path_file = path + file_name + ".mmf";

            list_DCU = hostFile.read_file_MMF <m_dcu>(path_file).ToList();

            for (int k = 0; k < list_DCU.Count; k++)
            {
                m_dcu it = list_DCU[k];
                it.is_online = false;
                list_DCU[k]  = it;
            }

            path_file = path + file_name + "_meter.mmf";
            var a = hostFile.read_file_MMF <Tuple <long, long[]> >(path_file);

            for (int k = 0; k < a.Length; k++)
            {
                var o = a[k];
                lock (lock_index)
                    dic_DCU_meter.AddListDistinct(o.Item1, o.Item2);
            }
        }
Beispiel #7
0
        private static string get_allJson_true(int page_number, int page_size)
        {
            int startRowIndex = page_size * (page_number - 1);
            var dt            = list_DCU.Where(o => o.status == true).Skip(startRowIndex).Take(page_size).ToList();

            for (int k = 0; k < dt.Count; k++)
            {
                m_dcu item = dt[k];
                //item.itemsub_count = store.f_dcu_meter_count(list[k].dcu_id);
                dt[k] = item;
            }

            return(JsonConvert.SerializeObject(dt));
        }
Beispiel #8
0
        public static string get_ItemJson(long dcu_id, string msg_default = "")
        {
            string json = msg_default;

            int pos = list_DCU.FindIndex(o => o.dcu_id == dcu_id);

            if (pos != -1)
            {
                m_dcu o = list_DCU[pos];
                //o.cat_array = store.f_meter_get_by_dcu_array(dcu_id);

                json = JsonConvert.SerializeObject(o);
            }

            return(json);
        }
Beispiel #9
0
        public static void add_Item(long dcu_id, string name, string type_code)
        {
            int index = list_DCU.FindIndex(o => o.dcu_id == dcu_id);

            if (index == -1)
            {
                m_dcu item = new m_dcu()
                {
                    dcu_id    = dcu_id,
                    name      = name,
                    status    = true,
                    is_online = true
                };

                lock (lock_list)
                    list_DCU.Add(item);

                update();
            }
        }
Beispiel #10
0
        public static bool updateStatusOnline(long dcu_id)
        {
            int index = list_DCU.FindIndex(o => o.dcu_id == dcu_id);

            if (index != -1)
            {
                m_dcu item = list_DCU[index];
                int   date = DateTime.Now.ToString("yyMMdd").TryParseToInt();

                if (item.date_update_lastest != date || item.is_online == false)
                {
                    item.is_online           = true;
                    item.date_update_lastest = date;

                    list_DCU[index] = item;

                    update();

                    return(true);
                }
                else
                {
                    if (item.date_update_lastest == date && item.is_online == false)
                    {
                        item.is_online           = true;
                        item.date_update_lastest = date;

                        list_DCU[index] = item;

                        update();

                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #11
0
        public static string changeStatus(string key, string msg_default = "")
        {
            string json = msg_default;
            long   id   = key.TryParseToLong();

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

                        lock (lock_list)
                            list_DCU[index] = u;

                        update();

                        json = JsonConvert.SerializeObject(u);
                    }
                }
                catch { }
            }
            return(json);
        }