unit U_BP_ProblemEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, DB, ADODB, cxControls, cxContainer, cxEdit,
  cxTextEdit, cxCurrencyEdit, BtnEdit, StdCtrls, ExtCtrls, cxStyles,
  cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxDBData,
  cxButtonEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, DBClient, cxDropDownEdit, Menus, cxLookAndFeelPainters,
  strUtils, cxButtons, cxImage, cxDBEdit, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, ShellAPI, IdFTP;

type
  TfrmBP_ProblemEdit = class(TForm)
    ToolBar1: TToolBar;
    TSAVE: TToolButton;
    Tclose: TToolButton;
    ADOQueryTMP: TADOQuery;
    ADOQueryCMD: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGridPopupMenu2: TcxGridPopupMenu;
    CDS_HZ: TClientDataSet;
    ADOQueryMain: TADOQuery;
    DS_HZ: TDataSource;
    ADOQueryImage: TADOQuery;
    DataSource1: TDataSource;
    Panel1: TPanel;
    Label11: TLabel;
    Label1: TLabel;
    Label5: TLabel;
    Label2: TLabel;
    Label10: TLabel;
    Label12: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label13: TLabel;
    Note: TMemo;
    CRTime: TDateTimePicker;
    ywy: TEdit;
    KHCPNO: TEdit;
    Qty: TEdit;
    money: TEdit;
    chker1: TBtnEditA;
    mainID: TEdit;
    subID: TEdit;
    orderNo: TEdit;
    SalesOrder: TEdit;
    C_CodeName: TEdit;
    SPType: TComboBox;
    factoryName: TBtnEditA;
    SCOrderNo: TBtnEditA;
    Label3: TLabel;
    SDNO: TEdit;
    Label4: TLabel;
    QTYUNIT: TComboBox;
    SPUNIT: TComboBox;
    procedure TcloseClick(Sender: TObject);
    procedure TSAVEClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure QtyKeyPress(Sender: TObject; var Key: Char);

    procedure chker1BtnClick(Sender: TObject);
    procedure NoteDblClick(Sender: TObject);
    procedure factoryNameBtnClick(Sender: TObject);
    procedure SCOrderNoBtnClick(Sender: TObject);
  private
    procedure savedata();
    procedure initdata();

    { Private declarations }
  public
    fkeyNo: string;
    fflag: integer;
    fSYRName: string;
    canshu1: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmBP_ProblemEdit: TfrmBP_ProblemEdit;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZDYHelpSel, U_ZdyAttachment, U_ZdyAttachGYS,
  U_ProductOrderListSel;

{$R *.dfm}

procedure TfrmBP_ProblemEdit.initdata();
begin
  with ADOQueryMain do
  begin
    close;
    sql.clear;
    sql.Add(' select * from BP_Problem ');
    sql.Add(' where CRNO=' + quotedstr(trim(fkeyNo)));
    open;
    if not IsEmpty then
    begin
      SCSHDataNew(ADOQueryMain, Panel1, 0);
    end;
  end;
end;

procedure TfrmBP_ProblemEdit.savedata();
begin
  try
    ADOQueryCMD.Connection.BeginTrans;

    with ADOQueryCMD do
    begin
      Close;
      sql.Clear;
      SQL.Add(' select * from BP_Problem where CRNO=''' + Trim(fkeyNo) + ''' ');
      Open;
    end;
    if ADOQueryCMD.IsEmpty then
    begin
      ADOQueryCMD.Append;
      ADOQueryCMD.FieldByName('Filler').Value := Trim(Dname);
      ADOQueryCMD.FieldByName('CRNO').Value := Trim(fkeyNo);
    end
    else
    begin
      ADOQueryCMD.Edit;
      ADOQueryCMD.FieldByName('Editer').Value := Trim(Dname);
      ADOQueryCMD.FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTMP);
    end;
    SSetsaveSqlNew(ADOQueryCMD, 'BP_Problem', Panel1, 0);
    ADOQueryCMD.FieldByName('CRID').Value := '1';
    ADOQueryCMD.FieldByName('CRFlag').Value := '扣损登记';
    ADOQueryCMD.Post;

    ADOquerycmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  except
    ADOquerycmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmBP_ProblemEdit.TcloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmBP_ProblemEdit.TSAVEClick(Sender: TObject);
begin
  savedata();
end;

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

procedure TfrmBP_ProblemEdit.FormDestroy(Sender: TObject);
begin
  frmBP_ProblemEdit := nil;
end;

procedure TfrmBP_ProblemEdit.FormShow(Sender: TObject);
begin
  SClearData(Panel1, 0);
  CRTime.DateTime := SGetServerDate10(adoqueryTmp);
  if Trim(fkeyNo) = '' then
  begin
    if GetLSNo(ADOQueryCMD, fkeyNo, 'BM', 'BP_Problem', 3, 1) = False then
    begin
      ADOQueryCMD.Connection.RollbackTrans;
      Application.MessageBox('取流水号失败!', '提示');
      Exit;
    end;
  end;
  initData();
end;

procedure TfrmBP_ProblemEdit.QtyKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', '.', '-', #8]) then
    Key := #0;
  if (Key = '.') and (Pos('.', Tedit(Sender).Text) > 0) then
    Key := #0;
end;

procedure TfrmBP_ProblemEdit.chker1BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'KSchker1';
      flagname := '扣损确认人';
      if ShowModal = 1 then
      begin
        chker1.Text := Trim(ClientDataSet1.fieldbyName('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmBP_ProblemEdit.NoteDblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := 'KSNote';
      flagname := '索赔事件及诉求';
      if ShowModal = 1 then
      begin
        Note.Text := Trim(ReturnStr);
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmBP_ProblemEdit.factoryNameBtnClick(Sender: TObject);
begin
  if trim(SPType.Text) = '供应商索赔' then
  begin
    try
      frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
      with frmZdyAttachGYS do
      begin
        if ShowModal = 1 then
        begin
          FactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachGYS.Free;
    end;
  end;

  if trim(SPType.Text) = '客户索赔' then
  begin
    try
      frmZdyAttachment := TfrmZdyAttachment.Create(Application);
      with frmZdyAttachment do
      begin
        if ShowModal = 1 then
        begin
          FactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachment.Free;
    end;
  end;
end;

procedure TfrmBP_ProblemEdit.SCOrderNoBtnClick(Sender: TObject);
var
  MMaxno: string;
begin
  try
    frmProductOrderListSel := TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal = 1 then
      begin
        with frmProductOrderListSel.Order_Main do
        begin

          C_CodeName.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCodeName').AsString);
          SCOrderNo.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('orderno').AsString);
          YWY.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('YWY').AsString);
          factoryName.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('CustomerNoName').AsString);
        end;
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
end;

end.

