程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> JCFXBL輔助類

JCFXBL輔助類

編輯:關於C

\

 
         編寫Helper類的目的主要是簡化在C# .NET環境下的編程。尤其是簡化在Windows Forms中的Combox控件、DataGridView控件、以及DataTable對象與數據庫進行交互的目的。

         使用下面的Helper類的前提是要引用

            using JCFXBL.SrvInterface;
            using JCFXBL.SrvInterface.Core.ProtocolLayer;

 

對應的程序集如下:

 

\

 

源代碼如下:

 

[csharp]
using JCFXBL.SrvInterface; 
using JCFXBL.SrvInterface.Core.ProtocolLayer; 
using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
 
namespace JCFXBL.API 

    public class Helper 
    { 
        public static string ServerUrl; 
 
        /// <summary>  
        /// 把DIC字典數據自動填充進combox控件  
        /// </summary>  
        /// <param name="dic">字典名稱</param>  
        /// <param name="cmb">combox控件對象</param>  
        public static void FillComboxByDic(string dic, ComboBox cmb) 
        { 
            BIRequest BIR = new BIRequest(); 
            BIR.url = Helper.ServerUrl + "Execute.ashx?Serlet=GetDICStore&ACT=GET&dic=" + dic; 
            if (BIR.Request()) 
            { 
                try 
                { 
                    SrvResponse r = new SrvResponse(BIR.Response()); 
                    DataTable dt = r.GetResultTable(); 
                    cmb.DataSource = dt; 
                    cmb.DisplayMember = "value"; 
                    cmb.ValueMember = "key"; 
                } 
                catch (Exception ex) 
                { 
                   // MessageBox.Show(ex.Message);  
                } 
            } 
        } 
 
        /// <summary>  
        /// 把數據表中對應的數據字段填充進combox控件  
        /// </summary>  
        /// <param name="cmb">combox控件對象</param>  
        /// <param name="Parms">查詢參數</param>  
        /// <param name="act">存儲過程名稱</param>  
        /// <param name="DisplayMember">combox顯示字段</param>  
        /// <param name="ValueMember">combox值字段</param>  
        public static void FillComboBoxByTable(ComboBox cmb, System.Collections.ArrayList Parms, string act, string DisplayMember, string ValueMember) 
        {             
            BIRequest BIR = new BIRequest(); 
            BIR.url = Helper.ServerUrl + "Execute.ashx?Serlet=GetDBStore&ACT=" + act; 
 
            if (Parms != null) 
                for (int i = 0; i < Parms.Count; i++) 
                { 
                    PostParm p = (PostParm)Parms[i]; 
                    BIR.AddFormParam(p.ParmName, p.ParmValue); 
 
                } 
            if (BIR.Request()) 
            { 
                try 
                { 
                    SrvResponse r = new SrvResponse(BIR.Response()); 
                    DataTable dt = r.GetResultTable(); 
                    cmb.DataSource = dt; 
                    cmb.DisplayMember = DisplayMember;// "";  
                    cmb.ValueMember = ValueMember;// "";  
                } 
                catch (Exception ex) 
                { 
                    // MessageBox.Show(ex.Message);  
                } 
            } 
        } 
 
 
        /// <summary>  
        /// 把數據庫中的數據填充到DataGridView控件  
        /// </summary>  
        /// <param name="dgv">DataGridView控件對象</param>  
        /// <param name="act">存儲過程名稱</param>  
        /// <param name="Parms">查詢參數</param>  
        public static void FillDataGridViewByTable(DataGridView dgv, string act, System.Collections.ArrayList Parms) 
        { 
            BIRequest BIR = new BIRequest(); 
            BIR.url = JCFXBL.API.Helper.ServerUrl + "Execute.ashx?Serlet=GetDBStore&ACT="+act; 
 
            if (Parms != null) 
                for (int i = 0; i < Parms.Count; i++) 
                { 
                    PostParm p = (PostParm)Parms[i]; 
                    BIR.AddFormParam(p.ParmName, p.ParmValue); 
 
                }            
 
            if (BIR.Request()) 
            { 
                SrvResponse r = new SrvResponse(BIR.Response()); 
                if (r.return_value == "1") 
                { 
                    DataTable dt = r.GetResultTable(); 
                    dgv.DataSource = dt; 
 
                } 
                else 
                { 
                    MessageBox.Show(BIR.Response()); 
                } 
            } 
            else 
            { 
 
                MessageBox.Show(BIR.Response()); 
            } 
        } 
 
 
        /// <summary>  
        /// 把從數據庫查詢到的數據填充到一個DataTable對象中  
        /// </summary>  
        /// <param name="act">存儲過程名稱</param>  
        /// <param name="Parms">查詢參數</param>  
        /// <returns></returns>  
        public static DataTable FillDataTable(string act, System.Collections.ArrayList Parms) 
        { 
            BIRequest BIR = new BIRequest(); 
            BIR.url = JCFXBL.API.Helper.ServerUrl + "Execute.ashx?Serlet=GetDBStore&ACT=" + act; 
 
            if (Parms != null) 
                for (int i = 0; i < Parms.Count; i++) 
                { 
                    PostParm p = (PostParm)Parms[i]; 
                    BIR.AddFormParam(p.ParmName, p.ParmValue); 
 
                } 
 
            if (BIR.Request()) 
            { 
                SrvResponse r = new SrvResponse(BIR.Response()); 
                if (r.return_value == "1") 
                { 
                    DataTable dt = r.GetResultTable(); 
 
                    return dt; 
 
                } 
                else 
                { 
                    MessageBox.Show(BIR.Response()); 
                } 
            } 
            else 
            { 
 
                MessageBox.Show(BIR.Response()); 
            } 
 
            return null; 
        } 
    } 

