unit U_ZDYHelpFZSel; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ToolWin, ComCtrls, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls, cxCheckBox, cxTextEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges, System.ImageList, System.Types, cxDropDownEdit, cxButtonEdit, dxBarBuiltInMenu, cxGridCustomPopupMenu, cxGridPopupMenu, U_BaseHelp, BtnEdit; type TfrmZDYHelpFZSel = class(TForm) TV1: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; cxGrid1: TcxGrid; V1Name: TcxGridDBColumn; ToolBar1: TToolBar; ADOQueryMain: TADOQuery; ADOQueryTemp: TADOQuery; ADOQueryCmd: TADOQuery; DataSource1: TDataSource; ClientDataSet1: TClientDataSet; TBAdd: TToolButton; TBDel: TToolButton; TBClose: TToolButton; ToolButton1: TToolButton; TBEdit: TToolButton; ADOConnection1: TADOConnection; Panel1: TPanel; Label1: TLabel; ZDYName: TEdit; ThreeImgList: TImageList; V1Column1: TcxGridDBColumn; Label2: TLabel; TV1Column1: TcxGridDBColumn; cxgrdpmn1: TcxGridPopupMenu; BZType: TBtnEditC; Label3: TLabel; ImageList_new32: TImageList; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBAddClick(Sender: TObject); procedure TBDelClick(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure TBEditClick(Sender: TObject); procedure TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); procedure ZDYNameChange(Sender: TObject); procedure V1NamePropertiesEditValueChanged(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure TV1Column1PropertiesEditValueChanged(Sender: TObject); procedure BZTypeBtnDnClick(Sender: TObject); procedure BZTypeBtnUpClick(Sender: TObject); private procedure InitGrid(); { Private declarations } public flag, flagname, snote, MainType, ReturnStr, FGStr, FChkStr: string; fnote, forderno: Boolean; PPSTE, JiangeStr: integer; { Public declarations } end; var frmZDYHelpFZSel: TfrmZDYHelpFZSel; implementation uses U_DataLink, U_RTFun, U_ZDYHelp; {$R *.dfm} procedure TfrmZDYHelpFZSel.TBAddClick(Sender: TObject); var maxno: string; begin if Trim(BZType.Text) = '' then begin Application.MessageBox('类型不能为空!', '提示', 0); Exit; end; ZDYName.SetFocus; TV1.OptionsData.Editing := True; TV1.OptionsSelection.CellSelect := True; if GetLSNo(ADOQueryTemp, maxno, 'SY', 'KH_ZDY', 3, 1) = False then begin Application.MessageBox('取最大编号失败!', '提示', 0); Exit; end; with ClientDataSet1 do begin Append; fieldbyname('ZDYNo').Value := maxno; fieldbyname('Note').Value := BZType.Text; Post; end; with ADOQueryCmd do begin close; sql.Clear; sql.Add('insert into KH_ZDY(Type,MainType,ZDYNo,Note) '); sql.Add('values(' + quotedstr(Trim(flag))); sql.Add(',' + quotedstr(Trim(MainType))); sql.Add(',' + quotedstr(Trim(maxno))); sql.Add(',' + quotedstr(Trim(BZType.Text)) + ') '); ExecSQL; end; end; procedure TfrmZDYHelpFZSel.FormCreate(Sender: TObject); begin try cxGrid1.Align := alClient; with ADOConnection1 do begin Connected := false; ConnectionString := DConString; //ConnectionString:=''; Connected := true; end; except frmZDYHelpFZSel.Free; end; end; procedure TfrmZDYHelpFZSel.BZTypeBtnDnClick(Sender: TObject); begin TBtnEditC(Sender).Text := ''; TBtnEditC(Sender).TxtCode := ''; end; procedure TfrmZDYHelpFZSel.BZTypeBtnUpClick(Sender: TObject); var fsj: string; FWZ: Integer; begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := Trim(self.flag) + 'MX'; flagname := '类型'; if ShowModal = 1 then begin TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmZDYHelpFZSel.FormClose(Sender: TObject; var Action: TCloseAction); begin inherited; writeCxGrid('自定义' + Trim(flag), TV1, '自定义数据'); ZDYName.SetFocus; Action := caFree; end; procedure TfrmZDYHelpFZSel.InitGrid(); begin try ADOQueryMain.DisableControls; with ADOQueryMain do begin Close; sql.Clear; sql.Add('select * from KH_ZDY where Type=''' + flag + ''''); if Trim(MainType) <> '' then begin sql.Add(' and MainType=''' + Trim(MainType) + ''''); end; Open; end; SCreateCDS(ADOQueryMain, ClientDataSet1); SInitCDSData(ADOQueryMain, ClientDataSet1); finally ADOQueryMain.EnableControls; end; end; procedure TfrmZDYHelpFZSel.TBDelClick(Sender: TObject); begin if ClientDataSet1.IsEmpty then Exit; if (Trim(ClientDataSet1.FieldByName('ZDYNo').AsString) <> '') or (Trim(ClientDataSet1.FieldByName('ZDYname').AsString) <> '') then begin if application.MessageBox('确定要删除吗?', '提示信息', 1) = 2 then exit; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('delete KH_ZDY where ZDYNo=''' + Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString) + ''''); SQL.Add('and Type=''' + Trim(flag) + ''''); ExecSQL; end; end; ClientDataSet1.Delete; end; procedure TfrmZDYHelpFZSel.TBCloseClick(Sender: TObject); begin ModalResult := 2; ZDYName.SetFocus; WriteCxGrid('自定义包装要求1', TV1, '自定义数据'); Close; end; procedure TfrmZDYHelpFZSel.FormShow(Sender: TObject); var fsj, fsj1: string; FStrs: TStringList; i: integer; begin ReadCxGrid('自定义包装要求1', TV1, '自定义数据'); InitGrid(); fsj := Trim(flag) + '01'; fsj1 := Trim(flagname) + '01'; if Trim(FChkStr) <> '' then begin FStrs := TStringList.Create(); ExtractStrings(['|'], [' '], PChar(FChkStr), FStrs); frmZDYHelpFZSel.Caption := Trim(flagname); // for i := 0 to FStrs.Count-1 do // showmessage(FStrs[i]); with ClientDataSet1 do begin First; while not eof do begin if FStrs.IndexOf(Trim(FieldByName('ZDYName').AsString)) >= 0 then begin Edit; FieldByName('SSel').Value := true; Post; end; Next; end; end; FStrs.Free; end; end; procedure TfrmZDYHelpFZSel.ToolButton1Click(Sender: TObject); begin ReturnStr := ''; with ClientDataSet1 do begin First; while not Eof do begin if FieldByName('SSel').AsBoolean = True then begin if JiangeStr <> 99 then begin if FGStr <> '' then ReturnStr := ReturnStr + Trim(fieldbyname('ZDYName').AsString) + FGStr else ReturnStr := ReturnStr + Trim(fieldbyname('ZDYName').AsString) + ';' end else ReturnStr := ReturnStr + Trim(fieldbyname('ZDYName').AsString); end; Next; end; end; if JiangeStr <> 99 then ReturnStr := Copy(ReturnStr, 1, Length(ReturnStr) - 1); ModalResult := 1; end; procedure TfrmZDYHelpFZSel.TBEditClick(Sender: TObject); begin TV1.OptionsData.Editing := True; end; procedure TfrmZDYHelpFZSel.TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin if TV1.OptionsData.Editing = False then begin ModalResult := 1; end; end; procedure TfrmZDYHelpFZSel.TV1Column1PropertiesEditValueChanged(Sender: TObject); var mvalue, FFieldName: string; begin mvalue := TcxTextEdit(Sender).EditingText; FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName); with ClientDataSet1 do begin Edit; FieldByName(FFieldName).Value := mvalue; Post; end; with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('Update KH_Zdy Set ' + FFieldName + '=' + quotedstr(Trim(mvalue))); sql.Add(' where ZdyNo=''' + Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString) + ''''); ExecSQL; end; tv1.Controller.EditingController.ShowEdit(); end; procedure TfrmZDYHelpFZSel.ZDYNameChange(Sender: TObject); begin if ADOQueryMain.Active then begin SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2)); SCreateCDS(ADOQueryMain, ClientDataSet1); SInitCDSData(ADOQueryMain, ClientDataSet1); end; end; procedure TfrmZDYHelpFZSel.V1NamePropertiesEditValueChanged(Sender: TObject); var maxno, mvalue: string; begin mvalue := TcxTextEdit(Sender).EditingText; with ClientDataSet1 do begin Edit; FieldByName('ZDYName').Value := mvalue; Post; end; with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('Update KH_Zdy Set ZDYName=''' + Trim(mvalue) + ''''); sql.Add(' where ZdyNo=''' + Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString) + ''''); ExecSQL; end; end; procedure TfrmZDYHelpFZSel.FormDestroy(Sender: TObject); begin frmZDYHelpFZSel := nil; end; end.