FlowPortal-BPM——創建新模塊


一、設置webconfig

(1)數據源設置  添加所有所用到數據庫

(2)修改企業信息

二、Main.ashx——添加新的功能選項卡

new {
    id = "EXECUTE",
    title = Resources.YZStrings.Module_Execute,
    modulePerm = new YZModulePermision("e52e8214-6e6e-4132-9873-d33a54eb977d", YZModuleDeniedBehavior.Hide),
    dataURL = this.ResolveUrl(context,"EXECUTE.ashx"),
    activeNode = "Worklist" //"Post/Worklist"
},
新建模塊選項卡區域代碼

三、New1.ashx——設置左側導航欄

<%@ WebHandler Language="C#" Class="BPMApp.New1ModuleTree" %>   //類名

using System;
using System.Web;
using System.Text;
using Newtonsoft.Json.Linq;

namespace BPMApp
{
    public class New1ModuleTree : YZServiceHandler  //類名
    {
        public object GetModuleTree(HttpContext context)
        {
            object[] modules = new object[] {
                new {
                    text = "第一個一級菜單",
                    expanded = true,
                    children = new object[]{
                        new {
                            id = "P1",//二級菜單的ID
                            text = "第一個子菜單",//二級菜單的名稱
                            xclass = "BPM.YW.CGGL.CGSQ.Modules.CGSQPanel"//二級菜單指向的JS文件路徑,控制主內容區域的樣式
                        },
                        new {
                            id = "Drafts",
                            text = "第二個子菜單",
                            xclass = "YZSoft.BPM.Drafts.Panel"
                        },
                        new {
                            id = "FormTemplates",
                            text = "第三個子菜單",
                            xclass = "YZSoft.BPM.FormTemplates.Panel"
                        }
                    }
                },
                new {
                    text = "第二個一級菜單",
                    expanded = true,
                    children = new object[]{
                        new {
                            id = "Worklist",
                            text = "第四個子菜單",
                            xclass = "BPM.YW.CGGL.CGSQ.Modules.CGSQPanel"
                        },
                        new {
                            id = "ShareTask",
                            text = "第五個子菜單",
                            xclass = "YZSoft.BPM.ShareTask.Panel"
                        }
                    }
                },
            };

            return YZSecurityManager.ApplayPermision(modules);
        }
    }
}
左側導航欄區域ashx代碼

 四、主內容區設置

JS文件設置:

Ext.define('BPM.YW.CGGL.CGSQ.Modules.CGSQPanel', {    //此JS文件的絕對路徑
    extend: 'Ext.panel.Panel',
    requires: [
        'YZSoft.BPM.src.ux.FormManager'
    ],
    dlgCfg: {
        dlgModel: 'Dialog',    //展示樣式:Tab,Window,Dialog
        width: 700,
        height: 650
    },

    constructor: function (config) {
        var me = this;

        //查詢所有要展示的數據
        me.store = Ext.create('Ext.data.JsonStore', {
            remoteSort: true,
            pageSize: YZSoft.EnvSetting.PageSize.defaultSize,
            model: 'Ext.data.Model',
            sorters: { property: 'TaskID', direction: 'desc' },    //數據排序:字段名、升降序
            proxy: {
                type: 'ajax',
                url: YZSoft.$url(me, '../StoreDataService/CGSQListData.ashx'),    //對應的一般處理程序的路徑
                extraParams: {
                    method: 'GetDataNoRecordPerm'    //一般處理程序的查詢方法
                },
                reader: {
                    rootProperty: 'children'
                }
            }
        });

        //展示數據表的表頭設置
        me.grid = Ext.create('Ext.grid.Panel', {
            store: me.store,
            border: false,
            selModel: { mode: 'MULTI' },
            columns: {
                defaults: {},
                items: [
                    { xtype: 'rownumberer' },
                    //header-表頭名稱  dataIndex-需要綁定的字段名  sortable-顯示(或隱藏)
                    { header: '姓名', dataIndex: 'Name', width: 80, align: 'left', sortable: true },
                    { header: '年齡', dataIndex: 'Age', width: 50, align: 'left', sortable: true, hidden: true },
                    { header: '級別', dataIndex: 'Level', width: 100, align: 'left', sortable: true },
                    { header: '電話', dataIndex: 'Tell', width: 150, align: 'left', sortable: true },
                    { header: '物料名稱', dataIndex: 'WName', width: 100, align: 'left', sortable: true },
                    { header: '物料單價', dataIndex: 'WPrice', width: 100, align: 'left', sortable: true },
                    { header: '物料數量', dataIndex: 'WShu', width: 100, align: 'left', sortable: true }
                ]
            },
            //狀態欄
            bbar: Ext.create('Ext.toolbar.Paging', {
                store: me.store,
                displayInfo: true
            }),
            //監聽
            listeners: {
                scope: me,
                rowdblclick: function (grid, record, tr, rowIndex, e, eOpts) {
                    me.read(record);
                }
            }
        });
        //【添加】按鈕
        me.btnNew = Ext.create('Ext.button.Button', {
            iconCls: 'yz-btn-add',
            text: '添加',
            //訪問權限的控制
            //updateStatus: function () {
            //    this.setDisabled(!YZSoft.UIHelper.IsOptEnable(null, me.grid, '', 1, 1));
            //    //this.setDisabled(!config.perm['New']);
            //},
            handler: function () {
                me.addNew();
            }
        });
        //【編輯】按鈕
        me.btnEdit = Ext.create('YZSoft.src.button.Button', {
            iconCls: 'yz-btn-edit',
            text: '編輯',
            sm: me.grid.getSelectionModel(),
            //權限
            //updateStatus: function () {
            //    this.setDisabled(!YZSoft.UIHelper.IsOptEnable(null, me.grid, '', 1, 1));
            //    //this.setDisabled(!config.perm['Edit']);
            //},
            handler: function () {
                var sm = me.grid.getSelectionModel(),
                    recs = sm.getSelection() || [];

                if (recs.length != 1)
                    return;

                me.edit(recs[0]);
            }
        });
        //【刪除】按鈕
        me.btnDelete = Ext.create('YZSoft.src.button.Button', {
            iconCls: 'yz-btn-delete',
            text: '刪除',
            sm: me.grid.getSelectionModel(),
            //updateStatus: function () {
            //    this.setDisabled(!YZSoft.UIHelper.IsOptEnable(null, me.grid, '', 1, 1));
            //    //this.setDisabled(!config.perm['Delete']);
            //},
            handler: function () {
                me.deleteSelection();
            }
        });
        //【打開】按鈕
        me.btnOpen = Ext.create('YZSoft.src.button.Button', {
            iconCls: 'yz-btn-public',
            text: '打開',
            sm: me.grid.getSelectionModel(),
            updateStatus: function () {
                this.setDisabled(!YZSoft.UIHelper.IsOptEnable(null, me.grid, '', 1, -1));
            },
            handler: function () {
                me.openSelection();
            }
        });
        //【關閉】按鈕
        me.btnClose = Ext.create('YZSoft.src.button.Button', {
            iconCls: 'yz-btn-power',
            text: '關閉',
            sm: me.grid.getSelectionModel(),
            updateStatus: function () {
                this.setDisabled(!YZSoft.UIHelper.IsOptEnable(null, me.grid, '', 1, -1));
            },
            handler: function () {
                me.closeSelection();
            }
        });

        //【高級查詢——加號】按鈕
        me.btnAdt = Ext.create('YZSoft.src.button.Button', {
            cls: 'yz-form-advsearch-trigger',
            scope: this,
            listeners: {
                scope: this,
                click: function () {
                    me.ShowAdvancedSearchdDlg(me.store,
                        {
                            title: '高級查詢',
                            scope: this,
                            fn: function (owner) {
                                //完成查詢后自動刷新列表
                                me.store.reload({ params: { start: me.store.cursor} });
                            }
                        }
                    );
                }
            }
        });
        //【導出】按鈕
        me.btnExcelExport = Ext.create('YZSoft.src.button.ExcelExportButton', {
            grid: me.grid,
            templateExcel: null, //YZSoft.$url(me, '采購申請.xls'), //導出模板,不設置則按缺省方式導出
            params: {},
            fileName: '采購申請',//▲導出文件名▲
            allowExportAll: true, //可選項,缺省使用YZSoft.EnvSetting.Excel.AllowExportAll中的設置,默認值false
            //maxExportPages: 10, //可選項,缺省使用YZSoft.EnvSetting.Excel.MaxExportPages中的設置,默認值100
            listeners: {
                beforeload: function (params) {
                    params.ReportDate = new Date();
                }
            }
        });

        //按鈕布局
        var cfg = {
            title: '采購申請',//▲標題▲
            layout: 'fit',
            border: false,
            items: [me.grid],
            tbar: [me.btnNew, me.btnEdit, me.btnDelete, me.btnOpen, me.btnClose, '|', me.btnExcelExport, '->', {
                xtype: 'button',
                text: '清除搜索條件',
                handler: function () {
                    var params = me.store.getProxy().getExtraParams();
                    params.searchType = '';
                    me.store.loadPage(1);
                }
            }, ' ', {
                xclass: 'YZSoft.src.form.field.Search',
                store: me.store,
                width: 160
            }
            , me.btnAdt
            ]
        };

        Ext.apply(cfg, config);
        me.callParent([cfg]);
    },

    //======================================================================================
    //高級查詢方法▲按需求修改▲
    ShowAdvancedSearchdDlg: function (store, cfg) {
        var showform = function () {
            var add_winForm = Ext.create('Ext.form.Panel', {
                frame: true,
                width: '100%',
                bodyPadding: 5,
                fieldDefaults: {
                    labelAlign: 'left',
                    anchor: '100%'
                },
                //彈窗顯示的查詢條件
                items: [{
                    fieldLabel: '申請人', //申請人
                    xtype: 'textfield', id: "idName"
                }, {
                    fieldLabel: '申請部門', //申請部門
                    xtype: 'textfield', id: "idDept"
                }, {
                    fieldLabel: '審批狀態', //申請人 YZSoft.src.form.field.User
                    xtype: 'textfield', id: "idState"
                }, {
                    fieldLabel: '申請時間', //申請時間
                    xclass: 'YZSoft.src.form.field.PeriodPicker', id: "idAddDate"
                }]
            });
            var syswin = Ext.create('Ext.window.Window', {
                title: "高級查詢",
                width: 450,
                resizable: false,
                closable: true,
                // 彈出模態窗體  
                modal: 'true',
                buttonAlign: "center",
                bodyStyle: "padding:0 0 0 0",
                items: [add_winForm],
                buttons: [{
                    text: RS.$('YZStrings.All_OK'), //確定
                    id: "idSubmit",
                    scope: this,
                    handler: function () {
                        //點擊確定傳參,以下為需要修改的傳遞給一般處理程序的參數
                        var appName = Ext.getCmp("idName").getValue(); //人員名稱
                        var appDeptName = Ext.getCmp("idDept").getValue(); //部門名稱
                        var state = Ext.getCmp("idState").getValue(); //審批狀態
                        var period = Ext.getCmp("idAddDate").getPeriod(); //日期區間
                        store.reload({
                            params:
                                {
                                    start: store.cursor,
                                    searchType: "AdvancedSearch",
                                    cUserName: appName,
                                    cState: state,
                                    cDepName: appDeptName,
                                    PeriodType: period.PeriodType,
                                    StartDate: period.Date1,
                                    EndDate: period.Date2
                                }
                        });
                        var params = store.getProxy().getExtraParams();
                        params.searchType = "AdvancedSearch";
                        params.cUserName = appName;
                        params.cState = state;
                        params.cDepName = appDeptName;
                        params.PeriodType = period.PeriodType;
                        params.StartDate = period.Date1;
                        params.EndDate = period.Date2;
                        store.loadPage(1);
                        add_winForm.close();
                        syswin.close();
                    }
                }, {
                    text: RS.$('YZStrings.All_Close'), //取消
                    scope: this,
                    handler: function () {
                        add_winForm.close();
                        syswin.close();
                    }
                }]
            });
            syswin.show();     //顯示window
        };
        showform();         //顯示form
    },

    //數據更新時自動刷新頁面
    onActivate: function (times) {
        if (times == 0)
            this.store.load({
                loadMask: {
                    msg: RS.$('All_Loading'),
                    delay: true
                }
            });
        else
            this.store.reload({ loadMask: false });

        this.updateStatus();
    },

    //控制按鈕權限
    updateStatus: function () {
        var sm = this.grid.getSelectionModel();
        recs = sm.getSelection() || new Array();

        //if (!YZSoft.UIHelper.IsOptEnable(this, this.grid, 'Edit')) {
        //    this.btnEdit.hide();
        //} else {
        //    this.btnEdit.setDisabled(recs.length != 1); //選中一行或者多行是否可用
        //}
        //if (!YZSoft.UIHelper.IsOptEnable(this, this.grid, 'Delete')) {
        //    this.btnDelete.hide();
        //} else {
        //    this.btnDelete.setDisabled(recs.length == 0);
        //}
    },

    //【添加】方法▲按照需求修改▲
    addNew: function () {
        var me = this;
        YZSoft.BPM.src.ux.FormManager.openPostWindow('物料申請流程', Ext.apply({  //選擇要使用的流程名稱
            sender: me,
            title: '物料申請',  //選項卡名稱
            listeners: {
                itemclick: function (view, record, item, index, e, eOpts) {
                    e.stopEvent();
                    me.store.load({
                        params: {
                            path: record.isRoot() ? '' : record.data.path,
                            start: 0
                        }
                    });
                }
            },
            tools: [{
                type: 'refresh',
                tooltip: RS.$('All_Refresh_Tip'),
                handler: function (event, toolEl, panel) {
                    me.treestore.load();
                }
            }]
        }, ''));
    },
    //【編輯】方法▲按照需求修改▲
    edit: function (rec) {
        var me = this;
        YZSoft.BPM.src.ux.FormManager.openFormApplication('業務管理/采購管理/采購申請', rec.data.TaskID, 'Edit', Ext.apply({
            sender: me,
            title: "采購申請",
            listeners: {
                submit: function (action, data) {
                    me.store.reload({
                        loadMask: {
                            msg: '保存已成功',
                            delay: 'x'
                        }
                    });
                }
            }
        }, ''));
    },
    //【刪除】方法
    deleteSelection: function () {
        var me = this,
            recs = me.grid.getSelectionModel().getSelection(),
            ids = [];

        if (recs.length == 0)
            return;

        Ext.each(recs, function (rec) {
            ids.push(rec.data.TaskID);
        });

        Ext.Msg.show({
            title: '刪除確認',
            msg: '您確定要刪除選中項嗎?',
            buttons: Ext.Msg.OKCANCEL,
            defaultFocus: 'cancel',
            icon: Ext.MessageBox.INFO,

            fn: function (btn, text) {
                if (btn != 'ok')
                    return;

                YZSoft.Ajax.request({
                    url: YZSoft.$url(me, '../StoreDataService/CGSQListData.ashx'),
                    method: 'POST',
                    params: {
                        method: 'Delete'
                    },
                    jsonData: ids,
                    waitMsg: { msg: '正在刪除...', target: me.grid },
                    success: function (action) {
                        me.store.reload({
                            loadMask: {
                                msg: Ext.String.format('{0}個對象已刪除!', recs.length),
                                delay: 'x'
                            }
                        });
                    },
                    failure: function (action) {
                        var mbox = Ext.Msg.show({
                            title: '錯誤提示',
                            msg: YZSoft.HttpUtility.htmlEncode(action.result.errorMessage, true),
                            buttons: Ext.Msg.OK,
                            icon: Ext.MessageBox.WARNING
                        });

                        me.store.reload({ mbox: mbox });
                    }
                });
            }
        });
    },
    //【雙擊查看】功能
    read: function (rec) {
        YZSoft.BPM.src.ux.FormManager.openFormApplication('業務管理/采購管理/采購申請', rec.data.TaskID, 'Read', Ext.apply({
            sender: this,
            params: { tid: rec.data.TaskID },
            title: "采購申請"
        }, ''));
    },
    //【打開】功能
    openSelection: function () {
        var me = this,
            recs = me.grid.getSelectionModel().getSelection(),
            ids = [];

        if (recs.length == 0)
            return;

        Ext.each(recs, function (rec) {
            ids.push(rec.data.TaskID);
        });

        Ext.Msg.show({
            title: '打開確認',
            msg: '您確定要打開選中項嗎?',
            buttons: Ext.Msg.OKCANCEL,
            defaultFocus: 'cancel',
            icon: Ext.MessageBox.INFO,

            fn: function (btn, text) {
                if (btn != 'ok')
                    return;

                YZSoft.Ajax.request({
                    url: YZSoft.$url(me, '../StoreDataService/CGSQListData.ashx'),
                    method: 'POST',
                    params: {
                        method: 'Open'
                    },
                    jsonData: ids,
                    waitMsg: { msg: '正在打開...', target: me.grid },
                    success: function (action) {
                        me.store.reload({
                            loadMask: {
                                msg: Ext.String.format('{0}個對象已打開!', recs.length),
                                delay: 'x'
                            }
                        });
                    },
                    failure: function (action) {
                        var mbox = Ext.Msg.show({
                            title: '錯誤提示',
                            msg: YZSoft.HttpUtility.htmlEncode(action.result.errorMessage, true),
                            buttons: Ext.Msg.OK,
                            icon: Ext.MessageBox.WARNING
                        });

                        me.store.reload({ mbox: mbox });
                    }
                });
            }
        });
    },
    //【關閉】功能
    closeSelection: function () {
        var me = this,
            recs = me.grid.getSelectionModel().getSelection(),
            ids = [];

        if (recs.length == 0)
            return;

        Ext.each(recs, function (rec) {
            ids.push(rec.data.TaskID);
        });

        Ext.Msg.show({
            title: '關閉確認',
            msg: '您確定要關閉選中項嗎?',
            buttons: Ext.Msg.OKCANCEL,
            defaultFocus: 'cancel',
            icon: Ext.MessageBox.INFO,

            fn: function (btn, text) {
                if (btn != 'ok')
                    return;

                YZSoft.Ajax.request({
                    url: YZSoft.$url(me, '../StoreDataService/CGSQListData.ashx'),
                    method: 'POST',
                    params: {
                        method: 'Close'
                    },
                    jsonData: ids,
                    waitMsg: { msg: '正在關閉...', target: me.grid },
                    success: function (action) {
                        me.store.reload({
                            loadMask: {
                                msg: Ext.String.format('{0}個對象已關閉!', recs.length),
                                delay: 'x'
                            }
                        });
                    },
                    failure: function (action) {
                        var mbox = Ext.Msg.show({
                            title: '錯誤提示',
                            msg: YZSoft.HttpUtility.htmlEncode(action.result.errorMessage, true),
                            buttons: Ext.Msg.OK,
                            icon: Ext.MessageBox.WARNING
                        });

                        me.store.reload({ mbox: mbox });
                    }
                });
            }
        });
    }
    
});
JS代碼根據實際情況進行更改

