DBTable.cs

using System;
using System.Data;

namespace ProductManager
{
    static class DBTable
    {
        private static DataSet dataSet;
        private static DataTable worker, provider, product, productBuy, productSell, productIn, productOut;

        #region DBTable
        static DBTable()
        {
            dataSet = new DataSet("ProductSet");
            dataSet.Locale = System.Globalization.CultureInfo.InvariantCulture;

            worker = dataSet.Tables.Add("Worker");
            worker.AddRange("WorkerID", "WorkerName", "DepartmentName", "Sex", "Jiguan", "Minzu", "Xueli", "CardID", "Single", "Phone", "TEL", "Address");
            worker.Columns.Add("Birthday", typeof(DateTime));
            worker.Columns.Add("Age", typeof(byte));
            worker.Columns.Add("DataImage", typeof(byte[]));

            provider = dataSet.Tables.Add("Provider");
            provider.AddRange("ProviderID", "ProviderName", "Linkman", "Email", "Bank", "LinkPhone", "Fax", "Address", "BankAccount", "Memo");

            product = dataSet.Tables.Add("Product");
            product.AddRange("ProductID", "ProductName", "ProductType", "Unit", "Memo");
            product.Columns.Add("Number", typeof(int)).DefaultValue = 0;
            product.Columns.Add("BuyPrice", typeof(decimal)).DefaultValue = 0.00M;
            product.Columns.Add("SellPrice", typeof(decimal)).DefaultValue = 0.00M;

            productBuy = dataSet.Tables.Add("ProductBuy");
            productBuy.AddRange("BuyID", "ProductID", "ProviderID", "Unit", "WorkerID", "Memo");
            productBuy.Columns.Add("Price", typeof(decimal)).DefaultValue = 0.00M;
            productBuy.Columns.Add("Number", typeof(int)).DefaultValue = 0;
            productBuy.Columns.Add("Total", typeof(decimal)).Expression = "Price * Number";
            productBuy.Columns.Add("StartDate", typeof(DateTime));
            productBuy.Columns.Add("OverDate", typeof(DateTime));

            productSell = dataSet.Tables.Add("ProductSell");
            productSell.AddRange("SellID", "ProductID", "ClientID", "Unit", "WorkerID", "Memo");
            productSell.Columns.Add("Price", typeof(decimal)).DefaultValue = 0.00M;
            productSell.Columns.Add("Number", typeof(int)).DefaultValue = 0;
            productSell.Columns.Add("Total", typeof(decimal)).Expression = "Price * Number";
            productSell.Columns.Add("StartDate", typeof(DateTime));
            productSell.Columns.Add("OverDate", typeof(DateTime));

            productIn = dataSet.Tables.Add("ProductIn");
            productIn.AddRange("InID", "BuyID", "ProductID", "Type", "Unit", "WorkerID", "Memo");
            productIn.Columns.Add("Price", typeof(decimal)).DefaultValue = 0.00M;
            productIn.Columns.Add("Number", typeof(int)).DefaultValue = 0;
            productIn.Columns.Add("Total", typeof(decimal)).Expression = "Price * Number";
            productIn.Columns.Add("Date", typeof(DateTime));

            productOut = dataSet.Tables.Add("ProductOut");
            productOut.AddRange("OutID", "SellID", "ProductID", "Type", "Unit", "WorkerID", "Memo");
            productOut.Columns.Add("Price", typeof(decimal)).DefaultValue = 0.00M;
            productOut.Columns.Add("Number", typeof(int)).DefaultValue = 0;
            productOut.Columns.Add("Total", typeof(decimal)).Expression = "Price * Number";
            productOut.Columns.Add("Date", typeof(DateTime));

            worker.Constraints.Add("ID", worker.Columns["WorkerID"], true);
            provider.Constraints.Add("ID", provider.Columns["ProviderID"], true);
            provider.Constraints.Add("Name", provider.Columns["ProviderName"], false);
            product.Constraints.Add("ID", product.Columns["ProductID"], true);
            product.Constraints.Add("Name", product.Columns["ProductName"], false);
            productBuy.Constraints.Add("ID", productBuy.Columns["BuyID"], true);
            productSell.Constraints.Add("ID", productSell.Columns["SellID"], true);
            productIn.Constraints.Add("ID", productIn.Columns["InID"], true);
            productOut.Constraints.Add("ID", productOut.Columns["OutID"], true);
            dataSet.Relations.Add("In", product.Columns["ProductID"], productIn.Columns["ProductID"], true);
            dataSet.Relations.Add("Out", product.Columns["ProductID"], productOut.Columns["ProductID"], true);
        }
        #endregion

        #region Schema
        private static void AddRange(this DataTable dataTable, params string[] columns)
        {
            foreach (string name in columns)
            {
                dataTable.Columns.Add(name, typeof(string));
            }
        }
        #endregion

        #region Property
        public static DataTable Worker
        {
            get { return worker; }
        }

        public static DataTable Provider
        {
            get { return provider; }
        }

        public static DataTable Product
        {
            get { return product; }
        }

        public static DataTable ProductSell
        {
            get { return productSell; }
        }

        public static DataTable ProductBuy
        {
            get { return productBuy; }
        }

        public static DataTable ProductIn
        {
            get { return productIn; }
        }

        public static DataTable ProductOut
        {
            get { return productOut; }
        }
        #endregion
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值