Example #1
0
 /// <summary>
 /// Создание новой БД
 /// </summary>
 /// <param name="DBName">Название и путь к файлу новой создаваемой БД</param>
 public static void CreateNewDB(string DBName)
 {
     // 1. формирование строки запроса для создания таблиц БД
     string query = @"CREATE TABLE 'ProductTypes' (
                         'PKey'  integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                         'Name'   varchar(30) NOT NULL
                     );
                     CREATE TABLE 'ReferenceProducts' (
                         'PKey'  integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                         'Name'   varchar(30) NOT NULL
                     );
                     CREATE TABLE 'ReferenceUnits' (
                         'PKey'      integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                         'FullName'   varchar(20) NOT NULL,
                         'SmallName'  varchar(5) NOT NULL
                     );
                     CREATE TABLE 'ReferenceSigns' (
                         'PKey'  integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                         'Name'   varchar(30) NOT NULL
                     );
                     CREATE TABLE 'ReferenceMaterials' (
                         'MaterialCode'  integer PRIMARY KEY NOT NULL,
                         'Name'          varchar(50) NOT NULL,
                         'UnitType'      integer NOT NULL,
                         FOREIGN KEY (UnitType)
                             REFERENCES 'ReferenceUnits'('PKey')
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION
                     );
                     CREATE TABLE 'ReferenceStandarts' (
                         'ProductCode'      integer PRIMARY KEY NOT NULL,
                         'MaterialCode'     integer NOT NULL,
                         'ConsumptionRate'  real NOT NULL DEFAULT 0,
                         'RateOfWaste'      real NOT NULL DEFAULT 0,
                         FOREIGN KEY ('MaterialCode')
                             REFERENCES 'ReferenceMaterials'('MaterialCode')
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION
                     );
                     CREATE TABLE 'ProductNames' (
                         'ProductKey'   integer PRIMARY KEY NOT NULL,
                         'Name'         varchar(50) NOT NULL,
                         'Designation'  varchar(50) NOT NULL,
                         'ViewCode'     integer NOT NULL,
                         'TypeCode'     integer NOT NULL,
                         'SignCode'     integer NOT NULL,
                         FOREIGN KEY ('ProductKey')
                             REFERENCES 'ReferenceStandarts'('ProductCode')
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION,
                         FOREIGN KEY ('TypeCode')
                             REFERENCES 'ProductTypes'('PKey')
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION,
                         FOREIGN KEY ('ViewCode')
                             REFERENCES 'ReferenceProducts'('PKey')
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION,
                         FOREIGN KEY ('SignCode')
                             REFERENCES 'ReferenceSigns'('PKey')
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION
                     );
                     CREATE TABLE 'CompositionProducts' (
                         'RootCode'   integer NOT NULL,
                         'WhereCode'  integer NOT NULL,
                         'WhatCode'   integer NOT NULL,
                         'Count'      integer NOT NULL
                     );
                     CREATE TABLE 'PlanProducts' (
                         'ProductCode'  integer NOT NULL,
                         'PlanCount'    integer NOT NULL,
                         'Month'        integer NOT NULL,
                         'Year'         integer NOT NULL
                     );
                     CREATE TABLE 'ShopsReference' (
                         'ShopCode'       integer NOT NULL,
                         'Name'           varchar(50) NOT NULL,
                         'ProductionCode' integer NOT NULL
                     );
                     CREATE TABLE 'ProductionReference' (
                         'ProductionCode'   integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                         'Name'             varchar(50) NOT NULL
                     );";
     CreateComplexityTable(); // создание таблицы СНТИ (структуры)
     CreateComplexityShopTable(); // создание таблицы СНТИЦ (структуры)
     // 2. Создание БД
     dbf = new DatabaseLib.dbFacade(DBName);
     dbf.CreateDatabase(query);
 }
Example #2
0
 /// <summary>
 /// Подключение к БД
 /// </summary>
 /// <param name="dbname">Путь и название файла БД</param>
 public static void ConnectToDB(string dbname)
 {
     dbf = new DatabaseLib.dbFacade(dbname);
     bool resut = dbf.Open();
     if (resut == false)
         MessageBox.Show("Подключение не установлено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     else
         flag = true;
 }