一般處理程序設置 :(注意相對或絕對路徑、數據類型)

<%@ WebHandler Language="C#" Class="ListData" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using BPM;
using BPM.Client;
using YZSoft.Web.DAL;
using Newtonsoft.Json.Linq;

public class ListData : YZServiceHandler
{
    //【刪除】功能▲按需求修改
    public void Delete(HttpContext context)
    {
        YZRequest request = new YZRequest(context);
        JArray jPost = request.GetPostData<JArray>();
        List<int> ids = jPost.ToObject<List<int>>();

        using (SqlConnection cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BPMDBDataTest"].ConnectionString))
        {
            cn.Open();

            foreach (int id in ids)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandText = "DELETE FROM CG_PurchaseApp_M WHERE TaskID=@TaskID;DELETE FROM CG_PurchaseApp_T WHERE TaskID=@TaskID";
                cmd.Parameters.Add("@TaskID", SqlDbType.Int).Value = id;
                cmd.ExecuteNonQuery();
            }
        }
    }

   
    public void Open(HttpContext context)
    {
        YZRequest request = new YZRequest(context);
        JArray jPost = request.GetPostData<JArray>();
        List<int> ids = jPost.ToObject<List<int>>();

        using (SqlConnection cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BPMDATA"].ConnectionString))
        {
            cn.Open();

            foreach (int id in ids)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandText = "update CG_PurchaseApp_M set IsOpenClose ='1' where TaskID =@TaskID";
                cmd.Parameters.Add("@TaskID", SqlDbType.Int).Value = id;
                cmd.ExecuteNonQuery();
            }
        }
    }

