个人账本管理系统+Windows phone 7客户端实现

个人账本管理系统

特点:

1.EasyUI实现网站管理维护 

2.Windows Phone 7客户端实现

3.后台WCF实现(暂还未实现) ,目前仅才用一般Ajax方法实现。

4.数据库才用sqlite 

 

先看主要界面欣赏:

 1。网站维护界面

 

 

 

 2。wphone7手机客户端界面

 

 

 功能说明:

 1.默认显示当月账单记录

 2.点击左边日期可以显示当天账单记录

 3.左边直接添加账单记录,很方便哟...

 5.右边部分:两个日期控件,点击可以显示指定日期的账单

 6.账单统计 实时更新

 7.datagrid 的toolbar上加了搜索,很有特色滴.....

 8.手机客户端 仅实现记账功能,更多功能继续完善....

 

介绍了这么多,重点就要来了:

代码实现:

 default.htm

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    
<title>账本系统</title>
    
<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" />
    
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
    
<script type="text/javascript" src="easyui/jquery-1.4.4.min.js"></script>
    
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    
<script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    
<script type="text/javascript" src="js/dateCore.js"></script>
    
<script type="text/javascript" src="Default.js"></script>
</head>
<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    
<div region="north" style="overflow: hidden; height: 25px; background: #D2E0F2;"
        border
="false">
        
<div style="height: 25px; margin-right: 10px; line-height: 25px; text-align: right;">
            我的简单记账系统
</div>
    
</div>
    
<div region="center" style="overflow: hidden;">
        
<div id="tabs" class="easyui-tabs" fit="true" border="false">
            
<div title="账单明细" style="padding: 5px; overflow: hidden;">
                
<div id="grid">
                
</div>
            
</div>
            
<div title="账单统计" style="padding: 5px; overflow: hidden;">
                
<div id="gridt">
                
</div>
            
</div>
        
</div>
    
</div>
    
<div region="south" style="height: 20px; background: #D2E0F2;" border="false">
        
<div style="text-align: center;">
            
&copy; 2011</div>
    
</div>
    
<div region="west" style="width: 200px; overflow: hidden;">
        
<div style="margin: 10px;">
            
<form id="ff" method="post">
            
<div id="cld" name="cld" style="width:180px;height:180px;"></div>
            
<div style=" margin-top:20px;">
                记账日期:
<br />
                
<input id="ConsumeDate" name="ConsumeDate" required="true"/>
            
</div>
            
<div>
                记账金额:
<br />
                
<input id="ConsumeAmount" name="ConsumeAmount" class="easyui-numberbox" min="1" type="text" style="width: 160px" required="true"/>
            
</div>
            
<div>
                记账大类:
<br />
                
<select id="Category" name="Category" class="easyui-combobox" style="width: 100px;" required="true">
                
</select>
            
</div>
            
<div>
                记账小类:
<br />
                
<select id="SubCategory" name="SubCategory" class="easyui-combobox" style="width: 160px;" required="true">
                
</select>
            
</div>
            
<div>
                记账描述:
<br />
                
<textarea id="AccountTips" name="AccountTips" style="height: 60px;width:160px;"></textarea>
            
</div>
            
<div style=" margin-top:10px;background:#efefef;width:166px; text-align:right">
                
<id="btnupdate" href="javascript:saveAccount();" iconCls="icon-save" class="easyui-linkbutton" plain="true">修改</a>
                
<id="btnadd" href="javascript:addAccount();" iconCls="icon-add" class="easyui-linkbutton" plain="true">添加</a>
            
</div>
            
</form>
        
</div>
    
</div>
    
<div region="east" style="width: 200px; overflow: hidden;" border="false">
        
<div style="margin: 7px 10px 10px 10px">
            
<div>
                条件过滤:
<br /><br />
                
<div id="cld1" name="cld1" style="width:180px;height:180px;"></div>
                
<br /><div id="cld2" name="cld2" style="width:180px;height:180px;"></div>
                
<input id="txtcld1" type="hidden"/>
                
<input id="txtcld2" type="hidden"/>
            
</div>
            
<div style=" margin-top:5px;">
                
<br />记账大类:<br />
                
<select id="CategoryFilter" name="CategoryFilter" class="easyui-combobox" style="width: 120px;">
                
</select>
                
<br />记账小类:<br />
                
<select id="SubCategoryFilter" name="SubCategoryFilter" class="easyui-combobox" style="width: 180px;">
                
</select>
            
</div>
        
</div>
    
</div>

    
<div id="search-window" title="查询窗口" style="width: 350px; height: 200px;">
        
<div style="padding: 20px">
            
<div style=" margin-top:10px;">
                记账日期:
                
<input id="date1" name="date1" class="easyui-datebox" style="width: 100px;"/>
                -
                
<input id="date2" name="date2" class="easyui-datebox" style="width: 100px;"/>
            
</div>
            
<div style=" margin-top:10px;">
                记账类型:
                
<select id="cg" name="cg" class="easyui-combobox" style="width: 200px;">
                
