Информационная система мебельного магазина

Тип работы:
Курсовая
Предмет:
Программирование


Узнать стоимость

Детальная информация о работе

Выдержка из работы

Министерство образования и науки Российской Федерации

Белгородский государственный технологический университет имени В.Г. Шухова

Институт ИТУС

Кафедра Информационных технологий

Курсовая работа

по информационным технологиям

на тему:

Информационная система мебельного магазина

Выполнил студент группы ИТ-31

Коденцев Александр Георгиевич

Проверил проф. Иванов И. В.

Белгород 2012

Содержание

  • 1. Постановка задачи и определение основных требований к разрабатываемому программному обеспечению
    • 1.1 Введение
    • 1.2 Основание для разработки
    • 1.3 Назначение программного средства
    • 1.4 Постановка задачи
    • 1.5 Требования к программному средству
      • 1.5.1 Требования к функциональным характеристикам
      • 1.5.2 Требования к надежности
      • 1.5.3 Требования к составу и параметрам технических средств
      • 1.5.4 Требования к информационно-программной совместимости
  • 2. Требования к программной документации
    • 2.1 Состав программной документации
  • 3. Проектирование базы данных и программная реализация
    • 3.1 Разработка структуры базы данных
    • 3.2 Структура таблиц
    • 3.3 Разработка модульной структуры программы
  • Заключение
  • Список литературы
  • Приложение 1. Содержание файла SCRIPT. SQL
  • Приложение 2. Исходный код программы
  • Приложение 3. Руководство пользователя

1. Постановка задачи и определение основных требований к разрабатываемому программному обеспечению

1.1 Введение

Цель данной работы: создание базы данных для предметной области, и разработка соответствующего клиентского приложения.

1.2 Основание для разработки

Программа разрабатывается на основе учебного плана кафедры «Информационные системы и технологии» по дисциплине «Информационные технологии».

1.3 Назначение программного средства

Данная программа предназначена для управления мебельным магазином. Управление программой возможно любым количеством лиц, для каждого из которых можно настроить права доступа.

Программа позволяет:

1. Хранить товары магазина

2. Разграничивать доступ к функционалу

3. Управлять заказами.

1.4 Постановка задачи

Реализовать следующий функционал:

1. Хранить товары магазина:

· Просмотр списка товаров

· Поиск по названию

· Редактирование товара

· Загрузка изображений

· Присвоение материалов для товаров

· Структурирование по каталогам

2. Разграничивать доступ к функционалу:

· Возможность создания групп пользователей.

· Возможность настройки прав доступа для различных групп пользователей

· Возможность добавления новых пользователей

· Возможность редактирования групп пользователей, и сами пользователей

3. Управлять заказами:

· Просмотр заказов

· Редактирование заказа

· Редактирование позиции заказа

1.5 Требования к программному средству

1.5.1 Требования к функциональным характеристикам

Возможность добавление, изменения, удаления записей.

· Невозможность изменения определенных полей.

· Удобный графический интерфейс клиентского приложения.

· Наглядное представление данных (в виде диаграмм графиков).

· Аутентификация пользователя

1.5.2 Требования к надежности

· Предусмотреть контроль вводимой информации.

· Предусмотреть ограничение изменения системных полей.

· Обеспечить ссылочную целостность.

1.5.3 Требования к составу и параметрам технических средств

Минимальная конфигурация:

· Объем оперативной памяти 22 Мб и более.

· Не менее 1 Мб свободного места на диске

· Мышь

· Клавиатура

1.5.4 Требования к информационно-программной совместимости

Программа должна работать под управлением операционной системы семейства Windows 9x и Windows NT. На сервере должно быть установлено серверное приложение Firebird версии 2.5 и InterBase 6.0.

2. Требования к программной документации

2.1 Состав программной документации

Состав программной документации должен включать в себя:

· Техническое задание

· Схема данных

· Код программы

· Руководство пользователя

3. Проектирование базы данных и программная реализация

3.1 Разработка структуры базы данных

Рис. 1 Схема данных

3.2 Структура таблиц:

Рис. 2 Структура таблицы «GOODS»

Рис. 3 Структура таблицы «MAT»

Рис. 4 Структура таблицы «USERS»

Рис. 5 Структура таблицы «USER_TYPE»

Рис. 6 Структура таблицы «CATALOGS»

Рис. 7 Структура таблицы «SALES»

Рис. 8 Структура таблицы «GOOD_SALES»

3.3 Разработка модульной структуры программы

Рис. 9 Модульная структура программы

Заключение

В результате выполнения данной курсовой работы была разработана база данных для информационной системы мебельного магазина, создано клиентское приложение для работы с этой базой данных. По проделанной работе составлен отчет с 3 приложениями:

· Исходный SQL-скрипт базы данных;

· Исходный код программы клиентского приложения (На языке Object Pascal);

· Руководство пользователя.

Список литературы

Шаптала В.В. «Управление данными. Лабораторный практикум для специальности 71 900» — Белгород, 2005

Информационные технологии: Учеб. для вузов / Б. Я. Советов, В. В. Цехановский. — 2-е изд., стер.- М.: Высш. шк., 2005. -263 с.: ил.

Кренке Д. Теория и практика построения баз данных. 9-е изд. — СПб.: Питер, 2005 — 859 с.: ил.

Приложение 1

Содержание файла SCRIPT. SQL

/*************************************************************

*****************/

/*** Generated by IBExpert 2012. 11. 26.1 28. 01. 2013 4: 45:38 ***/

/*************************************************************

*****************/

SET SQL DIALECT 3;

SET NAMES WIN1251;

CREATE DATABASE 'D: IT_Kursdb. fdb'

USER 'SYSDBA' PASSWORD 'masterkey'

PAGE_SIZE 16 384

DEFAULT CHARACTER SET WIN1251 COLLATION WIN1251;

/*************************************************************

*****************/

/*** Generators ***/

/*************************************************************

*****************/

CREATE GENERATOR GEN_CATALOGS_ID;

SET GENERATOR GEN_CATALOGS_ID TO 6;

CREATE GENERATOR GEN_COMPLECT_ID;

SET GENERATOR GEN_COMPLECT_ID TO 0;

CREATE GENERATOR GEN_GOODS_ID;

SET GENERATOR GEN_GOODS_ID TO 28;

CREATE GENERATOR GEN_GOOD_SALES_ID;

SET GENERATOR GEN_GOOD_SALES_ID TO 37;

CREATE GENERATOR GEN_MAT_ID;

SET GENERATOR GEN_MAT_ID TO 22;

CREATE GENERATOR GEN_MODEL_ROW_ID;

SET GENERATOR GEN_MODEL_ROW_ID TO 0;

CREATE GENERATOR GEN_MODULE_ID;

SET GENERATOR GEN_MODULE_ID TO 0;

CREATE GENERATOR GEN_MOD_IN_COMP_ID;

SET GENERATOR GEN_MOD_IN_COMP_ID TO 0;

CREATE GENERATOR GEN_MOD_IN_ROW_ID;

SET GENERATOR GEN_MOD_IN_ROW_ID TO 0;

CREATE GENERATOR GEN_MOD_SALES_ID;

SET GENERATOR GEN_MOD_SALES_ID TO 0;

CREATE GENERATOR GEN_SALES_ID;

SET GENERATOR GEN_SALES_ID TO 30;

CREATE GENERATOR GEN_USERS_ID;

SET GENERATOR GEN_USERS_ID TO 7;

CREATE GENERATOR GEN_USER_TYPE_ID;

SET GENERATOR GEN_USER_TYPE_ID TO 10;

/*************************************************************

*****************/

/*** Tables ***/

/*************************************************************

*****************/

CREATE TABLE CATALOGS (

ID INTEGER NOT NULL,

NAME VARCHAR (25) NOT NULL,

PARENT INTEGER DEFAULT 0 NOT NULL

);

CREATE TABLE COMPLECT (

ID INTEGER NOT NULL,

NAME VARCHAR (15) NOT NULL

);

CREATE TABLE GOOD_SALES (

ID INTEGER NOT NULL,

ID_SALES INTEGER NOT NULL,

ID_GOOD INTEGER NOT NULL,

CNT INTEGER DEFAULT 1 NOT NULL

);

