unit U_LLRKInPutMH_PBKCCG;

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_PBKCCG = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label21: TLabel;
    Label19: TLabel;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    Panel3: TPanel;
    labMYType: TLabel;
    Panel4: TPanel;
    Label13: TLabel;
    CRTime: TDateTimePicker;
    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;
    Panel6: TPanel;
    Panel8: TPanel;
    Button1: TButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    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;
    v1MXMoney: TcxGridDBColumn;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N3: TMenuItem;
    MenuItem2: TMenuItem;
    N4: TMenuItem;
    ImageList1: TImageList;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    Panel10: TPanel;
    Button10: TButton;
    Label41: TLabel;
    Label42: TLabel;
    KgQtyAvg: TEdit;
    QtyAvg: TEdit;
    Label39: TLabel;
    RCGangNo1: TEdit;
    Label40: TLabel;
    JH: TEdit;
    ADOQuery2: TADOQuery;
    Label44: TLabel;
    Label45: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Panel15: TPanel;
    Label22: TLabel;
    MYCode: TEdit;
    MYName: TBtnEditA;
    Label1: TLabel;
    Note: TEdit;
    v1MXNote: TcxGridDBColumn;
    Label33: TLabel;
    JCDanWei: TBtnEditA;
    JCNo: TEdit;
    Panel2: TPanel;
    Label6: TLabel;
    KCNote: TEdit;
    ToolButton1: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure Image1DblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BtnDelClick(Sender: TObject);
    procedure BtnPrtClick(Sender: TObject);
    procedure BtnQXClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure JCDanWeiBtnClick(Sender: TObject);
    procedure RCGangNo1Change(Sender: TObject);
    procedure PSChaEChange(Sender: TObject);
    procedure QtyChaEChange(Sender: TObject);
    procedure KgQtyChaEChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    lstPat:TStringList;
    FangXiang1,FSaveFlag:String;
    procedure InitData();
    procedure SaveImage(maxnoWB:String);
    procedure ReadINIFile10();
    function  SaveData():Boolean;
    procedure InitColor();
    function SaveDataMX():Boolean;
    procedure InitMXData();
    procedure Initimage();
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FMYType,FMYTypeFlag,FML:string;
    { Public declarations }
  end;

var
  frmLLRKInPutMH_PBKCCG: TfrmLLRKInPutMH_PBKCCG;
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;

{$R *.dfm}

procedure TfrmLLRKInPutMH_PBKCCG.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('坯布采购入库11',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmLLRKInPutMH_PBKCCG.Initimage();
begin
  
end;

procedure TfrmLLRKInPutMH_PBKCCG.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);
  MYName.text:=Trim(ADOQuery1.fieldbyname('MYName').AsString);
  MYCode.text:=Trim(ADOQuery1.fieldbyname('MYCode').AsString);
  KCNote.Text:=Trim(ADOQuery1.fieldbyname('KCNote').AsString);
  if PState=0 then
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
  end;
  initBtnColor(Panel4,clMenu);
  initBtnColor(Panel5,clMenu);
  InitMXData();
  if StrToFloatdef(Qty.Text,0)=0 then
  begin
    Qty.Visible:=false;
    Label45.Visible:=false;
  end
  else
  begin
    Qty.Visible:=true;
    Label45.Visible:=true;
  end;
  if StrToFloatdef(KgQty.Text,0)=0 then
  begin
    KgQty.Visible:=false;
    Label50.Visible:=false;
  end
  else
  begin
    KgQty.Visible:=true;
    Label50.Visible:=true;
  end;
  if StrToFloatdef(MXHZQty.Text,0)=0 then
  begin
    MXHZQty.Visible:=false;
    label44.Visible:=false;
  end
  else
  begin
    MXHZQty.Visible:=true;
    label44.Visible:=true;
  end;
  if StrToFloatdef(QtyChaE.Text,0)=0 then
  begin
    QtyChaE.Visible:=false;
    label17.Visible:=false;
  end
  else
  begin
    QtyChaE.Visible:=true;
    label17.Visible:=true;
  end;
  if StrToFloatdef(MXHZKgQty.Text,0)=0 then
  begin
    MXHZKgQty.Visible:=false;
    label49.visible:=false;
  end
  else
  begin
    MXHZKgQty.Visible:=true;
    label49.visible:=true;
  end;
  if StrToFloatdef(KgQtyChaE.Text,0)=0 then
  begin
    KgQtyChaE.Visible:=false;
    Label18.Visible:=false;
  end
  else
  begin
    KgQtyChaE.Visible:=true;
    Label18.Visible:=True;
  end;
  if ClientDataSet1.Locate('KGQty',NULL,[])=False then
  begin

  end
  else
  begin
    v1Column17.Visible:=false;
  end;
  if ClientDataSet1.Locate('MQty',NULL,[])=False then
  begin

  end
  else
  begin
    v1Column3.Visible:=false;
  end;
end;

procedure TfrmLLRKInPutMH_PBKCCG.InitMXData();
begin
  with ADOQuery2 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,(case when isnull(A.RCGangNo,'''')='''' then A.GangNo else A.RCGangNo end) RCGangNo1');
    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_PBKCCG.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmLLRKInPutMH_PBKCCG.SaveData():Boolean;
begin
  
end;

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

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

procedure TfrmLLRKInPutMH_PBKCCG.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_PBKCCG.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  ReadCxGrid('坯布采购入库11',Tv1,'贸易生产管理');
end;

procedure TfrmLLRKInPutMH_PBKCCG.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_PBKCCG.Button1Click(Sender: TObject);
begin
  Panel5.Visible:=True;
end;

procedure TfrmLLRKInPutMH_PBKCCG.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;
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmLLRKInPutMH_PBKCCG.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_PBKCCG.BtnQXClick(Sender: TObject);
begin
  Panel5.Visible:=False;
end;

function TfrmLLRKInPutMH_PBKCCG.SaveDataMX():Boolean;
begin

end;

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

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

procedure TfrmLLRKInPutMH_PBKCCG.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_PBKCCG.RCGangNo1Change(Sender: TObject);
begin
  SDofilter(ADOQuery2,SGetFilters(Panel8,1,2));
  SCreateCDS20(ADOQuery2,ClientDataSet1);
  SInitCDSData20(ADOQuery2,ClientDataSet1);
end;

procedure TfrmLLRKInPutMH_PBKCCG.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_PBKCCG.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_PBKCCG.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_PBKCCG.ToolButton1Click(Sender: TObject);
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' update CK_MYSC_CR');
    sql.Add(' set KCNote='''+trim(KCNote.Text)+''' ');
    sql.Add(' where MYID='''+Trim(FMainId)+'''');
    ExecSQL;
  end;
  application.MessageBox('保存成功','提示');
  ModalResult:=1;
end;

end.
