unit U_BPZdy_LRTJ1;

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, cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxButtonEdit, BtnEdit;

type                                             
  TfrmBPZDY_LRTJ1 = class(TForm)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    ThreeImgList: TImageList;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    ML_GYS: TClientDataSet;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    cxGridPopupMenu3: TcxGridPopupMenu;
    DataSource3: TDataSource;
    ML_GX: TClientDataSet;
    v3XHNo: TcxGridDBColumn;
    v3GYCode: TcxGridDBColumn;
    v3GYName: TcxGridDBColumn;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Ssel: TcxGridDBColumn;
    V1GYCode: TcxGridDBColumn;
    V1GYName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource4: TDataSource;
    ZDY_HGY: TClientDataSet;
    Panel5: TPanel;
    ToolBar3: TToolBar;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBGYCode: TcxGridDBColumn;
    cxGridDBGYName: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel4: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    HGYNameM: TEdit;
    HGYCodeM: TEdit;
    Button2: TButton;
    Panel7: TPanel;
    Label2: TLabel;
    CDS_LS: TClientDataSet;
    V1GYNameQC: TcxGridDBColumn;
    V4GYNameQC: TcxGridDBColumn;
    v3GYNameQC: TcxGridDBColumn;
    Panel8: TPanel;
    Label14: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBSaveClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure V1NotePropertiesEditValueChanged(Sender: TObject);
    procedure V1HelpTypePropertiesEditValueChanged(Sender: TObject);
    procedure v1note1PropertiesEditValueChanged(Sender: TObject);
    procedure V1BPCodePropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure V1BPNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton6Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV4CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    FBPID,FMXBPID:string;
    procedure InitGrid();
    procedure SaveData();
    procedure HGYSaveData();
    procedure HGYInitGrid();
    procedure UPDateML();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FGYName,Fint,canshu1,formid:string;
    fnote,fnote1,forderno,fZdyFlag,ViewFlag,fHelpType:Boolean;
    PPSTE:integer;
    { Public declarations }
  end;
var
  frmBPZDY_LRTJ1: TfrmBPZDY_LRTJ1;

implementation
uses
  U_DataLink,U_Fun10,U_BPZdy_SH, U_BPZdy_HXK,U_ZDYHelp;

