首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

JCFXBL辅助类-Helper种介绍

2013-04-09 
JCFXBL辅助类----Helper类介绍JCFXBL辅助类---Helper类介绍本系列文章由ex_net(张建波)编写,转载请注明出

JCFXBL辅助类----Helper类介绍

JCFXBL辅助类---Helper类介绍

本系列文章由ex_net(张建波)编写,转载请注明出处。


http://blog.csdn.net/ex_net/article/details/8771111


作者:张建波 邮箱: 281451020@qq.com 电话:13577062679 欢迎来电交流!

 

         编写Helper类的目的主要是简化在C# .NET环境下的编程。尤其是简化在Windows Forms中的Combox控件、DataGridView控件、以及DataTable对象与数据库进行交互的目的。

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

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

JCFXBL辅助类-Helper种介绍

对应的程序集如下:

JCFXBL辅助类-Helper种介绍

 

源代码如下:

 

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;        }    }}


 

热点排行