2006-09-28 02:25:00 cleverfoxloving 阅读数 3809
  • Servlet+MYSQL+JQuery+Bootstrap企业费用管理系统

    费用管理是企业流通费用的管理,是企业财务管理的组成部分。费用管理的任务是:通过预测、计划、控制、核算、考核和分析,反映商品流通费支出、挖掘降低费用的潜力,提高经济效益。管理的形式有:计划管理、定额管理、预算管理、分口管理、分级管理等。企业对费用的具体管理工作,通常从三方面组织进行:(1) 由财会部门对企业全部费用支出及费用水平实行综合管理;按照企业内部组织的分工,实行分口负责,分级管理。(2)对各费用开支项目,据其不同的特点,采用不同的管理方法。如费用的定率、定额管理、费用包干节约提成制、内部资金券贴现等。企业设置总会计师或具备有精通管理业务的主管经理,也可实行总会计师或主管经理一支笔批示后,才能列支的管理方式

    366 人正在学习 去看看 刘英杰
 

在项目中,有一个通讯录组以及通讯录的功能,通讯录组要求无限分级,树状结构显示 ,经过研究,完整地实现了树结构,效果如下还可以实时添加,修改,删除,使用ajax实现,客户端不会刷新

下面先讲怎样在服务端实现这个树结构,首先,数据库设计至少三个字段,主建,名称,父节点(记录父节点主键),由于本项目中树结构较多,所以我用一个实体类来表示TreeEntity.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace SmsSystem.Model
{
    
public class TreeEntity
    
{
        
public TreeEntity() { }

        
public TreeEntity(int id, string name, int parentId) {
            
this.id = id;
            
this.name = name;
            
this.parentId = parentId;
        }

        
private int id;
        
private string name;
        
private int parentId;

        
public int Id
        
{
            
get return id; }
            
set { id = value ; }
        }


        
public string Name
        
{
            
get return name; }
            
set { name = value ; }
        }


        
public int ParentId 
        
{
            
get return parentId; }
            
set { parentId = value; }
        }


    }

}

 

数据库访问层我在一篇文件中曾经提到过http://blog.csdn.net/cleverfoxloving/archive/2006/09/15/1226956.aspx具体实现不详述了,我用一个类返回一个IList<TreeEntity>(没接触过C#的泛型的这里可能不明白,请参阅相关资料)

/// <summary>
        
/// 获得数据列表返回ArrayList<TreeEntity>
        
/// </summary>

        public IList<TreeEntity> GetList(int companyRkey)
        
{
            IList
<TreeEntity> list = new List<TreeEntity>();
            DataSet ds 
= this.GetDatasetList(" company_Rkey = " + companyRkey);

            
if (ds.Tables[0].Rows.Count > 0)
            
{
                
foreach (DataRow dr in ds.Tables[0].Rows)
                
{
                    TreeEntity tree 
= new TreeEntity();
                    tree.Id 
= int.Parse(dr["Rkey"].ToString());
                    tree.Name 
= dr["Groupname"].ToString();
                    tree.ParentId 
= int.Parse(dr["Parent_rkey"].ToString());

                    list.Add(tree);
                }

            }

            
return list;

        }
接下来要写一个通用的方法,由list递归生成xml,GetTreeXML.cs
using System;
using System.Data;
using System.Collections.Generic;
using System.Xml;
using System.IO;

using SmsSystem.Model;

namespace SmsSystem.Utility
{
    
public class GetTreeXML
    
{
        
public GetTreeXML() 
        
        }

      
        
public void addDataXml(XmlDocument xmlDoc, XmlElement xmlRootNode, IList<TreeEntity> list)
        

            
foreach(TreeEntity treeEntity in list){
                
if (treeEntity.ParentId == int.Parse(xmlRootNode.GetAttribute("mid")))
                
{
                    XmlElement xmlNewElemene 
= xmlDoc.CreateElement("subject");
                    

                    xmlNewElemene.SetAttribute(
"mid", treeEntity.Id.ToString());
                    xmlNewElemene.SetAttribute(
"name", treeEntity.Name);
                    xmlNewElemene.SetAttribute(
"value", treeEntity.ParentId.ToString());
                    xmlRootNode.AppendChild(xmlNewElemene);
                    addDataXml(xmlDoc, xmlNewElemene, list);
                }

            }

        }


        
public XmlDocument getGroupTree(IList<TreeEntity> list)
        
{
            XmlDocument xmlDoc 
= new XmlDocument();
            XmlDeclaration objXmlDeclare 
= xmlDoc.CreateXmlDeclaration("1.0""UTF-8""yes");
            xmlDoc.InsertBefore(objXmlDeclare, xmlDoc.DocumentElement);
            XmlElement xmlRootElem 
= xmlDoc.CreateElement("subject");
            xmlRootElem.SetAttribute(
"mid""0");
            xmlRootElem.SetAttribute(
"name""通讯录组群");
            xmlDoc.AppendChild(xmlRootElem);
            addDataXml(xmlDoc, xmlRootElem, list);
            
return xmlDoc;

        }


        
public string getGruopTreeStr(IList<TreeEntity> list)
        
{
            
return this.XmlDocumentToString(this.getGroupTree(list));
        }

        
///………………(其它树结构)

        
public string XmlDocumentToString(XmlDocument doc)
        
{
            MemoryStream stream 
= new MemoryStream();
            XmlTextWriter writer 
= new XmlTextWriter(stream, null);
            
//writer.Formatting = Formatting.Indented;
            doc.Save(writer);

            StreamReader sr 
= new StreamReader(stream, System.Text.Encoding.UTF8);
            stream.Position 
= 0;
            
string xmlString = sr.ReadToEnd();
            sr.Close();
            stream.Close();

            
return xmlString;
        }


    }

}

 

这上面的四个方法是主要的核心方法,接下来就是客户端采用Ajax调用,以及有JS生成树结构显示了,只列出部分重要代码,首先简单说一个Ajax调用,采用AjaxPro.dll框架,具体用法参考相关资料,代码如下

 protected void Page_Load(object sender, EventArgs e)
        
{
            AjaxPro.Utility.RegisterTypeForAjax(
typeof(Address_AddressManage));
            
            
        
}

        [AjaxPro.AjaxMethod]
        
