unit U_WBSpecList;

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,
  dxDateRanges, U_BaseList, dxScrollbarAnnotations, cxContainer, cxMemo,
  dxSkinsCore, dxSkinsDefaultPainters, cxProgressBar, dxSkinOffice2013White,
  dxSkinSharpPlus, dxSkinWXI;

type
  TfrmWBSpecList = class(TfrmBaseList)
    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;
    TBDel: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column8: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column9: TcxGridDBColumn;
    Label2: TLabel;
    Label4: TLabel;
    WB_Code: TcxTextEdit;
    WB_Name: TcxTextEdit;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1Column18: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v1SPName: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    WB_YarnArrNote: TcxMemo;
    CDS_2: TClientDataSet;
    GPM_2: TcxGridPopupMenu;
    DS_2: TDataSource;
    ADO_2: TADOQuery;
    TV2Column1: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    ToolButton2: TToolButton;
    TV2Column5: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    TbLogLook: TToolButton;
    TV2FF: TcxGridDBColumn;
    TV2YarnFactor: TcxGridDBColumn;
    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 Y_NamePropertiesEditValueChanged(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure WB_CodePropertiesChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TbLogLookClick(Sender: TObject);
  private
    canshu1, FSTKName, canshu3: string;
    procedure InitGrid();
    { Private declarations }
  public

    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_WBSpecInPut, U_ZDYHelp, U_LabelPrint, U_LogInput;

{$R *.dfm}

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

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

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

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

procedure TfrmWBSpecList.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(Self.Caption + 'Tv1', Tv1, '经轴仓库');
  WriteCxGrid(Self.Caption + 'Tv2', Tv2, '经轴仓库');
end;

procedure TfrmWBSpecList.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'WBGYPrint';
      FFiltration1 := Trim(CDS_Main.fieldbyname('WB_Code').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmLabelPrint.Free;
  end;
end;

procedure TfrmWBSpecList.TbLogLookClick(Sender: TObject);
begin
  frmLogInput := TfrmLogInput.Create(Application);
  with frmLogInput do
  begin
    fWB_Code := Self.CDS_Main.FieldByName('WB_Code').AsString;
    fFlag := '查看';
    flogFlag := '整经工艺信息修改';
    if ShowModal = 1 then
    begin

    end;
  end;

end;

procedure TfrmWBSpecList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  WB_YarnArrNote.Text := Trim(CDS_Main.fieldbyname('WB_YarnArrNote').AsString);
  with ADO_2 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select * from Tat_WB_Formula ');
    sql.Add(' where WBSID=''' + Trim(CDS_Main.fieldbyname('WBSID').AsString) + '''');
    Open;
  end;
  SCreateCDS(ADO_2, CDS_2);
  SInitCDSData(ADO_2, CDS_2);
end;

procedure TfrmWBSpecList.WB_CodePropertiesChange(Sender: TObject);
begin

  TBFind.Click;

end;

procedure TfrmWBSpecList.Y_NamePropertiesEditValueChanged(Sender: TObject);
begin
  TBFind.Click;
end;

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

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

procedure TfrmWBSpecList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Self.Caption + 'Tv1', Tv1, '经轴仓库');
  ReadCxGrid(Self.Caption + 'Tv2', Tv2, '经轴仓库');
  InitGrid();
end;

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

procedure TfrmWBSpecList.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 TfrmWBSpecList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

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

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

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_WB_Card 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 TfrmWBSpecList.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 TfrmWBSpecList.TBEditClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  try
    frmWBSpecInPut := TfrmWBSpecInPut.Create(Application);
    with frmWBSpecInPut do
    begin
      FWBSID := Trim(CDS_Main.fieldbyname('WBSID').AsString);
      FSTKName := self.FSTKName;
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmWBSpecInPut.Free;
  end;
end;

end.

