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;

对应的程序集如下:

 

源代码如下:

 

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


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值