unit U_TatPlanJTSCLIST;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxCheckBox,
  BtnEdit, RM_BarCode, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxDateRanges, dxBarBuiltInMenu, U_BaseList, Vcl.Menus, dxScrollbarAnnotations,
  cxContainer, dxCore, cxDateUtils, cxMaskEdit, cxDropDownEdit, dxSkinsCore,
  dxSkinsDefaultPainters, cxProgressBar, dxSkinOffice2013White, dxSkinSharpPlus,
  dxSkinWXI;

type
  TfrmTatPlanJTSCLIST = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryPrint: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    ToolButton2: TToolButton;
    Label5: TLabel;
    MCType: TcxTextEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton5: TToolButton;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v3Column8: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    v3Column16: TcxGridDBColumn;
    v3Column6: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    CDS_2: TClientDataSet;
    DS_2: TDataSource;
    GPM_2: TcxGridPopupMenu;
    cxTabSheet3: TcxTabSheet;
    CDS_3: TClientDataSet;
    DS_3: TDataSource;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Tv1C_Name: TcxGridDBColumn;
    Tv1C_Composition: TcxGridDBColumn;
    Tv1C_Width: TcxGridDBColumn;
    Tv1Density: TcxGridDBColumn;
    Tv1YarnZS: TcxGridDBColumn;
    Tv1ConNo: TcxGridDBColumn;
    Tv3C_Code: TcxGridDBColumn;
    Tv3dayqty: TcxGridDBColumn;
    Tv3C_Composition: TcxGridDBColumn;
    Tv3C_Name: TcxGridDBColumn;
    Tv3C_Width: TcxGridDBColumn;
    Tv3YarnZS: TcxGridDBColumn;
    Tv3Density: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ConNoPropertiesChange(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
  private
    FInt, PFInt: Integer;
    FFMainID, BPFlag: string;
    procedure InitGrid();
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_TatCardInPut1;

{$R *.dfm}

procedure TfrmTatPlanJTSCLIST.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  WriteCxGrid('DCG13', Tv1, '坯布生产');
end;

procedure TfrmTatPlanJTSCLIST.TBCloseClick(Sender: TObject);
begin
  Close;

end;

procedure TfrmTatPlanJTSCLIST.InitGrid();
begin
  if cxPageControl1.ActivePageIndex = 0 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('EXEC P_Tat_Plan_Mach_MX ');

        Open;
      end;
      SCreateCDS(ADOQueryMain, CDS_1);
      SInitCDSData(ADOQueryMain, CDS_1);
    finally
      ADOQueryMain.EnableControls;
    end;
  end
  else if cxPageControl1.ActivePageIndex = 1 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('EXEC P_Tat_Plan_Mach_hz ');

        Open;
      end;
      SCreateCDS(ADOQueryMain, CDS_2);
      SInitCDSData(ADOQueryMain, CDS_2);
    finally
      ADOQueryMain.EnableControls;
    end;
  end
  else if cxPageControl1.ActivePageIndex = 2 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('EXEC P_Tat_Plan_Mach_HTHZ ');

        Open;
      end;
      SCreateCDS(ADOQueryMain, CDS_3);
      SInitCDSData(ADOQueryMain, CDS_3);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;

end;

procedure TfrmTatPlanJTSCLIST.N1Click(Sender: TObject);
begin
  SelOKNo(cds_1, true)
end;

procedure TfrmTatPlanJTSCLIST.N2Click(Sender: TObject);
begin
  SelOKNo(cds_1, false);
end;

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

procedure TfrmTatPlanJTSCLIST.ToolButton1Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  Tv1.OnFocusedRecordChanged := nil;
  if CDS_1.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := SelcdsKey(CDS_1, ['PCID'])[0];

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FPreviewPrint := False;
      FLMType := 'TatPlanCard';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin
        Self.InitGrid();
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update Tat_Plan_Card         ');
          sql.Add('set PRTer=' + quotedstr(DName));
          sql.Add(', PRTCount=PRTCount+1');
          sql.Add(', PRTDate=getdate()');
          sql.Add('where EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + QuotedStr(WSql) + ','','') X where Tat_Plan_Card.PCID=X.RTValue )  ');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmTatPlanJTSCLIST.ToolButton2Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption) + '1', Tv1, '坯布生产');
  WriteCxGrid(trim(self.Caption) + '2', Tv2, '坯布生产');
end;

procedure TfrmTatPlanJTSCLIST.ToolButton3Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  Tv1.OnFocusedRecordChanged := nil;
  if CDS_1.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := '';
  CDS_1.DisableControls;

  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      if CDS_1.fieldbyname('SSel').AsBoolean then
      begin
        if WSql <> '' then
        begin
          WSql := WSql + ',' + (Trim(CDS_1.fieldbyname('PCID').AsString));
        end
        else
        begin
          WSql := (Trim(CDS_1.fieldbyname('PCID').AsString));
        end;
      end;
      Next;
    end;
  end;

  CDS_1.Locate('SSel', True, []);
  CDS_1.EnableControls;

  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Card_Del ');
      Sql.Add('@PCIDS=' + quotedstr(Trim(WSql)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
    application.MessageBox('删除成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatPlanJTSCLIST.ToolButton4Click(Sender: TObject);
begin
  try
    frmTatCardInPut1 := TfrmTatCardInPut1.Create(Application);
    with frmTatCardInPut1 do
    begin
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTatCardInPut1.Free;
  end;
end;

procedure TfrmTatPlanJTSCLIST.ToolButton5Click(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatPlanJTSCLIST.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

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

  ReadCxGrid(trim(self.Caption) + '1', Tv1, '坯布生产');
  ReadCxGrid(trim(self.Caption) + '2', Tv2, '坯布生产');
  InitGrid();
end;

procedure TfrmTatPlanJTSCLIST.ConNoPropertiesChange(Sender: TObject);
begin
  ToolButton5.Click;
end;

procedure TfrmTatPlanJTSCLIST.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmTatPlanJTSCLIST.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

