protected void BindHasFunCode(List <FishEntity.RoleFunEntity> func, TreeNodeCollection nodes) { if (nodes == null || nodes.Count < 1) { return; } foreach (TreeNode node in nodes) { FishEntity.FunCodeEntity entity = node.Tag as FishEntity.FunCodeEntity; if (entity == null) { continue; } bool isExist = func.Exists((i) => { return(i.funid == entity.funid); }); if (isExist) { node.Checked = true; } else { node.Checked = false; } BindHasFunCode(func, node.Nodes); } }
public FormAddFunCode(FishEntity.FunCodeEntity funcode) { InitializeComponent(); SetButtomImage(btnOk); SetButtomImage(btnCancel); BindFuncode(); _funcode = funcode; if (_funcode != null) { txtcode.Text = _funcode.funcode; txtFunName.Text = _funcode.funname; ckbenable.Checked = _funcode.enable == 1; txtRemark.Text = _funcode.remark; rdbmenu.Checked = _funcode.type == 0; rdbbutton.Checked = _funcode.type == 1; cmbMenus.SelectedValue = _funcode.pid; numericUpDown1.Value = _funcode.sortid; this.Text = "修改功能"; } }
private void treeViewFunCode_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (treeViewFunCode.SelectedNode == null) { return; } FishEntity.FunCodeEntity entity = treeViewFunCode.SelectedNode.Tag as FishEntity.FunCodeEntity; if (entity == null) { return; } FormAddFunCode formfuncode = new FormAddFunCode(entity); formfuncode.RefreshData += formfuncode_RefreshData; formfuncode.ShowDialog(); } }
private void BindFuncode() { List <FishEntity.FunCodeEntity> data = _bll.GetModelList("pid=0 order by sortid asc"); if (data == null) { data = new List <FishEntity.FunCodeEntity>(); } FishEntity.FunCodeEntity empty = new FishEntity.FunCodeEntity(); empty.funid = 0; empty.funname = "请选择父节点"; data.Insert(0, empty); cmbMenus.DataSource = data; cmbMenus.DisplayMember = "funCodeAndName"; cmbMenus.ValueMember = "funid"; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FishEntity.FunCodeEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_funcode set "); strSql.Append("funcode=@funcode,"); strSql.Append("funname=@funname,"); strSql.Append("type=@type,"); strSql.Append("enable=@enable,"); strSql.Append("remark=@remark,"); strSql.Append("pid=@pid,"); strSql.Append("sortid=@sortid"); strSql.Append(" where funid=@funid"); MySqlParameter[] parameters = { new MySqlParameter("@funcode", MySqlDbType.VarChar, 255), new MySqlParameter("@funname", MySqlDbType.VarChar, 255), new MySqlParameter("@type", MySqlDbType.Int32, 4), new MySqlParameter("@enable", MySqlDbType.Int32, 4), new MySqlParameter("@remark", MySqlDbType.VarChar, 255), new MySqlParameter("@pid", MySqlDbType.Int32, 4), new MySqlParameter("@sortid", MySqlDbType.Int32, 4), new MySqlParameter("@funid", MySqlDbType.Int32, 11) }; parameters[0].Value = model.funcode; parameters[1].Value = model.funname; parameters[2].Value = model.type; parameters[3].Value = model.enable; parameters[4].Value = model.remark; parameters[5].Value = model.pid; parameters[6].Value = model.sortid; parameters[7].Value = model.funid; int rows = MySqlHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FishEntity.FunCodeEntity DataRowToModel(DataRow row) { FishEntity.FunCodeEntity model = new FishEntity.FunCodeEntity(); if (row != null) { if (row["funid"] != null && row["funid"].ToString() != "") { model.funid = int.Parse(row["funid"].ToString()); } if (row["funcode"] != null) { model.funcode = row["funcode"].ToString(); } if (row["funname"] != null) { model.funname = row["funname"].ToString(); } if (row["type"] != null && row["type"].ToString() != "") { model.type = int.Parse(row["type"].ToString()); } if (row["enable"] != null && row["enable"].ToString() != "") { model.enable = int.Parse(row["enable"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["pid"] != null && row["pid"].ToString() != "") { model.pid = int.Parse(row["pid"].ToString()); } if (row["sortid"] != null && row["sortid"].ToString() != "") { model.sortid = int.Parse(row["sortid"].ToString()); } } return(model); }
protected void GetFuncodes(List <FishEntity.FunCodeEntity> data, TreeNodeCollection nodes) { //List<FishEntity.FunCodeEntity> data = new List<FishEntity.FunCodeEntity>(); if (nodes == null || nodes.Count < 1) { return; } foreach (TreeNode item in nodes) { if (item.Checked) { FishEntity.FunCodeEntity fun = item.Tag as FishEntity.FunCodeEntity; if (fun == null) { continue; } data.Add(fun); } GetFuncodes(data, item.Nodes); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(FishEntity.FunCodeEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_funcode("); strSql.Append("funcode,funname,type,enable,remark,pid,sortid)"); strSql.Append(" values ("); strSql.Append("@funcode,@funname,@type,@enable,@remark,@pid,@sortid)"); MySqlParameter[] parameters = { new MySqlParameter("@funcode", MySqlDbType.VarChar, 255), new MySqlParameter("@funname", MySqlDbType.VarChar, 255), new MySqlParameter("@type", MySqlDbType.Int32, 4), new MySqlParameter("@enable", MySqlDbType.Int32, 4), new MySqlParameter("@remark", MySqlDbType.VarChar, 255), new MySqlParameter("@pid", MySqlDbType.Int32, 4), new MySqlParameter("@sortid", MySqlDbType.Int32, 4) }; parameters[0].Value = model.funcode; parameters[1].Value = model.funname; parameters[2].Value = model.type; parameters[3].Value = model.enable; parameters[4].Value = model.remark; parameters[5].Value = model.pid; parameters[6].Value = model.sortid; int rows = MySqlHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FishEntity.FunCodeEntity GetModel(int funid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select funid,funcode,funname,type,enable,remark,pid,sortid from t_funcode "); strSql.Append(" where funid=@funid"); MySqlParameter[] parameters = { new MySqlParameter("@funid", MySqlDbType.Int32) }; parameters[0].Value = funid; FishEntity.FunCodeEntity model = new FishEntity.FunCodeEntity(); DataSet ds = MySqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FishEntity.FunCodeEntity model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(FishEntity.FunCodeEntity model) { return(dal.Add(model)); }
private void btnOk_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtcode.Text) == true) { MessageBox.Show("请输入功能代码"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (string.IsNullOrEmpty(txtFunName.Text) == true) { MessageBox.Show("请输入功能名称"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (_funcode == null) { FishEntity.FunCodeEntity entity = new FishEntity.FunCodeEntity(); entity.funcode = txtcode.Text.Trim(); entity.funname = txtFunName.Text.Trim(); entity.remark = txtRemark.Text.Trim(); entity.enable = ckbenable.Checked ? 1 : 0; entity.type = rdbmenu.Checked ? 0 : 1; entity.pid = int.Parse(cmbMenus.SelectedValue.ToString()); entity.sortid = (int)numericUpDown1.Value; bool isexist = _bll.Exists(entity.funcode); if (isexist) { MessageBox.Show("代码重复,请重新输入。"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } _bll.Add(entity); MessageBox.Show("添加成功"); } else { string newcode = txtcode.Text.Trim(); if (newcode.Equals(_funcode.funcode) == false) { bool isexist = _bll.Exists(newcode); if (isexist) { MessageBox.Show("代码重复,请重新输入。"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } } _funcode.funcode = txtcode.Text.Trim(); _funcode.funname = txtFunName.Text.Trim(); _funcode.remark = txtRemark.Text.Trim(); _funcode.enable = ckbenable.Checked ? 1 : 0; _funcode.type = rdbmenu.Checked ? 0 : 1; _funcode.pid = int.Parse(cmbMenus.SelectedValue.ToString()); _funcode.sortid = (int)numericUpDown1.Value; _bll.Update(_funcode); MessageBox.Show("修改成功"); } if (RefreshData != null) { RefreshData(this, EventArgs.Empty); } }