extjs form表单 及 后台保存数据

extjs  form表单 及 后台保存数据

form表单


function formEdit(sel, templateid) {//sel
    Ext.BLANK_IMAGE_URL = '../../Content/js/ext2/resources/images/default/s.gif';
    var ID = sel.id;
    var edtform = new Ext.FormPanel({
        layout: 'column',
        items: [{
            items: {
                columnWidth: 15,
                layout: 'form',
                border: false,
                items: [{  //隐藏域
                        xtype : 'hidden', 
                        name: 'ID',
                        value :ID
                     },
                     {
                         xtype: 'hidden',
                         name: 'templateid',
                         value: templateid
                     },
                new Ext.form.DateField({//日期域
                    fieldLabel: '      评估日期',
                    name: 'EvaluateDate',
                    width: 200,
                    allowBlank:false,
                    blankText: '日期不能为空!',
                    value: sel.data["EvaluateDate"].replace(/\//g, "-")

                }),
                {//下拉列表
                    fieldLabel: '      评估结果',
                    name: 'EvaluateResult',
                    xtype: 'combo',
                    width: 200,
                    //本地数据源  local/remote
                    mode: 'local',
                    //设置为选项的text的字段
                    displayField: "name",
                    //设置为选项的value的字段
                    valueField: "Id",
                    //是否可以输入,还是只能选择下拉框中的选项
                    editable: false,
                    typeAhead: true,
                    //必须选择一项
                    forceSelection: true,
                    //输入部分选项内容匹配的时候显示所有的选项
                    triggerAction: 'all',
                    value: sel.data["EvaluateResult"],
                    //selectOnFocus:true,
                    //数据
                    store: new Ext.data.SimpleStore({
                        fields: ['Id', 'name'],
                        data: [[1, '好'], [2, '中'],[3,'差']]
                    })
                },
                {//文本区域
                    xtype: 'textarea',
                    fieldLabel: '      评估内容',
                    width: 200,
                    name: 'EvaluateContent',
                  //  allowBlank:false
                    value: sel.data["EvaluateContent"]//获取选择项的值
                }

                ]
            }
        }]
    });
    //保存按钮事件
    function doSave() {
        Ext.MessageBox.show({
            msg: '正在保存数据, 请稍侯',
            progressText: '正在保存中',
            width: 300,
            wait: true,
            waitConfig: { interval: 200 },
            icon: 'ext-mb-save',
            nimEl: 'btnSave'
        });

        edtform.getForm().submit({
            url: '/yl/DayCare/Evaluate.ashx',//调用后台保存页面
            method: 'POST',
            success: function (form, action) {
                Ext.MessageBox.hide();
                Ext.MessageBox.alert('提示', '数据保存成功!');
                window.hide();
                grid.store.reload();
                //   ds.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
                });
            }
        });
    }

    var window = new Ext.Window({
        title: '服务评估',//表单标题
        //layout : 'fit',//设置window里面的布局 
        width: 400,//宽度
        height: 200,//高度
        items: edtform,//调用加载的表单
        //关闭时执行隐藏命令,如果是close就不能再show出来了 
        closeAction: 'hide',
        //draggable : false, //不允许窗口拖放 
        //  maximizable : true,//最大化 
        // minimizable : true,//最小话 
        constrain: true,//防止窗口超出浏览器 
        //constrainHeader : true,//只保证窗口顶部不超出浏览器 
        //resizble : true,//是否可以改变大小 
        //resizHandles : true,//设置窗口拖放的方式 
        //modal : true,//屏蔽其他组件,自动生成一个半透明的div 
        animateTarget: 'target',//弹出和缩回的效果 
        //plain : true,//对窗口进行美化,可以看到整体的边框 

        buttonAlign: 'center',//按钮的对齐方式 
        defaultButton: 0,//默认选择哪个按钮 
        buttons: [{
            id: 'btnSave',
            text: '保 存',
            handler: doSave,
            disabled: false
        }, {
            text: '取消',
            handler: function () {
                window.hide();
            }
        }]
    });
    window.show();
    new Ext.Viewport({
        items: [window]
    });

}

 

前台调用编辑

        actions.push({text:'评估',iconCls: 'newbtn', handler:function(){
            var sel=grid.getSelectionModel().getSelections()[0];  //选中记录
            if(sel)
            formEdit(sel,'<%=templateid%>')  //传值并调用form表单
            }

 

保存按钮的后台处理页面

 public class Evaluate : IHttpHandler
    {
        protected string strJson = string.Empty;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string ID           = context.Request.Form["ID"];//获取前台的值
            string EvaluateDate = context.Request.Form["EvaluateDate"];
            string EvaluateResult = context.Request.Form["EvaluateResult"];
            string EvaluateContent = context.Request.Form["EvaluateContent"];
            string templateid = context.Request.Form["templateid"];
            DateTime date1 = Convert.ToDateTime(EvaluateDate);
            try
            {
            FormTemplate template1 = EntityManager.GetEntityInstance(typeof(FormTemplate), templateid) as FormTemplate;
            if (template1 != null)
            {
                string tableSql = "select * from " + template1.FormTableName + " where ID=" + ID;//SQL语句
                DataTable dt = FormDirector.GetTableBySQL(tableSql);
                if (dt.Rows.Count > 0)
                {
                    WebOA.CustomForm.Managers.FormDirector.updateTable(template1.FormTableName, "ID=" + ID + "", "EvaluateDate='" + date1 + "',EvaluateResult='" + EvaluateResult + "',EvaluateContent='" + EvaluateContent + "'");//执行SQL语句
                    strJson = @"{success: true}";//保存成功返回值
                }
                else {
                    strJson = @"{success: false}";//保存失败返回值
                }
            }
            }
           catch (Exception ex)
           {
               string strMsg = ex.Message;
               strJson = @"{success: false}";
           }
           context.Response.Write(strJson);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

 

阅读更多
换一批

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