unit U_MCGRKList_HBKC;

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, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxDropDownEdit, cxPC, Buttons, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore,    
   dxSkinDarkRoom,  
     
     
     
    
    
    
   dxSkinOffice2013White,  
    dxSkinSharpPlus, 
  dxSkinSpringTime,   
  dxSkinsDefaultPainters,   
   dxSkinscxPCPainter, cxNavigator, dxBarBuiltInMenu;

type
  TfrmMCGRKList_HBKC = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    ToolButton4: TToolButton;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport2: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    Label2: TLabel;
    MYName: TEdit;
    labMYType: TLabel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    V2MYName: TcxGridDBColumn;
    V2MYCode: TcxGridDBColumn;
    V2PS: TcxGridDBColumn;
    V2Qty: TcxGridDBColumn;
    V2KgQty: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    PB_MX: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    Label6: TLabel;
    MYCode: TEdit;
    V2CkType: TcxGridDBColumn;
    Label1: TLabel;
    MYType: TEdit;
    Panel2: TPanel;
    SpeedButton1: TSpeedButton;
    Image2: TImage;
    Button2: TButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    cxTabControl1: TcxTabControl;
    V2KUwei: TcxGridDBColumn;
    Label3: TLabel;
    KUwei: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure KHNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure MYCodeChange(Sender: TObject);
    procedure TV2DblClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
  private
    canshu1: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmMCGRKList_HBKC: TfrmMCGRKList_HBKC;

implementation

uses
  U_DataLink, U_RTFun, U_QCRKInPut, U_ZDYHelp, U_LLRKInPut, U_GYSList,
  U_RCCKInPut, U_LLRKInPutMH, U_LLRKInPutX, U_LLRKInPut_CG, U_LLRKInPutMH_CG,
  U_LLRKInPutMH_PBCG, U_LLRKInPutMH_PBKCCG, U_BPZdy_LRPB, U_LLRKInPutMH_MCG,
  U_BPZdy_LRM, U_MCGRKList_MKC_CX, U_MCGRKList_HBKC_CX;

{$R *.dfm}

procedure TfrmMCGRKList_HBKC.FormDestroy(Sender: TObject);
begin
  frmMCGRKList_HBKC := nil;
end;

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

procedure TfrmMCGRKList_HBKC.FormCreate(Sender: TObject);
begin
  canshu1 := Trim(DParameters1);
end;

procedure TfrmMCGRKList_HBKC.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('仓库汇总库存1', Tv2, '贸易生产管理');
  Close;
end;

procedure TfrmMCGRKList_HBKC.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select AA.*');
      SQL.Add(' from (select A.MYCode,B.KUwei,Max(A.MYName) MYName,A.MYType,Sum(MXKCPiQty) PS,Sum(MXKCKgQty) KgQty,Sum(MXKCQty) Qty');
      sql.Add(',CKType=(case when MYType=''染色面料'' then ''面料'' when MYType=''单面料'' then ''面料'' ');
      sql.Add(' when MYType=''采购坯布'' then ''坯布'' when MYType=''烫金面料'' then ''面料'' ');
      SQL.Add(' when MYType=''采购棉'' then ''棉'' when MYType=''采购线'' then ''线'' else MYType end)');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' inner join CK_MYSC_CR_MX B on B.MYID=A.MYID');
      sql.Add(' where isnull(CRFlag,'''')=''入库''');
      sql.Add(' group by A.MYCode,B.KUwei,A.MYType ');
      SQL.Add(' ) AA ');
      sql.Add(' where (AA.PS>0 or Qty>0 or KgQty>0)');
      if cxTabControl1.TabIndex = 0 then
      begin
        sql.Add(' and CKType=''面料''');
        V2PS.Caption := '匹数';
        V2Qty.Caption := '米数';
      end;
      if cxTabControl1.TabIndex = 1 then
      begin
        sql.Add(' and CKType=''组合面料''');
        V2PS.Caption := '匹数';
        V2Qty.Caption := '米数';
      end;
      if cxTabControl1.TabIndex = 2 then
      begin
        sql.Add(' and CKType=''坯布''');
        V2PS.Caption := '匹数';
        V2Qty.Caption := '米数';
      end;
      if cxTabControl1.TabIndex = 3 then
      begin
        sql.Add(' and CKType=''线''');
        V2PS.Caption := '件数';
        V2Qty.Caption := '只数';
      end;
      if cxTabControl1.TabIndex = 4 then
      begin
        sql.Add(' and CKType=''棉''');
        V2PS.Caption := '匹数';
        V2Qty.Caption := '米数';
      end;
      if cxTabControl1.TabIndex = 5 then
      begin
        sql.Add(' and CKType=''无纺布''');
      end;
      sql.Add('order by MYCode');
      //ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMCGRKList_HBKC.InitForm();
