unit U_YEYarnDRInPut; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils, cxDropDownEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu, U_BaseList; type TfrmYEYarnDRInPut = class(Tform) ToolBar1: TToolBar; TBSave: TToolButton; TBClose: TToolButton; ScrollBox1: TScrollBox; ToolBar2: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; ADOTemp: TADOQuery; ADOCmd: TADOQuery; DataSource1: TDataSource; Order_Sub: TClientDataSet; ADOQuery1: TADOQuery; cxGridPopupMenu2: TcxGridPopupMenu; Label1: TLabel; OutType: TComboBox; Note: TEdit; Label12: TLabel; Label11: TLabel; ToCoName: TBtnEditC; v1Column1: TcxGridDBColumn; cv1Column3: TcxGridDBColumn; cxStyleRepository1: TcxStyleRepository; dazi1: TcxStyle; v1Column2: TcxGridDBColumn; v1Column5: TcxGridDBColumn; v1Column6: TcxGridDBColumn; v1Column7: TcxGridDBColumn; Label2: TLabel; DlyDate: TDateTimePicker; Tv1Column2: TcxGridDBColumn; ToolButton3: TToolButton; Tv1Column6: TcxGridDBColumn; ToolButton4: TToolButton; Label27: TLabel; QtyUnit: TComboBox; Tv1Column1: TcxGridDBColumn; procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure ToCoNameBtnUpClick(Sender: TObject); procedure ToCoNameBtnDnClick(Sender: TObject); procedure JSQtyUnitChange(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); private fuserName: string; procedure InitData(); function SaveData(): Boolean; { Private declarations } public PState, CopyInt: Integer; FDRMID: string; { Public declarations } end; var frmYEYarnDRInPut: TfrmYEYarnDRInPut; newh: hwnd; implementation uses U_DataLink, U_ZDYHelp, U_RTFun, U_YEYarnPlanSel, U_CompanySel; {$R *.dfm} procedure TfrmYEYarnDRInPut.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmYEYarnDRInPut.InitData(); var fsj: string; begin if PState = 0 then begin DlyDate.DateTime := strtodatetime(Trim(FormatDateTime('yyyy-MM-dd', Now))); end; with ADOQuery1 do begin Close; SQL.Clear; sql.Add(' select A.* '); sql.Add(' from YE_Yarn_DR_Sub A'); if PState = 1 then begin sql.Add('where DRMID=''' + Trim(FDRMID) + ''''); end; if PState = 0 then begin sql.Add(' where 1<>1'); end; Open; end; SCreateCDS(ADOQuery1, Order_Sub); SInitCDSData(ADOQuery1, Order_Sub); with ADOQuery1 do begin Close; sql.Clear; sql.Add('select A.* '); sql.Add(' from YE_Yarn_DR_Main A'); sql.Add(' where DRMID=''' + Trim(FDRMID) + ''' '); Open; end; SCSHData(ADOQuery1, ScrollBox1, 1); end; procedure TfrmYEYarnDRInPut.JSQtyUnitChange(Sender: TObject); begin if not Order_Sub.IsEmpty then begin exit; end; end; procedure TfrmYEYarnDRInPut.FormShow(Sender: TObject); var fsj: string; begin readCxGrid(trim(self.Caption), Tv1, '加弹纱线仓库'); InitData(); end; function TfrmYEYarnDRInPut.SaveData(): Boolean; var MaxMid, MaxSid: string; begin try ADOCmd.Connection.BeginTrans; ///////////////// 保存主表 ///////////////// if Trim(FDRMID) = '' then begin if GetLSNo(ADOCmd, MaxMid, 'YED', 'YE_Yarn_DR_Main', 4, 1) = False then raise Exception.Create('取最大号失败!'); end else begin MaxMid := Trim(FDRMID); end; with ADOCmd do begin Close; sql.Clear; SQL.Add('select * from YE_Yarn_DR_Main where DRMID=''' + Trim(MaxMid) + ''''); Open; end; with ADOCmd do begin if Trim(FDRMID) = '' 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(ADOTemp); end; RTSetsavedata(ADOCmd, 'YE_Yarn_DR_Main', ScrollBox1, 1); FieldByName('DRMID').Value := Trim(MaxMid); FieldByName('Status').Value := '0'; Post; end; ///////////////// 保存主表 ///////////////// /// ///////////////// 保存子表 ///////////////// Order_Sub.DisableControls; with Order_Sub do begin First; while not Eof do begin if Trim(Order_Sub.fieldbyname('DRSID').AsString) = '' then begin if GetLSNo(ADOCmd, MaxSid, 'YDS', 'YE_Yarn_DR_Sub', 4, 1) = False then raise Exception.Create('取子流水号失败!'); end else begin MaxSid := Trim(Order_Sub.fieldbyname('DRSID').AsString); end; with ADOCmd do begin Close; SQL.Clear; sql.Add('select * from YE_Yarn_DR_Sub '); sql.Add(' where DRMID=''' + Trim(MaxMid) + ''''); sql.Add(' and DRSID=''' + Trim(MaxSid) + ''''); Open; if ADOCmd.IsEmpty then begin Append; end else begin Edit; end; RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'YE_Yarn_DR_Sub', 0); FieldByName('DRMID').Value := Trim(MaxMid); FieldByName('DRSID').Value := Trim(MaxSid); FieldByName('QtyUnit').Value := QtyUnit.Text; FieldByName('MainId').Value := Order_Sub.fieldbyname('MainId').Value; // FieldByName('SubId').Value := Order_Sub.fieldbyname('SubId').Value; // FieldByName('ConMId').Value := Order_Sub.fieldbyname('ConMId').Value; // FieldByName('ConSId').Value := Order_Sub.fieldbyname('ConSId').Value; Post; end; Order_Sub.Edit; Order_Sub.FieldByName('DRSID').Value := Trim(MaxSid); Next; end; end; Order_Sub.EnableControls; ///////////////// 保存子表 ///////////////// FDRMID := Trim(MaxMid); ADOCmd.Connection.CommitTrans; Result := True; except ADOCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); Result := False; end; end; procedure TfrmYEYarnDRInPut.TBSaveClick(Sender: TObject); var Freal: Double; begin ToolBar1.SetFocus; if Trim(OutType.Text) = '' then begin Application.MessageBox('出库类型不能为空!', '提示', 0); Exit; end; if Trim(ToCoName.Text) = '' then begin Application.MessageBox('收获单位不能为空!', '提示', 0); Exit; end; if (Order_Sub.Locate('Piece', null, [])) and (Order_Sub.Locate('Qty', null, [])) = True then begin Application.MessageBox('细码申请匹数和数量不能全为空!', '提示', 0); Exit; end; if SaveData() then begin Application.MessageBox('保存成功!', '提示', 0); ModalResult := 1; end; end; procedure TfrmYEYarnDRInPut.ToolButton2Click(Sender: TObject); begin if Order_Sub.IsEmpty then Exit; if Trim(Order_Sub.fieldbyname('DRSID').AsString) <> '' then begin with ADOTemp do begin Close; sql.Clear; sql.Add('select * from YE_Yarn_DR_Sub where DRSID=''' + Trim(Order_Sub.fieldbyname('DRSID').AsString) + ''''); sql.add(' and isnull(DlyPiece,0)>0'); Open; end; if ADOTemp.IsEmpty = False then begin Application.MessageBox('已发货不能删除数据!', '提示', 0); exit; end; if Application.MessageBox('确定要删除数据吗?', '提示', 32 + 4) <> IDYES then Exit; with ADOCmd do begin Close; sql.Clear; sql.Add('delete YE_Yarn_DR_Sub where DRSID=''' + Trim(Order_Sub.fieldbyname('DRSID').AsString) + ''''); ExecSQL; end; // with ADOCmd do // begin // Close; // sql.Clear; // sql.Add('Update YE_Yarn_DR_Main Set '); // sql.Add('SQPSHZ=(select Sum(SQPS) from YE_Yarn_DR_Sub A where A.DRMID=YE_Yarn_DR_Main.DRMID)'); // sql.Add('where DRMID=''' + Trim(FDRMID) + ''''); // ExecSQL; // end; end; Order_Sub.Delete; end; procedure TfrmYEYarnDRInPut.ToolButton3Click(Sender: TObject); begin try frmYEYarnPlanSel := TfrmYEYarnPlanSel.Create(Application); with frmYEYarnPlanSel do begin if ShowModal = 1 then begin while Order_Sub.locate('SSel', true, []) do begin begin with Self.Order_Sub do begin Append; FieldByName('OrderNo').Value := Trim(frmYEYarnPlanSel.Order_Sub.fieldbyname('Orderno').AsString); FieldByName('MainId').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('MainId').Value; FieldByName('YE_Name').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('YE_Name').Value; FieldByName('YE_Code').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('YE_Code').Value; FieldByName('Y_Spec').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('Y_Spec').Value; FieldByName('Y_Color').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('Y_Color').Value; FieldByName('FtyName').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('FtyName').Value; FieldByName('BatchNo').Value := frmYEYarnPlanSel.Order_Sub.fieldbyname('BatchNo').Value; post; end; end; Order_Sub.Delete; end; end; end; finally frmYEYarnPlanSel.Free; end; end; procedure TfrmYEYarnDRInPut.ToolButton4Click(Sender: TObject); begin WriteCxGrid(trim(self.Caption), Tv1, '加弹纱线仓库') end; procedure TfrmYEYarnDRInPut.ToCoNameBtnUpClick(Sender: TObject); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '客户'; if ShowModal = 1 then begin self.ToCoName.TxtCode := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString); self.ToCoName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString); end; end; finally frmCompanySel.Free; end; end; procedure TfrmYEYarnDRInPut.ToCoNameBtnDnClick(Sender: TObject); begin ToCoName.Text := ''; end; end.