转载

Ext.Net 1.x_Ext.Net.GridPanel CRUD

Grid.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grid.aspx.cs" Inherits="Ext.Net.Study.Grid" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!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 runat="server">
    <title></title>
    <script type="text/javascript">
        function Details(v) {
            var temp = '<a href="Edit.aspx?AutoId={0}" target="_blank">详细…</a>';
            return String.format(temp, v);
        };
        function CSRQ(v) {
                return String.format("{0}年{1}月{2}日",
                                    v.substr(0, 4),
                                    v.substr(4, 2),
                                    v.substr(6, 2));
        };
        function GridpanelCommand(command, record) {
            if (command == "Delete") {
                Ext.Msg.confirm("删除", "确定删除?" + record.data.AutoId + ":" + record.data.XM,
                function (result) {
                    if (result == "yes") {
                        Ext.net.DirectMethods.Delete(record.data.AutoId);
                    }
                });
            } else if (command == "Update") {
                Ext.net.DirectMethods.Update(record.data.AutoId);
            };
        };
        function BindStore() {
            Ext.net.DirectMethods.BindStore();
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Store ID="Store1" runat="server" OnRefreshData="Store1_RefreshData">
        <Reader>
            <ext:JsonReader IDProperty="AutoId">
                <Fields>
                    <ext:RecordField Name="AutoId">
                    </ext:RecordField>
                    <ext:RecordField Name="BMH">
                    </ext:RecordField>
                    <ext:RecordField Name="XM">
                    </ext:RecordField>
                    <ext:RecordField Name="KSBH">
                    </ext:RecordField>
                    <ext:RecordField Name="ZJHM">
                    </ext:RecordField>
                    <ext:RecordField Name="CSRQ">
                    </ext:RecordField>
                    <ext:RecordField Name="HKSZDXXDZ">
                    </ext:RecordField>
                    <ext:RecordField Name="XXGZDW">
                    </ext:RecordField>
                    <ext:RecordField Name="XXGZJL">
                    </ext:RecordField>
                    <ext:RecordField Name="TXDZ">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:GridPanel ID="GridPanel1" runat="server" Title="GridPanel" AutoHeight="True"
        StoreID="Store1" TrackMouseOver="True" DisableSelection="True">
        <LoadMask ShowMask="True" />
        <TopBar>
            <ext:Toolbar runat="server">
                <Items>
                    <ext:ToolbarSeparator>
                    </ext:ToolbarSeparator>
                    <ext:Button Text="增加" Icon="TableAdd" runat="server">
                        <Listeners>
                            <Click Handler="Ext.net.DirectMethods.Create();" />
                        </Listeners>
                    </ext:Button>
                    <ext:ToolbarSeparator>
                    </ext:ToolbarSeparator>
                    <ext:TriggerField runat="server" TriggerIcon="Search" EmptyText="证件号码">
                        <Listeners>
                            <TriggerClick Handler="Ext.net.DirectMethods.Retrieve(this.getValue());" />
                        </Listeners>
                    </ext:TriggerField>
                    <ext:ToolbarSeparator>
                    </ext:ToolbarSeparator>
                </Items>
            </ext:Toolbar>
        </TopBar>
        <ColumnModel>
            <Columns>
                <ext:RowNumbererColumn Width="30">
                </ext:RowNumbererColumn>
                <ext:Column DataIndex="AutoId" Header="自动编号">
                </ext:Column>
                <ext:Column DataIndex="BMH" Header="报名号">
                </ext:Column>
                <ext:Column DataIndex="XM" Header="姓名">
                </ext:Column>
                <ext:Column DataIndex="KSBH" Header="考生编号">
                </ext:Column>
                <ext:Column DataIndex="ZJHM" Header="证件号码">
                </ext:Column>
                <ext:Column DataIndex="CSRQ" Header="出生日期">
                    <Renderer Fn="CSRQ" />
                </ext:Column>
                <ext:Column DataIndex="AutoId">
                    <Renderer Fn="Details" />
                </ext:Column>
                <ext:CommandColumn>
                    <Commands>
                        <ext:GridCommand Text="修改" Icon="TableEdit" CommandName="Update">
                        </ext:GridCommand>
                        <ext:GridCommand Text="删除" Icon="TableDelete" CommandName="Delete">
                        </ext:GridCommand>
                    </Commands>
                </ext:CommandColumn>
            </Columns>
        </ColumnModel>
        <Plugins>
            <ext:RowExpander>
                <Template runat="server">
                    <Html>
                        <p>户口所在地址:{HKSZDXXDZ}</p>
                        <p>学习工作单位:{XXGZDW}</p>
                        <p>学习工作经历:{XXGZJL}</p>
                        <p>通信地址:{TXDZ}</p>
                    </Html>
                </Template>
            </ext:RowExpander>
        </Plugins>
        <Listeners>
            <Command Fn="GridpanelCommand" />
        </Listeners>
        <BottomBar>
            <ext:PagingToolbar runat="server" ID="PagingToolbar1">
            </ext:PagingToolbar>
        </BottomBar>
    </ext:GridPanel>
    <ext:Window ID="Window1" runat="server" Width="500" Height="350" Modal="True" Hidden="True">
        <AutoLoad Mode="IFrame" ShowMask="True">
        </AutoLoad>
    </ext:Window>
    </form>
</body>
</html>

Grid.aspx.cx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ext.Net.Study
{
    public partial class Grid : System.Web.UI.Page
    {
        #region 增删改查

        /// <summary>
        /// 增加
        /// </summary>
        [DirectMethod(ShowMask = true)]
        public void Create()
        {
            this.Window1.Icon = Icon.TableAdd;
            this.Window1.Title = "增加";
            this.Window1.AutoLoad.Url = "Edit.aspx?Type=Create";
            this.Window1.Render();
            this.Window1.Show();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="AutoId"></param>
        [DirectMethod(ShowMask = true)]
        public void Update(string AutoId)
        {
            this.Window1.Icon = Icon.TableEdit;
            this.Window1.Title = "修改";
            this.Window1.AutoLoad.Url = "Edit.aspx?Type=Update&AutoId=" + AutoId;
            this.Window1.Render();
            this.Window1.Show();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="AutoId"></param>
        [DirectMethod(ShowMask = true, Msg = "删除中…")]
        public void Delete(string AutoId)
        {
            Code.Common.DB.ExecuteNonQuery(CommandType.Text, "Delete From tb_Master Where AutoId=" + AutoId);
            this.Store1.RemoveRecord(AutoId);
            this.Store1.CommitChanges();
        }

        /// <summary>
        /// 查找
        /// </summary>
        [DirectMethod(ShowMask = true, Msg = "查找中…")]
        public void Retrieve(string ZJHM)
        {
            if (string.IsNullOrEmpty(ZJHM))
            {
                this.BindStore();
            }
            else
            {
                this.PagingToolbar1.PageSize = this.PagingToolbar1.PageSize;
                this.PagingToolbar1.PageIndex = this.PagingToolbar1.PageIndex;
                DataSet datasetTbMaster = Code.Common.DB.ExecuteDataSet(CommandType.Text,
               "Select * From tb_Master Where ZJHM Like '" + ZJHM + "%' Order By AutoId Desc ");
                this.Store1.DataSource = datasetTbMaster;
                this.Store1.DataBind();
            }
        }

        #endregion

        /// <summary>
        /// 绑定Store1
        /// </summary>
        [DirectMethod(ShowMask = true)]
        public void BindStore()
        {
            this.PagingToolbar1.PageSize = this.PagingToolbar1.PageSize;
            this.PagingToolbar1.PageIndex = this.PagingToolbar1.PageIndex;
            DataSet datasetTbMaster = Code.Common.DB.ExecuteDataSet(CommandType.Text,
                "Select * From tb_Master Order By AutoId Desc ");
            this.Store1.DataSource = datasetTbMaster;
            this.Store1.DataBind();
        }

        //---------------------------------

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.BindStore();
            }
        }

        protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            this.PagingToolbar1.PageSize = this.PagingToolbar1.PageSize;
            this.BindStore();
        }

    }
}

