C#结构函数

结构函数意义

定义: 结构函数是以Struct声明的 实现:
在日常写代码的过程中,可能会遇到以下的问题:往往调用结构体中的属性的时候,因为属性较多,比较繁琐,这时就会用到结构函数

结构函数不多说,直接上代码

    public struct GetSQLString
    {
        public string assetnumber;          //资产编号
        public string mac;          //电脑MAC地址
        public string recievename;     //领用人
        public string outname;        //领出人
        public string RecieveBegin;        //领用开始时间
        public string RecieveEnd;              //领用结束时间
        public string OutBegin;                    //领出开始时间
        public string OutEnd;                    //领出结束时间
        public string GetSQL()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat(@"select a.assetnumber as 资产编号,b.computername as 电脑名称,a.computermac as MAC地址,b.computerip as IP地址,b.computeruser as 登录用户名,a.recievename as 领用人,a.recievetime as 领用时间,
                            a.outname as 领出人, a.outtime as 领出时间
                             from computer_position_info a,computer_cell_info b where a.computermac = b.computermac");
            if (!string.IsNullOrEmpty(assetnumber)) strSql.AppendFormat(@" and a.assetnumber='{0}'", assetnumber);
            if (!string.IsNullOrEmpty(mac)) strSql.AppendFormat(@" and a.computermac='{0}'", mac);
            if (!string.IsNullOrEmpty(recievename)) strSql.AppendFormat(@" and a.recievename='{0}'", recievename);
            if (!string.IsNullOrEmpty(outname)) strSql.AppendFormat(@" and a.outname='{0}'", outname);
            if (!string.IsNullOrEmpty(RecieveBegin) && !string.IsNullOrEmpty(RecieveEnd)) strSql.AppendFormat(@" and (a.recievetime >=to_date('{0}','yyyy-MM-dd hh24:mi:ss') and a.recievetime <=to_date('{1}','yyyy-MM-dd hh24:mi:ss')) ", RecieveBegin, RecieveEnd);
            if (!string.IsNullOrEmpty(OutBegin) && !string.IsNullOrEmpty(OutEnd)) strSql.AppendFormat(@" and (a.outtime >=to_date('{0}','yyyy-MM-dd hh24:mi:ss') and a.outtime <=to_date('{1}','yyyy-MM-dd hh24:mi:ss')) ", OutBegin, OutEnd);
            strSql.AppendFormat(@" order by recievetime desc");
            return strSql.ToString();
        }

    }

调用方式

  GetSQLString strSql = new GetSQLString();
            strSql.assetnumber = assetnumber; strSql.mac = mac; strSql.recievename = recievename; strSql.outname = outname; strSql.RecieveBegin = RecieveBegin; strSql.RecieveEnd = RecieveEnd; strSql.OutBegin = OutBegin; strSql.OutEnd = OutEnd;
            DataSet ds = PubLibrary.objDB.GetDataSet(strSql.GetSQL());
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值