程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 個人開發框架總結(一)(3)

個人開發框架總結(一)(3)

編輯:關於C語言

這樣,每一個類就好維護了,Oracle就使用OracleConnection,OleDb就使用OleDbConnection。

Parameter 存儲過程參數類,這跟System.Data裡的差不多,都是實現同樣的一個功能,只是說使用這個的時候,ParameterName不用具體的加入@或:這樣的前綴。

ParameterCollection 存儲過程參數集合類,這裡面特別的有幾個方法

FromDataModel 從模型轉換為存儲參數。可以根據具體的模型,將所有屬性轉換為存儲過程參數,以為添加或修改作准備。

Format 可以格式化Sql查詢語句,比如在使用添加或修改的時候,可以這樣使用

dataHelper.ExecuteNonQuery(params.Format("insert into table({0}) values({1})"), params);

dataHelper.ExecuteNonQuery(params.Format("update table set {0}"), params);

BaseModel 數據模型基類,所有的數據模型都是繼承這個類,如TB_BUY_BILL.cs

using System;
using FaibClass.Data;

namespace WindowsApplication1
{
    /// <summary>
    /// 模型類
    /// </summary>
    [Serializable]
    public class TB_BUY_BILL : BaseModel
    {
        #region 表映射
        /// <summary>
        /// 表名稱
        /// </summary>
        public override string TableName
        {
            get { return "TB_BUY_BILL"; }
        }
        /// <summary>
        /// 表名稱
        /// </summary>
        public static string _TableName = "TB_BUY_BILL";
        /// <summary>
        /// 主鍵
        /// </summary>
        public override string PrimaryKey
        {
            get { return "BUY_BILL_ID"; }
        }
        /// <summary>
        /// 主鍵
        /// </summary>
        public static string _PrimaryKey = "BUY_BILL_ID";

        public override DataColumn GetDataColumn(string ColumnName)
        {
            DataColumn column = new DataColumn();
            switch (ColumnName)
            {

                case "BUY_BILL_ID":
                    column.ColumnName = "BUY_BILL_ID";
                    column.ColumnSize = 200;
                    column.DbType = 16;
                    column.IsPrimaryKey = true;
                    column.Precision = 0;
                    column.Scale = 0;
                    return column;

                case "BILL_TYPE":
                    column.ColumnName = "BILL_TYPE";
                    column.ColumnSize = 0;
                    column.DbType = 10;
                    column.IsPrimaryKey = false;
                    column.Precision = 0;
                    column.Scale = 0;
                    return column;

                case "BILL_NO":
                    column.ColumnName = "BILL_NO";
                    column.ColumnSize = 200;
                    column.DbType = 16;
                    column.IsPrimaryKey = false;
                    column.Precision = 0;
                    column.Scale = 0;
                    return column;

                case "DEPARTMENT_NAME":
                    column.ColumnName = "DEPARTMENT_NAME";
                    column.ColumnSize = 200;
                    column.DbType = 16;
                    column.IsPrimaryKey = false;
                    column.Precision = 0;
                    column.Scale = 0;
                    return column;

                case "SALED_AMOUNT":
                    column.ColumnName = "DEPARTMENT_NAME";
                    column.ColumnSize = 0;
                    column.DbType = 11;
                    column.IsPrimaryKey = false;
                    column.Precision = 0;
                    column.Scale = 0;
                    return column;

                case "CONTRACT_AMOUNT":
                    column.ColumnName = "CONTRACT_AMOUNT";
                    column.ColumnSize = 0;
                    column.DbType = 11;
                    column.IsPrimaryKey = false;
                    column.Precision = 0;
                    column.Scale = 0;
                    return column;

            }
            return null;
        }
        #endregion

        #region 字段常量

        public static string _BUY_BILL_ID = "BUY_BILL_ID";
        public static string _BILL_NO = "BILL_NO";
        public static string _BILL_TYPE = "BILL_TYPE";
        public static string _DEPARTMENT_NAME = "DEPARTMENT_NAME";
        public static string _SALED_AMOUNT = "SALED_AMOUNT";
        public static string _CONTRACT_AMOUNT = "CONTRACT_AMOUNT";
        #endregion

        #region 成員

        private string m_BUY_BILL_ID;
        private BILL_TYPE m_BILL_TYPE;
        private string m_BILL_NO;
        private string m_DEPARTMENT_NAME;
        private decimal m_SALED_AMOUNT;
        private decimal m_CONTRACT_AMOUNT;
        #endregion

        #region 屬性

        public string BUY_BILL_ID
        {
            get { return m_BUY_BILL_ID; }
            set { m_BUY_BILL_ID = value; }
        }

        public BILL_TYPE BILL_TYPE
        {
            get { return m_BILL_TYPE; }
            set { m_BILL_TYPE = value; }
        }

        public string BILL_NO
        {
            get { return m_BILL_NO; }
            set { m_BILL_NO = value; }
        }

        public string DEPARTMENT_NAME
        {
            get { return m_DEPARTMENT_NAME; }
            set { m_DEPARTMENT_NAME = value; }
        }

        public decimal SALED_AMOUNT
        {
            get { return m_SALED_AMOUNT; }
            set { m_SALED_AMOUNT = value; }
        }

        public decimal CONTRACT_AMOUNT
        {
            get { return m_CONTRACT_AMOUNT; }
            set { m_CONTRACT_AMOUNT = value; }
        }

        #endregion
    }

    public enum BILL_TYPE
    {
        [EnumText("電子")]
        ELE = 0,
        [EnumText("手工")]
        MAN = 1,
    }

    public enum BILL_STATE
    {
        [EnumText("暫存")]
        NoSave = 0,
        [EnumText("已保存")]
        Saved = 1,
    }

    /// <summary>
    /// 集合類
    /// </summary>
    [Serializable]
    public class TB_BUY_BILLs : DataModelList<TB_BUY_BILL>
    {
    }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved