unit U_CPGangNo;

interface

uses
  Windows, Messages, strutils,SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, StdCtrls, cxContainer, cxTextEdit,
  cxCurrencyEdit, BtnEdit, ExtCtrls, ComCtrls, ToolWin, DBClient, ADODB,
  MovePanel, Buttons, Menus, cxLookAndFeelPainters, cxButtons, RM_Common,
  RM_Class, RM_GridReport, RM_System, RM_Dataset, cxCheckBox;

type
  TfrmCPGangNo = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    PHYG: TBtnEditA;
    defstr2: TComboBox;
    Label16: TLabel;
    Label15: TLabel;
    packNo: TcxCurrencyEdit;
    Label14: TLabel;
    Label1: TLabel;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    CDSMJID: TClientDataSet;
    DataSource2: TDataSource;
    SmNO: TEdit;
    ADOQueryTmp: TADOQuery;
    V2Column1: TcxGridDBColumn;
    MovePanel1: TMovePanel;
    Edit2: TEdit;
    Button4: TButton;
    Label2: TLabel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    cxStyle_fontclOlive: TcxStyle;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    Tv3Column1: TcxGridDBColumn;
    ADOQueryTm: TADOQuery;
    DSTm: TDataSource;
    baoNo: TEdit;
    BaoID: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    V2BaoNO: TcxGridDBColumn;
    V2BaoID: TcxGridDBColumn;
    Panel3: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton49: TSpeedButton;
    FileName: TcxButton;
    RMDB_Main: TRMDBDataSet;
    RM2: TRMGridReport;
    cxButton1: TcxButton;
    ComboBox1: TComboBox;
    Label34: TLabel;
    V2Column2: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    Panel4: TPanel;
    ADOQueryPrint: TADOQuery;
    Label6: TLabel;
    BtnEditA1: TBtnEditA;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    CDSTM: TClientDataSet;
    Panel5: TPanel;
    V2MJstr4: TcxGridDBColumn;
    V2OrderNo: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    cxButton2: TcxButton;
    cxButton3: TcxButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);
    procedure SmNOKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure TV2CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure kcKwBtnClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure baoNoClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton49Click(Sender: TObject);
    procedure FileNameClick(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure BtnEditA1BtnClick(Sender: TObject);
    procedure cxButton3Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitMJID();
    function  SaveRK():Boolean;
    Procedure QueryRk();
    Procedure QueryTM();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCPGangNo: TfrmCPGangNo;

implementation
uses
  U_DataLink,U_Fun, U_ZDYHelp, U_OrderSelRK;
{$R *.dfm}
Procedure TfrmCPGangNo.QueryTm();
var
  FBaoID:string;
begin
  with ADOQueryTM do
  begin
    close;
    sql.Clear;
    sql.Add('select A.*,B.PrtColor,C.MPrtCodeName');
    sql.Add('from WFB_MJJY A   ');
    sql.Add('inner join JYOrder_sub B on B.subID=A.subID ');
    sql.Add('inner join JYOrder_main C on C.mainID=A.MainID ');
    sql.Add('and  A.mjstr2=''未入库'' and isnull(A.BaoID,'''')='''' and C.orderNo='+quotedstr(trim(BtnEditA1.Text)));
    open;
  end;
  SCreateCDS20(ADOQueryTM,CDSTM);
  SInitCDSData20(ADOQueryTM,CDSTM);

  IF not CDSTM.IsEmpty then
  begin
    with ADOQuery1 do
    begin
      close;
      sql.clear;
      sql.add('select isnull(max(cast(baoNo as int)),0)+1 as MaxBaoNo from WFB_MJJY ');
      sql.Add('where mainID='+quotedstr(trim(CDSTM.fieldbyname('MainID').AsString)));
      open;
    end;
    baoNo.text:=ADOQuery1.fieldbyname('MaxBaoNo').AsString;
    if GetLSNo(ADOQueryTmp,FBaoID,'BI','WFB_MJJY',3,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取包条码最大号失败！','提示',0);
      Exit;
    end;
    BaoID.Text:=trim(FBaoid);
  end;
end;

Procedure TfrmCPGangNo.QueryRk();
begin
  with ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select A.*,hC_ps=A.AordQty2,JY_ps=(select count(MainID) from WFB_MJJY X where X.APID=A.APID),');
    sql.Add('JY_Qty=(select sum(MJLen) from WFB_MJJY X where X.APID=A.APID), ');
    sql.Add('RK_RollNum=(select sum(SOrdQty1) from CK_BanCP_CR X where X.APID=A.APID and X.CRType=''检验入库''),');
    sql.Add('RK_Qty=(select sum(MJLen) from CK_BanCP_CR X where X.APID=A.APID and X.CRType=''检验入库'') ');
    sql.Add('from JYOrder_sub_anPai A   ');
    SQL.Add('WHERE exists(select MJID from WFB_MJJY X where X.APID=A.APID and X.MJID='+quotedstr(trim(smNO.Text)));
    sql.Add(')');
    open;
  end;
end;

function TfrmCPGangNo.SaveRK():Boolean;
var
  maxno:String;
  CRID:Integer;
  MaxCkNo,MaxCkSubNo:String;
  MhcTime:TdateTime;
begin
  Result:=false;
  ADOQueryCmd.Connection.BeginTrans;

  try
    {with ADOQueryTmp  do
    begin
      Close;
      sql.Clear;
      SQL.add('Update CK_BanCP_CRID Set CRID=CRID+1');
      sql.Add('select * from CK_BanCP_CRID');
      Open;
    end;
    CRID:=ADOQueryTmp.fieldbyname('CRID').AsInteger;
    if GetLSNo(ADOQueryTmp,MaxCkNo,'JR','CK_BanCP_CR',4,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取成品仓库最大号失败！','提示',0);
      Exit;
    end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from CK_BanCP_CR where 1<>1');
            Open;
          end;
          mhcTime:=SGetServerDateTime(ADOQueryTmp);

          with ADOQueryCmd do
          begin
            Append;
            FieldByName('MainId').Value:=Trim(ADOQueryMain.fieldbyname('MainId').AsString);
            FieldByName('SubId').Value:=Trim(ADOQueryMain.fieldbyname('SubId').AsString);
            FieldByName('C_Code').Value:=Trim(ADOQueryMain.fieldbyname('PRTCode').AsString);
            FieldByName('C_CodeName').Value:=Trim(ADOQueryMain.fieldbyname('PRTCodeName').AsString);
            //FieldByName('C_SPec').Value:=Trim(ADOQueryMain.fieldbyname('C_SPec').AsString);
            FieldByName('C_Color').Value:=Trim(ADOQueryMain.fieldbyname('PRTColor').AsString);
            FieldByName('APID').Value:=Trim(ADOQueryMain.fieldbyname('APID').AsString);
            FieldByName('MJID').Value:=Trim(ADOQueryMain.fieldbyname('MJId').AsString);
            FieldByName('mjxh').Value:=Trim(ADOQueryMain.fieldbyname('mjxh').AsString);
            FieldByName('BaoNo').Value:=Trim(BaoNo.Text);
            FieldByName('BaoID').Value:=Trim(BaoID.Text);

            FieldByName('BCID').Value:=Trim(MaxCkNo);
            FieldByName('CRTime').Value:=FormatDateTime('yyyy-MM-dd',mhcTime);
            FieldByName('CRFlag').Value:='入库';
            FieldByName('CRType').Value:='检验入库';
            FieldByName('CRID').Value:=CRID;
            FieldByName('KGQty').Value:=0;
            FieldByName('Qty').Value:=ADOQueryMain.fieldbyname('MJLen').Value;
            FieldByName('RollNum').Value:=1;
            FieldByName('QtyUnit').Value:=ADOQueryMain.fieldbyname('MJTypeOther').Value;
            FieldByName('CPType').Value:=ADOQueryMain.fieldbyname('MJType').Value;
            //FieldByName('Note').Value:=ADOQueryMain.fieldbyname('Note').Value;
            FieldByName('Filler').Value:=Trim(DName);
            FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTmp);
            //fieldbyname('kcKw').Value:=GetKw(ADOQueryTmp,ADOQueryMain.fieldbyname('PRTCodeName').AsString,ADOQueryMain.fieldbyname('PRTColor').AsString);
            Post;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from CK_BanCP_KC where 1<>1');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Append;
            FieldByName('CRID').Value:=CRID;
            FieldByName('BCID').Value:=Trim(MaxCkNo);
            FieldByName('CRTime').Value:=FormatDateTime('yyyy-MM-dd',mhcTime);
            FieldByName('CRType').Value:='检验入库';
            FieldByName('CPType').Value:=ADOQueryMain.fieldbyname('MJType').Value;
            FieldByName('C_Code').Value:=Trim(ADOQueryMain.fieldbyname('PRTCode').AsString);
            FieldByName('C_CodeName').Value:=Trim(ADOQueryMain.fieldbyname('PRTCodeName').AsString);
            //FieldByName('C_SPec').Value:=Trim(ADOQueryMain.fieldbyname('C_SPec').AsString);
            FieldByName('C_Color').Value:=Trim(ADOQueryMain.fieldbyname('PRTColor').AsString);
            FieldByName('BaoNo').Value:=Trim(BaoNo.Text);
            FieldByName('BaoID').Value:=Trim(BaoID.Text);
            FieldByName('MJID').Value:=Trim(ADOQueryMain.fieldbyname('MJID').AsString);
            FieldByName('KCKGQty').Value:=0;
            FieldByName('KCQty').Value:=ADOQueryMain.fieldbyname('MJlen').Value;
            FieldByName('RollNum').Value:=1;
            FieldByName('KCQtyUnit').Value:=ADOQueryMain.fieldbyname('MJTypeOther').Value;
            FieldByName('mjxh').Value:=Trim(ADOQueryMain.fieldbyname('mjxh').AsString);
            //FieldByName('KCNote').Value:=ADOQueryMain.fieldbyname('Note').Value;
            //fieldbyname('kcKw').Value:=GetKw(ADOQueryTmp,ADOQueryMain.fieldbyname('PRTCodeName').AsString,ADOQueryMain.fieldbyname('PRTColor').AsString);
            Post;
          end; }
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update WFB_MJJY Set BaoNo='''+trim(BaoNo.Text)+''',BaoID='''+trim(Baoid.text)+''' where MJID='''+Trim(ADOQueryMain.fieldbyname('MJID').AsString)+'''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=true;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
end;

procedure TfrmCPGangNo.InitGrid();
begin
  with ADOQueryMain do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,B.*,C.MprtCodeName from WFB_MJJY A ');
    sql.add('inner join JYOrder_Sub B on B.SubId=A.SubId');
    sql.add('inner join JYOrder_Main C on C.maiNID=A.mainID');
    SQL.Add('where 1=2 ');
    Open;
  end;
  SCreateCDS20(ADOQueryMain,CDSMJID);
  SInitCDSData20(ADOQueryMain,CDSMJID);
end;

procedure TfrmCPGangNo.InitMJID();
begin
  MovePanel1.Visible:=false;
  with ADOQueryMain do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,B.*,C.MprtCodeName,C.OrderNo as OrderNoM from WFB_MJJY A ');
    sql.add('inner join JYOrder_Sub B on B.SubId=A.SubId');
    sql.add('inner join JYOrder_Main C on C.maiNID=A.mainID');
    sql.Add('where MJID='+quotedstr(trim(SmNO.Text)));
    Open;
    if not IsEmpty  then
    begin
      IF not CDSMJID.IsEmpty then
      begin
        IF not CDSMJID.Locate('OrderNo',trim(ADOQueryMain.fieldbyname('OrderNoM').AsString),[]) then
        begin
          MovePanel1.Visible:=true;
          Edit2.Text:=SmNO.Text;
          Label2.Caption:='订单号不相同';
          exit;
        end;
      end;
      IF trim(Fieldbyname('MJstr2').AsString)='已入库' then
      begin
        CDSMJID.Append;
        CDSMJID.FieldByName('SDefNote').Value:='此条码已入库';
        CDSMJID.FieldByName('MJID').Value:=trim(SmNO.Text);
        CDSMJID.Post;
      end
      else
      IF trim(Fieldbyname('MJstr2').AsString)='已出库' then
      begin
        CDSMJID.Append;
        CDSMJID.FieldByName('SDefNote').Value:='此条码已出库';
        CDSMJID.FieldByName('MJID').Value:=trim(SmNO.Text);
        CDSMJID.Post;
      end
      else
      begin
        IF CDSMJID.Locate('MJID',trim(ADOQueryMain.Fieldbyname('MJID').AsString),[]) then
        begin
          CDSMJID.Append;
          CDSMJID.FieldByName('SDefNote').Value:='此条码已扫描';
          CDSMJID.FieldByName('MJID').Value:=trim(SmNO.Text);
          CDSMJID.Post;
        end
        else
        begin
           CDSMJID.Append;
            CDSMJID.FieldByName('SDefNote').Value:='扫描成功';
            CDSMJID.FieldByName('MJID').Value:=trim(ADOQueryMain.Fieldbyname('MJID').AsString);
//            CDSMJID.FieldByName('CRID').Value:=trim(ADOQueryMain.Fieldbyname('CRID').AsString);
            CDSMJID.FieldByName('orderNo').Value:=trim(ADOQueryMain.Fieldbyname('OrderNoM').AsString);
            CDSMJID.FieldByName('PRTCodeName').Value:=trim(ADOQueryMain.Fieldbyname('PRTCodeName').AsString);
            CDSMJID.FieldByName('MPRTCodeName').Value:=trim(ADOQueryMain.Fieldbyname('MPRTCodeName').AsString);
            CDSMJID.FieldByName('PRTColor').Value:=trim(ADOQueryMain.Fieldbyname('PRTColor').AsString);
            CDSMJID.FieldByName('MJType').Value:=trim(ADOQueryMain.Fieldbyname('MJType').AsString);
            CDSMJID.FieldByName('Mjstr4').Value:=trim(ADOQueryMain.Fieldbyname('Mjstr4').AsString);
           // CDSMJID.FieldByName('BaoNo').Value:=trim(BaoNo.Text);
           // CDSMJID.FieldByName('BaoID').Value:=trim(BaoID.Text);
            CDSMJID.FieldByName('SOrdQty1').Value:=1;
            CDSMJID.FieldByName('MJLen').Value:=ADOQueryMain.Fieldbyname('MJLen').AsFloat;
            CDSMJID.FieldByName('MJMaoZ').Value:=ADOQueryMain.Fieldbyname('MJMaoZ').AsFloat;
            CDSMJID.FieldByName('MJQty3').Value:=ADOQueryMain.Fieldbyname('MJQty3').AsFloat;
            CDSMJID.FieldByName('MJQty4').Value:=ADOQueryMain.Fieldbyname('MJQty4').AsFloat;
            CDSMJID.FieldByName('MJTypeOther').Value:=trim(ADOQueryMain.Fieldbyname('MJTypeOther').AsString);
            CDSMJID.FieldByName('mainID').Value:=trim(ADOQueryMain.Fieldbyname('mainID').AsString);
            CDSMJID.FieldByName('subID').Value:=trim(ADOQueryMain.Fieldbyname('subID').AsString);
            CDSMJID.Post;
         end;
      {  IF saveRk() then
        begin
            CDSMJID.Append;
            CDSMJID.FieldByName('SDefNote').Value:='打包成功';
            CDSMJID.FieldByName('MJID').Value:=trim(ADOQueryMain.Fieldbyname('MJID').AsString);
//            CDSMJID.FieldByName('CRID').Value:=trim(ADOQueryMain.Fieldbyname('CRID').AsString);
            CDSMJID.FieldByName('PRTCodeName').Value:=trim(ADOQueryMain.Fieldbyname('PRTCodeName').AsString);
            CDSMJID.FieldByName('MPRTCodeName').Value:=trim(ADOQueryMain.Fieldbyname('MPRTCodeName').AsString);
            CDSMJID.FieldByName('PRTColor').Value:=trim(ADOQueryMain.Fieldbyname('PRTColor').AsString);
            CDSMJID.FieldByName('MJType').Value:=trim(ADOQueryMain.Fieldbyname('MJType').AsString);
            CDSMJID.FieldByName('BaoNo').Value:=trim(BaoNo.Text);
            CDSMJID.FieldByName('BaoID').Value:=trim(BaoID.Text);
            CDSMJID.FieldByName('SOrdQty1').Value:=1;
            CDSMJID.FieldByName('MJLen').Value:=ADOQueryMain.Fieldbyname('MJLen').AsFloat;
            CDSMJID.FieldByName('MJMaoZ').Value:=ADOQueryMain.Fieldbyname('MJMaoZ').AsFloat;
            CDSMJID.FieldByName('MJQty3').Value:=ADOQueryMain.Fieldbyname('MJQty3').AsFloat;
            CDSMJID.FieldByName('MJQty4').Value:=ADOQueryMain.Fieldbyname('MJQty4').AsFloat;
            CDSMJID.FieldByName('MJTypeOther').Value:=trim(ADOQueryMain.Fieldbyname('MJTypeOther').AsString);
            CDSMJID.FieldByName('mainID').Value:=trim(ADOQueryMain.Fieldbyname('mainID').AsString);
            CDSMJID.FieldByName('subID').Value:=trim(ADOQueryMain.Fieldbyname('subID').AsString);
            CDSMJID.Post;
            //QueryRk();
            QueryTm();
        end
        else
        begin
          CDSMJID.Append;
          CDSMJID.FieldByName('SDefNote').Value:='此条码打包失败';
          CDSMJID.FieldByName('MJID').Value:=trim(SmNO.Text);
          CDSMJID.Post;
        end; }
      end;
    end
    else
    begin
      CDSMJID.Append;
      CDSMJID.FieldByName('SDefNote').Value:='此条码不存在';
      CDSMJID.FieldByName('MJID').Value:=trim(SmNO.Text);
      CDSMJID.Post;
    end;
  end;
  IF trim(CDSMJID.FieldByName('SDefNote').AsString)<>'扫描成功' then
  begin
    MovePanel1.Visible:=true;
    Edit2.Text:=SmNO.Text;
    Label2.Caption:=trim(CDSMJID.FieldByName('SDefNote').AsString);
    CDSMJID.Delete;
  end;
end;

procedure TfrmCPGangNo.FormDestroy(Sender: TObject);
begin
  frmCPGangNo:=nil;
end;

procedure TfrmCPGangNo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  //writeCxGrid(self.Caption+tv1.Name,Tv1,'成品仓库');
  writeCxGrid(self.Caption+Tv2.Name,Tv2,'成品仓库');
  writeCxGrid(self.Caption+Tv3.Name,Tv3,'成品仓库');
  Action:=cafree;
end;

procedure TfrmCPGangNo.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmCPGangNo.FormCreate(Sender: TObject);
begin
  Panel2.Align:=alClient;
  //readCxGrid(self.Caption+tv1.Name,Tv1,'成品仓库');
  readCxGrid(self.Caption+Tv2.Name,Tv2,'成品仓库');
  readCxGrid(self.Caption+Tv3.Name,Tv3,'成品仓库');
end;

procedure TfrmCPGangNo.SmNOKeyPress(Sender: TObject; var Key: Char);
begin
  IF key=#13 then
  begin
    if trim(smno.Text)='' then exit;
    initMJID();
    smno.Text:='';
    smno.SetFocus;
    tv2.Controller.EditingController.ShowEdit();
  end;
end;

procedure TfrmCPGangNo.FormShow(Sender: TObject);
begin
  MovePanel1.Left:=(Width-MovePanel1.Width) div 2;
  MovePanel1.top:=(Height-MovePanel1.Height-200) div 2;
  InitGrid();
end;

procedure TfrmCPGangNo.TV2CustomDrawCell(Sender: TcxCustomGridTableView;
  ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
  var ADone: Boolean);
var
  i:integer;
begin
{  i:=tv2.GetColumnByFieldName('SDefNote').Index;
  if (AViewInfo.GridRecord.Values[i]<>'打包成功')  then
  ACanvas.Brush.Color:=clred;      }
end;

procedure TfrmCPGangNo.kcKwBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CPKWFlag';
      flagname:='库位信息';
      V1Name.Caption:='库位名称';
      V1Note.Caption:='英文名称';
//      MainType:=Trim(DName);
      fnote:=FALSE;
      if ShowModal=1 then
      begin
      //  kcKw.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCPGangNo.Button4Click(Sender: TObject);
begin
  MovePanel1.Visible:=False;
  SmNO.SetFocus;
end;

procedure TfrmCPGangNo.baoNoClick(Sender: TObject);
var
  i:Integer;
begin
//  Panel3.Visible:=True;
 { with Panel3 do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint:=Trim(TEdit(Sender).Name);
      end;
    end;
  end;   }
end;

procedure TfrmCPGangNo.SpeedButton1Click(Sender: TObject);
var
  fsj:string;
begin
  fsj:=Trim(TSpeedButton(Sender).Hint);
  if Trim(fsj)='' then Exit;
  fsj:=Trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text:=fsj+Trim(TSpeedButton(Sender).Caption);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).SelectAll;
end;

procedure TfrmCPGangNo.SpeedButton12Click(Sender: TObject);
var
  fsj:string;
begin
  fsj:=Trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text);
  if Trim(fsj)='' then Exit;
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text:=Copy(fsj,1,Length(fsj)-1);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).SelectAll;
end;
procedure TfrmCPGangNo.SpeedButton49Click(Sender: TObject);
var
  FBaoID:string;
