// create the Data Store var store = new Ext.data.Store({ // load using script tags for cross domain, if the data in on the same domain as // this page, an HttpProxy would be better proxy: new Ext.data.WCFHttpProxy({ url: "/EmployeeService.svc/GetEmployeePaging" }),
// 把true和false转化为男或者女,这个其实可以在服务器端进行转化,写在这里只是为了测试 function renderSex(value, p, record){ return record.data.Sex=="true"?"男":"女"; } //这个函数演示了怎样把服务器端的DateTime类型转为Javascript的日期 function renderOnWorkDate(value, p, record){ var jsondate = record.data.OnWorkDate; return eval("new " + jsondate.substr(1,jsondate.length-2)).toLocaleDateString(); }
// the column model has information about grid columns // dataIndex maps the column to the specific data field in // the data store var nm = new Ext.grid.RowNumberer(); var sm = new Ext.grid.CheckboxSelectionModel(); // add checkbox column
function handleAdd(){ var AddEmpWin = new Ext.Window({ title: "增加新员工", layout:"fit", width:500, height:300, plain: true, items:EmpForm, buttons: [{ text:"保存", handler: AddRecord },{ text: "取消", handler: function(){ AddEmpWin.hide(); } }] }); AddEmpWin.show(this); } function handleEdit(){ var selectedKeys = grid.selModel.selections.keys; //returns array of selected rows ids only if(selectedKeys.length != 1){ Ext.MessageBox.alert("提示","请选择一条记录!"); } else { var EditEmpWin = new Ext.Window({ title: "修改员工资料", layout:"fit", width:500, height:300, plain: true, items:EmpForm, buttons: [{ text:"保存", handler: UpdateRecord },{ text: "取消", handler: function(){ EditEmpWin.hide(); } }] }); EditEmpWin.show(this); //Ext.MessageBox.alert("提示",selectedKeys); deptDs.load(); //取得科室列表 var request = {empID:selectedKeys[0]}; Ext.MessageBox.show({ msg: "正在请求数据, 请稍侯", progressText: "正在请求数据", width:300, wait:true, waitConfig: {interval:200} }); Ext.Ajax.request({ url: "/EmployeeService.svc/GetEmployee", //url to server side script method: "POST", params:Ext.util.JSON.encode(request),//the unique id(s) callback: function (options, success, response) { if (success) { //success will be true if the request succeeded Ext.MessageBox.hide(); var formvalue=ConvertResponseText(response.responseText,"OnWorkDate",true,true); EmpForm.form.setValues(formvalue); } else { Ext.MessageBox.hide(); Ext.MessageBox.alert("失败,请重试",response.responseText); } }, //the function to be called upon failure of the request (server script, 404, or 403 errors) failure:function(response,options){ Ext.MessageBox.hide(); ReturnValue = Ext.MessageBox.alert("警告","出现异常错误!请联系管理员!"); }, success:function(response,options){ Ext.MessageBox.hide(); } })// end Ajax request } } function UpdateRecord(btn) { if (EmpForm.form.isValid()) { btn.disabled=true; Ext.MessageBox.show({ msg: "正在请求数据, 请稍侯", progressText: "正在请求数据", width:300, wait:true, waitConfig: {interval:200} }); var formvalue = EmpForm.form.getValues(); var request = {emp:ConvertFormValue(formvalue,"OnWorkDate")}; //Ext.MessageBox.alert("提示",formvalues); Ext.Ajax.request({ url: "/EmployeeService.svc/UpdateEmployee", //url to server side script method: "POST", params:Ext.util.JSON.encode(request),//the unique id(s) callback: function (options, success, response) { if (success) { //success will be true if the request succeeded Ext.MessageBox.hide(); var alertcontent=ConvertResponseText(response.responseText,"",true,false); Ext.MessageBox.alert("成功",alertcontent); } else { Ext.MessageBox.hide(); Ext.MessageBox.alert("失败,请重试",response.responseText); } }, //the function to be called upon failure of the request (server script, 404, or 403 errors) failure:function(response,options){ Ext.MessageBox.hide(); ReturnValue = Ext.MessageBox.alert("警告","出现异常错误!请联系管理员!"); }, success:function(response,options){ Ext.MessageBox.hide(); store.reload(); } })// end Ajax request } }
function AddRecord(btn) { if (EmpForm.form.isValid()) { btn.disabled=true; Ext.MessageBox.show({ msg: "正在请求数据, 请稍侯", progressText: "正在请求数据", width:300, wait:true, waitConfig: {interval:200} }); var formvalue = EmpForm.form.getValues(); var request = {emp:ConvertFormValue(formvalue,"OnWorkDate")}; //Ext.MessageBox.alert("提示",formvalues); Ext.Ajax.request({ url: "/EmployeeService.svc/AddEmployee", //url to server side script method: "POST", params:Ext.util.JSON.encode(request),//the unique id(s) callback: function (options, success, response) { if (success) { //success will be true if the request succeeded Ext.MessageBox.hide(); var alertcontent=ConvertResponseText(response.responseText,"",true,false); Ext.MessageBox.alert("成功",alertcontent); } else { Ext.MessageBox.hide(); Ext.MessageBox.alert("失败,请重试",response.responseText); } }, //the function to be called upon failure of the request (server script, 404, or 403 errors) failure:function(response,options){ Ext.MessageBox.hide(); ReturnValue = Ext.MessageBox.alert("警告","出现异常错误!请联系管理员!"); }, success:function(response,options){ Ext.MessageBox.hide(); store.reload(); } })// end Ajax request
} }
function handleDelete(){ var selectedKeys = grid.selModel.selections.keys; //returns array of selected rows ids only if(selectedKeys.length > 0) { Ext.MessageBox.confirm("提示","您确实要删除选定的记录吗?", deleteRecord); } else { Ext.MessageBox.alert("提示","请至少选择一条记录!"); }//end }
function deleteRecord(btn){ if(btn=="yes"){ var selectedRows = grid.selModel.selections.items;//returns record objects for selected rows (all info for row) var selectedKeys = grid.selModel.selections.keys; //var deleteresult = AjaxRequest("/EmployeeService.svc/DelEmployee",selectedKeys,false,"") Ext.MessageBox.show({ msg: "正在请求数据, 请稍侯", progressText: "正在请求数据", width:300, wait:true, waitConfig: {interval:200} }); Ext.Ajax.request({ url: "/EmployeeService.svc/DelEmployee", //url to server side script method: "POST", params:Ext.util.JSON.encode(selectedKeys),//the unique id(s) callback: function (options, success, response) { if (success) { //success will be true if the request succeeded Ext.MessageBox.hide(); var alertcontent=ConvertResponseText(response.responseText,"",false,false); Ext.MessageBox.alert("成功",alertcontent); } else { Ext.MessageBox.hide(); Ext.MessageBox.alert("失败,请重试",response.responseText); } }, //the function to be called upon failure of the request (server script, 404, or 403 errors) failure:function(response,options){ Ext.MessageBox.hide(); ReturnValue = Ext.MessageBox.alert("警告","出现异常错误!请联系管理员!"); }, success:function(response,options){ Ext.MessageBox.hide(); store.reload(); } })// end Ajax request }//end if click "yes" on button } // end deleteRecord