unit U_TradePlanClothEnterInput;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxDropDownEdit, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator,   dxDateRanges,
  dxBarBuiltInMenu, U_BaseInput, System.ImageList, Vcl.ImgList, cxContainer,
  cxMemo,  dxScrollbarAnnotations, dxCore, cxDateUtils, cxCurrencyEdit,
      
     
     
     
     
    
    
    
    
    
     
     
     
    
    
    cxImageList;

type
  TfrmTradePlanClothEnterInput = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ToolButton3: TToolButton;
    ScrollBox1: TScrollBox;
    Label2: TLabel;
    Label7: TLabel;
    Label1: TLabel;
    FtyPCId: TcxTextEdit;
    C_Code: TcxTextEdit;
    Label8: TLabel;
    StkPosition: TcxButtonEdit;
    Note: TcxMemo;
    lbl5: TLabel;
    IOTime: TcxDateEdit;
    Label10: TLabel;
    Label11: TLabel;
    Qty: TcxCurrencyEdit;
    Piece: TcxCurrencyEdit;
    Label6: TLabel;
    C_Name: TcxTextEdit;
    QtyUnit: TcxTextEdit;
    Label3: TLabel;
    C_Color: TcxTextEdit;
    Label9: TLabel;
    OrderNo: TcxTextEdit;
    Label12: TLabel;
    C_Composition: TcxTextEdit;
    Label4: TLabel;
    GC_Name: TcxTextEdit;
    Label5: TLabel;
    CraftCode: TcxTextEdit;
    Label13: TLabel;
    Label14: TLabel;
    SettlementType: TcxButtonEdit;
    Label15: TLabel;
    Downgrade: TcxButtonEdit;
    Grade: TcxButtonEdit;
    ToolButton1: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure BuyNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure CoBusinessTypeDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SettlementTypeDblClick(Sender: TObject);
    procedure FtyNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
    procedure InitGrid1();
    function SaveData(MSaveType: string): Boolean;
  public
    { Public declarations }
    FSubId, FTPFId: string;
  end;

var
  frmTradePlanClothEnterInput: TfrmTradePlanClothEnterInput;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_CompanySel;

{$R *.dfm}

procedure TfrmTradePlanClothEnterInput.InitGrid1();
var
  Msql: string;
  SqlStr: string;
begin
//  SqlStr := ' select BatchNo,PCPiece=count(*),PCMeter=sum(PCMeter),PCYardage=sum(PCYardage),PCYardage=sum(PCYardage),PCWeight1=sum(PCWeight-PCTare),PCWeight=sum(PCWeight),Weight=sum(Weight)    ';
//
//  SqlStr := SqlStr + ' from Trade_Plan_Card A where Subid =''' + trim(FSubid) + '''';
//
//  SqlStr := SqlStr + ' group by BatchNo ';
//
//  InitCDSData(ADO_1, CDS_1, Tv1, SqlStr, Msql, '');
end;

