RTFormwork/项目代码/RTBasicsV1/E01梭织生产计划/U_TatCardInPut.pas
“ddf” 61630656e9 1
2024-07-07 09:35:27 +08:00

463 lines
14 KiB
ObjectPascal
Raw Permalink 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_TatCardInPut;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxCheckBox,
BtnEdit, cxPC, MovePanel, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
dxBarBuiltInMenu, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
U_BaseList, Vcl.Menus, U_BaseInput, System.ImageList, Vcl.ImgList;
type
TfrmTatCardInPut = class(TfrmBaseInput)
GPM_1: TcxGridPopupMenu;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
DS_1: TDataSource;
CDS_1: TClientDataSet;
DS_2: TDataSource;
CDS_2: TClientDataSet;
GPM_2: TcxGridPopupMenu;
Panel4: TPanel;
PM_1: TPopupMenu;
PM_2: TPopupMenu;
Panel5: TPanel;
Panel2: TPanel;
Label10: TLabel;
Label11: TLabel;
Button3: TButton;
edtMachNo: TEdit;
edtCardQty: TEdit;
Repairer: TBtnEditC;
Panel1: TPanel;
N2: TMenuItem;
cxStyleRepository1: TcxStyleRepository;
cxStyle1: TcxStyle;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid2: TcxGrid;
TV2: TcxGridDBTableView;
TV2Column1: TcxGridDBColumn;
TV2Column2: TcxGridDBColumn;
TV2Column3: TcxGridDBColumn;
TV2Column4: TcxGridDBColumn;
TV2Column5: TcxGridDBColumn;
TV2Column6: TcxGridDBColumn;
cxGridLevel1: TcxGridLevel;
Label3: TLabel;
MCNO: TEdit;
ToolBar1: TToolBar;
ToolButton12: TToolButton;
TBClose: TToolButton;
Label7: TLabel;
BatchNo: TEdit;
TV2Column7: TcxGridDBColumn;
Panel3: TPanel;
Label1: TLabel;
Label12: TLabel;
Label13: TLabel;
Label21: TLabel;
edtName: TEdit;
edtCode: TEdit;
edtConNo: TEdit;
edtWAPPS: TEdit;
Label8: TLabel;
Label9: TLabel;
edtYAPPS: TEdit;
Tv1Column1: TcxGridDBColumn;
Tv1Column2: TcxGridDBColumn;
Label4: TLabel;
isDY: TComboBox;
Tv1Column3: TcxGridDBColumn;
Tv1Column4: TcxGridDBColumn;
Button1: TButton;
ToolButton1: TToolButton;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBCloseClick(Sender: TObject);
procedure TBFindClick(Sender: TObject);
procedure TBRafreshClick(Sender: TObject);
procedure MCNOChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cxTabControl1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Tv1DblClick(Sender: TObject);
procedure ToolButton12Click(Sender: TObject);
procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
procedure RepairerBtnDnClick(Sender: TObject);
procedure RepairerBtnUpClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
private
procedure InitOrd();
procedure InitGrid1();
procedure InitGrid2();
{ Private declarations }
public
FMainId, FSubId, FWBCID: string;
{ Public declarations }
end;
var
frmTatCardInPut: TfrmTatCardInPut;
implementation
uses
U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_TatPlanSel;
{$R *.dfm}
procedure TfrmTatCardInPut.InitOrd();
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' select A.*,B.* ');
sql.Add(' ,YAPPS=ISNULL((select count(*) from Tat_Plan_Card X where X.MainId=A.MainId and isnull(Status,''0'') <>''-1'' ),0)');
sql.Add(' ,WAPPS=OrdPiece-ISNULL((select count(*) from Tat_Plan_Card X where X.MainId=A.MainId and isnull(Status,''0'') <>''-1''),0)');
sql.Add(' from Tat_Plan_Main A');
sql.Add(' inner join Tat_Plan_Sub B on A.MainId=B.MainId ');
sql.Add(' where B.SubId=' + QuotedStr(FSubId));
Open;
end;
edtConNo.Text := ADOQueryTemp.FieldByName('OrderNo').AsString;
edtCode.Text := ADOQueryTemp.FieldByName('C_Code').AsString;
edtName.Text := ADOQueryTemp.FieldByName('C_Name').AsString;
edtYAPPS.Text := ADOQueryTemp.FieldByName('YAPPS').AsString;
edtWAPPS.Text := ADOQueryTemp.FieldByName('WAPPS').AsString;
end;
procedure TfrmTatCardInPut.RepairerBtnDnClick(Sender: TObject);
begin
Repairer.Text := '';
end;
procedure TfrmTatCardInPut.RepairerBtnUpClick(Sender: TObject);
begin
try
frmZDYHelp := TfrmZDYHelp.Create(Application);
with frmZDYHelp do
begin
flag := 'Repairer';
flagname := '<27><><EFBFBD>޹<EFBFBD>';
if ShowModal = 1 then
begin
Repairer.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
end;
end;
finally
frmZDYHelp.Free;
end;
end;
procedure TfrmTatCardInPut.InitGrid1();
var
fwhere: string;
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Close;
sql.Clear;
sql.Add(' select * ');
sql.Add(' ,ZWJYPS=(select count(X.Loom) from Tat_Plan_Card X where X.Loom =AA.MCNO and isnull(Status,''0'')=''0'') ');
sql.Add(' ,BWJYPS=(select count(X.Loom) from Tat_Plan_Card X where X.Loom =AA.MCNO and isnull(Status,''0'')=''0'' and MainID=''' + trim(FMainID) + ''')');
sql.Add(' from (select A.MCNO,ISAP=''0'' from BS_Machine A where EXISTS (select Loom from Tat_Plan_Card X where X.Loom = A.MCNO and X.MainID=''' + trim(FMainID) + ''')');
sql.Add(' UNION ');
sql.Add(' select A.MCNO,ISAP=''1'' from BS_Machine A where not EXISTS (select Loom from Tat_Plan_Card X where X.Loom = A.MCNO and X.MainID=''' + trim(FMainID) + ''')');
sql.Add(' ) AA Order BY ISAP,MCNO');
// ShowMessage(sql.text);
Open;
end;
SCreateCDS(ADOQueryMain, CDS_1);
SInitCDSData(ADOQueryMain, CDS_1);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmTatCardInPut.InitGrid2();
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' select COUNT(*) AS APPS,Loom,isnull(Repairer,'''') AS Repairer,isnull(BatchNo,'''') AS BatchNo ');
sql.Add(',PCDate=(select top 1 CONVERT(VARCHAR(10),X.PCDate,120) from Tat_Plan_Card X where X.Loom=A.Loom ');
sql.Add(' and isnull(X.Repairer,'''') = isnull(A.Repairer,'''') and isnull(X.BatchNo,'''') = isnull(A.BatchNo,'''') and isnull(Status,''0'') <>''-1'' ORDER BY PCDate ) ');
sql.Add(' ,DYPS=(select count(*) from Tat_Plan_Card X where X.Loom=A.Loom and PrtCount > 0 and isnull(Status,''0'') <>''-1'' ');
sql.Add(' and isnull(X.Repairer,'''') = isnull(A.Repairer,'''') and isnull(X.BatchNo,'''') = isnull(A.BatchNo,'''') )');
sql.Add(' ,JYPS=(select count(*) from Tat_Plan_Card X where X.Loom=A.Loom and isnull(X.Status,''0'') = ''1'' ');
sql.Add(' and isnull(X.Repairer,'''') = isnull(A.Repairer,'''') and isnull(X.BatchNo,'''') = isnull(A.BatchNo,'''') )');
sql.Add(' from Tat_Plan_Card A where MainId =''' + trim(FMainId) + '''');
sql.Add(' GROUP BY Loom,isnull(Repairer,''''),isnull(BatchNo,'''') ');
// ShowMessage(sql.text);
Open;
end;
SCreateCDS(ADOQueryTemp, CDS_2);
SInitCDSData(ADOQueryTemp, CDS_2);
end;
procedure TfrmTatCardInPut.FormDestroy(Sender: TObject);
begin
inherited;
frmTatCardInPut := nil;
end;
procedure TfrmTatCardInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := caFree;
end;
procedure TfrmTatCardInPut.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmTatCardInPut.TBFindClick(Sender: TObject);
begin
if ADOQueryMain.Active = False then
Exit;
SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
SCreateCDS(ADOQueryMain, CDS_1);
SInitCDSData(ADOQueryMain, CDS_1);
end;
procedure TfrmTatCardInPut.TBRafreshClick(Sender: TObject);
begin
InitGrid1();
InitGrid2();
end;
procedure TfrmTatCardInPut.MCNOChange(Sender: TObject);
begin
if ADOQueryMain.Active = False then
Exit;
SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
SCreateCDS(ADOQueryMain, CDS_1);
SInitCDSData(ADOQueryMain, CDS_1);
end;
procedure TfrmTatCardInPut.FormShow(Sender: TObject);
begin
inherited;
ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
ReadCxGrid(trim(self.Caption) + 'Tv2', Tv2, ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
InitOrd();
InitGrid1();
InitGrid2();
end;
procedure TfrmTatCardInPut.cxTabControl1Change(Sender: TObject);
begin
InitGrid1();
end;
procedure TfrmTatCardInPut.Button1Click(Sender: TObject);
begin
edtMachNo.text := '';
end;
procedure TfrmTatCardInPut.Button3Click(Sender: TObject);
var
maxno, maxPCId, WSql: string;
FStrs: TStringList;
i, j, MPCNo: integer;
begin
if edtMachNo.Text = '' then
Exit;
if StrToIntdef(edtCardQty.Text, 0) = 0 then
Exit;
try
FStrs := TStringList.Create();
ExtractStrings([';'], [' '], PChar(edtMachNo.Text), FStrs);
ADOQueryCmd.Connection.BeginTrans;
// with ADOQueryTemp do
// begin
// Close;
// sql.Clear;
// sql.Add(' select CardQty=OrdPiece-ISNULL((select sum(CardQty) from Tat_Plan_Mach AA where AA.SubId=B.SubId),0)');
// sql.Add(' from Tat_Plan_Sub B ');
// sql.Add(' where B.SubId=' + QuotedStr(Trim(FSubId)));
// Open;
// end;
///////////////<2F>ж<EFBFBD><D0B6>Ƿ񳬳<C7B7><F1B3ACB3><EFBFBD><EFBFBD><EFBFBD>//////////////////
if FStrs.Count * StrToIntdef(edtCardQty.Text, 0) > StrToIntdef(edtWAPPS.text, 0) then
begin
raise Exception.Create('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!');
end;
///////////////<2F>ж<EFBFBD><D0B6>Ƿ񳬳<C7B7><F1B3ACB3><EFBFBD><EFBFBD><EFBFBD>//////////////////
for i := 0 to FStrs.Count - 1 do
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select PCNo=isnull(Max(PCNo),0) ');
sql.Add('from Tat_Plan_Card A ');
sql.Add('where isnull(Status,''0'') <>''-1'' and A.MainID=' + Quotedstr(Trim(FMainID)));
sql.Add('and A.Loom=' + Quotedstr(Trim(FStrs[i])));
Open;
end;
if ADOQueryTemp.IsEmpty then
MPCNo := 1
else
MPCNo := ADOQueryTemp.FieldByName('PCNo').AsInteger + 1;
////////////////// <20><><EFBFBD>벼Ʊ //////////////////////
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add(' insert into Tat_Plan_Card(MainId,SubId,WBCID,Loom,PCId,PCNo,PCDate,Filler,BatchNo,Repairer) values');
for j := 1 to StrToIntdef(edtCardQty.Text, 0) do
begin
if GetLSNo(ADOQueryTemp, maxPCId, 'TPC', 'Tat_Plan_Card', 3, 1) = False then
begin
raise Exception.Create(<><C8A1>Ʊ<EFBFBD><C6B1>ˮ<EFBFBD><CBAE>ʧ<EFBFBD><CAA7>!');
end;
if j > 1 then
sql.Add(',');
sql.Add(' (' + Quotedstr(Trim(FMainId)));
sql.Add(',' + Quotedstr(Trim(FSubId)));
sql.Add(',' + Quotedstr(Trim(FWBCID)));
sql.Add(',' + Quotedstr(Trim(FStrs[i])));
sql.Add(',' + Quotedstr(maxPCId));
sql.Add(',' + Quotedstr(IntToStr(MPCNo)));
sql.Add(',getdate() ');
sql.Add(',' + Quotedstr(Trim(DName)));
sql.Add(',' + Quotedstr(Trim(BatchNo.Text)));
sql.Add(',' + Quotedstr(Trim(Repairer.Text)));
sql.Add(' )');
MPCNo := MPCNo + 1;
if WSql <> '' then
begin
WSql := WSql + ',' + QuotedStr(Trim(maxPCId));
end
else
begin
WSql := QuotedStr(Trim(maxPCId));
end;
end;
ExecSQL;
end;
////////////////// <20><><EFBFBD>벼Ʊ //////////////////////
end;
ADOQueryCmd.Connection.CommitTrans;
FStrs.Free;
except
FStrs.Free;
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
if trim(isDY.text) = '<27><>' then
begin
try
frmLabelPrint := TfrmLabelPrint.Create(Application);
with frmLabelPrint do
begin
FPreviewPrint := False;
FLMType := 'TatPlanCard';
FFiltration1 := WSql;
if ShowModal = 1 then
begin
// Self.InitGrid();
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('update Tat_Plan_Card ');
sql.Add('set PRTer=' + quotedstr(DName));
sql.Add(', PRTCount=PRTCount+1');
sql.Add(', PRTDate=getdate()');
sql.Add(' where PCID in (' + WSql + ')');
ExecSQL;
end;
end;
end;
finally
frmLabelPrint.Free;
end;
end;
InitOrd();
InitGrid1();
InitGrid2();
edtMachNo.text := '';
end;
procedure TfrmTatCardInPut.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
if '0' = AViewInfo.GridRecord.Values[Tv1Column2.Index] then
ACanvas.Brush.Color := $66ff66;
end;
procedure TfrmTatCardInPut.Tv1DblClick(Sender: TObject);
var
FStrs: TStringList;
begin
try
FStrs := TStringList.Create();
ExtractStrings([';'], [' '], PChar(edtMachNo.Text), FStrs);
if FStrs.IndexOf(Trim(CDS_1.FieldByName('MCNO').AsString)) < 0 then
edtMachNo.Text := edtMachNo.Text + TRIM(CDS_1.FieldByName('MCNO').AsString) + ';';
finally
FStrs.Free
end;
end;
procedure TfrmTatCardInPut.ToolButton12Click(Sender: TObject);
begin
WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
WriteCxGrid(trim(self.Caption) + 'Tv2', Tv2, ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
end;
procedure TfrmTatCardInPut.ToolButton1Click(Sender: TObject);
begin
try
frmTatPlanSel := TfrmTatPlanSel.Create(Application);
with frmTatPlanSel do
begin
if ShowModal = 1 then
begin
self.FMainId := Trim(frmTatPlanSel.CDS_1.fieldbyname('MainId').AsString);
self.FSubId := Trim(frmTatPlanSel.CDS_1.fieldbyname('SubId').AsString);
end;
end;
finally
frmTatPlanSel.Free;
end;
InitOrd();
InitGrid1();
InitGrid2();
end;
end.