/// <summary> /// 获得自己的信息,包括设置,以及父标签和子标签集合 /// </summary> public void GetTagInfo() { List <TagInfo> list_result = new List <TagInfo>(); string str_sql = $"select * from 数据解析库.内容标签表 " + $"where 删除=0 and 名称='{_mingcheng}' and 库名='{_kuming}'"; DataRow mydr = MySqlHelper.ExecuteDataRow(SystemInfo._strConn, str_sql); _jibie = Convert.ToInt32(mydr["级别"].ToString()); _biaoqianSet = mydr["设置"].ToString(); _chuangjianren = mydr["创建人"].ToString(); _chuangjianshijian = mydr["创建时间"].ToString(); _parentName = mydr["父标签名"].ToString(); //GetParentNode(); GetChildNodes(); TagRoot root = JsonConvert.DeserializeObject <TagRoot>(_biaoqianSet); }
/// <summary> /// 获得父节点 /// </summary> public void GetParentNode() { //先判断是否是内容标签,内容标签没有父节点 if (_parentName.Equals("无")) { return; } string str_sql = $"select * from 数据解析库.内容标签表 " + $"where 删除=0 and 名称='{_parentName}' and 库名='{_kuming}'"; DataRow mydr = MySqlHelper.ExecuteDataRow(SystemInfo._strConn, str_sql); _parent._kuming = mydr["库名"].ToString(); _parent._mingcheng = mydr["名称"].ToString(); _parent._jibie = Convert.ToInt32(mydr["级别"].ToString()); _parent._biaoqianSet = mydr["设置"].ToString(); _parent._chuangjianren = mydr["创建人"].ToString(); _parent._chuangjianshijian = mydr["创建时间"].ToString(); _parent._parentName = mydr["父标签名"].ToString(); TagRoot root = JsonConvert.DeserializeObject <TagRoot>(_parent._biaoqianSet); _parent._tagRoot = root; }
/// <summary> /// 获得节点的所有子节点信息 /// </summary> /// <returns></returns> public void GetChildNodes() { List <TagInfo> list_result = new List <TagInfo>(); string str_sql = $"select * from 数据解析库.内容标签表 " + $"where 删除=0 and 父标签名='{_mingcheng}' and 库名='{_kuming}'"; DataTable mydt = MySqlHelper.ExecuteDataset(SystemInfo._strConn, str_sql).Tables[0]; for (int i = 0; i < mydt.Rows.Count; i++) { DataRow mydr = mydt.Rows[i]; TagInfo myinfo = new TagInfo( mydr["名称"].ToString(), this ) { }; TagRoot root = JsonConvert.DeserializeObject <TagRoot>(myinfo._biaoqianSet); myinfo._tagRoot = root; _childNodes.Add(myinfo); } }
/// <summary> /// 点击保存按钮时触发的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lbl_baocun_Click(object sender, EventArgs e) { //构造一个biaoqianinfo实例,保存在数据库中内容标签表 TagRoot _bqRoot = new TagRoot() { shuoming = tb_shuoming.Text, zhengze = tb_zhengze.Text, shunshu = Convert.ToInt32(tb_shunshu.Text), daoshu = Convert.ToInt32(tb_daoshu.Text), gudingzhi = tb_gudingzhi.Text, jushouzhi = tb_jushouzhi.Text, juzhongzhi = tb_juzhongzhi.Text, juweizhi = tb_juweizhi.Text, weizhiqian0 = tb_weizhiqian0.Text, weizhiqian1 = tb_weizhiqian1.Text, weizhihou0 = tb_weizhihou0.Text, weizhihou1 = tb_weizhihou1.Text, zhengzetiqu = tb_zhengzetiqu.Text, }; foreach (Control c in panel_neirong.Controls) { if (c is CheckBox && (c as CheckBox).Checked == true) { _bqRoot.list_leibie.Add(c.Text); } } foreach (Control c in flp_weizhi.Controls) { if (c is CheckBox && (c as CheckBox).Checked == true) { _bqRoot.list_position.Add(c.Text); } } foreach (Control c in flp_pipeidu.Controls) { if (c is CheckBox && (c as CheckBox).Checked == true) { _bqRoot.list_pipei.Add(c.Text); } } foreach (Control c in flp_jiedian.Controls) { if (c is CheckBox && (c as CheckBox).Checked == true) { _bqRoot.list_neirong.Add(c.Text); } } foreach (Control c in flp_yupian.Controls) { if (c is CheckBox && (c as CheckBox).Checked == true) { _bqRoot.list_yupian.Add(c.Text); } } string _bqSetJson = JsonConvert.SerializeObject(_bqRoot); //如果是新建一个标签,那么父标签是有实例传进来的,而自身的tagInfo没有 //如果是编辑标签,那么父标签是没有实例的,而自身的tagInfo有值 if (_parentInfo != null) { _tagInfo = new TagInfo() { }; _tagInfo._kuming = _parentInfo._kuming; _tagInfo._mingcheng = tb_mingcheng.Text; _tagInfo._jibie = _parentInfo._jibie + 1; //_tagInfo._fubiaoqianming = _parentInfo._mingcheng; _tagInfo._biaoqianSet = _bqSetJson; _tagInfo._chuangjianren = SystemInfo._userInfo._shiming; _tagInfo._chuangjianshijian = DateTime.Now.ToString("yyyy-MM-dd"); _tagInfo._parent = _parentInfo; //保存biaoqianinfo SaveBiaoqianInfo(); MessageBox.Show($"内容标签 {_tagInfo._mingcheng} 已添加成功!"); MyMethod._updateTag(); this.DialogResult = DialogResult.OK; } else { _tagInfo._biaoqianSet = _bqSetJson; //保存biaoqianinfo SaveBiaoqianInfo(); MessageBox.Show($"内容标签 {_tagInfo._mingcheng} 已设置成功!"); MyMethod._updateTag(); this.DialogResult = DialogResult.OK; } }