public string GetAddressGruopStr() {
            
if (null != Session["userInfo"])
            
{
                
bool isAll = (((SmsSystem.BO.UserInfo)Session["userInfo"]).PopedomType == "1"? true : false;
                
int userRkey = ((SmsSystem.BO.UserInfo)Session["userInfo"]).CustEmployee_Rkey;
                SmsSystem.BLL.AddressGroup addressGroupBll 
= new SmsSystem.BLL.AddressGroup();
                
return addressGroupBll.getGroupTreeStr(userRkey, isAll);
               
            }

            
else
            
{
                Response.Redirect(
"Default.aspx");
                
return null;
            }

           
        }

        [AjaxPro.AjaxMethod]
        
public DataSet GetAddressList(int AddressGroupRkey)
        
{
            
if (null != Session["userInfo"])
            
{
                
bool isAll = (((SmsSystem.BO.UserInfo)Session["userInfo"]).PopedomType == "1"? true : false;
                
int userRkey = ((SmsSystem.BO.UserInfo)Session["userInfo"]).CustEmployee_Rkey;
                SmsSystem.BLL.AddressList AddressListBll 
= new SmsSystem.BLL.AddressList();
                
return AddressListBll.GetDatasetList(userRkey, isAll, AddressGroupRkey);

            }

            
else
            
{
                Response.Redirect(
"Default.aspx");
                
return null;
            }

        }

 

首先在Page_Load要注册Ajax框架,然后是两个供Ajax调用的方法,返回字符串,在客户端

function swapClass(obj, cls) {
    obj.className 
= cls;
}


var TreeForm = document.getElementById("TreeForm");
function SelChkBox(para)
{
    
    
var bTrue=false;

    
with(TreeForm)
    
for(i=0;i<document.forms[0].elements.length;i++)
    
{
        
if ((document.forms[0].elements[i].name=="chkbutton"&& (document.forms[0].elements[i].value==para))
        
{
            bTrue
=!document.forms[0].elements[i].checked;
            document.forms[
0].elements[i].checked=bTrue;
            
break;
        }

    }


    
if (para=='All')
    
{
        
with(TreeForm)
        
for (i=0;i<document.forms[0].elements.length;i++)
        
{
            
if(document.forms[0].elements[i].name=="chkbutton")
            
{
                document.forms[
0].elements[i].checked=bTrue;
            }

        }

    }

    
else
    
{
        SelectAllNode(para,bTrue);
    }

}

//点击一个节点的复选框
function SelChkBoxSingle(para)
{
    
var bTrue=false;
    
with(TreeForm)

    
for(i=0;i<document.forms[0].elements.length;i++)
    
{
        
if ((document.forms[0].elements[i].name=="chkbutton"&& (document.forms[0].elements[i].value==para))
        
{
            bTrue
=!document.forms[0].elements[i].checked;
        }

        
else
        
{
            document.forms[
0].elements[i].checked = false;
        }

    }

}

//选择一个节点
function SelChkBoxSingle1(para)
{
    
var bTrue=false;
    
with(TreeForm)
    
for(i=0;i<document.forms[0].elements.length;i++)
    
{
        
if ((document.forms[0].elements[i].name=="chkbutton"&& (document.forms[0].elements[i].value==para))
        
{
            bTrue
=!document.forms[0].elements[i].checked;
            document.forms[
0].elements[i].checked=bTrue;
                                }

        }

        
else
        
{
            
if (document.forms[0].elements[i].checked) document.forms[0].elements[i].checked = !document.forms[0].elements[i].checked;
        }

    }

}
// checkbox onclick
function SelChkBox1(para)
{
    
var bTrue=false;
    
with(TreeForm)
    
for(i=0;i<document.forms[0].elements.length;i++)
    
{
        
if ((document.forms[0].elements[i].name=="chkbutton"&& (document.forms[0].elements[i].value==para))
        
{
            bTrue
=document.forms[0].elements[i].checked;
            
break;
        }

    }


    
if (para=='All')
    
{
        
with(TreeForm)
        
for(i=0;i<document.forms[0].elements.length;i++)
        
{
            
if(document.forms[0].elements[i].name=="chkbutton")
            
{
                document.forms[
0].elements[i].checked=bTrue;
            }

        }

    }

    
else
    
{
        SelectAllNode(para,bTrue);
    }

}


function SelectAllNode(sMidValue,bTrue)
{
    
var xmlDoc1 = new ActiveXObject("MSXML.DOMDocument")
    xmlDoc1.async 
= false;
    xmlDoc1.loadXML(xmlSSS)
    
return SelectNode(xmlDoc1.documentElement,sMidValue,bTrue)
}


function SelectNode(oElem,sMidValue,bTrue)
{
    
var retStr="";
    
var oNodeList = oElem.childNodes

    
if (GetAttributes(oElem,"mid")==sMidValue)
    
{
        SelectChildNode(oElem,bTrue);

        
if (bTrue)
            SelectParentNode(oElem,bTrue);
        
else
            IsParentChecked(oElem);

        
return;
    }

    
else
    
{
        
for (var i=0;i<=oNodeList.length-1;i++)
        
{
                SelectNode(oNodeList.item(i),sMidValue,bTrue)
        }

    }


}


function SelectChildNode(oElem,bTrue)
{
    
var oNodeList = oElem.childNodes
    
for (var i=0;i<=oNodeList.length-1;i++)
    
{
        ClickNode(GetAttributes(oNodeList.item(i),
"mid"),bTrue);
        SelectChildNode(oNodeList.item(i),bTrue)
    }

}



//检查当前节点的父节点的子节点是否有被选中的。
//
如故没有,则父节点的CheckBox的checked=false;
function IsParentChecked(oElem)
{
    
var bExist=false;
    
do
    
{
        
if (GetAttributes(oElem,"mid")=="")
            
break;
        
else
        
{
            
var pNode = oElem.parentNode
            
var oNodeList = pNode.childNodes;
            
for (var i=0;i<=oNodeList.length-1;i++)
            
{
                    
if (IsNodeChecked(GetAttributes(oNodeList.item(i),"mid")))
                
{
                    bExist 
= true;
                    
break;
                }

            }

            
if (bExist) break;
            ClickNode(GetAttributes(pNode,
"mid"),false);
            oElem
=pNode;
        }

    }
 while(true);
}


//选中所有的父节点
function SelectParentNode(oElem,bTrue)
{
    
do
    
{
        
if (GetAttributes(oElem,"mid")=="")
            
break;
        
else
        
{
            
var pNode=oElem.parentNode;
            ClickNode(GetAttributes(pNode,
"mid"),bTrue);
            oElem
=pNode;
        }

    }
 while(true);
}



//判断某一节点是否被选中。
function IsNodeChecked(sMidValue)
{
    
var bChecked=false;
    
with(TreeForm)
    
for(i=0;i<document.forms[0].elements.length;i++)
    
{
        
if ((document.forms[0].elements[i].name=="chkbutton"&& (document.forms[0].elements[i].value==sMidValue))
        
{
            bChecked
=document.forms[0].elements[i].checked;
            
break;
        }

    }

    
return bChecked;
}


function ClickNode(sMidValue,bTrue)
{
    
with(TreeForm)
    
for(i=0;i<document.forms[0].elements.length;i++)
    
{
        
if ((document.forms[0].elements[i].name=="chkbutton"&& (document.forms[0].elements[i].value==sMidValue))
        
{
            document.forms[
0].elements[i].checked=bTrue;
            
break;
        }

    }

}



var bAll=true;
bAll
=true;
if (bAll)
{
    sAllChecked
="";
}


var tree = new WebFXTree('通讯录组',sAllChecked,"0","javascript:void(0);");
tree.setBehavior(
'classic');

function AddNode(oElem,oTreeNode)
{
  
var oNewNode;
  
if (oTreeNode==null)
  
{
    oNewNode 
= tree;
  }

  
else
  
{
    
var sChecked=""
    
//if (GetAttributes(oElem,"value")=="1")
    //    sChecked="checked";

    
if (GetAttributes(oElem,"type")=="subject")
            
var oNewNode = new WebFXTreeItem(GetAttributes(oElem,"name"),sChecked,GetAttributes(oElem,"mid"),"javascript:SelChkBoxSingle('"+GetAttributes(oElem,"mid")+"')");
    
else
            
var oNewNode = new WebFXTreeItem(GetAttributes(oElem,"name"),sChecked,GetAttributes(oElem,"mid"),"javascript:GetResultXml('"+GetAttributes(oElem,"mid")+"')");

        oTreeNode.add(oNewNode);
  }


  
var oNodeList = oElem.childNodes
  
for (var i=0;i<=oNodeList.length-1;i++)
  
{
    
if (oElem.nodeType==1){
            AddNode(oNodeList.item(i),oNewNode)
    }

  }

}


function GetAttributes(oElm,AttrName)
{
  
var sAttr=""
  
for (var i=0;i<=oElm.attributes.length-1;i++)
  
{
    
if (oElm.attributes.item(i).nodeName==AttrName)
    
{
         sAttr 
= oElm.attributes.item(i).nodeValue;
     
break;
    }

  }

  
return sAttr
}

function LoadXmlResult(){
   document.getElementById(
"showAderessGroupTree").innerHTML="通讯录树正在载入……";
   SmsSystem.Address_AddressManage.GetAddressGruopStr(LoadXmlResult_callback);
}

function LoadXmlResult_callback(response){
    
if(response.value == null){
        alert(
"没有任何数据!");
        
return;
    }

    xmlString 
= response.value;
    createTree(
"showAderessGroupTree",xmlString);
    
}


function createTree(treeDivId,xmlString){
    
if (document.getElementById) {

      
var xmlDoc = new ActiveXObject("MSXML.DOMDocument")
      xmlDoc.async 
= false;

      xmlDoc.loadXML(xmlString)

      AddNode(xmlDoc.documentElement)
      
      document.getElementById(treeDivId).innerHTML
=tree;
      
//document.write(tree);

    
//  tree.expandAll()
    }

}



//添加资源

function addGroup(){
    
var str="";
    
var name="";
    
    
for(var i=0;i<document.forms[0].chkbutton.length;i++){
        
if(document.forms[0].chkbutton[i].checked==true){
            str
=document.forms[0].chkbutton[i].value;
            name 
= document.forms[0].chkbutton[i].label;
            
break;            
        }
    
    }
    
    
if(str==''){
        alert(
'请选择待修改类别名称!');
        
return false;
    }


    document.all[
"addGroupDiv"].style.left=120;
    document.all[
"addGroupDiv"].style.top=140;
    document.all[
"addGroupDiv"].style.display="";
    document.getElementById(
"groupName").value=name;
}

function modifyGroup(){
    (修改的代码,省略…………)}



function cancalAdd(divID){
    document.all[divID].style.display
="none";
}

function GetResultXml(mid){
    SmsSystem.Address_AddressManage.GetAddressList(mid,GetResult_callback);
    
}

function GetResult_callback(response){
    
    
if(response.value == null){
        alert(
"没有任何数据!");//可以自行添加对于无数据的处理流程
        return;
    }

    
    
var dt = response.value.Tables[0];
   
    
if (dt.Rows.length>0){
        
        fillContent(dt)
    }
else{
        removeContent();
        
var showAddressListt = document.getElementById("showAddressListt");

        
var row=document.createElement('tr');

        row.setAttribute(
"height","26");
        row.setAttribute(
"bgColor","#FFFFFF");
        
var cell=createCellth('没有记录,清先添加记录!');
         cell.setAttribute(
"width","380");
        row.appendChild(cell);
        showAddressListt.appendChild(row);
        
return;
    }

    
}





function removeContent(){

    
var showAddressListt = document.getElementById("showAddressListt");

    
while(showAddressListt.childNodes.length>0)
    
{
        showAddressListt.removeChild(showAddressListt.childNodes[
0]);
    }


}



function fillContent(dt){
    
    
    

    removeContent();
    
if (dt){
        document.getElementById(
"addressListtTable").style.width="800px";
        
//var showResult = document.getElementById("showResult");
        var showAddressListt = document.getElementById("showAddressListt");

        
//var tableContent = document.createElement("table");
        //tableContent.setAttribute("bgColor","#FF0000");
        //tableContent.setAttribute("width","300");
        //增加一行,设置标题
        var row=document.createElement('tr');

        row.setAttribute(
"height","26");
        row.setAttribute(
"bgColor","#FFFFFF");
        
        
var cell=createCellth('');
        cell.setAttribute(
"width","30");
        row.appendChild(cell);
        cell
=createCellth('序号');
        cell.setAttribute(
"width","60");
        row.appendChild(cell);

        cell
=createCellth('姓名');
        cell.setAttribute(
"width","120");
        row.appendChild(cell);
        cell
=createCellth('性别');
        cell.setAttribute(
"width","120");
        row.appendChild(cell);
        cell
=createCellth('手机号');
        cell.setAttribute(
"width","120");
        row.appendChild(cell);
        cell
=createCellth('生日');
        cell.setAttribute(
"width","200");
        row.appendChild(cell);
        cell
=createCellth('公司名称');
        cell.setAttribute(
"width","120");
        row.appendChild(cell);
        cell
=createCellth('公司电话');
        cell.setAttribute(
"width","120");
        row.appendChild(cell);
        cell
=createCellth('公司传真');
        cell.setAttribute(
"width","120");
        row.appendChild(cell);
        cell
=createCellth('职务');
        cell.setAttribute(
"width","100");
        row.appendChild(cell);
        cell
=createCellth('备注');
        cell.setAttribute(
"width","100");
        row.appendChild(cell);
        cell
=createCellth('创建日期');
        cell.setAttribute(
"width","140");
        row.appendChild(cell);
        
        showAddressListt.appendChild(row);
        
//设置标题结束

        
//循环处理填充表格
        for(var i=0;i<dt.Rows.length;i++){
        
            
            
            
var row=document.createElement('tr');
            row.setAttribute(
"height","23");
            
if(i%2==0){
                row.setAttribute(
"bgColor","#FFFFFF");
            }
else{
                row.setAttribute(
"bgColor","#F5F5F5");
            }

            
var cell=createCheckbox(dt.Rows[i].Rkey);
            
            row.appendChild(cell);
            
            cell
=createCelltd((i+1));
            row.appendChild(cell);

            cell
=createCelltd(dt.Rows[i].Name);
            row.appendChild(cell);
            
var sex = "";
            
if(dt.Rows[i].Sex == '1'){
                sex 
= "";
            }

            cell
=createCelltd(sex);
            row.appendChild(cell);
            cell
=createCelltd(dt.Rows[i].MobileNo);
            row.appendChild(cell);
            
var tempBirthday = new Date(dt.Rows[i].Birthday);
            cell
=createCelltd(tempBirthday.toLocaleDateString());
            row.appendChild(cell);
            cell
=createCelltd(dt.Rows[i].ComName);
            row.appendChild(cell);
            cell
=createCelltd(dt.Rows[i].ComTel);
            row.appendChild(cell);
            cell
=createCelltd(dt.Rows[i].ComFax);
            row.appendChild(cell);
            cell
=createCelltd(dt.Rows[i].Duty);
            row.appendChild(cell);
            cell
=createCelltd(dt.Rows[i].Remark);
            row.appendChild(cell);
            
var tempFileDate = new Date(dt.Rows[i].FileDate);
            
            cell
=createCelltd(tempFileDate.toLocaleDateString());
            row.appendChild(cell);


            
//生成操作链接
            //row.appendChild(addLink(smsID,smsContent));
            
            
            showAddressListt.appendChild(row);
        }

        
        
//showResult.appendChild(tableContent);

    }

}


function createCellth(text)
{
    
var cell=document.createElement('th');

    
var textNode=document.createTextNode(text);
    cell.appendChild(textNode);
    
return cell;
}

function createCelltd(text)
{
    
var cell=document.createElement('td');
    cell.style.background 
="#FFFFFF";
    
//cell.setAttribute("bgcolor","#FFFFFF");

    
var textNode=document.createTextNode(text);
    cell.appendChild(textNode);
    
return cell;
}

function createCheckbox(id)
{
    
var cell=document.createElement('td');
    cell.style.background 
="#FFFFFF";
    
var input=document.createElement('input');
    input.setAttribute(
"id","selectId");
    input.setAttribute(
"name","id");
    input.setAttribute(
"type","checkbox");
    
    cell.appendChild(input);
    
return cell;
}

 

以上是初步实现的部分js脚本,在未重构之前显得有些凌乱,还用到了一个WebFXTree的js树,是前辈高人写的,内容太多了,这里不便列出,页面上部分代码下如

<form id="TreeForm" runat="server">
      
<div>
         
          
<div class="mainTable" style="width:680px;">
            
<div id="row"><ul><li style="width:150px;">通讯录组群</li><li class="erect"></li><li style="width:489px;">通讯录</li></ul></div>
            
<div id="row">
                
<ul>
                    
<li style="width:150px;">
                        
<div id="showAderessGroupTree" style="height:317px;text-align:left;float:left;overflow-y:auto;">
                        
                        
                            
                        
</div>
                    
</li>
                    
<li class="erect" style="height:317px;"></li>
                    
<li style="width:480px;">
                        
<div id="showResult" style="width:460px;height:317px;text-align:center; overflow:auto;">
                            
<table cellpadding="4" cellspacing="1" class="tableborder" id="addressListtTable" style="width:400px;">
                                
                                
<tbody id="showAddressListt">
                                    
<tr class="altbg1">
                                        
<td width="100%">通讯录联系人员</td>
                                    
</tr>
                                
</tbody>
                            
</table>
                        
</div>
                        
<div id="pagination"></div>
                    
</li>
                
</ul>
            
</div>
            
<div id="row">
                
<ul>
                    
<li style="width:150px;"><input type="button" style="background-image:url(/images/add.jpg);border:0px;width:49px;height:21px;" onclick="addGroup();"/><input type="button" style="background-image:url(/images/modify.jpg);border:0px;width:49px;height:21px;" onclick="modifyGroup();"/><input type="button" style="background-image:url(/images/delete.jpg);border:0px;width:49px;height:21px;" onclick="modifyGroup();"/></li>
                    
<li class="erect"></li>
                    
<li><img id="selectAll" src="/images/selectAll.jpg" width="49" height="21" onclick="alert(document.all['id']);" alt=""/><input id="selectNull" type="button" style="background-image:url(/images/selectNull.jpg);border:0px;width:49px;height:21px;" onclick="alert('selectId');"/><input type="button" style="background-image:url(/images/add.jpg);border:0px;width:49px;height:21px;" onclick="addLinkman();"/><input type="button" style="background-image:url(/images/modify.jpg);border:0px;width:49px;height:21px;" onclick="modifyLinkman();"/></li>
                
</ul>
            
</div>
          
</div>
          
            
<div id="addGroupDiv" style="display:none; position:absolute;top:200px;left:240px;">
                   
<div class="frameMainTable" style="width:280px;">
                       
<div id="frmTitle" style="text-align:center;line-height:30px;color:#FFFFFF; font-weight:bold;" >新增组群</div>
                    
<div id="frmMain" >
                        
<div id="row" style="width:250px;text-align:center;">
                            
<ul>
                                
<li>上级组群</li><li><input id="groupName" type="text" readonly="readonly" style="color:Gray;border:solid 1px Gray;"/></li>
                            
</ul>
                        
</div>
                        
<div id="row" style="width:250px;text-align:center;">
                            
<ul>
                                
<li>组群名称</li><li><input type="text" /></li>
                            
</ul>
                        
</div>
                        
<div id="row" style="width:250px;text-align:center;">
                            
<ul>
                                
<li style="width:250px;"><img src="/images/submit.jpg" alt="提交" border="0" onclick="submitAddLinkman();"/><img src="/images/cancel.jpg" alt="取消" onclick="cancalAdd('addGroupDiv');"/></li>
                            
</ul>
                        
</div>
                    
</div>
                    
<div id="frmBottom"></div>
                 
</div>
                   

                

               
            
</div>
            
<div id="modifyGroupDiv" style="display:none; position:absolute;top:100px;">
                   
<div id="moveDiv" style="width:240px;background-color:#FF9900;">新增组群</div>

                        
<div id="row">
                            
<input type="text" readonly="readonly" style="color:Gray;border:solid 1px Gray;"/>
                        
</div>
                        
<div id="row"><input type="text" /></div>
                            
                        
<div>
                            
<href="javascript:void(0);" onclick="cancalAdd('modifyGroupDiv');">取消</a>
                        
</div>

               
            
</div>
      
</div>
    
</form>
                         

<script type="text/javascript"  defer="defer">
var dw=new slcDragWindow("addGroupDiv","frmTitle","closeFrame");
LoadXmlResult();


</script>

最下面这个LoadXmlResult()便是采用Ajax调用,当然,这里实际上没怎么体现Ajax的优势,只有点了某个节点,去取出此节点下对应的通讯录联系人员,才是真正的Ajax应用,在上面的js中GetResultXml(mid)才是。

刚初步实现了效果,没有重构,样式也没有整理,所以html和js的代码较凌散,还有部分未给出(实在是太多了),而且还有一些功能没有实现,比如全选,批量删除,把一个组中的的联系人员转到另一组中,对某条记录点右键菜单中列出复制,粘贴,剪贴,发送短信,编辑,删除等,有待日后完善,努力把web程序做的跟C/S可蓖美的用户体验,我今天所做只希望能起到抛砖引玉的作用,如果确实需要参考全部代码,可以用cleverfoxloving@gmail.com跟我联系,夜太深了,写的有些乱,请多包涵:)晚安。

2008-03-01 17:50:00 weijing_321 阅读数 959
  • Servlet+MYSQL+JQuery+Bootstrap企业费用管理系统

    费用管理是企业流通费用的管理,是企业财务管理的组成部分。费用管理的任务是:通过预测、计划、控制、核算、考核和分析,反映商品流通费支出、挖掘降低费用的潜力,提高经济效益。管理的形式有:计划管理、定额管理、预算管理、分口管理、分级管理等。企业对费用的具体管理工作,通常从三方面组织进行:(1) 由财会部门对企业全部费用支出及费用水平实行综合管理;按照企业内部组织的分工,实行分口负责,分级管理。(2)对各费用开支项目,据其不同的特点,采用不同的管理方法。如费用的定率、定额管理、费用包干节约提成制、内部资金券贴现等。企业设置总会计师或具备有精通管理业务的主管经理,也可实行总会计师或主管经理一支笔批示后,才能列支的管理方式

    366 人正在学习 去看看 刘英杰
导读:
  
  在项目中,有一个通讯录组以及通讯录的功能,通讯录组要求无限分级,树状结构显示 ,经过研究,完整地实现了树结构,效果如下还可以实时添加,修改,删除,使用ajax实现,客户端不会刷新
  下面先讲怎样在服务端实现这个树结构,首先,数据库设计至少三个字段,主建,名称,父节点(记录父节点主键),由于本项目中树结构较多,所以我用一个实体类来表示TreeEntity.cs
  using System;using System.Collections.Generic;using System.Text;namespace SmsSystem.Model{
  public class TreeEntity
  {
  public TreeEntity() { } public TreeEntity(int id, string name, int parentId) {
  this.id = id;
  this.name = name;
  this.parentId = parentId;
  } private int id;
  private string name;
  private int parentId;
  public int Id
  {
  get { return id; } set { id = value ; } } public string Name
  {
  get { return name; } set { name = value ; } } public int ParentId
  {
  get { return parentId; } set { parentId = value; } } }}
  
  数据库访问层我在一篇文件中曾经提到过http://blog.csdn.net/cleverfoxloving/archive/2006/09/15/1226956.aspx具体实现不详述了,我用一个类返回一个IList(没接触过C#的泛型的这里可能不明白,请参阅相关资料)
  /// /// 获得数据列表返回ArrayList ///
  public IList GetList(int companyRkey)
  {
  IList list = new List();
  DataSet ds = this.GetDatasetList(" company_Rkey = " + companyRkey);
  if (ds.Tables[0].Rows.Count > 0)
  {
  foreach (DataRow dr in ds.Tables[0].Rows)
  {
  TreeEntity tree = new TreeEntity();
  tree.Id = int.Parse(dr["Rkey"].ToString());
  tree.Name = dr["Groupname"].ToString();
  tree.ParentId = int.Parse(dr["Parent_rkey"].ToString());
  list.Add(tree);
  } } return list;
  }
  接下来要写一个通用的方法,由list递归生成xml,GetTreeXML.cs
  using System;using System.Data;using System.Collections.Generic;using System.Xml;using System.IO;using SmsSystem.Model;namespace SmsSystem.Utility{
  public class GetTreeXML
  {
  public GetTreeXML() {
  
  }
  public void addDataXml(XmlDocument xmlDoc, XmlElement xmlRootNode, IList list)
  {
  foreach(TreeEntity treeEntity in list){
  if (treeEntity.ParentId == int.Parse(xmlRootNode.GetAttribute("mid")))
  {
  XmlElement xmlNewElemene = xmlDoc.CreateElement("subject");
  
  xmlNewElemene.SetAttribute("mid", treeEntity.Id.ToString());
  xmlNewElemene.SetAttribute("name", treeEntity.Name);
  xmlNewElemene.SetAttribute("value", treeEntity.ParentId.ToString());
  xmlRootNode.AppendChild(xmlNewElemene);
  addDataXml(xmlDoc, xmlNewElemene, list);
  } } } public XmlDocument getGroupTree(IList list)
  {
  XmlDocument xmlDoc = new XmlDocument();
  XmlDeclaration objXmlDeclare = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
  xmlDoc.InsertBefore(objXmlDeclare, xmlDoc.DocumentElement);
  XmlElement xmlRootElem = xmlDoc.CreateElement("subject");
  xmlRootElem.SetAttribute("mid", "0");
  xmlRootElem.SetAttribute("name", "通讯录组群");
  xmlDoc.AppendChild(xmlRootElem);
  addDataXml(xmlDoc, xmlRootElem, list);
  return xmlDoc;
  } public string getGruopTreeStr(IList list)
  {
  return this.XmlDocumentToString(this.getGroupTree(list));
  } ///………………(其它树结构)
  public string XmlDocumentToString(XmlDocument doc)
  {
  MemoryStream stream = new MemoryStream();
  XmlTextWriter writer = new XmlTextWriter(stream, null);
  //writer.Formatting = Formatting.Indented; doc.Save(writer);
  StreamReader sr = new StreamReader(stream, System.Text.Encoding.UTF8);
  stream.Position = 0 string xmlString = sr.ReadToEnd();
  sr.Close();
  stream.Close();
  return xmlString;
  } }}
  
  这上面的四个方法是主要的核心方法,接下来就是客户端采用Ajax调用,以及有JS生成树结构显示了,只列出部分重要代码,首先简单说一个Ajax调用,采用AjaxPro.dll框架,具体用法参考相关资料,代码如下
  protected void Page_Load(object sender, EventArgs e)
  {
  AjaxPro.Utility.RegisterTypeForAjax(typeof(Address_AddressManage));
  
  
  } [AjaxPro.AjaxMethod]
  public string GetAddressGruopStr() {
  if (null != Session["userInfo"])
  {
  bool isAll = (((SmsSystem.BO.UserInfo)Session["userInfo"]).PopedomType == "1") ? true : false int userRkey = ((SmsSystem.BO.UserInfo)Session["userInfo"]).CustEmployee_Rkey;
  SmsSystem.BLL.AddressGroup addressGroupBll = new SmsSystem.BLL.AddressGroup();
  return addressGroupBll.getGroupTreeStr(userRkey, isAll);
  
  } else {
  Response.Redirect("Default.aspx");
  return null }
  } [AjaxPro.AjaxMethod]
  public DataSet GetAddressList(int AddressGroupRkey)
  {
  if (null != Session["userInfo"])
  {
  bool isAll = (((SmsSystem.BO.UserInfo)Session["userInfo"]).PopedomType == "1") ? true : false int userRkey = ((SmsSystem.BO.UserInfo)Session["userInfo"]).CustEmployee_Rkey;
  SmsSystem.BLL.AddressList AddressListBll = new SmsSystem.BLL.AddressList();
  return AddressListBll.GetDatasetList(userRkey, isAll, AddressGroupRkey);
  } else {
  Response.Redirect("Default.aspx");
  return null } }
  
  首先在Page_Load要注册Ajax框架,然后是两个供Ajax调用的方法,返回字符串,在客户端
  function swapClass(obj, cls) {
  obj.className = cls;
  }var TreeForm = document.getElementById("TreeForm");function SelChkBox(para){
  
  var bTrue=false with(TreeForm)
  for(i=0i  {
  if ((document.forms[0].elements[i].name=="chkbutton") && (document.forms[0].elements[i].value==para))
  {
  bTrue=!document.forms[0].elements[i].checked;
  document.forms[0].elements[i].checked=bTrue;
  break } } if (para=='All')
  {
  with(TreeForm)
  for (i=0i  {
  if(document.forms[0].elements[i].name=="chkbutton")
  {
  document.forms[0].elements[i].checked=bTrue;
  } } } else {
  SelectAllNode(para,bTrue);
  }}//点击一个节点的复选框function SelChkBoxSingle(para){
  var bTrue=false with(TreeForm)
  for(i=0i  {
  if ((document.forms[0].elements[i].name=="chkbutton") && (document.forms[0].elements[i].value==para))
  {
  bTrue=!document.forms[0].elements[i].checked;
  } else {
  document.forms[0].elements[i].checked = false } }}//选择一个节点function SelChkBoxSingle1(para){
  var bTrue=false with(TreeForm)
  for(i=0i  {
  if ((document.forms[0].elements[i].name=="chkbutton") && (document.forms[0].elements[i].value==para))
  {
  bTrue=!document.forms[0].elements[i].checked;
  document.forms[0].elements[i].checked=bTrue;
  } } else {
  if (document.forms[0].elements[i].checked) document.forms[0].elements[i].checked = !document.forms[0].elements[i].checked;
  } }}// checkbox onclickfunction SelChkBox1(para){
  var bTrue=false with(TreeForm)
  for(i=0i  {
  if ((document.forms[0].elements[i].name=="chkbutton") && (document.forms[0].elements[i].value==para))
  {
  bTrue=document.forms[0].elements[i].checked;
  break } } if (para=='All')
  {
  with(TreeForm)
  for(i=0i  {
  if(document.forms[0].elements[i].name=="chkbutton")
  {
  document.forms[0].elements[i].checked=bTrue;
  } } } else {
  SelectAllNode(para,bTrue);
  }}function SelectAllNode(sMidValue,bTrue){
  var xmlDoc1 = new ActiveXObject("MSXML.DOMDocument")
  xmlDoc1.async = false xmlDoc1.loadXML(xmlSSS)
  return SelectNode(xmlDoc1.documentElement,sMidValue,bTrue)
  }function SelectNode(oElem,sMidValue,bTrue){
  var retStr="" var oNodeList = oElem.childNodes
  if (GetAttributes(oElem,"mid")==sMidValue)
  {
  SelectChildNode(oElem,bTrue);
  if (bTrue)
  SelectParentNode(oElem,bTrue);
  else IsParentChecked(oElem);
  return } else {
  for (var i=0i<=oNodeList.length-1i++)
  {
  SelectNode(oNodeList.item(i),sMidValue,bTrue)
  } }}function SelectChildNode(oElem,bTrue){
  var oNodeList = oElem.childNodes
  for (var i=0i<=oNodeList.length-1i++)
  {
  ClickNode(GetAttributes(oNodeList.item(i),"mid"),bTrue);
  SelectChildNode(oNodeList.item(i),bTrue)
  }}//检查当前节点的父节点的子节点是否有被选中的。//如故没有,则父节点的CheckBox的checked=false;function IsParentChecked(oElem){
  var bExist=false do {
  if (GetAttributes(oElem,"mid")=="")
  break else {
  var pNode = oElem.parentNode
  var oNodeList = pNode.childNodes;
  for (var i=0i<=oNodeList.length-1i++)
  {
  if (IsNodeChecked(GetAttributes(oNodeList.item(i),"mid")))
  {
  bExist = true break } } if (bExist) break ClickNode(GetAttributes(pNode,"mid"),false);
  oElem=pNode;
  } } while(true);
  }//选中所有的父节点function SelectParentNode(oElem,bTrue){
  do {
  if (GetAttributes(oElem,"mid")=="")
  break else {
  var pNode=oElem.parentNode;
  ClickNode(GetAttributes(pNode,"mid"),bTrue);
  oElem=pNode;
  } } while(true);
  }//判断某一节点是否被选中。function IsNodeChecked(sMidValue){
  var bChecked=false with(TreeForm)
  for(i=0i  {
  if ((document.forms[0].elements[i].name=="chkbutton") && (document.forms[0].elements[i].value==sMidValue))
  {
  bChecked=document.forms[0].elements[i].checked;
  break } } return bChecked;
  }function ClickNode(sMidValue,bTrue){
  with(TreeForm)
  for(i=0i  {
  if ((document.forms[0].elements[i].name=="chkbutton") && (document.forms[0].elements[i].value==sMidValue))
  {
  document.forms[0].elements[i].checked=bTrue;
  break } }}var bAll=truebAll=trueif (bAll){
  sAllChecked=""}var tree = new WebFXTree('通讯录组',sAllChecked,"0","javascript:void(0);");
  tree.setBehavior('classic');function AddNode(oElem,oTreeNode){
  var oNewNode;
  if (oTreeNode==null)
  {
  oNewNode = tree;
  } else {
  var sChecked="" //if (GetAttributes(oElem,"value")=="1") // sChecked="checked"; if (GetAttributes(oElem,"type")=="subject")
  var oNewNode = new WebFXTreeItem(GetAttributes(oElem,"name"),sChecked,GetAttributes(oElem,"mid"),"javascript:SelChkBoxSingle('"+GetAttributes(oElem,"mid")+"')");
  else var oNewNode = new WebFXTreeItem(GetAttributes(oElem,"name"),sChecked,GetAttributes(oElem,"mid"),"javascript:GetResultXml('"+GetAttributes(oElem,"mid")+"')");
  oTreeNode.add(oNewNode);
  } var oNodeList = oElem.childNodes
  for (var i=0i<=oNodeList.length-1i++)
  {
  if (oElem.nodeType==1){
  AddNode(oNodeList.item(i),oNewNode)
  } }}function GetAttributes(oElm,AttrName){
  var sAttr="" for (var i=0i<=oElm.attributes.length-1i++)
  {
  if (oElm.attributes.item(i).nodeName==AttrName)
  {
  sAttr = oElm.attributes.item(i).nodeValue;
  break } } return sAttr
  }function LoadXmlResult(){
  document.getElementById("showAderessGroupTree").innerHTML="通讯录树正在载入……" SmsSystem.Address_AddressManage.GetAddressGruopStr(LoadXmlResult_callback);
  }function LoadXmlResult_callback(response){
  if(response.value == null){
  alert("没有任何数据!");
  return } xmlString = response.value;
  createTree("showAderessGroupTree",xmlString);
  
  }function createTree(treeDivId,xmlString){
  if (document.getElementById) {
  var xmlDoc = new ActiveXObject("MSXML.DOMDocument")
  xmlDoc.async = false xmlDoc.loadXML(xmlString)
  AddNode(xmlDoc.documentElement)
  
  document.getElementById(treeDivId).innerHTML=tree;
  //document.write(tree); // tree.expandAll() }}//添加资源function addGroup(){
  var str="" var name=""
  for(var i=0i  if(document.forms[0].chkbutton[i].checked==true){
  str=document.forms[0].chkbutton[i].value;
  name = document.forms[0].chkbutton[i].label;
  break
  }
  }
  if(str=='){
  alert('请选择待修改类别名称!');
  return false } document.all["addGroupDiv"].style.left=120 document.all["addGroupDiv"].style.top=140 document.all["addGroupDiv"].style.display="" document.getElementById("groupName").value=name;
  }function modifyGroup(){
  (修改的代码,省略…………)}function cancalAdd(divID){
  document.all[divID].style.display="none"}function GetResultXml(mid){
  SmsSystem.Address_AddressManage.GetAddressList(mid,GetResult_callback);
  
  }function GetResult_callback(response){
  
  if(response.value == null){
  alert("没有任何数据!");//可以自行添加对于无数据的处理流程 return }
  var dt = response.value.Tables[0];
  
  if (dt.Rows.length>0){
  
  fillContent(dt)
  }else{
  removeContent();
  var showAddressListt = document.getElementById("showAddressListt");
  var row=document.createElement('tr');
  row.setAttribute("height","26");
  row.setAttribute("bgColor","#FFFFFF");
  var cell=createCellth('没有记录,清先添加记录!');
  cell.setAttribute("width","380");
  row.appendChild(cell);
  showAddressListt.appendChild(row);
  return }
  }function removeContent(){
  var showAddressListt = document.getElementById("showAddressListt");
  while(showAddressListt.childNodes.length>0)
  {
  showAddressListt.removeChild(showAddressListt.childNodes[0]);
  }}function fillContent(dt){
  
  
  
  removeContent();
  if (dt){
  document.getElementById("addressListtTable").style.width="800px" //var showResult = document.getElementById("showResult"); var showAddressListt = document.getElementById("showAddressListt");
  //var tableContent = document.createElement("table"); //tableContent.setAttribute("bgColor","#FF0000"); //tableContent.setAttribute("width","300"); //增加一行,设置标题 var row=document.createElement('tr');
  row.setAttribute("height","26");
  row.setAttribute("bgColor","#FFFFFF");
  
  var cell=createCellth(');
  cell.setAttribute("width","30");
  row.appendChild(cell);
  cell=createCellth('序号');
  cell.setAttribute("width","60");
  row.appendChild(cell);
  cell=createCellth('姓名');
  cell.setAttribute("width","120");
  row.appendChild(cell);
  cell=createCellth('性别');
  cell.setAttribute("width","120");
  row.appendChild(cell);
  cell=createCellth('手机号');
  cell.setAttribute("width","120");
  row.appendChild(cell);
  cell=createCellth('生日');
  cell.setAttribute("width","200");
  row.appendChild(cell);
  cell=createCellth('公司名称');
  cell.setAttribute("width","120");
  row.appendChild(cell);
  cell=createCellth('公司电话');
  cell.setAttribute("width","120");
  row.appendChild(cell);
  cell=createCellth('公司传真');
  cell.setAttribute("width","120");
  row.appendChild(cell);
  cell=createCellth('职务');
  cell.setAttribute("width","100");
  row.appendChild(cell);
  cell=createCellth('备注');
  cell.setAttribute("width","100");
  row.appendChild(cell);
  cell=createCellth('创建日期');
  cell.setAttribute("width","140");
  row.appendChild(cell);
  
  showAddressListt.appendChild(row);
  //设置标题结束 //循环处理填充表格 for(var i=0i  
  
  
  var row=document.createElement('tr');
  row.setAttribute("height","23");
  if(i%2==0){
  row.setAttribute("bgColor","#FFFFFF");
  }else{
  row.setAttribute("bgColor","#F5F5F5");
  } var cell=createCheckbox(dt.Rows[i].Rkey);
  
  row.appendChild(cell);
  
  cell=createCelltd((i+1));
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].Name);
  row.appendChild(cell);
  var sex = "男" if(dt.Rows[i].Sex == '1'){
  sex = "女" } cell=createCelltd(sex);
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].MobileNo);
  row.appendChild(cell);
  var tempBirthday = new Date(dt.Rows[i].Birthday);
  cell=createCelltd(tempBirthday.toLocaleDateString());
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].ComName);
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].ComTel);
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].ComFax);
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].Duty);
  row.appendChild(cell);
  cell=createCelltd(dt.Rows[i].Remark);
  row.appendChild(cell);
  var tempFileDate = new Date(dt.Rows[i].FileDate);
  
  cell=createCelltd(tempFileDate.toLocaleDateString());
  row.appendChild(cell);
  //生成操作链接 //row.appendChild(addLink(smsID,smsContent));
  
  showAddressListt.appendChild(row);
  }
  //showResult.appendChild(tableContent); }}function createCellth(text){
  var cell=document.createElement('th');
  var textNode=document.createTextNode(text);
  cell.appendChild(textNode);
  return cell;
  }function createCelltd(text){
  var cell=document.createElement('td');
  cell.style.background ="#FFFFFF" //cell.setAttribute("bgcolor","#FFFFFF"); var textNode=document.createTextNode(text);
  cell.appendChild(textNode);
  return cell;
  }function createCheckbox(id){
  var cell=document.createElement('td');
  cell.style.background ="#FFFFFF" var input=document.createElement('input');
  input.setAttribute("id","selectId");
  input.setAttribute("name","id");
  input.setAttribute("type","checkbox");
  
  cell.appendChild(input);
  return cell;
  }
  
  以上是初步实现的部分js脚本,在未重构之前显得有些凌乱,还用到了一个WebFXTree的js树,是前辈高人写的,内容太多了,这里不便列出,页面上部分代码下如
  
