EXTJS 添加及删除数据
var newwin;
function showAddPanel(){
newwin = new Ext.Window({
xtype: 'window',
title: "添加数据",
modal: 'true',
width:620,
height: 435,
closeAction:'hide',
items:
addForm,
buttons: [{
id:'btnSave',
text:'保 存',
handler:doSave,
disabled:false
},{
text: '取 消',
handler: function(){
newwin.hide();
}
}]
});
newwin.show(this);
};
//------addForm
var addForm = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
bodyStyle:'padding:5px 5px 0',
items: [{
xtype:'textfield',
fieldLabel: '标题',
name: 'title',
width: 230,
allowBlank:false
},{
xtype:'textfield',
width: 230,
fieldLabel: '作者',
name: 'hca_art_author'
},{
fieldLabel: '内容',
name: 'hca_art_content',
//width: 600,
//height:450,
xtype:'htmleditor',
} ]
});
//保存按钮事件
function doSave()
{
Ext.MessageBox.show({
msg: '正在保存数据, 请稍侯',
progressText: '正在保存中',
width:300,
wait:true,
waitConfig: {interval:200},
icon:'ext-mb-save',
nimEl: 'btnSave'
});
addForm.getForm().submit({
url:'json_grid/art_add.aspx?list=add',
method:'POST',
success: function(form, action){
Ext.MessageBox.hide();
Ext.MessageBox.alert('提示', '数据保存成功!');
newwin.hide(this);
store.load({params:{start:0, limit:25}});
},
failure: function(form, action){
Ext.MessageBox.hide();
Ext.MessageBox.show({
title:'错误',
msg: '数据保存失败!',
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
}
});
}
//处理批量删除
function delall(){
Ext.MessageBox.confirm('提示', '确实要删除所选的记录吗?',showResult);
}
function showResult(btn){
if(btn=='yes'){
var gsm = grid.getSelectionModel();//获取选择列
var row = gsm.getSelections();//根据选择列获取到所有的行
var jsonData="";
for(var i=0;i<row.length;i++){
var ss = row[i].get("hca_art_id");
jsonData =jsonData+ ss+ ";"; //这样处理是为了删除的Lambda语句方便
}
var conn = new Ext.data.Connection();
conn.request({
url:"json_grid/art_add.aspx?list=dell", //请注意引用的路径
params:{strdel:jsonData},
method: 'post',
scope: this,
callback:function(options,success, response){
if(success){
Ext.MessageBox.alert("提示","所选记录成功删除!");
store.load({params:{start:0, limit:25}});
}
else
{Ext.MessageBox.alert("提示","所选记录删除失败!");}
}
})
}
};
art_add.aspx页面
protected string strJson = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
string list = Request.QueryString["list"].ToString().Trim();
// string strdel = Request.Form["strdel"].ToString().Trim();
switch (list)
{
case "add": insert(); break;
case "dell": delall(Request.Form["strdel"].ToString().Trim()); break;
}
}
public void insert()
{
string title = Request.Form["title"].ToString();
string hca_art_author = Request.Form["hca_art_author"].ToString();
string hca_art_content = Request.Form["hca_art_content"].ToString();
int i = DbHelperSQL.ExecuteSql("insert into hca_art (hca_art_title,hca_art_author,hca_art_content) values('" + title + "','" + hca_art_author + "','" + hca_art_content + "')");
try {
if (i > 0)
{
strJson = @"{success: true}";
}
else
{
strJson = @"{success: false}";
}
}
catch(Exception ex)
{
string strMsg = ex.Message;
strJson = @"{success: false}";
}
Response.Write(strJson);
}
public bool delall(string strdel)
{
bool result = false;
try
{ string[] a;
a = strdel.Split(';');
for (int i = 0; i < a.Length;i++)
{
DbHelperSQL.ExecuteSql("DELETE FROM hca_art where hca_art_id=" + a[i]);
}
result = true;
}
catch
{
result = false;
}
return result;
}
}
浙公网安备 33010602011771号