unit U_LLRKInPutMH_XTH;

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_XTH = 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;
    Panel5: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label45: TLabel;
    Label1: TLabel;
    Label4: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQtyChaE: TEdit;
    JCDanWei: TBtnEditA;
    JCNo: TEdit;
    Note: TEdit;
    Label10: TLabel;
    MDJChang: TEdit;
    Label17: TLabel;
    Label25: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label34: TLabel;
    PSChaE: TEdit;
    QtyChaE: TEdit;
    MoneyChaE: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1MYName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1MYMDPrice: TcxGridDBColumn;
    v1MYMDMoney: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label28: TLabel;
    MYMDMoney: TEdit;
    Label18: TLabel;
    JChangCharE: TEdit;
    v1MYSpec: TcxGridDBColumn;
    v1MYColor: TcxGridDBColumn;
    v1MYColorNo: TcxGridDBColumn;
    Panel1: TPanel;
    Label23: TLabel;
    ZJQty: TEdit;
    Label35: TLabel;
    Label37: TLabel;
    ZMQty: TEdit;
    Label38: TLabel;
    ZMoney: TEdit;
    v1XTKGQty: TcxGridDBColumn;
    MYPrice: TEdit;
    Button1: TButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    XTKGQty: TEdit;
    MYCF: TEdit;
    v1MYCF: TcxGridDBColumn;
    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;
    Label24: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label11: TLabel;
    Label20: TLabel;
    MXHZPS: TEdit;
    MXHZQty: TEdit;
    MXHZJChang: TEdit;
    MYHDMoney: TEdit;
    MYColor: TEdit;
    Label2: TLabel;
    MYColorNo: TEdit;
    HSFlag: TCheckBox;
    BHSFlag: TCheckBox;
    Label3: TLabel;
    MYMDPrice: TEdit;
    Label22: TLabel;
    MYName: TEdit;
    Button3: TButton;
    Button4: TButton;
    Label9: TLabel;
    MYSpec: TEdit;
    Button5: TButton;
    N2: TMenuItem;
    ADOQueryTemp: TADOQuery;
    cxGroupBox2: TcxGroupBox;
    ListView1: TListView;
    Panel12: TPanel;
    Label8: TLabel;
    Button2: TButton;
    Panel13: TPanel;
    Image2: TImage;
    WJName: TEdit;
    Button7: TButton;
    WJPach: TEdit;
    Button8: TButton;
    Panel2: TPanel;
    RKNo: TEdit;
    GFOrderNo: TEdit;
    Label12: TLabel;
    vGFOrderNo: TcxGridDBColumn;
    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 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 HSFlagClick(Sender: TObject);
    procedure BHSFlagClick(Sender: TObject);
    procedure PSChaEChange(Sender: TObject);
    procedure QtyChaEChange(Sender: TObject);
    procedure KgQtyChaEChange(Sender: TObject);
    procedure MoneyChaEChange(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 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 Button5Click(Sender: TObject);
    procedure PSChange(Sender: TObject);
    procedure MYMDPriceChange(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  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:String;
    FRead:String;
    FMYType,FMYTypeFlag,FML:string;

    { Public declarations }
  end;

var
  frmLLRKInPutMH_XTH: TfrmLLRKInPutMH_XTH;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_RTFun,U_ZDYHelpSel, U_GYSList,U_SCPerson,U_QCRKJLList,U_RSColorBig,U_ZDYHelp_XCG,
  U_RTPTColor,U_KHListSelJJ,U_ZHCPBigTP,U_LLRKMXInPutMH,U_ZDYCPName,U_BPZdy_LRPB,U_BPZdy_LRX,U_ZDYHelp_LSCol;

{$R *.dfm}
function TfrmLLRKInPutMH_XTH.YFData(FM:string):Boolean;
var
  CRID,OrdMainId,YFID,FComTaiTou,FCRID,FFactoryName,FFactoryNo:String;
begin
  Result:=False;
  FFactoryName:=Trim(KHName.Text);
  FFactoryNo:=Trim(KHNo.Text);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YS_Money_KC where FactoryName='+quotedstr(Trim(FFactoryName)));
    sql.Add(' and KCType=''KH'' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    CRID:=ADOQueryTemp.fieldbyname('CRID').AsString;
  end
  else
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CRID');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YS_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('insert into YS_Money_CRID select 0 ');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
    end;

    CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_KC where 1=2');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value:=StrToInt(CRID);
      FieldByName('FactoryName').Value:=Trim(FFactoryName);
      FieldByName('FactoryNo').Value:=Trim(FFactoryNo);
      FieldByName('ZdyStr1').Value:='应付付';
      FieldByName('KCType').Value:='KH';
      Post;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where FactoryNo='+quotedstr(Trim(FFactoryNo)));
    sql.Add(' and YFTypeId='''+Trim(FM)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd,YFID,'MH','YS_Money_CR',3,1)=False then
    begin
      Application.MessageBox('取应付最大号失败!','提示',0);
      Exit;
    end;
  end
  else
  begin
    YFID:=Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFID='''+Trim(YFID)+'''');
    Open;
  end;
  with ADOQueryCmd do
  begin
    if ADOQueryTemp.IsEmpty then
    begin
      Append;
      FieldByName('SCQty').Value:=ClientDataSet1.fieldbyname('Qty').AsFloat;
      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;
    FieldByName('Qty').Value:=-ClientDataSet1.fieldbyname('Qty').AsFloat;
    FieldByName('QtyUnit').Value:='只';
    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('SJQty').Value:=-ClientDataSet1.fieldbyname('Qty').AsFloat;
    FieldByName('MiQty').Value:=-ClientDataSet1.fieldbyname('Qty').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('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_XTH.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('面线采购入库3',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmLLRKInPutMH_XTH.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_XTH.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);
    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);
    MYMDPrice.text:=Trim(floattostr(ADOQuery1.fieldbyname('MYMDPrice').asfloat));
    Button1.Visible:=false;
  end
  else
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
  end;
  if TBSave.Visible=False then
  begin
    Panel2.Visible:=False;
    initBtnColor(Panel4,clMenu);
    initBtnColor(Panel5,clMenu);
  end;
  SCreateCDS20(ADOQuery1,ClientDataSet1);
  SInitCDSData20(ADOQuery1,ClientDataSet1);
  with ClientDataSet1 do
  begin
    first;
    while not eof do
    begin
      Edit;
      FieldByName('MYID').AsString:='';
      next;
    end;
  end;
  if RKNo.Text='' then
  begin
    if GetLSNo(ADOCmd,maxmxno,'RX','CK_MYSC_CR',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
    RKNo.Text:=Trim(maxmxno);
  end;
  initImage();
end;

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

function TfrmLLRKInPutMH_XTH.SaveData():Boolean;
var
  maxno,maxmxno,maxnoflag,fsj,FMXID:String;
begin
  Result:=False;
  if RKNo.Text='' then
  begin
    if GetLSNo(ADOCmd,maxmxno,'RN','CK_MYSC_CR',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
    RKNo.Text:=Trim(maxmxno);
  end;
  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(ClientDataSet1.fieldbyname('RKNo').asstring)+''')');
    SQL.Add(' delete from CK_MYSC_CR where RKNo='''+Trim(ClientDataSet1.fieldbyname('RKNo').asstring)+'''');
    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
          if IsEmpty then
          begin
            Append;
            FieldByName('Filler').Value:=Trim(DName);
            FieldByName('FillerCode').Value:=Trim(DCode);
            FieldByName('MYCode').Value:='MX'+Trim(ClientDataSet1.fieldbyname('MYColorNo').AsString);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditerCode').Value:=Trim(DCode);
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
            FieldByName('MYCode').Value:='MX'+Trim(ClientDataSet1.fieldbyname('MYColorNo').AsString);
          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('PS').asfloat;
          FieldByName('MXKCKgQty').value:=ClientDataSet1.fieldbyname('KgQty').asfloat;
          FieldByName('MXKCQty').value:=ClientDataSet1.fieldbyname('Qty').asfloat;
          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);
          FieldByName('MDJChang').Value:=ClientDataSet1.fieldbyname('MDJChang').asfloat;
          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 KH_ZDY set ZdyStr1='''+trim(ClientDataSet1.fieldbyname('MYMDPrice').AsString)+''' ');
          sql.Add(' where RTrim(ZDYName)+RTrim(Note)='''+trim(ClientDataSet1.fieldbyname('MYSpec').AsString)+'''');
          sql.Add(' and Type=''MYSpec''');
          sql.Add(' and MainType='''+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_XTH.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_XTH.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_XTH.SaveImage(maxnoWB:string);
begin
  
end;

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

procedure TfrmLLRKInPutMH_XTH.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  ReadCxGrid('面线采购入库3',Tv1,'贸易生产管理');
end;

procedure TfrmLLRKInPutMH_XTH.KHNameBtnClick(Sender: TObject);
begin
  if ClientDataSet1.IsEmpty=false then
  begin
    application.MessageBox('已存在明细,不能修改厂商','提示');
    exit;
  end;
  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);
        self.MYName.Text:=trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString)+Trim(FML);
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmLLRKInPutMH_XTH.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_XTH.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_XTH.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_XTH.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;
  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));
  MoneyChaE.Text:=FloatToStr(strtofloatdef(MYHDMoney.Text,0)-strtofloatdef(MYMDMoney.Text,0));
end;

function TfrmLLRKInPutMH_XTH.SaveDataMX():Boolean;
begin

end;

procedure TfrmLLRKInPutMH_XTH.MYNameBtnClick(Sender: TObject);
begin
  frmBPZDY_LRX:=TfrmBPZDY_LRX.create(self);
  with frmBPZDY_LRX do
  begin
    flag:='XName';
    flagName:='面线';
    ViewFlag:=true;
    Panel4.Align:=alClient;
    ToolBar3.Visible:=false;
    Button1.Visible:=False;
    if ShowModal=1 then
    begin
      MYName.text:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      MYPrice.text:=Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      MYMDPrice.text:=Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      Note.text:=Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
      MDJChang.SetFocus;
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_XTH.MXHZQtyChange(Sender: TObject);
begin
  QtyChaE.Text:=FloatToStr(StrToFloatDef(MXHZQty.Text,0)-strtofloatdef(Qty.Text,0));
end;

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

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

procedure TfrmLLRKInPutMH_XTH.MenuItem1Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName:string;
  fFilePath:string;
begin
  OpenDiaLog := TOpenDialog.Create(Self);
  if OpenDiaLog.Execute then
  begin
    fFilePath:=OpenDiaLog.FileName;
    fFileName:=ExtractFileName(OpenDiaLog.FileName);
    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_XTH.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_XTH.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_XTH.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_XTH.Panel2Click(Sender: TObject);
begin
  Panel2.Visible:=false;
end;

procedure TfrmLLRKInPutMH_XTH.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_XTH.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_XTH.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_XTH.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_XTH.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_XTH.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_XTH.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_XTH.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_XTH.N1Click(Sender: TObject);
var FJQty,FM,FMoney:string;
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;
  ClientDataSet1.Delete;
  FJQty:=Tv1.DataController.Summary.FooterSummaryTexts[0];  //件
  FM:=Tv1.DataController.Summary.FooterSummaryTexts[1];     //总只
  FMoney:=Tv1.DataController.Summary.FooterSummaryTexts[2]; //总金额
  ZJQty.Text:=FJQty;
  ZMQty.Text:=FM;
  ZMoney.Text:=FMoney;
end;

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

procedure TfrmLLRKInPutMH_XTH.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(MYColor.Text)='' then
  begin
    Application.MessageBox('颜色不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYColorNo.Text)='' then
  begin
    Application.MessageBox('线号不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYMDPrice.Text)='' then
  begin
    if Application.MessageBox('单价为空是否继续','提示',1)=2 then 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)='' 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;
  with ClientDataSet1 do
  begin
    if Button1.Caption='确定' then
      Append
    else
      edit;
    RTsavedataCDS(ClientDataSet1,Panel5,2);
    ClientDataSet1.FieldByName('MYName').AsString:=trim(MYName.Text);
    post;
  end;
  SClearData(Panel5,2);
  MYMDPrice.Text:='';
  JCDanWei.Text:='绍兴宇昊绣品有限公司';
  JCNo.Text:='GS02';
  HSFlag.Checked:=true;
  FJQty:=Tv1.DataController.Summary.FooterSummaryTexts[0];  //件
  FM:=Tv1.DataController.Summary.FooterSummaryTexts[1];     //总只
  FMoney:=Tv1.DataController.Summary.FooterSummaryTexts[2]; //总金额
  ZJQty.Text:=FJQty;
  ZMQty.Text:=FM;
  ZMoney.Text:=FMoney;
  Button1.Caption:='确定';
  //button1.Visible:=false;
  cxGrid1.Enabled:=true;
  Panel5.Visible:=false;
end;

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

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

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

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

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

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

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

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

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

procedure TfrmLLRKInPutMH_XTH.Button5Click(Sender: TObject);
begin
  if KHName.Text='' then
  begin
    Application.MessageBox('线厂商不能为空','提示');
    exit;
  end;
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='MYSpec';
    flagname:='纱支规格';
    FNote:=true;
    V1Note.Caption:='成份';
    V1Name.Caption:='纱支';
    FZdyStr2:=True;
    V1ZdyStr2.Caption:='备注';
    Label1.Caption:='纱支';
    Label2.Caption:='成份';
    Label3.Caption:=Trim(MYName.Text);
    if Trim(DParameters1)<>'高权限' then
    begin
      ViewFlag:=true;
    end
    else
    begin
      ViewFlag:=false;
      V1ZdyStr1.Caption:='单价';
      FZdyStr1:=true;
    end;
    MainType:=Trim(MYName.Text);
    if ShowModal=1 then
    begin
      MYSpec.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+trim(ClientDataSet1.fieldbyname('Note').AsString);
      MYMDPrice.Text:=Trim(ClientDataSet1.fieldbyname('ZdyStr1').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_XTH.PSChange(Sender: TObject);
begin
  Qty.Text:=MDJChang.Text;
  MYMDMoney.Text:=FloatToStr(StrToFloatDef(Qty.Text,0)*strtofloatdef(MYMDPrice.Text,0));
end;

procedure TfrmLLRKInPutMH_XTH.MYMDPriceChange(Sender: TObject);
begin
  MYMDMoney.Text:=FloatToStr(StrToFloatDef(Qty.Text,0)*strtofloatdef(MYMDPrice.Text,0));
end;

procedure TfrmLLRKInPutMH_XTH.Button4Click(Sender: TObject);
begin
  if KHName.Text='' then
  begin
    Application.MessageBox('线厂商不能为空','提示');
    exit;
  end;
  frmZDYHelp_XCG:=TfrmZDYHelp_XCG.Create(self);
  with frmZDYHelp_XCG do
  begin
    flag:='MYColor';
    flagname:='颜色';
    FNote:=true;
    V1Note.Caption:='颜色';
    V1Name.Caption:='线号';
    FZdyStr2:=True;
    V1ZdyStr2.Caption:='备注';
    Label3.Caption:=Trim(MYName.Text);
    Label1.Caption:='线号';
    Label2.Caption:='颜色';
    if Trim(DParameters1)<>'高权限' then
    begin
      ViewFlag:=true;
    end
    else
    begin
      ViewFlag:=false;
    end;
    //MainType:=Trim(KHName.Text);
    if ShowModal=1 then
    begin
      MYColor.Text:=trim(ClientDataSet1.fieldbyname('Note').AsString);
      MYColorNo.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      self.Note.Text:=Trim(ClientDataSet1.fieldbyname('ZdyStr2').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_XTH.Button3Click(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='MYColorName';
    flagname:='颜色';
    if ShowModal=1 then
    begin
      MYColor.Text:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_XTH.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  SCSHDataCDS(ClientDataSet1,Panel5,2);
  MYName.Text:=Trim(ClientDataSet1.fieldbyname('MYName').AsString);
  MDJChang.Text:=Trim(ClientDataSet1.fieldbyname('Qty').AsString);
  Initimage();
  Button1.Visible:=true;
  button1.Caption:='修改';
  //cxGrid1.Enabled:=false;
  Panel5.Visible:=true;
end;

end.
