public void Bind(int recordCount) { _RecordCount = recordCount; XmlNode pagerNode = doc.Get(PagerID); if (pagerNode == null || _RecordCount <= _PageSize || (_RecordCount <= 0 && _PageIndex <= 1)) { return; } int pageCount = (RecordCount % PageSize) == 0 ? RecordCount / PageSize : RecordCount / PageSize + 1;//页数 if (PageIndex > pageCount) { return; } if (pagerNode.InnerXml == "") { pagerNode.InnerXml = InnerXml; } //if (_RecordCount <= _PageSize) // 总数不够一页。 //{ // if (onlyRemoveChild.Length > 0 && onlyRemoveChild[0]) // { // doc.RemoveAllChild(IDKey.Node_Pager); // doc.RemoveAllChild(IDKey.Node_Pager2); // } // else // { // doc.Remove(IDKey.Node_Pager); // doc.Remove(IDKey.Node_Pager2);//一个页面允许出现上下两个分页。 // } // return; //} //if (_RecordCount <= 0 && _PageIndex <= 1) //{ // return; //} FormatFourNum(pageCount); FormatNum(pageCount); XmlNode xNode2 = doc.Get(PagerID + "2"); if (xNode2 != null) { doc.Set(xNode2, SetType.InnerText, pagerNode.InnerXml); } }
public static void Bind(object ct, object source, string nodeID) { if (ct == null) { return; } if (ct is XHtmlAction) { #region XHtmlAction 对象处理 XHtmlAction doc = ct as XHtmlAction; MDataTable dt = source as MDataTable; doc.LoadData(dt); XmlNode node = null; if (string.IsNullOrEmpty(nodeID)) { doc.SetForeach(); } else { node = doc.Get(nodeID); if (node != null) { doc.SetForeach(node, node.InnerXml); } } #endregion } else { #region 检测下拉列表控件 if (ct is ListControl) { BindList(ct as ListControl, source as MDataTable); } else if (ct is Win.ListControl) { BindList(ct as Win.ListControl, source as MDataTable); } else { Type t = ct.GetType(); PropertyInfo p = t.GetProperty("DataSource"); if (p != null) { #region DataGridView处理 MethodInfo meth = t.GetMethod("DataBind"); if (meth != null)//web { p.SetValue(ct, source, null); meth.Invoke(ct, null); } else { if (source is MDataTable) { MDataTable dt = source as MDataTable; source = new MDataView(ref dt); } p.SetValue(ct, source, null);//winform } #endregion } else //wpf,sliverlight { p = t.GetProperty("ItemsSource"); if (p != null) { MDataTable dt = null; if (source is MDataTable) { dt = source as MDataTable; source = dt.ToDataTable().DefaultView; } p.SetValue(ct, source, null); //winform p = t.GetProperty("SelectedValuePath"); //判断是不是下拉列表 if (p != null) { p.SetValue(ct, dt.Columns[0].ColumnName, null); p = t.GetProperty("DisplayMemberPath"); p.SetValue(ct, dt.Columns[dt.Columns.Count > 1 ? 1 : 0].ColumnName, null); } } } } #endregion } }
private static void ReplaceItemRef(XHtmlAction view, XmlNodeList list, bool isBreak, int loopCount) { //处理Shared目录下的节点替换。 if (list != null && list.Count > 0) { if (loopCount > 50) { throw new Exception("Reference loop : " + list[0].InnerXml); } string itemref = "itemref"; for (int i = 0; i < list.Count; i++) { string itemValue = list[i].Attributes[itemref].Value; if (!string.IsNullOrEmpty(itemValue)) { bool isOK = false; string[] items = itemValue.Split('.'); if (items.Length == 1)// 只一个节点,从当前节点寻找。 { XmlNode xNode = view.Get(items[0]); if (xNode != null) { view.ReplaceNode(xNode, list[i]); view.Remove(xNode);//从自己拿节点的,需要移除 isOK = true; } } else { XHtmlAction sharedView = GetSharedView(items[0], view.FileName);//找到masterView if (sharedView != null) { XmlNode xNode = sharedView.Get(items[1]);//找到被替换的节点 if (xNode != null) { view.InsertAfter(xNode, list[i]); //先插入节点。 XmlNodeList childNodeList = view.GetList("*", itemref, list[i].NextSibling); //检测内部是否有引用指向外部。 if (childNodeList != null && childNodeList.Count > 0) { loopCount++; ReplaceItemRef(view, childNodeList, true, loopCount); //下次跳出,避免死循环。 } view.Remove(list[i]); //移除节点 isOK = true; } } } if (!isOK) { view.Remove(list[i]);//移除没有引用的节点 // view.RemoveAttr(list[i], itemref); } } } loopCount++; if (!isBreak)//避免死循环。 { ReplaceItemRef(view, view.GetList("*", itemref), isBreak, loopCount); } } }