</select>
            
</div>
        
</div>
        
<div style="text-align: center; padding: 5px;">
            
<href="javascript:void(0)" onclick="SearchOK()" id="btn-search" icon="icon-ok">确定</a>
            
<href="javascript:void(0)" onclick="closeSearchWindow()" id="btn-search-cancel" icon="icon-cancel">关闭</a>
        
</div>
    
</div>
    
<span id="searchTool" style="display: none;">
        搜索:
<input type="text" id="txtSearch" title="请输入关键字" onkeydown="if(event.keyCode==13) toolSearch();"/><href="javascript:toolSearch();" iconcls="icon-search" class="easyui-linkbutton" plain="true"></a>
    
</span>
</body>
</html>

 

dateCore.js

 

/*
Date.prototype.isLeapYear 判断闰年
Date.prototype.Format 日期格式化
Date.prototype.DateAdd 日期计算
Date.prototype.DateDiff 比较日期差
Date.prototype.toString 日期转字符串
Date.prototype.toArray 日期分割为数组
Date.prototype.DatePart 取日期的部分信息
Date.prototype.MaxDayOfDate 取日期所在月的最大天数
Date.prototype.WeekNumOfYear 判断日期所在年的第几周
StringToDate 字符串转日期型
IsValidDate 验证日期有效性
CheckDateTime 完整日期时间检查
daysBetween 日期天数差
*/
// 判断闰年   
//
---------------------------------------------------   
Date.prototype.isLeapYear = function()    
{    
    
return (0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0)));    
}    
   
//---------------------------------------------------   
//
 日期格式化   
//
 格式 YYYY/yyyy/YY/yy 表示年份   
//
 MM/M 月份   
//
 W/w 星期   
//
 dd/DD/d/D 日期   
//
 hh/HH/h/H 时间   
//
 mm/m 分钟   
//
 ss/SS/s/S 秒   
//
---------------------------------------------------   
Date.prototype.Format = function(format)    
{    
    
var o = {
    
"M+" : this.getMonth()+1//month
    "d+" : this.getDate(),    //day
    "h+" : this.getHours(),   //hour
    "m+" : this.getMinutes(), //minute
    "s+" : this.getSeconds(), //second
    "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
    "S" : this.getMilliseconds() //millisecond
  }
  
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
    (
this.getFullYear()+"").substr(4 - RegExp.$1.length));
  
for(var k in o)if(new RegExp("("+ k +")").test(format))
    format 
= format.replace(RegExp.$1,
      RegExp.$
1.length==1 ? o[k] : 
        (
"00"+ o[k]).substr((""+ o[k]).length));
  
return format;  
}    
   
//+---------------------------------------------------   
//
| 求两个时间的天数差 日期格式为 YYYY-MM-dd    
//
+---------------------------------------------------   
function daysBetween(DateOne,DateTwo)   
{    
    
var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));   
    
var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);   
    
var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));   
   
    
var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));   
    
var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);   
    
var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));   
   
    
var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);    
    return Math.abs(cha);   
}   
   
   
//+---------------------------------------------------   
//
| 日期计算   
//
+---------------------------------------------------   
Date.prototype.DateAdd = function(strInterval, Number) {    
    
var dtTmp = this;   
    
switch (strInterval) {    
        
case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number));   
        
case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number));   
        
case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number));   
        
case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number));   
        
case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7* Number));   
        
case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
        
case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
        
case 'y' :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
    }   
}   
   
//+---------------------------------------------------   
//
| 比较日期差 dtEnd 格式为日期型或者 有效日期格式字符串   
//
+---------------------------------------------------   
Date.prototype.DateDiff = function(strInterval, dtEnd) {    
    
var dtStart = this;   
    
if (typeof dtEnd == 'string' )//如果是字符串转换为日期型   
    {    
        dtEnd 
= StringToDate(dtEnd);   
    }   
    
switch (strInterval) {    
        
case 's' :return parseInt((dtEnd - dtStart) / 1000);   
        
case 'n' :return parseInt((dtEnd - dtStart) / 60000);   
        
case 'h' :return parseInt((dtEnd - dtStart) / 3600000);   
        
case 'd' :return parseInt((dtEnd - dtStart) / 86400000);   
        
case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7));   
        
case 'm' :return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12- (dtStart.getMonth()+1);   
        
case 'y' :return dtEnd.getFullYear() - dtStart.getFullYear();   
    }   
}   
   
//+---------------------------------------------------   
//
| 日期输出字符串,重载了系统的toString方法   
//
+---------------------------------------------------   
Date.prototype.toString = function(showWeek)   
{    
    
var myDate= this;   
    
var str = myDate.toLocaleDateString();   
    
if (showWeek)   
    {    
        
var Week = ['','','','','','',''];   
        str 
+= ' 星期' + Week[myDate.getDay()];   
    }   
    
return str;   
}   
   
