unit U_ClothHCList;

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, cxDropDownEdit,
  cxCheckBox, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, Buttons;

type
  TfrmClothHCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNoM: TEdit;
    Order_Main: TClientDataSet;
    Label6: TLabel;
    PRTColor: TEdit;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2filltime: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    V2Column10: TcxGridDBColumn;
    V2Column13: TcxGridDBColumn;
    V2Subid: TcxGridDBColumn;
    V2KHOrderNo: TcxGridDBColumn;
    V2Column14: TcxGridDBColumn;
    SubID: TEdit;
    conNo: TEdit;
    Label9: TLabel;
    V2Column15: TcxGridDBColumn;
    V2Column16: TcxGridDBColumn;
    prtCodeName: TEdit;
    Label2: TLabel;
    prtspec: TEdit;
    Label10: TLabel;
    V2CustomerNoName: TcxGridDBColumn;
    V2MPRTNiuDu: TcxGridDBColumn;
    V2MPRTBZNote: TcxGridDBColumn;
    V2PRTOrderQty: TcxGridDBColumn;
    Label4: TLabel;
    V2OrderUnit: TcxGridDBColumn;
    Button1: TButton;
    V2Column1: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    PRTHX: TEdit;
    Label5: TLabel;
    TV2Column1: TcxGridDBColumn;
    ScrollBox1: TScrollBox;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton22: TSpeedButton;
    SpeedButton23: TSpeedButton;
    SpeedButton24: TSpeedButton;
    SpeedButton25: TSpeedButton;
    SpeedButton26: TSpeedButton;
    SpeedButton29: TSpeedButton;
    SpeedButton31: TSpeedButton;
    SpeedButton32: TSpeedButton;
    SpeedButton33: TSpeedButton;
    SpeedButton34: TSpeedButton;
    SpeedButton37: TSpeedButton;
    SpeedButton38: TSpeedButton;
    SpeedButton40: TSpeedButton;
    SpeedButton41: TSpeedButton;
    SpeedButton42: TSpeedButton;
    SpeedButton45: TSpeedButton;
    SpeedButton46: TSpeedButton;
    SpeedButton47: TSpeedButton;
    SpeedButton50: TSpeedButton;
    SpeedButton51: TSpeedButton;
    SpeedButton54: TSpeedButton;
    SpeedButton55: TSpeedButton;
    SpeedButton56: TSpeedButton;
    SpeedButton57: TSpeedButton;
    SpeedButton59: TSpeedButton;
    SpeedButton62: TSpeedButton;
    SpeedButton63: TSpeedButton;
    SpeedButton64: TSpeedButton;
    SpeedButton65: TSpeedButton;
    SpeedButton66: TSpeedButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoMChange(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OrderNoMKeyPress(Sender: TObject; var Key: Char);
    procedure TV2DblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
//    procedure SpeedButton13Click(Sender: TObject);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitJP();
    procedure InitForm();
    procedure InitGridWSQL(FWSQL: string);
    { Private declarations }
  public
    fType: string;
    { Public declarations }
  end;

var
  frmClothHCList: TfrmClothHCList;

implementation

uses
  U_DataLink, U_ClothContractInPut, U_Fun, U_ProductOrderList, U_ZDYHelp,
  U_ProductOrderNewList_JD;

{$R *.dfm}
procedure TfrmClothHCList.InitJP();
var
  AA: array[0..100] of string;
  i, j: Integer;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select C.JTH from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' order by JTH ');
//    showmessage(sql.text);
    Open;
  end;
//  if ADOTmp.IsEmpty then
//  begin
//    Application.MessageBox('没有定义疵点！', '提示', 0);
//    Exit;
//  end;
  with ADOQueryTemp do
  begin
    First;
    i := 0;
    while not Eof do
    begin
      AA[i] := Trim(fieldbyname('JTH').AsString);
      i := i + 1;
      Next;
    end;
  end;
  i := i - 1;
  if i > 35 then
  begin
    i := 35;
  end;
  for j := 0 to i do
  begin
    with ScrollBox1 do
    begin
      TSpeedButton(Controls[j]).Visible := True;
      TSpeedButton(Controls[j]).Hint := AA[j];
      if Length(AA[j]) > 4 then
      begin
        TSpeedButton(Controls[j]).Caption := Copy(Trim(AA[j]), 1, 4) + #13 + Copy(Trim(AA[j]), 5, Length(AA[j]) - 4);
      end
      else
        TSpeedButton(Controls[j]).Caption := AA[j];
    end;
  end;

