unit U_TatWBPlanCard;

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,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, Vcl.Menus, cxContainer, dxScrollbarAnnotations, cxProgressBar;

type
  TfrmTatWBPlanCard = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    Label3: TLabel;
    ConNos: TEdit;
    ADOQueryPrint: TADOQuery;
    WB_MachNo: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    WB_ClothName: TEdit;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Label5: TLabel;
    OrderNos: TEdit;
    Label6: TLabel;
    BatchNo: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton3: TToolButton;
    Label7: TLabel;
    WBCID: TEdit;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    TV1Column8: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    TV1Column5: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    TV1Column4: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    TV1Column1: TcxGridDBColumn;
    TV1Column9: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    TV1Column6: TcxGridDBColumn;
    TV1Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolButton6: TToolButton;
    Label8: TLabel;
    Label10: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    TV1Column10: TcxGridDBColumn;
    TV1Column7: TcxGridDBColumn;
    TV1Column11: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNosChange(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 ToolButton6Click(Sender: TObject);
    procedure FormCreate(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_TatWBCardInPut, U_TatCardInPut,
  U_TatWBCardInPutXIUGAI;

{$R *.dfm}

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

procedure TfrmTatWBPlanCard.FormCreate(Sender: TObject);
begin
  inherited;
  InitGrid();
end;

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

end;

procedure TfrmTatWBPlanCard.InitGrid();
begin
  FFMainID := '';
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*  ');
      sql.Add(' from  Tat_WB_Card A ');
      sql.Add(' where  isnull(A.status,''0'')=''0''');
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and PRTCount=0');
          end;
        1:
          begin
            sql.Add(' and PRTCount>0');
            sql.add(' and A.FILLTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
            sql.Add(' and A.FILLTime<''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
          end;
        2:
          begin

          end;
      end;

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

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

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

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

procedure TfrmTatWBPlanCard.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 := '';
  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 + ',' + QuotedStr(Trim(CDS_1.fieldbyname('WBCID').AsString));
        end
        else
        begin
          WSql := QuotedStr(Trim(CDS_1.fieldbyname('WBCID').AsString));
        end;
      end;
      Next;
    end;
  end;

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

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FPreviewPrint := False;
      FLMType := 'TatWBCard';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin
        Self.InitGrid();
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update Tat_WB_Card         ');
          sql.Add(' set PRTer=' + quotedstr(DName));
          sql.Add(', PRTCount=PRTCount+1');
          sql.Add(', PRTDate=getdate()');
          sql.Add(' where WBCID in (' + WSql + ')');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

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

procedure TfrmTatWBPlanCard.ToolButton3Click(Sender: TObject);
var
  rtvalues: TArray<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;

  //删除提示 如果点击叉叉 就返回不执行删除
  if CDS_1.FieldByName('SSel').AsString <> '' then
  begin
    if Application.MessageBox('确定要删除吗？', '提示', MB_OKCANCEL) = IDOK then

  rtvalues := SelCDSKey(CDS_1, ['WBCID']);
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_TatWB_Card_Del ');
      Sql.Add('@WBCIDS=' + quotedstr(Trim(rtvalues[0])));
      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;
end;

procedure TfrmTatWBPlanCard.ToolButton4Click(Sender: TObject);
begin
  try
    frmTatCardInPut := TfrmTatCardInPut.Create(Application);
    with frmTatCardInPut do
    begin
      FMainId := Trim(Self.CDS_1.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.CDS_1.fieldbyname('SubId').AsString);
      FWBCID := Trim(Self.CDS_1.fieldbyname('WBCID').AsString);
//      begin
//        if FWBCID = '' then
//          ShowMessage('11111111111');
//      end;

      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTatCardInPut.Free;
  end;

end;

procedure TfrmTatWBPlanCard.ToolButton5Click(Sender: TObject);
begin

  try
    frmTatWBCardInPut := TfrmTatWBCardInPut.Create(Application);
    with frmTatWBCardInPut do
    begin
      FWBCNO := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTatWBCardInPut.Free;
  end;
  begin
    InitGrid();
  end;
end;

procedure TfrmTatWBPlanCard.ToolButton6Click(Sender: TObject);
begin
  try
    frmTatWBCardInPutXIUGAI := TfrmTatWBCardInPutXIUGAI.Create(Application);
    with frmTatWBCardInPutXIUGAI do
    begin
      begin
        FWBCNO := Trim(Self.CDS_1.fieldbyname('WBCNO').AsString);
        WBCID.text := Trim(Self.CDS_1.fieldbyname('WBCID').AsString);
        WB_ClothNameL.text := Trim(Self.CDS_1.fieldbyname('WB_ClothName').AsString);
        WB_Clothcode.text := Trim(Self.CDS_1.fieldbyname('WB_Clothcode').AsString);
        WB_YarnArrQty.text := Trim(Self.CDS_1.fieldbyname('WB_YarnArrQty').AsString);
        WB_BatchNo.text := Trim(Self.CDS_1.fieldbyname('WB_BatchNo').AsString);
        WB_MachNo.text := Trim(Self.CDS_1.fieldbyname('WB_MachNo').AsString);
        FtyCoName.text := Trim(Self.CDS_1.fieldbyname('FtyCoName').AsString);
        WB_YarnQty.text := Trim(Self.CDS_1.fieldbyname('WB_YarnQty').AsString);
        WB_Len.text := Trim(Self.CDS_1.fieldbyname('WB_Len').AsString);
        WB_YarnLen.text := Trim(Self.CDS_1.fieldbyname('WB_YarnLen').AsString);
        WB_Macher.text := Trim(Self.CDS_1.fieldbyname('WB_Macher').AsString);
        WB_YarnWidth.text := Trim(Self.CDS_1.fieldbyname('WB_YarnWidth').AsString);
        Note.text := Trim(Self.CDS_1.fieldbyname('Note').AsString);

        ConNoL.text := Trim(Self.CDS_1.fieldbyname('ConNo').AsString);
//        WBCNOL.text := Trim(Self.CDS_1.fieldbyname('WBCNO').AsString);
      end;
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTatWBCardInPutXIUGAI.Free;
  end;
end;

procedure TfrmTatWBPlanCard.ConNosChange(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 TfrmTatWBPlanCard.FormShow(Sender: TObject);
begin
  inherited;

  ReadCxGrid(trim(self.Caption), Tv1, '坯布生产2');
  EndDate.DateTime := SGetServerDate(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 5;
  InitGrid();
end;

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

end.