    public void Close(HttpContext context)
    {
        YZRequest request = new YZRequest(context);
        JArray jPost = request.GetPostData<JArray>();
        List<int> ids = jPost.ToObject<List<int>>();

        using (SqlConnection cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BPMDATA"].ConnectionString))
        {
            cn.Open();

            foreach (int id in ids)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandText = "update CG_PurchaseApp_M set IsOpenClose ='0' where TaskID =@TaskID";
                cmd.Parameters.Add("@TaskID", SqlDbType.Int).Value = id;
                cmd.ExecuteNonQuery();
            }
        }
    }
    //在Panel.js中的顯示的方法名稱
    public JObject GetDataNoRecordPerm(HttpContext context)
    {
        YZRequest request = new YZRequest(context);
        SqlServerProvider queryProvider = new SqlServerProvider();

        string searchType = request.GetString("searchType", null);
        string keyword = request.GetString("Keyword", null);

        //獲得查詢條件
        string filter = null;

        if (searchType == "QuickSearch")
        {
            //應用關鍵字過濾
            if (!string.IsNullOrEmpty(keyword))
                filter = queryProvider.CombinCond(filter, String.Format(" and cApp LIKE N'%{0}%' OR cMarkerDepName LIKE N'%{0}%' OR cInvName LIKE N'%{0}%'", queryProvider.EncodeText(keyword)));
        }

        //獲取查詢類型
        //if (searchType == "AdvancedSearch")
        //{
        //    string Name = request.GetString("cUserName", null);
        //    string State = request.GetString("cState", null);
        //    string Dept = request.GetString("cDepName", null);
        //    //添加日期(高級搜索)
        //    string PeriodType = context.Request.Params["PeriodType"].ToString();
        //    string StartDate = "";
        //    string EndDate = "";
        //    if (PeriodType == "all")
        //    {
        //        //日期為全部時進來無意義
        //        StartDate = request.GetString("StartDate".Replace("T", " "), null);//yyyy-MM-ddThh:mm:ss,T沒轉換成空
        //        EndDate = request.GetString("EndDate".Replace("T", " "), null);
        //    }
        //    else
        //    {
        //        StartDate = Convert.ToDateTime(request.GetString("StartDate", null)).ToString("yyyy-MM-dd");
        //        EndDate = Convert.ToDateTime(request.GetString("EndDate", null).Replace("T", "").Substring(0, 10)).AddDays(-1).ToString("yyyy-MM-dd");
        //    }

        //    if (!string.IsNullOrEmpty(Name))
        //    {
        //        filter = filter + string.Format(" and cApp like '%{0}%'", Name);
        //    }
        //    if (!string.IsNullOrEmpty(Dept))
        //    {
        //        filter = filter + string.Format(" and cMarkerDepName like '%{0}%'", Dept);
        //    }
        //    if (!string.IsNullOrEmpty(State))
        //    {
        //        filter = filter + string.Format(" and cState like '%{0}%'", State);
        //    }
        //    //添加日期(高級搜索)。 查詢 數據庫中 填寫的日期的字段  例如: and convert(nvarchar(50),BaoxiaoDate,120) like '%{0}%'
        //    if (!string.IsNullOrEmpty(PeriodType) && PeriodType.ToLower() != "all")
        //    {
        //        if (PeriodType.ToLower() == "day")
        //        {
        //            filter = filter + string.Format(" and convert(nvarchar(50),dDate,120) like '%{0}%'", StartDate);
        //        }
        //        else
        //        {
        //            filter = filter + string.Format(" and dDate Between '{0}' and '{1}'", StartDate, EndDate);
        //        }
        //    }
        //}

        if (!String.IsNullOrEmpty(filter))
            filter = " WHERE 1=1 " + filter;

        //獲得排序子句
        string order = request.GetSortString("TaskID");

        //獲得Query
        string query = @"
            WITH X AS(
                SELECT ROW_NUMBER() OVER(ORDER BY {0}) AS RowNum,* FROM v_iDemoDevice {1}
            ),
            Y AS(
                SELECT count(*) AS TotalRows FROM X
            ),
            Z AS(
                SELECT Y.TotalRows,X.* FROM Y,X
            )
            SELECT * FROM Z WHERE RowNum BETWEEN {2} AND {3}
        ";

        query = String.Format(query, order, filter, request.RowNumStart, request.RowNumEnd);

        
        //執行查詢
        JObject rv = new JObject();
        using (SqlConnection cn = new SqlConnection())
        {
            cn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BPMDBDataTest"].ConnectionString;
            cn.Open();

            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = cn;
                cmd.CommandText = query;

                using (YZReader reader = new YZReader(cmd.ExecuteReader()))
                {
                    //將數據轉化為Json集合
                    JArray children = new JArray();
                    rv["children"] = children;
                    int totalRows = 0;

                    while (reader.Read())
                    {
                        JObject item = new JObject();
                        children.Add(item);

                        if (totalRows == 0)
                            totalRows = reader.ReadInt32("TotalRows");

                        item["id"] = reader.ReadInt32("id");
                        item["RowNum"] = reader.ReadInt32("RowNum");
                        item["Type"] = reader.ReadString("Type");
                        item["StationName"] = reader.ReadString("StationName");
                        item["Name"] = reader.ReadString("Name");
                        item["Number"] = reader.ReadString("Number");
                        item["Model"] = reader.ReadString("Model");
                        item["Standard"] = reader.ReadString("Standard");
                        item["Price"] = reader.IsDBNull("Price") ? "-" : reader.ReadDecimal("Price").ToString("F2");
                        item["Power"] = reader.ReadDecimal("Power");
                        item["Manufacture"] = reader.ReadString("Manufacture");
                        item["Provider"] = reader.ReadString("Provider");
                        item["DateOfManufacture"] = YZStringHelper.DateToString(reader.ReadDateTime("DateOfManufacture"));
                        item["SystemName"] = reader.ReadString("SystemName");
                        item["IntendAge"] = reader.IsDBNull("IntendAge") ? "-" : reader.ReadDecimal("IntendAge").ToString();
                        item["StartDate"] = YZStringHelper.DateToString(reader.ReadDateTime("StartDate"));
                        item["Location"] = reader.ReadString("Location");
                        item["Picture"] = reader.ReadString("Picture");
                        item["Status"] = reader.ReadString("Status");
                    }
                    rv[YZJsonProperty.total] = totalRows;
                }
            }
        }
        return rv;
    }

    //獲取打開、關閉
    public static string getIsOpenClose(string IsOpenClos)
    {
        if (IsOpenClos == "1")
        {
            IsOpenClos = "打開";
        }
        else if (IsOpenClos == "0")
        {
            IsOpenClos = "關閉";
        }
        return IsOpenClos;
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
一般處理程序代碼

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM