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
}
}