unit U_BPZdy_LRGX_CX;

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, Menus;

type
  TfrmBPZDY_LRGX_CX = class(TForm)
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    ThreeImgList: TImageList;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    DataSource3: TDataSource;
    ML_GX: TClientDataSet;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Ssel: TcxGridDBColumn;
    V1GYCode: TcxGridDBColumn;
    V1GYName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource4: TDataSource;
    ZDY_HGY: TClientDataSet;
    CDS_LS: TClientDataSet;
    V1GYNameQC: TcxGridDBColumn;
    ClientDataSet1: TClientDataSet;
    Panel1: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    v3XHNo: TcxGridDBColumn;
    v3GYCode: TcxGridDBColumn;
    v3GYName: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Button1: TButton;
    ToolBar1: TToolBar;
    Panel6: TPanel;
    Label1: TLabel;
    ToolBar3: TToolBar;
    Panel7: TPanel;
    Label2: TLabel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBGYCode: TcxGridDBColumn;
    cxGridDBGYName: TcxGridDBColumn;
    V4GYNameQC: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    ToolBar4: TToolBar;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBTableView;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    Panel4: TPanel;
    Label3: TLabel;
    Panel5: TPanel;
    Label4: TLabel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel8: TPanel;
    ToolBar5: TToolBar;
    ToolBar6: TToolBar;
    cxGrid6: TcxGrid;
    TV6: TcxGridDBTableView;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxGridPopupMenu5: TcxGridPopupMenu;
    cxGridPopupMenu6: TcxGridPopupMenu;
    cxGridPopupMenu7: TcxGridPopupMenu;
    ClientDataSet2: TClientDataSet;
    DataSource5: TDataSource;
    Panel9: TPanel;
    Label5: TLabel;
    Panel10: TPanel;
    Label6: TLabel;
    cxGrid7: TcxGrid;
    TV7: TcxGridDBTableView;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    DataSource6: TDataSource;
    ClientDataSet3: TClientDataSet;
    DataSource7: TDataSource;
    ClientDataSet4: TClientDataSet;
    DataSource8: TDataSource;
    ClientDataSet5: TClientDataSet;
    Panel11: TPanel;
    Button2: TButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBSaveClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure V1NotePropertiesEditValueChanged(Sender: TObject);
    procedure V1HelpTypePropertiesEditValueChanged(Sender: TObject);
    procedure v1note1PropertiesEditValueChanged(Sender: TObject);
    procedure V1BPCodePropertiesEditValueChanged(Sender: TObject);
    procedure V1BPNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton6Click(Sender: TObject);
    procedure TV4CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure TV2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV7CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV7MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV5CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV5MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV6CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV6MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure N1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    FBPID,FMXBPID:string;
    PXH:Integer;
    procedure InitGrid();
    procedure SaveData();
    procedure HGYSaveData();
    procedure HGYInitGrid();
    procedure UPDateML();
    procedure TJInitgrid();
    procedure TJHGYInitgrid();
    procedure YHInitgrid();
    procedure YHHGYInitgrid();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FGYName,Fint,canshu1,formid,FZGY:string;
    fnote,fnote1,forderno,fZdyFlag,ViewFlag,fHelpType:Boolean;
    PPSTE:integer;
    { Public declarations }
  end;
var
  frmBPZDY_LRGX_CX: TfrmBPZDY_LRGX_CX;

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

{$R *.dfm}
procedure TfrmBPZDY_LRGX_CX.YHInitgrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag=''YHName''');
      sql.Add(' and isnull(GYType,'''')=''印花''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet3);
    SInitCDSData20(ADOQueryMain,ClientDataSet3);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.YHHGYInitgrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag=''YHName''');
      sql.Add(' and isnull(GYType,'''')=''HGY''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet5);
    SInitCDSData20(ADOQueryMain,ClientDataSet5);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.TJHGYInitgrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag=''TJName''');
      sql.Add(' and isnull(GYType,'''')=''HGY''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet4);
    SInitCDSData20(ADOQueryMain,ClientDataSet4);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.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_LRGX_CX.SaveData();