begin
  IF trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Hint)<>'' then
  begin
    if GetLSNo(ADOQueryTmp,FBaoID,'BI','WFB_MJJY',3,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取包条码最大号失败！','提示',0);
      Exit;
    end;
    BaoID.Text:=trim(FBaoid);
  end;
  Panel3.Visible:=False;
end;

procedure TfrmCPGangNo.FileNameClick(Sender: TObject);
var
  fPrintFile:string;
   Txt,fImagePath:string;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if CDSMJID.IsEmpty then Exit;
  if CDSMJID.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  CDSMJID.DisableControls;
  with CDSMJID do
  begin
    First;
    while not Eof do
    begin
      if FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryPrint do
        begin
          Close;
          SQL.Clear;
          sql.Add('select QtyUnit=A.MJTypeOther,B.orderNo,B.conNo,GangNo=D.AOrddefStr1,PRTColorEng=E.Note,B.LBName ');
          sql.Add(',khConNo=(select top 1 khConNo from JYOrderCon_Main X where X.ConNO=B.conNO) ');
          sql.Add(',MPRTCodeNameEng=ISNULL((select Top 1 F.note from KH_Zdy F where F.zdyname=B.MPRTCodeName and F.Type=''PRTCodeName''),B.MPRTCodeName)');
          sql.Add(',B.MPRTCF,B.MPRTMF,B.MPRTKZ,C.SOrddefstr4,B.MPRTCodeName,B.MPRTSpec,B.MPRTKuanNO,C.*,A.* ');
          sql.Add(',Case when A.MJSJKZ*A.MJFK<>0 then Cast(A.MJQty4*1000/A.MJSJKZ/(A.MJFK/100) as int) else 0 end as MQty');
          sql.Add(' from WFB_MJJY A') ;
          sql.Add(' inner join JYOrder_Main B On A.Mainid=B.Mainid');
          sql.Add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
          sql.Add(' left join KH_Zdy E on C.PRTColor=E.ZdyName and E.Type=''OrdColor'' ');
          sql.Add(' inner join JYOrder_Sub_AnPai D on A.APId=D.APId ');
          SQL.Add(' where A.MJID='''+Trim(CDSMJID.fieldbyname('MJID').AsString)+'''');
          Open;
        end;
        try
          Moudle:=LoadLibrary('MakeQRBarcode.dll');
          @Makebar:=GetProcAddress(Moudle,'Make');
          @Mixtext:=GetProcAddress(Moudle,'MixText');
          Txt:=Trim(ADOQueryPrint.fieldbyname('MJID').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;
        if Trim(ADOQueryPrint.fieldbyname('LbName').AsString)<>'' then
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\'+Trim(ADOQueryPrint.fieldbyname('LbName').AsString)+'.rmf'
        else
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用英文标签.rmf' ;
        if FileExists(fPrintFile) then
        begin
            RMVariables['QRBARCODE']:=fImagePath;
          RM2.LoadFromFile(fPrintFile);
          RM2.ShowReport;
        //  RM2.PrintReport;
        end else
        begin
          CDSMJID.EnableControls;
          Application.MessageBox(PChar('没有找'+fPrintFile),'提示',0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  CDSMJID.EnableControls;
end;

procedure TfrmCPGangNo.cxButton1Click(Sender: TObject);
begin
  TBClose.Click;
end;

procedure TfrmCPGangNo.BtnEditA1BtnClick(Sender: TObject);
begin
    frmOrderSelRK:=TfrmOrderSelRK.Create(Application);
    with frmOrderSelRK do
    begin
      if ShowModal=1 then
      begin
        CDS_OrderSel.DisableControls;
        with CDS_OrderSel do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').Value=True then
            begin
              BtnEditA1.Text:=trim(CDS_OrderSel.fieldbyname('OrderNo').asstring);
            end;
            Next;
          end;
        end;
        CDS_OrderSel.EnableControls;
      end;
    end;
  QueryTm();
end;

procedure TfrmCPGangNo.cxButton3Click(Sender: TObject);
begin
  IF CDSMJID.IsEmpty then exit;
  CDSMJID.Delete;
end;

procedure TfrmCPGangNo.cxButton2Click(Sender: TObject);
begin
  IF CDSMJID.IsEmpty then exit;
  ADOQueryCmd.Connection.BeginTrans;
  try
    with  CDSMJID do
    begin
      DisableControls;
      first;
      while not eof do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update WFB_MJJY Set MJstr4='''+trim(BaoNo.Text)+''' where  MJID='''+Trim(CDSMJID.fieldbyname('MJID').AsString)+'''');
          ExecSQL;
        end;
        edit;
        fieldbyname('MJstr4').Value:=trim(BaoNo.Text);
        post;
        next;
      end;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('数据修改成功！','提示信息',0);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('数据修改失败！','提示信息',0);
  end;
end;

end.
