unit U_WBSpecSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  System.ImageList, U_BaseInput, cxButtonEdit, cxCheckBox, Vcl.Menus,
  dxScrollbarAnnotations, cxImageList, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinOffice2013White, dxSkinSharpPlus, dxSkinWXI;

type
  TfrmWBSpecSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    Label1: TLabel;
    WB_Code: TEdit;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxImageList_bar: TcxImageList;
    Label2: TLabel;
    WB_Name: TEdit;
    TbAdd: TToolButton;
    TbEdit: TToolButton;
    TbDelete: TToolButton;
    Tv1WB_YarnKCQty: TcxGridDBColumn;
    Tv1BCRFQty: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure WB_CodeChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TbAddClick(Sender: TObject);
    procedure TbEditClick(Sender: TObject);
    procedure TbDeleteClick(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FSTKName, FAuthority, FYType: string;
    fWB_TYPE : string;
    { Public declarations }
  end;

var
  frmWBSpecSel: TfrmWBSpecSel;

implementation

uses
  U_DataLink, U_RTFun;
//    , U_WBSpecInPut
{$R *.dfm}

procedure TfrmWBSpecSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmWBSpecSel.WB_CodeChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;

end;

procedure TfrmWBSpecSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  WB_Code.SetFocus;
  Action := cahide;
end;

procedure TfrmWBSpecSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from Tat_WB_Spec A');
      SQL.Add(' where 1=1');
      sql.Add(' and isnull(ISSizing,''否'')=''否'' ');
      if Trim(fWB_TYPE) <> '' then
        sql.Add(' and WB_TYPE=' + QuotedStr(fWB_TYPE));
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWBSpecSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_1, true);

end;

procedure TfrmWBSpecSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);

end;

procedure TfrmWBSpecSel.FormShow(Sender: TObject);
begin
  inherited;

  InitGrid();

  ReadCxGrid('单位名称' + Trim(FSTKName), TV1, '自定义数据');

end;

procedure TfrmWBSpecSel.TBCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmWBSpecSel.TbDeleteClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_WB_Card where WB_Code=''' + Trim(CDS_1.fieldbyname('WB_Code').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('已开卡不能修改!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' delete Tat_WB_Spec where WBSID=''' + Trim(CDS_1.fieldbyname('WBSID').AsString) + '''');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    CDS_1.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('删除异常!', '提示', 0);
  end;

end;

procedure TfrmWBSpecSel.TbEditClick(Sender: TObject);
begin
//  if CDS_1.IsEmpty then
//    Exit;
//
//  try
//    frmWBSpecInPut := TfrmWBSpecInPut.Create(Application);
//    with frmWBSpecInPut do
//    begin
//      FWBSID := Trim(CDS_1.fieldbyname('WBSID').AsString);
//      FSTKName := self.FSTKName;
//      if ShowModal = 1 then
//      begin
//        Self.InitGrid();
//      end;
//    end;
//  finally
//    frmWBSpecInPut.Free;
//  end;
end;

procedure TfrmWBSpecSel.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid('单位名称' + Trim(FSTKName), TV1, '自定义数据');

end;

procedure TfrmWBSpecSel.ToolButton1Click(Sender: TObject);
begin
  WB_Code.SetFocus;
  ModalResult := 1;
end;

procedure TfrmWBSpecSel.TbAddClick(Sender: TObject);
begin
//  try
//    frmWBSpecInPut := TfrmWBSpecInPut.Create(Application);
//    with frmWBSpecInPut do
//    begin
//      FWBSID := '';
//      FSTKName := self.FSTKName;
//      if ShowModal = 1 then
//      begin
//        Self.InitGrid();
//      end;
//    end;
//  finally
//    frmWBSpecInPut.Free;
//  end;
end;

procedure TfrmWBSpecSel.TV1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmWBSpecSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmWBSpecSel := nil;
end;

end.

