unit U_LLCKInPutMH_MPDNew;

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
  TfrmLLCKInPutMH_MPDNew = 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;
    MYCode: TEdit;
    MYName: TBtnEditA;
    Panel5: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label45: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    KgQtyChaE: TEdit;
    JCDanWei: TBtnEditA;
    JCNo: TEdit;
    Panel14: TPanel;
    Label43: TLabel;
    Label3: TLabel;
    MDMFlag: TCheckBox;
    MDKGFlag: TCheckBox;
    HSFlag: TCheckBox;
    BHSFlag: TCheckBox;
    MYMDPrice: TEdit;
    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;
    v1Column1: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1MYMDPrice: TcxGridDBColumn;
    v1MYMDMoney: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label28: TLabel;
    MYMDMoney: TEdit;
    Label20: TLabel;
    MYHDMoney: TEdit;
    Label18: TLabel;
    JChangCharE: TEdit;
    v1MYKZ: TcxGridDBColumn;
    v1MYMF: TcxGridDBColumn;
    v1MDJChang: 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;
    v1RKNo: TcxGridDBColumn;
    cxStyle2: TcxStyle;
    GroupBox1: TGroupBox;
    N2: TMenuItem;
    ADOQueryTemp: TADOQuery;
    filler: TEdit;
    GFOrderNo: TEdit;
    Label24: TLabel;
    v1GFOrderNo: TcxGridDBColumn;
    Label53: TLabel;
    CGName: TComboBox;
    MYMF: TBtnEditA;
    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 MDMFlagClick(Sender: TObject);
    procedure MDKGFlagClick(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 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 Tv1DblClick(Sender: TObject);
    procedure MYMFBtnClick(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: string;
    FRead: string;
    FMYType, FMYTypeFlag, FML: string;
    { Public declarations }
  end;

var
  frmLLCKInPutMH_MPDNew: TfrmLLCKInPutMH_MPDNew;

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_MCP;

{$R *.dfm}
function TfrmLLCKInPutMH_MPDNew.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;
      if MDMFlag.Checked = 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('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 MDMFlag.Checked = 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('YFName').Value := '棉采购';
    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 TfrmLLCKInPutMH_MPDNew.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('棉采购出库', Tv1, '贸易生产管理');
  Close;
end;

procedure TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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);
    KgQty.text := Trim(ADOQuery1.fieldbyname('KgQty').AsString);
    MYMDMoney.text := Trim(ADOQuery1.fieldbyname('MYMDMoney').AsString);
    MYName.text := Trim(ADOQuery1.fieldbyname('MYName').AsString);
    MYCode.text := Trim(ADOQuery1.fieldbyname('MYCode').AsString);
    MYMDPrice.text := Trim(floattostr(ADOQuery1.fieldbyname('MYMDPrice').asfloat));
    CGName.text := Trim(ADOQuery1.fieldbyname('CGName').AsString);
    Button1.Visible := false;
  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 = 3 then
  begin
    FSubid := '';
  end;
  if PState = 2 then
  begin
    FSubid := '';
    FMainid := '';
    RKNo.Text := '';
    CRTime.Date := SGetServerDate(ADOTemp);
    filler.Text := Trim(DName);
    GFOrderNo.Text := '';
    PS.Text := '';
    MDJChang.Text := '';
    KgQty.Text := '';
    Qty.Text := '';
    MYMDMoney.Text := '';
    MYMDPrice.Text := '';
    HSFlag.Checked := true;
    BHSFlag.Checked := false;
    MDKGFlag.Checked := true;
    MDMFlag.Checked := false;
  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 TfrmLLCKInPutMH_MPDNew.FormShow(Sender: TObject);
begin
  InitData();
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.add(' select UserName from SY_User where Udept like ''%采购部%'' ');
    open;
  end;
  with ADOQueryTemp do
  begin
    first;
    CGName.Items.Add('');
    while not EOF do
    begin
      CGName.Items.Add(trim(fieldByName('UserName').AsString));
      next;
    end;
  end;
end;

function TfrmLLCKInPutMH_MPDNew.SaveData(): Boolean;
var
  maxno, maxmxno, maxnoflag, fsj, FMXID: string;
begin
  Result := False;
  if RKNo.Text = '' then
  begin
    if GetLSNo(ADOCmd, maxmxno, 'PN', '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;
          end
          else
          begin
            edit;
          end;
          FieldByName('Filler').Value := Trim(filler.Text);
          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('MYId').Value := Trim(maxno);
          FieldByName('CRType').Value := '盘点出库';
          FieldByName('CRFlag').Value := '出库';
          FieldByName('SJLX').Value := '新';
          FieldByName('CRQtyFlag').Value := -1;
          FieldByName('MYType').Value := Trim(FMYType);
          FieldByName('MYTypeFlag').Value := Trim(FMYTypeFlag);
          fieldbyname('CGName').AsString := Trim(CGName.Text);
          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 TfrmLLCKInPutMH_MPDNew.TBSaveClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if Trim(KHName.Text) = '' then
  begin
    Application.MessageBox('厂商不能为空!', '提示', 0);
    Exit;
  end;
  Button1.Click;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

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

end;

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

procedure TfrmLLCKInPutMH_MPDNew.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  ReadCxGrid('棉采购出库', Tv1, '贸易生产管理');
end;

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

end;

procedure TfrmLLCKInPutMH_MPDNew.QtyChange(Sender: TObject);
begin
  if MDMFlag.Checked = true then
    MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(Qty.text, 0));
  if MDKGFlag.Checked = true then
    MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(KgQty.text, 0));
  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 TfrmLLCKInPutMH_MPDNew.MDMFlagClick(Sender: TObject);
begin
  if MDMFlag.Checked = true then
  begin
    if MDKGFlag.Checked = true then
      MDKGFlag.Checked := false;
    KgQty.ReadOnly := True;
    KgQty.Color := clMenu;
  end
  else
  begin
    if MDKGFlag.Checked = false then
      MDKGFlag.Checked := true;
    KgQty.ReadOnly := false;
    KgQty.Color := clWindow;
  end;
  if MDMFlag.Checked = true then
  begin
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZQty.text, 0));
    MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(Qty.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));
  end;
