D10SZKaiXiYa/B02基础纱线仓库/U_YarnInfoInPut.pas
2026-01-14 17:32:54 +08:00

651 lines
16 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit U_YarnInfoInPut;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, StdCtrls, ExtCtrls,
cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
dxBarBuiltInMenu, U_BaseInput, U_BaseList, System.ImageList, Vcl.ImgList,
cxContainer, cxMaskEdit, cxMemo, cxImageList, dxSkinsCore,
dxSkinsDefaultPainters, dxCore, cxDateUtils, dxSkinOffice2013White,
dxSkinSharpPlus, dxSkinWXI, dxScrollbarAnnotations, cxCheckBox;
type
TfrmYarnInfoInPut = class(TfrmBaseInput)
ToolBar1: TToolBar;
TBSave: TToolButton;
TBClose: TToolButton;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
ToolButton1: TToolButton;
ScrollBox1: TScrollBox;
Label7: TLabel;
Label1: TLabel;
Y_Name: TcxTextEdit;
Label3: TLabel;
Y_Code: TcxTextEdit;
Label8: TLabel;
Denier: TcxTextEdit;
Label9: TLabel;
Note: TcxMemo;
Label5: TLabel;
ADOConnection1: TADOConnection;
Label10: TLabel;
FF: TcxTextEdit;
Label12: TLabel;
ZS: TcxTextEdit;
Y_Color: TcxButtonEdit;
Y_Composition: TcxButtonEdit;
Label16: TLabel;
ToolBar2: TToolBar;
TbAdd: TToolButton;
TbDel: TToolButton;
Tv1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
Tv1DH: TcxGridDBColumn;
Tv1CF: TcxGridDBColumn;
Tv1BL: TcxGridDBColumn;
CDS_1: TClientDataSet;
DS_1: TDataSource;
Tv1serialno: TcxGridDBColumn;
Tv1CFID: TcxGridDBColumn;
Tv1BYIID: TcxGridDBColumn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBCloseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TBSaveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Y_NameClick(Sender: TObject);
procedure Y_NameExit(Sender: TObject);
procedure Y_SpecPropertiesChange(Sender: TObject);
procedure DenierClick(Sender: TObject);
procedure DenierExit(Sender: TObject);
procedure ZSClick(Sender: TObject);
procedure ZSExit(Sender: TObject);
procedure DenierPropertiesEditValueChanged(Sender: TObject);
procedure ZSPropertiesEditValueChanged(Sender: TObject);
procedure ParentCoNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
procedure Y_ColorDblClick(Sender: TObject);
procedure CJPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
procedure Y_CompositionPropertiesChange(Sender: TObject);
procedure ZSPropertiesChange(Sender: TObject);
procedure Y_ColorPropertiesChange(Sender: TObject);
procedure FFPropertiesChange(Sender: TObject);
procedure CJPropertiesChange(Sender: TObject);
procedure TbAddClick(Sender: TObject);
procedure TbDelClick(Sender: TObject);
procedure TextEdit(Sender: TObject);
private
{ Private declarations }
function SaveData(): Boolean;
procedure UpdateYarnName;
procedure initCFGrid();
function CheckBL(): Boolean;
public
{ Public declarations }
FBYIID, FSTKName: string;
end;
var
frmYarnInfoInPut: TfrmYarnInfoInPut;
implementation
uses
U_DataLink, U_RTFun, U_ZDYHelp, U_CompanySel, U_YarnCFInfoSel; //, U_ProductInfoSel
{$R *.dfm}
procedure TfrmYarnInfoInPut.CJPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
try
frmCompanySel := TfrmCompanySel.Create(Application);
with frmCompanySel do
begin
FCoType := '<27><>Ӧ<EFBFBD><D3A6>';
if ShowModal = 1 then
begin
end;
end;
finally
frmCompanySel.Free;
end;
end;
procedure TfrmYarnInfoInPut.CJPropertiesChange(Sender: TObject);
begin
UpdateYarnName;
end;
procedure TfrmYarnInfoInPut.DenierClick(Sender: TObject);
begin
ZS.Style.Color := clMoneyGreen;
end;
procedure TfrmYarnInfoInPut.DenierExit(Sender: TObject);
begin
ZS.Style.Color := clWhite;
end;
procedure TfrmYarnInfoInPut.DenierPropertiesEditValueChanged(Sender: TObject);
begin
ZS.text := floattostr(roundfloat(5315.5 / strtofloatdef(Denier.text, 0), 0));
end;
procedure TfrmYarnInfoInPut.FFPropertiesChange(Sender: TObject); //<2F>ķ<EFBFBD>
begin
UpdateYarnName;
end;
procedure TfrmYarnInfoInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := caFree;
end;
procedure TfrmYarnInfoInPut.initCFGrid();
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select A.* from BS_Yarn_Info_CF A ');
sql.Add(' where BYIID = ' + quotedStr(Trim(FBYIID)));
sql.Add('Order By A.serialno ');
Open;
end;
SCreateCDS(ADOQueryTemp, CDS_1);
SInitCDSData(ADOQueryTemp, CDS_1);
end;
function TfrmYarnInfoInPut.SaveData(): Boolean;
var
MaxNo, MaxPRID, maxCFID: string;
begin
try
ADOQueryCmd.Connection.BeginTrans;
if Trim(FBYIID) = '' then
begin
if GetLSNo(ADOQueryCmd, MaxNo, 'P', 'BS_Yarn_Info', 4, 0) = False then
raise Exception.Create(<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>');
Y_Code.Text := MaxNo;
end
else
begin
MaxNo := Trim(FBYIID);
end;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('select * from BS_Yarn_Info where BYIID=''' + Trim(MaxNo) + '''');
Open;
end;
with ADOQueryCmd do
begin
if Trim(FBYIID) = '' then
begin
Append;
FieldByName('FillId').Value := Trim(DCode);
FieldByName('Filler').Value := Trim(DName);
end
else
begin
Edit;
FieldByName('EditId').Value := Trim(DCode);
FieldByName('Editer').Value := Trim(DName);
FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
end;
FieldByName('BYIID').Value := Trim(MaxNo);
RTSetsavedata(ADOQueryCmd, 'BS_Yarn_Info', ScrollBox1, 2);
Post;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from BS_Yarn_Info where Y_Code=' + quotedstr(trim(Y_Code.Text)));
Open;
end;
if ADOQueryCmd.RecordCount > 1 then
raise Exception.Create('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>!');
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from BS_Yarn_Info where Y_Name=' + quotedstr(trim(Y_Name.Text)));
Open;
end;
if ADOQueryCmd.RecordCount > 1 then
raise Exception.Create('Ʒ<><C6B7><EFBFBD>ظ<EFBFBD>!');
////////////////// <20><><EFBFBD><EFBFBD><EFBFBD>ɷֱ<C9B7><D6B1><EFBFBD>ʼ //////////////////////
with CDS_1 do
begin
First;
while not Eof do
begin
if Trim(CDS_1.fieldbyname('CFID').AsString) = '' then
begin
if GetLSNo(ADOQueryTemp, maxCFID, 'CF', 'BS_Yarn_Info_CF', 5, 1) = False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox(<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><CBAE>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', 0);
Exit;
end;
end
else
begin
maxCFID := Trim(CDS_1.fieldbyname('CFID').AsString);
end;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('select * from BS_Yarn_Info_CF where ');
sql.Add(' CFID=''' + Trim(maxCFID) + '''');
Open;
end;
with ADOQueryCmd do
begin
if Trim(CDS_1.fieldbyname('BYIID').AsString) = '' then
begin
Append;
end
else
begin
Edit;
end;
FieldByName('Y_Code').Value := Y_Code.Text;
FieldByName('BYIID').Value := Trim(MaxNo);
FieldByName('CFID').Value := Trim(maxCFID);
RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_1, 'BS_Yarn_Info_CF', 0);
Post;
end;
Next;
end;
end;
//////////////// <20><><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7>ӱ<EFBFBD><D3B1><EFBFBD><EFBFBD><EFBFBD> //////////////////////
ADOQueryCmd.Connection.CommitTrans;
Result := True;
except
Result := False;
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
end;
procedure TfrmYarnInfoInPut.TbAddClick(Sender: TObject);
begin
try
frmYarnCFInfoSel := TfrmYarnCFInfoSel.Create(Application);
with frmYarnCFInfoSel do
begin
if ShowModal = 1 then
begin
frmYarnCFInfoSel.CDS_1.First;
while not frmYarnCFInfoSel.CDS_1.Eof do
begin
if frmYarnCFInfoSel.CDS_1.FieldByName('SSel').Value = true then
begin
with Self.CDS_1 do
begin
Append;
FieldByName('DH').Value := frmYarnCFInfoSel.CDS_1.fieldbyname('DH').value;
FieldByName('CF').Value := frmYarnCFInfoSel.CDS_1.fieldbyname('CF').value;
FieldByName('serialno').Value := Self.CDS_1.RecordCount + 1;
Post;
end;
end;
frmYarnCFInfoSel.CDS_1.Next;
end;
end;
end;
finally
frmYarnCFInfoSel.Free;
end;
end;
procedure TfrmYarnInfoInPut.TbDelClick(Sender: TObject);
var
i: Integer;
begin
if not CDS_1.IsEmpty then
begin
if Application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', 32 + 4) = IDYES then
begin
if Trim(CDS_1.fieldbyname('CFID').AsString) <> '' then
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete BS_Yarn_Info_CF where CFID=' + quotedStr(Trim(CDS_1.fieldbyname('CFID').AsString)));
ExecSQL;
end;
end;
CDS_1.Delete;
end
else
exit;
i := 0;
CDS_1.First;
while not CDS_1.Eof do
begin
i := i + 1;
CDS_1.Edit;
CDS_1.fieldByName('serialno').value := i;
CDS_1.Post;
CDS_1.Next;
end;
end
else
begin
Application.MessageBox('<27>޿<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
Exit;
end;
end;
procedure TfrmYarnInfoInPut.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmYarnInfoInPut.FormCreate(Sender: TObject);
begin
inherited;
try
with ADOConnection1 do
begin
Connected := false;
ConnectionString := DConString;
Connected := true;
end;
ADOQueryBaseCmd.Connection := ADOConnection1;
ADOQueryBaseTemp.Connection := ADOConnection1;
except
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
end;
end;
procedure TfrmYarnInfoInPut.FormShow(Sender: TObject);
var
fsj: string;
begin
inherited;
// fsj := ' select Code=ZDYNo,Name=ZDYName from KH_ZDY where Type=''YType'' and MainType=''ɴ<>ߵ<EFBFBD><DFB5><EFBFBD>'' ';
// SInitTcxComBoxBySql(ADOQueryTemp, Y_Type, false, fsj);
//
// fsj := ' select Code=ZDYNo,Name=ZDYName from KH_ZDY where Type=''Y_Spec'' and MainType=''ɴ<>ߵ<EFBFBD><DFB5><EFBFBD>'' ';
// SInitTcxComBoxBySql(ADOQueryTemp, Y_Spec, false, fsj);
//
// fsj := ' select Code=ZDYNo,Name=ZDYName from KH_ZDY where Type=''Y_Composition'' and MainType=''ɴ<>ߵ<EFBFBD><DFB5><EFBFBD>'' ';
// SInitTcxComBoxBySql(ADOQueryTemp, Y_Composition, false, fsj);
//
// fsj := ' select Code=ZDYNo,Name=ZDYName from KH_ZDY where Type=''Y_Color'' and MainType=''ɴ<>ߵ<EFBFBD><DFB5><EFBFBD>'' ';
// SInitTcxComBoxBySql(ADOQueryTemp, Y_Color, false, fsj);
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add(' select * from BS_Yarn_Info ');
sql.Add(' where BYIID=''' + Trim(FBYIID) + '''');
Open;
end;
SCSHData(ADOQueryTemp, ScrollBox1, 2);
initCFGrid();
if FBYIID = '' then
begin
end;
end;
procedure TfrmYarnInfoInPut.Y_ColorDblClick(Sender: TObject);
begin
TcxButtonEdit(Sender).Text := '';
TcxButtonEdit(Sender).Properties.LookupItems.Text := '';
end;
procedure TfrmYarnInfoInPut.Y_ColorPropertiesChange(Sender: TObject); //<2F><>ɫ
begin
UpdateYarnName;
end;
procedure TfrmYarnInfoInPut.Y_CompositionPropertiesChange(Sender: TObject); //<2F>ɷ<EFBFBD>
begin
UpdateYarnName;
end;
procedure TfrmYarnInfoInPut.ParentCoNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
fsj: string;
FWZ: Integer;
begin
fsj := Trim(TcxButtonEdit(Sender).Hint);
FWZ := Pos('/', fsj);
try
frmZDYHelp := TfrmZDYHelp.Create(Application);
with frmZDYHelp do
begin
MainType := <>ߵ<EFBFBD><DFB5><EFBFBD>';
flag := Copy(fsj, 1, FWZ - 1);
flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
if ShowModal = 1 then
begin
TcxButtonEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
end;
end;
finally
frmZDYHelp.Free;
end;
end;
procedure TfrmYarnInfoInPut.TBSaveClick(Sender: TObject);
begin
// if Trim(Y_Code.Text) = '' then
// begin
// Application.MessageBox('<27><><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
// Exit;
// end;
ToolBar1.SetFocus;
Y_Name.text := Trim(Y_Composition.text) + Trim(ZS.text) + 'S' + Trim(Y_Color.text) + Trim(FF.text); //+ Trim(CJ.text)
if Trim(Y_Name.Text) = '' then
begin
Application.MessageBox('<27><><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
Exit;
end;
if Trim(Denier.Text) <> '' then
begin
if StrToFloatdef(Denier.Text, 0) = 0 then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>D<EFBFBD><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
Exit;
end;
end;
if not CheckBL() then
begin
Exit;
end;
if SaveData() then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!', '<27><>ʾ', 0);
ModalResult := 1;
Exit;
end;
end;
procedure TfrmYarnInfoInPut.TextEdit(Sender: TObject);
var
s: string;
fValue: Double;
begin
s := TcxTextEdit(Sender).EditingText;
if (s <> '') and (s[Length(s)] <> '%') then
begin
try
// <20><><EFBFBD>Խ<EFBFBD><D4BD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fValue := StrToFloat(s);
// if fValue < 0 then
// begin
// s := '0';
// end;
// if fValue > 100 then
// begin
// s := '100';
// end;
// <20><>ʽ<EFBFBD><CABD>Ϊ<EFBFBD><CEAA>λС<CEBB><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱٷֺ<D9B7>
// Tv1.Controller.FocusedColumn.EditValue := FormatFloat('0.00', fValue) + '%';
Tv1.Controller.FocusedColumn.EditValue := s + '%';
Y_Composition.Text := '';
CDS_1.First;
while not CDS_1.Eof do
begin
if Y_Composition.Text = '' then
begin
Y_Composition.Text := CDS_1.FieldByName('BL').AsString + CDS_1.FieldByName('CF').AsString;
end
else
begin
Y_Composition.Text := Y_Composition.Text + ' ' + CDS_1.FieldByName('BL').AsString + CDS_1.FieldByName('CF').AsString;
end;
CDS_1.Next;
end;
except
on E: EConvertError do
begin
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱٷֺ<D9B7>
Tv1.Controller.FocusedColumn.EditValue := s + '%';
end;
end;
end;
end;
function TfrmYarnInfoInPut.CheckBL(): Boolean;
var
mBL: Double;
msubBL: Double;
begin
Result := False;
msubBL := 0;
CDS_1.First;
while not CDS_1.Eof do
begin
// һ<>д<EFBFBD><D0B4><EFBFBD><EBB4A6><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>%<25>Ų<EFBFBD><C5B2><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
if not TryStrToFloat(StringReplace(CDS_1.FieldByName('BL').AsString, '%', '', [rfReplaceAll]), mBL) then
begin
ShowMessage('<27><><EFBFBD><EFBFBD> ' + CDS_1.FieldByName('DH').AsString + ' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>');
Exit;
end
else
begin
msubBL := msubBL + mBL;
end;
if (mBL <= 0) or (mBL > 100) then
begin
ShowMessage('<27><><EFBFBD><EFBFBD> ' + CDS_1.FieldByName('DH').AsString + ' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0-100% ֮<><D6AE>');
Exit;
end;
CDS_1.Next;
end;
if msubBL > 100 then
begin
ShowMessage('<27><><EFBFBD><EFBFBD>֮<EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD><EFBFBD> 0-100% ֮<><D6AE>');
Exit;
end;
Result := True;
end;
procedure TfrmYarnInfoInPut.Y_NameClick(Sender: TObject);
begin
Y_Composition.Style.Color := clMoneyGreen;
ZS.Style.Color := clMoneyGreen;
Y_Color.Style.Color := clMoneyGreen;
FF.Style.Color := clMoneyGreen;
// CJ.Style.Color := clMoneyGreen;
end;
procedure TfrmYarnInfoInPut.Y_NameExit(Sender: TObject);
begin
Y_Composition.Style.Color := clWhite;
ZS.Style.Color := clWhite;
Y_Color.Style.Color := clWhite;
FF.Style.Color := clWhite;
// CJ.Style.Color := clWhite;
end;
procedure TfrmYarnInfoInPut.Y_SpecPropertiesChange(Sender: TObject);
begin
Y_Name.text := Trim(Y_Composition.text) + Trim(ZS.text) + 'S' + Trim(Y_Color.text) + Trim(FF.text); //+ Trim(CJ.text)
end;
procedure TfrmYarnInfoInPut.ZSClick(Sender: TObject);
begin
Denier.Style.Color := clMoneyGreen;
end;
procedure TfrmYarnInfoInPut.ZSExit(Sender: TObject);
begin
Denier.Style.Color := clWhite;
end;
procedure TfrmYarnInfoInPut.ZSPropertiesChange(Sender: TObject);
begin
UpdateYarnName;
end;
procedure TfrmYarnInfoInPut.ZSPropertiesEditValueChanged(Sender: TObject);
begin
Denier.text := floattostr(roundfloat(5315.5 / strtofloatdef(ZS.text, 0), 0));
end;
procedure TfrmYarnInfoInPut.UpdateYarnName;
begin
Y_Name.Text := Trim(Y_Composition.Text) + Trim(ZS.Text) + 'S' + Trim(Y_Color.Text) + Trim(FF.Text); // + Trim(CJ.Text)
end;
end.