begin
  
end;

procedure TfrmBPZDY_LRGX_CX.HGYSaveData();
begin
  
end;

procedure TfrmBPZDY_LRGX_CX.FormCreate(Sender: TObject);
begin
  try
    //cxGrid1.Align:=alClient;
    with ADOConnection1 do
    begin
      Connected:=false;
      ConnectionString:=DConString;
      //ConnectionString:='';
      Connected:=true;
    end;
  except;
    frmBPZDY_LRGX_CX.Free;
  end;
  canshu1:=Trim(DParameters1);
end;

procedure TfrmBPZDY_LRGX_CX.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ToolBar1.SetFocus;
  WriteCxGrid('自定义'+Trim(flag)+'4',TV4,'自定义数据');
  WriteCxGrid('自定义'+Trim(flag)+'2',TV3,'自定义数据');
  Action:=caFree;
end;

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

procedure TfrmBPZDY_LRGX_CX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag=''GXName''');
      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_LRGX_CX.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_LRGX_CX.TJInitgrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where A.GYFlag=''TJName''');
      sql.Add(' and isnull(GYType,'''')=''烫金''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet2);
    SInitCDSData20(ADOQueryMain,ClientDataSet2);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.FormShow(Sender: TObject);
begin
  InitGrid();
  HGYInitgrid();
  TJInitgrid();
  TJHGYInitgrid();
  YHInitgrid();
  YHHGYInitgrid();
  ReadCxGrid('自定义'+Trim(flag)+'4',TV4,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'2',TV3,'自定义数据');
end;

procedure TfrmBPZDY_LRGX_CX.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 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);
      FieldByName('GYFlag').Value:=Trim(ML_GX.fieldbyname('GYFlag').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);
      FieldByName('GYFlag').Value:=Trim(ClientDataSet1.fieldbyname('GYFlag').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);
      FieldByName('GYFlag').Value:=Trim(CDS_LS.fieldbyname('GYFlag').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);
      FieldByName('GYFlag').Value:=Trim(ClientDataSet1.fieldbyname('GYFlag').AsString);
      Post;
    end;
    ClientDataSet1.Delete;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.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_LRGX_CX.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_LRGX_CX.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_LRGX_CX.V1BPCodePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPCode').Value:=mvalue;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.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_LRGX_CX.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_LRGX_CX.TV4CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
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);
    FieldByName('GYFlag').Value:=Trim(ZDY_HGY.fieldbyname('GYFlag').AsString);
    Post;
  end;
  ZDY_HGY.Delete;
end;

procedure TfrmBPZDY_LRGX_CX.TV1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FBPID:=Trim(ClientDataSet1.fieldbyname('GYID').AsString);
end;

procedure TfrmBPZDY_LRGX_CX.TV4MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FMXBPID:=Trim(ZDY_HGY.fieldbyname('GYID').AsString);
end;

procedure TfrmBPZDY_LRGX_CX.FormDestroy(Sender: TObject);
begin
  frmBPZDY_LRGX_CX:=nil;
end;

procedure TfrmBPZDY_LRGX_CX.Button1Click(Sender: TObject);
var i:Integer;
begin
  ToolBar1.SetFocus;
  ML_GX.DisableControls;
  with ML_GX do
  begin
    first;
    i:=1;
    while not eof do
    begin
      if FieldByName('XHNo').Value=null then
      begin
        Delete;
      end
      else
      begin
        if ML_GX.Locate('XHNo',i,[])=true then
        begin
          ML_GX.Locate('XHNo',i,[]);
          if FZGY='' then
          begin
            FZGY:=trim(fieldbyname('GYName').AsString);
          end
          else
          FZGY:=FZGY+'+'+trim(fieldbyname('GYName').AsString);
          delete;
        end;
        i:=i+1;
      end;
    end;
  end;
  ML_GX.EnableControls;
  ModalResult:=1;
end;

procedure TfrmBPZDY_LRGX_CX.TV2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
    FGYName:string;
begin
  FGYName:=Trim(ClientDataSet2.fieldbyname('ZGYName').AsString);
  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);
      FieldByName('GYFlag').Value:=Trim(ML_GX.fieldbyname('GYFlag').AsString);
      post;
    end;
    with ML_GX do
    begin
      Edit;
      FieldByName('GYName').Value:=Trim(ClientDataSet2.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ClientDataSet2.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ClientDataSet2.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ClientDataSet2.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ClientDataSet2.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ClientDataSet2.fieldbyname('GYID').AsString);
      FieldByName('GYFlag').Value:=Trim(ClientDataSet2.fieldbyname('GYFlag').AsString);
      Post;
    end;
    with ClientDataSet2 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);
      FieldByName('GYFlag').Value:=Trim(CDS_LS.fieldbyname('GYFlag').AsString);
      Post;
    end;
  end else
  begin
    with ML_GX do
    begin
      Append;
      FieldByName('XHNo').Value:=ML_GX.RecordCount+1;
      FieldByName('GYName').Value:=Trim(ClientDataSet2.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ClientDataSet2.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ClientDataSet2.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ClientDataSet2.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ClientDataSet2.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ClientDataSet2.fieldbyname('GYID').AsString);
      FieldByName('GYFlag').Value:=Trim(ClientDataSet2.fieldbyname('GYFlag').AsString);
      Post;
    end;
    ClientDataSet2.Delete;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.TV7CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
    FGYName:string;
begin
  FGYName:=Trim(ClientDataSet3.fieldbyname('ZGYName').AsString);
  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);
      FieldByName('GYFlag').Value:=Trim(ML_GX.fieldbyname('GYFlag').AsString);
      post;
    end;
    with ML_GX do
    begin
      Edit;
      FieldByName('GYName').Value:=Trim(ClientDataSet3.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ClientDataSet3.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ClientDataSet3.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ClientDataSet3.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ClientDataSet3.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ClientDataSet3.fieldbyname('GYID').AsString);
      FieldByName('GYFlag').Value:=Trim(ClientDataSet3.fieldbyname('GYFlag').AsString);
      Post;
    end;
    with ClientDataSet3 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);
      FieldByName('GYFlag').Value:=Trim(CDS_LS.fieldbyname('GYFlag').AsString);
      Post;
    end;
  end else
  begin
    with ML_GX do
    begin
      Append;
      FieldByName('XHNo').Value:=ML_GX.RecordCount+1;
      FieldByName('GYName').Value:=Trim(ClientDataSet3.fieldbyname('GYName').AsString);
      FieldByName('GYNameQC').Value:=Trim(ClientDataSet3.fieldbyname('GYNameQC').AsString);
      FieldByName('GYCode').Value:=Trim(ClientDataSet3.fieldbyname('GYCode').AsString);
      FieldByName('ZGYName').Value:=Trim(ClientDataSet3.fieldbyname('ZGYName').AsString);
      FieldByName('ZGYCode').Value:=Trim(ClientDataSet3.fieldbyname('ZGYCode').AsString);
      FieldByName('GYID').Value:=Trim(ClientDataSet3.fieldbyname('GYID').AsString);
      FieldByName('GYFlag').Value:=Trim(ClientDataSet3.fieldbyname('GYFlag').AsString);
      Post;
    end;
    ClientDataSet3.Delete;
  end;
end;

procedure TfrmBPZDY_LRGX_CX.TV2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FBPID:=Trim(ClientDataSet2.fieldbyname('GYID').AsString);
end;

procedure TfrmBPZDY_LRGX_CX.TV7MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FBPID:=Trim(ClientDataSet3.fieldbyname('GYID').AsString);
end;

procedure TfrmBPZDY_LRGX_CX.TV5CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
begin
  with ML_GX do
  begin
    Append;
    FieldByName('XHNo').Value:=ML_GX.RecordCount+1;
    FieldByName('GYName').Value:=Trim(ClientDataSet4.fieldbyname('GYName').AsString);
    FieldByName('GYNameQC').Value:=Trim(ClientDataSet4.fieldbyname('GYNameQC').AsString);
    FieldByName('GYCode').Value:=Trim(ClientDataSet4.fieldbyname('GYCode').AsString);
    FieldByName('ZGYName').Value:=Trim(ClientDataSet4.fieldbyname('ZGYName').AsString);
    FieldByName('ZGYCode').Value:=Trim(ClientDataSet4.fieldbyname('ZGYCode').AsString);
    FieldByName('GYID').Value:=Trim(ClientDataSet4.fieldbyname('GYID').AsString);
    FieldByName('GYFlag').Value:=Trim(ClientDataSet4.fieldbyname('GYFlag').AsString);
    Post;
  end;
  ClientDataSet4.Delete;
end;

procedure TfrmBPZDY_LRGX_CX.TV5MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FMXBPID:=Trim(ClientDataSet4.fieldbyname('GYID').AsString);
end;

procedure TfrmBPZDY_LRGX_CX.TV6CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
begin
  with ML_GX do
  begin
    Append;
    FieldByName('XHNo').Value:=ML_GX.RecordCount+1;
    FieldByName('GYName').Value:=Trim(ClientDataSet5.fieldbyname('GYName').AsString);
    FieldByName('GYNameQC').Value:=Trim(ClientDataSet5.fieldbyname('GYNameQC').AsString);
    FieldByName('GYCode').Value:=Trim(ClientDataSet5.fieldbyname('GYCode').AsString);
    FieldByName('ZGYName').Value:=Trim(ClientDataSet5.fieldbyname('ZGYName').AsString);
    FieldByName('ZGYCode').Value:=Trim(ClientDataSet5.fieldbyname('ZGYCode').AsString);
    FieldByName('GYID').Value:=Trim(ClientDataSet5.fieldbyname('GYID').AsString);
    FieldByName('GYFlag').Value:=Trim(ClientDataSet5.fieldbyname('GYFlag').AsString);
    Post;
  end;
  ClientDataSet5.Delete;
end;

procedure TfrmBPZDY_LRGX_CX.TV6MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FMXBPID:=Trim(ClientDataSet5.fieldbyname('GYID').AsString);
end;

procedure TfrmBPZDY_LRGX_CX.N1Click(Sender: TObject);
var i:Integer;
begin
  if ML_GX.IsEmpty then exit;
  if ML_GX.FieldByName('GYFlag').AsString='GXName' then
  begin
    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;
  end;
  
  if ML_GX.FieldByName('GYFlag').AsString='TJName' then
  begin
    if ML_GX.FieldByName('ZGYName').AsString='烫金' then
    begin
      //if ML_GX.Locate('ZGYName','烫金',[])=true then Exit;
      with ClientDataSet2 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 ClientDataSet4 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;
  end;
  
  if ML_GX.FieldByName('GYFlag').AsString='YHName' then
  begin
    if ML_GX.FieldByName('ZGYName').AsString='印花' then
    begin
      //if ML_GX.Locate('ZGYName','印花',[])=true then Exit;
      with ClientDataSet3 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 ClientDataSet5 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;
  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_LRGX_CX.Button2Click(Sender: TObject);
begin
  ML_GX.DisableControls;
  with ML_GX do
  begin
    first;
    while not eof do
    begin
      Edit;
      FieldByName('XHNo').Value:=NULL;
      next;
    end;
  end;
  ML_GX.EnableControls;
  PXH:=1;
end;

procedure TfrmBPZDY_LRGX_CX.Tv3CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if ML_GX.FieldByName('XHNo').Value=NULL then
  begin
    with ML_GX do
    begin
      Edit;
      FieldByName('XHNo').Value:=PXH;
    end;
    PXH:=PXH+1;
  end;
  Panel11.SetFocus;
end;

end.