end;

procedure TfrmLLCKInPutMH_MPDNew.MDKGFlagClick(Sender: TObject);
begin
  if MDKGFlag.Checked = true then
  begin
    if MDMFlag.Checked = true then
      MDMFlag.Checked := false;
    KgQty.ReadOnly := false;
    KgQty.Color := clWindow;
  end
  else
  begin
    if MDMFlag.Checked = false then
      MDMFlag.Checked := true;
    KgQty.ReadOnly := True;
    KgQty.Color := clMenu;
  end;
  if MDMFlag.Checked = true then
  begin
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZQty.text, 0));
    MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(Qty.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));
  end;
end;

procedure TfrmLLCKInPutMH_MPDNew.MYNameBtnClick(Sender: TObject);
begin
  frmMCP := TfrmMCP.create(self);
  with frmMCP do
  begin
    Flag := 'MName';
    flagName := '棉';
    ViewFlag := true;
    Panel4.Align := alClient;
    ToolBar3.Visible := false;
    ToolBar2.Enabled := false;
    Button1.Visible := False;
    if ShowModal = 1 then
    begin
      MYName.text := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      MYCode.text := Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      MYMF.text := Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
      MYKZ.text := Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
      MYCF.text := Trim(ClientDataSet1.fieldbyname('BPCF').AsString);
      MYPrice.text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      MYMDPrice.text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      Note.text := Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add(' select B.KHName,B.KHNo from M_Tree A INNER JOIN KH_Main B on A.CPName =B.KHNameJC where CPID =(');
        sql.Add(' select CPParent from M_Tree where CPID =(select CPID from M_ZDY where BPID =''' + Trim(ClientDataSet1.fieldbyname('BPID').AsString) + '''');
        sql.Add(' ))');
        open;
      end;
      Self.KHName.Text := Trim(ADOTemp.fieldbyname('KHName').AsString);
      Self.KHNo.Text := Trim(ADOTemp.fieldbyname('KHNo').AsString);
      MDJChang.SetFocus;
    end;
    free;
  end;
end;

procedure TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.Panel13Click(Sender: TObject);
begin
  Panel12.Visible := False;
end;

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

procedure TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.Panel2Click(Sender: TObject);
begin
  Panel2.Visible := false;
end;

procedure TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.MYMDPriceChange(Sender: TObject);
begin
  if MDMFlag.Checked = true then
  begin
    MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(Qty.text, 0));
    MYHDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(MXHZQty.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));
  end;
end;

procedure TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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 TfrmLLCKInPutMH_MPDNew.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
    edit;
    RTsavedataCDS(ClientDataSet1, Panel5, 2);
    RTsavedataCDS(ClientDataSet1, Panel14, 2);
    ClientDataSet1.FieldByName('MYName').AsString := trim(MYName.Text);
    ClientDataSet1.FieldByName('MYCode').AsString := trim(MYCode.Text);
    post;
  end;
  SClearData(Panel5, 2);
  SClearData(Panel15, 2);
  MYMDPrice.Text := '';
  JCDanWei.Text := '绍兴宇昊绣品有限公司';
  JCNo.Text := 'GS02';
  MYMF.Text := '151';
  MDKGFlag.Checked := True;
  HSFlag.Checked := true;
  Button1.Caption := '确定';
end;

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

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

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

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

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

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

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

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

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

procedure TfrmLLCKInPutMH_MPDNew.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;
  Panel5.Visible := true;
end;

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

procedure TfrmLLCKInPutMH_MPDNew.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);
      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);
      MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(KgQty.text, 0));
    end;
    free;
  end;
end;

end.

