• 代码升级 荣


    1:修改Add方法:
    /// <summary>
            /// 添加一条记录。
            /// </summary>
            /// <param name="detail">一条记录</param>
            /// <returns>true 成功 false 失败</returns>
            /// <example>调用案例:
            /// <code>
            /// TableBN bn = new TableBN();
            /// OrderDT baseDT = new OrderDT();
            /// baseDT.ID = 1;
            /// baseDT.Name = "订单1";
            /// bool result = bn.Add(baseDT);
            /// </code>
            /// </example>
            public new bool Add(BaseDT detail)
            {
                Data.ObjectBroker.Create(detail);
                return true;
            }

    2:添加DT类的配置文件:
    RecorderDT.hbm.xml:
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
      <class name="Data.RecorderDT, Data" table="Recorder" discriminator-value="C">
        <id name="RedId" type="Int32" column="RedId" unsaved-value="0">
          <generator class="identity"/>
        </id>
        <property name="CreateDate" type="String" column="CreateDate" insert="false" />
        <property name="RecDate" type="String" column="RecDate" />
        <property name="RecType" type="Int32" column="RecType" />
        <property name="RecValue" type="Decimal" column="RecValue" />
        <property name="Remark" type="String(250)" column="Remark" />
      </class>
    </hibernate-mapping>

    RecorderDT.cs:
    /// <copyright>Xumingxsh  1999-2006</copyright>
    /// <version>1.0</version>
    /// <author>Xuming</author>
    /// <email>Xumingxsh21@126.com</email>
    /// <log date="2006-05-30">创建</log>

    using System;
    using System.Data;

    namespace Data
    {
     /// <summary>
     /// Recorder表的描述类。
     /// </summary>
     /// <author>Xuming</author>
     /// <log date="2006-05-30">创建</log>
     public class RecorderDT : BaseDataDT
     {
      public RecorderDT() : base()
      {
      }

      /// <summary>
      /// 记录ID。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private int _RedId;

      /// <summary>
      /// 记录时间。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private string _CreateDate;

      /// <summary>
      /// 花销日期。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private string _RecDate;

      /// <summary>
      /// 花销类型。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private int _RecType;

      /// <summary>
      /// 花销金额。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private decimal _RecValue;

      /// <summary>
      /// 备注。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private string _Remark;

      /// <summary>
      /// 记录ID。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public int RedId
      {
       set
       {
        _RedId = value;
       }
       get
       {
        return _RedId;
       }
      }

      /// <summary>
      /// 记录时间。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public string CreateDate
      {
       set
       {

        _CreateDate = value;
       }
       get
       {
        return _CreateDate;
       }
      }

      /// <summary>
      /// 花销日期。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public string RecDate
      {
       set
       {

        _RecDate = value;
       }
       get
       {
        return _RecDate;
       }
      }

      /// <summary>
      /// 花销类型。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public int RecType
      {
       set
       {

        _RecType = value;
       }
       get
       {
        return _RecType;
       }
      }

      /// <summary>
      /// 花销金额。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public decimal RecValue
      {
       set
       {
        _RecValue = value;
       }
       get
       {
        return _RecValue;
       }
      }

      /// <summary>
      /// 备注。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public string Remark
      {
       set
       {

        _Remark = value;
       }
       get
       {
        return _Remark;
       }
      }
     }
    }


    RectypeDT.hbm.xml:
    <?xml version="1.0" encoding="utf-8" ?>
     <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
      <class name="Data.RectypeDT, Data" table="RecType">
       <id name="RecTypeId" type="Int32" column="RecTypeId">
        <generator class="identity"/>
       </id>
       <property name="RecTypeName" type="String(10)" column="RecTypeName" />
       </class>
    </hibernate-mapping>

    RectypeDT.cs:
    /// <copyright>Xumingxsh  1999-2006</copyright>
    /// <version>1.0</version>
    /// <author>Xuming</author>
    /// <email>Xumingxsh21@126.com</email>
    /// <log date="2006-05-30">创建</log>

    using System;
    using System.Data;

    namespace Data
    {
     /// <summary>
     /// Rectype表的描述类。
     /// </summary>
     /// <author>Xuming</author>
     /// <log date="2006-05-30">创建</log>
     [Serializable()]
     public class RectypeDT : BaseDataDT
     {
      public RectypeDT() : base()
      {
      }

      /// <summary>
      /// 花销类型编号。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private int _RecTypeId;

      /// <summary>
      /// 花销类型名称。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      private string _RecTypeName;

      /// <summary>
      /// 花销类型编号。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public int RecTypeId
      {
       set
       {
        _RecTypeId = value;
       }
       get
       {
        return _RecTypeId;
       }
      }

      /// <summary>
      /// 花销类型名称。
      /// </summary>
      /// <author>Xuming</author>
      /// <log date="2006-05-30">创建</log>
      public string RecTypeName
      {
       set
       {

        _RecTypeName = value;
       }
       get
       {
        return _RecTypeName;
       }
      }
     }
    }

    3:修改添加记录:
    /// <summary>
      /// 添加花销记录。
      /// </summary>
      public void AddRecorder(RecorderDV detail)
      {
       int recId = GetTypeId(detail.RecTypeName);

       detail.RecType = recId;
                this.Add(detail);
      }

    /// <summary>
      /// 取得类型编号。
      /// </summary>
      /// <param name="recTypeName"></param>
      /// <returns></returns>
      private int GetTypeId(string recTypeName)
      {
       if (!IsExistType(recTypeName))
       {
        RectypeDT detail = new RectypeDT();
        detail.RecTypeName = recTypeName;
        this.Add(detail);
       }

       RectypeSQL sql = new RectypeSQL();
       SqlInfo info = sql.GetTypeID(recTypeName);

       return this.GetRows(info);
      }

    修改后的AddRecorder:
    /// <summary>
            /// 添加花销记录。
            /// </summary>
            public void AddRecorder(RecorderDV detail)
            {
                int recId = GetTypeId(detail.RecTypeName);

                detail.RecType = recId;

                RecorderDT dtDetail = new RecorderDT();
                dtDetail.RecDate = detail.RecDate;
                dtDetail.RecType = detail.RecType;
                dtDetail.RecValue = detail.RecValue;
                dtDetail.Remark = detail.Remark;
                this.Add(dtDetail);
            }

    4:接下来,是把取得花销类型ID和添加花销记录合起来,用NHibernate实现。
    步骤:1)修改DT类;2)修改配置文件;3)修改AddRecorder和GetTypeId方法。

  • 相关阅读:
    数组乘积更新
    win向linux传文件
    遇到autoreconf: not found
    python thread
    aptitude
    virtualbox安装ubuntu出现“The system is running in low-graphics mode”
    webform用户控件
    LinQ to SQL
    表单验证
    文件上传
  • 原文地址:https://www.cnblogs.com/admin11/p/637586.html
Copyright © 2020-2023  润新知