Edit1->Visible = false;
Edit2->Visible = false;
UpDown1->Visible = false;
UpDown2->Visible = false;
Button3->Visible = false;
CGauge1->Visible = true;
while(!pFIBDataSet1->Eof)
{ pFIBDataSet1->GetFieldData(1,Ar);
if(AnsiString(Ar) == Edit4->Text)
pFIBDataSet1->GetFieldData(2,Ar);
Name = pFIBDatabase2->QueryValueAsStr("SELECT NAME FROM GOODS WHERE ARTICLE=" + AnsiString("'")+AnsiString(Ar)+"'",0);
D1 = VarToDateTime(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(3),i));
D2 = VarToDateTime(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(4),i));
BarSeries1->AddBar(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(5),i),Name+"("+AnsiString(Ar)+") "+D1.DateString()+"-"+D2.DateString(),clTeeColor);
pFIBDataSet1->Next();
CGauge1->Progress++;
i++;}
pFIBDataSet1->Active = false;
pFIBDatabase1->Close();
pFIBDatabase2->Close();
Button4->Enabled = true;
Button6->Enabled = true;
Edit3->Enabled = true;
Edit3->Text = "1";
Label6->Caption = IntToStr(Chart2->NumPages());
Edit1->Visible = true;
Edit2->Visible = true;
UpDown1->Visible = true;
UpDown2->Visible = true;
Button3->Visible = true;
CGauge1->Visible = false;
CGauge1->Progress = 0;}
Заголовочный файл модуля обработки “Test. h”:
#ifndef TestH
#define TestH
//
#include <Classes. hpp>
#include <Controls. hpp>
#include <StdCtrls. hpp>
#include <Forms. hpp>
#include "FIBDatabase. hpp"
#include "pFIBDatabase. hpp"
#include "FIBDataSet. hpp"
#include "pFIBDataSet. hpp"
#include <DB. hpp>
#include <DBGrids. hpp>
#include <Grids. hpp>
#include "FIBQuery. hpp"
#include "pFIBQuery. hpp"
#include <ComCtrls. hpp>
#include "CGAUGES. h"
#include <Chart. hpp>
#include <DbChart. hpp>
#include <ExtCtrls. hpp>
#include <Series. hpp>
#include <TeEngine. hpp>
#include <TeeProcs. hpp>
//
class TForm1 : public TForm
{__published: // IDE-managed Components
TpFIBDatabase *pFIBDatabase2;
TpFIBTransaction *pFIBTransaction2;
TpFIBDataSet *pFIBDataSet1;
TpFIBDataSet *pFIBDataSet2;
TButton *Button3;
TLabel *Label1;
TpFIBDataSet *pFIBDataSet3;
TpFIBDatabase *pFIBDatabase1;
TpFIBTransaction *pFIBTransaction1;
TLabel *Label2;
TGroupBox *GroupBox1;
TRadioButton *RadioButton1;
TRadioButton *RadioButton2;
TComboBox *ComboBox1;
TEdit *Edit1;
TDateTimePicker *DateTimePicker1;
TLabel *Label3;
TLabel *Label4;
TDateTimePicker *DateTimePicker2;
TUpDown *UpDown1;
TCGauge *CGauge1;
TLabel *Label5;
TButton *Button1;
TGroupBox *GroupBox2;
void __fastcall Button3Click(TObject *Sender);
void __fastcall RadioButton1Click(TObject *Sender);
void __fastcall RadioButton2Click(TObject *Sender);
void __fastcall ComboBox1Change(TObject *Sender);
void __fastcall DateTimePicker1Change(TObject *Sender);
void __fastcall DateTimePicker2Change(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
AnsiString Date1,Date2;
__fastcall TForm1(TComponent* Owner);};
//
extern PACKAGE TForm1 *Form1;
//
#endif
Файл реализации модуля обработки “Test. cpp”:
#include <vcl. h>
#pragma hdrstop
#include "Test. h"
//
#pragma package(smart_init)
#pragma link "FIBDatabase"
#pragma link "pFIBDatabase"
#pragma link "FIBDataSet"
#pragma link "pFIBDataSet"
#pragma link "FIBQuery"
#pragma link "pFIBQuery"
#pragma link "CGAUGES"
#pragma resource "*.dfm"
TForm1 *Form1;
//
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{}
void __fastcall TForm1::Button3Click(TObject *Sender)
{int locid, y,count1,count2,x;
char ar1[8], ar2[8];
TDateTime D1,D2;
/* y - кол-во дней в которые товары регистрировалисль в одном чеке
x - кол-во дней в которые товары продовались вместе
count1 - кол-во обработанных записей
count2 - общее кол-во записей
ar1 - артикул1
ar2 - артикул2
D1 - начальная дата
D2 - конечная дата */
pFIBDatabase1->Connected = true;
pFIBDatabase2->Connected = true;
pFIBDataSet1->Active = true;
//Выборка нужных записей из таблицы ASSOTIATION_2D
pFIBDataSet2->SQLs->SelectSQL->Clear();
pFIBDataSet2->SQLs->SelectSQL->Add("SELECT ARTICLE1,ARTICLE2,LOCID, COUNT(ID) FROM ASSOTIATIONS_2D WHERE SALESDATE >="+Date1+" AND SALESDATE <="+Date2+" GROUP BY ARTICLE1,ARTICLE2,LOCID ORDER BY ARTICLE1,ARTICLE2");
pFIBDataSet2->Active = true;
count1 = pFIBDataSet1->RecordCountFromSrv();
count2 = pFIBDataSet2->RecordCountFromSrv();
GroupBox2->Caption = "Обработка:";
Label1->Caption = IntToStr(count1);
Form1->Refresh();
Label5->Caption = Label5->Caption + IntToStr(count2);
CGauge1->MaxValue = count2;
CGauge1->Progress = count1;
Form1->Refresh();
//Поиск необработанной записи
if(!pFIBDataSet1->IsEmpty())
{ TLocateOptions Opts;
Opts. Clear();
Opts << loCaseInsensitive;
Variant locvalues[3];
pFIBDataSet1->Last();
pFIBDataSet1->GetFieldData(2,ar1);
pFIBDataSet1->GetFieldData(3,ar2);
pFIBDataSet1->GetFieldData(4,&locid);
locvalues[0] = Variant(ar1);
locvalues[1] = Variant(ar2);
locvalues[2] = Variant(locid);
if(pFIBDataSet2->Locate("ARTICLE1;ARTICLE2;LOCID",VarArrayOf(locvalues,2),Opts))
pFIBDataSet2->Next();
else {Application->MessageBox("Запись не найдена!","ОШИБКА!",MB_OK); Form1->Close();}}
//Обработка
while(!pFIBDataSet2->Eof)
{pFIBTransaction1->StartTransaction();
pFIBDataSet2->GetFieldData(1,ar1);
pFIBDataSet2->GetFieldData(2,ar2);
pFIBDataSet2->GetFieldData(3,&locid);
pFIBDataSet2->GetFieldData(4,&y);
pFIBDataSet3->SQLs->SelectSQL->Clear();
pFIBDataSet3->SQLs->SelectSQL->Add("SELECT COUNT(ID),MIN(INTERVAL),MAX(INTERVAL) FROM SMSADMPL WHERE GOOD_ARTICLE="+AnsiString("'")+AnsiString(ar1)+"'"+" AND LOCID="+"'"+IntToStr(locid)+"'"+" AND INTERVAL >="+Date1+"AND INTERVAL <="+Date2+" AND INTERVAL=ANY(SELECT INTERVAL FROM SMSADMPL WHERE GOOD_ARTICLE="+"'"+AnsiString(ar2)+"'"+"AND LOCID="+"'"+IntToStr(locid)+"'"+")");
pFIBDataSet3->Active = true;
pFIBDataSet3->GetFieldData(1,&x);
if(x) { D1 = VarToDateTime(pFIBDataSet3->RecordFieldValue(pFIBDataSet3->FieldByFieldNo(2),1));
D2 = VarToDateTime(pFIBDataSet3->RecordFieldValue(pFIBDataSet3->FieldByFieldNo(3),1)); }
else {//!!!!Для ошибочных данных!!!!
locid = 777;
D1 = StrToDate("07.07.2007");
D2 = StrToDate("07.07.2007");
x = y; }
pFIBDataSet3->Active = false;
pFIBDataSet1->Insert();
pFIBDataSet1->FieldByName("ARTICLE1")->AsString = ar1;
pFIBDataSet1->FieldByName("ARTICLE2")->AsString = ar2;
pFIBDataSet1->FieldByName("LOCID")->AsInteger = locid;
pFIBDataSet1->FieldByName("FIRSTDATE")->AsDateTime = D1;
pFIBDataSet1->FieldByName("LASTDATE")->AsDateTime = D2;
pFIBDataSet1->FieldByName("P1")->AsFloat = (100/float(x))*y;
pFIBDataSet1->Post();
pFIBTransaction1->CommitRetaining();
count1++;
CGauge1->Progress = count1;
Label1->Caption = IntToStr(count1);
Form1->Refresh();
pFIBDataSet2->Next();}
pFIBDatabase1->Connected = false;
pFIBDatabase2->Connected = false;
pFIBDataSet1->Active = false;
pFIBDataSet2->Active = false;
CGauge1->Progress = 0;
Label1->Caption = "";
Label5->Caption = "Всего записей:";}
//
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{ComboBox1->Enabled = true;
Edit1->Enabled = true;
UpDown1->Enabled = true;
DateTimePicker1->Enabled = false;
DateTimePicker2->Enabled = false;}
//
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{ComboBox1->Enabled = false;
Edit1->Enabled = false;
UpDown1->Enabled = false;
DateTimePicker1->Enabled = true;
DateTimePicker2->Enabled = true;}
//
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{switch(ComboBox1->ItemIndex)
{case 0: {Date1 = "'01.03." + Edit1->Text+"'";
Date2 = "'31.05." + Edit1->Text+"'";
break;}
case 1: {Date1 = "'01.06." + Edit1->Text+"'";
Date2 = "'31.08." + Edit1->Text+"'";
break;}
case 2: {Date1 = "'01.09." + Edit1->Text+"'";
Date2 = "'30.11." + Edit1->Text+"'";
break;}
case 3{Date1 = "'01.12." + IntToStr(StrToInt(Edit1->Text)-1)+"'";
Date2 = "'29.02." + Edit1->Text+"'";
break;} }}
void __fastcall TForm1::DateTimePicker1Change(TObject *Sender)
{ Date1 = "'"+DateToStr(DateTimePicker1->Date)+"'";}
//
void __fastcall TForm1::DateTimePicker2Change(TObject *Sender)
{ Date2 = "'"+DateToStr(DateTimePicker2->Date)+"'";}
//
void __fastcall TForm1::Button1Click(TObject *Sender)
{int count1;
if(Application->MessageBox("Все записи из тестовой таблицы будут удалены!\nВы уверены?","Подтверждение.",MB_OKCANCEL) == 1)
{ pFIBDatabase1->Connected = true;
pFIBDataSet1->Active = true;
GroupBox2->Caption = "Удаление:";
count1 = pFIBDataSet1->RecordCountFromSrv();
CGauge1->MaxValue = count1;
Label5->Caption = Label5->Caption + IntToStr(count1);
pFIBDataSet1->First();
pFIBTransaction1->StartTransaction();
while(!pFIBDataSet1->Eof)
{pFIBDataSet1->Delete();
CGauge1->Progress++;
Label1->Caption = IntToStr(CGauge1->Progress); }
Application->MessageBox("Все записи удалены.","Удаление.",MB_OK);
pFIBDatabase1->Execute("SET GENERATOR TEST_G TO 0;");
pFIBTransaction1->Commit();
pFIBDatabase1->Connected = false;
pFIBDataSet1->Active = false;
CGauge1->Progress = 0;
Label1->Caption = "";
Label5->Caption = "Всего записей:"; }}
//
Приложение В
(обязательное)
Листинг программы задачи 2
Заголовочный файл модуля визуализации “Visual.h”:
#ifndef VisualH
#define VisualH
//
#include <Classes. hpp>
#include <Controls. hpp>
#include <StdCtrls. hpp>
#include <Forms. hpp>
#include "FIBDatabase. hpp"
#include "FIBDataSet. hpp"
#include "pFIBDatabase. hpp"
#include "pFIBDataSet. hpp"
#include <Chart. hpp>
#include <ComCtrls. hpp>
#include <DB. hpp>
#include <ExtCtrls. hpp>
#include <TabNotBk. hpp>
#include <TeEngine. hpp>
#include <TeeProcs. hpp>
#include <Series. hpp>
#include "CGAUGES. h"
#include "Unit1.h"
#include "Oracle. hpp"
//
class TForm2 : public TForm
{__published: // IDE-managed Components
TpFIBDatabase *pFIBDatabase1;
TpFIBTransaction *pFIBTransaction1;
TpFIBDataSet *pFIBDataSet1;
TTabbedNotebook *TabbedNotebook1;
TChart *Chart1;
TBarSeries *Series1;
TpFIBTransaction *pFIBTransaction2;
TpFIBDatabase *pFIBDatabase2;
TGroupBox *GroupBox2;
TLabel *Label3;
TLabel *Label5;
TLabel *Label6;
TButton *Button4;
TButton *Button6;
TEdit *Edit3;
TGroupBox *GroupBox1;
TLabel *Label1;
TLabel *Label2;
TEdit *Edit1;
TUpDown *UpDown1;
TEdit *Edit2;
TUpDown *UpDown2;
TButton *Button1;
TButton *Button2;
TGroupBox *GroupBox3;
TLabel *Label4;
TEdit *Edit4;
TLabel *Label7;
TEdit *Edit5;
TCGauge *CGauge1;
TButton *Button3;
TBarSeries *Series2;
TLabel *Label8;
TChart *Chart2;
TBarSeries *BarSeries1;
TBarSeries *BarSeries2;
TLabel *Label9;
TGroupBox *GroupBox4;
TLabel *Label10;
TEdit *Edit6;
TButton *Button5;
TLabel *Label11;
TLabel *Label12;
TOracleSession *OracleSession1;
TOracleQuery *OracleQuery1;
TpFIBDatabase *pFIBDatabase3;
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button6Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
void __fastcall Edit3Exit(TObject *Sender);
void __fastcall Edit3KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall TabbedNotebook1Change(TObject *Sender, int NewTab,
bool &AllowChange);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Chart1AfterDraw(TObject *Sender);
void __fastcall Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall Edit2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall Chart2AfterDraw(TObject *Sender);
void __fastcall Series1Click(TChartSeries *Sender, int ValueIndex,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall Series2Click(TChartSeries *Sender, int ValueIndex,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall Button5Click(TObject *Sender);
void __fastcall Edit4KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
private: // User declarations
public: // User declarations
TChart *Chart;
AnsiString articul, data1,data2,location;
__fastcall TForm2(TComponent* Owner);};
//
extern PACKAGE TForm2 *Form2;
//
#endif
Файл реализации модуля визуализации “Visual.cpp”:
#include <vcl. h>
#pragma hdrstop
#include "Visual. h"
//
#pragma package(smart_init)
#pragma link "FIBDatabase"
#pragma link "FIBDataSet"
#pragma link "pFIBDatabase"
#pragma link "pFIBDataSet"
#pragma link "CGAUGES"
#pragma link "Oracle"
#pragma resource "*.dfm"
TForm2 *Form2;
//
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{Chart = Chart1;}
//
void __fastcall TForm2::Button2Click(TObject *Sender)
{ Form1->ShowModal();}
//
void __fastcall TForm2::Button1Click(TObject *Sender)
{ AnsiString Name1,Name2;
char Ar1[8],Ar2[8];
TDateTime D1,D2,MaxD, MinD;
int Loc;
pFIBDataSet1->Active = false;
pFIBDataSet1->SQLs->SelectSQL->Clear();
pFIBDataSet1->SQLs->SelectSQL->Add("SELECT ARTICLE1,ARTICLE2,LOCID, FIRSTDATE, LASTDATE, P2,P3 "
"FROM TEST "
"WHERE P4>="+Edit1->Text+" "
"AND P4<="+Edit2->Text+" "
"ORDER BY P4 DESC, ARTICLE1");
pFIBDatabase1->Open();
pFIBDatabase2->Open();
pFIBDataSet1->Active = true;
pFIBDataSet1->First();
MinD = VarToDateTime(pFIBDatabase1->QueryValue("SELECT MIN(FIRSTDATE) FROM TEST",0));
MaxD = VarToDateTime(pFIBDatabase1->QueryValue("SELECT MAX(LASTDATE) FROM TEST",0));
Series1->Clear();
Series2->Clear();
Chart1->Page = 1;
CGauge1->MaxValue = pFIBDataSet1->RecordCountFromSrv();
Label8->Caption = "Пары товаров от "+MinD. DateString()+" до "+MaxD. DateString()+" "
"(диапазон процентов: от "+Edit1->Text+" до "+Edit2->Text+")";
Edit1->Visible = false;
Edit2->Visible = false;
UpDown1->Visible = false;
UpDown2->Visible = false;
Button1->Visible = false;
CGauge1->Visible = true;
while(!pFIBDataSet1->Eof)
{ pFIBDataSet1->GetFieldData(1,Ar1);
pFIBDataSet1->GetFieldData(2,Ar2);
Name1 = pFIBDatabase2->QueryValueAsStr("SELECT NAME FROM GOODS "
"WHERE ARTICLE=\'"+AnsiString(Ar1)+"\'",0);
Name2 = pFIBDatabase2->QueryValueAsStr("SELECT NAME FROM GOODS "
"WHERE ARTICLE=\'"+AnsiString(Ar2)+"\'",0);
D1 = pFIBDataSet1->FieldByName("FIRSTDATE")->AsDateTime;
D2 = pFIBDataSet1->FieldByName("LASTDATE")->AsDateTime;
Loc = pFIBDataSet1->FieldByName("LOCID")->AsInteger;
Series1->AddBar(pFIBDataSet1->FieldByName("P2")->AsFloat, Name1+"("+AnsiString(Ar1)+");"+D1.DateString()+"-"+D2.DateString(),clTeeColor);
Series2->AddBar(pFIBDataSet1->FieldByName("P3")->AsFloat, Name2+"("+AnsiString(Ar2)+");"+IntToStr(Loc),clTeeColor);
pFIBDataSet1->Next();
CGauge1->Progress++;}
pFIBDataSet1->Active = false;
pFIBDatabase1->Close();
pFIBDatabase2->Close();
Button4->Enabled = true;
Button6->Enabled = true;
Edit3->Enabled = true;
Edit3->Text = "1";
Label6->Caption = IntToStr(Chart1->NumPages());
Edit1->Visible = true;
Edit2->Visible = true;
UpDown1->Visible = true;
UpDown2->Visible = true;
Button1->Visible = true;
CGauge1->Visible = false;
CGauge1->Progress = 0;}
//
void __fastcall TForm2::Button6Click(TObject *Sender)
{AnsiString STR;
Chart->NextPage();
if(StrToInt(Edit3->Text) < Chart->NumPages())
Edit3->Text = IntToStr(StrToInt(Edit3->Text)+1);}
//
void __fastcall TForm2::Button4Click(TObject *Sender)
{Chart->PreviousPage();
if(StrToInt(Edit3->Text)>1)
Edit3->Text = IntToStr(StrToInt(Edit3->Text)-1);}
//
void __fastcall TForm2::Edit3Exit(TObject *Sender)
{ if(StrToInt(Edit3->Text)>Chart->NumPages())
Chart->Page = Chart->NumPages();
else if(StrToInt(Edit3->Text)<1) Chart->Page = 1;
else Chart->Page = StrToInt(Edit3->Text);}
//
void __fastcall TForm2::Edit3KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{ if(Key == VK_RETURN)
{if(StrToInt(Edit3->Text)>Chart->NumPages())
{Chart->Page = Chart->NumPages();
Edit3->Text = StrToInt(Chart->NumPages());}
else if(StrToInt(Edit3->Text)<1)
{Chart->Page = 1;
Edit3->Text = "1";}
else Chart->Page = StrToInt(Edit3->Text);
Edit3->SelectAll();}}
//
void __fastcall TForm2::TabbedNotebook1Change(TObject *Sender, int NewTab,
bool &AllowChange)
{if(NewTab)
{Button1->Visible = false;
Button3->Visible = true;
Chart = Chart2;
Button2->Left = 920;
Edit3->Text = IntToStr(Chart2->Page);
Label6->Caption = IntToStr(Chart2->NumPages());}
else { Button3->Visible = false;
Button1->Visible = true;
Chart = Chart1;
Button2->Left = 270;
Edit3->Text = StrToInt(Chart1->Page);
Label6->Caption = IntToStr(Chart1->NumPages());}}
//
void __fastcall TForm2::Button3Click(TObject *Sender)
{ AnsiString Name1,Name2;
char Ar1[8],Ar2[8];
TDateTime D1,D2,MaxD, MinD;
int i=1,fieldnum, Loc;
pFIBDatabase2->Open();
if(Edit4->Text!=""||Edit5->Text!="")
{if(Edit4->Text!="")
{Edit5->Text = VarToStr(pFIBDatabase2->QueryValue("SELECT NAME FROM GOODS WHERE ARTICLE=\'"+Edit4->Text+"\'",0));
if(Edit5->Text. IsEmpty()){Application->MessageBox("Товар не найден!","ОШИБКА!",MB_OK); return; }}
else {Edit4->Text = pFIBDatabase2->QueryValueAsStr("SELECT ARTICLE FROM GOODS WHERE NAME=\'"+Edit5->Text+"\'",0);
if(Edit4->Text == NULL)
{Application->MessageBox("Товар не найден!","ОШИБКА!",MB_OK); return; }}}
else {Application->MessageBox("Введите артикул или наименование товара!","ОШИБКА!",MB_OK); return; }
pFIBDataSet1->Active = false;
pFIBDataSet1->SQLs->SelectSQL->Text="SELECT ARTICLE1,ARTICLE2,FIRSTDATE, LASTDATE, P2,P3,LOCID "
"FROM TEST "
"WHERE P4>=\'"+Edit1->Text+"\' AND P4<=\'"+Edit2->Text+"\' "
"AND (ARTICLE1=\'"+Edit4->Text+"\' OR ARTICLE2=\'"+Edit4->Text+"\') "
"ORDER BY P4 DESC, ARTICLE1";
pFIBDatabase1->Open();
pFIBDataSet1->Active = true;
pFIBDataSet1->First();
BarSeries1->Clear();
BarSeries2->Clear();
MinD = VarToDateTime(pFIBDatabase1->QueryValue("SELECT MIN(FIRSTDATE) FROM TEST",0));
MaxD = VarToDateTime(pFIBDatabase1->QueryValue("SELECT MAX(LASTDATE) FROM TEST",0));
CGauge1->MaxValue = pFIBDataSet1->RecordCountFromSrv();
Label9->Caption = "Пары для \""+Edit5->Text+"\" от "+MinD. DateString()+" до "+MaxD. DateString()+" (диапазон процентов: от "+Edit1->Text+" до "+Edit2->Text+")";
Edit1->Visible = false;
Edit2->Visible = false;
UpDown1->Visible = false;
UpDown2->Visible = false;
Button3->Visible = false;
CGauge1->Visible = true;
while(!pFIBDataSet1->Eof)
{ pFIBDataSet1->GetFieldData(1,Ar1);
pFIBDataSet1->GetFieldData(2,Ar2);
Name1 = pFIBDatabase2->QueryValueAsStr("SELECT NAME FROM GOODS "
"WHERE ARTICLE=\'"+AnsiString(Ar1)+"\'",0);
Name2 = pFIBDatabase2->QueryValueAsStr("SELECT NAME FROM GOODS "
"WHERE ARTICLE=\'"+AnsiString(Ar2)+"\'",0);
D1 = VarToDateTime(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(3),i));
D2 = VarToDateTime(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(4),i));
Loc = pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(7),i);
BarSeries1->AddBar(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(5),i),Name1+"("+AnsiString(Ar1)+");"+D1.DateString()+"-"+D2.DateString(),clTeeColor);
BarSeries2->AddBar(pFIBDataSet1->RecordFieldValue(pFIBDataSet1->FieldByFieldNo(6),i),Name2+"("+AnsiString(Ar2)+");"+IntToStr(Loc),clTeeColor);
pFIBDataSet1->Next();
CGauge1->Progress++;
i++; }
pFIBDataSet1->Active = false;
pFIBDatabase1->Close();
pFIBDatabase2->Close();
Button4->Enabled = true;
Button6->Enabled = true;
Edit3->Enabled = true;
Edit3->Text = "1";
Label6->Caption = IntToStr(Chart2->NumPages());
Edit1->Visible = true;
Edit2->Visible = true;
UpDown1->Visible = true;
UpDown2->Visible = true;
Button3->Visible = true;
CGauge1->Visible = false;
CGauge1->Progress = 0;}
//
void __fastcall TForm2::Chart1AfterDraw(TObject *Sender)
{AnsiString label1,label2,str1,str2,date;
int h, w,w1,x, y,i, n,a;
Chart1->Canvas->Pen->Color = clBlack;
for(i = 0;i < Chart1->MaxPointsPerPage;i++)
{ n = 4*(Chart1->Page-1)+i;
if(Series1->Count()-n-1<0) return;
label2 = Series2->XLabel[n];
label1 = Series1->XLabel[n];
a = label1.AnsiPos(";");
str1 = label1.SubString(1,a-1)+" ";
date = label1.SubString(a+1,label1.Length());
a = label2.AnsiPos(";");
str2 = label2.SubString(1,a-1);
h = Chart1->Canvas->TextHeight(str2);
w1 = Chart1->Canvas->TextWidth(str2);
w= Chart1->Canvas->TextWidth(str1);
x = Series2->CalcXPos(n)-w-1;
if(x<0)x = 0;
if((x+w+w1+6)>Chart1->Width) x = Chart1->Width-(w+w1+6);
y = i*(h+8);
Chart1->Canvas->Brush->Color = clYellow;
Chart1->Canvas->FillRect(Rect(x, y,x+w, y+h));
Chart1->Canvas->Rectangle(x, y,x+w+2,y+h+2);
Chart1->Canvas->TextOutA(x+1,y+1,str1);
Chart1->Canvas->Brush->Color = clLime;
Chart1->Canvas->FillRect(Rect(x+w+2,y, x+w+w1+3,y+h));
Chart1->Canvas->Rectangle(x+w+2,y, x+w+w1+4,y+h+2);
Chart1->Canvas->TextOutA(x+w+3,y+1,str2);
Chart1->Canvas->Brush->Color = clFuchsia;
Chart1->Canvas->TextOutA(Series2->CalcXPos(n)-62,351,date);
Chart1->Canvas->Line(Series2->CalcXPos(n),y+h+1,Series2->CalcXPos(n),353);}}
//
void __fastcall TForm2::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{if(Key == VK_RETURN)
{if(TabbedNotebook1->PageIndex)Button3->OnClick(NULL);
else Button1->OnClick(NULL); }}
//
void __fastcall TForm2::Edit2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{ if(Key == VK_RETURN)
{if(TabbedNotebook1->PageIndex)Button3->OnClick(NULL);
else Button1->OnClick(NULL); }}
//
void __fastcall TForm2::Chart2AfterDraw(TObject *Sender)
{AnsiString label1,label2,str1,str2,date;
int h, w,w1,x, y,i, n,a;
Chart2->Canvas->Pen->Color = clBlack;
for(i = 0;i < Chart1->MaxPointsPerPage;i++)
{ n = 4*(Chart2->Page-1)+i;
if(BarSeries1->Count()-n-1<0) return;
label2 = BarSeries2->XLabel[n];
label1 = BarSeries1->XLabel[n];
a = label1.AnsiPos(";");
str1 = label1.SubString(1,a-1)+" ";
date = label1.SubString(a+1,label1.Length());
a = label2.AnsiPos(";");
str2 = label2.SubString(1,a-1);
h = Chart2->Canvas->TextHeight(str2);
w1 = Chart2->Canvas->TextWidth(str2);
w= Chart2->Canvas->TextWidth(str1);
x = BarSeries2->CalcXPos(n)-w-1;
if(x<0)x = 0;
if((x+w+w1+6)>Chart2->Width) x = Chart2->Width-(w+w1+6);
y = i*(h+8);
Chart2->Canvas->Brush->Color = clYellow;
Chart2->Canvas->FillRect(Rect(x, y,x+w, y+h));
Chart2->Canvas->Rectangle(x, y,x+w+2,y+h+2);
Chart2->Canvas->TextOutA(x+1,y+1,str1);
Chart2->Canvas->Brush->Color = clLime;
Chart2->Canvas->FillRect(Rect(x+w+2,y, x+w+w1+3,y+h));
Chart2->Canvas->Rectangle(x+w+2,y, x+w+w1+4,y+h+2);
Chart2->Canvas->TextOutA(x+w+3,y+1,str2);
Chart2->Canvas->Brush->Color = clFuchsia;
Chart2->Canvas->TextOutA(BarSeries2->CalcXPos(n)-62,351,date);
Chart2->Canvas->Line(BarSeries2->CalcXPos(n),y+h+1,BarSeries2->CalcXPos(n),353); }}
//
void __fastcall TForm2::Series1Click(TChartSeries *Sender, int ValueIndex,
TMouseButton Button, TShiftState Shift, int X, int Y)
{int len, p;
len = Series1->XLabel[ValueIndex].Length();
Label10->Caption = Series1->XLabel[ValueIndex].SubString(len-28,6);
data1 = Series1->XLabel[ValueIndex].SubString(len-20,10);
data2 = Series1->XLabel[ValueIndex].SubString(len-9,10);
len = Series2->XLabel[ValueIndex].Length();
p = Series2->XLabel[ValueIndex].AnsiPos(";");
articul = Series2->XLabel[ValueIndex].SubString(p-7,6);
location = Series2->XLabel[ValueIndex].SubString(p+1,len-p);}
//
void __fastcall TForm2::Series2Click(TChartSeries *Sender, int ValueIndex,
TMouseButton Button, TShiftState Shift, int X, int Y)
{int len, p;
len = Series1->XLabel[ValueIndex].Length();
articul = Series1->XLabel[ValueIndex].SubString(len-28,6);
data1 = Series1->XLabel[ValueIndex].SubString(len-20,10);
data2 = Series1->XLabel[ValueIndex].SubString(len-9,10);
len = Series2->XLabel[ValueIndex].Length();
p = Series2->XLabel[ValueIndex].AnsiPos(";");
Label10->Caption = Series2->XLabel[ValueIndex].SubString(p-7,6);
location = Series2->XLabel[ValueIndex].SubString(p+1,len-p);}
//
void __fastcall TForm2::Button5Click(TObject *Sender)
{if(Label10->Caption. IsEmpty()) { Application->MessageBox("Выберите артикул!","Не выбраны данные.",MB_OK); }
else { AnsiString Query;
int A;
double AB;
Query = "SELECT SUM(SALESCOUNT) "
"FROM ASSOTIATIONS_2D "
"WHERE ((ARTICLE1=\'"+Label10->Caption+"\' AND ARTICLE2=\'"+articul+"\') "
"OR (ARTICLE2=\'"+Label10->Caption+"\' AND ARTICLE1=\'"+articul+"\')) "
"AND LOCID="+location+" "
"AND SALESDATE BETWEEN \'"+data1+"\' AND \'"+data2+"\'";
pFIBDatabase2->Open();
AB = pFIBDatabase2->QueryValue(Query,0);
OracleSession1->Connected = true;
OracleQuery1->SQL->Text = "SELECT COUNT(SUPERMAG. SMCASHCHECKS. CHECKNUM) "
"FROM SUPERMAG. SMCASHCHECKS, SUPERMAG. SMCASHCHECKITEMS "
"WHERE SUPERMAG. SMCASHCHECKITEMS. ARTICLE=\'"+Label10->Caption+"\' "
"AND SUPERMAG. SMCASHCHECKITEMS. LOCID="+location+" "
"AND SUPERMAG. SMCASHCHECKITEMS. CHECKNUM=SUPERMAG. SMCASHCHECKS. CHECKNUM "
"AND SUPERMAG. SMCASHCHECKITEMS. ZNUM=SUPERMAG. SMCASHCHECKS. ZNUM "
"AND SUPERMAG. SMCASHCHECKITEMS. DESKNUM=SUPERMAG. SMCASHCHECKS. DESKNUM "
"AND SUPERMAG. SMCASHCHECKS. PRINTTIME >= \'"+data1+"\' "
"AND SUPERMAG. SMCASHCHECKS. PRINTTIME <= \'"+data2+"\' ";
OracleQuery1->Execute();
A = OracleQuery1->FieldAsInteger(0);
Edit6->Text = FloatToStr(((A-AB)/A)*100);
OracleSession1->Connected = false;
pFIBDatabase2->Close(); }}
//
void __fastcall TForm2::Edit4KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{ if(Key == VK_RETURN){ if(TabbedNotebook1->PageIndex)Button3->OnClick(NULL);
else Button1->OnClick(NULL); }
//
Заголовочный файл модуля обработки “Unit1.h”:
#ifndef Unit1H
#define Unit1H
//
#include <Classes. hpp>
#include <Controls. hpp>
#include <StdCtrls. hpp>
#include <Forms. hpp>
#include "FIBDatabase. hpp"
#include "FIBDataSet. hpp"
#include "pFIBDatabase. hpp"
#include "pFIBDataSet. hpp"
#include <DB. hpp>
#include <ComCtrls. hpp>
#include "CGAUGES. h"
#include "Oracle. hpp"
#include "OracleData. hpp"
#include "FIBQuery. hpp"
#include "pFIBQuery. hpp"
#include "WORK. H"
//
class TForm1 : public TForm
{__published: // IDE-managed Components
TpFIBDatabase *pFIBDatabase1;
TpFIBDataSet *pFIBDataSet1;
TpFIBTransaction *pFIBTransaction1;
TpFIBTransaction *pFIBTransaction2;
TpFIBDatabase *pFIBDatabase2;
TGroupBox *GroupBox1;
TRadioButton *RadioButton1;
TRadioButton *RadioButton2;
TRadioButton *RadioButton3;
TComboBox *ComboBox1;
TEdit *Edit1;
TUpDown *UpDown1;
TDateTimePicker *DateTimePicker1;
TDateTimePicker *DateTimePicker2;
TLabel *Label1;
TLabel *Label2;
TButton *Button1;
TCGauge *CGauge1;
TLabel *Label3;
TLabel *Label4;
TLabel *Label5;
TLabel *Label6;
TOracleQuery *OracleQuery1;
TButton *Button2;
TOracleSession *OracleSession1;
TpFIBQuery *pFIBQuery1;
TpFIBDataSet *pFIBDataSet2;
void __fastcall RadioButton1Click(TObject *Sender);
void __fastcall RadioButton2Click(TObject *Sender);
void __fastcall RadioButton3Click(TObject *Sender);
void __fastcall ComboBox1Change(TObject *Sender);
|
Из за большого объема этот материал размещен на нескольких страницах:
1 2 3 4 |