Edit.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="Ext.Net.Study.Edit" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:Panel ID="Panel10" runat="server" Layout="Fit" Region="Center" Border="False">
                <Items>
                    <ext:FormPanel ID="FormPanel1" runat="server" ButtonAlign="Right" Padding="30" Border="False">
                        <Items>
                            <ext:TextField ID="TextField1" runat="server" AnchorHorizontal="100%" FieldLabel="TextField1"
                                AllowBlank="False">
                            </ext:TextField>
                        </Items>
                        <Buttons>
                            <ext:Button ID="Button1" runat="server" Icon="Disk" Text="确认" Type="Submit">
                                <Listeners>
                                    <Click Handler="Ext.net.DirectMethods.Submit();" />
                                </Listeners>
                            </ext:Button>
                        </Buttons>
                    </ext:FormPanel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>

Edit.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ext.Net.Study
{
    public partial class Edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [DirectMethod(ShowMask = true)]
        public void Submit()
        {
            if (Request.QueryString["Type"].ToString() == "Create")
            {
                Code.Common.DB.ExecuteNonQuery(CommandType.Text,
                " Insert Into " +
                " tb_Master(CSRQ) " +
                " Values('" + this.TextField1.Text + "')");
                X.Js.ResourceManager.RegisterClientScriptBlock(DateTime.Now.ToString(),
                    "window.parent.BindStore();" +
                    "window.parent.Window1.hide();");
            }
            else if (Request.QueryString["Type"].ToString() == "Update")
            {
                Code.Common.DB.ExecuteNonQuery(CommandType.Text,
                " Update tb_Master" +
                " Set BMH='" + this.TextField1.Text + "' " +
                " Where AutoId=" + Request.QueryString["AutoId"].ToString());
                X.Js.ResourceManager.RegisterClientScriptBlock(DateTime.Now.ToString(),
                    "window.parent.BindStore();" +
                    "window.parent.Window1.hide();");
            }
        }
    }
}

文章最后发布于: 2012-05-31 11:55:34
展开阅读全文
0 个人打赏
私信求帮助

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

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览