unit U_TatWBCardInPut; 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, cxPC, Menus, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, BtnEdit, U_BaseInput, System.ImageList, Vcl.ImgList; type TfrmTatWBCardInPut = class(TfrmBaseInput) ADOQueryCmd: TADOQuery; ADOQueryTemp: TADOQuery; RM1: TRMGridReport; RMXLSExport1: TRMXLSExport; RMDB_1: TRMDBDataSet; Panel2: TPanel; DS_Card: TDataSource; CDS_Card: TClientDataSet; GPM_1: TcxGridPopupMenu; ADOQueryPrint: TADOQuery; PopupMenu1: TPopupMenu; N2: TMenuItem; N3: TMenuItem; Panel4: TPanel; cxGrid2: TcxGrid; TV2: TcxGridDBTableView; cxGridDBColumn1: TcxGridDBColumn; V2Column4: TcxGridDBColumn; V2Column1: TcxGridDBColumn; V2Column3: TcxGridDBColumn; TV2Column4: TcxGridDBColumn; cxGridDBColumn15: TcxGridDBColumn; cxGridDBColumn9: TcxGridDBColumn; cxGridDBColumn10: TcxGridDBColumn; TV2Column1: TcxGridDBColumn; TV2Column2: TcxGridDBColumn; TV2Column3: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; ToolBar1: TToolBar; TBSave: TToolButton; ToolButton1: TToolButton; ToolButton8: TToolButton; ToolButton2: TToolButton; TBClose: TToolButton; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; v1OrderNo: TcxGridDBColumn; Tv1Column2: TcxGridDBColumn; v1Column31: TcxGridDBColumn; v1Column5: TcxGridDBColumn; Tv1Column1: TcxGridDBColumn; v1Column19: TcxGridDBColumn; v1Column21: TcxGridDBColumn; v1Column2: TcxGridDBColumn; v1Column6: TcxGridDBColumn; v1PRTOrderQty: TcxGridDBColumn; v1Column7: TcxGridDBColumn; v1Column20: TcxGridDBColumn; v1PRTMF: TcxGridDBColumn; v1PRTKZ: TcxGridDBColumn; Tv1Column5: TcxGridDBColumn; Tv1Column6: TcxGridDBColumn; Tv1Column7: TcxGridDBColumn; Tv1Column8: TcxGridDBColumn; v1Column4: TcxGridDBColumn; cxGrid1Level1: TcxGridLevel; Panel1: TPanel; Label8: TLabel; Label9: TLabel; Label11: TLabel; Label2: TLabel; Label12: TLabel; Label15: TLabel; Label3: TLabel; Label5: TLabel; Label6: TLabel; Label4: TLabel; WB_YarnQty: TEdit; WB_Len: TEdit; edtCardQty: TEdit; WB_YarnArr: TEdit; WB_Type: TComboBox; WB_ClothPiece: TEdit; WB_MachNo: TBtnEditC; WB_Macher: TBtnEditC; WB_YarnLen: TEdit; Note: TRichEdit; GPM_2: TcxGridPopupMenu; ToolButton4: TToolButton; CDS_1: TClientDataSet; DS_1: TDataSource; TV2Column5: TcxGridDBColumn; Label7: TLabel; WB_Code: TBtnEditC; WB_Spec: TEdit; TV2Column6: TcxGridDBColumn; Label1: TLabel; WBCNO: TEdit; Label10: TLabel; WBTray: TBtnEditC; TV2Column7: TcxGridDBColumn; TV2Column8: TcxGridDBColumn; PM_1: TPopupMenu; N1: TMenuItem; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure N2Click(Sender: TObject); procedure N3Click(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure WB_MachNoBtnUpClick(Sender: TObject); procedure WB_MachNoBtnDnClick(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); procedure ToolButton8Click(Sender: TObject); procedure WB_CodeBtnUpClick(Sender: TObject); procedure WB_CodeBtnDnClick(Sender: TObject); procedure N1Click(Sender: TObject); private function TestData(): Boolean; procedure PrtDate(MWBCID: string); procedure InitMain(); procedure InitCard(); procedure InitCardGrop(); { Private declarations } public FWBCNO: string; { Public declarations } end; var frmTatWBCardInPut: TfrmTatWBCardInPut; implementation uses U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_WBTatPlanSel, U_WBSpecSel; {$R *.dfm} procedure TfrmTatWBCardInPut.InitCardGrop(); begin with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('select * from V_Tat_WB_CardGrop A where A.WBCNO=''' + Trim(FWBCNO) + ''''); Open; end; SCSHData(ADOQueryTemp, Panel1, 1); end; function TfrmTatWBCardInPut.TestData(): Boolean; begin try if Trim(FWBCNO) = '' then begin if GetLSNo(ADOQueryTemp, FWBCNO, 'QJ', 'Tat_WB_Card', 3, 1) = False then begin raise Exception.Create('迁经单号失败!'); end; WBCNO.Text := FWBCNO; end; if trim(WB_Code.Text) = '' then raise Exception.Create('经规格不能为空!'); if StrToIntDef(edtCardQty.Text, 0) = 0 then raise Exception.Create('排轴数不能为空!'); if StrToIntDef(WB_YarnQty.Text, 0) = 0 then raise Exception.Create('头纹不能为空!'); if Trim(WB_YarnArr.Text) = '' then raise Exception.Create('上排不能为空!'); if Trim(WB_Len.Text) = '' then raise Exception.Create('轴长不能为空!'); if StrToIntDef(WB_YarnLen.Text, 0) = 0 then raise Exception.Create('整经长度不能为空!'); if Trim(WB_Macher.Text) = '' then raise Exception.Create('扦经工位不能为空!'); if Trim(WB_MachNo.Text) = '' then raise Exception.Create('迁经机不能为空!'); if StrToIntDef(WB_ClothPiece.Text, 0) = 0 then raise Exception.Create('匹额不能为空!'); if Trim(WB_Type.Text) = '' then raise Exception.Create('类型不能为空!'); Result := True; except Result := false; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end; procedure TfrmTatWBCardInPut.InitMain(); begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select A.*,B.* '); sql.Add(' from Tat_Plan_Main A inner join Tat_Plan_Sub B on A.Mainid=B.MainId '); sql.Add(' inner join Tat_WB_Card_Link C on B.SubId=C.SubId '); sql.Add(' where C.WBCNO= ' + QuotedStr(Trim(FWBCNO))); Open; end; SCreateCDS(ADOQueryTemp, CDS_1); SInitCDSData(ADOQueryTemp, CDS_1); end; procedure TfrmTatWBCardInPut.InitCard(); begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select A.* '); sql.Add('from Tat_WB_Card A '); sql.Add('where isnull(Status,''0'')<>''-1'' and WBCNO=' + quotedstr(Trim(FWBCNO))); Open; end; SCreateCDS(ADOQueryTemp, CDS_Card); SInitCDSData(ADOQueryTemp, CDS_Card); end; procedure TfrmTatWBCardInPut.PrtDate(MWBCID: string); var fPrintFile, FFCYID: string; DPS, i, j: Integer; begin ExportFtErpFile('轴卡标签.rmf', ADOQueryTemp); fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\轴卡标签.rmf'; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('update Tat_WB_Card set PrtFlag=PrtFlag+1 '); sql.Add(' where WBCID=' + quotedstr(MWBCID)); ExecSQL; end; with ADOQueryPrint do begin Close; sql.Clear; sql.Add('select A.*,B.*,D.* '); sql.Add(' from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId'); sql.Add(' inner join Tat_WB_Card_MS C on C.Subid=B.Subid '); sql.Add(' inner join Tat_WB_Card D on C.WBCID=D.WBCID '); sql.Add(' where D.WBCID=' + quotedstr(MWBCID)); // ShowMessage(SQL.Text); Open; end; // with ADOQueryTemp do // begin // Close; // sql.Clear; // sql.Add('select Y.* from PD_Plan_Yarn Y INNER JOIN Tat_WB_Card_MS M ON M.MainId=Y.MainId where Y.PYType=''经丝'' and M.WBCID=' + Quotedstr(Trim(MWBCID))); // Open; // end; // SCreateCDS(ADOQueryTemp, CDS_PJS); // SInitCDSData(ADOQueryTemp, CDS_PJS); // // with ADOQueryTemp do // begin // Close; // sql.Clear; // sql.Add('select Y.* from PD_Plan_Yarn Y INNER JOIN Tat_WB_Card_MS M ON M.MainId=Y.MainId where Y.PYType=''纬丝'' and M.WBCID=' + Quotedstr(Trim(MWBCID))); // Open; // end; // SCreateCDS(ADOQueryTemp, CDS_PWS); // SInitCDSData(ADOQueryTemp, CDS_PWS); if FileExists(fPrintFile) then begin RM1.LoadFromFile(fPrintFile); RM1.DefaultCopies := 1; RM1.ShowReport; end else begin Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0); Exit; end; end; procedure TfrmTatWBCardInPut.WB_CodeBtnDnClick(Sender: TObject); begin Self.WB_Code.Text := ''; Self.WB_Spec.Text := ''; Self.WB_YarnQty.Text := ''; end; procedure TfrmTatWBCardInPut.WB_CodeBtnUpClick(Sender: TObject); begin try frmWBSpecSel := TfrmWBSpecSel.Create(Application); with frmWBSpecSel do begin if ShowModal = 1 then begin Self.WB_Code.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Code').AsString); Self.WB_Spec.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Spec').AsString); Self.WB_YarnQty.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnQty').AsString); end; end; finally frmWBSpecSel.Free; end; end; procedure TfrmTatWBCardInPut.FormClose(Sender: TObject; var Action: TCloseAction); begin inherited; Action := caFree; end; procedure TfrmTatWBCardInPut.FormShow(Sender: TObject); begin inherited; ReadCxGrid(Trim(self.Caption) + 'Tv1', Tv1, '坯布轴卡'); ReadCxGrid(Trim(self.Caption) + 'Tv2', Tv2, '坯布轴卡'); InitMain(); InitCard(); InitCardGrop(); end; procedure TfrmTatWBCardInPut.N1Click(Sender: TObject); begin if not CDS_1.IsEmpty then CDS_1.Delete; end; procedure TfrmTatWBCardInPut.N2Click(Sender: TObject); begin SelOKNo(CDS_Card, True); end; procedure TfrmTatWBCardInPut.N3Click(Sender: TObject); begin SelOKNo(CDS_Card, False); end; procedure TfrmTatWBCardInPut.TBCloseClick(Sender: TObject); begin ModalResult := 1; end; procedure TfrmTatWBCardInPut.TBSaveClick(Sender: TObject); var MWBCID: string; i, j: integer; begin if TestData() = false then exit; try ADOQueryCmd.Connection.BeginTrans; with ADOQueryCmd do begin Close; sql.Clear; ////////////////// 插入轴卡 ////////////////////// sql.Add(' insert into Tat_WB_Card(WBCNO,WBCID,WBTray,WB_Code,WB_Spec,WB_YarnQty,WB_YarnArr,WB_Len,WB_YarnLen,WB_Macher,WB_MachNo,WB_ClothPiece,WB_Type,Note,FillId,Filler) values'); for i := 1 to StrToIntdef(edtCardQty.Text, 0) do begin if GetLSNo(ADOQueryTemp, MWBCID, 'ZK', 'Tat_WB_Card', 3, 1) = False then begin raise Exception.Create('取布票流水号失败!'); end; if i > 1 then sql.Add(','); sql.Add(' (' + Quotedstr(Trim(FWBCNO))); sql.Add(',' + Quotedstr(Trim(MWBCID))); sql.Add(',' + Quotedstr(Trim(WBTray.Text))); sql.Add(',' + Quotedstr(Trim(WB_Code.Text))); sql.Add(',' + Quotedstr(Trim(WB_Spec.Text))); sql.Add(',' + (Trim(WB_YarnQty.Text))); sql.Add(',' + Quotedstr(Trim(WB_YarnArr.Text))); sql.Add(',' + Quotedstr(Trim(WB_Len.Text))); sql.Add(',' + FloatToStr(strtointdef(WB_YarnLen.Text, 0) / StrToIntdef(edtCardQty.Text, 0))); sql.Add(',' + Quotedstr(Trim(WB_Macher.Text))); sql.Add(',' + Quotedstr(Trim(WB_MachNo.Text))); sql.Add(',' + (Trim(WB_ClothPiece.Text))); sql.Add(',' + Quotedstr(Trim(WB_Type.Text))); sql.Add(',' + Quotedstr(Trim(Note.Text))); sql.Add(',' + Quotedstr(Trim(DCode))); sql.Add(',' + Quotedstr(Trim(DName))); sql.Add(' )'); end; ////////////////// 插入轴卡 ////////////////////// /// ////////////////// 插入轴卡计划单 ////////////////////// if not CDS_1.IsEmpty then begin with CDS_1 do begin First; sql.Add(' delete Tat_WB_Card_Link where WBCNO=' + Quotedstr(Trim(FWBCNO))); while not Eof do begin sql.Add(' insert into Tat_WB_Card_Link(MainId,SubID,WBCNO) values'); sql.Add(' (' + Quotedstr(Trim(CDS_1.FieldByName('MainId').AsString))); sql.Add(',' + Quotedstr(Trim(CDS_1.FieldByName('SubID').AsString))); sql.Add(',' + Quotedstr(Trim(FWBCNO))); sql.Add(' )'); Next; end; end; end; ////////////////// 插入轴卡计划单 ////////////////////// ExecSQL; end; with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('select * from V_Tat_WB_CardGrop A where A.WBCNO=''' + Trim(FWBCNO) + ''''); Open; end; if ADOQueryTemp.RecordCount > 1 then raise Exception.Create('计划单信息不能变更!'); ADOQueryCmd.Connection.CommitTrans; except ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; InitCard(); end; procedure TfrmTatWBCardInPut.ToolButton1Click(Sender: TObject); var WSql: string; begin if CDS_Card.IsEmpty then Exit; if CDS_Card.Locate('SSel', True, []) = False then begin Application.MessageBox('没有选择数据!', '提示', 0); Exit; end; WSql := ''; CDS_Card.DisableControls; with CDS_Card do begin First; while not Eof do begin if CDS_Card.fieldbyname('SSel').AsBoolean then begin if WSql <> '' then begin WSql := WSql + ',' + QuotedStr(Trim(CDS_Card.fieldbyname('WBCID').AsString)); end else begin WSql := QuotedStr(Trim(CDS_Card.fieldbyname('WBCID').AsString)); end; end; Next; end; end; CDS_Card.Locate('SSel', True, []); CDS_Card.EnableControls; try frmLabelPrint := TfrmLabelPrint.Create(Application); with frmLabelPrint do begin FPreviewPrint := False; FLMType := 'TatWBCard'; FFiltration1 := WSql; if ShowModal = 1 then begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('update Tat_WB_Card '); sql.Add(' set PRTer=' + quotedstr(DName)); sql.Add(', PRTCount=PRTCount+1'); sql.Add(', PRTDate=getdate()'); sql.Add(' where WBCID in (' + WSql + ')'); ExecSQL; end; end; end; finally frmLabelPrint.Free; end; end; procedure TfrmTatWBCardInPut.ToolButton2Click(Sender: TObject); begin WriteCxGrid(Trim(self.Caption) + 'Tv1', Tv1, '坯布轴卡'); WriteCxGrid(Trim(self.Caption) + 'Tv2', Tv2, '坯布轴卡'); end; procedure TfrmTatWBCardInPut.ToolButton4Click(Sender: TObject); begin try frmWBTatPlanSel := TfrmWBTatPlanSel.Create(Application); with frmWBTatPlanSel do begin if ShowModal = 1 then begin frmWBTatPlanSel.CDS_1.DisableControls; with frmWBTatPlanSel.CDS_1 do begin First; while not Eof do begin if FieldByName('SSel').AsBoolean then begin with Self.CDS_1 do begin Append; FieldByName('ConNo').Value := frmWBTatPlanSel.CDS_1.FieldByName('ConNo').Value; FieldByName('OrderNo').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrderNo').Value; FieldByName('MainId').Value := frmWBTatPlanSel.CDS_1.FieldByName('MainId').Value; FieldByName('SubID').Value := frmWBTatPlanSel.CDS_1.FieldByName('SubID').Value; FieldByName('CustName').Value := frmWBTatPlanSel.CDS_1.FieldByName('CustName').Value; FieldByName('OrdDate').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdDate').Value; FieldByName('FtyCoName').Value := frmWBTatPlanSel.CDS_1.FieldByName('FtyCoName').Value; FieldByName('DlyDate').Value := frmWBTatPlanSel.CDS_1.FieldByName('DlyDate').Value; FieldByName('C_Code').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Code').Value; FieldByName('C_Name').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Name').Value; FieldByName('C_Spec').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Spec').Value; FieldByName('C_Width').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Width').Value; FieldByName('C_GramWeight').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_GramWeight').Value; FieldByName('OrdPieceLen').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdPieceLen').Value; FieldByName('C_YarnQty').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_YarnQty').Value; FieldByName('C_LatitudeSpec').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_LatitudeSpec').Value; FieldByName('C_LongitudeSpec').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_LongitudeSpec').Value; FieldByName('C_ReedNo').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_ReedNo').Value; FieldByName('OrdPiece').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdPiece').Value; FieldByName('OrdQty').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdQty').Value; FieldByName('OrdSNote').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdSNote').Value; Post; end; end; Next; end; end; frmWBTatPlanSel.CDS_1.EnableControls; end; end; finally frmWBTatPlanSel.Free; end; end; procedure TfrmTatWBCardInPut.ToolButton8Click(Sender: TObject); var WSql: string; begin if CDS_Card.IsEmpty then Exit; if CDS_Card.Locate('SSel', True, []) = False then begin Application.MessageBox('没有选择数据!', '提示', 0); Exit; end; WSql := ''; CDS_Card.DisableControls; while CDS_Card.Locate('SSel', True, []) do begin if CDS_Card.fieldbyname('SSel').AsBoolean then begin if WSql <> '' then begin WSql := WSql + ',' + (Trim(CDS_Card.fieldbyname('WBCID').AsString)); end else begin WSql := (Trim(CDS_Card.fieldbyname('WBCID').AsString)); end; end; CDS_Card.Delete; end; CDS_Card.EnableControls; try ADOQueryCmd.Connection.BeginTrans; // with ADOQueryCmd do // begin // Close; // sql.Clear; // sql.Add('insert into Knit_Need_Up(UOperation,UType,UDataId) values(''检验'',''检验删除'',' + quotedstr(MCIIDS) + ') '); // ExecSQL; // end; with ADOQueryCmd do begin Close; Sql.Clear; Sql.Add('exec P_TatWB_Card_Del '); Sql.Add('@WBCIDS=' + quotedstr(Trim(WSql))); Sql.Add(',@DCode=' + Quotedstr(DCode)); Sql.Add(',@DName=' + Quotedstr(DName)); Open; end; if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then begin raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString))); end; ADOQueryCmd.Connection.CommitTrans; application.MessageBox('删除成功!', '提示信息'); except ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end; procedure TfrmTatWBCardInPut.WB_MachNoBtnDnClick(Sender: TObject); begin TBtnEditC(Sender).Text := ''; TBtnEditC(Sender).TxtCode := ''; end; procedure TfrmTatWBCardInPut.WB_MachNoBtnUpClick(Sender: TObject); var fsj: string; FWZ: Integer; begin fsj := Trim(TEdit(Sender).Hint); FWZ := Pos('/', fsj); try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := Copy(fsj, 1, FWZ - 1); flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ); if ShowModal = 1 then begin TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; end.