CREATE TABLE GOODS (

ID INTEGER NOT NULL,

NAME VARCHAR (50) NOT NULL,

DESCR VARCHAR (1000),

S INTEGER,

V INTEGER,

G INTEGER,

MAT INTEGER,

PRICE INTEGER NOT NULL,

CNT INTEGER DEFAULT 1 NOT NULL,

MIN_PRICE INTEGER NOT NULL,

IMG VARCHAR (30),

CAT INTEGER NOT NULL

);

CREATE TABLE MAT (

ID INTEGER NOT NULL,

NAME VARCHAR (20) NOT NULL,

MAT VARCHAR (20),

COLOR VARCHAR (20),

IMG VARCHAR (100)

);

CREATE TABLE MOD_IN_COMP (

ID INTEGER NOT NULL,

ID_MOD INTEGER NOT NULL,

ID_COMP INTEGER NOT NULL,

«COUNT» SMALLINT DEFAULT 1 NOT NULL

);

CREATE TABLE MOD_IN_ROW (

ID INTEGER NOT NULL,

ID_MOD INTEGER NOT NULL,

ID_ROW INTEGER NOT NULL

);

CREATE TABLE MOD_SALES (

ID INTEGER NOT NULL,

ID_SALES INTEGER NOT NULL,

ID_MOD INTEGER NOT NULL,

«COUNT» INTEGER DEFAULT 1 NOT NULL

);

CREATE TABLE MODEL_ROW (

ID INTEGER NOT NULL,

NAME VARCHAR (30) NOT NULL,

MAT INTEGER NOT NULL

);

CREATE TABLE MODULE (

ID INTEGER NOT NULL,

NAME VARCHAR (50) NOT NULL,

DESCR VARCHAR (1000),

S INTEGER,

V INTEGER,

G INTEGER,

PRICE INTEGER NOT NULL,

MIN_PRICE INTEGER,

«COUNT» INTEGER DEFAULT 1 NOT NULL,

PARENT INTEGER NOT NULL,

IMG VARCHAR (30),

CAT INTEGER NOT NULL

);

CREATE TABLE SALES (

ID INTEGER NOT NULL,

DAT TIMESTAMP NOT NULL,

SALER INTEGER NOT NULL

);

CREATE TABLE USER_TYPE (

ID INTEGER NOT NULL,

NAME VARCHAR (20) NOT NULL,

SELECT_GOODS SMALLINT DEFAULT 1,

SELECT_SALES SMALLINT DEFAULT 0,

EDIT_GOODS SMALLINT DEFAULT 0,

ADD_GOODS SMALLINT DEFAULT 0,

SUPER SMALLINT DEFAULT 0

);

CREATE TABLE USERS (

ID INTEGER NOT NULL,

FN VARCHAR (20) NOT NULL,

«LN» VARCHAR (20) NOT NULL,

PN VARCHAR (20),

«TYPE» INTEGER NOT NULL,

PASS VARCHAR (20) NOT NULL

);

/*************************************************************

*****************/

/*** Primary Keys ***/

/*************************************************************

*****************/

ALTER TABLE CATALOGS ADD CONSTRAINT PK_CATALOGS

PRIMARY KEY (ID);

ALTER TABLE COMPLECT ADD CONSTRAINT PK_COMPLECT

PRIMARY KEY (ID);

ALTER TABLE GOODS ADD CONSTRAINT PK_GOODS PRIMARY

KEY (ID);

ALTER TABLE GOOD_SALES ADD CONSTRAINT PK_GOOD_SALES

PRIMARY KEY (ID);

ALTER TABLE MAT ADD CONSTRAINT PK_MAT PRIMARY KEY (ID);

ALTER TABLE MODEL_ROW ADD CONSTRAINT PK_MODEL_ROW PRIMARY KEY (ID);

ALTER TABLE MODULE ADD CONSTRAINT PK_MODULE PRIMARY KEY (ID);

ALTER TABLE MOD_IN_COMP ADD CONSTRAINT PK_MOD_IN_COMP PRIMARY KEY (ID);

ALTER TABLE MOD_IN_ROW ADD CONSTRAINT PK_MOD_IN_ROW PRIMARY KEY (ID);

ALTER TABLE MOD_SALES ADD CONSTRAINT PK_MOD_SALES PRIMARY KEY (ID);

ALTER TABLE SALES ADD CONSTRAINT PK_SALES PRIMARY KEY (ID);

ALTER TABLE USERS ADD CONSTRAINT PK_USERS PRIMARY KEY (ID);

ALTER TABLE USER_TYPE ADD CONSTRAINT PK_USER_TYPE PRIMARY KEY (ID);

/******************************************************************************/

/*** Foreign Keys ***/

/******************************************************************************/