>  
  • 通讯录组群
  • 通讯录

  •   
      
      

  •   
    通讯录联系人员

  

  最下面这个LoadXmlResult()便是采用Ajax调用,当然,这里实际上没怎么体现Ajax的优势,只有点了某个节点,去取出此节点下对应的通讯录联系人员,才是真正的Ajax应用,在上面的js中GetResultXml(mid)才是。
  刚初步实现了效果,没有重构,样式也没有整理,所以html和js的代码较凌散,还有部分未给出(实在是太多了),而且还有一些功能没有实现,比如全选,批量删除,把一个组中的的联系人员转到另一组中,对某条记录点右键菜单中列出复制,粘贴,剪贴,发送短信,编辑,删除等,有待日后完善,努力把web程序做的跟C/S可蓖美的用户体验,我今天所做只希望能起到抛砖引玉的作用,如果确实需要参考全部代码,可以用cleverfoxloving@gmail.com跟我联系,夜太深了,写的有些乱,请多包涵:)晚安。
  Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1298167

本文转自
http://blog.csdn.net/cleverfoxloving/archive/2006/09/28/1298167.aspx
2004-10-14 16:05:00 colayungnew 阅读数 670
  • Servlet+MYSQL+JQuery+Bootstrap企业费用管理系统

    费用管理是企业流通费用的管理,是企业财务管理的组成部分。费用管理的任务是:通过预测、计划、控制、核算、考核和分析,反映商品流通费支出、挖掘降低费用的潜力,提高经济效益。管理的形式有:计划管理、定额管理、预算管理、分口管理、分级管理等。企业对费用的具体管理工作,通常从三方面组织进行:(1) 由财会部门对企业全部费用支出及费用水平实行综合管理;按照企业内部组织的分工,实行分口负责,分级管理。(2)对各费用开支项目,据其不同的特点,采用不同的管理方法。如费用的定率、定额管理、费用包干节约提成制、内部资金券贴现等。企业设置总会计师或具备有精通管理业务的主管经理,也可实行总会计师或主管经理一支笔批示后,才能列支的管理方式

    366 人正在学习 去看看 刘英杰

 

