unit U_WBSpecEditSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, U_Basehelp, U_BaseList,
  System.ImageList, Vcl.ImgList;

type
  TfrmWBSpecEditSel = class(TfrmBasehelp)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    TBDel: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column8: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Y_Name: TEdit;
    Y_Spec: TEdit;
    Brand: TEdit;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    ToolButton2: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    canshu1, FSTKName, canshu3: string;
    procedure InitGrid();
    { Private declarations }
  public

    { Public declarations }
  end;

var
  frmWBSpecEditSel: TfrmWBSpecEditSel;

implementation

uses
  U_DataLink, U_RTFun, U_WBSpecInPut, U_ZDYHelp;

{$R *.dfm}

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

procedure TfrmWBSpecEditSel.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(DParameters1);
  FSTKName := Trim(DParameters2);
  canshu3 := Trim(DParameters3);
end;

procedure TfrmWBSpecEditSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.*  from Tat_WB_Spec A');
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWBSpecEditSel.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmWBSpecEditSel.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(Self.Caption, Tv1, '染色坯布仓库');
end;

procedure TfrmWBSpecEditSel.ToolButton2Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmWBSpecEditSel.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ToolButton2.Click;
end;

procedure TfrmWBSpecEditSel.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

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

procedure TfrmWBSpecEditSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Self.Caption, Tv1, '染色坯布仓库');
  InitGrid();
end;

procedure TfrmWBSpecEditSel.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel(trim(self.Caption), cxGrid2);
end;

procedure TfrmWBSpecEditSel.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmWBSpecEditSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmWBSpecEditSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmWBSpecEditSel.TBDelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_WB_IO where WB_Code=''' + Trim(CDS_Main.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_Main.fieldbyname('WBSID').AsString) + '''');
      ExecSQL;
    end;

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

end;

procedure TfrmWBSpecEditSel.TBAddClick(Sender: TObject);
begin
  try
    frmYarnInfoInPut := TfrmYarnInfoInPut.Create(Application);
    with frmYarnInfoInPut do
    begin
      FWBSID := '';
      FSTKName := self.FSTKName;
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmYarnInfoInPut.Free;
  end;
end;

procedure TfrmWBSpecEditSel.TBEditClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  try
    frmYarnInfoInPut := TfrmYarnInfoInPut.Create(Application);
    with frmYarnInfoInPut do
    begin
      FWBSID := Trim(CDS_Main.fieldbyname('WBSID').AsString);
      FSTKName := self.FSTKName;
      TBDel.Visible := False;
      TBAdd.Visible := False;
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmYarnInfoInPut.Free;
  end;
end;

end.