//+---------------------------------------------------   
//
| 日期合法性验证   
//
| 格式为:YYYY-MM-DD或YYYY/MM/DD   
//
+---------------------------------------------------   
function IsValidDate(DateStr)    
{    
    
var sDate=DateStr.replace(/(^\s+|\s+$)/g,''); //去两边空格;    
    if(sDate==''return true;    
    
//如果格式满足YYYY-(/)MM-(/)DD或YYYY-(/)M-(/)DD或YYYY-(/)M-(/)D或YYYY-(/)MM-(/)D就替换为''    
    //数据库中,合法日期可以是:YYYY-MM/DD(2003-3/21),数据库会自动转换为YYYY-MM-DD格式    
    var s = sDate.replace(/[\d]{ 4,4 }[\-/]{ 1 }[\d]{ 1,2 }[\-/]{ 1 }[\d]{ 1,2 }/g,'');    
    
if (s==''//说明格式满足YYYY-MM-DD或YYYY-M-DD或YYYY-M-D或YYYY-MM-D    
    {    
        
var t=new Date(sDate.replace(/\-/g,'/'));    
        
var ar = sDate.split(/[-/:]/);    
        if(ar[0!= t.getYear() || ar[1!= t.getMonth()+1 || ar[2!= t.getDate())    
        {    
            
//alert('错误的日期格式!格式为:YYYY-MM-DD或YYYY/MM/DD。注意闰年。');    
            return false;    
        }    
    }    
    
else    
    {    
        
//alert('错误的日期格式!格式为:YYYY-MM-DD或YYYY/MM/DD。注意闰年。');    
        return false;    
    }    
    
return true;    
}    
   
//+---------------------------------------------------   
//
| 日期时间检查   
//
| 格式为:YYYY-MM-DD HH:MM:SS   
//
+---------------------------------------------------   
function CheckDateTime(str)   
{    
    
var reg = /^(\d+)-(\d{ 1,2 })-(\d{ 1,2 }) (\d{ 1,2 }):(\d{ 1,2 }):(\d{ 1,2 })$/;    
    
var r = str.match(reg);    
    
if(r==null)return false;    
    r[
2]=r[2]-1;    
    
var d= new Date(r[1],r[2],r[3],r[4],r[5],r[6]);    
    
if(d.getFullYear()!=r[1])return false;    
    
if(d.getMonth()!=r[2])return false;    
    
if(d.getDate()!=r[3])return false;    
    
if(d.getHours()!=r[4])return false;    
    
if(d.getMinutes()!=r[5])return false;    
    
if(d.getSeconds()!=r[6])return false;    
    
return true;    
}    
   
//+---------------------------------------------------   
//
| 把日期分割成数组   
//
+---------------------------------------------------   
Date.prototype.toArray = function()   
{    
    
var myDate = this;   
    
var myArray = Array();   
    myArray[
0= myDate.getFullYear();   
    myArray[
1= myDate.getMonth();   
    myArray[
2= myDate.getDate();   
    myArray[
3= myDate.getHours();   
    myArray[
4= myDate.getMinutes();   
    myArray[
5= myDate.getSeconds();   
    
return myArray;   
}   
   
//+---------------------------------------------------   
//
| 取得日期数据信息   
//
| 参数 interval 表示数据类型   
//
| y 年 m月 d日 w星期 ww周 h时 n分 s秒   
//
+---------------------------------------------------   
Date.prototype.DatePart = function(interval)   
{    
    
var myDate = this;   
    
var partStr='';   
    
var Week = ['','','','','','',''];   
    
switch (interval)   
    {    
        
case 'y' :partStr = myDate.getFullYear();break;   
        
case 'm' :partStr = myDate.getMonth()+1;break;   
        
case 'd' :partStr = myDate.getDate();break;   
        
case 'w' :partStr = Week[myDate.getDay()];break;   
        
case 'ww' :partStr = myDate.WeekNumOfYear();break;   
        
case 'h' :partStr = myDate.getHours();break;   
        
case 'n' :partStr = myDate.getMinutes();break;   
        
case 's' :partStr = myDate.getSeconds();break;   
    }   
    
return partStr;   
}   
   
//+---------------------------------------------------   
//
| 取得当前日期所在月的最大天数   
//
+---------------------------------------------------   
Date.prototype.MaxDayOfDate = function()   
{    
    
var myDate = this;   
    
var ary = myDate.toArray();   
    
var date1 = (new Date(ary[0],ary[1]+1,1));   
    
var date2 = date1.dateAdd(1,'m',1);   
    
var result = dateDiff(date1.Format('yyyy-MM-dd'),date2.Format('yyyy-MM-dd'));   
    
return result;   
}   
   
//+---------------------------------------------------   
//
| 取得当前日期所在周是一年中的第几周   
//
+---------------------------------------------------   
Date.prototype.WeekNumOfYear = function()   
{    
    
var myDate = this;   
    
var ary = myDate.toArray();   
    
var year = ary[0];   
    
var month = ary[1]+1;   
    
var day = ary[2];      
    
return result;   
}   
   
//+---------------------------------------------------   
//
| 字符串转成日期类型    
//
| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd   
//
+---------------------------------------------------   
function StringToDate(DateStr)   
{    
   
    
var converted = Date.parse(DateStr);   
    
var myDate = new Date(converted);   
    
if (isNaN(myDate))   
    {    
        
//var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';   
        var arys= DateStr.split('-');   
        myDate 
= new Date(arys[0],--arys[1],arys[2]);   
    }   
    
return myDate;   
}

 

 default.js

 


var grid;
var gridt;
var searchWin;
var consumedate;
$(
function () {
    $(
'#btn-search,#btn-search-cancel').linkbutton();
    searchWin 
= $('#search-window').window({
        closed: 
true,
        modal: 
false
    });
    $(
'#btnupdate').hide();
    $(
'#cld,#cld1,#cld2').calendar({
        onSelect: 
function (date) {
            
var cldid = this.id;
            
if (cldid == "cld") {
                selectCalendar(date);
            }
            
else {
                
var fdate = date.Format('yyyy-MM-dd');
                $(
"#txt" + cldid).val(fdate);
                filterGrid();
            }
        }
    });
    $(
'#Category,#CategoryFilter').combobox({
        url: 
'json/Category.json',
        valueField: 
'id',
        textField: 
'text'
    });
    $(
'#SubCategory,#SubCategoryFilter,#cg').combobox({
        url: 
'ajax/AccountBook.ashx?action=getsubCategory&Category=' + $('#Category').val(),
        valueField: 
'id',
        textField: 
'text'
    });
    consumedate 
= $('#ConsumeDate').datebox({

    });
    
var fdatenow = new Date().Format('yyyy-MM-dd');
    consumedate.datebox(
'setValue', fdatenow);
    
var lastIndex;
    grid 
= $('#grid').datagrid({
        methord: 
'get',
        url: 
'ajax/AccountBook.ashx?action=default&ran=' + Math.random(),
        sortName: 
'ConsumeDate',
        sortOrder: 
'desc',
        idField: 
'RecordID',
        frozenColumns: [[
                            { field: 
'ck', checkbox: true }
                        ]],
        columns: [[
                            { field: 
'ConsumeDate', title: '记账日期', width: 60, sortable: true, editor: 'text' },
                            { field: 
'ConsumeAmount', title: '记账金额', width: 60, sortable: true, editor: 'numberbox', align: 'right' },
                            { field: 
'SubCategory', title: '记账小类', width: 80, sortable: true, editor: 'text' },
                            { field: 
'Category', title: '记账大类', width: 40, sortable: true, editor: 'text' },
                            { field: 
'AccountTips', title: '记账描述', width: 140, editor: 'textarea' },
                            { field: 
'RecordDate', title: '录入时间', width: 80 },
                            { field: 
'action', title: 'Action', width: 30, align: 'center',
                                formatter: 
function (value, row, index) {
                                    
if (row.SubCategory != "合计:") {
                                        
if (row.editing) {
                                            
var s = '<a href="#" onclick="saverow(' + index + ')">Save</a> ';
                                            
var c = '<a href="#" onclick="cancelrow(' + index + ')">Cancel</a>';
                                            
return s + c;
                                        } 
else {
                                            
var e = '<a href="#" onclick="editrow(' + index + ')">Edit</a> ';
                                            
var d = '<a href="#" onclick="del(' + row.RecordID + ')">Delete</a>';
                                            
return e + d;
                                        }
                                    }
                                }
                            }
                        ]],
        showFooter: 
true,
        fit: 
true,
        striped: 
true,
        rownumbers: 
true,
        fitColumns: 
true,
        toolbar: [{
            text: 
'删除',
            iconCls: 
'icon-remove',
            handler: delSelected
        }, 
'-', {
            text: 
'查询',
            iconCls: 
'icon-search',
            handler: OpensearchWin
        }, 
'-', {
            text: 
'所有',
            iconCls: 
'icon-reload',
            handler: showAll
        }, 
'-', {
            text: 
'保存更改',
            iconCls: 
'icon-save',
            handler: savechange
        }, 
'-'
                ],
        onClickRow: 
function (rowIndex, rowData) {
            editAccount(rowData.RecordID);
        },
        onBeforeEdit: 
function (index, row) {
            row.editing 
= true;
            $(
'#grid').datagrid('refreshRow', index);
        },
        onAfterEdit: 
function (index, row) {
            row.editing 
= false;
            $(
'#grid').datagrid('refreshRow', index);
        },
        onCancelEdit: 
function (index, row) {
            row.editing 
= false;
            $(
'#grid').datagrid('refreshRow', index);
        },
        onLoadSuccess: 
function () {
            $(
'.datagrid-toolbar').append($('#searchTool'));
            $(
'#searchTool').show();
        }
    });
    gridt 
= $('#gridt').datagrid({
        methord: 
'get',
        url: 
'ajax/AccountBook.ashx?action=default&ran=' + Math.random(),
        sortName: 
'Category',
        sortOrder: 
'asc',
        pageSize: 
30,
        columns: [[
                            { field: 
'Category', title: '记账大类', width: 40, sortable: true },
                            { field: 
'SubCategory', title: '记账小类', width: 80, sortable: true },
                            { field: 
'ConsumeAmount', title: '记账金额', width: 60, sortable: true, align: 'right' }
                     ]],
        showFooter: 
true,
        fit: 
true,
        rownumbers: 
true,
        fitColumns: 
true
    });
    $(
'body').layout();
});
function editrow(index) {
    grid.datagrid(
'beginEdit', index);
}
function deleterow(index) {
    $.messager.confirm(
'Confirm''Are you sure?'function (r) {
        
if (r) {
            grid.datagrid(
'deleteRow', index);
        }
    });
}
function saverow(index) {
    grid.datagrid(
'endEdit', index);
    savechange();
}
function cancelrow(index) {
    grid.datagrid(
'cancelEdit', index);
}
function savechange() {
    
var rows = grid.datagrid('getChanges');
    
if (rows.length > 0) {
        
var account = {
            
'action''saveinline',
            
'RecordID': rows[0].RecordID,
            
'ConsumeDate': rows[0].ConsumeDate,
            
'ConsumeAmount': rows[0].ConsumeAmount,
            
'Category': rows[0].Category,
            
'SubCategory': rows[0].SubCategory,
            
'AccountTips': rows[0].AccountTips
        }
        $.post(
'ajax/AccountBook.ashx',
            account,
            
function (result) {
                
            }
        );
    }
    grid.datagrid(
'acceptChanges');
}
function filterGrid() {
    
var date1 = $("#txtcld1").val();
    
var date2 = $("#txtcld2").val();
    
if (date1.length > 0 & date2.length > 0) {
        $(
'#grid').datagrid('options').url = 'ajax/AccountBook.ashx?action=filter&date1=' + date1 + '&date2=' + date2;
        $(
'#grid').datagrid("reload");
        $(
'#gridt').datagrid('options').url = 'ajax/AccountBook.ashx?action=filter&date1=' + date1 + '&date2=' + date2;
        $(
'#gridt').datagrid("reload");
//        grid.datagrid({ url: 'ajax/AccountBook.ashx?action=filter&date1=' + date1 + '&date2=' + date2 });
//
        gridt.datagrid({ url: 'ajax/AccountBook.ashx?action=filter&date1=' + date1 + '&date2=' + date2 });
    }
}
function selectCalendar(date) {
    
var fdate = date.Format('yyyy-MM-dd');
    consumedate.datebox(
'setValue', fdate);
    $(
'#grid').datagrid('options').url = 'ajax/AccountBook.ashx?action=get&date=' + fdate;
    $(
'#grid').datagrid("reload");
    $(
'#gridt').datagrid('options').url = 'ajax/AccountBook.ashx?action=get&date=' + fdate;
    $(
'#gridt').datagrid("reload");
//    grid.datagrid({ url: 'ajax/AccountBook.ashx?action=get&date=' + fdate });
//
    gridt.datagrid({ url: 'ajax/AccountBook.ashx?action=get&date=' + fdate });
}
function editAccount(id) {
    $(
'#ff').form('load''ajax/AccountBook.ashx?action=getsingle&id=' + id);
    $(
'#ff').form.url = 'ajax/AccountBook.ashx?action=save&id=' + id;
    $(
'#btnupdate').show();
}
function addAccount() {
    $(
'#ff').form.url = 'ajax/AccountBook.ashx?action=save';
    saveAccount();
    $(
'#btnupdate').hide();
}
function saveAccount() {
    $(
'#ff').form('submit', {
        url: $(
'#ff').form.url,
        onSubmit: 
function () {
            
return $(this).form('validate');
        },
        success: 
function (data) {
            eval(
'data=' + data);
            
if (data.success) {
                grid.datagrid(
'reload');
                gridt.datagrid(
'reload');
            } 
else {
                $.messager.alert(
'错误', data.msg, 'error');
            }
        }
    });
}
function OpensearchWin() {
    searchWin.window(
'open');
}
function toolSearch() {
    
var txt = $('#txtSearch').val();
    
if (txt.length > 0) {
        $(
'#grid').datagrid('options').url = 'ajax/AccountBook.ashx?action=query&search=' + escape(txt);
        $(
'#grid').datagrid("reload");
        $(
'#gridt').datagrid('options').url = 'ajax/AccountBook.ashx?action=query&search=' + escape(txt);
        $(
'#gridt').datagrid("reload");
    }
}
function SearchOK() {
    grid.datagrid({ url: 
'ajax/AccountBook.ashx?action=filter',
        queryParams: { date1: $(
'#date1').val() }
    });
}
function closeSearchWindow() {
    searchWin.window(
'close');
}
function showAll() {
    grid.datagrid({ url: 
'ajax/AccountBook.ashx?action=get' });
    gridt.datagrid({ url: 
'ajax/AccountBook.ashx?action=get' });
}
function delSelected() {
    
var arr = getSelectedArr();
    
if (arr.length > 0) {
        del(arr.join(
','));
    } 
else {
        $.messager.show({
            title: 
'提示',
            msg: 
'请先选择要删除的记录。',
            showType: 
'show'
        });
    }
}
function del(ids) {
    $.messager.confirm(
'提示信息''您确认要删除吗?'function (data) {
        
if (data) {
            $.ajax({
                url: 
'ajax/AccountBook.ashx?action=del&id=' + ids,
                type: 
'GET',
                timeout: 
1000,
                error: 
function () {
                    $.messager.alert(
'错误''删除失败!''error');
                },
                success: 
function (data) {
                    eval(
'data=' + data);
                    
if (data.success) {
                        grid.datagrid(
'reload');
                        grid.datagrid(
'clearSelections');
                        gridt.datagrid(
'reload');
                    } 
else {
                        $.messager.alert(
'错误', data.msg, 'error');
                    }
                }
            });
        }
    });
}
function getSelectedArr() {
    
var ids = [];
    
var rows = grid.datagrid('getSelections');
    
for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].RecordID);
    }
    
return ids;
}

 

AccountBook.ashx

 


using System;
using System.Web;
using System.Data;
using System.Text;
using Utility4Net;
using Utility4Net.Web;
using Utility4Net.Web.Object;

public class AccountBook : IHttpHandler
{
    
private string connectString = string.Empty;
    
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType 
= "text/plain";
        
string sReturnJson = string.Empty;
        
string action = ParamsofEasyUI.RequstString("action");
        
switch (action)
        {
            
case "default":
            
case "get":
            
case "filter":
            
case "query":
            
case "total":
                sReturnJson 
= getData(action);
                
break;
            
case "getsingle":
                sReturnJson 
= getSingleData();
                
break;
            
case "getCategory":
                sReturnJson 
= getCategory();
                
break;
            
case "getsubCategory":
                sReturnJson 
= getsubCategory();
                
break;
            
case "save":
                sReturnJson 
= saveData();
                
break;
            
case "saveinline":
                sReturnJson 
= saveinlineData();
                
break;
            
case "save4phone":
                sReturnJson 
= saveData4Phone();
                
break;
            
case "del":
                sReturnJson 
= delete();
                
break;
            
default:
                
break;
        }
        context.Response.Write(sReturnJson);
    }
    
private string delete()
    {
        
string sReturnJson = string.Empty;
        
string id = ParamsofEasyUI.RequstString("id");
        
if (Account.Instance.deleteAccount(id))
            sReturnJson 
= "{success:true}";
        
else
            sReturnJson 
= "{success:false}";
        
return sReturnJson;
    }
    
private string saveData4Phone()
    {
        
string sReturnJson = string.Empty;
        
string id = RequestAccessor.QueryString("id");
        
string AccountTips = RequestAccessor.QueryString("AccountTips");
        
string Category = RequestAccessor.QueryString("Category");
        
string SubCategory = RequestAccessor.QueryString("SubCategory");
        
string ConsumeAmount = RequestAccessor.QueryString("ConsumeAmount");
        
string ConsumeDate = RequestAccessor.QueryString("ConsumeDate");
        ConsumeDate 
= DateTime.Parse(ConsumeDate).ToString("yyyy-MM-dd");
        AccountModel mode 
= new AccountModel();
        mode.AccountTips 
= AccountTips;
        mode.Category 
= Category;
        mode.SubCategory 
= SubCategory;
        mode.ConsumeAmount 
= Decimal.Parse(ConsumeAmount);
        mode.ConsumeDate 
= ConsumeDate;
        
if (id.Length > 0)
        {
            mode.RecordID 
= int.Parse(id);
            
if (Account.Instance.updateAccount(mode))
                sReturnJson 
= "{success:true}";
            
else
                sReturnJson 
= "{success:false,msg:'保存信息失败'}";
        }
        
else
        {
            
if (Account.Instance.insertAccount(mode))
                sReturnJson 
= "{success:true}";
            
else
                sReturnJson 
= "{success:false,msg:'保存信息失败'}";
        }
        
return sReturnJson;
    }
    
private string saveinlineData()
    {
        
string sReturnJson = string.Empty;
        
string id = ParamsofEasyUI.RequstString("id");
        
string AccountTips = ParamsofEasyUI.RequstString("AccountTips");
        
string Category = ParamsofEasyUI.RequstString("Category");
        
string SubCategory = ParamsofEasyUI.RequstString("SubCategory");
        
string ConsumeAmount = ParamsofEasyUI.RequstString("ConsumeAmount");
        
string ConsumeDate = ParamsofEasyUI.RequstString("ConsumeDate");
        ConsumeDate 
= DateTime.Parse(ConsumeDate).ToString("yyyy-MM-dd");
        AccountModel mode 
= new AccountModel();
        mode.AccountTips 
= AccountTips;
        mode.Category 
= Category;
        mode.SubCategory 
= SubCategory;
        mode.ConsumeAmount 
= Decimal.Parse(ConsumeAmount);
        mode.ConsumeDate 
= ConsumeDate;
        
if (id.Length > 0)
        {
            mode.RecordID 
= int.Parse(id);
            
if (Account.Instance.updateAccount(mode))
                sReturnJson 
= "{success:true}";
            
else
                sReturnJson 
= "{success:false,msg:'保存信息失败'}";
        }
        
else
        {
            
if (Account.Instance.insertAccount(mode))
                sReturnJson 
= "{success:true}";
            
else
                sReturnJson 
= "{success:false,msg:'保存信息失败'}";
        }
        
return sReturnJson;
    }
    
private string saveData()
    {
        
string sReturnJson = string.Empty;
        
string id = ParamsofEasyUI.RequstString("id");
        
string AccountTips = ParamsofEasyUI.RequstForm("AccountTips");
        
string Category = ParamsofEasyUI.RequstForm("Category");
        
string SubCategory = ParamsofEasyUI.RequstForm("SubCategory");
        
string ConsumeAmount = ParamsofEasyUI.RequstForm("ConsumeAmount");
        
string ConsumeDate = ParamsofEasyUI.RequstForm("ConsumeDate");
        ConsumeDate 
= DateTime.Parse(ConsumeDate).ToString("yyyy-MM-dd");
        AccountModel mode 
= new AccountModel();
        mode.AccountTips 
= AccountTips;
        mode.Category 
= Category;
        mode.SubCategory 
= SubCategory;
        mode.ConsumeAmount 
= Decimal.Parse(ConsumeAmount);
        mode.ConsumeDate 
= ConsumeDate;
        
if (id.Length > 0)
        {
            mode.RecordID 
= int.Parse(id);
            
if (Account.Instance.updateAccount(mode))
                sReturnJson 
= "{success:true}";
            
else
                sReturnJson 
= "{success:false,msg:'保存信息失败'}";
        }
        
else
        {
            
if (Account.Instance.insertAccount(mode))
                sReturnJson 
= "{success:true}";
            
else
                sReturnJson 
= "{success:false,msg:'保存信息失败'}";
        }
        
return sReturnJson;
    }
    
private string getsubCategory()
    {
        StringBuilder sb 
= new StringBuilder();
        DataTable dt 
= Account.Instance.getsubCategory(ParamsofEasyUI.RequstString("Category"));
        sb.Append(
"[");
        
for (int i = 0; i < dt.Rows.Count; i++)
        {
            
if (i > 0)
                sb.Append(
",");
            sb.Append(Json4EasyUI.onForm(dt,dt.Rows[i]));
        }
        sb.Append(
"]");
        
return sb.ToString();
    }
    
private string getCategory()
    {
        StringBuilder sb 
= new StringBuilder();
        DataTable dt 
= Account.Instance.getCategory();
        sb.Append(
"[");
        
for (int i = 0; i < dt.Rows.Count; i++)
        {
            
if (i > 0)
                sb.Append(
",");
            sb.Append(Json4EasyUI.onForm(dt,dt.Rows[i]));
        }
        sb.Append(
"]");
        
return sb.ToString();
    }
    
private string getSingleData()
    {
        
string id = ParamsofEasyUI.RequstString("id");
        DataTable dt 
= Account.Instance.getSingleAccount(id);
        
return Json4EasyUI.onForm(dt);
    }
    
private string getData(string action)
    {
        
string order = ParamsofEasyUI.order;
        
string sort = ParamsofEasyUI.sort;
        
string sWhere = string.Empty;
        
switch (action)
        {
            
case "get":
                
string date = ParamsofEasyUI.RequstString("date");
                
if (!string.IsNullOrEmpty(date))
                    sWhere 
= " where ConsumeDate='" + date + "'";
                
break;
            
case "filter":
                sWhere 
= " where 1=1 ";
                
string date1 = ParamsofEasyUI.RequstString("date1");
                
string date2 = ParamsofEasyUI.RequstString("date2");
                
if (!string.IsNullOrEmpty(date1))
                    sWhere 
+= " and ConsumeDate >='" + date1 + "'";
                
if (!string.IsNullOrEmpty(date2))
                    sWhere 
+= " and ConsumeDate <='" + date2 + "'";
                
break;
            
case "default":
                
string dateMonth = System.DateTime.Now.ToString("yyyy-MM");
                sWhere 
= " where ConsumeDate like'" + dateMonth + "%'";
                
break;
            
case "query":
                sWhere 
= " where 1=1 ";
                
string cg = ParamsofEasyUI.RequstString("cg");
                
string search = ParamsofEasyUI.RequstString("search");
                
if (!string.IsNullOrEmpty(search))
                    sWhere 
+= " and (Category like '%" + search + "%' or SubCategory like '%" + search + "%')";
                
if (!string.IsNullOrEmpty(cg))
                    sWhere 
+= " and Category like '%" + cg + "%'";
                
break;   
            
default:
                
break;
        }
        DataTable dt 
= Account.Instance.getAccount(sWhere, order, sort);
        
string gridjson = "";
        
//if (action.Equals("total"))
        
//{
            double dtotal=0;
            
foreach (DataRow dr in dt.Rows)
            {
                dtotal 
= dtotal + double.Parse(dr["ConsumeAmount"].ToString());
            }
            StringBuilder fItems 
= new StringBuilder();
            fItems.Append(
"{");
            fItems.Append(
"\"SubCategory\":\"合计:\",");
            fItems.Append(
"\"ConsumeAmount\":\"" + dtotal.ToString()+ "\"");
            fItems.Append(
"}");
            gridjson 
= Json4EasyUI.onGridFooter(dt, fItems.ToString());
        
//}
        
//else
        
//{
        
//    gridjson= Json4EasyUI.onDataGrid(dt, dt.Rows.Count);
        
//}
        return gridjson;
    }
    
public bool IsReusable {
        
get {
            
return false;
        }
    }


至于json4easyui类,可参见我之前的文章

这里把新增的函数公布如下:

 

public static string onGridFooter(DataTable dt, string footer)
    {
        StringBuilder sb 
= new StringBuilder();
        sb.Append(
"{");
        sb.Append(GirdTotal(dt.Rows.Count.ToString()));
        sb.Append(
",");
        sb.Append(GridRows(dt));
        sb.Append(
",");
        sb.Append(GridFooter(footer));
        sb.Append(
"}");
        
return sb.ToString();
    }
    
public static string GirdTotal(string count)
    {
        
return "\"total\":" + count;
    }
    
public static string GridRows(DataTable dt)
    {
        StringBuilder jsonBuilder 
= new StringBuilder();
        jsonBuilder.Append(
"\"rows\":[");
        
for (int i = 0; i < dt.Rows.Count; i++)
        {
            jsonBuilder.Append(
"{");
            
for (int j = 0; j < dt.Columns.Count; j++)
            {
                jsonBuilder.Append(
"\"");
                jsonBuilder.Append(dt.Columns[j].ColumnName);
                jsonBuilder.Append(
"\":\"");
                jsonBuilder.Append(dt.Rows[i][j].ToString());
                jsonBuilder.Append(
"\",");
            }
            jsonBuilder.Remove(jsonBuilder.Length 
- 11);
            jsonBuilder.Append(
"},");
        }
        jsonBuilder.Remove(jsonBuilder.Length 
- 11);
        jsonBuilder.Append(
"]");
        
return jsonBuilder.ToString();
    }
    
public static string GridFooter(string items)
    {
        StringBuilder jsonBuilder 
= new StringBuilder();
        jsonBuilder.Append(
"\"footer\":[");
        jsonBuilder.Append(items);
        jsonBuilder.Append(
"]");
        
return jsonBuilder.ToString();
    }

 

windows phone 7 手机客户端代码实现:


private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            UriBuilder fullUri 
= new UriBuilder("http://localhost/AccountBook/ajax/AccountBook.ashx");
            fullUri.Query 
= @"action=save4phone
                        &AccountTips=
" + AccountTips.Text + @"
                        &Category=
" + Category.Text + @"
                        &SubCategory=
" + SubCategory.Text + @"
                        &ConsumeAmount=
" + ConsumeAmount.Text + @"
                        &ConsumeDate=
" + ConsumeDate.Text;
            
// 创建WebRequest
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(fullUri.Uri);
            
// 创建同步的AsyncRequest
            UpdateState State = new UpdateState();
            State.AsyncRequest 
= myRequest;
            
// 开始异步请求
            myRequest.BeginGetResponse(new AsyncCallback(HandleMyResponse), State);
        }
        
private void HandleMyResponse(IAsyncResult asyncResult)
        {
            
// 获取返回的信息
            UpdateState myState = (UpdateState)asyncResult.AsyncState;
            HttpWebRequest myRequest 
= (HttpWebRequest)myState.AsyncRequest;
            
//结束异步请求
            myState.AsyncResponse = (HttpWebResponse)myRequest.EndGetResponse(asyncResult);
            Stream streamResult 
= myState.AsyncResponse.GetResponseStream();

            Deployment.Current.Dispatcher.BeginInvoke(() 
=>
            {
                
if (streamResult.Length != 0)
                {
                    StreamReader sr 
= new StreamReader(streamResult);
                    MessageBox.Show(sr.ReadToEnd());
                }
            });
        }

 

public class UpdateState
    {
        
public HttpWebRequest AsyncRequest { getset; }
        
public HttpWebResponse AsyncResponse { getset; }
    }

 

 多有代码都贴出来了,程序文件就暂时不打包下载;

等实现了wcf和windows phone 手机客户端完善了后在将源码打包. 

posted @ 2011-04-08 16:01  undefined?  阅读(2060)  评论(0编辑  收藏  举报