本文描述了如何把Repeater 控件嵌套进DataGrid来显示分级的数据 。当然,你也可以将这一技术应用到其他的列表绑定控件上去,比如DataGrid包含DataGrid,DataList包含DataList等等的组合。

 

完整的代码 如下,要注意的是,

 

   DataGrid1.DataSource=dv;

    DataGrid1.DataBind();

 

一定要在ds.Relations.Add(..)之后..

 

<%@import namespace="System.Data" %>

<%@import namespace="System.Data.OleDb"%>

<script language="c#" runat="server">

string connstr=ConfigurationSettings.AppSettings["ConnectionString"];

 

//小区信息

string sql="select * from location where location_id in(select location from catalyst)";

//交换机信息

string sqltext="select * from catalyst order by location desc";

 

private void page_load(Object obj,EventArgs e)

{

  if(!Page.IsPostBack)

   {

     Dataload();

   }

}

 

private void Dataload()

{

     try

  { 

    OleDbConnection conn=new  OleDbConnection(connstr);

    DataSet ds=new DataSet();

    OleDbDataAdapter da=new OleDbDataAdapter(sql,conn);

    da.Fill(ds,"location");

    DataView dv=new DataView(ds.Tables["location"]);

 

    OleDbDataAdapter da2=new OleDbDataAdapter(sqltext,conn);

    da2.Fill(ds,"catalyst");

    ds.Relations.Add("myrelation",ds.Tables["location"].Columns["location_id"],ds.Tables["catalyst"].Columns["location"]);

 

    DataGrid1.DataSource=dv;

    DataGrid1.DataBind();

 

    conn.Close();

  }

  catch(OleDbException ex)

  {

    info.Text=ex.Message;

  }                

}

