Prvni verze
This commit is contained in:
443
frmKontrolaCCP1edt.pas
Normal file
443
frmKontrolaCCP1edt.pas
Normal file
@ -0,0 +1,443 @@
|
||||
unit frmKontrolaCCP1edt;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.ExtCtrls, Vcl.Grids, Vcl.DBGrids,
|
||||
ddPlugin_TLB, Vcl.StdCtrls, Vcl.Mask, RxToolEdit, Vcl.ComCtrls, Vcl.NumberBox,
|
||||
Vcl.Buttons;
|
||||
|
||||
type
|
||||
TMyGrid = class(TDBGrid);
|
||||
|
||||
TformKontrolaCCP1edt = class(TForm)
|
||||
GridPanel1: TGridPanel;
|
||||
grdCCP1: TStringGrid;
|
||||
GridPanel2: TGridPanel;
|
||||
Label1: TLabel;
|
||||
pnlLabel1: TPanel;
|
||||
Label2: TLabel;
|
||||
pnlLabel2: TPanel;
|
||||
Label3: TLabel;
|
||||
pnlLabel3: TPanel;
|
||||
Label4: TLabel;
|
||||
pnlLabel4: TPanel;
|
||||
Label5: TLabel;
|
||||
pnlLabel5: TPanel;
|
||||
Label6: TLabel;
|
||||
pnlLabel6: TPanel;
|
||||
Label7: TLabel;
|
||||
pnlLabel7: TPanel;
|
||||
Label8: TLabel;
|
||||
pnlLabel8: TPanel;
|
||||
Label9: TLabel;
|
||||
pnlLabel9: TPanel;
|
||||
Label10: TLabel;
|
||||
pnlLabel10: TPanel;
|
||||
Label11: TLabel;
|
||||
pnlLabel11: TPanel;
|
||||
Label12: TLabel;
|
||||
pnlLabel12: TPanel;
|
||||
GridPanel3: TGridPanel;
|
||||
GridPanel4: TGridPanel;
|
||||
GridPanel5: TGridPanel;
|
||||
Label13: TLabel;
|
||||
edtVyrDenDis: TEdit;
|
||||
Label14: TLabel;
|
||||
GridPanel6: TGridPanel;
|
||||
dtDatum: TDateTimePicker;
|
||||
dtTime: TDateTimePicker;
|
||||
numBoxEditor: TNumberBox;
|
||||
checkBoxEditor: TCheckBox;
|
||||
btnQuit: TSpeedButton;
|
||||
GridPanel7: TGridPanel;
|
||||
pnlInfo: TPanel;
|
||||
GridPanel8: TGridPanel;
|
||||
Label15: TLabel;
|
||||
Label16: TLabel;
|
||||
GridPanel9: TGridPanel;
|
||||
Label17: TLabel;
|
||||
Label18: TLabel;
|
||||
Label19: TLabel;
|
||||
Label20: TLabel;
|
||||
lblTeplotaCCP1: TLabel;
|
||||
lblRozmer: TLabel;
|
||||
lblHmotnost: TLabel;
|
||||
lblDelka: TLabel;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormResize(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure grdCCP1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
|
||||
procedure numBoxEditorChange(Sender: TObject);
|
||||
procedure grdCCP1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
|
||||
procedure checkBoxEditorClick(Sender: TObject);
|
||||
procedure btnQuitClick(Sender: TObject);
|
||||
procedure numBoxEditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
procedure numBoxEditorExit(Sender: TObject);
|
||||
private
|
||||
function VisibleColsCount: integer;
|
||||
public
|
||||
apiMod: boolean;
|
||||
Helios: IHelios;
|
||||
vyrobniDen: TDateTime;
|
||||
end;
|
||||
|
||||
var
|
||||
formKontrolaCCP1edt: TformKontrolaCCP1edt;
|
||||
colWidths: TArray<Extended>;
|
||||
oldGridWidth: integer;
|
||||
zapisNum: boolean;
|
||||
aktCol, aktRow, oldCol: integer;
|
||||
|
||||
implementation
|
||||
uses System.StrUtils,
|
||||
datMod, funkceTB, helTabsBIDs;
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
procedure TformKontrolaCCP1edt.FormResize (Sender: TObject);
|
||||
var i1,i2: integer;
|
||||
begin
|
||||
i2:= 0;
|
||||
for i1:=0 to grdCCP1.ColCount-1 do
|
||||
begin
|
||||
if (grdCCP1.ColWidths[i1]>1) then
|
||||
begin
|
||||
grdCCP1.ColWidths[i1]:= Trunc(grdCCP1.Width * colWidths[i1]);
|
||||
// GridPanel2.ColumnCollection[i2].Value:= grdCCP1.Columns[i1].Width;
|
||||
// Inc(i2);
|
||||
end
|
||||
else
|
||||
grdCCP1.ColWidths[i1]:= 1;
|
||||
end;
|
||||
|
||||
GridPanel2.Invalidate;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.FormShow (Sender: TObject);
|
||||
var i: integer;
|
||||
p: Integer;
|
||||
begin
|
||||
|
||||
dm.NactiCCP1ProNoveZaznamy (self);
|
||||
|
||||
edtVyrDenDis.Text:= FormatDateTime('dd.mm.yyyy', vyrobniDen);
|
||||
dtDatum.Date:= vyrobniDen;
|
||||
dtTime.Time:= Now;
|
||||
|
||||
grdCCP1.Invalidate;
|
||||
self.Invalidate;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.grdCCP1DrawCell (Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
|
||||
var cellRect: TRect;
|
||||
t: string;
|
||||
a: TAlignment;
|
||||
sAlg: word;
|
||||
begin
|
||||
a:= grdCCP1.ColAlignments[ACol];
|
||||
|
||||
if not(gdFixed in State) then
|
||||
if (ARow=aktRow) then
|
||||
begin
|
||||
grdCCP1.Canvas.Brush.Color:= $00FFC891;
|
||||
// grdCCP1.Canvas.Font.Color:= clWindow;
|
||||
end
|
||||
else
|
||||
begin
|
||||
grdCCP1.Canvas.Brush.Color:= clWindow;
|
||||
// grdCCP1.Canvas.Font.Color:= clBlack;
|
||||
end;
|
||||
|
||||
|
||||
if (ACol=13) then // bunka je Checkbox ?
|
||||
begin
|
||||
grdCCP1.Canvas.FillRect (cellRect); // Nakreslíme buňku jako prázdnou
|
||||
cellRect:= Rect;
|
||||
InflateRect(cellRect, -2, -2); // Zmenšíme velikost checkboxu, aby byl uvnitř buňky
|
||||
checkBoxEditor.Left:= cellRect.Left;
|
||||
checkBoxEditor.Top:= cellRect.Top;
|
||||
checkBoxEditor.Width:= cellRect.Width;
|
||||
checkBoxEditor.Height:= cellRect.Height;
|
||||
checkBoxEditor.Visible:= true;
|
||||
checkBoxEditor.Checked:= (grdCCP1.Cells[ACol, ARow]='1'); // Např. '1' značí zaškrtnutý checkbox
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Pro ostatní sloupce nakreslíme text normálně
|
||||
if (a=taCenter) then
|
||||
begin
|
||||
t:= grdCCP1.Cells[ACol, ARow];
|
||||
sAlg:= SetTextAlign (grdCCP1.Canvas.Handle, TA_CENTER);
|
||||
grdCCP1.Canvas.TextRect (Rect, Rect.Left + (Rect.Right-Rect.Left) div 2, Rect.Top + 2, t);
|
||||
SetTextAlign (grdCCP1.Canvas.Handle, sAlg);
|
||||
{
|
||||
grdCCP1.Canvas.FillRect (cellRect); // Nakreslíme buňku jako prázdnou
|
||||
cellRect:= Rect;
|
||||
cellRect.Top:= cellRect.Top + 3; // adjust top to center vertical
|
||||
DrawText(grdCCP1.Canvas.Handle, PChar(t), Length(t), cellRect, DT_CENTER); // draw text
|
||||
}
|
||||
end
|
||||
else
|
||||
grdCCP1.Canvas.TextRect (Rect, Rect.Left + 2, Rect.Top + 2, grdCCP1.Cells[ACol, ARow]);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.grdCCP1SelectCell (Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
|
||||
var R: TRect;
|
||||
t, s: string;
|
||||
begin
|
||||
CanSelect:= false;
|
||||
|
||||
oldCol:= aktCol;
|
||||
aktCol:= ACol;
|
||||
aktRow:= ARow;
|
||||
|
||||
s:= grdCCP1.Cells[1, ARow];
|
||||
if (s<>'') then
|
||||
begin
|
||||
if (ACol<4) or (ACol=10) or (ACol=12) then
|
||||
CanSelect:= false;
|
||||
|
||||
if (ACol=11) then
|
||||
CanSelect:= true;
|
||||
|
||||
if (ACol in [4..8]) then
|
||||
begin
|
||||
R:= grdCCP1.CellRect(ACol, ARow);
|
||||
R.Left:= R.Left + grdCCP1.Left;
|
||||
R.Right := R.Right + grdCCP1.Left;
|
||||
R.Top := R.Top + grdCCP1.Top;
|
||||
R.Bottom := R.Bottom + grdCCP1.Top;
|
||||
if (ACol in [4,5]) then
|
||||
numBoxEditor.Decimal:= 0;
|
||||
if (ACol in [6,7,8]) then
|
||||
numBoxEditor.Decimal:= 2;
|
||||
numBoxEditor.Left:= R.Left + 1;
|
||||
numBoxEditor.Top:= R.Top + 1;
|
||||
numBoxEditor.Width:= (R.Right + 1) - R.Left;
|
||||
numBoxEditor.Height:= (R.Bottom + 1) - R.Top;
|
||||
numBoxEditor.Visible:= True;
|
||||
t:= numBoxEditor.Text;
|
||||
numBoxEditor.SetFocus;
|
||||
CanSelect:= true;
|
||||
end;
|
||||
end
|
||||
else
|
||||
CanSelect:= false;
|
||||
|
||||
|
||||
// if (ACol=1) then
|
||||
// CanSelect:= true;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.numBoxEditorChange (Sender: TObject);
|
||||
begin
|
||||
// grdCCP1.Cells[grdCCP1.Col, grdCCP1.Row]:= numBoxEditor.Text;
|
||||
// numBoxEditor.Visible:= False;
|
||||
// grdCCP1.SetFocus;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.numBoxEditorExit (Sender: TObject);
|
||||
begin
|
||||
grdCCP1.SetFocus;
|
||||
grdCCP1.Cells[aktCol, grdCCP1.Row]:= numBoxEditor.Text;
|
||||
numBoxEditor.Text:= '';
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.numBoxEditorKeyDown (Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
var c: Boolean;
|
||||
begin
|
||||
if (Key=VK_RETURN) or (Key=VK_TAB) then
|
||||
begin
|
||||
|
||||
grdCCP1.Cells[aktCol, grdCCP1.Row]:= numBoxEditor.Text;
|
||||
numBoxEditor.Visible:= False;
|
||||
numBoxEditor.Text:= '';
|
||||
grdCCP1.SetFocus;
|
||||
|
||||
case aktCol of
|
||||
4, 5, 6, 7: grdCCP1SelectCell(Sender, aktCol+1, grdCCP1.Row, c);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
function TformKontrolaCCP1edt.VisibleColsCount: Integer;
|
||||
var i: integer;
|
||||
begin
|
||||
result:= 0;
|
||||
for i:=0 to grdCCP1.ColCount-1 do
|
||||
if (grdCCP1.ColWidths[i]>1) then
|
||||
result:= result + 1;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.btnQuitClick (Sender: TObject);
|
||||
var lSQL: string;
|
||||
i: integer;
|
||||
tepl, rychl, hmot, delka, prum: Extended;
|
||||
function PrazdnyOrNull(const inStr: string): string;
|
||||
var e: Extended;
|
||||
begin
|
||||
if not(TryStrToFloat(inStr, e)) then
|
||||
e:= 0;
|
||||
result:= inStr.Trim.Replace(' ', '').Replace(',', '.');
|
||||
if (inStr.Trim='') or (e=0) then
|
||||
result:= 'NULL';
|
||||
end;
|
||||
begin
|
||||
Helios.ExecSQL('DROP TABLE IF EXISTS #InsertCCP1Zaznamy');
|
||||
|
||||
// lSQL:= 'IF OBJECT_ID(N''temp..#InsertCCP1Zaznamy'', N''U'') IS NOT NULL DROP TABLE #InsertCCP1Zaznamy' + CRLF;
|
||||
lSQL:= 'DROP TABLE IF EXISTS #InsertCCP1Zaznamy' + CRLF;
|
||||
lSQL:= lSQL + 'CREATE TABLE #InsertCCP1Zaznamy (ID INT IDENTITY(1,1) NOT NULL, Smena TINYINT, IDPrikaz INT, IDStroj INT, Teplota NUMERIC(15, 3), Rychlost NUMERIC(15, 2), Hmotnost NUMERIC(15, 3)';
|
||||
lSQL:= lSQL + ', Delka NUMERIC(15, 2), Prumer NUMERIC(15, 3), NapravneOpatreni NVARCHAR(255) )';
|
||||
Helios.ExecSQL(lSQL);
|
||||
|
||||
i:= 0;
|
||||
while (grdCCP1.Cells[1, i]<>'') do
|
||||
begin
|
||||
if (grdCCP1.Cells[4, i]<>'') or (grdCCP1.Cells[5, i]<>'') or (grdCCP1.Cells[6, i]<>'') or (grdCCP1.Cells[7, i]<>'') or (grdCCP1.Cells[8, i]<>'') then
|
||||
begin
|
||||
if not(TryStrToFloat(grdCCP1.Cells[4, i], tepl)) then
|
||||
tepl:= 0;
|
||||
if not(TryStrToFloat(grdCCP1.Cells[5, i], rychl)) then
|
||||
rychl:= 0;
|
||||
if not(TryStrToFloat(grdCCP1.Cells[6, i], hmot)) then
|
||||
hmot:= 0;
|
||||
if not(TryStrToFloat(grdCCP1.Cells[7, i], delka)) then
|
||||
delka:= 0;
|
||||
if not(TryStrToFloat(grdCCP1.Cells[8, i], prum)) then
|
||||
prum:= 0;
|
||||
|
||||
if (tepl>0) or (rychl>0) or (hmot>0) or (delka>0) or (prum>0) then
|
||||
begin
|
||||
lSQL:= 'INSERT #InsertCCP1Zaznamy (IDStroj, IDPrikaz, Smena, Teplota, Rychlost, Hmotnost, Delka, Prumer, NapravneOpatreni) SELECT ' + PrazdnyOrNull (grdCCP1.Cells[0, i]);
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[13, i]);
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[3, i]);
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[4, i]); // teplota
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[5, i]); // rychlost
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[6, i]); // hmotnost
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[7, i]); // delka
|
||||
lSQL:= lSQL + ', ' + PrazdnyOrNull (grdCCP1.Cells[8, i]); // prumer
|
||||
lSQL:= lSQL + ', ' + IfThen(grdCCP1.Cells[11, i]='', PrazdnyOrNull (grdCCP1.Cells[11, i]), grdCCP1.Cells[11, i].QuotedString); // napravne opatreni
|
||||
Helios.ExecSQL(lSQL);
|
||||
end;
|
||||
end;
|
||||
Inc(i);
|
||||
end;
|
||||
Helios.ExecSQL('IF OBJECT_ID(N''dbo.ep_Vyroba_ZapisCCP1'', N''P'') IS NOT NULL EXEC dbo.ep_Vyroba_ZapisCCP1');
|
||||
|
||||
Close;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.checkBoxEditorClick (Sender: TObject);
|
||||
begin
|
||||
// Aktualizujeme hodnotu v buňce podle stavu checkboxu
|
||||
if (grdCCP1.Col=13) and (grdCCP1.Row>=0) then
|
||||
begin
|
||||
if checkBoxEditor.Checked then
|
||||
grdCCP1.Cells[grdCCP1.Col, grdCCP1.Row] := '1'
|
||||
else
|
||||
grdCCP1.Cells[grdCCP1.Col, grdCCP1.Row] := '0';
|
||||
end;
|
||||
checkBoxEditor.Visible:= false; // Skryjeme checkbox po kliknutí
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.FormCreate (Sender: TObject);
|
||||
const HideScrollStyles = WS_HSCROLL;
|
||||
var i1, i2: integer;
|
||||
grdStyle: Integer;
|
||||
begin
|
||||
|
||||
{ // pro TDBGrid
|
||||
TMyGrid(grdCCP1).DefaultRowHeight:= 40;
|
||||
TMyGrid(grdCCP1).RowHeights[0]:= 0;
|
||||
TMyGrid(grdCCP1).ScrollBars:= TScrollStyle.ssVertical;
|
||||
|
||||
grdStyle:= GetWindowLong(grdCCP1.Handle, GWL_STYLE);
|
||||
if (grdStyle and HideScrollStyles) <> 0 then
|
||||
SetWindowLong(grdCCP1.Handle, GWL_STYLE, grdStyle and not HideScrollStyles);
|
||||
}
|
||||
|
||||
{
|
||||
grdCCP1.ColWidths[0]:= 0; // colID
|
||||
grdCCP1.ColWidths[1]:= Trunc(GridPanel2.ColumnCollection[0].Value + GridPanel2.ColumnCollection[1].Value) - 6;
|
||||
grdCCP1.ColWidths[2]:= Trunc(GridPanel2.ColumnCollection[2].Value);
|
||||
grdCCP1.ColWidths[3]:= Trunc(GridPanel2.ColumnCollection[3].Value);
|
||||
grdCCP1.ColWidths[4]:= Trunc(GridPanel2.ColumnCollection[4].Value);
|
||||
grdCCP1.ColWidths[5]:= Trunc(GridPanel2.ColumnCollection[5].Value);
|
||||
grdCCP1.ColWidths[6]:= Trunc(GridPanel2.ColumnCollection[6].Value);
|
||||
grdCCP1.ColWidths[7]:= Trunc(GridPanel2.ColumnCollection[7].Value);
|
||||
grdCCP1.ColWidths[8]:= Trunc(GridPanel2.ColumnCollection[8].Value);
|
||||
grdCCP1.ColWidths[9]:= Trunc(GridPanel2.ColumnCollection[9].Value);
|
||||
grdCCP1.ColWidths[10]:= Trunc(GridPanel2.ColumnCollection[10].Value);
|
||||
grdCCP1.ColWidths[11]:= Trunc(GridPanel2.ColumnCollection[11].Value);
|
||||
grdCCP1.ColWidths[12]:= Trunc(GridPanel2.ColumnCollection[12].Value);
|
||||
}
|
||||
grdCCP1.ColWidths[13]:= 0; // colIDNorma
|
||||
|
||||
grdCCP1.ColAlignments[3]:= taCenter; // smena
|
||||
|
||||
grdCCP1.DefaultDrawing:= false;
|
||||
|
||||
i2:= 0;
|
||||
SetLength(colWidths, grdCCP1.ColCount);
|
||||
for i1:=0 to grdCCP1.ColCount-1 do
|
||||
begin
|
||||
if (grdCCP1.ColWidths[i1]>0) then
|
||||
begin
|
||||
colWidths[i1]:= grdCCP1.ColWidths[i1] / grdCCP1.Width;
|
||||
// GridPanel2.ColumnCollection[i2].SizeStyle:= ssAbsolute;
|
||||
// GridPanel2.ColumnCollection[i2].Value:= grdCCP1.Columns[i1].Width;
|
||||
// Inc(i2);
|
||||
end
|
||||
else
|
||||
colWidths[i1]:= 0;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TformKontrolaCCP1edt.FormKeyUp (Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
if (Key=VK_ESCAPE) then
|
||||
Close;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user