unit U_BPZdy_LRGX;

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_LRGX = class(TForm)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    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;
    Panel2: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    ZGYName: TEdit;
    ZGYCode: TEdit;
    GYName: TEdit;
    GYCode: TEdit;
    Button1: TButton;
    Panel5: TPanel;
    ToolBar3: TToolBar;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBGYCode: TcxGridDBColumn;
    cxGridDBGYName: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel4: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    HGYNameM: TEdit;
    HGYCodeM: TEdit;
    GYNameM: TEdit;
    GYCodeM: TEdit;
    Button2: TButton;
    Panel1: TPanel;
    Label12: TLabel;
    DASH: TBtnEditA;
    Panel6: TPanel;
    Label1: TLabel;
    Panel7: TPanel;
    Label2: TLabel;
    CDS_LS: TClientDataSet;
    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 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 ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure DASHBtnClick(Sender: TObject);
    procedure V1BPNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure TV4CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    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);
  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_LRGX: TfrmBPZDY_LRGX;

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

{$R *.dfm}
procedure TfrmBPZDY_LRGX.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.SaveData();
var maxno:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if FBPID='' then
    begin
      if GetLSNo(ADOQueryTemp,FBPID,'GY','GY_ZDY',3,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大编号失败！','提示',0);
        Exit;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from GY_ZDY where GYID='''+Trim(FBPID)+'''');
      Open;
    end;
    if ADOQueryCmd.IsEmpty then
    begin
      ADOQueryCmd.Append;
      ADOQueryCmd.FieldByName('fillcode').Value:=trim(DCode);
      ADOQueryCmd.FieldByName('filler').Value:=trim(DName);
    end
    else
    begin
      ADOQueryCmd.Edit;
    end;
    ADOQueryCmd.FieldByName('GYID').Value:=Trim(FBPID);
    SSetsaveSqlNew(ADOQueryCmd,'GY_ZDY',panel2,2);
    ADOQueryCmd.FieldByName('GYType').Value:=flagName;
    ADOQueryCmd.FieldByName('GYFlag').Value:=flag;
    ADOQueryCmd.FieldByName('valid').Value:='Y';
    ADOQueryCmd.Post;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('select * from GY_ZDY where GYCode='''+Trim(GYCode.Text)+'''');
      sql.Add(' and GYFlag='''+trim(flag)+'''');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      if ADOQueryTemp.RecordCount>1 then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('染色代码重复！','提示',0);
        Exit;
      end;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('select * from GY_ZDY where GYName='''+Trim(GYName.Text)+'''');
      sql.Add(' and GYFlag='''+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 GY_ZDY where GYID='''+Trim(FBPID)+'''');
          ExecSQL;
        end;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('染色名称！','提示',0);
        Exit;
      end;
    end;
    with ClientDataSet1 do
    begin
      if Button1.Caption<>'确定修改' then
        Append
      else
        edit;
      FieldByName('GYID').Value:=Trim(FBPID);
      FieldByName('GYCode').Value:=Trim(GYCode.Text);
      FieldByName('GYName').Value:=Trim(GYName.Text);
      post;
    end;
    UPDateML();
    GYCode.Text:='';
    GYName.Text:='';
    FBPID:='';
    ADOQueryCmd.Connection.CommitTrans;
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmBPZDY_LRGX.HGYSaveData();
var maxno:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if FMXBPID='' then
    begin
      if GetLSNo(ADOQueryTemp,FMXBPID,'BP','GY_ZDY',3,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大编号失败！','提示',0);
        Exit;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from GY_ZDY where GYID='''+Trim(FMXBPID)+'''');
      Open;
    end;
    if ADOQueryCmd.IsEmpty then
    begin
      ADOQueryCmd.Append;
      ADOQueryCmd.FieldByName('Filler').Value:=Trim(Dname);
      ADOQueryCmd.FieldByName('Fillcode').Value:=Trim(DCode);
    end
    else
    begin
      ADOQueryCmd.Edit;
    end;
    ADOQueryCmd.FieldByName('GYID').Value:=Trim(FMXBPID);
    ADOQueryCmd.FieldByName('GYType').Value:=flagName;
    ADOQueryCmd.FieldByName('GYFlag').Value:=flag;
    ADOQueryCmd.FieldByName('valid').Value:='Y';
    ADOQueryCmd.FieldByName('GYType').Value:='HGY';
    ADOQueryCmd.FieldByName('ZGYCode').Value:='R';
    ADOQueryCmd.FieldByName('ZGYName').Value:='后工艺';
    ADOQueryCmd.FieldByName('GYCode').Value:=GYCodeM.Text;
    ADOQueryCmd.FieldByName('GYName').Value:=GYNameM.Text;
    ADOQueryCmd.Post;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('select * from GY_ZDY where GYCode='''+Trim(GYCodeM.Text)+'''');
      sql.Add(' and GYFlag='''+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 GY_ZDY where GYID='''+Trim(FMXBPID)+'''');
          ExecSQL;
        end;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('后工艺代码重复！','提示',0);
        Exit;
      end;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('select * from GY_ZDY where GYName='''+Trim(GYName.Text)+'''');
      sql.Add(' and GYFlag='''+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 GY_ZDY where GYID='''+Trim(FMXBPID)+'''');
          ExecSQL;
        end;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('后工艺名称重复！','提示',0);
        Exit;
      end;
    end;
    with ZDY_HGY do
    begin
      if Button2.Caption<>'确定修改' then
        Append
      else
        edit;
      FieldByName('GYID').Value:=Trim(FMXBPID);
      FieldByName('ZGYCode').Value:='R';
      FieldByName('ZGYName').Value:='后工艺';
      FieldByName('GYCode').Value:=Trim(GYCodeM.Text);
      FieldByName('GYName').Value:=Trim(GYNameM.Text);
      post;
    end;
    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(ZDY_HGY.fieldbyname('GYID').AsString)+''')');
      ExecSQL;
    end;
    GYCodeM.Text:='';
    GYNameM.Text:='';
    FMXBPID:='';
    ADOQueryCmd.Connection.CommitTrans;
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

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

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

procedure TfrmBPZDY_LRGX.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_LRGX.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_LRGX.TBAddClick(Sender: TObject);
var
  i:Integer;
  maxno,FH:string;
begin
  toolbar1.SetFocus;
  panel2.visible:=true;
  FBPID:='';
  Button1.Caption:='确定新增';
  GYCode.Text:='';
  GYName.Text:='';
end;

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

procedure TfrmBPZDY_LRGX.TBCloseClick(Sender: TObject);
begin
  //WriteCxGrid('自定义'+Trim(flag)+'3',TV1,'自定义数据');
  panel6.SetFocus;
  WriteCxGrid('自定义'+Trim(flag)+'4',TV4,'自定义数据');
  WriteCxGrid('自定义'+Trim(flag)+'2',TV3,'自定义数据');
  Close;
end;

procedure TfrmBPZDY_LRGX.FormShow(Sender: TObject);
begin
  InitGrid();
  HGYInitgrid();
  ReadCxGrid('自定义'+Trim(flag)+'4',TV4,'自定义数据');
  ReadCxGrid('自定义'+Trim(flag)+'2',TV3,'自定义数据');
  if formid='1' then
  begin
    cxGrid3.Visible:=false;
    Panel3.Align:=alClient;
    frmBPZDY_LRGX.FGYName:='染色';
    Label12.Visible:=false;
    DASH.Visible:=false;
  end;
  if canshu1='查询' then
  begin
    ToolButton1.Visible:=false;
    TBAdd.Visible:=false;
    TBDel.Visible:=false;
    ToolButton7.Visible:=false;
    ToolButton8.Visible:=false;
    button1.Visible:=false;
    Button2.Visible:=false;
  end
  else
  begin
    ToolButton1.Visible:=true;
    TBAdd.Visible:=true;
    TBDel.Visible:=true;
    ToolButton7.Visible:=true;
    ToolButton8.Visible:=true;
    button1.Visible:=true;
    Button2.Visible:=true;
  end;
  frmBPZDY_LRGX.Caption:=Trim(flagname);
  if ViewFlag=True then
  begin
    TBAdd.Visible:=False;
    TBDel.Visible:=False;
    ToolButton1.Visible:=true;
    Button1.Visible:=False;
    Button2.Visible:=False;
    ToolButton7.Visible:=False;
    ToolButton8.Visible:=False;
  end;
  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_LRGX.ToolButton1Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  Fint:='1'; 
  ModalResult:=1;
end;

procedure TfrmBPZDY_LRGX.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 ToolButton1.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('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('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('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('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_LRGX.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.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.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.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.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_LRGX.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_LRGX.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('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('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_LRGX.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);
    end;
    free;
  end;
end;

procedure TfrmBPZDY_LRGX.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.ToolButton7Click(Sender: TObject);
var
  i:Integer;
  maxno,FH:string;
begin
  toolbar1.SetFocus;
  Panel4.Visible:=true;
  FMXBPID:='';
  Button2.Caption:='确定新增';
  GYCodeM.Text:='';
  GYNameM.Text:='';
end;

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

procedure TfrmBPZDY_LRGX.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.TV4CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
begin
  if ToolButton1.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('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;

procedure TfrmBPZDY_LRGX.Button1Click(Sender: TObject);
begin
  if GYCode.text='' then
  begin
    application.messagebox('染色代码不能为空','提示');
    exit;
  end;
  savedata();
end;

procedure TfrmBPZDY_LRGX.Button2Click(Sender: TObject);
var
  maxno:string;
begin
  Toolbar1.SetFocus;
  if HGYCodeM.text='' then
  begin
    Application.MessageBox('后工艺代码不能为空！','提示',0);
    Exit;
  end;
  HGYSaveData();
  Application.MessageBox('保存成功！','提示',0);
end;

procedure TfrmBPZDY_LRGX.TV1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 // panel2.visible:=true;

  //BPMF.SetFocus;
  GYCode.Text:=Trim(ClientDataSet1.fieldbyname('GYCode').AsString);
  GYName.Text:=Trim(ClientDataSet1.fieldbyname('GYName').AsString);
  ZGYCode.Text:='R';
  ZGYName.Text:='染色';
  FBPID:=Trim(ClientDataSet1.fieldbyname('GYID').AsString);
  Button1.Caption:='确定修改';
end;

procedure TfrmBPZDY_LRGX.TV4MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 // Panel4.Visible:=true;
 // BPMF.SetFocus;
  HGYCodeM.Text:='R';
  HGYNameM.Text:='后工艺';
  GYCodeM.Text:=Trim(ZDY_HGY.fieldbyname('GYCode').AsString);
  GYNameM.Text:=Trim(ZDY_HGY.fieldbyname('GYName').AsString);
  FMXBPID:=Trim(ZDY_HGY.fieldbyname('GYID').AsString);
  Button2.Caption:='确定修改';
end;

procedure TfrmBPZDY_LRGX.FormDestroy(Sender: TObject);
begin
  frmBPZDY_LRGX:=nil;
end;

end.
