public static m_column get_ItemByID(int data_type, int colunm_index)
        {
            m_column o = new m_column();

            Tuple <int, int> key = new Tuple <int, int>(data_type, colunm_index);

            dic_column.TryGetValue(key, out o);

            return(o);
        }
Exemple #2
0
        private void bUpdate_Config_Click(object sender, EventArgs e)
        {
            m_column co = db_column.get_ItemByID(data_type, index);

            if (!string.IsNullOrEmpty(co.col_id))
            {
                co.code  = txt_code.Text.ToAscii().ToLower().Trim();
                co.name  = txt_name.Text.ToAscii().ToLower().Trim();
                co.title = txt_title.Text.Trim();

                co.div10n = txt_div10n.Text.Trim().TryParseToInt();
                co.note   = txt_note.Text;

                co.value_max = txt_value_max.Text.TryParseToInt();
                co.value_min = txt_value_min.Text.TryParseToInt();

                co.index_date  = check_index_date.Checked;
                co.index_time  = check_index_time.Checked;
                co.progressive = check_progressive.Checked;

                string s_data_join = "";
                if (check_data_join_meter.Checked)
                {
                    s_data_join = "meter";
                }
                if (check_data_join_meter_updown.Checked)
                {
                    if (s_data_join == "")
                    {
                        s_data_join = "updown";
                    }
                    else
                    {
                        s_data_join += ";updown";
                    }
                }
                co.data_join = s_data_join;
            }

            var rs = db_column.edit_Item(co);

            if (rs)
            {
                update_ok = true;
                OnEventUpdated(new Column_Edit_EventArgs()
                {
                    result = true, data_type = data_type
                });
                this.Close();
            }
        }
        public static bool edit_Item(m_column o)
        {
            Tuple <int, int> key = new Tuple <int, int>(o.data_type, o.index);

            if (dic_column.ContainsKey(key))
            {
                lock (lock_write)
                {
                    dic_column[key] = o;
                    update(o.data_type);
                }
                return(true);
            }
            return(false);
        }
        public static bool add_Item(m_column o)
        {
            Tuple <int, int> key = new Tuple <int, int>(o.data_type, o.index);

            if (dic_column.ContainsKey(key) == false)
            {
                lock (lock_write)
                {
                    o.col_id = Guid.NewGuid().ToString();
                    dic_column.Add(key, o);
                    update(o.data_type);
                }
                return(true);
            }
            return(false);
        }