{$R *.dfm}
procedure TfrmBPZDY_LRTJ1.UPDateML();
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('update ML_Manage set GYLXName=dbo.F_Get_Order_SubStr(MLID,''GXName'')');
    sql.Add(' where exists (select GYID from ML_Manage_GX where MLID=ML_Manage.MLID ');
    sql.Add(' and GYID='''+trim(ClientDataSet1.fieldbyname('GYID').AsString)+''')');
    ExecSQL;
  end;
end;

procedure TfrmBPZDY_LRTJ1.SaveData();
begin

end;

procedure TfrmBPZDY_LRTJ1.HGYSaveData();
begin
 
end;

procedure TfrmBPZDY_LRTJ1.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmBPZDY_LRTJ1.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ToolBar1.SetFocus;
  WriteCxGrid('自定义'+Trim(flag)+'14',TV4,'自定义数据');
  WriteCxGrid('自定义'+Trim(flag)+'12',TV3,'自定义数据');
  WriteCxGrid('自定义'+Trim(flag)+'121',TV1,'自定义数据');
  Action:=caFree;
end;

procedure TfrmBPZDY_LRTJ1.HGYInitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag='''+trim(flag)+'''');
      sql.Add(' and isnull(GYType,'''')=''HGY''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ZDY_HGY);
    SInitCDSData20(ADOQueryMain,ZDY_HGY);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRTJ1.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag='''+trim(flag)+'''');
      sql.Add(' and isnull(GYType,'''')=''烫金''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
    if ML_GX.IsEmpty then
    begin
      SCreateCDS20(ADOQueryMain,ML_GX);
    end;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRTJ1.TBSaveClick(Sender: TObject);
var
  maxno:string;
begin
  if ClientDataSet1.IsEmpty then Exit;
  Toolbar1.SetFocus;
  if ClientDataSet1.Locate('BPCode',null,[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPCode','',[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPName',null,[]) then
  begin
    Application.MessageBox('简称不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPName','',[]) then
  begin
    Application.MessageBox('简称不能为空！','提示',0);
    Exit;
  end;
  SaveData();
  Application.MessageBox('保存成功！','提示',0);
end;

procedure TfrmBPZDY_LRTJ1.FormShow(Sender: TObject);
begin
  InitGrid();
  HGYInitgrid();
  ReadCxGrid('自定义'+Trim(flag)+'14',TV4,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'12',TV3,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'121',TV1,'自定义数据');
  if ML_GX.IsEmpty=False then
  begin
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if ML_GX.Locate('GYName',Trim(ClientDataSet1.fieldbyname('GYName').AsString),[])=True then
        begin
          ClientDataSet1.Delete;
        end else
        begin
          Next;
        end;
      end;
    end;
    with ZDY_HGY do
    begin
      First;
      while not eof do
      begin
        if ML_GX.Locate('GYName',Trim(ZDY_HGY.fieldbyname('GYName').AsString),[])=True then
        begin
          ZDY_HGY.Delete;
        end else
        begin
          Next;
        end;
      end;
    end;
  end;
end;

procedure TfrmBPZDY_LRTJ1.V1NotePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPKZ').Value:=mvalue;
    //Post;
  end;
end;

procedure TfrmBPZDY_LRTJ1.V1HelpTypePropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPWS').Value:=mvalue;
    Post;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update KH_Zdy Set HelpType='''+Trim(mvalue)+'''');
    sql.Add(' where ZdyNo='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
    ExecSQL;
  end;}
end;

procedure TfrmBPZDY_LRTJ1.v1note1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPMiDu').Value:=mvalue;
    Post;
  end;
end;

procedure TfrmBPZDY_LRTJ1.V1BPCodePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPCode').Value:=mvalue;
  end;
end;

procedure TfrmBPZDY_LRTJ1.ToolButton4Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ClientDataSet1.IsEmpty then exit;
  if ClientDataSet1.FieldByName('GYID').AsString='' then
  begin
    application.MessageBox('请保存主信息','提示');
    exit;
  end;
  with ML_GYS do
  begin
    Append;
    post;
  end;
end;

procedure TfrmBPZDY_LRTJ1.ToolButton5Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ML_GYS.IsEmpty then Exit;
  if Trim(ML_GYS.FieldByName('BPSubID').AsString)<>'' then
  begin
    if application.MessageBox('确定要删除吗?','提示信息',1)=2 then exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete GY_ZDY_Sub where BPSubID='''+Trim(ML_GYS.fieldbyname('BPSubID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ML_GYS.Delete;
end;

procedure TfrmBPZDY_LRTJ1.Tv3CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:Integer;
begin
  if ML_GX.IsEmpty then exit;
  if ML_GX.FieldByName('ZGYName').AsString='烫金' then
  begin
    if ML_GX.Locate('ZGYName','烫金',[])=true then Exit;
    with ClientDataSet1 do
    begin
      append;
      FieldByName('GYName').Value:=Trim(ML_GX.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ML_GX.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ML_GX.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ML_GX.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ML_GX.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ML_GX.fieldbyname('GYID').AsString);
      post;
    end;
  end
  else
  begin
    with ZDY_HGY do
    begin
      append;
      FieldByName('GYName').Value:=Trim(ML_GX.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ML_GX.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ML_GX.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ML_GX.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ML_GX.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ML_GX.fieldbyname('GYID').AsString);
      post;
    end;
  end;
  ML_GX.Delete;
  i:=1;
  ML_GX.DisableControls;
  with ML_GX do
  begin
    first;
    while not eof do
    begin
      Edit;
      FieldByName('XHNo').Value:=i;
      i:=i+1;
      next;
    end;
  end;
  ML_GX.EnableControls;
end;

procedure TfrmBPZDY_LRTJ1.V1BPNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.create(self);
  with frmZDYHelp do
  begin
    frmZDYHelp.flag:='BPName';
    frmZDYHelp.flagName:='简称';
    frmZDYHelp.MainType:=Self.flag;
    if DName<>'ADMIN' then
    begin
      ViewFlag:=true;
    end;
    if ShowModal=1 then
    begin
      with Self.ClientDataSet1 do
      begin
        edit;
        FieldByName('BPName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    Free;
  end;
end;

procedure TfrmBPZDY_LRTJ1.ToolButton6Click(Sender: TObject);
var
  maxno:string;
begin
  if ZDY_HGY.IsEmpty then Exit;
  Toolbar1.SetFocus;
  if ZDY_HGY.Locate('BPCode',null,[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ZDY_HGY.Locate('BPCode','',[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ZDY_HGY.Locate('BPName',null,[]) then
  begin
    Application.MessageBox('简称不能为空！','提示',0);
    Exit;
  end;
  if ZDY_HGY.Locate('BPName','',[]) then
  begin
    Application.MessageBox('简称不能为空！','提示',0);
    Exit;
  end;
  HGYSaveData();
  Application.MessageBox('保存成功！','提示',0);
end;

procedure TfrmBPZDY_LRTJ1.Button2Click(Sender: TObject);
var
  maxno:string;
begin
  Toolbar1.SetFocus;
  Fint:='1';
  ModalResult:=1;
end;

procedure TfrmBPZDY_LRTJ1.FormDestroy(Sender: TObject);
begin
  frmBPZDY_LRTJ1:=nil;
end;

procedure TfrmBPZDY_LRTJ1.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
    FGYName:string;
begin
  FGYName:=Trim(ClientDataSet1.fieldbyname('ZGYName').AsString);
  //if button2.Visible=true then
  begin
    if ML_GX.Locate('ZGYName',Trim(FGYName),[])=true then
    begin
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.* from GY_ZDY A where 1=2');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_LS);
      SInitCDSData20(ADOQueryMain,CDS_LS);
      with CDS_LS do
      begin
        append;
        FieldByName('GYName').Value:=Trim(ML_GX.fieldbyname('GYName').AsString);
        FieldByName('GYNameQC').Value:=Trim(ML_GX.fieldbyname('GYNameQC').AsString);
        FieldByName('GYCode').Value:=Trim(ML_GX.fieldbyname('GYCode').AsString);
        FieldByName('ZGYName').Value:=Trim(ML_GX.fieldbyname('ZGYName').AsString);
        FieldByName('ZGYCode').Value:=Trim(ML_GX.fieldbyname('ZGYCode').AsString);
        FieldByName('GYID').Value:=Trim(ML_GX.fieldbyname('GYID').AsString);
        post;
      end;
      with ML_GX do
      begin
        Edit;
        FieldByName('GYName').Value:=Trim(ClientDataSet1.fieldbyname('GYName').AsString);
        FieldByName('GYNameQC').Value:=Trim(ClientDataSet1.fieldbyname('GYNameQC').AsString);
        FieldByName('GYCode').Value:=Trim(ClientDataSet1.fieldbyname('GYCode').AsString);
        FieldByName('ZGYName').Value:=Trim(ClientDataSet1.fieldbyname('ZGYName').AsString);
        FieldByName('ZGYCode').Value:=Trim(ClientDataSet1.fieldbyname('ZGYCode').AsString);
        FieldByName('GYID').Value:=Trim(ClientDataSet1.fieldbyname('GYID').AsString);
        Post;
      end;
      with ClientDataSet1 do
      begin
        Edit;
        FieldByName('GYName').Value:=Trim(CDS_LS.fieldbyname('GYName').AsString);
        FieldByName('GYNameQC').Value:=Trim(CDS_LS.fieldbyname('GYNameQC').AsString);
        FieldByName('GYCode').Value:=Trim(CDS_LS.fieldbyname('GYCode').AsString);
        FieldByName('ZGYName').Value:=Trim(CDS_LS.fieldbyname('ZGYName').AsString);
        FieldByName('ZGYCode').Value:=Trim(CDS_LS.fieldbyname('ZGYCode').AsString);
        FieldByName('GYID').Value:=Trim(CDS_LS.fieldbyname('GYID').AsString);
        Post;
      end;
    end else
    begin
      with ML_GX do
      begin
        Append;
        FieldByName('XHNo').Value:=ML_GX.RecordCount+1;
        FieldByName('GYName').Value:=Trim(ClientDataSet1.fieldbyname('GYName').AsString);
        FieldByName('GYNameQC').Value:=Trim(ClientDataSet1.fieldbyname('GYNameQC').AsString);
        FieldByName('GYCode').Value:=Trim(ClientDataSet1.fieldbyname('GYCode').AsString);
        FieldByName('ZGYName').Value:=Trim(ClientDataSet1.fieldbyname('ZGYName').AsString);
        FieldByName('ZGYCode').Value:=Trim(ClientDataSet1.fieldbyname('ZGYCode').AsString);
        FieldByName('GYID').Value:=Trim(ClientDataSet1.fieldbyname('GYID').AsString);
        Post;
      end;
      ClientDataSet1.Delete;
    end;
  end;
end;

procedure TfrmBPZDY_LRTJ1.TV4CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
begin
  //if button2.Visible=true then
  begin
    with ML_GX do
    begin
      Append;
      FieldByName('XHNo').Value:=ML_GX.RecordCount+1;
      FieldByName('GYName').Value:=Trim(ZDY_HGY.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ZDY_HGY.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ZDY_HGY.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ZDY_HGY.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ZDY_HGY.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ZDY_HGY.fieldbyname('GYID').AsString);
      Post;
    end;
    ZDY_HGY.Delete;
  end;
end;

end.
