当前位置: 首页 > 工具软件 > ExHtmlEditor > 使用案例 >

EXT文本编辑器(htmleditor)[初始化界面]

华安民
2023-12-01

Ext的文本编辑器: Ext.form.HtmlEditor

PS:数据库表  TEXT 存放内容字段 yjnr(clob类型)

(1)前台页面:

     (注意在页面加上:ValidateRequest="false" 否则在传输数据时会报错,取消验证)

     <link rel="stylesheet" type="text/css" href="../../../ext-3.2.0/resources/css/ext-all.css" />

     <script type="text/javascript" language="javascript" src="../../../ext-3.2.0/adapter/ext/ext-base.js"></script>

     <script type="text/javascript" src="../../../ext-3.2.0/ext-all.js"></script>

     <script type="text/javascript" language="javascriptsrc="../../TZ.js"></script>

 

(2)引用TZ.JS代码:

     Ext.onReady(function(){

          Ext.QuickTips.init();
   
    //此方法为frompanel里面的内容时行初始化赋值
    function setContent(s,records)
    {
        try
        {  
            var txt_mc = Ext.getCmp('YJMC');    //根据ID获取组件
            var hedit = Ext.getCmp('content');


            txt_mc.setValue(records[0].get('YJMC'));  //取records里的值进行赋值
            hedit.setValue(records[0].get('YJNR'));
        }
        catch(err)
        {
            alert(err.description);
        }
    };
        //初始化数据源
     var store=  new Ext.data.JsonStore({
            url: 'TEXT.aspx?action=buildContent',
            root: 'data',
            autoLoad:true,
            fields: ['YJNR','YJMC']     //对应JSON语句中的字段
        });

           //数据源监听事件
     store.addListener('load',setContent);
    
    var form = new Ext.FormPanel({
        labelAlign: 'top',
        labelWidth:75,
        frame:true,
        renderTo:'Div',
        title: '主题',
        bodyStyle:'padding:5px 5px 0',
        width: 600,
        url:'TEXT.aspx?action=initdate',
        items:[
            {
            xtype:'textfield',
            fieldLabel:'名称',
            id:'YJMC',
            name:'YJMC',
            value:'',
            readOnly:false,
            anchor:'99%'
            },
           {
            xtype:'htmleditor',
            id:'content',
            name:'content',
            fieldLabel:'文本',
            height:440,
            anchor:'98%',
            enableAlignments:true,
            enableColors:true,
            enableFont:true,
            enableFontSize:true,
            enableFormat:true,
            enableLinks:true,
            enableLists:true,
           enableSourceEdit:true
          }
        ],

        buttons: [
          {
            text: '保存',
            handler: function(){
      
               Ext.getCmp('content').syncValue();
               form.getForm().submit({
                    success: function(form, action) {
                        var obj = Ext.util.JSON.decode(action.response.responseText);       
                        Ext.Msg.alert('提示',obj.data);
                    },
                    failure: function(form, action) {
                        var obj = Ext.util.JSON.decode(action.response.responseText);
                        Ext.Msg.alert('提示',obj.data);
                    }
               });
             }},
            {
              text:'重置',
               handler:function(){form.getForm().reset();}
            }
        ]
    });

  
    });

 

 (3) 后台页面代码TEXT.aspx.cs:

    

       protected void Page_Load(object sender, EventArgs e)
    {
        string action = Request.Params["action"];

        if (action == "initdate")
        {
            try
            {
                Initdate();     //保存方法
                Response.Write("{success:true,data:'保存成功~'}");
            }
            catch (Exception)
            {
                Response.Write("{success:false,data:'保存数据出现错误!'}");
                throw;
            }
            Response.End();
        }
        if (action == "buildContent")
        {
            string result = TEXT_CS.GetWordReportData();    //初始化时,获得取JSON数据(方法在CS类文件里)
            Response.Write(result);
            Response.End();
        }
    }
    public void Initdate()
    {
        OracleHelper oralce = new OracleHelper();              //自己的数据库操作类
        string content = Request.Params["content"];
        string yjmc = Request.Params["YJMC"];

        string selSql = string.Format("select yjmc from TEXT");


        DataTable selDT = oralce.ExecuteDataTable(selSql);

           //根据条件判断是插入还是更新
        if (selDT.Rows.Count == 1)
        {
            string updateSql = "update TEXT set yjnr=:wordcontent";
            oralce.AddParmeter("wordcontent", OracleType.Clob, content);
            oralce.ExecuteNonQuery(updateSql);
        }
        else
        {
            string inSql = string.Format("insert into TEXT(yjnr) values (:wordcontent);
            oralce.AddParmeter("wordcontent", OracleType.Clob, content);
            oralce.ExecuteNonQuery(inSql);
        }

 

    }

 

  (4)方法类文件: App_Code/TEXT_CS.CS 

        //返回初始化数据集信息 以JSON数据格式,在取出原先存入的信息时,因为数据库里内容存入的是clob格式,取出时,很多页面字符可能不合法,

       所以需要进行轮换(橙色部分)

        public static string GetWordReportData()
      {
        string result = "";
        try
        {
            string sql = "select  xxbg, xxbgmc from yj_sgjbnr where TFSJJLXH=" + tfsjjlxh;
            DataTable dt = dbHelpSql.Query(sql);
            string temp = "";
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    result += "{";
                    foreach (DataColumn column in dt.Columns)
                    {
                        temp = row[column].ToString();
                        temp = temp.Replace("/r/n", "<br/>");

                        temp = temp.Replace("<BR>", " ");
                        temp = temp.Replace("/'", "/"");

                        result += column.ColumnName + ":'" + temp + "',";
                    }
                    result = result.Substring(0, result.Length - 1);
                    result += "},";
                }
                result = result.Substring(0, result.Length - 1);
                result = "{data:[" + result + "]}";
            }
        }
        catch (Exception ex)
        {
        }
        return result;
    }

 类似资料: