unit U_TJCKRKOKView;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxButtonEdit, cxCalendar,
  cxDropDownEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, StdCtrls, ExtCtrls, ComCtrls, ToolWin, DBClient,
  ADODB, cxCheckBox, cxPC, BtnEdit, cxGridDBTableView,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxTextEdit;

type
  TfrmTJCKRKOKView = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label3: TLabel;
    OrderNo: TEdit;
    ClientDataSet6: TClientDataSet;
    DataSource6: TDataSource;
    ADOQuery1: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Label18: TLabel;
    BatchNo: TEdit;
    Label19: TLabel;
    ConName: TEdit;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label2: TLabel;
    PRTColor: TEdit;
    Label1: TLabel;
    PRTHX: TEdit;
    cxTabControl1: TcxTabControl;
    Label4: TLabel;
    FactoryName: TEdit;
    Label5: TLabel;
    ToFactoryName: TEdit;
    ToolButton1: TToolButton;
    cxGrid6: TcxGrid;
    Tv6: TcxGridDBTableView;
    v3Column1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    LiYongXS: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    v3Column10: TcxGridDBColumn;
    v3Column11: TcxGridDBColumn;
    v3Column13: TcxGridDBColumn;
    v3Column18: TcxGridDBColumn;
    v3Column20: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    v3Column2: TcxGridDBColumn;
    v3Column14: TcxGridDBColumn;
    v3Column15: TcxGridDBColumn;
    v3Column16: TcxGridDBColumn;
    v3Column17: TcxGridDBColumn;
    v6Column1: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure Button6Click(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure BatchNoChange(Sender: TObject);
    procedure LiYongXSPropertiesEditValueChanged(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    { Private declarations }
    canshu1:string;
    procedure InitGrid();
    procedure InitGridKK();
  public
    { Public declarations }
  end;

var
  frmTJCKRKOKView: TfrmTJCKRKOKView;

implementation
uses
  U_DataLink,U_RTFun, U_GYSList,U_ZDYHelp;
{$R *.dfm}

procedure TfrmTJCKRKOKView.FormDestroy(Sender: TObject);
begin
  frmTJCKRKOKView:=nil;
end;

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

procedure TfrmTJCKRKOKView.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;
procedure TfrmTJCKRKOKView.InitGrid();
begin
  with ADOQueryMain do
  begin
    Filtered:=False;
    Close;
    sql.Clear;
    sql.Add(' exec P_View_DCLKC :ClotheType');
    Parameters.ParamByName('ClotheType').Value:=Trim(cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption);
    Open;
  end;
  SCreateCDS20(ADOQueryMain,ClientDataSet6);
  SInitCDSData20(ADOQueryMain,ClientDataSet6);
end;
procedure TfrmTJCKRKOKView.InitGridKK();

begin


end;
procedure TfrmTJCKRKOKView.FormShow(Sender: TObject);
begin
  ReadCxGrid('Tv6111',Tv6,'调节仓库');
  if Trim(canshu1)<>'高权限' then
  begin
    LiYongXS.Options.Focusing:=False;
  end else
  begin
    LiYongXS.Options.Focusing:=True;
  end;
end;

procedure TfrmTJCKRKOKView.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('Tv6111',Tv6,'调节仓库');
  close;
end;

procedure TfrmTJCKRKOKView.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
 { if Key=#13 then
  begin
    if Trim(OrderNo.Text)='' then Exit;
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('select JM.OrderNo, A.*,B.PSName OrdPSName,C.ConNo,C.FactoryNoName,D.Price,JM.MPRTMF,JM.MPRTKZ, ');
      sql.Add(' JS.PRTHX,PRTColor=JS.PRTColorNo+'' ''+JS.PRTColor+'' ''+JS.PRTColorEng,D.C_Code,D.C_CodeName,ClotheType10=A.ClotheType,');
      sql.Add(' JSKCPS=A.RKPS-A.CKPS,');
      sql.Add(' JSKCQty=A.RKQty-A.CKQty');
      sql.Add(' from JYOrder_Main_MD  A');
      sql.Add(' inner join JYOrder_Main JM on A.OrdMainId=JM.MainId');
      sql.Add(' left join JYOrder_Sub JS on A.OrdSubId=JS.SubId');
      sql.Add(' inner join JYOrder_Process B on A.PSID=B.PSID');
      sql.Add(' inner join Contract_Main C on A.ConMainid=C.MainID');
      sql.Add(' inner join Contract_Sub D on A.ConSubid=D.SubID');
      sql.Add(' where JM.OrderNo like '''+'%'+Trim(OrderNo.Text)+'%'+'''');
      SQL.Add(' and isnull(A.CKName,'''')=''调节仓库'' ');
      sql.Add(' and (A.RKQty-A.CKQty)>0');

      Open;
    end;
    SCreateCDS20(ADOQuery1,ClientDataSet6);
    SInitCDSData20(ADOQuery1,ClientDataSet6);
  end;
  }
end;

procedure TfrmTJCKRKOKView.Button6Click(Sender: TObject);
var
  maxno:string;
begin

end;

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

procedure TfrmTJCKRKOKView.OrderNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTJCKRKOKView.BatchNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTJCKRKOKView.LiYongXSPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    if Trim(mvalue)='' then
      sql.Add('Update JYOrder_Main_MD Set LiYongXS=Null')
    else
      sql.Add('Update JYOrder_Main_MD Set LiYongXS='+Trim(mvalue));
    sql.Add(' where MDID='''+Trim(ClientDataSet6.fieldbyname('MDID').AsString)+'''');
    ExecSQL;
  end;
  with ClientDataSet6 do
  begin
    Edit;
    if Trim(mvalue)<>'' then
      FieldByName('LiYongXS').Value:=mvalue
    else
      FieldByName('LiYongXS').Value:=Null;
    Post;
  end;
end;

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

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

procedure TfrmTJCKRKOKView.ToolButton1Click(Sender: TObject);
var
  fsj:string;
begin
  if ClientDataSet6.IsEmpty then Exit;
  fsj:=cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption;
  TcxGridToExcel('待处理仓库库存('+fsj+')',cxGrid6);
end;

end.
