/// <summary> /// 插入数据 /// </summary> /// <param name="s"></param> /// <returns></returns> public int Insert(Scripts s) { string sql = "insert into T_Scripts values(@title,@msg,@pid)"; SqlParameter[]pas=new SqlParameter[]{ new SqlParameter("@title",s.Title), new SqlParameter("@msg",s.Msg), new SqlParameter("@pid",s.ParentId) }; return SqlHelper.ExecuteNonQuery(sql, CommandType.Text, pas); }
private void button1_Click(object sender, EventArgs e) { Scripts s=new Scripts(); s.Msg=textBox2.Text; s.ParentId=_pid; s.Title=textBox1.Text; bll.Insert(s); //更新TreeView _method(); this.Close(); }
/// <summary> /// 根据Id获取子节点 /// </summary> /// <param name="id"></param> /// <returns></returns> public List<Scripts> GetSonNodesById(int id) { List<Scripts> list = new List<Scripts>(); string sql = "select * from T_Scripts where ScriptParentId=@id"; using (SqlDataReader reader=SqlHelper.ExecuteReader(sql, System.Data.CommandType.Text,new SqlParameter("@id",id))) { if (reader.HasRows) { while (reader.Read()) { Scripts s = new Scripts(); s.ID = reader.GetInt32(0); s.Title = reader.GetString(1); s.Msg = reader.GetString(2); s.ParentId = reader.GetInt32(3); list.Add(s); } } } return list; }
/// <summary> /// 修改节点 /// </summary> /// <param name="s"></param> private void ChangeNode(Scripts s) { treeView1.SelectedNode.Text = s.Title; textBox1.Text = s.Msg; }
/// <summary> /// 编辑,弹出窗口编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e) { Scripts s=new Scripts(); s.ID = (int)treeView1.SelectedNode.Tag; s.Msg = textBox1.Text; s.Title = treeView1.SelectedNode.Text; fmEdit fm=new fmEdit(s,ChangeNode); fm.Show(); }
/// <summary> /// 更新数据 /// </summary> /// <param name="s"></param> /// <returns></returns> public int Update(Scripts s) { string sql = "update T_Scripts set ScriptTitle=@title,ScriptMsg=@msg where ScriptId=@id"; SqlParameter[] pas = new SqlParameter[]{ new SqlParameter("@title",s.Title), new SqlParameter("@msg",s.Msg), new SqlParameter("@id",s.ID), }; return SqlHelper.ExecuteNonQuery(sql, CommandType.Text, pas); }
/// <summary> /// 构造函数,保存主窗体的数据,已经更新数据的方法 /// </summary> /// <param name="s"></param> /// <param name="m"></param> public fmEdit(Scripts s,Action<Scripts> m) : this() { this.model = s; this._method = m; }
/// <summary> /// 更新数据 /// </summary> /// <param name="s"></param> /// <returns></returns> public int Update(Scripts s) { return dal.Update(s); }
/// <summary> /// 插入数据 /// </summary> /// <param name="s"></param> /// <returns></returns> public int Insert(Scripts s) { return dal.Insert(s); }