unit U_LLRKInPutMH_PTCL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxDropDownEdit, jpeg, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, cxPC, cxGridCustomPopupMenu, cxGridPopupMenu, cxGroupBox,
  cxCheckBox, RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport,
  IniFiles, Menus, ImgList, ShellAPI, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

type
  TfrmLLRKInPutMH_PTCL = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    TBSave: TToolButton;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label21: TLabel;
    Label26: TLabel;
    Label19: TLabel;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    labMYType: TLabel;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    adoqueryPicture: TADOQuery;
    Panel16: TPanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N3: TMenuItem;
    MenuItem2: TMenuItem;
    N4: TMenuItem;
    ImageList1: TImageList;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuery2: TADOQuery;
    Panel4: TPanel;
    Label13: TLabel;
    Label27: TLabel;
    CRTime: TDateTimePicker;
    KHName: TBtnEditA;
    KHNo: TEdit;
    Panel15: TPanel;
    Label22: TLabel;
    MYName: TBtnEditA;
    Panel5: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    Label45: TLabel;
    Label1: TLabel;
    Label4: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    KgQtyChaE: TEdit;
    Panel14: TPanel;
    Label43: TLabel;
    MDMFlag: TCheckBox;
    MDKGFlag: TCheckBox;
    HSFlag: TCheckBox;
    BHSFlag: TCheckBox;
    Note: TEdit;
    cxGroupBox2: TcxGroupBox;
    ListView1: TListView;
    Panel12: TPanel;
    Label8: TLabel;
    Button2: TButton;
    Panel13: TPanel;
    Image2: TImage;
    WJName: TEdit;
    Button7: TButton;
    WJPach: TEdit;
    Button8: TButton;
    Panel2: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    MXHZPS: TEdit;
    MXHZQty: TEdit;
    Label7: TLabel;
    Label9: TLabel;
    MXHZKgQty: TEdit;
    Label10: TLabel;
    MDJChang: TEdit;
    Label11: TLabel;
    Label17: TLabel;
    Label25: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label34: TLabel;
    PSChaE: TEdit;
    QtyChaE: TEdit;
    MoneyChaE: TEdit;
    Label12: TLabel;
    Label16: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    MYKZ: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1MYName: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1MYMDPrice: TcxGridDBColumn;
    v1MYMDMoney: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label28: TLabel;
    MYMDMoney: TEdit;
    Label20: TLabel;
    MYHDMoney: TEdit;
    Label18: TLabel;
    JChangCharE: TEdit;
    v1HWType: TcxGridDBColumn;
    Panel1: TPanel;
    Label23: TLabel;
    ZJQty: TEdit;
    Label35: TLabel;
    Label36: TLabel;
    ZKGQty: TEdit;
    Label37: TLabel;
    ZMQty: TEdit;
    Label38: TLabel;
    ZMoney: TEdit;
    v1XTKGQty: TcxGridDBColumn;
    MXHZJChang: TEdit;
    MYPrice: TEdit;
    Button1: TButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    XTKGQty: TEdit;
    MYCF: TEdit;
    v1MYCF: TcxGridDBColumn;
    RKNo: TEdit;
    v1MYCode: TcxGridDBColumn;
    v1MXHZJChang: TcxGridDBColumn;
    v1MXHZPS: TcxGridDBColumn;
    v1MXHZQty: TcxGridDBColumn;
    v1MXHZKgQty: TcxGridDBColumn;
    v1MYHDMoney: TcxGridDBColumn;
    v1JChangCharE: TcxGridDBColumn;
    v1PSChaE: TcxGridDBColumn;
    v1QtyChaE: TcxGridDBColumn;
    v1KgQtyChaE: TcxGridDBColumn;
    v1MoneyChaE: TcxGridDBColumn;
    v1MDKGFlag: TcxGridDBColumn;
    v1MDMFlag: TcxGridDBColumn;
    v1HSFlag: TcxGridDBColumn;
    v1BHSFlag: TcxGridDBColumn;
    v1JCDanWei: TcxGridDBColumn;
    v1JCNo: TcxGridDBColumn;
    N5: TMenuItem;
    cxStyle2: TcxStyle;
    GroupBox1: TGroupBox;
    N2: TMenuItem;
    ADOQueryTemp: TADOQuery;
    filler: TEdit;
    GFOrderNo: TEdit;
    Label24: TLabel;
    MYMF: TBtnEditA;
    Label3: TLabel;
    MYMDPrice: TEdit;
    QtyUnit: TBtnEditA;
    Label2: TLabel;
    HWType: TBtnEditA;
    v1CGName: TcxGridDBColumn;
    Label53: TLabel;
    CGName: TBtnEditA;
    Label33: TLabel;
    ishs: TComboBox;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure KHNameBtnClick(Sender: TObject);
    procedure Image1DblClick(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure Label20Click(Sender: TObject);
    procedure QtyChange(Sender: TObject);
    procedure MYNameBtnClick(Sender: TObject);
    procedure MXHZQtyChange(Sender: TObject);
    procedure Panel13Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure Panel2Click(Sender: TObject);
    procedure ListView1DblClick(Sender: TObject);
    procedure MXHZKgQtyChange(Sender: TObject);
    procedure MYMDPriceChange(Sender: TObject);
    procedure HSFlagClick(Sender: TObject);
    procedure BHSFlagClick(Sender: TObject);
    procedure PSChaEChange(Sender: TObject);
    procedure QtyChaEChange(Sender: TObject);
    procedure KgQtyChaEChange(Sender: TObject);
    procedure MoneyChaEChange(Sender: TObject);
    procedure MDJChangChange(Sender: TObject);
    procedure JChangCharEChange(Sender: TObject);
    procedure MXHZJChangChange(Sender: TObject);
    procedure MXHZPSChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure MYMDMoneyChange(Sender: TObject);
    procedure MDJChangKeyPress(Sender: TObject; var Key: Char);
    procedure PSKeyPress(Sender: TObject; var Key: Char);
    procedure MXHZJChangKeyPress(Sender: TObject; var Key: Char);
    procedure MXHZPSKeyPress(Sender: TObject; var Key: Char);
    procedure NoteKeyPress(Sender: TObject; var Key: Char);
    procedure MYMDPriceKeyPress(Sender: TObject; var Key: Char);
    procedure Button1KeyPress(Sender: TObject; var Key: Char);
    procedure N2Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure MYMFBtnClick(Sender: TObject);
    procedure QtyUnitBtnClick(Sender: TObject);
    procedure HWTypeBtnClick(Sender: TObject);
    procedure CGNameBtnClick(Sender: TObject);
  private
    lstPat: TStringList;
    FangXiang1, FSaveFlag: string;
    procedure InitData();
    procedure SaveImage(maxnoWB: string);
    procedure ReadINIFile10();
    function SaveData(): Boolean;
    procedure GetHZData();
    function SaveDataMX(): Boolean;
    procedure Initimage();
    function YFData(FM: string): Boolean;
    { Private declarations }
  public
    canshu1: string;
    PState, CopyInt: Integer;
    FMainId, FSubid, FFKHName, FFKHCode: string;
    FRead: string;
    FMYType, FMYTypeFlag, FML: string;
    { Public declarations }
  end;

var
  frmLLRKInPutMH_PTCL: TfrmLLRKInPutMH_PTCL;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_RTFun, U_ZDYHelpSel, U_GYSList, U_SCPerson,
  U_QCRKJLList, U_RSColorBig, U_RTPTColor, U_KHListSelJJ, U_ZHCPBigTP,
  U_LLRKMXInPutMH, U_ZDYCPName, U_BPZdy_LRPB, U_BPZdy_LRM;

{$R *.dfm}
function TfrmLLRKInPutMH_PTCL.YFData(FM: string): Boolean;
var
  CRID, OrdMainId, YFID, FComTaiTou, FCRID, FFactoryName, FFactoryNo: string;
begin
  Result := False;
  FFactoryName := Trim(KHName.Text);
  FFactoryNo := Trim(KHNo.Text);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YS_Money_KC where FactoryName=' + quotedstr(Trim(FFactoryName)));
    sql.Add(' and KCType=''KH'' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    CRID := ADOQueryTemp.fieldbyname('CRID').AsString;
  end
  else
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CRID');
      Open;
    end;
    if ADOQueryTemp.IsEmpty = False then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YS_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
    end
    else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('insert into YS_Money_CRID select 0 ');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
    end;
    CRID := ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_KC where 1=2');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('FactoryName').Value := Trim(FFactoryName);
      FieldByName('FactoryNo').Value := Trim(FFactoryNo);
      FieldByName('ZdyStr1').Value := '应付付';
      FieldByName('KCType').Value := 'KH';
      Post;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where FactoryNo=' + quotedstr(Trim(FFactoryNo)));
    sql.Add(' and YFTypeId=''' + Trim(FM) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd, YFID, 'MH', 'YS_Money_CR', 3, 1) = False then
    begin
      Application.MessageBox('取应付最大号失败!', '提示', 0);
      Exit;
    end;
  end
  else
  begin
    YFID := Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFID=''' + Trim(YFID) + '''');
    Open;
  end;
  with ADOQueryCmd do
  begin
    if ADOQueryTemp.IsEmpty then
    begin
      Append;
      FieldByName('SCQty').Value := ClientDataSet1.fieldbyname('KGQty').AsFloat;
    end
    else
      Edit;
    FieldByName('YFID').Value := Trim(YFID);
    FieldByName('YFTypeId').Value := Trim(FM);
    FieldByName('CRID').Value := StrToInt(CRID);
    FieldByName('Filler').Value := Trim(DName);
    FieldByName('YFName').Value := '材料采购';
    FieldByName('CRType').Value := '应付款登记';
    FieldByName('CRFlag').Value := '应付付';
    FieldByName('ChkStatusP').Value := '未审核';
    FieldByName('ChkStatusQ').Value := '未审核';
    FieldByName('QtyFlag').Value := 1;
    FieldByName('FactoryName').Value := Trim(FFactoryName);
    FieldByName('FactoryNo').Value := Trim(FFactoryNo);
    FieldByName('CRTime').Value := CRTime.datetime;
    FieldByName('Qty').Value := ClientDataSet1.fieldbyname('KGQty').AsFloat;
    FieldByName('SJQty').Value := ClientDataSet1.fieldbyname('KGQty').AsFloat;
    FieldByName('QtyUnit').Value := ClientDataSet1.fieldbyname('QtyUnit').Value;
    FieldByName('YFType').Value := '自动生成';
    FieldByName('Price').Value := ClientDataSet1.fieldbyname('MYMDPrice').AsFloat;
    if Trim(ishs.text) = '含税' then
    begin
      FieldByName('HanShui').Value := '含税';
    end
    else
    begin
      FieldByName('HanShui').Value := '不含税';
    end;
    FieldByName('CKNO').Value := trim(FMainid);
    FieldByName('money').Value := ClientDataSet1.fieldbyname('MYMDMoney').AsFloat;
    FieldByName('JSmoney').Value := ClientDataSet1.fieldbyname('MYMDMoney').AsFloat;
    FieldByName('HSmoney').Value := ClientDataSet1.fieldbyname('MYMDMoney').AsFloat;
    FieldByName('P_CodeName').Value := ClientDataSet1.fieldbyname('MYName').AsString;
    FieldByName('P_MF').Value := ClientDataSet1.fieldbyname('MYMF').AsString;
    FieldByName('P_KZ').Value := ClientDataSet1.fieldbyname('MYKZ').AsString;
    FieldByName('P_Code').Value := ClientDataSet1.fieldbyname('MYCode').AsString;
    FieldByName('BZType').Value := '￥';
    FieldByName('status').Value := '0';
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YS_Money_KC Set KCMoney=(select isnull(Sum(HSMoney*QtyFlag),0) from YS_Money_CR A where A.CRID=YS_Money_KC.CRID)');
    sql.Add(' where CRID=' + CRID);
    ExecSQL;
  end;
  Result := True;
end;

procedure TfrmLLRKInPutMH_PTCL.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('材料采购入库1', Tv1, '贸易生产管理');
  Close;
end;

procedure TfrmLLRKInPutMH_PTCL.Initimage();
var
  ListItem: TListItem;
  Flag: Cardinal;
  info: SHFILEINFOA;
  Icon: TIcon;
begin
  ListView1.Items.Clear;
  with adoqueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select fileName from TP_File ');
    sql.Add('where WBID=''' + trim(RKNo.Text) + ''' ');
    sql.Add('and TFType=''采购材料''');
    open;
    if not IsEmpty then
    begin
      while not eof do
      begin
        with ListView1 do
        begin
          LargeImages := ImageList1;
          Icon := TIcon.Create;
          ListItem := Items.Add;
          ListItem.Caption := trim(fieldbyname('fileName').AsString);
          Flag := (SHGFI_LARGEICON or SHGFI_ICON or SHGFI_USEFILEATTRIBUTES);
          SHGetFileInfo(Pchar(trim(fieldbyname('fileName').AsString)), 0, info, Sizeof(info), Flag);
          Icon.Handle := info.hIcon;
          ImageList1.AddIcon(Icon);
          ListItem.ImageIndex := ImageList1.Count - 1;
        end;
        next;
      end;
    end;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.InitData();
var
  maxmxno: string;
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select * ');
    sql.Add(' from CK_MYSC_CR   ');
    sql.Add(' where RKNo=''' + Trim(FMainId) + '''');
    SQL.Add(' and MYID=''' + Trim(FSubid) + '''');
    Open;
  end;
  if ADOQuery1.IsEmpty = false then
  begin
    SCSHDataNew(ADOQuery1, Panel4, 2);
    SCSHDataNew(ADOQuery1, Panel4, 0);
    SCSHDataNew(ADOQuery1, Panel5, 2);
    SCSHDataNew(ADOQuery1, Panel5, 0);
    SCSHDataNew(ADOQuery1, Panel1, 2);
    MDMFlag.Checked := ADOQuery1.FieldByName('MDMflag').AsBoolean;
    MDKGFlag.Checked := ADOQuery1.FieldByName('MDKGFlag').AsBoolean;
    HSFlag.Checked := ADOQuery1.FieldByName('HSFlag').AsBoolean;
    BHSFlag.Checked := ADOQuery1.FieldByName('BHSFlag').AsBoolean;
    KHName.TxtCode := Trim(ADOQuery1.fieldbyname('KHCode').AsString);
    labMYType.Caption := Trim(ADOQuery1.fieldbyname('MYType').AsString);
    MYName.text := Trim(ADOQuery1.fieldbyname('MYName').AsString);
    HWType.text := Trim(ADOQuery1.fieldbyname('HWType').AsString);
    MYMDPrice.text := Trim(floattostr(ADOQuery1.fieldbyname('MYMDPrice').asfloat));
    CGName.text := Trim(ADOQuery1.fieldbyname('CGName').AsString);
    KGQty.text := Trim(FloatToStr(ADOQuery1.fieldbyname('KGQty').AsFloat));
    Button1.Visible := false;

    FFKHName := Trim(ADOQuery1.fieldbyname('KHName').AsString);
    FFKHCode := Trim(ADOQuery1.fieldbyname('KHCode').AsString);
  end
  else
  begin
    CRTime.Date := SGetServerDate(ADOTemp);
    labMYType.Caption := FMYType;
    filler.Text := Trim(DName);
  end;
  if TBSave.Visible = False then
  begin
    Panel2.Visible := False;
    initBtnColor(Panel4, clMenu);
    initBtnColor(Panel5, clMenu);
  end;
  SCreateCDS20(ADOQuery1, ClientDataSet1);
  SInitCDSData20(ADOQuery1, ClientDataSet1);
  if PState = 2 then
  begin
    FMainId := '';
    RKNo.Text := '';
    FSubid := '';
    CRTime.Date := SGetServerDate(ADOTemp);
    filler.Text := Trim(DName);
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        edit;
        fieldbyname('MYID').AsString := '';
        next;
      end;
    end;
  end;
  if PState = 3 then
  begin
    FSubid := '';
  end;
  if RKNo.Text = '' then
  begin
    if GetLSNo(ADOCmd, maxmxno, 'RN', 'CK_MYSC_CR', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    RKNo.Text := Trim(maxmxno);
  end;
  initImage();
end;

procedure TfrmLLRKInPutMH_PTCL.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmLLRKInPutMH_PTCL.SaveData(): Boolean;
var
  maxno, maxmxno, maxnoflag, fsj, FMXID: string;
begin
  Result := False;
  if RKNo.Text = '' then
  begin
    if GetLSNo(ADOCmd, maxmxno, 'RN', 'CK_MYSC_CR', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    RKNo.Text := Trim(maxmxno);
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if Trim(FSubid) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'MH', 'CK_MYSC_CR', 3, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(FSubid);
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from CK_MYSC_CR where MYId=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if IsEmpty then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillerCode').Value := Trim(DCode);
          end
          else
          begin
            edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditerCode').Value := Trim(DCode);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          RTSetsavedata(ADOCmd, 'CK_MYSC_CR', Panel4, 2);
          RTSetsavedata(ADOCmd, 'CK_MYSC_CR', Panel1, 2);
          SSetSaveDataCDS(ADOCmd, TV1, ClientDataSet1, 'CK_MYSC_CR', 2);
          FieldByName('MYId').Value := Trim(maxno);
          FieldByName('CRType').Value := '采购入库';
          FieldByName('CRFlag').Value := '入库';
          FieldByName('ishs').Value := Trim(ishs.text);
          FieldByName('CRQtyFlag').Value := 1;
          FieldByName('MYType').Value := Trim(FMYType);
          FieldByName('MYTypeFlag').Value := Trim(FMYTypeFlag);
          Post;
        end;
        FMainId := Trim(maxno);
        with ClientDataSet1 do
        begin
          edit;
          FieldByName('MYID').AsString := Trim(maxno);
        end;
        if (Trim(KHName.text) <> Trim(FFKHName)) and (PState = 1) then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add(' delete  YS_Money_CR where ChkStatusQ =''未审核'' and YFTypeId=''' + Trim(maxno) + '''');
//            ShowMessage(sql.text);
            execsql;
          end;
        end;
        YFData(maxno);
        next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;

  except
    Result := False;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.TBSaveClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if Trim(KHName.Text) = '' then
  begin
    Application.MessageBox('供应商不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(ishs.Text) = '' then
  begin
    Application.MessageBox('是否含税不能为空!', '提示', 0);
    Exit;
  end;
  Button1.Click;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.ReadINIFile10();
var
  programIni: Tinifile;  //配置文件名
  FileName: string;
begin
  FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI';
  programIni := Tinifile.create(FileName);
  server := programIni.ReadString('SERVER', '服务器地址', '127.0.0.1');
  programIni.Free;
end;

procedure TfrmLLRKInPutMH_PTCL.SaveImage(maxnoWB: string);
begin

end;

procedure TfrmLLRKInPutMH_PTCL.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ModalResult := 1;
end;

procedure TfrmLLRKInPutMH_PTCL.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  ReadCxGrid('材料采购入库1', Tv1, '贸易生产管理');
end;

procedure TfrmLLRKInPutMH_PTCL.KHNameBtnClick(Sender: TObject);
begin
  try
    frmGYSList := TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      //KHType.Text:='材料厂';
      //KHType.TxtCode:='材料厂';
      if ShowModal = 1 then
      begin
        Self.KHName.Text := Trim(frmGYSList.Order_Main.fieldbyname('KHName').AsString);
        Self.KHNo.Text := Trim(frmGYSList.Order_Main.fieldbyname('KHNo').AsString);
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Image1DblClick(Sender: TObject);
begin
  if Trim(FMainId) = '' then
  begin
    Application.MessageBox('没有保存数据，不能查看大图!', '提示', 0);
    Exit;
  end;
  try
    frmZHCPBigTP := TfrmZHCPBigTP.Create(Application);
    with frmZHCPBigTP do
    begin
      frmZHCPBigTP.FMainId := Self.FMainId;
      frmZHCPBigTP.FIMNO := '';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZHCPBigTP.Free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Panel1Click(Sender: TObject);
begin
  if Trim(FMainId) = '' then
  begin
    Application.MessageBox('未保存数据！', '', 0);
    Exit;
  end;
  try
    frmLLRKMXInPutMH := TfrmLLRKMXInPutMH.Create(Application);
    with frmLLRKMXInPutMH do
    begin
      PState := 1;
      frmLLRKMXInPutMH.FMainId := Trim(Self.FMainId);
      if Self.TBSave.Visible = False then
      begin
        frmLLRKMXInPutMH.TBSave.Visible := False;
      end;
      if ShowModal = 1 then
      begin
        InitData();
      end;
    end;
  finally
    frmLLRKMXInPutMH.Free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Label20Click(Sender: TObject);
begin
  if Trim(FMainId) = '' then
  begin
    Application.MessageBox('未保存数据！', '', 0);
    Exit;
  end;
  try
    frmLLRKMXInPutMH := TfrmLLRKMXInPutMH.Create(Application);
    with frmLLRKMXInPutMH do
    begin
      PState := 1;
      frmLLRKMXInPutMH.FMainId := Trim(Self.FMainId);
      if Self.TBSave.Visible = False then
      begin
        frmLLRKMXInPutMH.TBSave.Visible := False;
      end;
      if ShowModal = 1 then
      begin
        InitData();
      end;
    end;
  finally
    frmLLRKMXInPutMH.Free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.GetHZData();
var
  FKG, FM, FPS: string;
begin
  FKG := Tv1.DataController.Summary.FooterSummaryTexts[0];
  FM := Tv1.DataController.Summary.FooterSummaryTexts[1];
  FPS := Tv1.DataController.Summary.FooterSummaryTexts[2];
  MXHZPS.Text := FPS;
  MXHZKGQty.Text := FKG;
  MXHZQty.Text := FM;
  if (Trim(FPS) = '') or (Trim(FPS) = '0') then
  begin
    SClearData(Panel2, 2);
    SClearData(Panel2, 99);
  end
  else
  begin
    with ADOTemp do
    begin
      close;
      sql.Clear;
      sql.Add('exec P_Avg_JS :KgQty,:MQty,:PS');
      if Trim(FKG) <> '' then
      begin
        Parameters.ParamByName('KGQty').Value := FKG;
      end
      else
      begin
        Parameters.ParamByName('KGQty').Value := Null;
      end;
      if Trim(FM) <> '' then
      begin
        Parameters.ParamByName('MQty').Value := FM;
      end
      else
      begin
        Parameters.ParamByName('MQty').Value := Null;
      end;
      Parameters.ParamByName('PS').Value := FPS;
      Open;
    end;
  end;
  PSChaE.Text := FloatToStr(strtofloatdef(MXHZPS.Text, 0) - strtofloatdef(PS.Text, 0));
  QtyChaE.Text := FloatToStr(strtofloatdef(MXHZQty.Text, 0) - strtofloatdef(Qty.Text, 0));
  KgQtyChaE.Text := FloatToStr(strtofloatdef(MXHZKgQty.Text, 0) - strtofloatdef(KGQty.Text, 0));
  MoneyChaE.Text := FloatToStr(strtofloatdef(MYHDMoney.Text, 0) - strtofloatdef(MYMDMoney.Text, 0));
end;

function TfrmLLRKInPutMH_PTCL.SaveDataMX(): Boolean;
begin

end;

procedure TfrmLLRKInPutMH_PTCL.QtyChange(Sender: TObject);
begin
  MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(KgQty.text, 0));
  MXHZKgQty.Text := KgQty.Text;
  QtyChaE.Text := FloatToStr(StrToFloatDef(MXHZQty.Text, 0) - strtofloatdef(Qty.Text, 0));
  KgQtyChaE.Text := FloatToStr(StrToFloatDef(MXHZKgQty.Text, 0) - strtofloatdef(KgQty.Text, 0));
end;

procedure TfrmLLRKInPutMH_PTCL.MYNameBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'PTCL';
    flagName := '普通材料';
    if ShowModal = 1 then
    begin
      MYName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MXHZQtyChange(Sender: TObject);
begin
  if MDMFlag.Checked = true then
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZQty.text, 0));
  if MDKGFlag.Checked = true then
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZKgQty.text, 0));
  QtyChaE.Text := FloatToStr(StrToFloatDef(MXHZQty.Text, 0) - strtofloatdef(Qty.Text, 0));
  KgQtyChaE.Text := FloatToStr(StrToFloatDef(MXHZKgQty.Text, 0) - strtofloatdef(KgQty.Text, 0));
end;

procedure TfrmLLRKInPutMH_PTCL.Panel13Click(Sender: TObject);
begin
  Panel12.Visible := False;
end;

procedure TfrmLLRKInPutMH_PTCL.Button2Click(Sender: TObject);
var
  fFileName: string;
  fFilePath: string;
  maxNo: string;
begin
  try
    adoqueryCmd.Connection.BeginTrans;
    begin
      fFilePath := WJPach.Text;
      fFileName := WJName.Text;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select TFId from TP_File ');
        sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
        sql.Add(' and TFType=''采购材料''');
        sql.Add(' and FileName=' + quotedstr(trim(fFileName)));
        open;
      end;
      if ADOQueryCmd.IsEmpty = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        application.MessageBox('此附件名称已存在，请修改文件名，继续上传！', '提示信息', MB_ICONERROR);
        exit;
      end;
      Panel12.Visible := False;
      Panel2.Caption := '正在上传数据，请稍等...';
      Panel2.Visible := true;
      application.ProcessMessages;

      if GetLSNo(ADOQueryCmd, maxNo, 'MD', 'TP_File', 4, 1) = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;

      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('delete from TP_File ');
        sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
        sql.Add('and TFType=''采购材料''');
        sql.Add('and FileName=' + quotedstr(trim(fFileName)));
        execsql;
      end;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from TP_File ');
        sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
        sql.Add('and TFType=''采购材料''');
        sql.Add('and FileName=' + quotedstr(trim(fFileName)));
        open;
        append;
        fieldbyname('TFID').Value := trim(maxNo);
        fieldbyname('WBID').Value := trim(RKNo.Text);
        fieldbyname('TFType').Value := '采购材料';
        fieldbyname('FileName').Value := trim(fFileName);
        post;
      end;
      if fFilePath <> '' then
      begin
        try
          IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
          IdFTP1.Username := 'three';
          IdFTP1.Password := '641010';
          IdFTP1.Connect();
          IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
          IdFTP1.Quit;
        except
          IdFTP1.Quit;
          Application.MessageBox('上传文件失败，请检查文件服务器！', '提示', MB_ICONWARNING);
        end;
      end;
      IdFTP1.Quit;
      Panel2.Visible := false;
      Initimage();
    end;
    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('文件保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Button8Click(Sender: TObject);
var
  fFileName: string;
begin
  fFileName := WJName.Hint;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('UPdate TP_File Set FileName=''' + Trim(WJName.Text) + '''');
    sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
    sql.Add('and TFType=''采购材料''');
    sql.Add('and FileName=' + quotedstr(trim(fFileName)));
    execsql;
  end;
  Panel12.Visible := False;
  Initimage();
end;

procedure TfrmLLRKInPutMH_PTCL.Button7Click(Sender: TObject);
var
  fFileName: string;
  fFilePath: string;
  maxNo: string;
begin
  try
    adoqueryCmd.Connection.BeginTrans;
    fFilePath := WJPach.Text;
    fFileName := WJName.Hint;
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select TFId from TP_File ');
      sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
      sql.Add('and TFType=''采购材料''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      open;
      if not adoqueryCmd.IsEmpty then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        application.MessageBox('此附件名称已存在，请修改文件名，继续上传！', '提示信息', MB_ICONERROR);
        exit;
      end;
    end;
    Panel12.Visible := False;
    Panel2.Caption := '正在上传数据，请稍等...';
    Panel2.Visible := true;
    application.ProcessMessages;

    if GetLSNo(ADOQueryCmd, maxNo, 'FJ', 'TP_File', 4, 1) = False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;

    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from TP_File ');
      sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
      sql.Add('and TFType=''采购材料''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      execsql;
    end;
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from TP_File ');
      sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
      sql.Add('and TFType=''采购材料''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      open;
      append;
      fieldbyname('TFID').Value := trim(maxNo);
      fieldbyname('WBID').Value := trim(RKNo.Text);
      fieldbyname('TFType').Value := '采购材料';
      fieldbyname('FileName').Value := trim(fFileName);
      post;
    end;
    if fFilePath <> '' then
    begin
      try
        IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
        IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
        IdFTP1.Quit;
      except
        IdFTP1.Quit;
        Application.MessageBox('上传文件失败，请检查文件服务器！', '提示', MB_ICONWARNING);
      end;
    end;
    IdFTP1.Quit;
    Panel2.Visible := false;
    Initimage();
    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('文件保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Image2Click(Sender: TObject);
begin
  Panel12.Visible := false;
end;

procedure TfrmLLRKInPutMH_PTCL.MenuItem1Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName, FWJName: string;
  fFilePath: string;
begin
  if GetLSNo(ADOCmd, FWJName, 'M', 'CK_MYSC_CR_MX', 2, 1) = False then
  begin
    ClientDataSet1.EnableControls;
    Application.MessageBox('取来料入库数据最大号失败', '提示', 0);
    Exit;
  end;
  OpenDiaLog := TOpenDialog.Create(Self);
  if OpenDiaLog.Execute then
  begin
    fFilePath := OpenDiaLog.FileName;
    fFileName := ExtractFileName(OpenDiaLog.FileName);
    fFileName := FWJName + copy(fFileName, Pos('.', fFileName), Length(fFileName));
    Panel12.Visible := True;
    WJName.Text := Trim(fFileName);
    WJName.Hint := Trim(fFileName);
    WJPach.Text := fFilePath;
    Button8.Visible := False;
    Button2.Visible := True;
    Button7.Visible := True;
    Panel12.Refresh;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.N3Click(Sender: TObject);
var
  fFileName: string;
begin
  if listView1.SelCount < 1 then
    exit;
  try
    fFileName := ListView1.Selected.Caption;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete  from TP_File ');
      sql.Add('where WBID=''' + trim(RKNo.Text) + '''');
      sql.Add('and TFType=''采购材料''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      execsql;
    end;
    Initimage();
  except
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MenuItem2Click(Sender: TObject);
begin
  if listView1.SelCount < 1 then
    exit;
  Panel12.Visible := True;
  Button2.Visible := False;
  Button7.Visible := False;
  Button8.Visible := True;
  Panel12.Refresh;
  WJName.Text := Trim(ListView1.Selected.Caption);
  WJName.Hint := Trim(ListView1.Selected.Caption);
end;

procedure TfrmLLRKInPutMH_PTCL.N4Click(Sender: TObject);
var
  SaveDialog: TSaveDialog;
  fFileName: string;
  fFilePath: string;
begin
  if listView1.SelCount < 1 then
    exit;
  try
    fFileName := ListView1.Selected.Caption;
    SaveDialog := TSaveDialog.Create(Self);
    SaveDialog.FileName := fFileName;
    if SaveDialog.Execute then
    begin
      Panel2.Caption := '正在保存数据，请稍等...';
      Panel2.Visible := true;
      application.ProcessMessages;
      fFilePath := SaveDialog.FileName;
      try
        IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', 'FTP地址', '127.0.0.1');
        ;
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
      except
        ;
      end;

      if IdFTP1.Connected then
      begin
        Panel2.Caption := '正在下载数据，请稍等...';
        Panel2.Visible := true;
        application.ProcessMessages;
        try
          IdFTP1.Get('FJ\' + Trim(fFileName), fFilePath, false, true);
        except
          Panel2.Visible := false;
          Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
          IdFTP1.Quit;
          Exit;
        end;
      end
      else
      begin
        Panel2.Visible := false;
        Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
        IdFTP1.Quit;
        Exit;
      end;
      Panel2.Visible := false;
      if IdFTP1.Connected then
        IdFTP1.Quit;
    end;
  except
    Panel2.Visible := false;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Panel2Click(Sender: TObject);
begin
  Panel2.Visible := false;
end;

procedure TfrmLLRKInPutMH_PTCL.ListView1DblClick(Sender: TObject);
var
  sFieldName: string;
  fileName: string;
begin
  if ListView1.Items.Count < 1 then
    EXIT;

  if listView1.SelCount < 1 then
    exit;
  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);

  fileName := ListView1.Selected.Caption;

  sFieldName := sFieldName + '\' + trim(fileName);

  try
    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    ;
  end;

  if IdFTP1.Connected then
  begin

    Panel2.Caption := '正在下载数据，请稍等...';
    Panel2.Visible := true;
    application.ProcessMessages;
    try
      IdFTP1.Get('FJ\' + Trim(fileName), sFieldName, true, false);
    except
      Panel2.Visible := false;
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Panel2.Visible := false;
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
  Panel2.Visible := false;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

procedure TfrmLLRKInPutMH_PTCL.MXHZKgQtyChange(Sender: TObject);
begin
  if MDMFlag.Checked = true then
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZQty.text, 0));
  if MDKGFlag.Checked = true then
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZKgQty.text, 0));
end;

procedure TfrmLLRKInPutMH_PTCL.MYMDPriceChange(Sender: TObject);
begin
  MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(KgQty.text, 0));
  MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZKgQty.text, 0));
end;

procedure TfrmLLRKInPutMH_PTCL.HSFlagClick(Sender: TObject);
begin
  if HSFlag.Checked = true then
  begin
    if BHSFlag.Checked = true then
      BHSFlag.Checked := false;
  end
  else
  begin
    if BHSFlag.Checked = false then
      BHSFlag.Checked := true;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.BHSFlagClick(Sender: TObject);
begin
  if BHSFlag.Checked = true then
  begin
    if HSFlag.Checked = true then
      HSFlag.Checked := false;
  end
  else
  begin
    if HSFlag.Checked = false then
      HSFlag.Checked := true;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.PSChaEChange(Sender: TObject);
begin
  if StrToFloatDef(PSChaE.Text, 0) > 0 then
  begin
    PSChaE.Font.Color := clGreen;
  end;
  if StrToFloatDef(PSChaE.Text, 0) < 0 then
  begin
    PSChaE.Font.Color := clRed;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.QtyChaEChange(Sender: TObject);
begin
  if StrToFloatDef(QtyChaE.Text, 0) > 0 then
  begin
    QtyChaE.Font.Color := clGreen;
  end;
  if StrToFloatDef(QtyChaE.Text, 0) < 0 then
  begin
    QtyChaE.Font.Color := clRed;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.KgQtyChaEChange(Sender: TObject);
begin
  if StrToFloatDef(KgQtyChaE.Text, 0) > 0 then
  begin
    KgQtyChaE.Font.Color := clGreen;
  end;
  if StrToFloatDef(KgQtyChaE.Text, 0) < 0 then
  begin
    KgQtyChaE.Font.Color := clRed;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MoneyChaEChange(Sender: TObject);
begin
  if StrToFloatDef(MoneyChaE.Text, 0) > 0 then
  begin
    MoneyChaE.Font.Color := clGreen;
  end;
  if StrToFloatDef(MoneyChaE.Text, 0) < 0 then
  begin
    MoneyChaE.Font.Color := clRed;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MDJChangChange(Sender: TObject);
begin
  XTKGQty.Text := FormatFloat('0.0', strtofloatdef(MYKZ.text, 0) * strtofloatdef(MYMF.text, 0) * strtofloatdef(MDJChang.text, 0) * strtofloatdef(PS.text, 0) / 100000);
  KgQty.Text := FormatFloat('0.0', strtofloatdef(MYKZ.text, 0) * strtofloatdef(MYMF.text, 0) * strtofloatdef(MDJChang.text, 0) * strtofloatdef(PS.text, 0) / 100000);
  Qty.Text := FloatToStr(strtofloatdef(MDJChang.text, 0) * strtofloatdef(PS.text, 0));
  MXHZJChang.Text := MDJChang.Text;
  MXHZPS.Text := PS.Text;
  JChangCharE.Text := FloatToStr(StrToFloatDef(MXHZJChang.Text, 0) - strtofloatdef(MDJChang.Text, 0));
  PSChaE.Text := FloatToStr(StrToFloatDef(MXHZPS.Text, 0) - strtofloatdef(PS.Text, 0));
end;

procedure TfrmLLRKInPutMH_PTCL.JChangCharEChange(Sender: TObject);
begin
  if StrToFloatDef(JChangCharE.Text, 0) > 0 then
  begin
    JChangCharE.Font.Color := clGreen;
  end;
  if StrToFloatDef(JChangCharE.Text, 0) < 0 then
  begin
    JChangCharE.Font.Color := clRed;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MXHZJChangChange(Sender: TObject);
begin
  JChangCharE.Text := FloatToStr(StrToFloatDef(MXHZJChang.Text, 0) - strtofloatdef(MDJChang.Text, 0));
  MXHZQty.Text := FloatToStr(StrToFloatDef(MXHZJChang.Text, 0) * StrToFloatDef(MXHZPS.Text, 0));
  MXHZKgQty.Text := FormatFloat('0.0', strtofloatdef(MYKZ.text, 0) * strtofloatdef(MYMF.text, 0) * strtofloatdef(MXHZJChang.text, 0) * strtofloatdef(MXHZPS.text, 0) / 100000);
end;

procedure TfrmLLRKInPutMH_PTCL.MXHZPSChange(Sender: TObject);
begin
  PSChaE.Text := FloatToStr(StrToFloatDef(MXHZPS.Text, 0) - strtofloatdef(PS.Text, 0));
  MXHZQty.Text := FloatToStr(StrToFloatDef(MXHZJChang.Text, 0) * StrToFloatDef(MXHZPS.Text, 0));
  MXHZKgQty.Text := FormatFloat('0.0', strtofloatdef(MYKZ.text, 0) * strtofloatdef(MYMF.text, 0) * strtofloatdef(MXHZJChang.text, 0) * strtofloatdef(MXHZPS.text, 0) / 100000);
end;

procedure TfrmLLRKInPutMH_PTCL.N1Click(Sender: TObject);
begin
  if ClientDataSet1.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFTypeId=''' + trim(ClientDataSet1.fieldbyname('MYID').AsString) + '''');
    sql.Add(' and (isnull(ChkerP,'''')<>'''' ');
    sql.Add(' or isnull(ChkerQ,'''')<>'''') ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = false then
  begin
    Application.MessageBox('应付款已审核,不能删除', '提示');
    exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  {if ClientDataSet1.FieldByName('MYID').AsString<>'' then
  begin
    with ADOQueryTmp do
    begin
      Close;
      sql.Clear;
      sql.Add('delete from CK_MYSC_CR ');
      sql.Add('where MYID='''+trim(ClientDataSet1.FieldByName('MYID').AsString)+'''');
      ExecSQL;
    end;
  end;}
  ClientDataSet1.Delete;
end;

procedure TfrmLLRKInPutMH_PTCL.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  SCSHDataCDS(ClientDataSet1, Panel5, 2);
  SCSHDataCDS(ClientDataSet1, Panel14, 2);
  MYName.Text := Trim(ClientDataSet1.fieldbyname('MYName').AsString);
  Initimage();
end;

procedure TfrmLLRKInPutMH_PTCL.Button1Click(Sender: TObject);
var
  FJQty, FKG, FM, FMoney: string;
  FReal: Double;
  FInt: Integer;
begin
  if Trim(MYName.Text) = '' then
  begin
    Application.MessageBox('材料品名不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(KHName.Text) = '' then
  begin
    Application.MessageBox('材料厂商不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(MYMDPrice.Text) = '' then
  begin
    if Application.MessageBox('单价为空是否继续', '提示', 1) = 2 then
      exit;
  end;
  if Trim(KgQty.Text) <> '' then
  begin
    if TryStrToFloat(KgQty.Text, FReal) = False then
    begin
      Application.MessageBox('数量非法数字!', '提示', 0);
      exit;
    end;
  end;
  with ClientDataSet1 do
  begin
    edit;
    RTsavedataCDS(ClientDataSet1, Panel5, 2);
    RTsavedataCDS(ClientDataSet1, Panel15, 2);
    ClientDataSet1.FieldByName('MYName').AsString := trim(MYName.Text);
    ClientDataSet1.FieldByName('CGName').AsString := trim(CGName.Text);
    post;
  end;
  SClearData(Panel5, 2);
  SClearData(Panel15, 2);
  MYMDPrice.Text := '';
  HSFlag.Checked := true;
  Button1.Caption := '确定';
  //button1.Visible:=false;
  cxGrid1.Enabled := true;
end;

procedure TfrmLLRKInPutMH_PTCL.MYMDMoneyChange(Sender: TObject);
begin
  MoneyChaE.Text := FloatToStr(strtofloatdef(MYHDMoney.text, 0) * strtofloatdef(MYMDMoney.text, 0));
end;

procedure TfrmLLRKInPutMH_PTCL.MDJChangKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    PS.SetFocus;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.PSKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    MXHZJChang.SetFocus;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MXHZJChangKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    MXHZPS.SetFocus;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MXHZPSKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Note.SetFocus;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.NoteKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    MYMDPrice.SetFocus;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MYMDPriceKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    button1.SetFocus;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.Button1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Button1.Click;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.N2Click(Sender: TObject);
begin
  Button1.Visible := true;
  button1.Caption := '确定';
  SClearData(Panel5, 2);
  SClearData(Panel15, 2);
  MYMDPrice.Text := '';
  MYMF.Text := '151';
  MDKGFlag.Checked := True;
  HSFlag.Checked := true;
  Panel5.Visible := true;
end;

procedure TfrmLLRKInPutMH_PTCL.N5Click(Sender: TObject);
begin
  SCSHDataCDS(ClientDataSet1, Panel5, 2);
  SCSHDataCDS(ClientDataSet1, Panel14, 2);
  MYName.Text := Trim(ClientDataSet1.fieldbyname('MYName').AsString);
  HWType.Text := Trim(ClientDataSet1.fieldbyname('HWType').AsString);
  MYMDMoney.Text := Trim(ClientDataSet1.fieldbyname('MYMDMoney').AsString);
  Initimage();
  Button1.Visible := true;
  button1.Caption := '修改';
  cxGrid1.Enabled := false;
  Panel5.Visible := true;
end;

procedure TfrmLLRKInPutMH_PTCL.Tv1DblClick(Sender: TObject);
begin
  if TBSave.Visible = False then
  begin
    ModalResult := 1;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.MYMFBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'MMYKZ';
    flagName := '克重';
    V1Name.Caption := '克重';
    //MainType:=Trim(KHName.Text);
    if ShowModal = 1 then
    begin
      MYMF.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.QtyUnitBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'PTCLUnit';
    flagName := '数量单位';
    if ShowModal = 1 then
    begin
      Qtyunit.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.HWTypeBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'HWType';
    flagName := '材料类型';
    if ShowModal = 1 then
    begin
      HWType.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_PTCL.CGNameBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'CGName';
    flagName := '采购人';
    if ShowModal = 1 then
    begin
      CGName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

end.