Exemple #5
0
        private void fColumn_Edit_Load(object sender, EventArgs e)
        {
            m_column co = db_column.get_ItemByID(data_type, index);

            if (!string.IsNullOrEmpty(co.col_id))
            {
                lbl_data_type.Text = co.data_type.ToString();
                lbl_index.Text     = co.index.ToString();

                txt_code.Text   = co.code;
                txt_div10n.Text = co.div10n.ToString();
                txt_name.Text   = co.name;

                txt_note.Text  = co.note;
                txt_title.Text = co.title;

                txt_value_max.Text = co.value_max.ToString();
                txt_value_min.Text = co.value_min.ToString();

                check_index_date.Checked  = co.index_date;
                check_index_time.Checked  = co.index_time;
                check_progressive.Checked = co.progressive;

                string s_data_join = co.data_join;
                if (!string.IsNullOrEmpty(s_data_join))
                {
                    if (s_data_join.IndexOf("meter") != -1)
                    {
                        check_data_join_meter.Checked = true;
                    }

                    if (s_data_join.IndexOf("updown") != -1)
                    {
                        check_data_join_meter_updown.Checked = true;
                    }
                }
            }
        }
        private static string convert_Item2TD(
            string tem_item,
            string tem_item_def,
            string[] cols_select,
            Dictionary <int, m_column[]> dic_type_col,
            decimal[] ar, int id)
        {
            string tr = tem_item_def;

            if (id == 252)
            {
                tr = tem_item_def;
            }

            int d_type = (int)ar[0];

            d2_data data_type = d2_data._;

            switch (d_type.ToString().Length)
            {
            case 6:
                data_type = (d2_data)(d_type.ToString().Substring(0, 1).TryParseToInt() * 100000);
                break;

            case 7:
                data_type = (d2_data)(d_type.ToString().Substring(1, 1).TryParseToInt() * 100000);
                break;
            }

            m_column[] a_col = new m_column[] { };
            if (dic_type_col.TryGetValue(d_type, out a_col))
            {
                tr = tem_item;
                string ss  = "";
                int    len = ar.Length;
                for (int k = 0; k < a_col.Length; k++)
                {
                    try
                    {
                        string val   = "-";
                        int    index = a_col[k].index;
                        if (index < len)
                        {
                            val = ar[k].ToString();
                            int div10n = a_col[k].div10n;
                            if (div10n > 0)
                            {
                                val = ((decimal)ar[k] / div10n).ToString("0,0.00");
                            }
                        }


                        string code = a_col[k].code;
                        switch (code)
                        {
                        case "device_id":
                        case "meter_id":
                            tr = tr.Replace("{{device_id}}", val)
                                 .Replace("{{meter_id}}", val);
                            break;

                        case "yyyyMMdd":
                            tr = tr.Replace("{{yyyyMMdd}}", "&nbsp;" + f_yyyyMMdd(data_type, val));
                            break;

                        case "HHmmss":
                            tr = tr.Replace("{{HHmmss}}", "&nbsp;" + f_HHmmss(data_type, val));
                            break;

                        default:
                            tr = tr.Replace("{{" + a_col[k].code + "}}", val);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        ss = ex.Message + k.ToString();
                    }
                }

                tr = tr.Replace(col_index_key, (id + 1).ToString());
            }

            return(tr);
        }
        private static string convert_Item2Json(
            string[] cols_select, Dictionary <int, m_column[]> dic_type_col,
            decimal[] ar, int id)
        {
            try
            {
                #region

                long me_id = (long)ar[3];
                if (me_id < 1000000)
                {
                    return("");
                }

                int        d_type = (int)ar[0];
                m_column[] a_col  = new m_column[] { };
                if (dic_type_col.TryGetValue(d_type, out a_col))
                {
                    string   error_Parse = "";
                    string[] lii         = new string[] { };

                    #region /// process cols ...

                    d4_tech tech = d4_tech._;
                    if (ar.Length > 9)
                    {
                        tech = (d4_tech)ar[9];
                    }

                    int    len_val  = a_col.Length - ar.Length;
                    string col_miss = "";
                    if (len_val > 0)
                    {
                        for (int x = 0; x < len_val; x++)
                        {
                            m_column cx = a_col[x + ar.Length];
                            col_miss += @",""" + cx.code + @""":""-""";
                        }
                    }

                    lii = ar.Zip(a_col, (val, col) =>
                    {
                        #region // ...

                        string sii = "";
                        object rso = "";

                        if (col.code.Length == 2)
                        {
                            error_Parse = "config data type " + d_type.ToString();
                            return(@"""_x" + col.code + @""":" + val.ToString());
                        }
                        else
                        {
                            #region //...

                            try
                            {
                                if (d_type > 999)
                                {
                                    switch (col.index)
                                    {
                                    case 6:
                                        rso = @"""" + ((d1_pha)val).ToString() + @"""";
                                        break;

                                    case 7:
                                        rso = @"""" + ((d2_data)val).ToString() + @"""";
                                        break;

                                    case 8:
                                        rso = @"""" + ((d4_tech)val).ToString() + @"""";
                                        break;

                                    case 9:
                                        rso = @"""" + ((d5_nsx)val).ToString() + @"""";
                                        break;

                                    default:
                                        int div10n = col.div10n;
                                        if (div10n > 0)
                                        {
                                            rso = (decimal)val / div10n;
                                        }
                                        else
                                        {
                                            rso = (decimal)val;
                                        }
                                        break;
                                    }
                                }
                                else
                                {
                                    rso = (decimal)val;
                                }

                                sii = @"""" + col.code + @""":" + rso.ToString();
                            }
                            catch (Exception ex)
                            {
                                error_Parse = ex.ToString();
                                return(@"""" + col.code + @"_error"":""" + val.ToString() + "|" + error_Parse + @"""");
                            }

                            #endregion
                        }
                        return(sii);

                        #endregion
                    }).ToArray();

                    #endregion

                    string s_stt_export = "";
                    if (error_Parse == "")
                    {
                        s_stt_export = @"""__ok"":true, ";
                    }
                    else
                    {
                        s_stt_export = @"""__ok"":false, ""__msg"":""" + error_Parse + @""", ";
                    }

                    string json = "";
                    if (lii.Length > 0)
                    {
                        json = "{" + s_stt_export + string.Join(",", lii) + col_miss + "}";
                    }
                    return(json);
                }

                #endregion
            }
            catch (Exception ex)
            {
                return("{" +
                       @"""msg"":""" +
                       ex.Message.Replace(":", "").Replace("\\", "").Replace(@"""", "") + @""", " +
                       @"""data"":" + JsonConvert.SerializeObject(ar) +
                       "}");
            }

            return("");
        }