unit U_LLRKMXInPutMH_PBMX;

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, Menus,
  cxGridBandedTableView, cxGridDBBandedTableView, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmLLRKMXInPutMH_PBMX = 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;
    labMYType: TLabel;
    RM1: TRMGridReport;
    CDS_Print: TClientDataSet;
    RMDB_Main: TRMDBDataSet;
    Panel16: TPanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel6: TPanel;
    Panel8: TPanel;
    BtnDel: TButton;
    Button1: TButton;
    Button5: TButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    V1JH: TcxGridDBBandedColumn;
    V1RCGangNo: TcxGridDBBandedColumn;
    V1MQty: TcxGridDBBandedColumn;
    V1KGQty: TcxGridDBBandedColumn;
    V1MQty2: TcxGridDBBandedColumn;
    V1KGQty2: TcxGridDBBandedColumn;
    V1MQty3: TcxGridDBBandedColumn;
    V1KGQty3: TcxGridDBBandedColumn;
    V1MQty4: TcxGridDBBandedColumn;
    V1KGQty4: TcxGridDBBandedColumn;
    V1MQty5: TcxGridDBBandedColumn;
    V1KGQty5: TcxGridDBBandedColumn;
    V1MQty6: TcxGridDBBandedColumn;
    V1KGQty6: TcxGridDBBandedColumn;
    V1MQty7: TcxGridDBBandedColumn;
    V1KGQty7: TcxGridDBBandedColumn;
    V1MQty8: TcxGridDBBandedColumn;
    V1KGQty8: TcxGridDBBandedColumn;
    V1MQty9: TcxGridDBBandedColumn;
    V1KGQty9: TcxGridDBBandedColumn;
    V1MQty10: TcxGridDBBandedColumn;
    V1KGQty10: TcxGridDBBandedColumn;
    V1HJPS: TcxGridDBBandedColumn;
    V1HJQty: TcxGridDBBandedColumn;
    V1HJKGQty: TcxGridDBBandedColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel10: TPanel;
    Label41: TLabel;
    Label42: TLabel;
    Button10: TButton;
    KgQtyAvg: TEdit;
    QtyAvg: TEdit;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label4: TLabel;
    Label5: TLabel;
    Label29: TLabel;
    Label44: TLabel;
    Label49: TLabel;
    MXHZPS: TEdit;
    MXHZQty: TEdit;
    MXHZKgQty: TEdit;
    MYHDMoney: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label6: TLabel;
    PSChaE: TEdit;
    QtyChaE: TEdit;
    KgQtyChaE: TEdit;
    MoneyChaE: TEdit;
    Label31: TLabel;
    Label32: TLabel;
    Label28: TLabel;
    Label45: TLabel;
    Label50: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    MYMDMoney: TEdit;
    Label25: TLabel;
    Label30: TLabel;
    Label35: TLabel;
    UnitM: TEdit;
    UnitKg: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ShuiXiSuoLvClick(Sender: TObject);
    procedure ShuiXiSuoLvJGMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure UnitMClick(Sender: TObject);
    procedure UnitKgClick(Sender: TObject);
    procedure BtnDelClick(Sender: TObject);
    procedure v1Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure UnitMChange(Sender: TObject);
    procedure UnitKgChange(Sender: TObject);
    procedure V1MQtyPropertiesEditValueChanged(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    procedure InitData();
    procedure InitMXData();
    function  SaveData():Boolean;
    procedure GetHZData();
    function SaveDataMX():Boolean;
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FSaveFlag:string;
    { Public declarations }
  end;

var
  frmLLRKMXInPutMH_PBMX: TfrmLLRKMXInPutMH_PBMX;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun, U_QCRKJLList;

{$R *.dfm}

procedure TfrmLLRKMXInPutMH_PBMX.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmLLRKMXInPutMH_PBMX.InitData();
begin
  InitMXData();
  GetHZData();
  if TBSave.Visible=False then
  begin
    BtnDel.Visible:=False;
  end;
end;
procedure TfrmLLRKMXInPutMH_PBMX.InitMXData();
begin
  with ADOTemp 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(ADOTemp,ClientDataSet1);
  SInitCDSData20(ADOTemp,ClientDataSet1);
end;
procedure TfrmLLRKMXInPutMH_PBMX.GetHZData();
var
  FKG,FM,FPS:double;
begin
  FKG:=strtofloatdef(TV1.DataController.Summary.FooterSummaryTexts[2],0);
  FM:=StrToFloatDef(Tv1.DataController.Summary.FooterSummaryTexts[1],0);
  FPS:=StrToFloatDef(Tv1.DataController.Summary.FooterSummaryTexts[0],0);
  MXHZPS.Text:=FloatToStr(FPS);
  MXHZKGQty.Text:=FloatToStr(FKG);
  MXHZQty.Text:=FloatToStr(FM);
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Avg_JS :KgQty,:MQty,:PS');
    if Trim(MXHZKGQty.Text)<>'0' then
    begin
      Parameters.ParamByName('KGQty').Value:=FKG;
    end else
    begin
      Parameters.ParamByName('KGQty').Value:=Null;
    end;
    if Trim(MXHZQty.Text)<>'0' then
    begin
      Parameters.ParamByName('MQty').Value:=FM;
    end else
    begin
      Parameters.ParamByName('MQty').Value:=Null;
    end;
    Parameters.ParamByName('PS').Value:=NULL;
    Open;
  end;
  KgQtyAvg.Text:=FloatToStr(ADOTemp.fieldbyname('KgQtyAvg').asfloat);
  QtyAvg.Text:=FloatToStr(ADOTemp.fieldbyname('QtyAvg').asfloat);
  QtyChaE.Text:=FloatToStr(strtofloatdef(MXHZQty.Text,0)-strtofloatdef(Qty.Text,0));
  PSChaE.Text:=FloatToStr(strtofloatdef(MXHZPS.Text,0)-strtofloatdef(PS.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 TfrmLLRKMXInPutMH_PBMX.FormShow(Sender: TObject);
begin
  ReadCxBandedGrid('坯布明细录入1',Tv1,'贸易生产管理');
  InitData();
end;

function TfrmLLRKMXInPutMH_PBMX.SaveData():Boolean;
var
  maxmxno,maxnoflag,fsj,FMXID:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not Eof do
      begin
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
          Open;
        end;
        FMXID:=Trim(ADOCmd.fieldbyname('MXID').AsString);
        if Trim(FMXID)='' then
        begin
          if GetLSNo(ADOCmd,maxmxno,'LM','CK_MYSC_CR_MX',4,1)=False then
          begin
            ClientDataSet1.EnableControls;
            ADOCmd.Connection.RollbackTrans;
            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('KgQty').Value:=ClientDataSet1.fieldbyname('KgQty').Value;
            FieldByName('MQty').Value:=ClientDataSet1.fieldbyname('MQty').Value;
            FieldByName('Filler').Value:=Trim(DName);
            FieldByName('FillerCode').Value:=Trim(DCode);
            Post;
          end;

          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' exec P_Update_QCRK_GangNo :MYID');
            Parameters.ParamByName('MYID').Value:=Trim(FMainId);
            ExecSQL;
          end;

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

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

procedure TfrmLLRKMXInPutMH_PBMX.TBSaveClick(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  Panel16.Visible:=True;
  Panel16.Refresh;
  Button5.Click;
  Panel16.Visible:=False;
end;

procedure TfrmLLRKMXInPutMH_PBMX.ShuiXiSuoLvClick(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text)='' then
  begin
    TEdit(Sender).Text:='√';
  end else
  begin
    TEdit(Sender).Text:='';
  end;
end;

procedure TfrmLLRKMXInPutMH_PBMX.ShuiXiSuoLvJGMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(FRead)='' then
  begin
    TEdit(Sender).ReadOnly:=True;
  end else
  begin
    TEdit(Sender).ReadOnly:=False;
  end;
end;

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

procedure TfrmLLRKMXInPutMH_PBMX.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 TfrmLLRKMXInPutMH_PBMX.BtnDelClick(Sender: TObject);
var
  FFMXID:string;
begin
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.Delete;
    GetHZData();
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmLLRKMXInPutMH_PBMX.v1Column7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmQCRKJLList:=TfrmQCRKJLList.Create(Application);
    with frmQCRKJLList do
    begin
      FMXID:=Trim(Self.ClientDataSet1.fieldbyname('MXID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmQCRKJLList.Free;
  end;
end;

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

procedure TfrmLLRKMXInPutMH_PBMX.Button1Click(Sender: TObject);
var FPNO:string;
    i:integer;
begin
  tv1.OptionsData.Editing:=true;
  FPNO:=Trim(ClientDataSet1.fieldbyname('RCGangNo').AsString);
  for i:=1 to 10 do
  begin
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('JH').AsInteger:=ClientDataSet1.RecordCount+1;
      FieldByName('RCGangNo').Value:=Trim(FPNo);
      post;
    end;
  end;
end;

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

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

procedure TfrmLLRKMXInPutMH_PBMX.UnitMChange(Sender: TObject);
begin
  if UnitM.Text='√' then
  begin
    v1MQty.Visible:=true;
    v1MQty2.Visible:=true;
    v1MQty3.Visible:=true;
    v1MQty4.Visible:=true;
    v1MQty5.Visible:=true;
    v1MQty6.Visible:=true;
    v1MQty7.Visible:=true;
    v1MQty8.Visible:=true;
    v1MQty9.Visible:=true;
    v1MQty10.Visible:=true;
    V1HJQty.Visible:=true;
    {Label45.Visible:=true;
    Qty.Visible:=true;
    Label44.Visible:=true;
    Label17.Visible:=True;
    QtyChaE.Visible:=True;
    MXHZQty.Visible:=true;}
  end
  else
  begin
    v1MQty.Visible:=false;
    v1MQty2.Visible:=false;
    v1MQty3.Visible:=false;
    v1MQty4.Visible:=false;
    v1MQty5.Visible:=false;
    v1MQty6.Visible:=false;
    v1MQty7.Visible:=false;
    v1MQty8.Visible:=false;
    v1MQty9.Visible:=false;
    v1MQty10.Visible:=false;
    V1HJQty.Visible:=false;
    {Label45.Visible:=false;
    Qty.Visible:=false;
    Label44.Visible:=false;
    Label17.Visible:=false;
    QtyChaE.Visible:=false;
    MXHZQty.Visible:=false;}
  end;
end;

procedure TfrmLLRKMXInPutMH_PBMX.UnitKgChange(Sender: TObject);
begin
  if UnitKg.Text='' then
  begin
    v1KgQty.Visible:=false;
    v1KgQty2.Visible:=false;
    v1KgQty3.Visible:=false;
    v1KgQty4.Visible:=false;
    v1KgQty5.Visible:=false;
    v1KgQty6.Visible:=false;
    v1KgQty7.Visible:=false;
    v1KgQty8.Visible:=false;
    v1KgQty9.Visible:=false;
    v1KgQty10.Visible:=false;
    V1HJKGQty.Visible:=false;
    {KgQty.Visible:=false;
    Label50.Visible:=false;
    MXHZKgQty.Visible:=false;
    label49.Visible:=false;
    KgQtyChaE.Visible:=false;
    Label18.Visible:=false;}
  end
  else
  begin
    v1KgQty.Visible:=true;
    v1KgQty2.Visible:=true;
    v1KgQty3.Visible:=true;
    v1KgQty4.Visible:=true;
    v1KgQty5.Visible:=true;
    v1KgQty6.Visible:=true;
    v1KgQty7.Visible:=true;
    v1KgQty8.Visible:=true;
    v1KgQty9.Visible:=true;
    v1KgQty10.Visible:=true;
    V1HJKGQty.Visible:=true;
    {KgQty.Visible:=true;
    Label50.Visible:=true;
    MXHZKgQty.Visible:=true;
    label49.Visible:=true;
    KgQtyChaE.Visible:=true;
    Label18.Visible:=true;}
  end;
end;

function TfrmLLRKMXInPutMH_PBMX.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 fieldbyname('HJPS').AsFloat<>0 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('KgQty2').Value:=ClientDataSet1.fieldbyname('KgQty2').Value;
            FieldByName('KgQty3').Value:=ClientDataSet1.fieldbyname('KgQty3').Value;
            FieldByName('KgQty4').Value:=ClientDataSet1.fieldbyname('KgQty4').Value;
            FieldByName('KgQty5').Value:=ClientDataSet1.fieldbyname('KgQty5').Value;
            FieldByName('KgQty6').Value:=ClientDataSet1.fieldbyname('KgQty6').Value;
            FieldByName('KgQty7').Value:=ClientDataSet1.fieldbyname('KgQty7').Value;
            FieldByName('KgQty8').Value:=ClientDataSet1.fieldbyname('KgQty8').Value;
            FieldByName('KgQty9').Value:=ClientDataSet1.fieldbyname('KgQty9').Value;
            FieldByName('KgQty10').Value:=ClientDataSet1.fieldbyname('KgQty10').Value;
            FieldByName('MQty').Value:=ClientDataSet1.fieldbyname('MQty').Value;
            FieldByName('MQty2').Value:=ClientDataSet1.fieldbyname('MQty2').Value;
            FieldByName('MQty3').Value:=ClientDataSet1.fieldbyname('MQty3').Value;
            FieldByName('MQty4').Value:=ClientDataSet1.fieldbyname('MQty4').Value;
            FieldByName('MQty5').Value:=ClientDataSet1.fieldbyname('MQty5').Value;
            FieldByName('MQty6').Value:=ClientDataSet1.fieldbyname('MQty6').Value;
            FieldByName('MQty7').Value:=ClientDataSet1.fieldbyname('MQty7').Value;
            FieldByName('MQty8').Value:=ClientDataSet1.fieldbyname('MQty8').Value;
            FieldByName('MQty9').Value:=ClientDataSet1.fieldbyname('MQty9').Value;
            FieldByName('MQty10').Value:=ClientDataSet1.fieldbyname('MQty10').Value;
            FieldByName('HJPS').Value:=ClientDataSet1.fieldbyname('HJPS').Value;
            FieldByName('HJQty').Value:=ClientDataSet1.fieldbyname('HJQty').Value;
            FieldByName('HJKGQty').Value:=ClientDataSet1.fieldbyname('HJKGQty').Value;
            FieldByName('JH').Value:=ClientDataSet1.fieldbyname('JH').Value;
            FieldByName('Filler').Value:=Trim(DName);
            FieldByName('FillerCode').Value:=Trim(DCode);
            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;
          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_PBQty :MYID');
      Parameters.ParamByName('MYID').Value:=Trim(FMainId);
      ExecSQL;
    end;
    //InitData();
    Result:=True;
  except
    Result:=False;
    ClientDataSet1.EnableControls;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmLLRKMXInPutMH_PBMX.V1MQtyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
    FPS1:integer;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with ClientDataSet1 do
  begin
    Edit;
    IF mavlue<>'' then
      FieldByName(FFieldName).Value:=mavlue
    else
      FieldByName(FFieldName).Value:=NULL;
    Post;
  end;
  FPS1:=0;
  if (ClientDataSet1.FieldByName('MQty').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty2').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty2').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty3').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty3').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty4').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty4').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty5').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty5').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty6').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty6').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty7').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty7').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty8').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty8').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty9').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty9').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  if (ClientDataSet1.FieldByName('MQty10').AsFloat<>0) or (ClientDataSet1.FieldByName('KGQty10').AsFloat<>0) then
  begin
    FPS1:=FPS1+1;
  end;
  with ClientDataSet1 do
  begin
    edit;
    FieldByName('HJQty').AsFloat:=fieldbyname('MQty').AsFloat+fieldbyname('MQty2').AsFloat+fieldbyname('MQty3').AsFloat
                                 +fieldbyname('MQty4').AsFloat+fieldbyname('MQty5').AsFloat+fieldbyname('MQty6').AsFloat
                                 +fieldbyname('MQty7').AsFloat+fieldbyname('MQty8').AsFloat+fieldbyname('MQty9').AsFloat
                                 +fieldbyname('MQty10').AsFloat;
    FieldByName('HJKGQty').AsFloat:=fieldbyname('KGQty').AsFloat+fieldbyname('KGQty2').AsFloat+fieldbyname('KGQty3').AsFloat
                                 +fieldbyname('KGQty4').AsFloat+fieldbyname('KGQty5').AsFloat+fieldbyname('KGQty6').AsFloat
                                 +fieldbyname('KGQty7').AsFloat+fieldbyname('KGQty8').AsFloat+fieldbyname('KGQty9').AsFloat
                                 +fieldbyname('KGQty10').AsFloat;
    FieldByName('HJPS').AsFloat:=FPS1;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();
  GetHZData();
end;

procedure TfrmLLRKMXInPutMH_PBMX.Button5Click(Sender: TObject);
var
  FReal:Double;
begin
  if SaveDataMX() then
  begin
    ModalResult:=1;
  end;
end;

end.