end;

procedure TfrmClothHCList.FormDestroy(Sender: TObject);
begin
  frmClothHCList := nil;
end;

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

procedure TfrmClothHCList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption + tv2.Name, Tv2, '指示单管理2');
end;

procedure TfrmClothHCList.InitGrid();
begin
//  try
//    //ADOQueryMain.DisableControls;
//    with ADOQueryMain do
//    begin
//
//      Close;
//      Filtered:=False;
//      sql.Clear;
////      sql.Add('exec P_View_HC_copy1 :begdate,:enddate,:WSQL');
//      sql.Add('exec P_View_HC_copy1 :WSQL');   //:begdate,:enddate,
////      Parameters.ParamByName('begdate').Value:=FormatDateTime('yyyy-MM-dd',BegDate.Date);
////      Parameters.ParamByName('enddate').Value:=FormatDateTime('yyyy-MM-dd',EndDate.Date+1);
//      Parameters.ParamByName('WSQL').Value:='';
//      Open;
//    end;
//    SCreateCDS20(ADOQueryMain,Order_Main);
//    SInitCDSData20(ADOQueryMain,Order_Main);
//  finally
//    //ADOQueryMain.EnableControls;
//  end;
//  try
//    //ADOQueryMain.DisableControls;
//    with ADOQueryMain do
//    begin
//
//      Close;
////      Filtered := False;
//      sql.Clear;
//
//      sql.Add('select C.subid from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' and C.JTH=''' + Trim(TSpeedButton(Sender).Hint) + ''' ');   //:begdate,:enddate,
//
//      Open;
//    end;
//    SCreateCDS20(ADOQueryMain, Order_Main);
//    SInitCDSData20(ADOQueryMain, Order_Main);
//  finally
//    //ADOQueryMain.EnableControls;
//  end;

end;

procedure TfrmClothHCList.InitGridWSQL(FWSQL: string);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_HC :begdate,:enddate,:WSQL');
      Parameters.ParamByName('begdate').Value := '2014-01-01';
      Parameters.ParamByName('enddate').Value := '2050-01-01';
      Parameters.ParamByName('WSQL').Value := FWSQL;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothHCList.InitForm();
begin
  ReadCxGrid(self.Caption + tv2.Name, Tv2, '指示单管理2');
  EndDate.DateTime := SGetServerDateTime(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  //InitGrid();
end;

procedure TfrmClothHCList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

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

procedure TfrmClothHCList.OrderNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmClothHCList.FormShow(Sender: TObject);
begin
  InitJP();
//  InitForm();
//  TBRafresh.Click;
end;

procedure TfrmClothHCList.OrderNoMKeyPress(Sender: TObject; var Key: Char);
var
  fsj: string;
begin
  if Key = #13 then
  begin
    if Length(Trim(OrderNoM.Text)) < 4 then
      Exit;
    fsj := ' and B.OrderNo like ''' + '%' + Trim(OrderNoM.Text) + '%' + '''';
    InitGridWSQL(fsj);
  end;
end;

procedure TfrmClothHCList.TV2DblClick(Sender: TObject);
begin
  if fType = '10' then
    frmClothHCList.ModalResult := 1;
end;

procedure TfrmClothHCList.Button1Click(Sender: TObject);
begin

  if fType = '10' then
    frmClothHCList.ModalResult := 1;
end;

procedure TfrmClothHCList.SpeedButton13Click(Sender: TObject);
begin
  try
//    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin

      Close;
      Filtered := False;
      sql.Clear;

      sql.Add('select C.subid from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' and C.JTH=''' + Trim(TSpeedButton(Sender).Hint) + ''' ');   //:begdate,:enddate,

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
//    ADOQueryMain.EnableControls;
  end;
//  try
//    ADOQueryMain.DisableControls;
//    with ADOQueryMain do
//    begin
//      Close;
//      Filtered := False;
//      sql.Clear;
//      sql.Add('select C.subid from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' and C.JTH=''' + Trim(TSpeedButton(Sender).Hint) + ''' ');   //:begdate,:enddate,
////      showmessage(sql.text);
//      Open;
//    end;
//    SCreateCDS20(ADOQueryMain, Order_Main);
//    SInitCDSData20(ADOQueryMain, Order_Main);
//  finally
//    ADOQueryMain.EnableControls;
//  end;
  if fType = '10' then
    frmClothHCList.ModalResult := 1;
end;

end.

