unit U_frameBads; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit, Vcl.StdCtrls, Vcl.ExtCtrls, cxTextEdit, MovePanel, Vcl.Buttons, cxGeometry, dxFramedControl, Vcl.Menus, cxButtons, dxPanel, cxScrollBox, dxLayoutcxEditAdapters, dxLayoutContainer, cxClasses, dxLayoutControl, Data.DB, Data.Win.ADODB, cxCheckBox, cxLabel, cxMaskEdit, cxButtonEdit, cxDropDownEdit; type TframeBads = class(TFrame) dxPanel1: TdxPanel; RadioGroup1: TRadioGroup; dxPanel3: TdxPanel; cxButton1: TcxButton; cxButton2: TcxButton; CIFBeg: TcxTextEdit; CIFEnd: TcxTextEdit; CIFQty: TcxTextEdit; CIFNumber: TcxTextEdit; dxLayoutControl1Group_Root: TdxLayoutGroup; dxLayoutControl1: TdxLayoutControl; dxLayoutGroup1: TdxLayoutGroup; dxLayoutGroup2: TdxLayoutGroup; dxLayoutItem2: TdxLayoutItem; lblCIFName: TdxLayoutLabeledItem; dxLayoutEmptySpaceItem1: TdxLayoutEmptySpaceItem; dxLayoutLabeledItem1: TdxLayoutLabeledItem; dxLayoutItem1: TdxLayoutItem; dxLayoutItem3: TdxLayoutItem; dxLayoutItem4: TdxLayoutItem; dxLayoutItem5: TdxLayoutItem; dxLayoutItem6: TdxLayoutItem; lblLenUnit1: TdxLayoutLabeledItem; ADOTmp: TADOQuery; IsSubtract: TcxCheckBox; cxScrollBox1: TcxScrollBox; SubtractQty: TcxTextEdit; dxLayoutAutoCreatedGroup1: TdxLayoutAutoCreatedGroup; cxCheck_len: TcxCheckBox; dxLayoutItem_checkLen: TdxLayoutItem; cxLabel1: TcxLabel; CIFPoints111: TcxButtonEdit; cxLabel2: TcxLabel; CIFnote: TcxButtonEdit; CIFPoints: TcxComboBox; procedure cxButton2Click(Sender: TObject); procedure cxButton1Click(Sender: TObject); procedure CIFBegPropertiesEditValueChanged(Sender: TObject); procedure IsSubtractClick(Sender: TObject); procedure SubtractQtyPropertiesEditValueChanged(Sender: TObject); procedure CIFEndPropertiesChange(Sender: TObject); private procedure SpeedButtonClick(Sender: TObject); public fBadBtnSize: Integer; fRowNumber: Integer; procedure InitBadPanel(); end; implementation uses U_DataLink, U_iniParam; {$R *.dfm} procedure TframeBads.CIFBegPropertiesEditValueChanged(Sender: TObject); var mvalue: Double; begin if Trim(CIFBeg.Text) <> '' then begin if TryStrToFloat(CIFBeg.Text, mvalue) = False then begin Application.MessageBox('非法数字!', '提示', 0); Exit; end; end else begin Exit; end; if Trim(CIFEnd.Text) = '' then begin CIFQty.Text := ''; exit; end; CIFQty.Text := FloatToStr(StrToFloat(CIFEnd.Text) - StrToFloat(CIFBeg.Text)); if IsSubtract.Checked = true then SubtractQty.text := CIFQty.Text; end; procedure TframeBads.CIFEndPropertiesChange(Sender: TObject); var mvalue: Double; begin if Trim(CIFEnd.Text) <> '' then begin if TryStrToFloat(CIFEnd.Text, mvalue) = False then begin Application.MessageBox('非法数字!', '提示', 0); Exit; end; end; if trim(CIFBeg.Text) = '' then CIFQty.Text := '' else begin CIFQty.Text := FloatToStr(StrToFloatDef(trim(CIFEnd.Text), 0) - StrToFloatdef(trim(CIFBeg.Text), 0)); if IsSubtract.Checked = true then SubtractQty.text := CIFQty.Text; end; end; procedure TframeBads.cxButton1Click(Sender: TObject); begin RadioGroup1.ItemIndex := -1; end; procedure TframeBads.cxButton2Click(Sender: TObject); var mvalue: Double; begin if Trim(CIFBeg.Text) <> '' then begin if Trim(CIFEnd.Text) <> '' then begin if StrToFloat(CIFEnd.Text) < StrToFloat(CIFBeg.Text) then begin Application.MessageBox('疵点位置录入错误!', '提示', 0); Exit; end; end; end; if CIFQty.Text <> '' then begin if TryStrToFloat(CIFQty.Text, mvalue) = False then begin Application.MessageBox('非法数字!', '提示', 0); Exit; end; end; if strTofloatdef(Trim(SubtractQty.Text), 0) > 0 then begin IsSubtract.Checked := true; end else begin IsSubtract.Checked := false; end; end; //procedure TframeBads.InitBadPanel(); //var // speedBtn: TSpeedButton; // zdyName, ZdyType, LastZdyType: string; // i, k, j: Integer; // typeLabel: TLabel; //begin // with ADOTmp do // begin // Close; // sql.Clear; // sql.Add('select ZDYName,Note1 from KH_Zdy where Type=''WFBCD'' order by Note1 desc'); // Open; // end; // if ADOTmp.IsEmpty then // begin // Application.MessageBox('没有定义疵点!', '提示', 0); // Exit; // end; // if fRowNumber = 0 then // fRowNumber := 5; // // j := fRowNumber; // if fBadBtnSize < 30 then // fBadBtnSize := 40; // // cxScrollBox1.DisableAlign; // with ADOTmp do // begin // First; // i := 0; // while not Eof do // begin // ZdyType := Trim(fieldbyname('Note1').AsString); // k := i div j; // zdyName := Trim(fieldbyname('ZDYName').AsString); // // speedBtn := TSpeedButton.Create(self); // speedBtn.OnClick := SpeedButtonClick; // // speedBtn.Width := fBadBtnSize; // speedBtn.Height := fBadBtnSize; // // speedBtn.Left := 5 + (i mod j) * speedBtn.Width; // speedBtn.Top := 3 + k * speedBtn.Height; // // speedBtn.Parent := cxScrollBox1; // speedBtn.Hint := zdyName; // if Length(zdyName) > 4 then // begin // speedBtn.Caption := Copy(zdyName, 1, 4) + #13 + Copy(zdyName, 5, Length(zdyName) - 4); // end // else // speedBtn.Caption := zdyName; // // i := i + 1; // Next; // end; // end; // cxScrollBox1.EnableAlign; // if gFlawscore then // begin // RadioGroup1.Items.Text := '1' + #13#10 + '2' + #13#10 + '3' + #13#10 + '4' + #13#10 + '整匹' + #13#10 + '连续出现瑕疵'; // end; //end; procedure TframeBads.InitBadPanel(); const nBtnHeight = 50; // 疵点按钮高度=两行文字的高度 var speedBtn: TSpeedButton; typeLabel: TLabel; zdyName, ZdyType, LastZdyType: string; i, j: Integer; col, row: Integer; begin with ADOTmp do begin Close; SQL.Clear; SQL.Add('select ZDYName, Note1 from KH_Zdy ' + 'where Type=''WFBCD'' order by Note1 desc'); Open; end; if ADOTmp.IsEmpty then begin Application.MessageBox('没有定义疵点!', '提示', 0); Exit; end; if fRowNumber = 0 then fRowNumber := 5; j := fRowNumber; if fBadBtnSize < 30 then fBadBtnSize := 40; cxScrollBox1.DisableAlign; // 如果 InitBadPanel 会重复调用,先清空旧控件 while cxScrollBox1.ControlCount > 0 do cxScrollBox1.Controls[0].Free; with ADOTmp do begin First; i := 0; col := 0; row := 0; LastZdyType := ''; while not Eof do begin ZdyType := Trim(FieldByName('Note1').AsString); zdyName := Trim(FieldByName('ZDYName').AsString); // ZdyType 发生变化,创建一个新的类型标题 if (i = 0) or (ZdyType <> LastZdyType) then begin // 如果不是第一组,先留一点空白 if i > 0 then Inc(row); // 创建 ZdyType 标题 typeLabel := TLabel.Create(Self); typeLabel.Parent := cxScrollBox1; typeLabel.Left := 5; // typeLabel.Top := 3 + row * (fBadBtnSize + 5); typeLabel.Top := 3 + row * nBtnHeight; // 按钮高度改为两行文字(40)后,标题Top同步按新高度计算,防止标题与按钮重叠错位 typeLabel.Width := cxScrollBox1.ClientWidth - 15; typeLabel.Height := 20; typeLabel.Caption := '【' + ZdyType + '】'; typeLabel.Font.Style := [fsBold]; typeLabel.Font.Size := 10; // 进入下一行,下面开始放疵点按钮 Inc(row); col := 0; end; //========================================================== // 创建疵点按钮 //========================================================== speedBtn := TSpeedButton.Create(Self); speedBtn.Parent := cxScrollBox1; speedBtn.OnClick := SpeedButtonClick; // speedBtn.Width := fBadBtnSize; // speedBtn.Height := fBadBtnSize; speedBtn.Width := 65; // 宽度保持不变 speedBtn.Height := nBtnHeight; // 只改高度,改为两行文字的高度(40) speedBtn.Font.Size := 8; // 字号 speedBtn.Left := 5 + col * speedBtn.Width; speedBtn.Top := 3 + row * speedBtn.Height; // speedBtn.Hint := zdyName; if Length(zdyName) > 4 then begin speedBtn.Caption := Copy(zdyName, 1, 4) + #13 + Copy(zdyName, 5, Length(zdyName) - 4); end else speedBtn.Caption := zdyName; Inc(i); Inc(col); // 当前行已经达到最大按钮数量 if col >= j then begin col := 0; Inc(row); end; LastZdyType := ZdyType; Next; end; end; cxScrollBox1.EnableAlign; if gFlawscore then begin RadioGroup1.Items.Text := '1' + #13#10 + '2' + #13#10 + '3' + #13#10 + '4' + #13#10 + '整匹' + #13#10 + '连续出现瑕疵'; end; end; procedure TframeBads.IsSubtractClick(Sender: TObject); begin end; // procedure TframeBads.SpeedButtonClick(Sender: TObject); begin dxPanel1.Visible := true; lblCIFName.Caption := Trim(TSpeedButton(Sender).Hint); // CIFNumber.SetFocus; end; procedure TframeBads.SubtractQtyPropertiesEditValueChanged(Sender: TObject); begin if trim(SubtractQty.Text) <> '' then isSubTract.Checked := true else isSubTract.Checked := false; end; end.