begin
  ReadCxGrid('仓库汇总库存1', Tv2, '贸易生产管理');
  InitGrid();
end;

procedure TfrmMCGRKList_HBKC.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;

function TfrmMCGRKList_HBKC.DelData(): Boolean;
begin

end;

procedure TfrmMCGRKList_HBKC.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(Self.Caption, cxGrid2);
end;

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

procedure TfrmMCGRKList_HBKC.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmMCGRKList_HBKC.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMCGRKList_HBKC.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmMCGRKList_HBKC.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    frmMCGRKList_HBKC_CX := TfrmMCGRKList_HBKC_CX.Create(Application);
    with frmMCGRKList_HBKC_CX do
    begin
      FMYCode := Trim(Self.Order_Main.fieldbyname('MYCode').AsString);
      FMYName := Trim(Self.Order_Main.fieldbyname('MYName').AsString);
      FKUWei := Trim(Self.Order_Main.fieldbyname('KUWei').AsString);
      if cxTabControl1.TabIndex = 0 then
      begin
        labMYType.Caption := '        面料库存汇总';
      end;
      if cxTabControl1.TabIndex = 1 then
      begin
        labMYType.Caption := '      组合面料库存汇总';
      end;
      if cxTabControl1.TabIndex = 2 then
      begin
        labMYType.Caption := '      坯布库存汇总';
        cxGrid2.PopupMenu := PopupMenu1;
      end;
      if cxTabControl1.TabIndex = 3 then
      begin
        labMYType.Caption := '      线库存汇总';
      end;
      if cxTabControl1.TabIndex = 4 then
      begin
        labMYType.Caption := '      棉库存汇总';
      end;
      if cxTabControl1.TabIndex = 5 then
      begin
        labMYType.Caption := '      无纺布库存汇总';
      end;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmMCGRKList_HBKC_CX.Free;
  end;
end;

procedure TfrmMCGRKList_HBKC.CustomerNoNameChange(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 TfrmMCGRKList_HBKC.N2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MYSC_CR_MX where MYID=''' + Trim(Order_Main.fieldbyname('MYID').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('已产生明细数据，不能删除!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    //Order_Main.Delete;
  end;
end;

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

procedure TfrmMCGRKList_HBKC.ZJStatusChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmMCGRKList_HBKC.ToolButton4Click(Sender: TObject);
var
  fPrintFile: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(Order_Main.fieldbyname('Chker').AsString) = '' then
    exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\检测报告.rmf';
  RMXLSExport2 := TRMXLSExport.Create(RMXLSExport2);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Test_Report where TRId=''' + Trim(Order_Main.fieldbyname('TRId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['OrderUnit']:=Order_Main.fieldbyname('OrderUnit').Value;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\检测报告.rmf'), '提示', 0);
  end;
end;

procedure TfrmMCGRKList_HBKC.Tv1DblClick(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmMCGRKList_HBKC.KHNameChange(Sender: TObject);
begin
  SDofilter(ADOQueryCmd, SGetFilters(Panel1, 3, 4));
  SCreateCDS20(ADOQueryCmd, PB_MX);
  SInitCDSData20(ADOQueryCmd, PB_MX);
end;

procedure TfrmMCGRKList_HBKC.N1Click(Sender: TObject);
begin
  frmRCCKInPut := TfrmRCCKInPut.Create(self);
  with frmRCCKInPut do
  begin
    if ShowModal = 1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMCGRKList_HBKC.MYCodeChange(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 TfrmMCGRKList_HBKC.TV2DblClick(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmMCGRKList_HBKC.Button2Click(Sender: TObject);
begin
  panel2.Visible := true;
end;

procedure TfrmMCGRKList_HBKC.Image2Click(Sender: TObject);
begin
  Panel2.Visible := false;
end;

procedure TfrmMCGRKList_HBKC.SpeedButton1Click(Sender: TObject);
begin
  MYType.Text := '坯布';
  Panel2.Visible := false;
end;

procedure TfrmMCGRKList_HBKC.SpeedButton2Click(Sender: TObject);
begin
  MYType.Text := '染色';
  Panel2.Visible := false;
end;

procedure TfrmMCGRKList_HBKC.SpeedButton4Click(Sender: TObject);
begin
  MYType.Text := '线';
  Panel2.Visible := false;
end;

procedure TfrmMCGRKList_HBKC.SpeedButton3Click(Sender: TObject);
begin
  MYType.Text := '棉';
  Panel2.Visible := false;
end;

procedure TfrmMCGRKList_HBKC.SpeedButton5Click(Sender: TObject);
begin
  MYType.Text := '无纺布';
  Panel2.Visible := false;
end;

end.

