unit U_LLRKMXInPut_WJG;

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;

type
  TfrmLLRKMXInPut_WJG = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    TBSave: TToolButton;
    Panel3: TPanel;
    Label13: TLabel;
    CRTime: TDateTimePicker;
    cxGroupBox1: TcxGroupBox;
    QtyLRM: TEdit;
    Label7: TLabel;
    UnitM: TEdit;
    Label9: TLabel;
    UnitKg: TEdit;
    Label10: TLabel;
    Label22: TLabel;
    RCGangNo: TEdit;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    QtyLRKg: TEdit;
    Panel1: TPanel;
    Panel2: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label4: TLabel;
    GangQty: TEdit;
    Label8: TLabel;
    MXHZPS: TEdit;
    Label17: TLabel;
    MXHZKGQty: TEdit;
    Label18: TLabel;
    MYType: TBtnEditA;
    BtnDel: TButton;
    v1Column4: TcxGridDBColumn;
    Panel4: TPanel;
    Label23: TLabel;
    Label24: TLabel;
    KgQty1: TEdit;
    MQty1: TEdit;
    Button6: TButton;
    Label20: TLabel;
    RCGangNO1: TEdit;
    MLID: TEdit;
    BPID: TEdit;
    DYID: TEdit;
    PTID: TEdit;
    KgQtyAvg: TEdit;
    Label25: TLabel;
    QtyAvg: TEdit;
    Label5: TLabel;
    Label21: TLabel;
    Label26: TLabel;
    Label19: TLabel;
    labMYType: TLabel;
    MXHZQty: TEdit;
    v1Column7: TcxGridDBColumn;
    RM1: TRMGridReport;
    CDS_Print: TClientDataSet;
    RMDB_Main: TRMDBDataSet;
    Button1: TButton;
    BtnM: TButton;
    BtnKg: TButton;
    Panel5: TPanel;
    Label28: TLabel;
    ComboBox2: TComboBox;
    Label29: TLabel;
    ComboBox1: TComboBox;
    BtnPrt: TButton;
    BtnQX: TButton;
    Label30: TLabel;
    Button3: TButton;
    Panel16: TPanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    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 QtyLRMKeyPress(Sender: TObject; var Key: Char);
    procedure QtyLRKgKeyPress(Sender: TObject; var Key: Char);
    procedure BtnQXClick(Sender: TObject);
    procedure MYNameKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button6Click(Sender: TObject);
    procedure BtnDelClick(Sender: TObject);
    procedure v1Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnPrtClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BtnMClick(Sender: TObject);
    procedure BtnKgClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    procedure InitData();
    procedure InitMXData();
    function  SaveData():Boolean;
    procedure GetHZData();
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FSaveFlag:string;
    { Public declarations }
  end;

var
  frmLLRKMXInPut_WJG: TfrmLLRKMXInPut_WJG;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun, U_QCRKJLList;

{$R *.dfm}

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

procedure TfrmLLRKMXInPut_WJG.InitData();
begin
  InitMXData();
  GetHZData();
  if TBSave.Visible=False then
  begin
    BtnDel.Visible:=False;
    Panel3.Visible:=False;
  end;
