var app={};
var table_Name;
var panel;
var data;
var grid={};
var combobox;
var URLSTR;
function DataColumn() {
this.fields = '';
this.columns = '';
this.addColumns=function(name,caption){
if(this.fields.length > 0)
{
this.fields += ',';
}
if(this.columns.length > 0){
this.columns += ',';
}
this.fields += '{name:"' + name + '"}';
if(name=="sex")
this.columns += '{header:"' + caption + '",dataIndex:"' + name + '",width:100,sortable:false,renderer:function(val){if(val=="") return "";return app.SexStore.getAt(app.SexStore.find("SexValue",val))["data"]["SexName"];}}';
else if(name=="SCODE")
this.columns += '{header:"' + caption + '",dataIndex:"' + name + '",width:100,sortable:false,renderer:function(val){if(val=="") return "";if(app.ChronicDiseaseStore.find("ChronicDiseaseValue",val)!=-1){return app.ChronicDiseaseStore.getAt(app.ChronicDiseaseStore.find("ChronicDiseaseValue",val))["data"]["ChronicDiseaseName"];}else{return val;}}}';
else if(name=="RId"||name=="SubUnit"||name=="MemCard"||name=="SCID")
this.columns += '{header:"' + caption + '",dataIndex:"' + name + '",hidden:true}';
else
this.columns += '{header:"' + caption + '",dataIndex:"' + name + '",width:100,sortable:false}';
};
}
function DataGrid(URL) {
var cm = new Ext.grid.ColumnModel(eval('([' + data.columns + '])'));
cm.defaultSortable = true;
var fields = eval('([' + data.fields + '])');
var newStore = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:URL}),
reader:new Ext.data.JsonReader({totalProperty:"totalPorperty",root:"result",fields:fields})
});
newStore.load({params:{columns:app.displayColumns,Name:Ext.getCmp('name').getValue(),Gender:Ext.getCmp('Gender').getValue(),ComId:Ext.getCmp('CreateCombQ').getValue(),SCODE:Ext.getCmp('ChronicDisease').getValue(),AdCon:CreateQueryXML(),MEMCARD:MEMCARD,ChronicId:ChronicId,NewAction:true}});
var pagingBar = new Ext.PagingToolbar({
displayInfo:true,
beforePageText:"第",
firstText:"第一页",
prevText:"上页",
nextText:"下页",
lastText:"最后页",
refreshText:"刷新",
emptyMsg:"没有符合条件的记录",
displayMsg:"第{0}条到{1}条,一共{2}条",
store:newStore,
pageSize:20 });
app.gridPanel = new Ext.grid.GridPanel({
cm:cm,
id:"grid_panel",
renderTo:"QueryGrid",
store:newStore,
frame:true,
border:true,
loadMask:true,
layout:"fit",
//pageSize:16,
// viewConfig:{autoFill:true,sortAscText:'正序',sortDescText:'降序'},
height:document.body.clientHeight-208,
width:document.body.clientWidth-4,
viewConfig:{forceFit:true},
tbar:pagingBar,
listeners:{cellclick:function(grid,rowIndex,columnIndex,e){
var rec=grid.getSelectionModel().getSelected();
if(Flag=="1")
{
//alert(rec['data']['SubUnit']);
window.close();
dialogArguments.app.SelectedID=rec['data']['RId'];
dialogArguments.app.SelectedComId=rec['data']['SubUnit']
dialogArguments.Ext.getCmp('RID').setValue(rec['data']['RId']);
dialogArguments.LoadFollowUpRow();
if(dialogArguments.FollowUpStore.find("RId",rec['data']['RId'])!=-1)
dialogArguments.app.VisitRecordGrid.getSelectionModel().selectRow(dialogArguments.FollowUpStore.find("RId",rec['data']['RId']));
else
dialogArguments.app.VisitRecordGrid.getSelectionModel().clearSelections();
} else if(Flag=="2"){
window.close();
dialogArguments.app.SelectedID=rec['data']['RId'];
dialogArguments.app.SelectedComId=rec['data']['SubUnit']
dialogArguments.SelectedRow();
if(dialogArguments.followUpStore.find("RId",rec['data']['RId'])!=-1)
dialogArguments.FollowUpGrid.getSelectionModel().selectRow(dialogArguments.followUpStore.find("RId",rec['data']['RId']));
else
dialogArguments.FollowUpGrid.getSelectionModel().clearSelections();
}
},celldblclick:function(grid,rowIndex,columnIndex,e){
var rec=grid.getSelectionModel().getSelected();
if(Flag=="")
{
self.location="ChronicDiseaseFrame.aspx?MemCard="+ rec['data']['MemCard'] + "&ChronicId=" + rec['data']['SCID'] +"&FollowUpId="+rec['data']['RId'];
}
}}
});
}
function QueryTable(){
//app.QueryGrid.hide();
if(app.displayColumns=="")
{
Ext.Msg.alert('提示','请选择展示项目。');
app.QueryGrid.show();
return false;
}
if(Ext.getCmp('grid_panel')){
Ext.getCmp('grid_panel').destroy();
data.fields = '';
data.columns = '';
}
data = new DataColumn();
data.fields = '';
data.columns = '';
Ext.Ajax.request ({
url:"QueryVisitAction.ashx?method=GetQueryGrid",
params:{columns:app.displayColumns,AdCon:CreateQueryXML(),NewAction:true},
success:function(response,option) {
if(response.responseText==""){
Ext.Msg.alert("提示消息","可能没有数据!");
return;
}
var res = Ext.util.JSON.decode(response.responseText);
for(var i=0;i<res['result'].length;i++) {
for(var i=0;i<res['result'].length;i++){
data.addColumns(res['result'][i].name,res['result'][i].caption);
}
}
grid = new DataGrid("QueryVisitAction.ashx?method=GetQuery");
},
failure:function(){
Ext.Msg.alert("提示","查询出错,请检查网络连接是否超时。");
}
});
}
使用:QueryTable()
后台数据返回:
/// <summary>
/// 得到表的列
/// </summary>
/// <returns></returns>
protected string GetQueryGrid()
{
string colums="";
colums += "{result:[";
colums += "{name:'RId',caption:'随访ID'},{name:'MemCard',caption:'MemCard'},{name:'SCID',caption:'慢病记录ID'},{name:'SubUnit',caption:'提交社区'},{name:'Name',caption:'姓名'},{name:'sex',caption:'性别'},{name:'SCODE',caption:'慢病分类'},{name:'FollowTime',caption:'随访日期'},";
if(!string.IsNullOrEmpty(_Columns))
{
string[] CL=_Columns.Split(',');
foreach (var item in CL)
{
string[] temp = item.Split('|');
colums += "{name:'C" + temp[0] + "',caption:'" + temp[1] + "'},";
}
}
colums = colums.Substring(0, colums.Length - 1);
colums += "]}";
// 格式:colums = "{count:4,result:[{name:'myname',caption:'姓名'},{name:'CardNum',caption:'编号'},{name:'sex',caption:'性别'},{name:'age',caption:'年龄'}]}";
return colums;
}
/// <summary>
/// 查询结果
/// </summary>
/// <returns></returns>
protected string GetQuery(HttpContext context)
{
string JsonString = string.Empty;
string RowString = string.Empty;
string ItemCodes = string.Empty;
string fields = "{name:'RId'},{name:'MemCard'},{name:'SCID'},{name:'SubUnit'},{name:'Name'},{name:'sex'},{name:'age'},"; //列
string sql = "select id ,";//sql是根据查询条件拼出的语句,*写成要查询出来的列名
string sqlHead = "select PP.* from ( select T.id,";
string union = "";
if (!string.IsNullOrEmpty(_Columns))
{
string[] CL = _Columns.Split(',');
foreach (var item in CL)
{
string[] temp = item.Split('|');
ItemCodes += temp[0] + ",";
sqlHead += "max(T.C" + temp[0] + ") as C" + temp[0] + ",";
sql += "(case ItemCode when '" + temp[0] + "' then ItemResult else '' end) C" + temp[0] + ",";
fields += "{name:'C" + temp[0] + "'},";
}
ItemCodes = ItemCodes.Substring(0, ItemCodes.Length - 1);
if (ItemQuery != "")
ItemsQuery = ItemCodes + "," + ItemQuery;
else
ItemsQuery = ItemCodes;
sqlHead = sqlHead.Substring(0, sqlHead.Length - 1); //去掉结尾,
sql = sql.Substring(0, sql.Length - 1); //去掉结尾,
sql = sqlHead + " from (" + sql + " from (select Id,ItemCode,ItemResult from DIS_CheckItemResult where PTYPE=1 union select RecordId as Id,ItemCode,ItemValue as ItemResult from DIS_CheckUpDetail left join DIS_CheckGBase on DIS_CheckGBase.BaseId=DIS_CheckUpDetail.BaseId where DIS_CheckGBase.TID='1') TT where TT.ItemCode in (" + ItemsQuery + ")";
sql += ") T group by id) PP where 1=1 ";
if (union != "")
sql += union;
}
string count = "";//所有记录的总数
SqlDataReader co = CBase.ExecuteReader("select Count(P.id) as total from (" + sql + ") P");
if (co.Read())
{
count = co["total"].ToString();
}
JsonString += "{totalPorperty:" + count + ",result:[";
co.Close();
sql = "select top " + _PageSize + " F1.* from (select top " + (Convert.ToInt32(_start) + _PageSize) + " temp.* from (" + sql + ") temp order by id desc ) F1 order by id";//查询出本页需要的数据
SqlDataReader rs = CBase.ExecuteReader(sql);
qlHelper.ListType = QueryListType.UnconfirmedList;
while (rs.Read())
{
RowString += "{RId:'" + rs["id"].ToString().Trim() + "',MemCard:'" + rs["MemCard"].ToString().Trim() + "',SCID:'"+ rs["SCID"].ToString().Trim()+ "',SubUnit:'" + rs["SubUnit"].ToString().Trim() + "',Name:'" + rs["Name"].ToString().Trim() + "',sex:'" + rs["Sex"].ToString().Trim() + "',SCODE:'" + rs["SCODE"].ToString().Trim() + "',FollowTime:'" + Convert.ToDateTime(rs["FollowTime"]).ToString("yyyy-MM-dd") + "";
string[] item = ItemCodes.Split(',');
//循环动态列
foreach (var id in item)
{
SqlDataReader re = CBase.ExecuteReader("select ValueCont from DIS_CheckUPItemValue where ItemCdoe='" + id + "' and ValueCode='" + rs["C" + id] + "'");
if (re.Read())
RowString += "',C" + id + ":'" + re["ValueCont"];
else
RowString += "',C" + id + ":'" + rs["C" + id];
re.Close();
}
RowString += "'},";
}
rs.Close();
if (RowString.Length > 0)
RowString = RowString.Substring(0, RowString.Length - 1);
JsonString += RowString + "],";
JsonString += "fields:[" + fields + "]}";
return JsonString;
//返回数据格式:JsonString="{totalPorperty:100,result:[{RId:'001',MemCard:'4556',Name:'张三',Sex:'男'},{RId:'002',MemCard:'4576',Name:'张三',Sex:'男'},{RId:'003',MemCard:'4554',Name:'张三',Sex:'女'}],fields:[{name:'RId'},{name:'MemCard'},{name:'SCID'},{name:'SubUnit'},{name:'Name'},{name:'sex'},{name:'age'}]}";
}