unit U_LLRKInPutMH_PMTHCK;

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;

type
  TfrmLLRKInPutMH_PMTHCK = 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;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1MYName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1MYMDPrice: TcxGridDBColumn;
    v1MYMDMoney: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1MYKZ: TcxGridDBColumn;
    v1MYMF: TcxGridDBColumn;
    v1MYColor: TcxGridDBColumn;
    Panel1: TPanel;
    Label23: TLabel;
    ZJQty: TEdit;
    Label35: TLabel;
    Label36: TLabel;
    ZKGQty: TEdit;
    Label37: TLabel;
    ZMQty: TEdit;
    Label38: TLabel;
    ZMoney: TEdit;
    v1XTKGQty: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    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;
    v1RKNo: TcxGridDBColumn;
    cxStyle2: TcxStyle;
    N2: TMenuItem;
    ADOQueryTemp: TADOQuery;
    filler: TEdit;
    v1MYMD: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Panel5: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label45: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label17: TLabel;
    Label25: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label34: TLabel;
    Label12: TLabel;
    Label16: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label28: TLabel;
    Label20: TLabel;
    Label18: TLabel;
    Label24: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    XTKGQty: TEdit;
    KgQtyChaE: TEdit;
    JCDanWei: TBtnEditA;
    JCNo: TEdit;
    Panel14: TPanel;
    Label43: TLabel;
    Label3: TLabel;
    Label39: TLabel;
    MDMFlag: TCheckBox;
    MDKGFlag: TCheckBox;
    HSFlag: TCheckBox;
    BHSFlag: TCheckBox;
    MYMDPrice: TEdit;
    Price: TEdit;
    Note: TEdit;
    MXHZPS: TEdit;
    MXHZQty: TEdit;
    MXHZKgQty: TEdit;
    MDJChang: TEdit;
    MXHZJChang: TEdit;
    PSChaE: TEdit;
    QtyChaE: TEdit;
    MoneyChaE: TEdit;
    MYKZ: TEdit;
    MYMF: TEdit;
    MYMDMoney: TEdit;
    MYHDMoney: TEdit;
    JChangCharE: TEdit;
    MYPrice: TEdit;
    Button1: TButton;
    MYCF: TEdit;
    GFOrderNo: TEdit;
    cxGroupBox2: TcxGroupBox;
    ListView1: TListView;
    Panel12: TPanel;
    Label8: TLabel;
    Button2: TButton;
    Panel13: TPanel;
    Image2: TImage;
    WJName: TEdit;
    Button7: TButton;
    WJPach: TEdit;
    Button8: TButton;
    GroupBox1: TGroupBox;
    Panel2: TPanel;
    Panel15: TPanel;
    Label22: TLabel;
    MYCode: TEdit;
    MYName: TBtnEditA;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridDBColumn26: TcxGridDBColumn;
    cxGridDBColumn27: TcxGridDBColumn;
    cxGridDBColumn28: TcxGridDBColumn;
    cxGridDBColumn29: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource3: TDataSource;
    Ord_M: TClientDataSet;
    ToolBar2: TToolBar;
    Panel3: TPanel;
    Label41: TLabel;
    ToolBar3: TToolBar;
    Panel6: TPanel;
    Label40: TLabel;
    V2MYType: TcxGridDBColumn;
    v1MYType: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    V2MYColor: TcxGridDBColumn;
    Label42: TLabel;
    MYColor: TEdit;
    Label44: TLabel;
    MYMD: TEdit;
    procedure TBCloseClick(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 MDMFlagClick(Sender: TObject);
    procedure MDKGFlagClick(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 JCDanWeiBtnClick(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 PriceKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column17PropertiesEditValueChanged(Sender: TObject);
    procedure v1MYMDPricePropertiesEditValueChanged(Sender: TObject);
    procedure v1MDJChangPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column1PropertiesEditValueChanged(Sender: TObject);
    procedure v1JCDanWeiPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure v1MYNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormShow(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,FFZMYID:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FMYType,FMYTypeFlag,FML:string;
    { Public declarations }
  end;

var
  frmLLRKInPutMH_PMTHCK: TfrmLLRKInPutMH_PMTHCK;
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,U_MCGRKList_CX;

{$R *.dfm}
function TfrmLLRKInPutMH_PMTHCK.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,'TM','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;
      if ClientDataSet1.fieldbyname('MDMFlag').AsBoolean=true then
      begin
        FieldByName('SCQty').Value:=-ClientDataSet1.fieldbyname('Qty').AsFloat;
      end
      else
      begin
        FieldByName('SCQty').Value:=-ClientDataSet1.fieldbyname('KGQty').AsFloat;
      end;
      FieldByName('SCPS').Value:=-ClientDataSet1.fieldbyname('PS').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;
    if ClientDataSet1.fieldbyname('MDMFlag').AsBoolean=true then
    begin
      FieldByName('Qty').Value:=-ClientDataSet1.fieldbyname('Qty').AsFloat;
      FieldByName('SJQty').Value:=-ClientDataSet1.fieldbyname('Qty').AsFloat;
      FieldByName('QtyUnit').Value:='M';
    end
    else
    begin
      FieldByName('Qty').Value:=-ClientDataSet1.fieldbyname('KGQty').AsFloat;
      FieldByName('SJQty').Value:=-ClientDataSet1.fieldbyname('KGQty').AsFloat;
      FieldByName('QtyUnit').Value:='KG';
    end;
    FieldByName('PS').Value:=-ClientDataSet1.fieldbyname('PS').AsFloat;
    FieldByName('YFType').Value:='自动生成';
    FieldByName('Price').Value:=ClientDataSet1.fieldbyname('MYMDPrice').AsFloat;
    if HSFlag.Checked=true then
    begin
      FieldByName('HanShui').Value:='含税';
    end else
    begin
      FieldByName('HanShui').Value:='不含税';
    end;
    FieldByName('CKNO').Value:=trim(FMainid);
    FieldByName('MiQty').Value:=-ClientDataSet1.fieldbyname('Qty').AsFloat;
    FieldByName('KGQty').Value:=-ClientDataSet1.fieldbyname('KGQty').AsFloat;
    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_PMTHCK.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('泡棉退货出库31',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmLLRKInPutMH_PMTHCK.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_PMTHCK.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)+'''');
    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);
    MYCode.text:=Trim(ADOQuery1.fieldbyname('MYCode').AsString);
    MYMDPrice.text:=Trim(floattostr(ADOQuery1.fieldbyname('MYMDPrice').asfloat));
    Price.Text:=Trim(floattostr(ADOQuery1.fieldbyname('Price').asfloat));
    Button1.Visible:=false;
  end
  else
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
    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);
  SCreateCDS20(ADOQuery1,Ord_M);
  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;
  if PState=0 then
  Button1.Click;
  initImage();
end;

function TfrmLLRKInPutMH_PMTHCK.SaveData():Boolean;
var
  maxno,maxmxno,maxnoflag,fsj,FMXID:String;
begin
  Result:=False;
  if RKNo.Text='' then
  begin
    if GetLSNo(ADOCmd,maxmxno,'MT','CK_MYSC_CR',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
    RKNo.Text:=Trim(maxmxno);
  end;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete from YS_Money_CR where YFTypeId in (select MYID from CK_MYSC_CR where RKNo='''+Trim(RKNo.Text)+''')');
    SQL.Add(' delete from CK_MYSC_CR where RKNo='''+Trim(RKNo.Text)+'''');
    ExecSQL;
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if Trim(ClientDataSet1.fieldbyname('MYID').AsString)='' 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(ClientDataSet1.fieldbyname('MYID').AsString);
        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
          Append;
          FieldByName('Filler').Value:=Trim(DName);
          FieldByName('FillerCode').Value:=Trim(DCode);
          if PState=1 then
          begin
            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('MXKCPiQty').value:=ClientDataSet1.fieldbyname('MXHZPS').asfloat;
          FieldByName('MXKCKgQty').value:=ClientDataSet1.fieldbyname('MXHZKgQty').asfloat;
          FieldByName('MXKCQty').value:=-ClientDataSet1.fieldbyname('MXHZQty').asfloat;
          fieldbyname('FZMYID').Value:=Trim(FFZMYID);
          FieldByName('MYId').Value:=Trim(maxno);
          FieldByName('CRType').Value:='退货出库';
          FieldByName('CRFlag').Value:='出库';
          FieldByName('CRQtyFlag').Value:=-1;
          FieldByName('MYType').Value:=Trim(FMYType);
          FieldByName('MYTypeFlag').Value:=Trim(FMYTypeFlag);
          if ClientDataSet1.fieldbyname('GFOrderNo').AsString<>'' then
          begin
            FieldByName('GFOrderNo').Value:=ClientDataSet1.fieldbyname('GFOrderNo').AsString;
          end
          else
          begin
            FieldByName('GFOrderNo').Value:=ClientDataSet1.fieldbyname('RKNo').AsString;
          end;
          Post;
        end;
        FMainId:=Trim(maxno);
        with ADOCmd do
        begin
          close;
          sql.Clear;
          SQL.Add('update M_ZDY set BPPrice='''+trim(ClientDataSet1.fieldbyname('MYMDPrice').AsString)+''' ');
          if ClientDataSet1.fieldbyname('HSFlag').AsBoolean=false then
          sql.Add(',IFHS=''不含税''')
          else
          sql.Add(',IFHS=''含税''');
          sql.Add(' where BPCode='''+trim(ClientDataSet1.fieldbyname('MYCode').AsString)+'''');
          sql.Add(' and BPName='''+trim(ClientDataSet1.fieldbyname('MYName').AsString)+'''');
          ExecSQL;
        end;
        with ClientDataSet1 do
        begin
          edit;
          FieldByName('MYID').AsString:=Trim(maxno);
        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_PMTHCK.TBSaveClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if Trim(KHName.Text)='' then
  begin
    Application.MessageBox('泡棉厂商不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet1.IsEmpty then
  begin
    Application.MessageBox('没有数据保存','提示');
    exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.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_PMTHCK.SaveImage(maxnoWB:string);
begin
  
end;

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

procedure TfrmLLRKInPutMH_PMTHCK.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  ReadCxGrid('泡棉退货出库31',Tv1,'贸易生产管理');
  
end;

procedure TfrmLLRKInPutMH_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.SaveDataMX():Boolean;
begin

end;

procedure TfrmLLRKInPutMH_PMTHCK.QtyChange(Sender: TObject);
begin
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(MXHZQty.text,0));
    MYMDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(Qty.text,0));
    if strtofloatdef(KGQty.text,0)<>0 then
    MYMDPrice.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(KGQty.text,0));
  end;
  if MDKGFlag.Checked=true then
  begin
    MYMDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(KgQty.text,0));
    MYHDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(MXHZKgQty.text,0));
    if strtofloatdef(Qty.text,0)<>0 then
    Price.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(Qty.text,0));
  end;
  MXHZQty.Text:=Qty.Text;
  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_PMTHCK.MDMFlagClick(Sender: TObject);
begin
  if MDMFlag.Checked=true then
  begin
    if MDKGFlag.Checked=true then
    MDKGFlag.Checked:=false;
  end
  else
  begin
    if MDKGFlag.Checked=false then
    MDKGFlag.Checked:=true;
  end;
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(MXHZQty.text,0));
    MYMDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(Qty.text,0));
    if strtofloatdef(KGQty.text,0)<>0 then
    MYMDPrice.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(KGQty.text,0));
  end;
  if MDKGFlag.Checked=true then
  begin
    MYMDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(KgQty.text,0));
    MYHDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(MXHZKgQty.text,0));
    if strtofloatdef(Qty.text,0)<>0 then
    Price.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(Qty.text,0));
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.MDKGFlagClick(Sender: TObject);
begin
  if MDKGFlag.Checked=true then
  begin
    if MDMFlag.Checked=true then
    MDMFlag.Checked:=false;
  end
  else
  begin
    if MDMFlag.Checked=false then
    MDMFlag.Checked:=true;
  end;
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(MXHZQty.text,0));
    MYMDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(Qty.text,0));
    if strtofloatdef(KGQty.text,0)<>0 then
    MYMDPrice.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(KGQty.text,0));
  end;
  if MDKGFlag.Checked=true then
  begin
    MYMDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(KgQty.text,0));
    MYHDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(MXHZKgQty.text,0));
    if strtofloatdef(Qty.text,0)<>0 then
    Price.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(Qty.text,0));
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.MXHZQtyChange(Sender: TObject);
begin
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(MXHZQty.text,0));
    MYMDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(Qty.text,0));
    if strtofloatdef(KGQty.text,0)<>0 then
    MYMDPrice.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(KGQty.text,0));
  end;
  if MDKGFlag.Checked=true then
  begin
    MYMDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(KgQty.text,0));
    MYHDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(MXHZKgQty.text,0));
    if strtofloatdef(Qty.text,0)<>0 then
    Price.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(Qty.text,0));
  end;
  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_PMTHCK.Panel13Click(Sender: TObject);
begin
  Panel12.Visible:=False;
end;

procedure TfrmLLRKInPutMH_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.Image2Click(Sender: TObject);
begin
  Panel12.Visible:=false;
end;

procedure TfrmLLRKInPutMH_PMTHCK.MenuItem1Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName,FWJName:string;
  fFilePath:string;
begin
  if GetLSNo(ADOCmd,FWJName,'TM','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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.Panel2Click(Sender: TObject);
begin
  Panel2.Visible:=false;
end;

procedure TfrmLLRKInPutMH_PMTHCK.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_PMTHCK.JCDanWeiBtnClick(Sender: TObject);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      KHType.Text:='绣花厂';
      KHType.TxtCode:='绣花厂';
      if ShowModal=1 then
      begin
        Self.JCDanWei.Text:=Trim(frmGYSList.Order_Main.fieldbyname('KHName').AsString);
        Self.JCNo.Text:=Trim(frmGYSList.Order_Main.fieldbyname('KHNo').AsString);
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.MXHZKgQtyChange(Sender: TObject);
begin
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(Price.Text,0)*strtofloatdef(MXHZQty.text,0));
    MYMDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(Qty.text,0));
    if strtofloatdef(KGQty.text,0)<>0 then
    MYMDPrice.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(KGQty.text,0));
  end;
  if MDKGFlag.Checked=true then
  begin
    MYMDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(KgQty.text,0));
    MYHDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(MXHZKgQty.text,0));
    if strtofloatdef(Qty.text,0)<>0 then
    Price.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(Qty.text,0));
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.MYMDPriceChange(Sender: TObject);
begin
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(MXHZQty.text,0));
    MYMDMoney.Text:=FloatToStr(strtofloatdef(Price.text,0)*strtofloatdef(Qty.text,0));
    if strtofloatdef(KGQty.text,0)<>0 then
    MYMDPrice.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(KGQty.text,0));
  end;
  if MDKGFlag.Checked=true then
  begin
    MYMDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(KgQty.text,0));
    MYHDMoney.Text:=FloatToStr(strtofloatdef(MYMDPrice.text,0)*strtofloatdef(MXHZKgQty.text,0));
    if strtofloatdef(Qty.text,0)<>0 then
    Price.Text:=FloatToStr(strtofloatdef(MYMDMoney.Text,0)/strtofloatdef(Qty.text,0));
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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_PMTHCK.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);
  MYCode.Text:=Trim(ClientDataSet1.fieldbyname('MYCode').AsString);
  Initimage();
end;

procedure TfrmLLRKInPutMH_PMTHCK.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(MYCode.Text)='' then
  begin
    Application.MessageBox('泡棉编号不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYMDPrice.Text)='' then
  begin
    if Application.MessageBox('单价为空是否继续','提示',1)=2 then exit;
  end;
  if (MDMFlag.Checked=False) and (MDKGFlag.Checked=False) then
  begin
    Application.MessageBox('请选择计价方式','提示',0);
    Exit;
  end;
  if (HSFlag.Checked=False) and (BHSFlag.Checked=False) then
  begin
    Application.MessageBox('请选择含税或不含税','提示',0);
    Exit;
  end;
  if Trim(PS.Text)='' then
  begin
    Application.MessageBox('匹数不能为空!','提示',0);
    Exit;
  end;
  if TryStrToInt(PS.Text,FInt)=False then
  begin
    Application.MessageBox('匹数非法数字!','提示',0);
    exit;
  end;
  if (Trim(Qty.Text)='') and (Trim(KgQty.text)='') then
  begin
    Application.MessageBox('米数和公斤数不能同时为空!','提示',0);
    exit;
  end;
  if Trim(Qty.Text)<>'' then
  begin
    if TryStrToFloat(Qty.Text,FReal)=False then
    begin
      Application.MessageBox('米数非法数字!','提示',0);
      exit;
    end;
  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
    if Button1.Caption='确定' then
      Append
    else
      edit;
    RTsavedataCDS(ClientDataSet1,Panel5,2);
    RTsavedataCDS(ClientDataSet1,Panel14,2);
    ClientDataSet1.FieldByName('MYName').AsString:=trim(MYName.Text);
    ClientDataSet1.FieldByName('MYCode').AsString:=trim(MYCode.Text);
    ClientDataSet1.FieldByName('MDJChang').Value:=0;
    ClientDataSet1.FieldByName('PS').Value:=0;
    ClientDataSet1.FieldByName('Qty').Value:=0;
    ClientDataSet1.FieldByName('KgQty').Value:=0;
    ClientDataSet1.FieldByName('MYMDMoney').Value:=0;
    ClientDataSet1.FieldByName('MYType').AsString:='退货泡棉';
    ClientDataSet1.FieldByName('MDMflag').AsBoolean:=MDMFlag.Checked;
    ClientDataSet1.FieldByName('MDKGFlag').AsBoolean:=MDKGFlag.Checked;
    post;
  end;
  with Ord_M do
  begin
    if Button1.Caption='确定' then
      Append
    else
      edit;
    RTsavedataCDS(Ord_M,Panel5,2);
    RTsavedataCDS(Ord_M,Panel14,2);
    Ord_M.FieldByName('MYName').AsString:=trim(MYName.Text);
    Ord_M.FieldByName('MYCode').AsString:=trim(MYCode.Text);
    Ord_M.FieldByName('MYType').AsString:='退货泡棉';
    post;
  end;
  SClearData(Panel5,2);
  SClearData(Panel15,2);
  MYMDPrice.Text:='';
  Price.Text:='';
  JCDanWei.Text:='绍兴宇昊绣品有限公司';
  JCNo.Text:='GS02';
  MYMF.Text:='151';
  MDKGFlag.Checked:=True;
  HSFlag.Checked:=true;
  FJQty:=Tv1.DataController.Summary.FooterSummaryTexts[0];
  FM:=Tv1.DataController.Summary.FooterSummaryTexts[1];
  FKG:=Tv1.DataController.Summary.FooterSummaryTexts[2];
  FMoney:=Tv1.DataController.Summary.FooterSummaryTexts[3];
  ZJQty.Text:=FJQty;
  ZMQty.Text:=FM;
  ZKGQty.Text:=FKG;
  ZMoney.Text:=FMoney;
  Button1.Caption:='确定';
  cxGrid1.Enabled:=true;
end;

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

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

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

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

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

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

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

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

procedure TfrmLLRKInPutMH_PMTHCK.N2Click(Sender: TObject);
begin
  Button1.Visible:=true;
  button1.Caption:='确定';
  SClearData(Panel5,2);
  SClearData(Panel15,2);
  MYMDPrice.Text:='';
  Price.Text:='';
  JCDanWei.Text:='绍兴宇昊绣品有限公司';
  JCNo.Text:='GS02';
  MYMF.Text:='151';
  MDKGFlag.Checked:=True;
  HSFlag.Checked:=true;
end;

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

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

procedure TfrmLLRKInPutMH_PMTHCK.ToolButton1Click(Sender: TObject);
begin
  frmMCGRKList_CX:=TfrmMCGRKList_CX.create(self);
  with frmMCGRKList_CX do
  begin
    KHNameJC.Text:=self.KHName.Text;
    KHNo.Text:=Self.KHNo.Text;
    if showmodal=1 then
    begin
      self.KHName.Text:=Trim(Order_Main.fieldbyname('KHName').AsString);
      self.KHNo.Text:=Trim(Order_Main.fieldbyname('KHNo').AsString);
      self.MYName.Text:=Trim(Order_Main.fieldbyname('MYName').AsString);
      self.MYCode.Text:=Trim(Order_Main.fieldbyname('MYCode').AsString);
      self.MYKZ.Text:=Trim(Order_Main.fieldbyname('MYKZ').AsString);
      self.MYMF.Text:=Trim(Order_Main.fieldbyname('MYMF').AsString);
      self.GFOrderNo.Text:=Trim(Order_Main.fieldbyname('GFOrderNo').AsString);
      self.PS.Text:=Trim(Order_Main.fieldbyname('PS').AsString);
      self.Qty.Text:=Trim(Order_Main.fieldbyname('Qty').AsString);
      self.KGQty.Text:=Trim(Order_Main.fieldbyname('KGQty').AsString);
      self.MYColor.Text:=Trim(Order_Main.fieldbyname('MYColor').AsString);
      self.MYMD.Text:=Trim(Order_Main.fieldbyname('MYMD').AsString);
      self.MDKGFlag.Checked:=Order_Main.fieldbyname('MDKGFlag').AsBoolean;
      self.MDMFlag.Checked:=Order_Main.fieldbyname('MDMFlag').AsBoolean;
      self.HSFlag.Checked:=Order_Main.fieldbyname('HSFlag').AsBoolean;
      self.BHSFlag.Checked:=Order_Main.fieldbyname('BHSFlag').AsBoolean;
      self.MYMDPrice.Text:=Order_Main.fieldbyname('MYMDPrice').asstring;
      self.Price.Text:=floattostr(Order_Main.fieldbyname('Price').asfloat);
      Self.FFZMYID:=Order_Main.fieldbyname('FZMYID').asstring;
      self.Button1.Click;
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1Column3PropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('Qty').Value:=mavlue;
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('MYMDMoney').Value:=FieldByName('MYMDPrice').AsFloat*FieldByName('Qty').AsFloat;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1Column17PropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('KgQty').Value:=mavlue;
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('MYMDMoney').Value:=FieldByName('MYMDPrice').AsFloat*FieldByName('KgQty').AsFloat;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1MYMDPricePropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('MYMDPrice').Value:=mavlue;
  end;
  with ClientDataSet1 do
  begin
    edit;
    if FieldByName('KgQty').AsFloat<>0 then
    FieldByName('MYMDMoney').Value:=FieldByName('MYMDPrice').AsFloat*FieldByName('KgQty').AsFloat
    else
    FieldByName('MYMDMoney').Value:=FieldByName('MYMDPrice').AsFloat*FieldByName('Qty').AsFloat;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1MDJChangPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('MDJChang').Value:=mavlue;
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('Qty').Value:=FieldByName('MDJChang').AsFloat*FieldByName('PS').AsFloat
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('MYMDMoney').Value:=FieldByName('MYMDPrice').AsFloat*FieldByName('Qty').AsFloat;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1Column1PropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('PS').Value:=mavlue;
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('Qty').Value:=FieldByName('MDJChang').AsFloat*FieldByName('PS').AsFloat
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('MYMDMoney').Value:=FieldByName('MYMDPrice').AsFloat*FieldByName('Qty').AsFloat;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1JCDanWeiPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      KHType.Text:='泡棉厂';
      KHType.TxtCode:='泡棉厂';
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          edit;
          FieldByName('JCDanWei').Value:=Trim(frmGYSList.Order_Main.fieldbyname('KHName').AsString);
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.ToolButton3Click(Sender: TObject);
begin
  ClientDataSet1.Delete;
end;

procedure TfrmLLRKInPutMH_PMTHCK.ToolButton2Click(Sender: TObject);
begin
  with ClientDataSet1 do
  begin
    Append;
    FieldByName('MYType').AsString:='退货泡棉';
    post;
  end;
end;

procedure TfrmLLRKInPutMH_PMTHCK.v1MYNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmBPZDY_LRM:=TfrmBPZDY_LRM.create(self);
  with frmBPZDY_LRM do
  begin
    flag:='MName';
    flagName:='泡棉';
    ViewFlag:=true;
    Panel4.Align:=alClient;
    ToolBar3.Visible:=false;
    Button1.Visible:=False;
    if ShowModal=1 then
    begin
      with Self.ClientDataSet1 do
      begin
        Edit;
        fieldbyname('MYName').AsString:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPName').AsString);
        fieldbyname('MYMF').AsString:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPMF').AsString);
        fieldbyname('MYKZ').AsString:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPKZ').AsString);
        fieldbyname('MYMDPrice').AsString:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPPrice').AsString);
      end;
      MDJChang.SetFocus;
    end;
    free;
  end;
end;

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

end.
