unit U_LLRKInPutMH_PMCGCE;

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_PMCGCE = 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;
    Panel3: TPanel;
    labMYType: TLabel;
    Panel4: TPanel;
    Label13: TLabel;
    Label27: TLabel;
    CRTime: TDateTimePicker;
    KHName: TBtnEditA;
    Panel5: TPanel;
    Label12: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    MYKZ: TEdit;
    MYMF: TEdit;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    MXHZPS: TEdit;
    MXHZQty: TEdit;
    MXHZKgQty: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    PSChaE: TEdit;
    QtyChaE: TEdit;
    KgQtyChaE: TEdit;
    Panel7: TPanel;
    Panel1: TPanel;
    Label20: TLabel;
    PTID: TEdit;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    adoqueryPicture: TADOQuery;
    Label2: TLabel;
    MYCF: TEdit;
    Label3: TLabel;
    MYJWS: TEdit;
    Label11: TLabel;
    MYMD: TEdit;
    Label23: TLabel;
    MYPrice: TEdit;
    Panel16: TPanel;
    Label24: TLabel;
    MYMDMoney: TEdit;
    MYHDMoney: TEdit;
    Label28: TLabel;
    Label29: TLabel;
    cxGroupBox1: TcxGroupBox;
    Label25: TLabel;
    Label30: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    QtyLRM: TEdit;
    UnitM: TEdit;
    UnitKg: TEdit;
    RCGangNo: TEdit;
    QtyLRKg: TEdit;
    BtnM: TButton;
    BtnKg: TButton;
    Panel6: TPanel;
    Panel8: TPanel;
    BtnDel: TButton;
    Button1: TButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1JH: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel11: TPanel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    ComboBox2: TComboBox;
    ComboBox1: TComboBox;
    BtnPrt: TButton;
    BtnQX: TButton;
    Button5: TButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    v1MXPrice: TcxGridDBColumn;
    KHNo: TEdit;
    v1MXMoney: TcxGridDBColumn;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N3: TMenuItem;
    MenuItem2: TMenuItem;
    N4: TMenuItem;
    ImageList1: TImageList;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    cxGroupBox2: TcxGroupBox;
    ListView1: TListView;
    Label33: TLabel;
    JCDanWei: TBtnEditA;
    JCNo: TEdit;
    Panel9: TPanel;
    Button3: TButton;
    Button9: TButton;
    Label38: TLabel;
    Edit2: TEdit;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    CheckBox1: TCheckBox;
    Label37: TLabel;
    PLPS: TEdit;
    Panel10: TPanel;
    Button10: TButton;
    Label41: TLabel;
    Label42: TLabel;
    KgQtyAvg: TEdit;
    QtyAvg: TEdit;
    Label39: TLabel;
    RCGangNo1: TEdit;
    Label40: TLabel;
    JH: TEdit;
    ADOQuery2: TADOQuery;
    Panel12: TPanel;
    Label8: TLabel;
    Button2: TButton;
    Panel13: TPanel;
    Image2: TImage;
    WJName: TEdit;
    Button7: TButton;
    WJPach: TEdit;
    Button8: TButton;
    Label44: TLabel;
    Label45: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Panel14: TPanel;
    Label51: TLabel;
    MYMDPrice: TEdit;
    Label43: TLabel;
    MDMFlag: TCheckBox;
    MDKGFlag: TCheckBox;
    MXNote: TEdit;
    Label52: TLabel;
    Panel15: TPanel;
    Label22: TLabel;
    MYCode: TEdit;
    MYName: TBtnEditA;
    Panel2: TPanel;
    Label6: TLabel;
    MoneyChaE: TEdit;
    Label1: TLabel;
    Note: TEdit;
    v1MXNote: TcxGridDBColumn;
    HSFlag: TCheckBox;
    BHSFlag: TCheckBox;
    ADOQueryTemp: TADOQuery;
    Label7: TLabel;
    RKNo: TEdit;
    Label34: TLabel;
    MQty: TEdit;
    Label53: TLabel;
    CGName: TComboBox;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Panel6DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure KHNameBtnClick(Sender: TObject);
    procedure Image1DblClick(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure Label20Click(Sender: TObject);
    procedure UnitMClick(Sender: TObject);
    procedure UnitKgClick(Sender: TObject);
    procedure QtyLRMKeyPress(Sender: TObject; var Key: Char);
    procedure QtyLRKgKeyPress(Sender: TObject; var Key: Char);
    procedure BtnMClick(Sender: TObject);
    procedure BtnKgClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BtnDelClick(Sender: TObject);
    procedure BtnPrtClick(Sender: TObject);
    procedure BtnQXClick(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(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 Button9Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure RCGangNo1Change(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 UnitMChange(Sender: TObject);
    procedure UnitKgChange(Sender: TObject);
  private
    lstPat:TStringList;
    FangXiang1,FSaveFlag:String;
    procedure InitData();
    procedure SaveImage(maxnoWB:String);
    procedure ReadINIFile10();
    function  SaveData():Boolean;
    procedure InitColor();
    procedure ShowImage();
    procedure GetHZData();
    function SaveDataMX():Boolean;
    procedure InitMXData();
    procedure Initimage();
    function YFData():Boolean;
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FMYType,FMYTypeFlag,FML:string;
    { Public declarations }
  end;

var
  frmLLRKInPutMH_PMCGCE: TfrmLLRKInPutMH_PMCGCE;
implementation
uses
  U_DataLink,U_ZDYHelp,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_Fun,U_BPZdy_LRPM;

{$R *.dfm}
function TfrmLLRKInPutMH_PMCGCE.YFData():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(FMainId)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd,YFID,'PB','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:=strtofloatdef(Qty.text,0);
      FieldByName('SCPS').Value:=strtofloatdef(PS.text,0);
    end
    else
    Edit;
    FieldByName('YFID').Value:=Trim(YFID);
    FieldByName('YFTypeId').Value:=Trim(FMainid);
    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:=Strtofloatdef(Qty.text,0);
      FieldByName('QtyUnit').Value:='M';
    end
    else
    begin
      FieldByName('Qty').Value:=Strtofloatdef(KGQty.text,0);
      FieldByName('QtyUnit').Value:='KG';
    end;
    FieldByName('PS').Value:=Strtofloatdef(PS.text,0);
    FieldByName('YFType').Value:='自动生成';
    FieldByName('Price').Value:=Strtofloatdef(MYMDPrice.text,0);
    if HSFlag.Checked=true then
    begin
      FieldByName('HanShui').Value:='含税';
    end else
    begin
      FieldByName('HanShui').Value:='不含税';
    end;
    FieldByName('CKNO').Value:=trim(FMainid);
    FieldByName('SJQty').Value:=Strtofloatdef(Qty.text,0);
    FieldByName('MiQty').Value:=Strtofloatdef(Qty.text,0);
    FieldByName('KGQty').Value:=Strtofloatdef(KGQty.text,0);
    FieldByName('money').Value:=Strtofloatdef(MYMDMoney.text,0);
    FieldByName('HSmoney').Value:=Strtofloatdef(MYMDMoney.text,0);
    FieldByName('P_CodeName').Value:=Trim(MYName.text);
    FieldByName('P_MF').Value:=Trim(MYMF.text);
    FieldByName('P_KZ').Value:=Trim(MYKZ.Text);
    FieldByName('P_Code').Value:=Trim(MYCode.Text);
    FieldByName('P_Spec').Value:=Trim(MYCF.Text);
    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_PMCGCE.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('泡绵采购入库1',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmLLRKInPutMH_PMCGCE.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(FMainId)+''' ');
    sql.Add('and TFType=''采购泡绵''');
    //ShowMessage(sql.Text);
    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_PMCGCE.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select * ');
    sql.Add(' from CK_MYSC_CR   ');
    sql.Add(' where MYID='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel4,2);
  SCSHDataNew(ADOQuery1,Panel4,0);
  SCSHDataNew(ADOQuery1,Panel5,2);
  SCSHDataNew(ADOQuery1,Panel5,0);
  MDMFlag.Checked:=ADOQuery1.FieldByName('MDMflag').AsBoolean;
  MDKGFlag.Checked:=ADOQuery1.FieldByName('MDKGFlag').AsBoolean;
  HSFlag.Checked:=ADOQuery1.FieldByName('HSFlag').AsBoolean;
  BHSFlag.Checked:=ADOQuery1.FieldByName('BHSFlag').AsBoolean;
  KHName.TxtCode:=Trim(ADOQuery1.fieldbyname('KHCode').AsString);
  labMYType.Caption:=Trim(ADOQuery1.fieldbyname('MYType').AsString);
  MYName.text:=Trim(ADOQuery1.fieldbyname('MYName').AsString);
  MYCode.text:=Trim(ADOQuery1.fieldbyname('MYCode').AsString);
  CGName.text:=Trim(ADOQuery1.fieldbyname('CGName').AsString);
  MYMDPrice.text:=Trim(floattostr(ADOQuery1.fieldbyname('MYMDPrice').asfloat));
  ShowImage();
  if PState=0 then
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
    labMYType.Caption:=FMYType;
  end;
  if TBSave.Visible=False then
  begin
   // Panel8.Visible:=False;
    Panel2.Visible:=False;
    initBtnColor(Panel4,clMenu);
    initBtnColor(Panel5,clMenu);
  end;
  InitMXData();
  GetHZData();
  initImage();
end;

procedure TfrmLLRKInPutMH_PMCGCE.InitMXData();
begin
  with ADOQuery2 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,RCGangNo1=(case when isnull(RCGangNo,'''')='''' then GangNo else RCGangNo end)');
    sql.Add(',Laster=isnull(Editer,Filler) from CK_MYSC_CR_MX A where isnull(MYID,'''')='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery2,ClientDataSet1);
  SInitCDSData20(ADOQuery2,ClientDataSet1);
end;

procedure TfrmLLRKInPutMH_PMCGCE.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 TfrmLLRKInPutMH_PMCGCE.SaveData():Boolean;
var
  maxno,maxmxno,maxnoflag,fsj,FMXID:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'PM','CK_MYSC_CR',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end else
    begin
      maxno:=Trim(FMainId);
    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('RKNo').Value:=Trim(maxno);
      end
      else begin
        Edit;
      end;
      FieldByName('MYId').Value:=Trim(maxno);
      FieldByName('CRType').Value:='采购入库';
      FieldByName('CRFlag').Value:='入库';
      FieldByName('CRQtyFlag').Value:=1;
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('FillerCode').Value:=Trim(DCode);
      end else
      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',Panel5,2);
      FieldByName('MDMflag').Value:=MDMFlag.Checked;
      FieldByName('MDKGflag').Value:=MDKGflag.Checked;
      FieldByName('HSFlag').AsBoolean:=HSFlag.Checked;
      FieldByName('BHSFlag').AsBoolean:=BHSFlag.Checked;
      FieldByName('MYType').Value:=Trim(FMYType);
      FieldByName('MYTypeFlag').Value:=Trim(FMYTypeFlag);
      fieldbyname('KHCode').AsString:=Trim(KHName.TxtCode);
      fieldbyname('MYName').AsString:=Trim(MYName.Text);
      fieldbyname('MYCode').AsString:=Trim(MYCode.Text);
      fieldbyname('MYMDPrice').Value:=StrToFloatdef(MYMDPrice.Text,0);
      fieldbyname('CGName').AsString:=Trim(CGName.Text); 
      if RKNo.Text='' then
      begin
        FieldByName('RKNo').Value:=Trim(maxno);
      end;
      Post;
    end;
    FMainId:=Trim(maxno);
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('UPdate CK_MYSC_CR Set KHDayCS=isnull((select isnull(max(KHDayCS),0) from CK_MYSC_CR A ');
      sql.Add(' where A.CRTime=CK_MYSC_CR.CRTime and A.MYType=CK_MYSC_CR.MYType and isnull(A.KHName,'''')=isnull(CK_MYSC_CR.KHName,'''')),0)+1');
      SQL.Add('where MYID='''+Trim(FMainId)+''' and isnull(KHName,'''')<>'''' ');
      sql.Add(' and isnull(KHDayCS,0)=0');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Update_LLRK_Qty :MYID');
      Parameters.ParamByName('MYID').Value:=Trim(maxno);
      ExecSQL;
    end;
    {with ADOCmd do
    begin
      close;
      sql.Clear;
      SQL.Add('update BP_ZDY set BPPrice='''+trim(MYMDPrice.Text)+''' ');
      if HSFlag.Checked=True then
      sql.Add(',IFHS=''含税''')
      else
      sql.Add(',IFHS=''不含税''');
      sql.Add(' where BPCode='''+trim(MYCode.Text)+'''');
      sql.Add(' and BPName='''+trim(MYName.Text)+'''');
      ExecSQL;
    end;}
    Button5.Click;
    YFData();
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.TBSaveClick(Sender: TObject);
var
  FReal:Double;
  FInt:Integer;
begin
  ToolBar1.SetFocus;
  if Trim(KHName.Text)='' then
  begin
    Application.MessageBox('客户不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYCode.Text)='' then
  begin
    Application.MessageBox('产品编号不能为空!','提示',0);
    Exit;
  end;
  {if Trim(RKNo.Text)='' then
  begin
    Application.MessageBox('入库单号不能为空!','提示',0);
    Exit;
  end;}
  if Trim(MYMF.Text)='' then
  begin
    Application.MessageBox('门幅不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYKZ.Text)='' then
  begin
    Application.MessageBox('克重不能为空!','提示',0);
    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;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

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

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

procedure TfrmLLRKInPutMH_PMCGCE.InitColor();
var
  fsj:string;
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from RT_PTColor where PTID='''+Trim(PTID.Text)+'''');
    Open;
  end;
  fsj:=Trim(ADOTemp.fieldbyname('ColDaiMa').AsString);
  if Trim(fsj)<>'' then
  begin
    //Panel6.Color:=StrToInt('$'+Trim(fsj));
  end;
end;
procedure TfrmLLRKInPutMH_PMCGCE.ShowImage();
begin

end;
procedure TfrmLLRKInPutMH_PMCGCE.Panel6DblClick(Sender: TObject);
begin
  {try
    frmRSColorBig:=TfrmRSColorBig.Create(Application);
    with frmRSColorBig do
    begin
      frmRSColorBig.Label1.Caption:=Self.MYColorNo.Text+'#';
      frmRSColorBig.Label2.Caption:=Self.MYColor.Text;
      frmRSColorBig.Color:=Self.Panel6.Color;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
  end; }
end;

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

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

procedure TfrmLLRKInPutMH_PMCGCE.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_PMCGCE.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_PMCGCE.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_PMCGCE.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;
    KgQtyAvg.Text:=ADOTemp.fieldbyname('KgQtyAvg').Value;
    QtyAvg.Text:=ADOTemp.fieldbyname('QtyAvg').Value;
  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;

procedure TfrmLLRKInPutMH_PMCGCE.UnitMClick(Sender: TObject);
begin
  if Trim(UnitM.Text)='' then
  begin
    UnitM.Text:='√';
    QtyLRM.Visible:=True;
    BtnM.Visible:=True;
    if Trim(UnitKg.Text)<>'' then
    begin
      BtnM.Visible:=False;
    end;
  end else
  begin
    UnitM.Text:='';
    QtyLRM.Visible:=False;
    BtnM.Visible:=False;
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.UnitKgClick(Sender: TObject);
begin
  if Trim(UnitKg.Text)='' then
  begin
    UnitKg.Text:='√';
    QtyLRKg.Visible:=True;
    BtnKg.Visible:=True;
    if Trim(UnitM.Text)<>'' then
    begin
      BtnM.Visible:=False;
    end;
  end else
  begin
    UnitKg.Text:='';
    QtyLRKg.Visible:=False;
    BtnKg.Visible:=False;
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.QtyLRMKeyPress(Sender: TObject;
  var Key: Char);
var
  FReal:Double;
  i:Integer;
begin
  if Key=#13 then
  begin
    if Trim(QtyLRM.Text)='' then Exit;
    if TryStrToFloat(QtyLRM.Text,FReal)=False then
    begin
      Application.MessageBox('非法数字!','提示',0);
      Exit;
    end;
    if Trim(UnitKg.Text)<>'' then
    begin
      QtyLRKg.SetFocus;
      Exit;
    end;
    for i:=1 to StrToIntdef(PLPS.Text,1) do
    begin
      with ClientDataSet1 do
      begin
        Append;
        FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
        FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
        FieldByName('MXPrice').Value:=Trim(MYMDPrice.Text);
        FieldByName('MXMoney').Value:=strtofloatdef(MYMDPrice.Text,0)*strtofloatdef(QtyLRM.Text,0);
        FieldByName('MQty').Value:=Trim(QtyLRM.Text);
        FieldByName('MXNote').Value:=Trim(MXNote.Text);
        Post;
      end;
    end;
    QtyLRM.Text:='';
    GetHZData();
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.QtyLRKgKeyPress(Sender: TObject;
  var Key: Char);
var
  FReal:Double;
  i:integer;
begin
  if Key=#13 then
  begin
    if Trim(QtyLRKg.Text)='' then Exit;
    if Trim(UnitM.Text)<>'' then
    begin
      if Trim(QtyLRM.Text)='' then
      begin
        Application.MessageBox('米数不能为空!','提示',0);
        Exit;
      end;
    end;
    if TryStrToFloat(QtyLRKg.Text,FReal)=False then
    begin
      Application.MessageBox('非法数字!','提示',0);
      Exit;
    end;
    for i:=1 to StrToIntdef(PLPS.Text,1) do
    begin
      with ClientDataSet1 do
      begin
        Append;
        FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
        FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
        FieldByName('KgQty').Value:=Trim(QtyLRKg.Text);
        FieldByName('MXPrice').Value:=Trim(MYMDPrice.Text);
        if Trim(UnitM.Text)<>'' then
        begin
          FieldByName('MQty').Value:=Trim(QtyLRM.Text);
        end;
        FieldByName('MXMoney').Value:=strtofloatdef(MYMDPrice.Text,0)*strtofloatdef(QtyLRKg.Text,0);
        FieldByName('MXNote').Value:=Trim(MXNote.Text);
        Post;
      end;
    end;
    QtyLRM.Text:='';
    QtyLRKg.Text:='';
    if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
    GetHZData();
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.BtnMClick(Sender: TObject);
var
  FReal:Double;
  i:integer;
begin
  if Trim(QtyLRM.Text)='' then Exit;
  if TryStrToFloat(QtyLRM.Text,FReal)=False then
  begin
    Application.MessageBox('非法数字!','提示',0);
    Exit;
  end;
  if Trim(UnitKg.Text)<>'' then
  begin
    QtyLRKg.SetFocus;
    Exit;
  end;
  for i:=1 to StrToIntdef(PLPS.Text,1) do
  begin
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
      FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
      FieldByName('MXPrice').Value:=StrToFloatdef(MYMDPrice.Text,0);
      FieldByName('MQty').Value:=StrToFloatdef(QtyLRM.Text,0);
      FieldByName('MXMoney').Value:=strtofloatdef(MYMDPrice.Text,0)*strtofloatdef(QtyLRM.Text,0);
      FieldByName('MXNote').Value:=Trim(MXNote.Text);
      Post;
    end;
  end;
  QtyLRM.Text:='';
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.BtnKgClick(Sender: TObject);
var
  FReal:Double;
  i:integer;
begin
  if Trim(QtyLRKg.Text)='' then Exit;
  if Trim(UnitM.Text)<>'' then
  begin
    if Trim(QtyLRM.Text)='' then
    begin
      Application.MessageBox('米数不能为空!','提示',0);
      Exit;
    end;
  end;
  if TryStrToFloat(QtyLRKg.Text,FReal)=False then
  begin
    Application.MessageBox('非法数字!','提示',0);
    Exit;
  end;
  for i:=1 to StrToIntdef(PLPS.Text,1) do
  begin
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
      FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
      FieldByName('KgQty').Value:=Trim(QtyLRKg.Text);
      FieldByName('MXPrice').Value:=Trim(MYMDPrice.Text);
      if Trim(UnitM.Text)<>'' then
      begin
        FieldByName('MQty').Value:=Trim(QtyLRM.Text);
      end;
      FieldByName('MXMoney').Value:=strtofloatdef(MYMDPrice.Text,0)*strtofloatdef(QtyLRKg.Text,0);
      FieldByName('MXNote').Value:=Trim(MXNote.Text);
      Post;
    end;
  end;
  QtyLRM.Text:='';
  QtyLRKg.Text:='';
  if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.Button1Click(Sender: TObject);
begin
  Panel5.Visible:=True;
end;

procedure TfrmLLRKInPutMH_PMCGCE.BtnDelClick(Sender: TObject);
var
  FFMXID:string;
begin
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      first;
      while ClientDataSet1.Locate('SSel',True,[]) do
      begin
        ClientDataSet1.Delete;
      end;
    end;
    ClientDataSet1.EnableControls;
    GetHZData();
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.BtnPrtClick(Sender: TObject);
var
   fPrintFile,Txt,fImagePath:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if ClientDataSet1.Locate('GangNo',null,[])=true then
  begin
    Application.MessageBox('没有保存数据, 请先点击保存，再打印标签。','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('SSel',True,[])=false then
  begin
    Application.MessageBox('没有选择数据, 请先选择数据，再打印标签。','提示',0);
    Exit;
  end;
  if ComboBox2.Text='' then
  begin
    Application.MessageBox('请选择张数!','提示',0);
    Exit;
  end;
  if ComboBox1.Text='' then
  begin
    Application.MessageBox('请选择尺寸!','提示',0);
    Exit;
  end;
  if ComboBox1.Text='9*7' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\来料入库棉无纺布标签97.rmf';
  end else
  if ComboBox1.Text='8*5' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\来料入库棉无纺布标签85.rmf';
  end;
  if FileExists(fPrintFile)=False then
  begin
    if ComboBox1.Text='9*7' then
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\来料入库棉无纺布标签97.rmf'),'提示',0);
    if ComboBox1.Text='8*5' then
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\来料入库棉无纺布标签85.rmf'),'提示',0);
    exit;
  end;
  ClientDataSet1.DisableControls;
  with ClientDataSet1 do
  begin
    First;
    while Locate('SSel',True,[]) do
    begin
      with ADOTemp do
      begin
        Close;
        SQL.Clear;
        sql.Add(' Exec P_PRT_LLRK_ML :MXID');
        Parameters.ParamByName('MXID').Value:=Trim(ClientDataSet1.fieldbyname('MXID').AsString);
        Open;
      end;
      SCreateCDS20(ADOTemp,CDS_Print);
      SInitCDSData20(ADOTemp,CDS_Print);
      try
        Moudle:=LoadLibrary('MakeQRBarcode.dll');
        @Makebar:=GetProcAddress(Moudle,'Make');
        @Mixtext:=GetProcAddress(Moudle,'MixText');
        Txt:=Trim(ClientDataSet1.fieldbyname('MXID').AsString);
        fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
        if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
          CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
        if FileExists(fImagePath) then DeleteFile(fImagePath);
        Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
      except
        application.MessageBox('二维码生成失败！','提示信息',MB_ICONERROR);
        exit;
      end;
      Edit;
      FieldByName('SSel').Value:=False;
      RMVariables['QRBARCODE']:=fImagePath;
      RM1.LoadFromFile(fPrintFile);
      //RM1.ShowReport;
      for i:=1 to StrToInt(ComboBox2.Text) do
      begin
        RM1.PrintReport;
      end;
    end;
  end;
  ClientDataSet1.EnableControls;
  ComboBox2.ItemIndex:=0;
  ComboBox1.ItemIndex:=-1;
  Panel5.Visible:=False;
end;

procedure TfrmLLRKInPutMH_PMCGCE.BtnQXClick(Sender: TObject);
begin
  Panel5.Visible:=False;
end;

function TfrmLLRKInPutMH_PMCGCE.SaveDataMX():Boolean;
var
  maxmxno,maxnoflag,fsj,FMXID:String;
begin
  Result:=False;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete from CK_MYSC_CR_MX where MYID='''+Trim(FMainId)+'''');
    ExecSQL;
  end;
  try
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        //if FMXID='' then
        begin
          if GetLSNo(ADOCmd,maxmxno,'LM','CK_MYSC_CR_MX',4,1)=False then
          begin
            ClientDataSet1.EnableControls;
            Application.MessageBox('取来料入库数据最大号失败','提示',0);
            Exit;
          end;
          maxmxno:=maxmxno+'LML';
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(maxmxno)+'''');
            Open;
          end;
          with ADOCmd do
          begin
            Append;
            FieldByName('MYID').Value:=Trim(FMainId);
            FieldByName('MXID').Value:=Trim(maxmxno);
            FieldByName('RCGangNo').Value:=ClientDataSet1.fieldbyname('RCGangNo').Value;
            FieldByName('MXPrice').Value:=ClientDataSet1.fieldbyname('MXPrice').Value;
            FieldByName('MXMoney').Value:=ClientDataSet1.fieldbyname('MXMoney').Value;
            FieldByName('KgQty').Value:=ClientDataSet1.fieldbyname('KgQty').Value;
            FieldByName('MQty').Value:=ClientDataSet1.fieldbyname('MQty').Value;
            FieldByName('JH').Value:=ClientDataSet1.fieldbyname('JH').Value;
            FieldByName('Filler').Value:=Trim(DName);
            FieldByName('FillerCode').Value:=Trim(DCode);
            FieldByName('MXNote').Value:=Trim(MXNote.Text);
            Post;
          end;
          if ClientDataSet1.fieldbyname('GangNo').AsString='' then
          begin
            with ADOCmd do
            begin
              Close;
              sql.Clear;
              sql.Add(' exec P_Update_QCRK_GangNo :MYID');
              Parameters.ParamByName('MYID').Value:=Trim(FMainId);
              ExecSQL;
            end;
          end;
          if ClientDataSet1.fieldbyname('JH').AsFloat=0 then
          begin
            with ADOCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('Update CK_MYSC_CR_MX Set JH=isnull((select isnull(max(JH),0) from CK_MYSC_CR_MX A ');
              sql.Add(' where A.MYID='''+Trim(FMainId)+''' and isnull(A.RCGangNO,'''')=isnull(CK_MYSC_CR_MX.RCGangNO,'''')');
              sql.Add(' and isnull(A.GangNO,'''')=isnull(CK_MYSC_CR_MX.GangNO,'''')),0)+1 ');
              sql.Add(' where MXID='''+Trim(maxmxno)+'''');
              ExecSQL;
            end;
          end;
          Edit;
          FieldByName('MYID').Value:=Trim(FMainId);
          FieldByName('MXID').Value:=Trim(maxmxno);
          Post;
        end;
        Next;
      end;
    end;
    ClientDataSet1.EnableControls;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Update_LLRK_Qty :MYID');
      Parameters.ParamByName('MYID').Value:=Trim(FMainId);
      ExecSQL;
    end;
    //InitData();
    Result:=True;
  except
    Result:=False;
    ClientDataSet1.EnableControls;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.Button5Click(Sender: TObject);
var
  FReal:Double;
begin
  if SaveDataMX() then
  begin
    GetHZData();
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.N1Click(Sender: TObject);
begin
  SelOKNo(ClientDataSet1,True);
end;

procedure TfrmLLRKInPutMH_PMCGCE.N2Click(Sender: TObject);
begin
  SelOKNo(ClientDataSet1,False);
end;

procedure TfrmLLRKInPutMH_PMCGCE.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));
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.MDMFlagClick(Sender: TObject);
begin
  if MDMFlag.Checked=true then
  begin
    if MDKGFlag.Checked=true then
    MDKGFlag.Checked:=false;
  end
  else
  begin
    if MDKGFlag.Checked=false then
    MDKGFlag.Checked:=true;
  end;
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(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;
  if ClientDataSet1.IsEmpty=false then
  begin
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        edit;
        FieldByName('MXPrice').Value:=strtofloatdef(MYMDPrice.text,0);
        if MDMFlag.Checked=True then
        FieldByName('MXMoney').Value:=FieldByName('MQty').AsFloat*strtofloatdef(MYMDPrice.text,0)
        else
        FieldByName('MXMoney').Value:=FieldByName('KgQty').AsFloat*strtofloatdef(MYMDPrice.text,0);
        next;
      end;
    end;
    ClientDataSet1.EnableControls;
  end;
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.MDKGFlagClick(Sender: TObject);
begin
  if MDKGFlag.Checked=true then
  begin
    if MDMFlag.Checked=true then
    MDMFlag.Checked:=false;
  end
  else
  begin
    if MDMFlag.Checked=false then
    MDMFlag.Checked:=true;
  end;
  if MDMFlag.Checked=true then
  begin
    MYHDMoney.Text:=FloatToStr(strtofloatdef(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;
  if ClientDataSet1.IsEmpty=false then
  begin
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        edit;
        FieldByName('MXPrice').Value:=strtofloatdef(MYMDPrice.text,0);
        if MDMFlag.Checked=True then
        FieldByName('MXMoney').Value:=FieldByName('MQty').AsFloat*strtofloatdef(MYMDPrice.text,0)
        else
        FieldByName('MXMoney').Value:=FieldByName('KgQty').AsFloat*strtofloatdef(MYMDPrice.text,0);
        next;
      end;
    end;
    ClientDataSet1.EnableControls;
  end;
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.MYNameBtnClick(Sender: TObject);
begin
  frmBPZDY_LRPM:=TfrmBPZDY_LRPM.create(self);
  with frmBPZDY_LRPM do
  begin
    flag:='PMName';
    flagName:='泡绵';
    ViewFlag:=true;
    ToolBar3.Visible:=false;
    Button1.Visible:=False;
    Panel7.Visible:=false;
    if ShowModal=1 then
    begin
      MYName.text:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      MYCode.text:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      MYCF.text:=Trim(ClientDataSet1.fieldbyname('BPCF').AsString);
      MYMF.text:=Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
      MYKZ.text:=Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
      MYJWS.text:=Trim(ClientDataSet1.fieldbyname('BPJS').AsString);
      MYMD.text:=Trim(ClientDataSet1.fieldbyname('BPMiDu').AsString);
      Note.text:=Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
      if ClientDataSet1.fieldbyname('IFHS').AsString='含税' then
      begin
        HSFlag.Checked:=True;
        BHSFlag.Checked:=false;
      end
      else
      begin
        HSFlag.Checked:=false;
        BHSFlag.Checked:=true;
      end;
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.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));
  GetHZData();
end;

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

procedure TfrmLLRKInPutMH_PMCGCE.Button2Click(Sender: TObject);
var
  fFileName:string;
  fFilePath:string;
  maxNo:string;
begin
  if FMainid='' then
  begin
    if GetLSNo(ADOCmd,FMainid,'LL','CK_MYSC_CR',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
  end;
  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(FMainid)+''' ');
        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(FMainid)+'''');
        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(FMainid)+'''');
        sql.Add('and TFType=''采购泡绵''');
        sql.Add('and FileName='+quotedstr(trim(fFileName)));
        open;
        append;
        fieldbyname('TFID').Value:=trim(maxNO);
        fieldbyname('WBID').Value:=trim(FMainid);
        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_PMCGCE.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(FMainid)+'''');
    sql.Add('and TFType=''采购泡绵''');
    sql.Add('and FileName='+quotedstr(trim(fFileName)));
    execsql;
  end;
  Panel12.Visible:=False;
  Initimage();
end;

procedure TfrmLLRKInPutMH_PMCGCE.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(FMainid)+'''');
      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(FMainid)+'''');
      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(FMainid)+'''');
      sql.Add('and TFType=''采购泡绵''');
      sql.Add('and FileName='+quotedstr(trim(fFileName)));
      open;
      append;
      fieldbyname('TFID').Value:=trim(maxNO);
      fieldbyname('WBID').Value:=trim(FMainid);
      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_PMCGCE.Image2Click(Sender: TObject);
begin
  Panel12.Visible:=false;
end;

procedure TfrmLLRKInPutMH_PMCGCE.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_PMCGCE.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(FMainid)+'''');
      sql.Add('and TFType=''采购泡绵''');
      sql.Add('and FileName='+quotedstr(trim(fFileName)));
      execsql;
    end;
    Initimage();
  except
  end;
end;

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

procedure TfrmLLRKInPutMH_PMCGCE.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_PMCGCE.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_PMCGCE.Button9Click(Sender: TObject);
begin
  Panel9.Visible:=false;
end;

procedure TfrmLLRKInPutMH_PMCGCE.N5Click(Sender: TObject);
begin
  panel9.Visible:=true;
  Label38.Caption:='批量更改批号:';
end;

procedure TfrmLLRKInPutMH_PMCGCE.N6Click(Sender: TObject);
begin
  panel9.Visible:=true;
  Label38.Caption:='批量更改米数:';
end;

procedure TfrmLLRKInPutMH_PMCGCE.N7Click(Sender: TObject);
begin
  panel9.Visible:=true;
  Label38.Caption:='批量更改公斤数:';
end;

procedure TfrmLLRKInPutMH_PMCGCE.Button3Click(Sender: TObject);
var
  FFMXID:string;
begin
  if Label38.Caption='批量更改批号:' then
  begin
    if ClientDataSet1.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择数据!','提示',0);
      Exit;
    end;
    try
      ADOCmd.Connection.BeginTrans;
      ClientDataSet1.DisableControls;
      with ClientDataSet1 do
      begin
        first;
        while not eof do
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            SQL.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            Open;
          end;
          FFMXID:=Trim(ADOTemp.fieldbyname('MXID').AsString);
          if Trim(FFMXID)<>'' then
          begin
            with ADOCmd do
            begin
              Close;
              sql.Clear;
              sql.Add(' UPdate CK_MYSC_CR_MX Set RCGangNo='''+Trim(Edit2.Text)+'''');
              sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
              ExecSQL;
            end;
          end;
          if FieldByName('Ssel').AsBoolean then
          begin
            Edit;
          //FieldByName('SSel').Value:=false;
            FieldByName('RCGangNo').Value:=Trim(Edit2.Text);
          end;
          next;
        end;
      end;
      ClientDataSet1.EnableControls;
      ADOCmd.Connection.CommitTrans;
      FSaveFlag:='99';
      //Button5.Click;
      FSaveFlag:='';
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' exec P_Update_LLRK_Qty :MYID');
        Parameters.ParamByName('MYID').Value:=Trim(FMainId);
        ExecSQL;
      end;
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(FMainId)+'''');
        Open;
      end;
      SCSHDataNew(ADOTemp,Panel2,2);
      GetHZData();
    except
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('数据删除异常！','提示',0);
      Exit;
    end;
  end;
  if Label38.Caption='批量更改米数:' then
  begin
    if ClientDataSet1.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择数据!','提示',0);
      Exit;
    end;
    try
      ADOCmd.Connection.BeginTrans;
      ClientDataSet1.DisableControls;
      with ClientDataSet1 do
      begin
        first;
        while not eof do
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            SQL.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            Open;
          end;
          FFMXID:=Trim(ADOTemp.fieldbyname('MXID').AsString);
          if Trim(FFMXID)<>'' then
          begin
            with ADOCmd do
            begin
              Close;
              sql.Clear;
              sql.Add(' UPdate CK_MYSC_CR_MX Set MQty='''+Trim(Edit2.Text)+'''');
              if MDMFlag.Checked=True then
              sql.add(',MXMoney=MQty*MXPrice');
              sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
              ExecSQL;
            end;
          end;
          if FieldByName('Ssel').AsBoolean=true then
          begin
            Edit;
          //FieldByName('SSel').Value:=false;
            FieldByName('MQty').Value:=Trim(Edit2.Text);
            if MDMFlag.Checked=True then
            FieldByName('MXMoney').Value:=StrToFloatdef(Edit2.Text,0)*strtofloatdef(MYMDPrice.Text,0);
          end;
          next;
        end;
      end;
      ClientDataSet1.EnableControls;
      ADOCmd.Connection.CommitTrans;
      FSaveFlag:='99';
      //Button5.Click;
      FSaveFlag:='';
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' exec P_Update_LLRK_Qty :MYID');
        Parameters.ParamByName('MYID').Value:=Trim(FMainId);
        ExecSQL;
      end;
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(FMainId)+'''');
        Open;
      end;
      SCSHDataNew(ADOTemp,Panel2,2);
      GetHZData();
    except
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('数据删除异常！','提示',0);
      Exit;
    end;
  end;

  if Label38.Caption='批量更改公斤数:' then
  begin
    if ClientDataSet1.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择数据!','提示',0);
      Exit;
    end;
    try
      ADOCmd.Connection.BeginTrans;
      ClientDataSet1.DisableControls;
      with ClientDataSet1 do
      begin
        first;
        while not eof do
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            SQL.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            Open;
          end;
          FFMXID:=Trim(ADOTemp.fieldbyname('MXID').AsString);
          if Trim(FFMXID)<>'' then
          begin
            with ADOCmd do
            begin
              Close;
              sql.Clear;
              sql.Add(' UPdate CK_MYSC_CR_MX Set KgQty='''+Trim(Edit2.Text)+'''');
              if MDKGFlag.Checked=True then
              sql.add(',MXMoney=KgQty*MXPrice');
              sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
              ExecSQL;
            end;
          end;
          if FieldByName('Ssel').AsBoolean=true then
          begin
            Edit;
            //FieldByName('SSel').Value:=false;
            FieldByName('KgQty').Value:=Trim(Edit2.Text);
            if MDKGFlag.Checked=True then
            FieldByName('MXMoney').Value:=StrToFloatdef(Edit2.Text,0)*strtofloatdef(MYMDPrice.Text,0);
          end;
          next;
        end;
      end;
      ClientDataSet1.EnableControls;
      ADOCmd.Connection.CommitTrans;
      FSaveFlag:='99';
      //Button5.Click;
      FSaveFlag:='';
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' exec P_Update_LLRK_Qty :MYID');
        Parameters.ParamByName('MYID').Value:=Trim(FMainId);
        ExecSQL;
      end;
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(FMainId)+'''');
        Open;
      end;
      SCSHDataNew(ADOTemp,Panel2,2);
      GetHZData();
    except
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('数据删除异常！','提示',0);
      Exit;
    end;
  end;
  Edit2.Text:='';
  Panel9.Visible:=false;
  TBSave.Caption:='保存改';
  ClientDataSet1.Locate('SSel',True,[]);
end;

procedure TfrmLLRKInPutMH_PMCGCE.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked=True then
  begin
    PLPS.Visible:=True;
    Label37.Visible:=true;
    PLPS.Text:='';
  end
  else
  begin
    PLPS.Visible:=false;
    Label37.Visible:=false;
    PLPS.Text:='';
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.RCGangNo1Change(Sender: TObject);
begin
  SDofilter(ADOQuery2,SGetFilters(Panel8,1,2));
  SCreateCDS20(ADOQuery2,ClientDataSet1);
  SInitCDSData20(ADOQuery2,ClientDataSet1);
end;

procedure TfrmLLRKInPutMH_PMCGCE.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));
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.MYMDPriceChange(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));
  if ClientDataSet1.IsEmpty=false then
  begin
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        edit;
        FieldByName('MXPrice').Value:=strtofloatdef(MYMDPrice.text,0);
        if MDMFlag.Checked=True then
        FieldByName('MXMoney').Value:=FieldByName('MQty').AsFloat*strtofloatdef(MYMDPrice.text,0)
        else
        FieldByName('MXMoney').Value:=FieldByName('KgQty').AsFloat*strtofloatdef(MYMDPrice.text,0);
        next;
      end;
    end;
    ClientDataSet1.EnableControls;
  end;
  GetHZData();
end;

procedure TfrmLLRKInPutMH_PMCGCE.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_PMCGCE.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_PMCGCE.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_PMCGCE.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_PMCGCE.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_PMCGCE.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_PMCGCE.UnitMChange(Sender: TObject);
begin
  if UnitM.Text='√' then
  begin
    v1Column3.Visible:=true;
    Label45.Visible:=true;
    Qty.Visible:=true;
    Label44.Visible:=true;
    Label17.Visible:=True;
    QtyChaE.Visible:=True;
    MXHZQty.Visible:=true;
    QtyLRM.Visible:=true;
  end
  else
  begin
    v1Column3.Visible:=false;
    Label45.Visible:=false;
    Qty.Visible:=false;
    Label44.Visible:=false;
    Label17.Visible:=false;
    QtyChaE.Visible:=false;
    MXHZQty.Visible:=false;
    QtyLRM.Visible:=false;
  end;
end;

procedure TfrmLLRKInPutMH_PMCGCE.UnitKgChange(Sender: TObject);
begin
  if UnitKg.Text='' then
  begin
    v1Column17.Visible:=false;
    KgQty.Visible:=false;
    Label50.Visible:=false;
    MXHZQty.Visible:=false;
    label49.Visible:=false;
    KgQtyChaE.Visible:=false;
    Label18.Visible:=false;
    QtyLRKg.Visible:=false;
  end
  else
  begin
    v1Column17.Visible:=true;
    KgQty.Visible:=true;
    Label50.Visible:=true;
    MXHZQty.Visible:=true;
    label49.Visible:=true;
    KgQtyChaE.Visible:=true;
    Label18.Visible:=true;
    QtyLRKg.Visible:=true;
  end;
end;

end.
