coolite treepanel增删改并自动刷新
2010-08-12 15:15
281 查看
刚开始用coolite发现虽然比较强大,但太不熟悉里面东西了,还是应该仔细研究demo,边用边学实在费力
代码
代码
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack && !Ext.IsAjaxRequest) { NodeLoad(TypePanel.Root); } if (!Ext.IsAjaxRequest) { BindType(); } } private void BindType() { DepartmentList list = DepartmentManager.GetDepartments(100, 1, new QwpDataParameter[] { }); for (int i = 0; i < list.RecordCount; i++) { Coolite.Ext.Web.ListItem item = new Coolite.Ext.Web.ListItem(list[i].DepartmentName, list[i].ID.ToString()); cb_Type.Items.Add(item); } cb_Type.Items.Insert(0, new Coolite.Ext.Web.ListItem("所有部门", "0")); } [AjaxMethod] public string RefreshMenu() { Coolite.Ext.Web.TreeNodeCollection nodes = this.NodeLoad(null); return nodes.ToJson(); } public Coolite.Ext.Web.TreeNodeCollection NodeLoad(Coolite.Ext.Web.TreeNodeCollection nodes) { if(nodes==null) nodes = new Coolite.Ext.Web.TreeNodeCollection(); DepartmentList Dlist = DepartmentManager.GetDepartments(100, 1, new QwpDataParameter[] { }); Coolite.Ext.Web.TreeNode root = root = new Coolite.Ext.Web.TreeNode("0", "所有部门", Icon.Folder);//新建根节点 if (Dlist!=null) { AddChild(root); } nodes.Add(root); return nodes; } /// <summary> /// 递归添加子节点 /// </summary> /// <param name="root"></param> private void AddChild(Coolite.Ext.Web.TreeNode root) { List<Coolite.Ext.Web.TreeNode> list = GetChilds(root); if (list.Count == 0) { return; } else { for (int i = 0; i < list.Count; i++) { root.Nodes.Add(list[i]); } for (int i = 0; i < list.Count; i++) { AddChild(list[i]); } } } /// <summary> /// 得到父节点 /// </summary> /// <param name="node"></param> /// <returns></returns> private List<Coolite.Ext.Web.TreeNode> GetChilds(Coolite.Ext.Web.TreeNode node) { DepartmentList list = DepartmentManager.GetDepartments(100, 1, new QwpDataParameter[] { new QwpDataParameter("ParentID", DbType.Int16, node.NodeID) }); List<Coolite.Ext.Web.TreeNode> tn = new List<Coolite.Ext.Web.TreeNode>(); if (list != null) { for (int i = 0; i < list.Count; i++) { Coolite.Ext.Web.TreeNode n = new Coolite.Ext.Web.TreeNode(); n.Text = list[i].DepartmentName; n.NodeID = list[i].ID.ToString(); n.Qtip = string.Format("右键管理{0}", list[i].DepartmentName); //List<DT.Model.Type> nl = DT.BLL.ShowView.NewsType.SelAllNewsTypeByFID(n.NodeID); DepartmentList nl = DepartmentManager.GetDepartments(100, 1, new QwpDataParameter[] { new QwpDataParameter("ParentID", DbType.Int16, n.NodeID) }); if (nl == null) { n.Qtip = string.Format("点击管理{0}下的用户", list[i].DepartmentName); } tn.Add(n); } } return tn; } [AjaxMethod] public void ActionDo(string nodeid, string action) { SaveAction.Text = nodeid + "," + action; Department depart = DepartmentManager.GetDepartment(int.Parse(nodeid)); switch (action) { case "add": cb_Type.HideMode = HideMode.Display; cb_Type.Hidden = true; WinCategoryAction.Icon = Icon.ApplicationFormAdd; //if (depart != null) //{ // WinCategoryAction.SetTitle(string.Format("添加{0}的子节点", depart.DepartmentName)); //} //else //{ // WinCategoryAction.SetTitle(string.Format("添加{0}的子节点", "所有部门")); //} if (depart != null && depart.ParentID != 0) { Department departParent = DepartmentManager.GetDepartment(depart.ParentID); WinCategoryAction.SetTitle(string.Format("添加{0}的子节点{1}", departParent.DepartmentName, depart.DepartmentName)); cb_Type.SetRawValue(departParent.DepartmentName); } else { WinCategoryAction.SetTitle(string.Format("添加{0}的子节点{1}", "所有部门", depart.DepartmentName)); cb_Type.SelectedItem.Value="0"; cb_Type.SetRawValue("所有部门"); //cb_Type.SelectedIndex = 0; } //cb_Type.SetRawValue(depart.DepartmentName); WinCategoryAction.Show(); break; case "edit": cb_Type.HideMode = HideMode.Display; cb_Type.Hidden = true; WinCategoryAction.Icon = Icon.ApplicationFormAdd; txf_TreeName.Text = depart.DepartmentName; if (depart != null && depart.ParentID != 0) { Department departParent = DepartmentManager.GetDepartment(depart.ParentID); WinCategoryAction.SetTitle(string.Format("编辑{0}的子节点{1}", departParent.DepartmentName, depart.DepartmentName)); cb_Type.SetRawValue(departParent.DepartmentName); } else { WinCategoryAction.SetTitle(string.Format("编辑{0}的子节点{1}", "所有部门",depart.DepartmentName)); cb_Type.SelectedItem.Value="0"; cb_Type.SetRawValue("所有部门"); //cb_Type.SelectedIndex = 0; } WinCategoryAction.Show(); break; case null: Ext.Msg.Alert(ConfigurationManager.AppSettings["MsgAlert"], ConfigurationManager.AppSettings["AlertMessage"]).Show(); break; } } [AjaxMethod] public void Delete(string nodeid, string action) { switch (action) { case "del": Ext.Msg.Confirm(ConfigurationManager.AppSettings["MsgTitle"], "<span style=\"color:#F00;\">此操作将会删除该节点类型下所有的数据!</span><br />是否确定删除?", new MessageBox.ButtonsConfig { Yes = new MessageBox.ButtonConfig { Handler = "Coolite.AjaxMethods.TreeNote_Del(" + nodeid + ");", Text = "确 定" }, No = new MessageBox.ButtonConfig { Text = "取 消" } }).Show(); break; } } [AjaxMethod] public void TreeNote_Del(string treeNote) { if (DepartmentManager.DeleteDepartments(int.Parse(treeNote))) { Ext.Msg.Alert(ConfigurationManager.AppSettings["MsgTitle"], "数据已成功删除!", new MessageBox.ButtonsConfig { Yes = new MessageBox.ButtonConfig { Handler = "refreshTree(" + TypePanel.ClientID + ");", Text = "确 定" } }).Show(); } else { Ext.Msg.Alert(ConfigurationManager.AppSettings["MsgError"], ConfigurationManager.AppSettings["ErrorMessage"]).Show(); } } /// <summary> /// 更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_upData_Ajax(object sender, AjaxEventArgs e) { Department depart = new Department(); string action = SaveAction.Text.Split(new char[] { ',' })[1]; switch (action) { case "add": depart.ParentID = Convert.ToInt32(SaveAction.Text.Split(new char[] { ',' })[0]); //depart.TypeID = 0; break; case "edit": depart.ID = Convert.ToInt32(SaveAction.Text.Split(new char[] { ',' })[0]); if (Save_NodeParent.Text == "0") { depart.ParentID = 0; } else { depart.ParentID = Convert.ToInt32(cb_Type.SelectedItem.Value); } break; default: break; } depart.DepartmentName = txf_TreeName.Text; depart.ApplicationID = WebUtils.GetApplicationId(); if (depart.Save()) { Ext.Msg.Alert(ConfigurationManager.AppSettings["MsgTitle"], "数据已经提交成功!~", new MessageBox.ButtonsConfig { Yes = new MessageBox.ButtonConfig { Handler = "refreshTree(" + TypePanel.ClientID + ");", Text = "确 定" } }).Show(); WinCategoryAction.Hidden = true; //QwpDataCache.RemoveByKeyPrefix } else { Ext.Msg.Alert(ConfigurationManager.AppSettings["MsgError"], ConfigurationManager.AppSettings["ErrorMessage"]).Show(); } //TypePanel.to }
相关文章推荐
- Coolite TreePanel 操作之一:TreePanel 刷新
- Coolite TreePanel 静态刷新
- Coolite TreePanel 操作之一:TreePanel 刷新
- [coolite] TreePanel CheckBox联动
- 动态sql 的增删改,缓存没办法自动刷新,解决方案
- [coolite] TreePanel CheckBox联动
- coolite有关 Treepanel 节点问题
- EXT3.1-gridpanel定时刷新滚动条自动滚动
- 解决了coolite官方示例"TreePanel/basic/refresh static tree"的一个错误
- Coolite TreePanel开发实例
- Coolite一个简单例子-GridPanel列表增删改预览
- ExtJs Treepanel刷新树形菜单
- Coolite一个简单例子-GridPanel列表增删改预览
- 【转载】Coolite一个简单例子-GridPanel列表增删改预览及在线编辑器
- Coolite一个简单例子-GridPanel列表增删改预览
- Extjs6 treepanel 自动靠右bug
- 【转载】Coolite之TreePanel右键功能菜单
- extjs4.0 tree 整体刷新,对单个节点的增删改问题
- jQuery EasyUI Tree 增删改 编辑结点名称自动全选文本域
- Coolite TreePanel的数据绑定操作