zoukankan      html  css  js  c++  java
  • csla.net 框架的实例应用二(集合多条记录的演示)

    //集合多条记录的演示

    窗体调用代码:

     #region 多条数据

     static TcouponList ListCoupon3;

    //获取
            TcouponList.Criteria cd=new TcouponList.Criteria();
            cd.MemberIdno = "M020697";
            
            ListCoupon3 = TcouponList.GetCouonList(cd);
            GridView1.DataSource = ListCoupon3;
            GridView1.DataBind();

    //增加,更改

    TcouponList ListCoupon = TcouponList.NewTcouponList();
            Tcoupon coupon = Tcoupon.NewCoupon();
            coupon.MemberIdNo = "sssss";
            coupon.CouponValue = 20;
            coupon.GenDate = DateTime.Today;
            coupon.Deadline = DateTime.Today;
            coupon.IsUsed = false;
            coupon.Remark = "shite";
            ListCoupon.Add(coupon);
            ListCoupon.Save();

            foreach (Tcoupon cc in ListCoupon3)
            {
                cc.CouponValue = 42;
            }
            ListCoupon3.Save();

            #endregion

    业务集合类:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Csla;
    using Csla.Data;
    using System.Data.SqlClient;

    namespace dllcsla
    {
        [Serializable]
       public class TcouponList :BusinessListBase<TcouponList,Tcoupon>
        {
            #region Factory Method
            public static TcouponList GetCouonList(Criteria crit)
            {
                return DataPortal.Fetch<TcouponList>(crit);
            }

            public static TcouponList NewTcouponList()
            {
                return new TcouponList();
            }
           
            #endregion

    #region Constructors
            private TcouponList()
            {

            }
    #endregion
            #region Class
            [Serializable]
          
            public class Criteria
            {
                public string CouponNum;
                public string MemberIdno;
                public DateTime? MaxDeadline;
                public bool IsOnlyGetAvail = false;
                public string IssueHotelName = string.Empty;
            }

            #endregion

            #region SQLDAL
            protected override void DataPortal_Fetch(object criteria)
            {
                Criteria Tcriteria = criteria as Criteria;
                StringBuilder sql = new StringBuilder();
                sql.Append("select a.* from table_coupon a ");

                sql.Append(" where '1'='1'");
                string Ttemp = string.Empty;
                Ttemp = GetReturnString(OperaTeype.dayu, Tcriteria.MaxDeadline, "a.deadline", 1);
                sql.Append(Ttemp);

                Ttemp = GetReturnString(OperaTeype.dengyu, Tcriteria.MemberIdno, "a.memberidno", 1);
                sql.Append(Ttemp);
                SafeDataReader dr = new SafeDataReader(SqlHelper.ExecuteReader(sql.ToString()));
                while(dr.Read())
                {
                    this.Add(Tcoupon.GetCoupon(dr));
                }
                dr.Close();

            }

           protected override void DataPortal_Update()
           {

               SqlConnection cn = new SqlConnection("Data Source=.;User ID=sa;Password=123456;Initial Catalog=tblcustom;");
                cn.Open();
               foreach (Tcoupon coupon in this)
               {
                   coupon.Update(cn);
               }
               cn.Close();
           }
            #endregion

            enum OperaTeype { dengyu,dayu, xiaoyu, dayuOrdengyu, xiaoyuOrdengyu, inType, like };
            
            #region UtilMethod
            private string GetReturnString(OperaTeype type, object value,string filed,int yihao)
            {
                string strStart=" and ";
                if (value == null)
                {
                    return string.Empty;
                }
                if (value.ToString().Length <= 0)
                {
                    return string.Empty;
                }
                if (yihao == 1)
                {
                    value = "'" + value + "'";
                }
               
                if ((type == OperaTeype.dayu))
                {             
                        return string.Format("{0}{1}>{2}", strStart, filed, value);
                    
                }
                if ((type == OperaTeype.dengyu))
                {
                    return string.Format("{0}{1}={2}", strStart, filed, value);
                }
                if ((type == OperaTeype.xiaoyu))
                {
                    return string.Format("{0}{1}<{2}", strStart, filed, value);
                }
                if ((type == OperaTeype.dayuOrdengyu))
                {
                    return string.Format("{0}{1}>={2}", strStart, filed, value);
                }
                if ((type == OperaTeype.xiaoyuOrdengyu))
                {
                    return string.Format("{0}{1}<={2}", strStart, filed, value);
                }
                if ((type == OperaTeype.inType))
                {
                    return string.Format("{0}{1} in ({2})", strStart, filed, value);
                }
                if ((type == OperaTeype.like))
                {
                    return string.Format("{0}{1} like '%{2}%'", strStart, filed, value);
                }
                return string.Empty;
            }
            #endregion
        }
    }


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    [Swift]LeetCode472. 连接词 | Concatenated Words
    [Swift]LeetCode470. 用 Rand7() 实现 Rand10() | Implement Rand10() Using Rand7()
    [Swift通天遁地]七、数据与安全-(19)使用Swift实现原生的SHA1加密
    [Swift通天遁地]七、数据与安全-(18)使用Swift实现原生的MD5加密
    [Swift通天遁地]七、数据与安全-(17)使用Swift实现原生的3DES加密和解密
    poj 1265 Area(pick 定理)
    Visual C++文件后缀名释义
    Linux 设备文件的创建和mdev
    37、ifconfig命令
    iOS开发- 生成/解析.vcf文件
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1777380.html
Copyright © 2011-2022 走看看