</script>

<html>

<body>

<form runat=server>

 

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="false">

  <Columns>

   <asp:TemplateColumn HeaderText="小区名">

   <ItemTemplate>

      <%# DataBinder.Eval(Container.DataItem,"location_name") %>

   </ItemTemplate>

   </asp:TemplateColumn>

   <asp:TemplateColumn HeaderText="交换机编号">

   <ItemTemplate>

     <asp:Repeater id="ChildRepeater" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' runat="server">

         <ItemTemplate>

            <%# Container.ItemIndex+1%>.<%# DataBinder.Eval(Container.DataItem, "[/"label/"]")%><br>

         </ItemTemplate>

      </asp:Repeater>

   </ItemTemplate>

   </asp:TemplateColumn>

  </Columns>

</asp:DataGrid>

 

 

</form>

<asp:label id="info" forecolor="blue" runat="server"/>

</body>

</html>

 

 

 

 

 

 

 

 

2007-03-02 12:53:00 aiqixiao2017 阅读数 65
  • Servlet+MYSQL+JQuery+Bootstrap企业费用管理系统

    费用管理是企业流通费用的管理,是企业财务管理的组成部分。费用管理的任务是:通过预测、计划、控制、核算、考核和分析,反映商品流通费支出、挖掘降低费用的潜力,提高经济效益。管理的形式有:计划管理、定额管理、预算管理、分口管理、分级管理等。企业对费用的具体管理工作,通常从三方面组织进行:(1) 由财会部门对企业全部费用支出及费用水平实行综合管理;按照企业内部组织的分工,实行分口负责,分级管理。(2)对各费用开支项目,据其不同的特点,采用不同的管理方法。如费用的定率、定额管理、费用包干节约提成制、内部资金券贴现等。企业设置总会计师或具备有精通管理业务的主管经理,也可实行总会计师或主管经理一支笔批示后,才能列支的管理方式

    366 人正在学习 去看看 刘英杰
 

