unit U_TJCKKC;

interface

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

type
  TfrmTJCKKC = class(TForm)
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton4: TToolButton;
    Panel1: TPanel;
    ADOQuery1: TADOQuery;
    Order_Sub: TClientDataSet;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxTabControl1: TcxTabControl;
    Panel2: TPanel;
    ComboBox1: TComboBox;
    Label6: TLabel;
    Label8: TLabel;
    DRPS: TEdit;
    Label9: TLabel;
    DRQty: TEdit;
    cxGrid6: TcxGrid;
    Tv6: TcxGridDBTableView;
    v3Column3: TcxGridDBColumn;
    v3Column16: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    v3Column10: TcxGridDBColumn;
    v3Column11: TcxGridDBColumn;
    v3Column17: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    LiYongXS: TcxGridDBColumn;
    v3Column13: TcxGridDBColumn;
    v3Column18: TcxGridDBColumn;
    v3Column20: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column14: TcxGridDBColumn;
    v3Column15: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label3: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label2: TLabel;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    OrderNo: TEdit;
    BatchNo: TEdit;
    ConName: TEdit;
    PRTColor: TEdit;
    PRTHX: TEdit;
    FactoryName: TEdit;
    ToFactoryName: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure v6Column2PropertiesEditValueChanged(Sender: TObject);
    procedure Tv6MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    procedure InitGrid();
  public
    { Public declarations }
    FFMainId:String;
    FDataType:string;
  end;

var
  frmTJCKKC: TfrmTJCKKC;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmTJCKKC.FormDestroy(Sender: TObject);
begin
  frmTJCKKC:=nil;
end;

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

procedure TfrmTJCKKC.FormShow(Sender: TObject);
begin
  ReadCxGrid('库存选择',Tv6,'调节仓库');
  InitGrid();
end;
procedure TfrmTJCKKC.InitGrid();
begin
  with ADOQuery1 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(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
end;

procedure TfrmTJCKKC.OrderNoChange(Sender: TObject);
begin
  if ADOQuery1.Active=False then Exit;
  SDofilter(ADOQuery1,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
end;

procedure TfrmTJCKKC.ToolButton1Click(Sender: TObject);
var
  FReal:Double;
begin
  if Order_Sub.IsEmpty then Exit;
 { if Order_Sub.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end; }
  if Trim(Order_Sub.fieldbyname('ToFactoryName').AsString)='本厂' then
  begin
    ComboBox1.ItemIndex:=1;
  end;
  if Trim(ComboBox1.Text)='' then
  begin
    Application.MessageBox('数据来源不能为空!','提示',0);
    Exit;
  end;
  if Trim(DRPS.Text)='' then
  begin
    Application.MessageBox('调入匹数不能为空!','提示',0);
    Exit;
  end;
  if Trim(DRQty.Text)='' then
  begin
    Application.MessageBox('调入数量不能为空!','提示',0);
    Exit;
  end;
  if TryStrToFloat(Trim(DRPS.Text),FReal)=False then
  begin
    Application.MessageBox('调入匹数非法数字!','提示',0);
    Exit;
  end;
  if TryStrToFloat(Trim(DRQty.Text),FReal)=False then
  begin
    Application.MessageBox('调入数量非法数字!','提示',0);
    Exit;
  end;
  if StrToFloat(DRQty.Text)>Order_Sub.FieldByName('JSKCQty').Value then
  begin
    Application.MessageBox('调入数量不能大于库存数量!','提示',0);
    Exit;
  end;
 { if Order_Sub.FieldByName('OtherOrdFlag').AsBoolean=True then
  begin
    if Trim(FFMainId)=Trim(Order_Sub.fieldbyname('ORDMainId').AsString) then
    begin
      Application.MessageBox('打入非本单的数据，本单不能调入!','提示',0);
      Exit;
    end;
  end;  }
  if Application.MessageBox(PChar('确定要从<'+ComboBox1.Text+'仓库>调入数据吗？'),'提示',32+4)<>IDYES then Exit;
  ModalResult:=1;

end;

procedure TfrmTJCKKC.ToolButton4Click(Sender: TObject);
begin
  Close;
  WriteCxGrid('库存选择',Tv6,'调节仓库');
  ModalResult:=-1;
end;

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

procedure TfrmTJCKKC.v6Column2PropertiesEditValueChanged(Sender: TObject);
var
  Mvalue:Boolean;
  MDID:string;
begin
  Mvalue:=TcxCheckBox(Sender).EditingValue;
  MDID:=Trim(Order_Sub.fieldbyname('MDID').AsString);
  with Order_Sub do
  begin
    while  Order_Sub.Locate('SSel',True,[])=True do
    begin
      Edit;
      FieldByName('SSel').Value:=False;
      Post;
    end;
    Order_Sub.Locate('MDID',MDID,[]);
    Edit;
    FieldByName('SSel').Value:=Mvalue;
    Post;
  end;
  
end;

procedure TfrmTJCKKC.Tv6MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Trim(FDataType)='仓库' then
  begin
    ComboBox1.ItemIndex:=1;
    ComboBox1.Enabled:=false;
    Exit;
  end;
  if Trim(Order_Sub.fieldbyname('ToFactoryName').AsString)='本厂' then
  begin
    ComboBox1.ItemIndex:=1;
    ComboBox1.Enabled:=false;
  end else
  begin
    ComboBox1.ItemIndex:=-1;
    ComboBox1.Enabled:=True;
  end;
end;

end.
