unit U_BZAdd;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, DBClient, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, ComCtrls, ToolWin,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxTextEdit, cxButtonEdit,
  StdCtrls, ExtCtrls, cxCurrencyEdit, BtnEdit;

type
  TfrmBZAdd = class(TForm)
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    TBClose: TToolButton;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    GXName: TEdit;
    PSID: TEdit;
    Label3: TLabel;
    CDS_Sub: TClientDataSet;
    Label2: TLabel;
    BZName: TEdit;
    Label4: TLabel;
    BZID: TEdit;
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CYColorKeyPress(Sender: TObject; var Key: Char);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    canshu1:string;
    Fint:Integer;
    procedure InitSubGrid();
    function  SaveData():Boolean;
    { Private declarations }
  public
    FCYID,FCYCode,FCPID,FCPNO,FCPName:String;
    CopyInt:Integer;

    { Public declarations }
  end;

var
  frmBZAdd: TfrmBZAdd;

implementation
uses
  U_DataLink,U_Fun,U_iniParam,U_ZDYHelp, U_ZdyAttachGYS,U_FileUp;

{$R *.dfm}

procedure TfrmBZAdd.InitSubGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from JYOrder_Process where PSID='''+Trim(FCYID)+'''');
      Open;
    end;
    SCSHDataNew(ADOQueryMain,ScrollBox1,2);
    SCSHDataNew(ADOQueryMain,ScrollBox1,0);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBZAdd.FormShow(Sender: TObject);
begin
//  InitSubGrid();
 
end;

procedure TfrmBZAdd.TBCloseClick(Sender: TObject);
begin
  Close;
end;
function TfrmBZAdd.SaveData():Boolean;
var
  maxId,FCYNo:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from OA_YG_BZ where BZID='''+Trim(FCYID)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin

      Append;
     // FieldByName('Filler').Value:=Trim(DName);
      SSetsaveSqlNew(ADOQueryCmd,'OA_YG_BZ',ScrollBox1,2);
      Post;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select count(*) as AA from OA_YG_BZ where BZName='''+Trim(BZName.Text)+'''');
      Open;
      if FieldByName('AA').AsInteger>1 then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Result:=False;
        Application.MessageBox('班组重复！','提示',0);
        Exit;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmBZAdd.ToolButton1Click(Sender: TObject);
begin
  if BZName.Text='' then
  begin
    Application.MessageBox('班组名称不能为空！','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    ModalResult:=1;
  end;
end;

procedure TfrmBZAdd.CYColorKeyPress(Sender: TObject; var Key: Char);
var c: Integer;
begin
  if key='.' then
  begin
    for c:=1 to length(TEdit(Sender).text) do
    begin
      if Tedit(Sender).text[c]='.' then key:=#0;
    end;
  end
  else
    if key=#13 then PerForm(WM_NEXTDLGCTL,0,0)
    else
        if key=#8 then key:=#8
        else
          if (key<'0') or (key>'9') then
            key:=#0;
end;

procedure TfrmBZAdd.FormDestroy(Sender: TObject);
begin
frmBZAdd:=nil;
end;

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

end.
