Ejemplo n.º 1
0
        public static void Add(MhxyType mt)
        {
            SQLiteConnection conn = SQLiteUtil.GetConn();

            conn.Open();
            string sql = "INSERT INTO mhxy_type (type_id, name, is_show,prefix,filert_rule) VALUES(@type_id, @name, @is_show,@prefix,@filert_rule)";

            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@type_id",     DbType.Int32,   4),
                new SQLiteParameter("@name",        DbType.String),
                new SQLiteParameter("@is_show",     DbType.Int32,   4),
                new SQLiteParameter("@prefix",      DbType.String),
                new SQLiteParameter("@filert_rule", DbType.String)
            };
            parameters[0].Value = mt.TypeId;
            parameters[1].Value = mt.Name;
            parameters[2].Value = mt.IsShow;
            parameters[3].Value = mt.prefix;
            parameters[4].Value = mt.filertRule;
            SQLiteCommand cmd = SQLiteHelper.CreateCommand(conn, sql, parameters);

            cmd.ExecuteNonQuery();
            conn.Close();
        }
Ejemplo n.º 2
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            if (txtId.Text.Trim() == "" || txtName.Text.Trim() == "")
            {
                return;
            }



            model.MhxyType mt = new model.MhxyType();
            mt.TypeId     = Convert.ToInt32(txtId.Text.Trim());
            mt.Name       = txtName.Text.Trim();
            mt.IsShow     = cbxShow.Checked == true ? 1 : 0;
            mt.prefix     = StringUtil.FormatIntToHexStyle(mt.TypeId, false);
            mt.filertRule = txt_rule.Text.Trim();
            bool exit = model.MhxyType.CheckTypeId(mt.TypeId);

            if (exit)
            {
                MessageBox.Show("已添加!");
                return;
            }
            model.MhxyType.Add(mt);
            lv_type.Items.Clear();
            lv_type.ItemChecked -= lv_typeCheckChange;
            loadDB();
            frmMain.loadType();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 判断数据包是否显示
        /// </summary>
        /// <param name="data"></param>
        /// <param name="recvType"></param>
        /// <returns>默认显示,过滤已配置的数据包</returns>
        public bool FilertMsgData(byte[] data, int t)
        {
            int recvType = data[0];

            //存在处理判断规则
            if (mapFilert.ContainsKey(recvType))
            {
                model.MhxyType mt = mapFilert[recvType];
                if (mt.IsShow == 1)
                {
                    return(false);
                }
                string[] rule = mt.filertRule.Split(']');
                //获取规则组
                for (int i = 0; i < rule.Length; i++)
                {
                    if (rule[i].Trim() == "")
                    {
                        continue;
                    }
                    //[7=48,6=49]
                    //取出条件匹配是否满足
                    string[] r    = rule[i].Replace("[", "").Split(',');
                    bool     flag = true;
                    //判断规则里面的条件
                    for (int k = 0; k < r.Length; k++)
                    {
                        string[] ret = r[k].Split('=');
                        int      idx = Convert.ToInt32(ret[0]);
                        //处理下标越界
                        if (idx > data.Length - 1)
                        {
                            //中断当前循环,重置标志位
                            flag = true;
                            break;
                        }
                        int val = Convert.ToInt32(ret[1], 16);
                        //判断配置条件
                        if (data[idx] != val)
                        {
                            flag = false;
                        }
                    }
                    //已经匹配到不显示的规则
                    if (flag)
                    {
                        return(false);
                    }
                }
            }


            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取全部数据
        /// </summary>
        /// <returns></returns>
        public static List <MhxyType> GetAll()
        {
            string           sql  = "select * from mhxy_type";
            SQLiteConnection conn = SQLiteUtil.GetConn();

            conn.Open();
            DataSet ds = SQLiteHelper.ExecuteDataSet(conn, sql, null);

            conn.Close();
            List <MhxyType> ret = new List <MhxyType>();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                MhxyType mt = new MhxyType();
                mt.TypeId     = Convert.ToInt32(ds.Tables[0].Rows[i]["type_id"].ToString());
                mt.Name       = ds.Tables[0].Rows[i]["name"].ToString();
                mt.IsShow     = Convert.ToInt32(ds.Tables[0].Rows[i]["is_show"].ToString());
                mt.prefix     = ds.Tables[0].Rows[i]["prefix"].ToString();
                mt.filertRule = ds.Tables[0].Rows[i]["filert_rule"].ToString();
                ret.Add(mt);
            }
            return(ret);
        }