ALTER TABLE CATALOGS ADD CONSTRAINT FK_CATALOGS1 FOREIGN KEY (PARENT) REFERENCES CATALOGS (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE GOODS ADD CONSTRAINT FK_GOODS1 FOREIGN KEY (MAT) REFERENCES MAT (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE GOODS ADD CONSTRAINT FK_GOODS2 FOREIGN KEY (CAT) REFERENCES CATALOGS (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE GOOD_SALES ADD CONSTRAINT FK_GOOD_SALES1 FOREIGN KEY (ID_SALES) REFERENCES SALES (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE GOOD_SALES ADD CONSTRAINT FK_GOOD_SALES2 FOREIGN KEY (ID_GOOD) REFERENCES GOODS (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MODEL_ROW ADD CONSTRAINT FK_MODEL_ROW1 FOREIGN KEY (MAT) REFERENCES MAT (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MODULE ADD CONSTRAINT FK_MODULE1 FOREIGN KEY (CAT) REFERENCES CATALOGS (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MODULE ADD CONSTRAINT FK_MODULE2 FOREIGN KEY (PARENT) REFERENCES MODEL_ROW (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MOD_IN_COMP ADD CONSTRAINT FK_MOD_IN_COMP1 FOREIGN KEY (ID_MOD) REFERENCES MODULE (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MOD_IN_COMP ADD CONSTRAINT FK_MOD_IN_COMP2 FOREIGN KEY (ID_COMP) REFERENCES COMPLECT (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MOD_IN_ROW ADD CONSTRAINT FK_MOD_IN_ROW1 FOREIGN KEY (ID_MOD) REFERENCES MODULE (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MOD_IN_ROW ADD CONSTRAINT FK_MOD_IN_ROW2 FOREIGN KEY (ID_ROW) REFERENCES MODEL_ROW (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MOD_SALES ADD CONSTRAINT FK_MOD_SALES1 FOREIGN KEY (ID_SALES) REFERENCES SALES (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE MOD_SALES ADD CONSTRAINT FK_MOD_SALES2 FOREIGN KEY (ID_MOD) REFERENCES MODULE (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE SALES ADD CONSTRAINT FK_SALES1 FOREIGN KEY (SALER) REFERENCES USERS (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE USERS ADD CONSTRAINT FK_USERS1 FOREIGN KEY («TYPE») REFERENCES USER_TYPE (ID) ON DELETE CASCADE ON UPDATE CASCADE;

/******************************************************************************/

/*** Triggers ***/

/******************************************************************************/

SET TERM ^;

/******************************************************************************/

/*** Triggers for tables ***/

/******************************************************************************/

/* Trigger: CATALOGS_BI */

CREATE TRIGGER CATALOGS_BI FOR CATALOGS

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_catalogs_id, 1);

end

^

/* Trigger: COMPLECT_BI */

CREATE TRIGGER COMPLECT_BI FOR COMPLECT

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_complect_id, 1);

end

^

/* Trigger: GOODS_BI */

CREATE TRIGGER GOODS_BI FOR GOODS

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_goods_id, 1);

end

^

/* Trigger: GOODS_BI_MIN */

CREATE TRIGGER GOODS_BI_MIN FOR GOODS

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. min_price is null) then

new. min_price = new. price;

end

^

/* Trigger: GOOD_SALES_BI */

CREATE TRIGGER GOOD_SALES_BI FOR GOOD_SALES

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_good_sales_id, 1);

end

^

/* Trigger: MAT_BI */

CREATE TRIGGER MAT_BI FOR MAT

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_mat_id, 1);

end

^

/* Trigger: MODEL_ROW_BI */

CREATE TRIGGER MODEL_ROW_BI FOR MODEL_ROW

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_model_row_id, 1);

end

^

/* Trigger: MODULE_BI */

CREATE TRIGGER MODULE_BI FOR MODULE

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_module_id, 1);

end

^

/* Trigger: MODULE_BI_MIN */

CREATE TRIGGER MODULE_BI_MIN FOR MODULE

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. min_price is null) then

new. min_price = new. price;

end

^

/* Trigger: MOD_IN_COMP_BI */

CREATE TRIGGER MOD_IN_COMP_BI FOR MOD_IN_COMP

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_mod_in_comp_id, 1);

end

^

/* Trigger: MOD_IN_ROW_BI */

CREATE TRIGGER MOD_IN_ROW_BI FOR MOD_IN_ROW

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_mod_in_row_id, 1);

end

^

/* Trigger: MOD_SALES_BI */

CREATE TRIGGER MOD_SALES_BI FOR MOD_SALES

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_mod_sales_id, 1);

end

^

/* Trigger: SALES_BI */

CREATE TRIGGER SALES_BI FOR SALES

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_sales_id, 1);

end

^

/* Trigger: USERS_BI */

CREATE TRIGGER USERS_BI FOR USERS

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_users_id, 1);

end

^

/* Trigger: USER_TYPE_BI */

CREATE TRIGGER USER_TYPE_BI FOR USER_TYPE

ACTIVE BEFORE INSERT POSITION 0

as

begin

if (new. id is null) then

new. id = gen_id (gen_user_type_id, 1);

end

^

SET TERM; ^

ПРИЛОЖЕНИЕ 2

Исходный код программы

Unit1

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, DB, IBDatabase, Grids, DBGrids, IBCustomDataSet, IBQuery,

ComCtrls,

Menus, StdCtrls, IdHashMessageDigest, ExtCtrls, TeEngine, TeeProcs,

Chart,

DBChart, Series;

type

TMainWnd = class (TForm)

IBDatabase1: TIBDatabase;

IBQuery1: TIBQuery;

IBTransaction1: TIBTransaction;

DataSource1: TDataSource;

catalog: TPageControl;

TabSheet1: TTabSheet;

Button1: TButton;

DBGrid1: TDBGrid;

Button2: TButton;

Button3: TButton;

TabSheet2: TTabSheet;

Edit1: TEdit;

Button4: TButton;

GroupBox1: TGroupBox;

Image1: TImage;

Label1: TLabel;

Memo1: TMemo;

Label2: TLabel;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Label8: TLabel;

Label9: TLabel;

Image2: TImage;

Label10: TLabel;

Label11: TLabel;

Label12: TLabel;

Label13: TLabel;

Button5: TButton;

Label14: TLabel;

Label15: TLabel;

Label16: TLabel;

Label17: TLabel;

Button6: TButton;

DBGrid2: TDBGrid;

GroupBox2: TGroupBox;

IBQuery2: TIBQuery;

DataSource2: TDataSource;

GroupBox3: TGroupBox;

DBGrid3: TDBGrid;

ComboBox1: TComboBox;

Label18: TLabel;

Label19: TLabel;

ComboBox2: TComboBox;

ComboBox3: TComboBox;

Label20: TLabel;

ComboBox4: TComboBox;

Label21: TLabel;

Label22: TLabel;

ComboBox5: TComboBox;

IBQuery3: TIBQuery;

DataSource3: TDataSource;

Label23: TLabel;

Edit2: TEdit;

Button7: TButton;

Button8: TButton;

Button9: TButton;

IBQuery4: TIBQuery;

Label24: TLabel;

Edit3: TEdit;

Edit4: TEdit;

Label25: TLabel;

Edit5: TEdit;

Label26: TLabel;

Label27: TLabel;

ComboBox6: TComboBox;

Button10: TButton;

Button11: TButton;

Button12: TButton;

Edit6: TEdit;

Label28: TLabel;

Button13: TButton;

Button14: TButton;

Button15: TButton;

Label29: TLabel;

Label30: TLabel;

Label31: TLabel;

Label32: TLabel;

TabSheet3: TTabSheet;

DBGrid4: TDBGrid;

GroupBox4: TGroupBox;

IBQuery5: TIBQuery;

IBQuery6: TIBQuery;

DataSource4: TDataSource;

DataSource5: TDataSource;

GroupBox5: TGroupBox;

DBGrid5: TDBGrid;

Button16: TButton;

Button17: TButton;

TabSheet4: TTabSheet;

Chart1: TChart;

IBQuery7: TIBQuery;

Series1: TBarSeries;

procedure FormCreate (Sender: TObject);

procedure FormCloseQuery (Sender: TObject; var CanClose: Boolean);

procedure Button3Click (Sender: TObject);

procedure Edit1Change (Sender: TObject);

procedure Button4Click (Sender: TObject);

procedure DBGrid1CellClick (Column: TColumn);

procedure Button5Click (Sender: TObject);

procedure UR;

procedure Button6Click (Sender: TObject);

procedure DBGrid3CellClick (Column: TColumn);

procedure Button9Click (Sender: TObject);

procedure Button7Click (Sender: TObject);

procedure Edit2Change (Sender: TObject);

procedure Button8Click (Sender: TObject);

procedure DBGrid2CellClick (Column: TColumn);

procedure Edit3Change (Sender: TObject);

procedure Edit4Change (Sender: TObject);

procedure Edit5Change (Sender: TObject);

procedure ComboBox6Change (Sender: TObject);

procedure Button10Click (Sender: TObject);

procedure Button11Click (Sender: TObject);

procedure Button12Click (Sender: TObject);

procedure Button13Click (Sender: TObject);

procedure Button14Click (Sender: TObject);

procedure Button2Click (Sender: TObject);

procedure Button15Click (Sender: TObject);

procedure DBGrid4CellClick (Column: TColumn);

procedure Button16Click (Sender: TObject);

procedure Button17Click (Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

type

BASC = record

ID: Integer;

CNT: byte;

PRICE: Integer;

end;

var

MainWnd: TMainWnd;

MODE: array [1. 5] of Boolean;

IDUSER: byte;

USERTYPES: array [0. 25] of byte;

MODENAME: string = 'Клиент';

USERNAME: string = 'Неавторизированный пользователь';

ADDFORMMODE: Integer = 0;

BASKET: array [0. 25] of BASC;

CNTBASK: byte = 0;

first: boolean;

implementation

uses Unit2, Unit3, Unit5, Unit6;

{$R *. dfm}

function md5(SourceString: string): string;

var

md5: TIdHashMessageDigest5;

begin

Result := '';

md5 := TIdHashMessageDigest5. Create;

try

Result := AnsiLowerCase (md5. HashStringAsHex (SourceString));

finally

FreeAndNil (md5);

end;

end;

procedure TMainWnd. UR;

var

i: byte;

tprice: Integer;

begin

MainWnd. Label15. Caption := Unit1. USERNAME;

MainWnd. Label17. Caption := Unit1. MODENAME;

MainWnd. DBGrid1. Refresh;

MainWnd. DBGrid2. Refresh;

MainWnd. DBGrid3. Refresh;

MainWnd. DBGrid4. Refresh;

MainWnd. DBGrid5. Refresh;

MainWnd. IBQuery5. Open;

//MainWnd. IBQuery6. Open;

MainWnd. IBQuery3. Open;

MainWnd. IBQuery2. Open;

//MainWnd. IBQuery1. Open;

tprice := 0;

for i := 0 to CNTBASK do

tprice := tprice + BASKET[i]. CNT * BASKET[i]. PRICE;

MainWnd. Label31. Caption := IntToStr (CNTBASK+1);

MainWnd. Label32. Caption := IntToStr (tprice) + ' р. ';

if MODE[5] then

begin

TabSheet2. TabVisible := true;

MainWnd. Button3. Visible:=true;

MainWnd. Button13. Visible:=true;

MainWnd. Button14. Visible:=true;

MainWnd. Button2. Visible:=true;

MainWnd. Button15. Visible:=true;

MainWnd. Label29. Visible:=true;

MainWnd. Label30. Visible:=true;

MainWnd. Label31. Visible:=true;

MainWnd. Label32. Visible:=true;

end

else begin

TabSheet2. TabVisible := false;

MainWnd. Button3. Visible:=false;

MainWnd. Button13. Visible:=false;

MainWnd. Button14. Visible:=false;

MainWnd. Button2. Visible:=false;

MainWnd. Button15. Visible:=false;

MainWnd. Label29. Visible:=false;

MainWnd. Label30. Visible:=false;

MainWnd. Label31. Visible:=false;

MainWnd. Label32. Visible:=false;

end;

if (MODE[5]) OR (MODE[2]) then begin

MainWnd. Button3. Visible:=true;

TabSheet3. TabVisible := true;

MainWnd. Button2. Visible:=true;

MainWnd. Button15. Visible:=true;

MainWnd. Label29. Visible:=true;

MainWnd. Label30. Visible:=true;

MainWnd. Label31. Visible:=true;

MainWnd. Label32. Visible:=true;

end

else begin

TabSheet3. TabVisible := false;

MainWnd. Button3. Visible:=false;

MainWnd. Button2. Visible:=false;

MainWnd. Button15. Visible:=false;

MainWnd. Label29. Visible:=false;

MainWnd. Label30. Visible:=false;

MainWnd. Label31. Visible:=false;

MainWnd. Label32. Visible:=false;

end;

if (MODE[5]) OR (MODE[2]) then begin

MainWnd. Button3. Visible:=true;

TabSheet4. TabVisible := true;

MainWnd. Button2. Visible:=true;

MainWnd. Button15. Visible:=true;

MainWnd. Label29. Visible:=true;

MainWnd. Label30. Visible:=true;

MainWnd. Label31. Visible:=true;

MainWnd. Label32. Visible:=true;

end

else begin

TabSheet4. TabVisible := false;

MainWnd. Button3. Visible:=false;

MainWnd. Button2. Visible:=false;

MainWnd. Button15. Visible:=false;

MainWnd. Label29. Visible:=false;

MainWnd. Label30. Visible:=false;

MainWnd. Label31. Visible:=false;

MainWnd. Label32. Visible:=false;

end;

if (MODE[5]) OR (MODE[3]) then begin

MainWnd. Button3. Visible:=true;

MainWnd. Button13. Visible:=true;

MainWnd. Button14. Visible:=true;

end

else begin

MainWnd. Button3. Visible:=false;

MainWnd. Button13. Visible:=false;

MainWnd. Button14. Visible:=false;

end;

end;

procedure TMainWnd. Button10Click (Sender: TObject);

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text := 'UPDATE USERS SET FN = ''' + Edit3. Text +

''', LN = ''' + Edit4. Text + ''', PN = ''' + Edit5. Text + ''', TYPE = ''' +

IntToStr (USERTYPES[ComboBox6. ItemIndex]) + ''', PASS = ''' +

Edit6. Text +

''' WHERE ID = ''' + DBGrid2. DataSource. DataSet. FieldByName ('ID')

. AsString + '''';

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid3. Refresh;

IBQuery3. Open;

DBGrid2. Refresh;

IBQuery2. Open;

Edit3. Text := '';

Edit4. Text := '';

Edit5. Text := '';

Edit6. Text := '';

end;

procedure TMainWnd. Button11Click (Sender: TObject);

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text: =

'INSERT INTO USERS (FN, LN, PN, TYPE, PASS) VALUES (''' + Edit3. Text

+ ''',''' + Edit4. Text + ''',''' + Edit5. Text + ''',''' + IntToStr

(USERTYPES[ComboBox6. ItemIndex]) + ''',''' + Edit6. Text + ''')';

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid3. Refresh;

IBQuery3. Open;

DBGrid2. Refresh;

IBQuery2. Open;

Edit3. Text := '';

Edit4. Text := '';

Edit5. Text := '';

Edit6. Text := '';

end;

procedure TMainWnd. Button12Click (Sender: TObject);

begin

if MessageBox (Handle, 'Удалить сотрудника?', 'Внимание', 35) = 6 then

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text: =

'DELETE FROM USERS WHERE ID = ' +

DBGrid2. DataSource. DataSet. FieldByName

('ID'). AsString;

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid3. Refresh;

IBQuery3. Open;

DBGrid2. Refresh;

IBQuery2. Open;

Edit3. Text := '';

Edit4. Text := '';

Edit5. Text := '';

Edit6. Text := '';

end;

end;

procedure TMainWnd. Button13Click (Sender: TObject);

begin

with AddGoods do

Begin

Image1. Picture. LoadFromFile (ExtractFilePath (Application. Exename)

+ MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('IMG'). AsString);

Image2. Picture. LoadFromFile (ExtractFilePath (Application. Exename)

+

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('MIMG'). AsString);

Edit1. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('NAME')

. AsString;

Edit6. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('PRICE')

. AsString;

Edit2. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('S'). AsString;

Edit3. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('V'). AsString;

Edit4. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('G'). AsString;

Memo1. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('DESCR')

. AsString;

Edit5. Text := MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('CNT')

. AsString;

Edit7. Text: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('MIN_PRICE')

. AsString;

TMPSTR: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('IMG'). AsString;

AddGoodTest[8] := true;

Image11. Picture. LoadFromFile ('images/icon/ok. jpg');

// Label13. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('CAT'). AsString;

End;

ADDFORMMODE: =

MainWnd. DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsInteger;

AddGoods. Button1. Caption := 'Сохранить';

AddGoods. ShowModal;

DBGrid1. Refresh;

IBQuery1. Open;

AddGoods. Button4Click (Sender);

end;

procedure TMainWnd. Button14Click (Sender: TObject);

begin

if MessageBox (Handle, 'Удалить товар?', 'Внимание', 35) = 6 then

begin

IBQuery2. SQL. Clear;

IBQuery2. SQL. Text: =

'DELETE FROM GOODS WHERE ID = ' +

DBGrid1. DataSource. DataSet. FieldByName

('ID'). AsString;

IBQuery2. Open;

MainWnd. IBTransaction1. Commit;

DBGrid1. Refresh;

IBQuery1. Open;

end;

end;

procedure TMainWnd. Button15Click (Sender: TObject);

var

SID, i: integer;

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text:='INSERT INTO SALES (DAT, SALER) VALUES ('''+

DateToStr (now)+''','''+IntToStr (IDUSER)+''')';

IBQuery4. Open;

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text:='SELECT MAX (ID) FROM SALES; ';

IBQuery4. Open;

SID:= IBQuery4. FieldByName ('MAX'). AsInteger;

for i := 0 to CNTBASK do

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text:='INSERT INTO

GOOD_SALES (ID_SALES, ID_GOOD, CNT) VALUES ('''+

IntToStr (SID)+''','''+IntToStr (BASKET[i]. ID)+''','''+

IntToStr (BASKET[i]. CNT)+''');';

IBQuery4. Open;

end;

CNTBASK: =0;

MainWnd. IBTransaction1. Commit;

DBGrid1. Refresh;

IBQuery1. Open;

UR;

end;

procedure TMainWnd. Button16Click (Sender: TObject);

begin

if MessageBox (Handle, 'Удалить заказ?', 'Внимание', 35) = 6 then

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text:= 'DELETE FROM SALES WHERE ID =

'+DBGrid4. DataSource. DataSet. FieldByName ('ID'). AsString;

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

UR;

end;

end;

procedure TMainWnd. Button17Click (Sender: TObject);

begin

if MessageBox (Handle, 'Удалить позицию заказа?', 'Внимание', 35) = 6

then

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text:= 'DELETE FROM GOOD_SALES WHERE ID =

'+DBGrid5. DataSource. DataSet. FieldByName ('ID'). AsString;

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid5. Refresh;

UR;

end;

end;

procedure TMainWnd. Button2Click (Sender: TObject);

var

i, too: byte;

flag: boolean;

begin

flag: =true;

for i := 0 to CNTBASK do

begin

if BASKET[i]. ID =

DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsInteger then

begin

BASKET[i]. CNT:= BASKET[i]. CNT+1;

flag: =false;

break;

end;

end;

if flag then

begin

if not first then

begin

CNTBASK: =CNTBASK+1;

end;

BASKET[CNTBASK]. ID:=

DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsInteger;

BASKET[CNTBASK]. CNT:= 1;

BASKET[CNTBASK]. PRICE:=

DBGrid1. DataSource. DataSet. FieldByName ('PRICE'). AsInteger;

if first then

begin

first:= false;

end;

end;

UR;

end;

procedure TMainWnd. Button3Click (Sender: TObject);

begin

ADDFORMMODE := 0;

AddGoods. Button1. Caption := 'Добавить';

AddGoods. ShowModal;

DBGrid1. Refresh;

IBQuery1. Open;

end;

procedure TMainWnd. Button4Click (Sender: TObject);

begin

with IBQuery1 do

begin

close;

SQL. Clear;

SQL. Add ('SELECT GOODS. ID, GOODS. NAME, DESCR, S, V, G, MAT. IMG

AS MIMG, PRICE,');

SQL. Add ('MAT. NAME AS MNAME, MAT. MAT AS MAT,');

SQL. Add ('CNT, GOODS. IMG, CATALOGS. NAME AS CAT FROM

GOODS, CATALOGS, MAT ');

SQL. Add ('WHERE GOODS. CAT = CATALOGS. ID AND MAT. ID =

GOODS. MAT ');

SQL. Add ('AND GOODS. NAME LIKE ''' + Edit1. Text + '''; ');

Open;

end;

end;

procedure TMainWnd. Button5Click (Sender: TObject);

begin

if Button5. Caption = 'Вход' then

begin

Login. ShowModal;

UR;

end else begin

MODE[1]: =true;

MODE[2]: =false;

MODE[3]: =false;

MODE[4]: =false;

MODE[5]: =false;

IDUSER: =0;

MODENAME:= 'Клиент';

USERNAME:= 'Неавторизированный пользователь';

Button5. Caption := 'Вход';

UR;

end;

end;

procedure TMainWnd. Button6Click (Sender: TObject);

begin

with AboutR do

begin

Label1. Caption := 'Права ' + Unit1. MODENAME + ' означают что вы: ';

if MODE[1] then

begin

Label2. Caption := 'Можете: ';

Image1. Picture. LoadFromFile ('imagesiconok. jpg');

end

else

begin

Label2. Caption := 'Не можете: ';

Image1. Picture. LoadFromFile ('imagesiconerr. jpg');

end;

if MODE[2] then

begin

Label3. Caption := 'Можете: ';

Image2. Picture. LoadFromFile ('imagesiconok. jpg');

end

else

begin

Label3. Caption := 'Не можете: ';

Image2. Picture. LoadFromFile ('imagesiconerr. jpg');

end;

if MODE[3] then

begin

Label4. Caption := 'Можете: ';

Image3. Picture. LoadFromFile ('imagesiconok. jpg');

end

else

begin

Label4. Caption := 'Не можете: ';

Image3. Picture. LoadFromFile ('imagesiconerr. jpg');

end;

if MODE[4] then

begin

Label5. Caption := 'Можете: ';

Image4. Picture. LoadFromFile ('imagesiconok. jpg');

end

else

begin

Label5. Caption := 'Не можете: ';

Image4. Picture. LoadFromFile ('imagesiconerr. jpg');

end;

if MODE[5] then

begin

Label6. Caption := 'Можете: ';

Image5. Picture. LoadFromFile ('imagesiconok. jpg');

end

else

begin

Label6. Caption := 'Не можете: ';

Image5. Picture. LoadFromFile ('imagesiconerr. jpg');

end;

ShowModal;

end;

end;

procedure TMainWnd. Button7Click (Sender: TObject);

var

t, i: byte;

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text: =

'INSERT INTO

USER_TYPE (NAME, SELECT_GOODS, SELECT_SALES, EDIT_GOODS

, ADD_GOODS'

+ ', SUPER) VALUES (''' + Edit2. Text + ''',''' + IntToStr

(1 — ComboBox1. ItemIndex) + ''',''' + IntToStr (1 — ComboBox2. ItemIndex)

+ ''',''' + IntToStr (1 — ComboBox3. ItemIndex) + ''',''' + IntToStr

(1 — ComboBox4. ItemIndex) + ''',''' + IntToStr (1 — ComboBox5. ItemIndex)

+ ''')';

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid3. Refresh;

IBQuery3. Open;

DBGrid2. Refresh;

IBQuery2. Open;

IBQuery3. Last;

t := IBQuery3. RecordCount;

IBQuery3. First;

ComboBox6. Clear;

for i := 0 to t — 1 do

begin

ComboBox6. Items. Add (IBQuery3. FieldByName ('NAME'). AsString);

USERTYPES[i] := IBQuery3. FieldByName ('ID'). AsInteger;

IBQuery3. Next;

end;

Edit2. Text := '';

end;

procedure TMainWnd. Button8Click (Sender: TObject);

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text := 'UPDATE USER_TYPE SET NAME = ''' +

Edit2. Text +

''', SELECT_GOODS = ''' + IntToStr (1 — ComboBox1. ItemIndex)

+ ''', SELECT_SALES = ''' + IntToStr (1 — ComboBox2. ItemIndex)

+ ''', EDIT_GOODS = ''' + IntToStr (1 — ComboBox3. ItemIndex)

+ ''', ADD_GOODS = ''' + IntToStr (1 — ComboBox4. ItemIndex)

+ ''', SUPER = ''' + IntToStr (1 — ComboBox5. ItemIndex)

+ ''' WHERE ID = ''' + DBGrid3. DataSource. DataSet. FieldByName ('ID')

. AsString + '''';

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid3. Refresh;

IBQuery3. Open;

DBGrid2. Refresh;

IBQuery2. Open;

Edit2. Text := '';

end;

procedure TMainWnd. Button9Click (Sender: TObject);

var

i, t: byte;

begin

if MessageBox (Handle, 'Удалить тип сотрудника?', 'Внимание', 35) = 6

then

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text: =

'DELETE FROM USER_TYPE WHERE ID = ' +

DBGrid3. DataSource. DataSet. FieldByName ('ID'). AsString;

IBQuery4. Open;

MainWnd. IBTransaction1. Commit;

DBGrid3. Refresh;

IBQuery3. Open;

DBGrid2. Refresh;

IBQuery2. Open;

IBQuery3. Last;

t := IBQuery3. RecordCount;

IBQuery3. First;

ComboBox6. Clear;

for i := 0 to t — 1 do

begin

ComboBox6. Items. Add (IBQuery3. FieldByName ('NAME'). AsString);

USERTYPES[i] := IBQuery3. FieldByName ('ID'). AsInteger;

IBQuery3. Next;

end;

Edit2. Text := '';

end;

end;

procedure TMainWnd. ComboBox6Change (Sender: TObject);

begin

if (Edit3. Text < > '') AND (Edit4. Text < > '') AND (Edit5. Text < > '') AND

(ComboBox6. ItemIndex < > -1) then

begin

Button10. Enabled := true;

Button11. Enabled := true;

end

else

begin

Button10. Enabled := false;

Button11. Enabled := false;

end;

end;

procedure TMainWnd. DBGrid1CellClick (Column: TColumn);

begin

GroupBox1. Visible := true;

Image1. Picture. LoadFromFile (ExtractFilePath (Application. Exename)

+ DBGrid1. DataSource. DataSet. FieldByName ('IMG'). AsString);

Image2. Picture. LoadFromFile (ExtractFilePath (Application. Exename)

+ DBGrid1. DataSource. DataSet. FieldByName ('MIMG'). AsString);

Label1. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('NAME'). AsString;

Label2. Caption := DBGrid1. DataSource. DataSet. FieldByName ('PRICE')

. AsString + 'р. ';

Label7. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('S'). AsString;

Label8. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('V'). AsString;

Label9. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('G'). AsString;

Memo1. Text: =

DBGrid1. DataSource. DataSet. FieldByName ('DESCR'). AsString;

Label10. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('MNAME'). AsString;

Label11. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('MAT'). AsString;

Label13. Caption: =

DBGrid1. DataSource. DataSet. FieldByName ('CAT'). AsString;

//

ShowMessage (DBGrid1. DataSource. DataSet. FieldByName ('MIMG'). AsStri

ng)

end;

procedure TMainWnd. DBGrid2CellClick (Column: TColumn);

var

i: byte;

begin

Edit3. Text := DBGrid2. DataSource. DataSet. FieldByName ('FN'). AsString;

Edit4. Text := DBGrid2. DataSource. DataSet. FieldByName ('LN'). AsString;

Edit5. Text := DBGrid2. DataSource. DataSet. FieldByName ('PN'). AsString;

Edit6. Text: =

DBGrid2. DataSource. DataSet. FieldByName ('PASS'). AsString;

for i := 0 to 25 do

if DBGrid2. DataSource. DataSet. FieldByName ('WTYPE'). AsInteger =

USERTYPES[i]

then

begin

ComboBox6. ItemIndex := i;

end;

end;

procedure TMainWnd. DBGrid3CellClick (Column: TColumn);

begin

Edit2. Text: =

DBGrid3. DataSource. DataSet. FieldByName ('NAME'). AsString;

ComboBox1. ItemIndex := 1 — DBGrid3. DataSource. DataSet. FieldByName

('SELECT_GOODS'). AsInteger;

ComboBox2. ItemIndex := 1 — DBGrid3. DataSource. DataSet. FieldByName

('SELECT_SALES'). AsInteger;

ComboBox3. ItemIndex := 1 — DBGrid3. DataSource. DataSet. FieldByName

('EDIT_GOODS'). AsInteger;

ComboBox4. ItemIndex := 1 —

DBGrid3. DataSource. DataSet. FieldByName ('ADD_GOODS')

. AsInteger;

ComboBox5. ItemIndex := 1 —

DBGrid3. DataSource. DataSet. FieldByName ('SUPER')

. AsInteger;

end;

procedure TMainWnd. DBGrid4CellClick (Column: TColumn);

begin

with IBQuery6 do

begin

SQL. Clear;

SQL. Add ('SELECT GOOD_SALES. ID, GOODS. NAME AS GOOD,

GOOD_SALES. CNT '+

', GOODS. PRICE*GOOD_SALES. CNT AS SUMM'+

' FROM GOOD_SALES, GOODS'+

' WHERE GOOD_SALES. ID_GOOD = GOODS. ID AND ID_SALES='+

DBGrid4. DataSource. DataSet. FieldByName ('ID'). AsString+';');

Open;

end;

end;

procedure TMainWnd. Edit1Change (Sender: TObject);

begin

if Edit1. Text < > '' then

begin

Button4. Enabled := true;

with IBQuery1 do

begin

close;

SQL. Clear;

SQL. Add ('SELECT GOODS. ID, GOODS. NAME, DESCR, S, V, G, MAT. IMG

AS MIMG, PRICE,');

SQL. Add ('MAT. NAME AS MNAME, MAT. MAT AS MAT,');

SQL. Add ('CNT, GOODS. IMG, CATALOGS. NAME AS CAT FROM

GOODS, CATALOGS, MAT ');

SQL. Add ('WHERE GOODS. CAT = CATALOGS. ID AND MAT. ID =

GOODS. MAT ');

SQL. Add ('AND GOODS. NAME LIKE ''' + Edit1. Text + '''; ');

Open;

end;

end

else

Button4. Enabled := false;

end;

procedure TMainWnd. Edit2Change (Sender: TObject);

begin

if Edit2. Text < > '' then

begin

Button7. Enabled := true;

Button8. Enabled := true;

end

else

begin

Button7. Enabled := false;

Button8. Enabled := false;

end

end;

procedure TMainWnd. Edit3Change (Sender: TObject);

begin

if (Edit3. Text < > '') AND (Edit4. Text < > '') AND (Edit5. Text < > '') AND

(ComboBox6. ItemIndex < > -1) then

begin

Button10. Enabled := true;

Button11. Enabled := true;

end

else

begin

Button10. Enabled := false;

Button11. Enabled := false;

end;

end;

procedure TMainWnd. Edit4Change (Sender: TObject);

begin

if (Edit3. Text < > '') AND (Edit4. Text < > '') AND (Edit5. Text < > '') AND

(ComboBox6. ItemIndex < > -1) then

begin

Button10. Enabled := true;

Button11. Enabled := true;

end

else

begin

Button10. Enabled := false;

Button11. Enabled := false;

end;

end;

procedure TMainWnd. Edit5Change (Sender: TObject);

begin

if (Edit3. Text < > '') AND (Edit4. Text < > '') AND (Edit5. Text < > '') AND

(ComboBox6. ItemIndex < > -1) then

begin

Button10. Enabled := true;

Button11. Enabled := true;

end

else

begin

Button10. Enabled := false;

Button11. Enabled := false;

end;

end;

procedure TMainWnd. FormCloseQuery (Sender: TObject; var CanClose:

Boolean);

begin

IBQuery1. close;

IBDatabase1. Connected := false;

end;

procedure TMainWnd. FormCreate (Sender: TObject);

var

i, t: byte;

begin

IBDatabase1. DatabaseName := 'db. FDB';

IBDatabase1. Connected := true;

MODE[1] := true;

MODE[2] := false;

MODE[3] := false;

MODE[4] := false;

MODE[5] := false;

IDUSER: =1;

first: =true;

with IBQuery1 do

begin

SQL. Add ('SELECT GOODS. ID, GOODS. NAME, DESCR, S, V, G, MAT. IMG

AS MIMG, PRICE,');

SQL. Add ('MAT. NAME AS MNAME, MAT. MAT AS MAT,');

SQL. Add (

'CNT, GOODS. IMG, CATALOGS. NAME AS CAT, MIN_PRICE FROM

GOODS, CATALOGS, MAT ');

SQL. Add ('WHERE GOODS. CAT = CATALOGS. ID AND MAT. ID =

GOODS. MAT');

Open;

end;

база данный информационный мебельный

with IBQuery2 do

begin

SQL. Add (

'SELECT USERS. ID, FN, LN, PN, USER_TYPE. NAME AS TYPE, TYPE AS

WTYPE, PASS FROM USERS,'

+ 'USER_TYPE WHERE USERS. TYPE = USER_TYPE. ID;');

Open;

end;

with IBQuery3 do

begin

SQL. Add ('SELECT * FROM USER_TYPE; ');

Open;

end;

IBQuery3. Last;

t := IBQuery3. RecordCount;

IBQuery3. First;

for i := 0 to t — 1 do

begin

ComboBox6. Items. Add (IBQuery3. FieldByName ('NAME'). AsString);

USERTYPES[i] := IBQuery3. FieldByName ('ID'). AsInteger;

IBQuery3. Next;

end;

with IBQuery5 do

begin

SQL. Add ('SELECT SALES. ID, DAT, USERS. FN AS SLR FROM

SALES, USERS '+

'WHERE USERS. ID = SALES. SALER;');

Open;

end;

with IBQuery7 do

begin

SQL. Add ('SELECT PRICE, NAME FROM GOODS ORDER BY PRICE

DESC');

Open;

end;

IBQuery7. Last;

t := IBQuery7. RecordCount;

IBQuery7. First;

for i := 0 to t — 1 do

begin

Chart1. Series[0]. Add (IBQuery7. FieldByName ('PRICE'). AsInteger,

IBQuery7. FieldByName ('NAME'). AsString, clBlue);

IBQuery7. Next;

end;

UR;

end;

end.

Unit2

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ComCtrls, ExtCtrls, jpeg, ExtDlgs, IdHashMessageDigest,

DB,

IBCustomDataSet, IBQuery, Grids, DBGrids, Menus;

type

TAddGoods = class (TForm)

Button3: TButton;

OpenPictureDialog1: TOpenPictureDialog;

IBQuery1: TIBQuery;

IBQuery2: TIBQuery;

IBQuery3: TIBQuery;

DataSource1: TDataSource;

DataSource2: TDataSource;

PageControl1: TPageControl;

TabSheet1: TTabSheet;

Image12: TImage;

Image13: TImage;

Image14: TImage;

Label13: TLabel;

Label14: TLabel;

Label15: TLabel;

GroupBox1: TGroupBox;

Label5: TLabel;

Label6: TLabel;

Image3: TImage;

Image4: TImage;

Edit1: TEdit;

Memo1: TMemo;

GroupBox2: TGroupBox;

Label7: TLabel;

Label8: TLabel;

Label9: TLabel;

Image5: TImage;

Image6: TImage;

Image7: TImage;

Edit2: TEdit;

Edit3: TEdit;

Edit4: TEdit;

GroupBox3: TGroupBox;

DBGrid1: TDBGrid;

Button7: TButton;

GroupBox4: TGroupBox;

Image1: TImage;

Image11: TImage;

Button8: TButton;

Button9: TButton;

GroupBox5: TGroupBox;

Image2: TImage;

DBGrid2: TDBGrid;

Button10: TButton;

GroupBox6: TGroupBox;

Label10: TLabel;

Label11: TLabel;

Label12: TLabel;

Image8: TImage;

Image9: TImage;

Image10: TImage;

Edit5: TEdit;

Edit6: TEdit;

Edit7: TEdit;

Button1: TButton;

Button4: TButton;

PopupMenu1: TPopupMenu;

N1: TMenuItem;

N2: TMenuItem;

IBQuery4: TIBQuery;

procedure FormCreate (Sender: TObject);

procedure DBGrid2CellClick (Column: TColumn);

procedure Edit1Change (Sender: TObject);

procedure Memo1Change (Sender: TObject);

procedure Edit2Change (Sender: TObject);

procedure Edit3Change (Sender: TObject);

procedure Edit4Change (Sender: TObject);

procedure Edit5Change (Sender: TObject);

procedure Edit6Change (Sender: TObject);

procedure Edit7Change (Sender: TObject);

procedure Button4Click (Sender: TObject);

procedure Button8Click (Sender: TObject);

procedure Button9Click (Sender: TObject);

procedure Button1Click (Sender: TObject);

procedure Button7Click (Sender: TObject);

procedure Button10Click (Sender: TObject);

procedure N2Click (Sender: TObject);

procedure N1Click (Sender: TObject);

procedure Button3Click (Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

AddGoods: TAddGoods;

TMPSTR: string;

AddGoodTest: array [0. 8] of boolean = (

false,

false,

false,

false,

false,

false,

false,

false,

false

);

implementation

{$R *. dfm}

uses Unit1, Unit3, Unit4;

function md5(SourceString: string): string;

var

md5: TIdHashMessageDigest5;

begin

Result := '';

md5 := TIdHashMessageDigest5. Create;

try

Result := AnsiLowerCase (md5. HashStringAsHex (SourceString));

finally

FreeAndNil (md5);

end;

end;

procedure TAddGoods. Button10Click (Sender: TObject);

begin

AddMat. ShowModal;

DBGrid1. Refresh;

IBQuery2. Open;

DBGrid2. Refresh;

IBQuery3. Open;

end;

procedure TAddGoods. Button1Click (Sender: TObject);

var

i: integer;

flag: boolean;

SQL, IMG, TMP: string;

begin

flag := true;

for i := 0 to 8 do

begin

if AddGoodTest[i] = false then

flag := false;

end;

if flag then

begin

if Unit1. ADDFORMMODE = 0 then

begin

TMP := md5(DateToStr (now) + TimeToStr (now));

SetLength (TMP, 10);

IMG := 'images' + TMP + '. jpg';

SQL: =

'INSERT INTO

GOODS (NAME, DESCR, S, V, G, MAT, PRICE, CNT, MIN_PRICE, IMG, CAT

) VALUES ('''

+ Edit1. Text + ''',''' + Memo1. Text + ''',''' + Edit2. Text +

''',''' + Edit3. Text + ''',''' + Edit4. Text + ''',''' +

DBGrid2. DataSource. DataSet. FieldByName ('ID')

. AsString + ''',''' + Edit6. Text + ''',''' + Edit5. Text +

''',''' + Edit7. Text + ''',''' + IMG + ''',''' +

DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsString + '''); ';

IBQuery1. SQL. Clear;

IBQuery1. SQL. Text := SQL;

IBQuery1. Open;

if NOT CopyFile (Pchar (TMPSTR), Pchar (IMG), false) then

ShowMessage ('Ошибка! Код ошибки: ' + IntToStr (GetLastError))

else

MainWND. IBTransaction1. Commit;

DBGrid1. Refresh;

IBQuery2. Open;

DBGrid2. Refresh;

IBQuery3. Open;

Button4Click (Sender);

AddGoods. Close;

end

else

begin

TMP := md5(DateToStr (now) + TimeToStr (now));

SetLength (TMP, 10);

IMG := 'images' + TMP + '. jpg';

SQL: =

'UPDATE GOODS SET'+

' NAME =''' + Edit1. Text +

''', DESCR =''' + Memo1. Text +

''', S =''' + Edit2. Text +

''', V =''' + Edit3. Text +

''', G =''' + Edit4. Text +

''', MAT =''' + DBGrid2. DataSource. DataSet. FieldByName ('ID'). AsString +

''', PRICE =''' + Edit6. Text +

''', CNT =''' + Edit5. Text +

''', MIN_PRICE =''' + Edit7. Text +

''', IMG =''' + IMG +

''', CAT =''' + DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsString +

''' WHERE ID = '+IntToStr (Unit1. ADDFORMMODE);

Memo1. Text := SQL+' '+TMPSTR;

IBQuery1. SQL. Clear;

IBQuery1. SQL. Text := SQL;

IBQuery1. Open;

if NOT CopyFile (Pchar (TMPSTR), Pchar (IMG), false) then

ShowMessage ('Ошибка! Код ошибки: ' + IntToStr (GetLastError))

else

MainWND. IBTransaction1. Commit;

Button4Click (Sender);

AddGoods. Close;

end;

DBGrid1. Refresh;

IBQuery2. Open;

DBGrid2. Refresh;

IBQuery3. Open;

end

else

ShowMessage ('Поля заполнены не верно. ');

end;

procedure TAddGoods. Button3Click (Sender: TObject);

begin

AddGoods. Close;

end;

procedure TAddGoods. Button4Click (Sender: TObject);

begin

Edit1. Text := '';

Edit2. Text := '';

Edit3. Text := '';

Edit4. Text := '';

Edit5. Text := '';

Edit6. Text := '';

Edit7. Text := '';

Memo1. Text := '';

TMPSTR := '';

Image3. Picture. LoadFromFile ('images/icon/note. jpg');

Image4. Picture. LoadFromFile ('images/icon/note. jpg');

Image5. Picture. LoadFromFile ('images/icon/note. jpg');

Image6. Picture. LoadFromFile ('images/icon/note. jpg');

Image7. Picture. LoadFromFile ('images/icon/note. jpg');

Image8. Picture. LoadFromFile ('images/icon/note. jpg');

Image9. Picture. LoadFromFile ('images/icon/note. jpg');

Image10. Picture. LoadFromFile ('images/icon/note. jpg');

Image11. Picture. LoadFromFile ('images/icon/note. jpg');

Image1. Picture := nil;

Image2. Picture := nil;

AddGoodTest[8] := false;

end;

procedure TAddGoods. Button7Click (Sender: TObject);

begin

AddCat. IBQuery1. SQL. Clear;

AddCat. IBQuery1. SQL. Text := 'SELECT ID, NAME, PARENT FROM

CATALOGS';

AddCat. IBQuery1. Open;

AddCat. ShowModal;

DBGrid1. Refresh;

IBQuery2. Open;

DBGrid2. Refresh;

IBQuery3. Open;

end;

procedure TAddGoods. Button8Click (Sender: TObject);

begin

if OpenPictureDialog1. Execute then

begin

Image1. Picture. LoadFromFile (OpenPictureDialog1. FileName);

TMPSTR := OpenPictureDialog1. FileName;

AddGoodTest[8] := true;

Image11. Picture. LoadFromFile ('images/icon/ok. jpg');

end;

end;

procedure TAddGoods. Button9Click (Sender: TObject);

begin

Image11. Picture. LoadFromFile ('images/icon/note. jpg');

TMPSTR := '';

AddGoodTest[8] := false;

Image1. Picture := nil;

end;

procedure TAddGoods. DBGrid2CellClick (Column: TColumn);

begin

Image2. Picture. LoadFromFile (DBGrid2. DataSource. DataSet. FieldByName ('

IMG')

. AsString);

end;

procedure TAddGoods. Edit1Change (Sender: TObject);

begin

if not (Edit1. Text = '') then

begin

Image3. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[0] := true;

end

else

begin

Image3. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[0] := false;

end

end;

procedure TAddGoods. Edit2Change (Sender: TObject);

var

t: integer;

begin

if not (Edit2. Text = '') AND TryStrToInt (Edit2. Text, t) AND

(StrToInt (Edit2. Text) > 0) AND (StrToInt (Edit2. Text) < 10 000) then

begin

Image5. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[2] := true;

end

else

begin

Image5. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[2] := false;

end;

end;

procedure TAddGoods. Edit3Change (Sender: TObject);

var

t: integer;

begin

if not (Edit3. Text = '') AND TryStrToInt (Edit3. Text, t) AND

(StrToInt (Edit3. Text) > 0) AND (StrToInt (Edit3. Text) < 10 000) then

begin

Image6. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[3] := true;

end

else

begin

Image6. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[3] := false;

end;

end;

procedure TAddGoods. Edit4Change (Sender: TObject);

var

t: integer;

begin

if not (Edit4. Text = '') AND TryStrToInt (Edit4. Text, t) AND

(StrToInt (Edit4. Text) > 0) AND (StrToInt (Edit4. Text) < 10 000) then

begin

Image7. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[4] := true;

end

else

begin

Image7. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[4] := false;

end;

end;

procedure TAddGoods. Edit5Change (Sender: TObject);

var

t: integer;

begin

if not (Edit5. Text = '') AND TryStrToInt (Edit5. Text, t) AND

(StrToInt (Edit5. Text) > 0) AND (StrToInt (Edit5. Text) < 10 000) then

begin

Image8. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[5] := true;

end

else

begin

Image8. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[5] := false;

end;

end;

procedure TAddGoods. Edit6Change (Sender: TObject);

var

t: integer;

begin

if not (Edit6. Text = '') AND TryStrToInt (Edit6. Text, t) AND

(StrToInt (Edit6. Text) > 0) AND (StrToInt (Edit6. Text) < 999 999) then

begin

Image9. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[6] := true;

if not (Edit7. Text = '') AND TryStrToInt (Edit7. Text, t) AND

(StrToInt (Edit7. Text) > 0) AND (StrToInt (Edit7. Text) < 999 999) then

if (StrToInt (Edit6. Text) >= StrToInt (Edit7. Text)) then

begin

Image10. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[7] := true;

end

else

begin

Image10. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[7] := false;

end;

end

else

begin

Image9. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[6] := false;

end;

end;

procedure TAddGoods. Edit7Change (Sender: TObject);

var

t: integer;

begin

if not (Edit7. Text = '') AND TryStrToInt (Edit7. Text, t) AND

(StrToInt (Edit7. Text) > 0) AND (StrToInt (Edit7. Text) < 999 999) AND not

(Edit6. Text = '') AND TryStrToInt (Edit6. Text, t) AND

(StrToInt (Edit6. Text) > 0) AND (StrToInt (Edit6. Text) < 999 999) AND

(StrToInt (Edit6. Text) >= StrToInt (Edit7. Text)) then

begin

Image10. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[7] := true;

end

else

begin

Image10. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[7] := false;

end;

end;

procedure TAddGoods. FormCreate (Sender: TObject);

begin

Memo1. Clear;

IBQuery2. SQL. Clear;

IBQuery2. SQL. Text := 'SELECT ID, NAME FROM CATALOGS';

IBQuery2. Open;

IBQuery3. SQL. Clear;

IBQuery3. SQL. Text := 'SELECT ID, NAME, MAT, COLOR, IMG FROM

MAT';

IBQuery3. Open;

Image2. Picture. LoadFromFile (DBGrid2. DataSource. DataSet. FieldByName ('

IMG')

. AsString);

end;

procedure TAddGoods. Memo1Change (Sender: TObject);

begin

if not (Memo1. Text = '') then

begin

Image4. Picture. LoadFromFile ('images/icon/ok. jpg');

AddGoodTest[1] := true;

end

else

begin

Image4. Picture. LoadFromFile ('images/icon/err. jpg');

AddGoodTest[1] := false;

end;

end;

procedure TAddGoods. N1Click (Sender: TObject);

begin

Unit4. AMMode: =

DBGrid2. DataSource. DataSet. FieldByName ('ID'). AsInteger;

AddMat. EditMatAddName. Text: =

DBGrid2. DataSource. DataSet. FieldByName ('NAME')

. AsString;

AddMat. EditMatAddMat. Text: =

DBGrid2. DataSource. DataSet. FieldByName ('MAT')

. AsString;

AddMat. EditMatAddColor. Text: =

DBGrid2. DataSource. DataSet. FieldByName ('COLOR')

. AsString;

AddMat. EditMatAddImg. Text: =

DBGrid2. DataSource. DataSet. FieldByName ('IMG')

. AsString;

AddMat. ImageAddMat. Picture. LoadFromFile

(DBGrid2. DataSource. DataSet. FieldByName ('IMG'). AsString);

AddMat. ShowModal;

DBGrid1. Refresh;

IBQuery2. Open;

DBGrid2. Refresh;

IBQuery3. Open;

end;

procedure TAddGoods. N2Click (Sender: TObject);

begin

if MessageBox (Handle, 'Удалить материал?', 'Внимание', 35) = 6 then

begin

IBQuery4. SQL. Clear;

IBQuery4. SQL. Text: =

'DELETE FROM MAT WHERE ID = ' +

DBGrid2. DataSource. DataSet. FieldByName

('ID'). AsString;

IBQuery4. Open;

MainWND. IBTransaction1. Commit;

DBGrid1. Refresh;

IBQuery2. Open;

DBGrid2. Refresh;

IBQuery3. Open;

end;

end;

end.

Unit3

unit Unit3;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids, DBGrids, DB, IBCustomDataSet, IBQuery, StdCtrls,

Menus;

type

TAddCat = class (TForm)

IBQuery1: TIBQuery;

DataSource1: TDataSource;

DBGrid1: TDBGrid;

Edit1: TEdit;

Button1: TButton;

Button2: TButton;

Button3: TButton;

IBQuery2: TIBQuery;

PopupMenu1: TPopupMenu;

HE1: TMenuItem;

N1: TMenuItem;

Button4: TButton;

Edit2: TEdit;

procedure Button2Click (Sender: TObject);

procedure Button1Click (Sender: TObject);

procedure N1Click (Sender: TObject);

procedure Edit1Change (Sender: TObject);

procedure DBGrid1CellClick (Column: TColumn);

procedure Edit2Change (Sender: TObject);

procedure Button4Click (Sender: TObject);

procedure Button3Click (Sender: TObject);

procedure FormCreate (Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

AddCat: TAddCat;

implementation

{$R *. dfm}

uses Unit1, Unit2;

procedure TAddCat. Button1Click (Sender: TObject);

begin

AddCat. Close;

end;

procedure TAddCat. Button2Click (Sender: TObject);

begin

IBQuery2. SQL. Clear;

IBQuery2. SQL. Text: =

'INSERT INTO CATALOGS (NAME, PARENT) VALUES (''' + Edit1. Text +

''',''' +

DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsString + ''')';

IBQuery2. Open;

MainWND. IBTransaction1. Commit;

DBGrid1. Refresh;

IBQuery1. Open;

Edit1. Text := '';

AddCat. Close;

end;

procedure TAddCat. Button3Click (Sender: TObject);

begin

IBQuery2. SQL. Clear;

IBQuery2. SQL. Text: =

'INSERT INTO CATALOGS (NAME, PARENT) VALUES (''' + Edit1. Text +

''',''' +

DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsString + ''')';

IBQuery2. Open;

MainWND. IBTransaction1. Commit;

MainWND. UR;

Edit1. Text := '';

end;

procedure TAddCat. Button4Click (Sender: TObject);

begin

IBQuery2. SQL. Clear;

IBQuery2. SQL. Text: ='UPDATE CATALOGS SET NAME =''' +

Edit2. Text +

''' WHERE ID = ''' + DBGrid1. DataSource. DataSet. FieldByName ('ID')

. AsString + '''; ';

IBQuery2. Open;

MainWND. IBTransaction1. Commit;

MainWND. UR;

Edit2. Text := '';

end;

procedure TAddCat. DBGrid1CellClick (Column: TColumn);

begin

Edit2. Text: =

DBGrid1. DataSource. DataSet. FieldByName ('NAME'). AsString;

end;

procedure TAddCat. Edit1Change (Sender: TObject);

begin

if Edit1. Text < > '' then

begin

Button2. Enabled := true;

Button3. Enabled := true

end

else begin

Button2. Enabled := false;

Button3. Enabled := False

end;

end;

procedure TAddCat. Edit2Change (Sender: TObject);

begin

if (Edit2. Text < > '') AND

(Edit2. Text < >

DBGrid1. DataSource. DataSet. FieldByName ('NAME'). AsString)

then

Button4. Enabled := true

else

Button4. Enabled := false;

end;

procedure TAddCat. FormCreate (Sender: TObject);

begin

end;

procedure TAddCat. N1Click (Sender: TObject);

begin

if MessageBox (Handle, 'Удалить каталог?', 'Внимание', 35) = 6 then

begin

IBQuery2. SQL. Clear;

IBQuery2. SQL. Text: =

'DELETE FROM CATALOGS WHERE ID = ' +

DBGrid1. DataSource. DataSet. FieldByName ('ID'). AsString;

ПоказатьСвернуть
Заполнить форму текущей работой