unit U_ClothSCDCGAnPai; 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, RM_BarCode, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter; type TfrmClothSCDCGAnPai = class(TForm) ToolBar1: TToolBar; TBRafresh: TToolButton; TBClose: TToolButton; Panel1: TPanel; cxGridPopupMenu1: TcxGridPopupMenu; ADOQueryCmd: TADOQuery; ADOQueryMain: TADOQuery; ADOQueryTemp: TADOQuery; Label3: TLabel; ConNo: TEdit; CDS_PRT: TClientDataSet; RM2: TRMGridReport; RMDBPRT: TRMDBDataSet; ADOQueryPrint: TADOQuery; DSAnPai: TDataSource; CDS_AnPai: TClientDataSet; cxGridPopupMenu2: TcxGridPopupMenu; ZhuanQty: TEdit; Label9: TLabel; Panel2: TPanel; CarNo: TEdit; Label1: TLabel; cxGrid3: TcxGrid; Tv3: TcxGridDBTableView; cxGridDBColumn8: TcxGridDBColumn; cxGridLevel2: TcxGridLevel; v3Column1: TcxGridDBColumn; v3Column2: TcxGridDBColumn; Label2: TLabel; C_CodeName: TEdit; Label6: TLabel; PS: TEdit; Label7: TLabel; JXPerson: TBtnEditA; Button2: TButton; Button1: TButton; cxGrid2: TcxGrid; Tv2: TcxGridDBTableView; v2Column2: TcxGridDBColumn; cxGridDBColumn1: TcxGridDBColumn; cxGridDBColumn2: TcxGridDBColumn; cxGridDBColumn3: TcxGridDBColumn; cxGridDBColumn6: TcxGridDBColumn; v2Column1: TcxGridDBColumn; v2Column4: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; DataSource3: TDataSource; ClientDataSet3: TClientDataSet; v3Column3: TcxGridDBColumn; v3Column4: TcxGridDBColumn; v3Column5: TcxGridDBColumn; Label4: TLabel; C_Code: TEdit; v3Column6: TcxGridDBColumn; Label5: TLabel; Label8: TLabel; APPS: TEdit; PSSX: TEdit; Label10: TLabel; v2Column3: TcxGridDBColumn; v3Column7: TcxGridDBColumn; Button3: TButton; v3Column8: TcxGridDBColumn; v3Column9: TcxGridDBColumn; Label11: TLabel; ChouZhen: TEdit; v3Column10: TcxGridDBColumn; v3Column11: TcxGridDBColumn; Label12: TLabel; CheJian: TComboBox; v3Column12: TcxGridDBColumn; v3Column13: TcxGridDBColumn; v3Column14: TcxGridDBColumn; v3Column15: TcxGridDBColumn; v3Column16: TcxGridDBColumn; v3Column17: TcxGridDBColumn; Label13: TLabel; v3Column18: TcxGridDBColumn; v3Column19: TcxGridDBColumn; Label14: TLabel; APBatchNo: TEdit; v2Column5: TcxGridDBColumn; v3Column20: TcxGridDBColumn; v3Column21: TcxGridDBColumn; Button4: TButton; cv3Column22: TcxGridDBColumn; cxStyleRepository1: TcxStyleRepository; cxStyle1: TcxStyle; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBCloseClick(Sender: TObject); procedure TBRafreshClick(Sender: TObject); procedure ConNoChange(Sender: TObject); procedure FormShow(Sender: TObject); procedure JXPersonBtnClick(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure cxTabControl1Change(Sender: TObject); procedure Button3Click(Sender: TObject); procedure v3Column8PropertiesEditValueChanged(Sender: TObject); procedure PSKeyPress(Sender: TObject; var Key: Char); procedure Button4Click(Sender: TObject); procedure ConNoKeyPress(Sender: TObject; var Key: Char); procedure C_CodeNameKeyPress(Sender: TObject; var Key: Char); procedure Tv3FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); private FInt, PFInt: Integer; FFMainID, BPFlag: string; procedure InitGrid(); procedure InitForm(); function SaveDataAP(): Boolean; { Private declarations } public canshu1: string; { Public declarations } end; implementation uses U_DataLink, U_Fun, U_ZDYHelp; {$R *.dfm} procedure TfrmClothSCDCGAnPai.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; WriteCxGrid('DCG13', Tv3, '坯布生产2'); end; procedure TfrmClothSCDCGAnPai.TBCloseClick(Sender: TObject); begin Close; WriteCxGrid('DCG12', Tv2, '坯布生产'); WriteCxGrid('DCG13', Tv3, '坯布生产'); end; procedure TfrmClothSCDCGAnPai.InitGrid(); begin FFMainID := ''; try ADOQueryMain.DisableControls; with ADOQueryMain do begin // Filtered := False; Close; sql.Clear; sql.Add('select A.*,B.ConNo,C.gongyi,B.GCCode,C.C_CodeName,C.ZhenCun,C_Qty=C.ZSCQty,C.C_Code,PiQty=C.ZSCPS '); sql.Add(',C.pikgqty,B.LabName,C.BatchNoHZ,C.ChouZhen,C.CarType,C.C_Spec,C.C_Color'); sql.Add(',CPName=( select TOP 1 CPName from CP_YDang X inner join CP_Type Y on X.CYType=Y.CPID where X.CYName=C.C_CodeName )'); sql.Add(',APPS=(select count(*) from JYCon_Sub_AnPai JSA where JSA.MainId=A.MainId and JSA.CarNo=A.CarNo )'); sql.Add(',APPSHZ=(select count(*) from JYCon_Sub_AnPai JSA where JSA.MainId=A.MainId )'); sql.Add(',JYPS=isnull((select Count(*) from WFB_MJJY_PB CR where CR.MainId=A.MainId and CR.CarNo=A.CarNo ),0) '); sql.Add(',JXPerson10=(select Top 1 JXPerson from JYCon_Sub_AnPai AP '); sql.Add(' where AP.MainId=B.MainId and AP.CarNo=A.CarNo and isnull(AP.JXPerson,'''')<>'''' Order by AP.FillTime Desc)'); if BPFlag = 'BS' then sql.Add(' , CustomerNoName=(select TOP 1 X.CoHRName from Company X where X.CoName=B.KHNAME and CoType=''客户'') ') else sql.Add(' ,B.KHNAME CustomerNoName '); sql.Add(' from Cloth_JiTai A'); sql.Add(' inner join Cloth_Main B on A.MainId=B.MainId'); sql.Add(' inner join Cloth_Sub C on A.SubId=C.SubId'); sql.Add(' where A.StopFlag=0 and B.EndFlag=0 '); sql.Add(' order by A.CarNo '); Open; end; SCreateCDS20(ADOQueryMain, ClientDataSet3); SInitCDSData20(ADOQueryMain, ClientDataSet3); ClientDataSet3.EnableControls; finally ADOQueryMain.EnableControls; end; end; procedure TfrmClothSCDCGAnPai.InitForm(); var fsj: string; begin BPFlag := Trim(DParameters1); ReadCxGrid('DCG12', Tv2, '坯布生产'); ReadCxGrid('DCG13', Tv3, '坯布生产2'); fsj := 'select distinct Code=Null,Name=MCCJ from Machine Group by MCCJ '; SInitComBoxBySql(ADOQueryTemp, CheJian, False, fsj); InitGrid(); end; procedure TfrmClothSCDCGAnPai.TBRafreshClick(Sender: TObject); begin InitGrid(); end; procedure TfrmClothSCDCGAnPai.ConNoChange(Sender: TObject); begin if ADOQueryMain.Active = False then Exit; SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2)); SCreateCDS20(ADOQueryMain, ClientDataSet3); SInitCDSData20(ADOQueryMain, ClientDataSet3); end; procedure TfrmClothSCDCGAnPai.FormShow(Sender: TObject); begin InitForm(); end; procedure TfrmClothSCDCGAnPai.JXPersonBtnClick(Sender: TObject); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'JXPerson'; flagname := '机修'; if ShowModal = 1 then begin JXPerson.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmClothSCDCGAnPai.Button2Click(Sender: TObject); var FFDS: Integer; FGYCarNo: string; begin if ClientDataSet3.IsEmpty then Exit; if ClientDataSet3.Locate('SSel', True, []) = False then begin Application.MessageBox('没有选择数据!', '提示', 0); Exit; end else begin Label10.Caption := Trim(ClientDataSet3.fieldbyname('ConNo').AsString); APPS.Text := Trim(ClientDataSet3.fieldbyname('APPSHZ').AsString); PSSX.Text := Trim(ClientDataSet3.fieldbyname('PiQty').AsString); // APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('BatchNoHZ').AsString); with ADOQueryTemp do begin Close; sql.Clear; SQL.Add(' select A.*'); sql.Add(' from JYCon_Sub_AnPai A'); sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + ''''); sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + ''''); sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + ''''); Open; end; SCreateCDS20(ADOQueryTemp, CDS_AnPai); SInitCDSData20(ADOQueryTemp, CDS_AnPai); with ADOQueryTemp do begin Close; sql.Clear; SQL.Add(' select COUNT(JYFlag) wjps'); sql.Add(' from JYCon_Sub_AnPai A'); sql.Add(' where A.JYFlag=0 and A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + ''''); sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + ''''); sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + ''''); Open; end; Label13.caption := '未检验匹数:' + trim(inttostr(ADOQueryTemp.fieldbyname('wjps').asinteger)); CDS_AnPai.Last; // if CDS_AnPai.IsEmpty then // APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('BatchNoHZ').AsString) // else // APBatchNo.Text := Trim(CDS_AnPai.fieldbyname('APBatchNo').AsString); end; if Trim(PS.Text) = '' then begin Application.MessageBox('匹数不能为空!', '提示', 0); Exit; end; if TryStrToInt(Trim(PS.Text), FFDS) = False then begin Application.MessageBox('匹数非法', '提示', 0); Exit; end; // if Trim(JXPerson.Text) = '' then // begin // Application.MessageBox('调试机修不能为空!', '提示', 0); // Exit; // end; // if Trim(APBatchNo.Text) = '' then // begin // Application.MessageBox('批号不能为空!', '提示', 0); // Exit; // end; FFDS := 0; FGYCarNo := Trim(ClientDataSet3.fieldbyname('CarNo').AsString); ClientDataSet3.DisableControls; with ClientDataSet3 do begin First; while not Eof do begin if ClientDataSet3.FieldByName('SSel').AsBoolean = True then begin FFDS := FFDS + 1; end; ClientDataSet3.Next; end; end; ClientDataSet3.EnableControls; ClientDataSet3.Locate('CarNo', FGYCarNo, []); // if FFDS * strtoint(PS.Text) + strtoint(APPS.Text) > StrToInt(PSSX.Text) then // begin // Application.MessageBox('安排匹数过多,不允许保存!', '提示', 0); // Exit; // end; if SaveDataAP() then begin InitGrid(); end; CDS_AnPai.Last; end; function TfrmClothSCDCGAnPai.SaveDataAP(): Boolean; var maxno, fPrintFile: string; i: Integer; FDate: string; Txt, fImagePath: string; Moudle: THandle; Makebar: TMakebar; Mixtext: TMixtext; GYMainId, GYSubId, GYCarNo, GYC_Code, GYC_CodeName: string; GYConNo, GYXHInt, GYLabName, GYCheJian, GYBatchNOHZ: string; GYChouZhen, GYCarType, GYC_Spec, GYC_CPName, GYC_ZhenCun: string; GYC_Custom, GYC_gongyi, GYC_PiKgQty, GYapBatchNo: string; begin cxGrid3.Enabled := False; FDate := FormatDateTime('yyyy-MM-dd', SGetServerDate(ADOQueryTemp)); with ClientDataSet3 do begin ClientDataSet3.DisableControls; First; while Locate('SSel', True, []) do begin GYMainId := Trim(ClientDataSet3.fieldbyname('Mainid').AsString); GYSubId := Trim(ClientDataSet3.fieldbyname('SubId').AsString); GYCarNo := Trim(ClientDataSet3.fieldbyname('CarNo').AsString); GYC_Code := Trim(ClientDataSet3.fieldbyname('C_Code').AsString); GYC_CodeName := Trim(ClientDataSet3.fieldbyname('C_CodeName').AsString); GYConNo := Trim(ClientDataSet3.fieldbyname('ConNo').AsString); GYLabName := Trim(ClientDataSet3.fieldbyname('LabName').AsString); GYCheJian := Trim(ClientDataSet3.fieldbyname('CheJian').AsString); GYBatchNOHZ := Trim(ClientDataSet3.fieldbyname('BatchNOHZ').AsString); GYChouZhen := Trim(ClientDataSet3.fieldbyname('ChouZhen').AsString); GYCarType := Trim(ClientDataSet3.fieldbyname('CarType').AsString); GYC_Spec := Trim(ClientDataSet3.fieldbyname('C_Spec').AsString); GYC_Custom := Trim(ClientDataSet3.fieldbyname('CustomerNoName').AsString); GYC_gongyi := Trim(ClientDataSet3.fieldbyname('gongyi').AsString); GYC_CPName := Trim(ClientDataSet3.fieldbyname('CPName').AsString); GYC_ZhenCun := Trim(ClientDataSet3.fieldbyname('ZhenCun').AsString); GYC_PiKgQty := Trim(ClientDataSet3.fieldbyname('PiKgQty').AsString); for i := 1 to StrToInt(PS.Text) do begin try ADOQueryCmd.Connection.BeginTrans; if GetLSNo(ADOQueryCmd, maxno, BPFlag, 'JYCon_Sub_AnPai', 4, 1) = False then begin cxGrid3.Enabled := True; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('生成坯布安排流水号异常!', '提示', 0); exit; end; with ADOQueryCmd do begin Close; sql.Clear; SQL.Add('select * from JYCon_Sub_AnPai where 1=2'); Open; end; with ADOQueryCmd do begin Append; FieldByName('MainId').Value := Trim(GYMainId); FieldByName('SubId').Value := Trim(GYSubId); FieldByName('APId').Value := Trim(maxno); FieldByName('JXPerson').Value := Trim(JXPerson.Text); FieldByName('APBatchNo').Value := Trim(APBatchNo.Text); FieldByName('CarNo').Value := Trim(GYCarNo); FieldByName('CheJian').Value := Trim(GYCheJian); FieldByName('PRTCount').Value := 1; FieldByName('APDate').Value := FDate; FieldByName('Filler').Value := Trim(DName); Post; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add(' Update JYCon_Sub_AnPai Set XHInt=isnull((select Max(XHInt) from JYCon_Sub_AnPai A where A.MainId=JYCon_Sub_AnPai.MainId and A.CarNo=JYCon_Sub_AnPai.CarNo ),0)+1'); sql.Add(' ,QDTime=(select DoTime from Cloth_JiTai JT where JT.MainId=''' + Trim(GYMainId) + ''' and CarNo=''' + Trim(GYCarNo) + ''''); sql.Add(' and StopFlag=0 )'); sql.Add(' where APId=''' + Trim(maxno) + ''''); ExecSQL; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select XHInt from JYCon_Sub_AnPai A where A.APId=''' + Trim(maxno) + ''''); Open; end; GYXHInt := Trim(ADOQueryTemp.fieldbyname('XHInt').AsString); with CDS_AnPai do begin Append; FieldByName('MainId').Value := Trim(GYMainId); FieldByName('SubId').Value := Trim(GYSubId); FieldByName('APId').Value := Trim(maxno); FieldByName('JXPerson').Value := Trim(JXPerson.Text); FieldByName('APBatchNo').Value := Trim(APBatchNo.Text); // FieldByName('APBatchNo').Value := ADOQueryTemp.fieldbyname('APBatchNo').Value; FieldByName('CarNo').Value := Trim(GYCarNo); FieldByName('XHInt').Value := ADOQueryTemp.fieldbyname('XHInt').Value; FieldByName('APDate').Value := FDate; FieldByName('PRTCount').Value := 1; Post; end; with ADOQueryTemp do begin Close; sql.Clear; SQL.Add('select * from JYCon_Sub_AnPai where APID=''' + Trim(maxno) + ''''); sql.Add(' and CarNo=''' + Trim(GYCarNo) + ''''); sql.Add(' and JXPerson=''' + Trim(JXPerson.Text) + ''''); sql.Add(' and MainId=''' + Trim(GYMainId) + ''''); sql.Add(' and SubId=''' + Trim(GYSubId) + ''''); Open; end; if ADOQueryTemp.IsEmpty then begin cxGrid3.Enabled := True; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('打印异常,请重新选择打印,已打印出的标签有效!', '提示', 0); Exit; end; ADOQueryCmd.Connection.CommitTrans; except ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('打印异常!', '提示', 0); Exit; end; fImagePath := ExtractFilePath(Application.ExeName) + 'image\' + trim(maxno) + '.bmp'; if FileExists(fImagePath) then DeleteFile(fImagePath); try if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil); if FileExists(fImagePath) then DeleteFile(fImagePath); Moudle := LoadLibrary('MakeQRBarcode.dll'); @Makebar := GetProcAddress(Moudle, 'Make'); @Mixtext := GetProcAddress(Moudle, 'MixText'); Txt := Trim(maxno); Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3); except cxGrid3.Enabled := True; application.MessageBox('条形码生成失败!', '提示信息', MB_ICONERROR); exit; end; Sleep(300); if Trim(GYLabName) = '有抬头标签' then begin fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\有抬头标签.rmf'; end else if Trim(GYLabName) = '无抬头标签' then begin fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\无抬头标签.rmf'; end else fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'; if FileExists(fPrintFile) then begin RM2.LoadFromFile(fPrintFile); RMVariables['QRBARCODE'] := fImagePath; RMVariables['PRTCS'] := ''; RMVariables['ConNo'] := Trim(GYConNo); RMVariables['APID'] := Trim(maxno); RMVariables['apdate'] := FDate; RMVariables['C_Code'] := Trim(GYC_Code); RMVariables['C_CodeName'] := Trim(GYC_CodeName); RMVariables['JXPerson'] := Trim(JXPerson.Text); RMVariables['APBatchNo'] := Trim(apbatchno.text); RMVariables['CarNo'] := Trim(GYCarNo); RMVariables['CheJian'] := Trim(GYCheJian); RMVariables['XHInt'] := Trim(GYXHInt); RMVariables['BatchNoHZ'] := Trim(GYBatchNOHZ); RMVariables['ChouZhen'] := Trim(GYChouZhen); RMVariables['CarType'] := Trim(GYCarType); RMVariables['C_Spec'] := Trim(GYC_Spec); RMVariables['CustomerNoName'] := Trim(GYC_Custom); RMVariables['gongyi'] := Trim(GYC_gongyi); RMVariables['CPName'] := Trim(GYC_CPName); RMVariables['ZhenCun'] := Trim(GYC_ZhenCun); RMVariables['PiKgQty'] := Trim(GYC_PiKgQty); RM2.PrintReport; end else begin cxGrid3.Enabled := True; Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'), '提示', 0); Exit; end; if FileExists(fImagePath) then DeleteFile(fImagePath); end; ClientDataSet3.Delete; end; ClientDataSet3.EnableControls; end; FFMainID := ''; cxGrid3.Enabled := True; Result := True; end; procedure TfrmClothSCDCGAnPai.Button1Click(Sender: TObject); begin if CDS_AnPai.IsEmpty then Exit; if CDS_AnPai.Locate('SSel', True, []) = False then begin Application.MessageBox('没有选择数据!', '提示', 0); Exit; end; if CDS_AnPai.Locate('SSel;JYFlag', VarArrayOf([True, True]), []) then begin Application.MessageBox('已检验不能作废!', '提示', 0); Exit; end; if Application.MessageBox('确定要作废数据吗?', '提示', 32 + 4) <> IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; CDS_AnPai.DisableControls; with CDS_AnPai do begin while CDS_AnPai.FieldByName('SSel').AsBoolean = True do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('delete JYCon_Sub_AnPai '); sql.Add(' where APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + ''''); sql.Add(' and not exists(select * from WFB_MJJY_PB A where A.MJID=JYCon_Sub_AnPai.APID)'); 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('作废布票'))); sql.Add(',' + quotedstr(trim('卷号:' + trim(CDS_AnPai.FieldByName('apid').AsString) + ' 车号:' + trim(CDS_AnPai.FieldByName('carno').AsString) + ' 批号:' + trim(CDS_AnPai.FieldByName('APBatchNo').AsString) + ' MAINID:' + trim(CDS_AnPai.FieldByName('mainid').AsString)))); sql.Add(',' + quotedstr(trim('成功'))); sql.Add(')'); ExecSQL; end; CDS_AnPai.Delete; end; end; CDS_AnPai.EnableControls; ADOQueryCmd.Connection.CommitTrans; except ADOQueryCmd.Connection.RollbackTrans; CDS_AnPai.EnableControls; Application.MessageBox('作废失败!', '提示', 0); Exit; end; end; procedure TfrmClothSCDCGAnPai.cxTabControl1Change(Sender: TObject); begin InitGrid(); end; procedure TfrmClothSCDCGAnPai.Button3Click(Sender: TObject); var fPrintFile: string; i: Integer; FDate: string; Txt, fImagePath: string; Moudle: THandle; Makebar: TMakebar; Mixtext: TMixtext; GYLabName: string; begin if ClientDataSet3.IsEmpty then Exit; if CDS_AnPai.IsEmpty then Exit; if CDS_AnPai.Locate('SSel', True, []) = False then begin Application.MessageBox('没有选择数据!', '提示', 0); Exit; end; if CDS_AnPai.Locate('SSel;JYFlag', VarArrayOf([True, True]), []) then begin Application.MessageBox('已检验不能重打!', '提示', 0); Exit; end; with CDS_AnPai do begin while CDS_AnPai.Locate('SSel', true, []) do begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Cloth_Main where Mainid=''' + Trim(CDS_AnPai.fieldbyname('MainId').AsString) + ''''); Open; end; GYLabName := Trim(ADOQueryTemp.fieldbyname('LabName').AsString); CDS_AnPai.Edit; CDS_AnPai.FieldByName('PRTFlag').Value := 1; CDS_AnPai.FieldByName('PRTCount').Value := 2; CDS_AnPai.Post; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('UPdate JYCon_Sub_AnPai Set PRTFlag=1,PRTCount=2 '); sql.Add(' where APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + ''''); ExecSQL; end; try Moudle := LoadLibrary('MakeQRBarcode.dll'); @Makebar := GetProcAddress(Moudle, 'Make'); @Mixtext := GetProcAddress(Moudle, 'MixText'); Txt := Trim(CDS_AnPai.fieldbyname('APId').AsString); fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp'; if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil); if FileExists(fImagePath) then DeleteFile(fImagePath); Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3); except application.MessageBox('条形码生成失败!', '提示信息', MB_ICONERROR); exit; end; if Trim(GYLabName) = '有抬头标签' then begin fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\有抬头标签.rmf'; end else if Trim(GYLabName) = '无抬头标签' then begin fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\无抬头标签.rmf'; end else fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'; if FileExists(fPrintFile) then begin with ADOQueryPrint do begin Close; sql.Clear; sql.Add('select A.*,B.*, '); sql.Add(' AA.APID,A.ZhuanQty,AA.SCPerson,AA.CarNo,AA.CheJian ,AA.XHInt,AA.JXPerson,AA.APBatchNo,aa.apdate'); sql.Add(',CPName=( select TOP 1 CPName from CP_YDang X inner join CP_Type Y on X.CYType=Y.CPID where X.CYName=A.C_CodeName )'); sql.Add(' ,CustomerNoName=(select top 1 CustomerNoName from JYOrderCon_Main_PB X where X.MainId=B.ConMainId) '); sql.Add(' from JYCon_Sub_AnPai AA'); sql.Add(' inner join Cloth_Sub A on AA.SubId=A.SubId and AA.Mainid=A.MainId'); sql.Add(' inner join Cloth_Main B on AA.MainId=B.MainId '); sql.Add(' where AA.APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + ''''); Open; end; RM2.LoadFromFile(fPrintFile); RMVariables['QRBARCODE'] := fImagePath; RMVariables['PRTCS'] := '2'; RMVariables['ConNo'] := Trim(ADOQueryPrint.fieldbyname('ConNo').AsString); RMVariables['APID'] := Trim(ADOQueryPrint.fieldbyname('APID').AsString); RMVariables['C_Code'] := Trim(ADOQueryPrint.fieldbyname('C_Code').AsString); RMVariables['C_CodeName'] := Trim(ADOQueryPrint.fieldbyname('C_CodeName').AsString); RMVariables['CustomerNoName'] := Trim(ADOQueryPrint.fieldbyname('CustomerNoName').AsString); RMVariables['JXPerson'] := Trim(ADOQueryPrint.fieldbyname('JXPerson').AsString); RMVariables['CarNo'] := Trim(ADOQueryPrint.fieldbyname('CarNo').AsString); RMVariables['CheJian'] := Trim(ADOQueryPrint.fieldbyname('CheJian').AsString); RMVariables['XHInt'] := Trim(ADOQueryPrint.fieldbyname('XHInt').AsString); RMVariables['BatchNoHZ'] := Trim(ADOQueryPrint.fieldbyname('BatchNoHZ').AsString); RMVariables['ChouZhen'] := Trim(ADOQueryPrint.fieldbyname('ChouZhen').AsString); RMVariables['CarType'] := Trim(ADOQueryPrint.fieldbyname('CarType').AsString); RMVariables['C_Spec'] := Trim(ADOQueryPrint.fieldbyname('C_Spec').AsString); RMVariables['C_Color'] := Trim(ADOQueryPrint.fieldbyname('C_Color').AsString); RMVariables['gongyi'] := Trim(ADOQueryPrint.fieldbyname('gongyi').AsString); RMVariables['APBatchNo'] := Trim(ADOQueryPrint.fieldbyname('APBatchNo').AsString); RMVariables['CPName'] := Trim(ADOQueryPrint.fieldbyname('CPName').AsString); RMVariables['ZhenCun'] := Trim(ADOQueryPrint.fieldbyname('ZhenCun').AsString); RMVariables['PiKgQty'] := Trim(ADOQueryPrint.fieldbyname('PiKgQty').AsString); RMVariables['APDATE'] := ADOQueryPrint.fieldbyname('APDATE').Value; RM2.PrintReport; end else begin Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'), '提示', 0); Exit; end; CDS_AnPai.Edit; CDS_AnPai.FieldByName('SSel').Value := false; end; end; end; procedure TfrmClothSCDCGAnPai.v3Column8PropertiesEditValueChanged(Sender: TObject); var mvale: Boolean; fsj: string; begin mvale := TcxCheckBox(Sender).EditingValue; if mvale = True then begin CDS_AnPai.Last; if CDS_AnPai.IsEmpty then APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('C_Code').AsString) else APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('C_Code').AsString); if Trim(FFMainID) = '' then begin FFMainID := Trim(ClientDataSet3.fieldbyname('Mainid').AsString) end else begin if Trim(FFMainID) <> Trim(ClientDataSet3.fieldbyname('Mainid').AsString) then begin with ClientDataSet3 do begin Edit; FieldByName('SSel').Value := False; end; Application.MessageBox('不能选择不同的订单号!', '提示', 0); Exit; end; end; Label10.Caption := Trim(ClientDataSet3.fieldbyname('ConNo').AsString); APPS.Text := Trim(ClientDataSet3.fieldbyname('APPSHZ').AsString); PSSX.Text := Trim(ClientDataSet3.fieldbyname('PiQty').AsString); // with ADOQueryTemp do // begin // Close; // sql.Clear; // SQL.Add(' select A.*'); // sql.Add(' from JYCon_Sub_AnPai A'); // sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + ''''); // sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + ''''); // sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + ''''); // Open; // end; // SCreateCDS20(ADOQueryTemp, CDS_AnPai); // SInitCDSData20(ADOQueryTemp, CDS_AnPai); // if CDS_AnPai.IsEmpty = False then // begin // with ADOQueryTemp do // begin // Close; // sql.Clear; // SQL.Add(' select TOP 1 A.*'); // sql.Add(' from JYCon_Sub_AnPai A'); // sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + ''''); // sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + ''''); // sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + ''''); // SQL.Add('ORDER BY APID DESC'); // Open; // end; // APBatchNo.Text := Trim(ADOQueryTemp.fieldbyname('APBatchNo').AsString); // end; end; fsj := Trim(ClientDataSet3.fieldbyname('JTID').AsString); with ClientDataSet3 do begin Edit; FieldByName('SSel').Value := mvale; end; if mvale = True then begin JXPerson.Text := Trim(ClientDataSet3.fieldbyname('JXPerson10').AsString); end else begin ClientDataSet3.Locate('SSel', True, []); JXPerson.Text := Trim(ClientDataSet3.fieldbyname('JXPerson10').AsString); end; if ClientDataSet3.Locate('SSel', True, []) = False then begin JXPerson.Text := ''; FFMainID := ''; end; ClientDataSet3.Locate('JTID', fsj, []); end; procedure TfrmClothSCDCGAnPai.PSKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin Button2.Click; end; end; procedure TfrmClothSCDCGAnPai.Button4Click(Sender: TObject); var fPrintFile: string; i: Integer; FDate: string; Txt, fImagePath: string; Moudle: THandle; Makebar: TMakebar; Mixtext: TMixtext; GYLabName: string; begin if ClientDataSet3.IsEmpty then Exit; if CDS_AnPai.IsEmpty then Exit; if CDS_AnPai.Locate('SSel', True, []) = False then begin Application.MessageBox('没有选择数据!', '提示', 0); Exit; end; if CDS_AnPai.Locate('SSel;JYFlag', VarArrayOf([True, True]), []) then begin Application.MessageBox('已检验不能重打!', '提示', 0); Exit; end; with CDS_AnPai do begin while CDS_AnPai.Locate('SSel', true, []) do begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Cloth_Main where Mainid=''' + Trim(CDS_AnPai.fieldbyname('MainId').AsString) + ''''); Open; end; GYLabName := Trim(ADOQueryTemp.fieldbyname('LabName').AsString); CDS_AnPai.Edit; CDS_AnPai.FieldByName('PRTFlag').Value := 1; CDS_AnPai.FieldByName('PRTCount').Value := 2; CDS_AnPai.Post; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('UPdate JYCon_Sub_AnPai Set PRTFlag=1,PRTCount=2 '); sql.Add(',APBatchNo =' + quotedstr(Trim(APBatchNo.Text))); sql.Add(' where APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + ''''); ExecSQL; end; try Moudle := LoadLibrary('MakeQRBarcode.dll'); @Makebar := GetProcAddress(Moudle, 'Make'); @Mixtext := GetProcAddress(Moudle, 'MixText'); Txt := Trim(CDS_AnPai.fieldbyname('APId').AsString); fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp'; if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil); if FileExists(fImagePath) then DeleteFile(fImagePath); Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3); except application.MessageBox('条形码生成失败!', '提示信息', MB_ICONERROR); exit; end; if Trim(GYLabName) = '有抬头标签' then begin fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\有抬头标签.rmf'; end else if Trim(GYLabName) = '无抬头标签' then begin fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\无抬头标签.rmf'; end else fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'; if FileExists(fPrintFile) then begin with ADOQueryPrint do begin Close; sql.Clear; sql.Add('select A.*,B.*, '); sql.Add(' AA.APID,A.ZhuanQty,AA.SCPerson,AA.CarNo,AA.CheJian ,AA.XHInt,AA.JXPerson,AA.APBatchNo'); sql.Add(',CPName=( select TOP 1 CPName from CP_YDang X inner join CP_Type Y on X.CYType=Y.CPID where X.CYName=A.C_CodeName )'); sql.Add(' ,CustomerNoName=(select top 1 CustomerNoName from JYOrderCon_Main_PB X where X.MainId=B.ConMainId) '); sql.Add(' from JYCon_Sub_AnPai AA'); sql.Add(' inner join Cloth_Sub A on AA.SubId=A.SubId and AA.Mainid=A.MainId'); sql.Add(' inner join Cloth_Main B on AA.MainId=B.MainId '); sql.Add(' where AA.APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + ''''); Open; end; RM2.LoadFromFile(fPrintFile); RMVariables['QRBARCODE'] := fImagePath; RMVariables['PRTCS'] := '2'; RMVariables['ConNo'] := Trim(ADOQueryPrint.fieldbyname('ConNo').AsString); RMVariables['APID'] := Trim(ADOQueryPrint.fieldbyname('APID').AsString); RMVariables['C_Code'] := Trim(ADOQueryPrint.fieldbyname('C_Code').AsString); RMVariables['C_CodeName'] := Trim(ADOQueryPrint.fieldbyname('C_CodeName').AsString); RMVariables['CustomerNoName'] := Trim(ADOQueryPrint.fieldbyname('CustomerNoName').AsString); RMVariables['JXPerson'] := Trim(ADOQueryPrint.fieldbyname('JXPerson').AsString); RMVariables['CarNo'] := Trim(ADOQueryPrint.fieldbyname('CarNo').AsString); RMVariables['CheJian'] := Trim(ADOQueryPrint.fieldbyname('CheJian').AsString); RMVariables['XHInt'] := Trim(ADOQueryPrint.fieldbyname('XHInt').AsString); RMVariables['BatchNoHZ'] := Trim(ADOQueryPrint.fieldbyname('BatchNoHZ').AsString); RMVariables['ChouZhen'] := Trim(ADOQueryPrint.fieldbyname('ChouZhen').AsString); RMVariables['CarType'] := Trim(ADOQueryPrint.fieldbyname('CarType').AsString); RMVariables['C_Spec'] := Trim(ADOQueryPrint.fieldbyname('C_Spec').AsString); RMVariables['C_Color'] := Trim(ADOQueryPrint.fieldbyname('C_Color').AsString); RMVariables['gongyi'] := Trim(ADOQueryPrint.fieldbyname('gongyi').AsString); RMVariables['APBatchNo'] := Trim(ADOQueryPrint.fieldbyname('APBatchNo').AsString); RMVariables['CPName'] := Trim(ADOQueryPrint.fieldbyname('CPName').AsString); RMVariables['ZhenCun'] := Trim(ADOQueryPrint.fieldbyname('ZhenCun').AsString); RMVariables['PiKgQty'] := Trim(ADOQueryPrint.fieldbyname('PiKgQty').AsString); // RM2.PrintReport; end else begin Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'), '提示', 0); Exit; end; CDS_AnPai.Edit; CDS_AnPai.FieldByName('SSel').Value := false; CDS_AnPai.FieldByName('APBatchNo').Value := Trim(APBatchNo.Text); end; end; end; procedure TfrmClothSCDCGAnPai.ConNoKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then TBRafresh.Click(); if ADOQueryMain.Active = False then Exit; SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2)); SCreateCDS20(ADOQueryMain, ClientDataSet3); SInitCDSData20(ADOQueryMain, ClientDataSet3); end; procedure TfrmClothSCDCGAnPai.C_CodeNameKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then TBRafresh.Click(); if ADOQueryMain.Active = False then Exit; SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2)); SCreateCDS20(ADOQueryMain, ClientDataSet3); SInitCDSData20(ADOQueryMain, ClientDataSet3); end; procedure TfrmClothSCDCGAnPai.Tv3FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); begin Label10.Caption := Trim(ClientDataSet3.fieldbyname('ConNo').AsString); APPS.Text := Trim(ClientDataSet3.fieldbyname('APPSHZ').AsString); PSSX.Text := Trim(ClientDataSet3.fieldbyname('PiQty').AsString); // APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('BatchNoHZ').AsString); // APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('C_Code').AsString); with ADOQueryTemp do begin Close; sql.Clear; SQL.Add(' select A.*'); sql.Add(' from JYCon_Sub_AnPai A'); sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + ''''); sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + ''''); sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + ''''); Open; end; SCreateCDS20(ADOQueryTemp, CDS_AnPai); SInitCDSData20(ADOQueryTemp, CDS_AnPai); with ADOQueryTemp do begin Close; sql.Clear; SQL.Add(' select COUNT(JYFlag) wjps'); sql.Add(' from JYCon_Sub_AnPai A'); sql.Add(' where A.JYFlag=0 and A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + ''''); sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + ''''); sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + ''''); Open; end; Label13.caption := '未检验匹数:' + trim(inttostr(ADOQueryTemp.fieldbyname('wjps').asinteger)); end; end.