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

492 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_KnitCardInPut;
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, StrUtils;
type
TfrmKnitCardInPut = 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;
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 N2Click(Sender: TObject);
procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
procedure RepairerBtnDnClick(Sender: TObject);
procedure RepairerBtnUpClick(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
private
procedure InitOrd();
procedure InitGrid1();
procedure InitGrid2();
{ Private declarations }
public
FMainId, FSubId: string;
{ Public declarations }
end;
var
frmKnitCardInPut: TfrmKnitCardInPut;
implementation
uses
U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_KnitPlanSel;
{$R *.dfm}
procedure TfrmKnitCardInPut.InitOrd();
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' select A.*,B.*');
sql.Add(' ,YAPPS=ISNULL((select count(*) from Knit_Plan_Card X where X.MainId=A.MainId),0)');
sql.Add(' ,WAPPS=OrdPiece-ISNULL((select count(*) from Knit_Plan_Card X where X.MainId=A.MainId),0)');
sql.Add(' from knit_Plan_Main A');
sql.Add(' inner join knit_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;
Repairer.Text := ADOQueryTemp.FieldByName('Repairer').AsString;
end;
procedure TfrmKnitCardInPut.N2Click(Sender: TObject);
begin
with ADOQueryTemp do
begin
close;
sql.Clear;
sql.Add(' select * from knit_Plan_Card A where A.PRTCount>1 and A.PMID=' + quotedstr(trim(CDS_2.fieldbyname('PMID').AsString)));
Open;
end;
if not ADOQueryTemp.IsEmpty then
begin
Application.MessageBox('<27>Ѵ<EFBFBD>ӡ<EFBFBD><D3A1>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>!', '<27><>ʾ', 0);
Exit;
end;
with ADOQueryCmd do
begin
close;
sql.Clear;
sql.Add('delete knit_Plan_Mach ');
sql.Add('where PMID=' + quotedstr(trim(CDS_2.fieldbyname('PMID').AsString)));
sql.Add('delete knit_Plan_Card ');
sql.Add('where PMID=' + quotedstr(trim(CDS_2.fieldbyname('PMID').AsString)));
execsql;
end;
CDS_2.Delete;
end;
procedure TfrmKnitCardInPut.RepairerBtnDnClick(Sender: TObject);
begin
Repairer.Text := '';
end;
procedure TfrmKnitCardInPut.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 TfrmKnitCardInPut.InitGrid1();
var
fwhere: string;
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Close;
sql.Clear;
sql.Add(' select * ');
sql.Add(' ,ZWJYPS=(select count(*) from Knit_Plan_Card X where X.Loom =AA.MCNO and isnull(Status,''0'')=''0'') ');
sql.Add(' ,BWJYPS=(select count(*) from Knit_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 Knit_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 Knit_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 TfrmKnitCardInPut.InitGrid2();
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' select Loom,BatchNo,PCDate=CONVERT(VARCHAR(10),PCDate,120)');
sql.Add(' ,APPS=COUNT(pcid) ');
sql.Add(',DYPS=SUM(case when Status = ''1'' then 1 else 0 end) ');
sql.Add(',JYPS=SUM(case when Status = ''1'' then 1 else 0 end) ');
sql.Add(' from Knit_Plan_Card A where MainId =''' + trim(FMainId) + '''');
sql.Add(' GROUP BY Loom,BatchNo,CONVERT(VARCHAR(10),PCDate,120) ');
Open;
end;
SCreateCDS(ADOQueryTemp, CDS_2);
SInitCDSData(ADOQueryTemp, CDS_2);
end;
procedure TfrmKnitCardInPut.FormDestroy(Sender: TObject);
begin
inherited;
frmKnitCardInPut := nil;
end;
procedure TfrmKnitCardInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := caFree;
end;
procedure TfrmKnitCardInPut.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmKnitCardInPut.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 TfrmKnitCardInPut.TBRafreshClick(Sender: TObject);
begin
InitGrid1();
InitGrid2();
end;
procedure TfrmKnitCardInPut.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 TfrmKnitCardInPut.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 TfrmKnitCardInPut.cxTabControl1Change(Sender: TObject);
begin
InitGrid1();
end;
procedure TfrmKnitCardInPut.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;
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 Knit_Plan_Card A ');
sql.Add('where 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>벼Ʊ //////////////////////
if GetLSNo(ADOQueryTemp, maxno, 'PC', 'knit_Plan_Mach', 2, 1) = False then
begin
raise Exception.Create(<><C8A1>Ʊ<EFBFBD><C6B1>ˮ<EFBFBD><CBAE>ʧ<EFBFBD><CAA7>!');
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add(' insert into Knit_Plan_Card(MainId,SubId,Loom,PCId,PCNo,PCDate,Filler,BatchNo) values');
for j := 1 to StrToIntdef(edtCardQty.Text, 0) do
begin
maxPCId := maxno + RightStr('00' + inttostr(j), 3);
if j > 1 then
sql.Add(',');
sql.Add(' (' + Quotedstr(Trim(FMainId)));
sql.Add(',' + Quotedstr(Trim(FSubId)));
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(' )');
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;
with ADOQueryCmd do
begin
close;
sql.Clear;
sql.Add('update knit_Plan_Main SET status=''9'',chker=''' + trim(DName) + ''',Chktime=getdate() ');
sql.Add('where isnull(status,''0'')=''0'' and mainID=' + quotedstr(trim(FMainID)));
// sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
// sql.Add(' ' + quotedstr(trim(DName)));
// sql.Add(',getdate() ');
// sql.Add(',' + quotedstr(trim(self.Caption)));
// sql.Add(',' + quotedstr(trim('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ')));
// sql.Add(',' + quotedstr(trim('<27>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD>ţ<EFBFBD>' + trim(edtConNo.Text))));
// sql.Add(',' + quotedstr(trim('<27>ɹ<EFBFBD>')));
// sql.Add(')');
execsql;
end;
ADOQueryCmd.Connection.CommitTrans;
FStrs.Free;
except
FStrs.Free;
ADOQueryCmd.Connection.RollbackTrans;
if GetLSNo(ADOQueryTemp, maxPCId, 'PC', 'knit_Plan_Mach', 3, 1) = False then
begin
// raise Exception.Create('ȡ<><C8A1>Ʊ<EFBFBD><C6B1>ˮ<EFBFBD><CBAE>ʧ<EFBFBD><CAA7>!');
end;
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 := 'KnitPlanCard';
FFiltration1 := WSql;
if ShowModal = 1 then
begin
// Self.InitGrid();
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('update Knit_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;
InitGrid1();
InitGrid2();
edtMachNo.text := '';
end;
procedure TfrmKnitCardInPut.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 TfrmKnitCardInPut.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 TfrmKnitCardInPut.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 TfrmKnitCardInPut.ToolButton1Click(Sender: TObject);
begin
try
frmKnitPlanSel := TfrmKnitPlanSel.Create(Application);
with frmKnitPlanSel do
begin
if ShowModal = 1 then
begin
self.FMainId := Trim(frmKnitPlanSel.CDS_1.fieldbyname('MainId').AsString);
self.FSubId := Trim(frmKnitPlanSel.CDS_1.fieldbyname('SubId').AsString);
end;
end;
finally
frmKnitPlanSel.Free;
end;
InitOrd();
InitGrid1();
InitGrid2();
end;
end.