unit U_BPZdy_LR;

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_LR = class(TForm)
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    V1BPCode: TcxGridDBColumn;
    V1BPMF1: TcxGridDBColumn;
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    TBAdd: TToolButton;
    TBSave: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    TBEdit: TToolButton;
    V1BPKZ: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    Label1: TLabel;
    BPName: TEdit;
    ThreeImgList: TImageList;
    V1BPJS: TcxGridDBColumn;
    V1Ssel: TcxGridDBColumn;
    v1BPMiDu: TcxGridDBColumn;
    Label2: TLabel;
    BPCode: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    ML_GYS: TClientDataSet;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGridPopupMenu3: TcxGridPopupMenu;
    DataSource3: TDataSource;
    ML_GX: TClientDataSet;
    v3BPMiDu: TcxGridDBColumn;
    v3BPMF: TcxGridDBColumn;
    v3BPKZ: TcxGridDBColumn;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2BPGYSName: TcxGridDBColumn;
    V2BPPrice: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DASH: TBtnEditA;
    Label12: TLabel;
    Label3: TLabel;
    DLHX: TBtnEditA;
    V1BPID: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBAddClick(Sender: TObject);
    procedure TBSaveClick(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 BPNameChange(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 ToolButton3Click(Sender: TObject);
    procedure TV1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure BPCodeChange(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure DASHBtnClick(Sender: TObject);
    procedure DLHXBtnClick(Sender: TObject);
    procedure TV1StylesGetContentStyle(Sender: TcxCustomGridTableView;
      ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
      out AStyle: TcxStyle);
    procedure V1BPNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    procedure InitGrid();
    procedure SaveData();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FGYName,Fint:string;
    fnote,fnote1,forderno,fZdyFlag,ViewFlag,fHelpType:Boolean;
    PPSTE:integer;
    { Public declarations }
  end;
var
  frmBPZDY_LR: TfrmBPZDY_LR;

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

{$R *.dfm}
procedure TfrmBPZDY_LR.SaveData();
var maxno:string;
begin
  if FGYName<>'' then exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if Trim(ClientDataSet1.FieldByName('BPID').AsString)='' then
        begin
          if GetLSNo(ADOQueryTemp,maxno,'BP','BP_ZDY',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('取最大编号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          maxno:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BP_ZDY where BPID='''+Trim(maxno)+'''');
          Open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          ADOQueryCmd.Append;
        end
        else
        begin
          ADOQueryCmd.Edit;
        end;
        ADOQueryCmd.FieldByName('BPID').Value:=Trim(maxno);
        SSetSaveDataCDSNew(ADOQueryCmd,Tv1,ClientDataSet1,'BP_ZDY',3);
        ADOQueryCmd.FieldByName('BPType').Value:=flagName;
        ADOQueryCmd.FieldByName('BPFlag').Value:=flag;
        ADOQueryCmd.FieldByName('valid').Value:='Y';
        ADOQueryCmd.Post;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.add('select * from BP_ZDY where BPCode='''+Trim(ClientDataSet1.fieldbyname('BPCode').AsString)+'''');
          sql.Add(' and BPFlag='''+trim(flag)+'''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          if ADOQueryTemp.RecordCount>1 then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              SQL.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
              ExecSQL;
            end;
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('编号重复！','提示',0);
            Exit;
          end;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.add('select * from BP_ZDY where BPName='''+Trim(ClientDataSet1.fieldbyname('BPName').AsString)+'''');
          sql.add(' and isnull(BPMF,'''')='''+Trim(ClientDataSet1.fieldbyname('BPMF').AsString)+'''');
          sql.add(' and isnull(BPKZ,'''')='''+Trim(ClientDataSet1.fieldbyname('BPKZ').AsString)+'''');
          sql.add(' and isnull(BPJS,'''')='''+Trim(ClientDataSet1.fieldbyname('BPJS').AsString)+'''');
          sql.add(' and isnull(BPWS,'''')='''+Trim(ClientDataSet1.fieldbyname('BPWS').AsString)+'''');
          sql.add(' and isnull(BPMiDu,'''')='''+Trim(ClientDataSet1.fieldbyname('BPMiDu').AsString)+'''');
          sql.Add(' and BPFlag='''+trim(flag)+'''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          if ADOQueryTemp.RecordCount>1 then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              SQL.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
              ExecSQL;
            end;
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('名称门幅克重经纱纬纱重复！','提示',0);
            Exit;
          end;
        end;
        ClientDataSet1.Edit;
        ClientDataSet1.FieldByName('BPID').Value:=Trim(maxno);
        //ClientDataSet1.Post;
        Next;
      end;
      ClientDataSet1.EnableControls;
    end;
    TV1.OptionsData.Editing:=false;
    TV1.OptionsSelection.CellSelect:=false;
    ADOQueryCmd.Connection.CommitTrans;
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

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

procedure TfrmBPZDY_LR.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ToolBar1.SetFocus;
  Action:=caFree;
end;

procedure TfrmBPZDY_LR.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      if FGYName<>'' then
      begin
        sql.Add('select B.BPCode,B.BPName,B.BPID,A.BPSubID,B.BPJS,B.BPWS,B.BPMiDu,B.BPUnit,');
        SQL.ADD('A.BPGYSName BPMF,A.BPPrice BPKZ from BP_ZDY_Sub A ');
        sql.Add('inner join BP_ZDY B on B.BPID=A.BPID ');
        sql.Add('where A.BPFlag='''+trim(flag)+''' and B.BPName='''+Trim(FGYName)+'''');
      end
      else
      begin
        sql.Add('select A.* from BP_ZDY A where A.BPFlag='''+trim(flag)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
    SCreateCDS20(ADOQueryMain,ML_GX);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LR.TBAddClick(Sender: TObject);
var
  i:Integer;
  maxno,FH:string;
begin
  toolbar1.SetFocus;
  TV1.OptionsData.Editing:=True;
  TV1.OptionsSelection.CellSelect:=True;
  if flagName='无纺布' then
  FH:='V';
  if flagName='棉花' then
  FH:='M';
  if flagName='绣线' then
  begin
    if GetLSNo(ADOQueryTemp,FH,'X','BP_ZDY',4,0)=False then
    begin
      Application.MessageBox('取最大编号失败！','提示',0);
      Exit;
    end;
  end;
  with ClientDataSet1 do
  begin
    Append;
    FieldByName('BPCode').Value:=FH;
    Post;
  end;
end;

procedure TfrmBPZDY_LR.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_LR.TBDelClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ClientDataSet1.IsEmpty then Exit;
  if Trim(ClientDataSet1.FieldByName('BPID').AsString)<>'' then
  begin
    if application.MessageBox('确定要删除吗?','提示信息',1)=2 then exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ClientDataSet1.Delete;
end;

procedure TfrmBPZDY_LR.TBCloseClick(Sender: TObject);
begin
  //WriteCxGrid('自定义'+Trim(flag)+'3',TV1,'自定义数据');
  ToolBar1.SetFocus;
  WriteCxGrid('自定义'+Trim(flag)+'1',TV2,'自定义数据');
  WriteCxGrid('自定义'+Trim(flag)+'2',TV3,'自定义数据');
  Close;
end;

procedure TfrmBPZDY_LR.FormShow(Sender: TObject);
begin
  InitGrid();
  //ReadCxGrid('自定义'+Trim(flag)+'3',TV1,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'1',TV2,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'2',TV3,'自定义数据');
  frmBPZDY_LR.Caption:=Trim(flagname);
  if ViewFlag=True then
  begin
    TBAdd.Visible:=False;
    TBSave.Visible:=False;
    TBDel.Visible:=False;
    TBEdit.Visible:=False;
    ToolBar2.Visible:=false;
    ToolButton1.Visible:=true;
  end;
end;

procedure TfrmBPZDY_LR.ToolButton1Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  Fint:='1'; 
  ModalResult:=1;
end;

procedure TfrmBPZDY_LR.TBEditClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  TV1.OptionsData.Editing:=True;
  TV1.OptionsSelection.CellSelect:=True;
end;

procedure TfrmBPZDY_LR.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
begin
  if ToolButton1.Visible=true then
  begin
    if flag='GXName' then
    begin
      with ML_GX do
      begin
        Append;
        FieldByName('BPMiDu').Value:=ML_GX.RecordCount+1;
        FieldByName('BPName').Value:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
        FieldByName('BPCode').Value:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
        FieldByName('BPMF').Value:=Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
        FieldByName('BPKZ').Value:=Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
        FieldByName('BPSubID').Value:=Trim(ClientDataSet1.fieldbyname('BPSubID').AsString);
        FieldByName('BPID').Value:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        Post;
      end;
    end
    else
    begin
      Fint:='1';
      ModalResult:=1;
    end;
  end;
end;

procedure TfrmBPZDY_LR.BPNameChange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(BPName.Text)<>'' then
  begin
    fsj:=' BPName like '''+'%'+Trim(BPName.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,fsj);
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  end;
end;

procedure TfrmBPZDY_LR.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_LR.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_LR.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_LR.V1BPCodePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPCode').Value:=mvalue;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update BP_ZDY Set BPCode='''+Trim(mvalue)+'''');
    sql.Add(' where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
    ExecSQL;
  end;}
end;

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

procedure TfrmBPZDY_LR.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 BP_ZDY_Sub where BPSubID='''+Trim(ML_GYS.fieldbyname('BPSubID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ML_GYS.Delete;
end;

procedure TfrmBPZDY_LR.ToolButton3Click(Sender: TObject);
  var maxno:string;
begin
  ToolBar1.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    ML_GYS.DisableControls;
    with ML_GYS do
    begin
      First;
      while not eof do
      begin
        if Trim(ML_GYS.FieldByName('BPSubID').AsString)='' then
        begin
          if GetLSNo(ADOQueryTemp,maxno,'BS','BP_ZDY_Sub',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            ML_GYS.EnableControls;
            Application.MessageBox('取最大编号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          maxno:=Trim(ML_GYS.fieldbyname('BPSubID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BP_ZDY_Sub where BPSubID='''+Trim(maxno)+'''');
          Open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          ADOQueryCmd.Append;
        end
        else
        begin
          ADOQueryCmd.edit;
        end;
        ADOQueryCmd.FieldByName('BPSubID').Value:=Trim(maxno);
        ADOQueryCmd.FieldByName('BPCode').Value:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
        ADOQueryCmd.FieldByName('BPID').Value:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        SSetSaveDataCDSNew(ADOQueryCmd,Tv2,ML_GYS,'BP_ZDY_Sub',1);
        ADOQueryCmd.FieldByName('BPPrice').Value:=ML_GYS.fieldbyname('BPPrice').AsString;
        ADOQueryCmd.FieldByName('BPType').Value:=flagName;
        ADOQueryCmd.FieldByName('BPFlag').Value:=flag;
        ADOQueryCmd.FieldByName('valid').Value:='Y';
        ADOQueryCmd.Post;
        ML_GYS.Edit;
        ML_GYS.FieldByName('BPSubID').Value:=Trim(maxno);
        Next;
      end;
      ML_GYS.EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！','提示',0);
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmBPZDY_LR.TV1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from BP_ZDY_Sub ');
    sql.Add('where BPID='''+trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,ML_GYS);
  SInitCDSData20(ADOQueryCmd,ML_GYS);
end;

procedure TfrmBPZDY_LR.BPCodeChange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(BPCode.Text)<>'' then
  begin
    fsj:=' BPCode like '''+'%'+Trim(BPCode.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,fsj);
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  end;
end;

procedure TfrmBPZDY_LR.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if ClientDataSet1.IsEmpty then exit;
  if Fint<>'1' then
  SaveData();
end;

procedure TfrmBPZDY_LR.Tv3CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:Integer;
begin
  if ML_GX.IsEmpty then exit;
  ML_GX.Delete;
  i:=1;
  ML_GX.DisableControls;
  with ML_GX do
  begin
    first;
    while not eof do
    begin
      Edit;
      FieldByName('BPMiDu').Value:=i;
      i:=i+1;
      next;
    end;
  end;
  ML_GX.EnableControls;
end;

procedure TfrmBPZDY_LR.DASHBtnClick(Sender: TObject);
begin
  frmBPZDY_SH:=TfrmBPZDY_SH.Create(self);
  with frmBPZDY_SH do
  begin
    flag:='SHK';
    flagName:='色号库';
    ViewFlag:=true;
    if ShowModal=1 then
    begin
      DASH.Text:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      DASH.TxtCode:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
      {ML_GYS.DisableControls;
      with ML_GYS do
      begin
        first;
        while not eof do
        begin
          with ML_Col do
          begin
            Append;
            FieldByName('BPSeHao').Value:=Trim(ML_GYS.fieldbyname('BPSeHao').AsString);
            FieldByName('BPCol').Value:=Trim(ML_GYS.fieldbyname('BPCol').AsString);
            FieldByName('BPColEng').Value:=Trim(ML_GYS.fieldbyname('BPColEng').AsString);
            FieldByName('BPNote').Value:=Trim(ML_GYS.fieldbyname('BPNote').AsString);
            post;
          end;
          Next;
        end;
      end;
      ML_GYS.EnableControls;}
    end;
    free;
  end;
end;

procedure TfrmBPZDY_LR.DLHXBtnClick(Sender: TObject);
begin
  frmBPZDY_HXK:=TfrmBPZDY_HXK.Create(self);
  with frmBPZDY_HXK do
  begin
    flag:='HXK';
    flagName:='花型库';
    ViewFlag:=true;
    if ShowModal=1 then
    begin
      DLHX.Text:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      DLHX.TxtCode:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
    end;
    free;
  end;
end;

procedure TfrmBPZDY_LR.TV1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id,id10:Integer;
begin
  {Id:=Tv1.GetColumnByFieldName('BPID').Index;
  if Id<0 then Exit;
  if VarToStr(ARecord.Values[id])<>'' then
   AStyle:=DataLink_YPGL.Red;}
end;

procedure TfrmBPZDY_LR.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;

end.