具体方法是:创建一个数据库,设计树图信息表S_Menu,包含NodeIdParentIdNodeNameAddressIcon字段,其它字段根据实际业务而定,节点名称NodeName将在树型控件的节点上显示,NodeId字段保存节点的唯一标识号,ParentId表示当前节点的父节点号,标识号组成了一个“链表”,记录了树上节点的结构。设计一个Web窗体其上放置TreeView控件,修改其属性IdtvMenu

 

数据结构如下:
CREATE TABLE [dbo].[S_Menu] (
 [NodeId] [char] (6) COLLATE Chinese_PRC_CI_AS NULL ,
 [ParentId] [char] (6) COLLATE Chinese_PRC_CI_AS NULL ,
 [NodeName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Address] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Icon] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

 

数据库如下:
NodeId ParentId NodeName Address  Icon
100000 0  
公共查询部   icon_document.gif
100001 100000  
人民币日报查询 public/a1.aspx icon_settings.gif
100002 100000  
外币日报查询 public/a2.aspx icon_settings.gif
100003 0  
分行科技部   icon_document.gif
100004 100003  
人民币日报查询 tech/a1.aspx icon_settings.gif
100005 100003  
外币日报查询 tech/a2.aspx icon_settings.gif
100006 0  
福田支行   icon_document.gif
100007 100006  
月存款进度表 a1.aspx  icon_settings.gif
100008 100006  
月存款走势图 a2.aspx  icon_settings.gif
100009 0  
罗湖支行   icon_document.gif
100010 100009  
月存款进度表 a1.aspx  icon_settings.gif
100011 100009  
月存款走势图 a2.aspx  icon_settings.gif
    