procedure TfrmTradePlanClothEnterInput.InitGrid();
begin

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*,B.* ');
    sql.Add(' from Trade_Plan_Main A inner join Trade_Plan_Sub B on A.MainId=B.MainId   ');
    sql.Add('  inner join Trade_Plan_Fty C on A.MainId=C.MainId   ');
    sql.Add(' where B.SubId=''' + Trim(FSubId) + '''');
    Open;
  end;
  CraftCode.Text := ADOQueryTemp.FieldByName('CraftCode').ASString;
  GC_Name.Text := ADOQueryTemp.FieldByName('GC_Name').ASString;
  OrderNo.Text := ADOQueryTemp.FieldByName('OrderNo').ASString;
  QtyUnit.Text := ADOQueryTemp.FieldByName('OrdUnit').ASString;
  C_Composition.Text := ADOQueryTemp.FieldByName('C_Composition').ASString;
  C_Code.Text := ADOQueryTemp.FieldByName('C_Code').ASString;
  C_Name.Text := ADOQueryTemp.FieldByName('C_Code').ASString;
  C_Color.Text := ADOQueryTemp.FieldByName('C_Color').ASString;
end;

procedure TfrmTradePlanClothEnterInput.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradePlanClothEnterInput := nil;
end;

procedure TfrmTradePlanClothEnterInput.BuyNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TcxButtonEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      MainType := 'Cust';
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TcxButtonEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTradePlanClothEnterInput.CoBusinessTypeDblClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';
end;

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

procedure TfrmTradePlanClothEnterInput.FormCreate(Sender: TObject);
begin
  inherited;
  IOTime.Date := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmTradePlanClothEnterInput.TBCloseClick(Sender: TObject);
begin

  close;
end;

procedure TfrmTradePlanClothEnterInput.FormShow(Sender: TObject);
var
  i: integer;
  a: string;
begin
  inherited;
  InitGrid();
  InitGrid1();
end;

procedure TfrmTradePlanClothEnterInput.SettlementTypeDblClick(Sender: TObject);
begin
  TcxButtonEdit(Sender).Text := '';
  TcxButtonEdit(Sender).Properties.LookupItems.Text := '';
end;

procedure TfrmTradePlanClothEnterInput.FtyNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TcxButtonEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TcxButtonEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

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

function TfrmTradePlanClothEnterInput.SaveData(MSaveType: string): Boolean;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_BS_Cloth_IOALL ');
      Sql.Add('  @Operation=' + quotedstr(Trim(MSaveType)));
      Sql.Add(' ,@TPFId=' + quotedstr(Trim(FTPFId)));
      Sql.Add(' ,@SubId=' + quotedstr(Trim(FSubId)));
      Sql.Add(' ,@IOTime=' + quotedstr(Trim(Trim(FormatDateTime('yyyy-MM-dd', IOTime.Date)))));
      Sql.Add(' ,@StkPosition=' + quotedstr(Trim(StkPosition.Text)));
      Sql.Add(' ,@FtyPCId=' + quotedstr(Trim(FtyPCId.Text)));
      Sql.Add(' ,@SettlementType=' + quotedstr(Trim(SettlementType.Text)));
      Sql.Add(' ,@Downgrade=' + quotedstr(Trim(Downgrade.Text)));
      Sql.Add(' ,@Grade=' + quotedstr(Trim(Grade.Text)));
      Sql.Add(' ,@Piece=' + Trim(Piece.Text));
      Sql.Add(' ,@Qty=' + Trim(Qty.Text));
      Sql.Add(' ,@Dcode=' + quotedstr(Trim(Dcode)));
      Sql.Add(' ,@DName=' + quotedstr(Trim(DName)));
//      ShowMessage(SQL.Text);
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;

end;

procedure TfrmTradePlanClothEnterInput.ToolButton1Click(Sender: TObject);
begin

  if Trim(FtyPCId.Text) = '' then
  begin
    Application.MessageBox('缸号不能为空!', '提示', 0);
    Exit;
  end;
  if StrToFloatDef(Piece.Text, 0) = 0 then
  begin
    Application.MessageBox('请输入匹数!', '提示', 0);
    Exit;
  end;
  if StrToFloatDef(Qty.Text, 0) = 0 then
  begin
    Application.MessageBox('请输入数量!', '提示', 0);
    Exit;
  end;
  if SaveData('加工完成并抄码') then
  begin
    Application.MessageBox('保存成功!', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmTradePlanClothEnterInput.ToolButton3Click(Sender: TObject);
begin

  if Trim(FtyPCId.Text) = '' then
  begin
    Application.MessageBox('缸号不能为空!', '提示', 0);
    Exit;
  end;
  if StrToFloatDef(Piece.Text, 0) = 0 then
  begin
    Application.MessageBox('请输入匹数!', '提示', 0);
    Exit;
  end;
  if StrToFloatDef(Qty.Text, 0) = 0 then
  begin
    Application.MessageBox('请输入数量!', '提示', 0);
    Exit;
  end;
  if SaveData('加工完成') then
  begin
    Application.MessageBox('保存成功!', '提示', 0);
    ModalResult := 1;
  end;
end;

end.