end;
procedure TfrmLLRKMXInPut_WJG.InitMXData();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,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 TfrmLLRKMXInPut_WJG.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;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(FMainId)+'''');
    Open;
  end;
  GangQty.Text:=ADOTemp.fieldbyname('GangQty').AsString;
end;

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

function TfrmLLRKMXInPut_WJG.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 TfrmLLRKMXInPut_WJG.TBSaveClick(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  Panel16.Visible:=True;
  Panel16.Refresh;
  if SaveData() then
  begin
    GetHZData();
    if Trim(FSaveFlag)<>'99' then
    begin
      Application.MessageBox('保存成功！','提示',0);
    end;
  end;
  Panel16.Visible:=False;
end;

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

procedure TfrmLLRKMXInPut_WJG.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 TfrmLLRKMXInPut_WJG.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 TfrmLLRKMXInPut_WJG.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 TfrmLLRKMXInPut_WJG.QtyLRMKeyPress(Sender: TObject; var Key: Char);
var
  FReal:Double;
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;
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
      FieldByName('MQty').Value:=Trim(QtyLRM.Text);
      Post;
    end;
    QtyLRM.Text:='';
    GetHZData();
  end;
end;

procedure TfrmLLRKMXInPut_WJG.QtyLRKgKeyPress(Sender: TObject; var Key: Char);
var
  FReal:Double;
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;
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
      FieldByName('KgQty').Value:=Trim(QtyLRKg.Text);
      if Trim(UnitM.Text)<>'' then
      begin
        FieldByName('MQty').Value:=Trim(QtyLRM.Text);
      end;
      Post;
    end;
    QtyLRM.Text:='';
    QtyLRKg.Text:='';
    if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
    GetHZData();
  end;
end;

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

procedure TfrmLLRKMXInPut_WJG.MYNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(MYType.Text)='' then
    begin
      Application.MessageBox('没有选择产品类型!','提示',0);
      Exit;
    end;
  end;
end;

procedure TfrmLLRKMXInPut_WJG.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if ClientDataSet1.IsEmpty then Exit;
  if BtnDel.Visible=False then Exit;
  if TBSave.Visible=False then Exit;
  Panel4.Visible:=True;
  RCGangNO1.Text:=ClientDataSet1.fieldbyname('RCGangNO').Value;
  if Trim(ClientDataSet1.fieldbyname('KgQty').AsString)<>'' then
    KgQty1.Text:=ClientDataSet1.fieldbyname('KgQty').Value
  else
     KgQty1.Text:='';
  if Trim(ClientDataSet1.fieldbyname('MQty').AsString)<>'' then
    MQty1.Text:=ClientDataSet1.fieldbyname('MQty').Value
  else
     MQty1.Text:='';
end;

procedure TfrmLLRKMXInPut_WJG.Button6Click(Sender: TObject);
var
  FReal:Double;
begin
  if Trim(KgQty1.Text)<>'' then
  begin
    if TryStrToFloat(KgQty1.Text,FReal)=False then
    begin
      Application.MessageBox('公斤数非法数字!','提示',0);
      Exit;
    end;
  end;
  if Trim(MQty1.Text)<>'' then
  begin
    if TryStrToFloat(MQty1.Text,FReal)=False then
    begin
      Application.MessageBox('米数非法数字!','提示',0);
      Exit;
    end;
  end;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('RCGangNo').Value:=Trim(RCGangNo1.Text);
    if Trim(MQty1.Text)<>'' then
      FieldByName('MQty').Value:=Trim(MQty1.Text)
    else
      FieldByName('MQty').Value:=Null;
    if Trim(KgQty1.Text)<>'' then
      FieldByName('KgQty').Value:=Trim(KgQty1.Text)
    else
      FieldByName('KgQty').Value:=Null;
    FieldByName('Laster').Value:=Trim(DName);
    Post;
  end;
  Panel4.Visible:=False;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty then exit;
  try
    ADOCmd.Connection.BeginTrans;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      Edit;
      FieldByName('RCGangNo').Value:=ClientDataSet1.fieldbyname('RCGangNo').Value;
      FieldByName('KgQty').Value:=ClientDataSet1.fieldbyname('KgQty').Value;
      FieldByName('MQty').Value:=ClientDataSet1.fieldbyname('MQty').Value;
      FieldByName('Editer').Value:=Trim(DName);
      FieldByName('EditerCode').Value:=Trim(DCode);
      FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Update_LLRK_Qty :MYID');
      Parameters.ParamByName('MYID').Value:=Trim(ClientDataSet1.fieldbyname('MYID').AsString);
      ExecSQL;
    end;
    ADOCmd.Connection.CommitTrans;
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(ClientDataSet1.fieldbyname('MYID').AsString)+'''');
      Open;
    end;
    SCSHDataNew(ADOTemp,Panel2,2);
    GetHZData();
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据更新失败!','提示',0);
    Exit;
  end;

end;

procedure TfrmLLRKMXInPut_WJG.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
        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(' insert into CK_MYSC_CR_MX_Log  ');
            sql.Add(' select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            sql.Add(' UPdate CK_MYSC_CR_MX_Log Set DelTime=getdate(),DelerCode='''+Trim(DCode)+''',Deler='''+Trim(DName)+'''');
            sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            sql.Add(' Delete CK_MYSC_CR_MX  where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            ExecSQL;
          end;
        end;

        ClientDataSet1.Delete;
      end;
    end;
    ClientDataSet1.EnableControls;
    if Trim(FMainId)<>'' then
    begin
      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();
    end;
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmLLRKMXInPut_WJG.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 TfrmLLRKMXInPut_WJG.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ModalResult:=1;
end;

procedure TfrmLLRKMXInPut_WJG.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 TfrmLLRKMXInPut_WJG.Button1Click(Sender: TObject);
var
  FFMXID:string;
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 ClientDataSet1.Locate('SSel',True,[]) 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(RCGangNO1.Text)+'''');
            sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Edit;
        FieldByName('SSel').Value:=false;
        FieldByName('RCGangNo').Value:=Trim(RCGangNO1.Text);
      end;
    end;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.CommitTrans;
    FSaveFlag:='99';
    TBSave.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;

procedure TfrmLLRKMXInPut_WJG.BtnMClick(Sender: TObject);
var
  FReal:Double;
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;
  with ClientDataSet1 do
  begin
    Append;
    FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
    FieldByName('MQty').Value:=Trim(QtyLRM.Text);
    Post;
  end;
  QtyLRM.Text:='';
  GetHZData();
end;

procedure TfrmLLRKMXInPut_WJG.BtnKgClick(Sender: TObject);
var
  FReal:Double;
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;
  with ClientDataSet1 do
  begin
    Append;
    FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
    FieldByName('KgQty').Value:=Trim(QtyLRKg.Text);
    if Trim(UnitM.Text)<>'' then
    begin
      FieldByName('MQty').Value:=Trim(QtyLRM.Text);
    end;
    Post;
  end;
  QtyLRM.Text:='';
  QtyLRKg.Text:='';
  if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
  GetHZData();
end;

procedure TfrmLLRKMXInPut_WJG.Button3Click(Sender: TObject);
begin
  Panel5.Visible:=True;
end;

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

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

end.