menu_left.aspx
文件如下:
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Page language="c#" Codebehind="menu_Left.aspx.cs" AutoEventWireup="false" Inherits="hzquery.menu.menu_Left" %>
<HTML>
 <HEAD>
  <title>menu_Left</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="
http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="menu_Left" method="post" runat="server">
   <iewc:TreeView id="tvMenu" runat="server"></iewc:TreeView>
  </form>
 </body>
</HTML>

 

CodeBehind代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
using System.Data.SqlClient;

 

namespace hzquery.menu
{
 /// <summary>
 /// menu_Left
的摘要说明。
 /// </summary>
 public class menu_Left : System.Web.UI.Page
 {
  protected Microsoft.Web.UI.WebControls.TreeView tvMenu;
  SqlConnection Conn;
  SqlDataAdapter myCmd;
  DataSet ds;
  string cmdSelect;

 

  private void Page_Load(object sender, System.EventArgs e)
  {
   Conn=new SqlConnection(Application["ConnString"].ToString());
   CreateDataSet();
   InitTree(tvMenu.Nodes,"0");
  }
  //
建立数据集
  private DataSet CreateDataSet()
  {
   cmdSelect="select * from S_Menu";
   myCmd=new SqlDataAdapter(cmdSelect,Conn);
   ds=new DataSet();
   myCmd.Fill(ds,"tree");
   return ds;
  }
  //
建树的基本思路是:从根节点开始递归调用显示子树
         private void InitTree(TreeNodeCollection Nds,string parentId)
  {
   DataView dv=new DataView();
   TreeNode tmpNd;
   string intId;
   dv.Table=ds.Tables["tree"];
   dv.RowFilter="ParentId="" + parentId + """ ;
   foreach(DataRowView drv in dv)
   {
    tmpNd=new TreeNode();
    tmpNd.ID=drv["NodeId"].ToString();
    tmpNd.Text=drv["NodeName"].ToString();
    tmpNd.ImageUrl="../webimages/"+drv["Icon"].ToString();
    tmpNd.NavigateUrl="../"+drv["Address"].ToString();
    Nds.Add(tmpNd);
    intId=drv["ParentId"].ToString();
    InitTree(tmpNd.Nodes,tmpNd.ID);
   }
  }

 

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   InitializeComponent();
   base.OnInit(e);
  }
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);

 

  }
  #endregion
 }
}

转载于:https://www.cnblogs.com/nianshi/archive/2007/03/02/661511.html

DateSet使用技巧

阅读数 1714

没有更多推荐了,返回首页