ext.net GridPanelHelper

<pre name="code" class="csharp">/// <summary>
///GridPanelHelper
<span style="font-family: Arial, Helvetica, sans-serif;">///date:2014.7.22 by:wyl</span>
///GridPanel在我们系统中保存的是子表信息
/// </summary>
public class GridPanelHelper
{
    /// <summary>
    /// gridpanel 单元格双击事件
    /// </summary>
    public const string fn = "function(e){e.cancel=true;return false;}";

    #region 保存GridPanel
    /// <summary>
    /// 保存gridpanel子表数据
    /// </summary>
    /// <param name="jsonData">子表Store的json数据</param>
    /// <param name="store">子表store(Ext.Net.Store)</param>
    /// <param name="tableName">子表名称</param>
    /// <param name="parentID">父表记录的ID</param>
    public static int SaveGridData(string jsonData, Ext.Net.Store store, string tableName, int parentID)
    {
        //反序列化得到JArray数组
        JArray ja = (JArray)JsonConvert.DeserializeObject(jsonData);
        if (ja.Count <= 0)
        {
            return 0;
        }
        RecordFieldCollection RecordField = store.Reader[0].Fields;
        string parentField = RecordField[0].Name; //父表记录的ID
        string fields = parentField;//字段列表
        string values = ""; //插入值列表
        string sqlStr = "";
        string selSql = "";
        for (int i = 0; i < ja.Count; i++) //行循环
        {
            values = "'" + parentID.ToString() + "'"; //父表ID取参数传过来的,而不是json中的
            for (int j = 1; j < RecordField.Count; j++) //列循环
            {
                if (i == 0) //只执行一次最外层循环
                {
                    fields += "," + RecordField[j].Name;
                }
                //date:2014.7.22 by:wyl
                if (ja[i][RecordField[j].Name] == null)
                {
                    string str = " ";
                    values += "," + "'" + str + "'";
                }
                else
                {
                    values += "," + "'" + ja[i][RecordField[j].Name].ToString() + "'";
                }
            }
            selSql += "select " + values + " union all "; //构造select语句
        }
        sqlStr = string.Format(@"begin
                                    delete from {0:g} where {1:g}={2:g};
                                    insert into {0:g}({3:g}) {4:g} ;
                                 end;", tableName, parentField, parentID, fields, selSql.Substring(0, selSql.Length - 10));
        return Sunway.DBUtility.DbHelperSQL.ExecuteNonQuery(CommandType.Text, sqlStr, null);
    }

    /// <summary>
    /// 保存gridpanel数据
    /// </summary>
    /// <param name="jsonData">Store的json数据</param>
    /// <param name="store">gridpanel的store</param>
    /// <param name="tableName">保存的表名称</param>
    public static int SaveGridData(string jsonData, Store store, string tableName)
    {
        //用Newtonsoft.Json得到JArray数组
        JArray ja = (JArray)JsonConvert.DeserializeObject(jsonData);

        RecordFieldCollection RecordField = store.Reader[0].Fields;
        string fields = RecordField[0].Name;//字段列表
        string values = ""; //插入值列表
        string sqlStr = "";
        string selSql = "";
        string sqlStr1 = "";
        string[] sqlArray;
        for (int i = 0; i < ja.Count; i++)
        {
            values = "'" + ja[i][RecordField[0].Name].ToString() + "'";
            for (int j = 1; j < RecordField.Count; j++)
            {
                if (i == 0)
                {
                    fields += "," + RecordField[j].Name;
                }
                values += "," + "'" + ja[i][RecordField[j].Name].ToString() + "'";
            }
            selSql += "select " + values + " union all ";
        }
        sqlStr = string.Format("delete from {0:g}", tableName);
        if (selSql != "")//grid没有记录时(可能内容全删除了,或是没填)
        {
            sqlStr1 = string.Format(@"insert into {0:g}({1:g}) {2:g} ", tableName, fields, selSql.Substring(0, selSql.Length - 10));
        }
        if (selSql == "")
        {
            return Sunway.DBUtility.DbHelperSQL.ExecuteNonQuery(CommandType.Text, sqlStr, null);
        }
        else
        {
         sqlArray = new string[] { selSql, selSql };
         return  TranHelp.ExecTran(sqlArray);

        }
    }

    /// <summary>
    /// 保存gridpanel子表(带触发器)
    /// </summary>
    /// <param name="jsonData">子表Store的json数据</param>
    /// <param name="store">子表store(Ext.Net.Store)</param>
    /// <param name="tableName">子表名称</param>
    /// <param name="parentID">父表记录的ID</param>
    /// <param name="isTrigger">是否带触发器</param>
    public static int SaveGridData(string jsonData, Ext.Net.Store store, string tableName, int parentID, bool isTrigger)
    {
        int num = 0;
        if (isTrigger == true)
        {
            //反序列化得到JArray数组
            JArray ja = (JArray)JsonConvert.DeserializeObject(jsonData);

            RecordFieldCollection RecordField = store.Reader[0].Fields;
            string parentField = RecordField[0].Name; //父表记录的ID
            string fields = parentField;//字段列表
            string values = ""; //插入值列表
            string sqlStr = "";
            string insSql = "";
            for (int i = 0; i < ja.Count; i++) //行循环
            {
                values = "'" + parentID.ToString() + "'";
                for (int j = 1; j < RecordField.Count; j++) //列循环
                {
                    if (i == 0) //只执行一次最外层循环
                    {
                        fields += "," + RecordField[j].Name;
                    }
                    values += "," + "'" + ja[i][RecordField[j].Name].ToString() + "'";
                }
                insSql += string.Format("insert into {0:g}({1:g}) values({2:g});", tableName, fields, values); //构造Insert语句
            }
            sqlStr = string.Format(@"begin
                                    delete from {0:g} where {1:g}={2:g};
                                    {3:g}
                                 end;", tableName, parentField, parentID, insSql);
            try
            {
                num = Sunway.DBUtility.DbHelperSQL.ExecuteNonQuery(CommandType.Text, sqlStr, null);
            }
            catch (Exception)
            {
                num = -1;
            }

        }
        return num;
    }

    /// <summary>
    /// 保存grid行
    /// </summary>
    /// <param name="jsonData"></param>
    /// <param name="store"></param>
    /// <param name="tableName"></param>
    /// <param name="parentID"></param>
    /// <returns></returns>
    public static int SaveGridRow(string jsonData, Ext.Net.Store store, string tableName, string parentID)
    {
        //反序列化得到JArray数组
        JArray ja = (JArray)JsonConvert.DeserializeObject(jsonData);
        RecordFieldCollection RecordField = store.Reader[0].Fields;
        string parentField = RecordField[0].Name; //父表记录的ID
        string fields = "";//字段列表
        string values = ""; //插入值列表
        string sqlStr = "";
        string insSql = "";
        for (int j = 1; j < RecordField.Count; j++) //列循环
        {
            fields += RecordField[j].Name+",";
            values += "'"+ja[0][RecordField[j].Name].ToString() + "',";
        }

        insSql += string.Format("insert into {0:g}({1:g}) values({2:g});", tableName, fields.Substring(0,fields.Length-1), values.Substring(0,values.Length-1)); //构造Insert语句
        if (parentID != "")
        {
            sqlStr = string.Format(@"begin
                                    delete from {0:g} where {1:g}={2:g};{3:g}
                                 end;", tableName, parentField, parentID, insSql);

        }
        else
        {
            sqlStr = insSql;
        }
        return Sunway.DBUtility.DbHelperSQL.ExecuteNonQuery(CommandType.Text, sqlStr, null);
    }
    #endregion

    #region 导入Excel
    /// <summary>
    /// 导入Excel到GridPanel,应用com组件
    /// </summary>
    /// <param name="filenameurl">物理路径</param>
    /// <param name="sheetIndex">sheet名称的索引</param>
    /// <returns></returns>
    public static void ImpExecleToGrid(string filenameurl, GridPanel grd)
    {
        int sheetIndex = 1;//sheet名称的索引
        Microsoft.Office.Interop.Excel.Workbook wb = null;
        Microsoft.Office.Interop.Excel.Worksheet ws = null;
        ArrayList columnArr = new ArrayList();//列字段表
        DataSet myDs = new DataSet();
        DataTable xlsTable = myDs.Tables.Add("show");
        object missing = System.Reflection.Missing.Value;
        Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
        if (excel != null)
        {
            excel.Visible = false;
            excel.UserControl = true;
            // 以只读的形式打开EXCEL文件
            wb = excel.Workbooks.Open(filenameurl, missing, true, missing, missing, missing,
             missing, missing, missing, true, missing, missing, missing, missing, missing);
            //取得第一个工作薄
            ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets.get_Item(sheetIndex);
            //取得总记录行数(包括标题列)
            int rowsint = ws.UsedRange.Cells.Rows.Count; //得到行数
            int columnsint = ws.UsedRange.Cells.Columns.Count;//得到列数
            DataRow dr;
            string colName = "";
            for (int i = 1; i < columnsint; i++)
            {
                colName = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[1, i]).Text.ToString();
                if (grd.ColumnModel.Columns[i].Header == colName)
                {
                    xlsTable.Columns.Add(grd.ColumnModel.Columns[i].DataIndex, typeof(string));
                    columnArr.Add(grd.ColumnModel.Columns[i].DataIndex);
                }
            }
            for (int i = 2; i <= rowsint; i++)
            {
                dr = xlsTable.NewRow();
                for (int j = 1; j < columnsint; j++)
                {
                    dr[columnArr[j - 1].ToString()] = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[i, j]).Text.ToString();
                }
                xlsTable.Rows.Add(dr);
            }
        }
        excel.Quit();
        excel = null;
        //Dispose(ws, wb);
        GC.Collect();
        grd.Store[0].DataSource = xlsTable;
        grd.Store[0].DataBind();
    }
    #endregion

    /// <summary>
    /// 设置列是否可修改
    /// </summary>
    /// <param name="cm">ColumnModel</param>
    /// <param name="isEditable"></param>
    public static void SetColumnsEditable(ColumnModel cm,bool isEditable)
    {
        for (int i = 0; i < cm.Columns.Count; i++)
        {
            cm.SetEditable(i, isEditable);
        }
    }
    public static void SaveStore(Store st, string ID)
    { 

    }
}
				
时间: 2024-09-28 05:48:57

ext.net GridPanelHelper的相关文章

Ext.js入门:常用组件与综合案例(七)

一:datefield简单示例 二:timefield简单示例 三:numberfield简单示例 四:FormPanel提交 datefield简单示例: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="Ext/resources/css/ext-all.css&

ExtJS中Ext.Ajax.request与form1.getForm().submit的基本区别

相同点:都属于Ajax提交方式! 不同点:Ext.Ajax.request是Ext.data.connection的一个实例 form1.getForm().submit是BasicForm的一个实现方式 使用上的区别: 1.form1.getForm().submit常用在表单提交的时候,就是说要提交页面数据,比如新增和修改数据页面 2.Ext.Ajax.request常用在根据参数提交的时候,比如删除,我们把页面选中的ID进行遍历,封装在一个Array中,作为一个参数做Ajax的提交 例子:

Ext.net里面放置KindEditor富文本框(解决KindEditor不显示和后台取不到值的问题)

上周六,从上午10点到晚上12点终于搞定了Ext.net与KindEditor的兼容性问题.对于Ext.net的原理,我是菜鸟,表示不懂.我遇到的两个问题是,问题一是不显示KindEditor控件,通过ext:ResourceManager里面的 <DocumentReady Handler="createEditor();" /> 解决了,问题二是KindEditor控件的值传不会后台去,就是在前台也收不到值,但是我通过点击全屏按钮后就可以收到其值了,于是采用<Cl

华为刀片,IBM刀片服务器将外部EXT端口流量复制给内部INT端口的实现方法不同

如何在刀片服务器中将外部端口EXT的流量复制给内部INT端口用于采集DNS流量 (1)对于IBM刀片服务器的北电Nortel_32R1860交换模块112.4.20.12DNS抓包的问题已经搞定 经过摸索和测试,感觉北电的交换机模块不是采用镜像命令来实现复制流量(虽然有相应的port-mirroring monitor-port...命令,但并不生效),而应该是在相同vlan就可以复制流量,如果要把ext3的流量复制给int14,只要把ext3和int14放在同一个vlan11下,都不打tagg

override Ext.grid.plugin.RowExpander的方法不起作用

Ext版本4.2 覆盖方法: Ext.override(Ext.grid.plugin.RowExpander, {     setCmp: function (grid) {         var me = this,             rowBodyTpl,             features;         console.log('我是盖子..');         me.callParent(arguments);         me.recordsExpanded 

谈谈Ext JS的组件——容器与布局

概述 在页面中,比較棘手的地方就是布局.而要实现布局.就得有能维护布局的容器. 能够说,在我试过和使用过的Javascript框架中,Ext JS的布局是做得最优秀的一个,而这得益于它强大的容器类和丰富的布局类.在本文将介绍Ext JS的容器组合和布局类. 容器:Ext.container.Container 容器的主要功能是管理其内部的组件.因而在继承Ext.Component的所有功能的基础上.加入了相应的用来处理内部组件的方法add.insert.remove和removeAll. 在配置

Ext概述

Ext是一个具有丰富组件的javascript集合类库,除了自身提供的一套选择器.效果.ajax等功能,还提供了大量的javascript创建页面元素的类.方法.这个意味着:只要客户端支持javascript,可以使用ext方便的生成所有页面元素,再不必搞大量的html代码,而且生成的页面的样式还很漂亮.EXT 强大的UI,而且性能不错,这是其最大的优点. 速度快,管是UI还是其它模块. 100%面向对象和组件化的思想,一致的语法,全局的命名空间. 文档的完整,规范,方便. 所有的组件(widg

Ext简单demo示例

1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <titl

EXT.JS以下两种写法在初始载入时是一样的效果

/* Ext.application({ name: 'MyfirstApplication', launch: function () { Ext.Msg.alert("Hello", "My first App!"); } }); */ Ext.onReady(function () { //alert("This is my first Extjs app !"); //Ext.Msg.alert("Alert", &q