using JCFXBL.SrvInterface;
using JCFXBL.SrvInterface.Core.ProtocolLayer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JCFXBL.API
{
    public class Helper
    {
        public static string ServerUrl;

        /// <summary>
        /// 把DIC字典數據自動填充進combox控件
        /// </summary>
        /// <param name="dic">字典名稱</param>
        /// <param name="cmb">combox控件對象</param>
        public static void FillComboxByDic(string dic, ComboBox cmb)
        {
            BIRequest BIR = new BIRequest();
            BIR.url = Helper.ServerUrl + "Execute.ashx?Serlet=GetDICStore&ACT=GET&dic=" + dic;
            if (BIR.Request())
            {
                try
                {
                    SrvResponse r = new SrvResponse(BIR.Response());
                    DataTable dt = r.GetResultTable();
                    cmb.DataSource = dt;
                    cmb.DisplayMember = "value";
                    cmb.ValueMember = "key";
                }
                catch (Exception ex)
                {
                   // MessageBox.Show(ex.Message);
                }
            }
        }

        /// <summary>
        /// 把數據表中對應的數據字段填充進combox控件
        /// </summary>
        /// <param name="cmb">combox控件對象</param>
        /// <param name="Parms">查詢參數</param>
        /// <param name="act">存儲過程名稱</param>
        /// <param name="DisplayMember">combox顯示字段</param>
        /// <param name="ValueMember">combox值字段</param>
        public static void FillComboBoxByTable(ComboBox cmb, System.Collections.ArrayList Parms, string act, string DisplayMember, string ValueMember)
        {           
            BIRequest BIR = new BIRequest();
            BIR.url = Helper.ServerUrl + "Execute.ashx?Serlet=GetDBStore&ACT=" + act;

            if (Parms != null)
                for (int i = 0; i < Parms.Count; i++)
                {
                    PostParm p = (PostParm)Parms[i];
                    BIR.AddFormParam(p.ParmName, p.ParmValue);

                }
            if (BIR.Request())
            {
                try
                {
                    SrvResponse r = new SrvResponse(BIR.Response());
                    DataTable dt = r.GetResultTable();
                    cmb.DataSource = dt;
                    cmb.DisplayMember = DisplayMember;// "";
                    cmb.ValueMember = ValueMember;// "";
                }
                catch (Exception ex)
                {
                    // MessageBox.Show(ex.Message);
                }
            }
        }


        /// <summary>
        /// 把數據庫中的數據填充到DataGridView控件
        /// </summary>
        /// <param name="dgv">DataGridView控件對象</param>
        /// <param name="act">存儲過程名稱</param>
        /// <param name="Parms">查詢參數</param>
        public static void FillDataGridViewByTable(DataGridView dgv, string act, System.Collections.ArrayList Parms)
        {
            BIRequest BIR = new BIRequest();
            BIR.url = JCFXBL.API.Helper.ServerUrl + "Execute.ashx?Serlet=GetDBStore&ACT="+act;

            if (Parms != null)
                for (int i = 0; i < Parms.Count; i++)
                {
                    PostParm p = (PostParm)Parms[i];
                    BIR.AddFormParam(p.ParmName, p.ParmValue);

                }          

            if (BIR.Request())
            {
                SrvResponse r = new SrvResponse(BIR.Response());
                if (r.return_value == "1")
                {
                    DataTable dt = r.GetResultTable();
                    dgv.DataSource = dt;

                }
                else
                {
                    MessageBox.Show(BIR.Response());
                }
            }
            else
            {

                MessageBox.Show(BIR.Response());
            }
        }


        /// <summary>
        /// 把從數據庫查詢到的數據填充到一個DataTable對象中
        /// </summary>
        /// <param name="act">存儲過程名稱</param>
        /// <param name="Parms">查詢參數</param>
        /// <returns></returns>
        public static DataTable FillDataTable(string act, System.Collections.ArrayList Parms)
        {
            BIRequest BIR = new BIRequest();
            BIR.url = JCFXBL.API.Helper.ServerUrl + "Execute.ashx?Serlet=GetDBStore&ACT=" + act;

            if (Parms != null)
                for (int i = 0; i < Parms.Count; i++)
                {
                    PostParm p = (PostParm)Parms[i];
                    BIR.AddFormParam(p.ParmName, p.ParmValue);

                }

            if (BIR.Request())
            {
                SrvResponse r = new SrvResponse(BIR.Response());
                if (r.return_value == "1")
                {
                    DataTable dt = r.GetResultTable();

                    return dt;

                }
                else
                {
                    MessageBox.Show(BIR.Response());
                }
            }
            else
            {

                MessageBox.Show(BIR.Response());
            }

            return null;
        }
    }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved