unit U_LLRKInPutMH_MCG;

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_MCG = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    TBSave: TToolButton;
    Label26: TLabel;
    Label19: TLabel;
    labMYType: TLabel;
    Panel16: TPanel;
    ImageList1: TImageList;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuery2: TADOQuery;
    Panel4: TPanel;
    Label13: TLabel;
    Label27: TLabel;
    CRTime: TDateTimePicker;
    KHName: TBtnEditA;
    KHNo: TEdit;
    ADOQueryTemp: TADOQuery;
    Label22: TLabel;
    Label53: TLabel;
    MYCode: TEdit;
    MYName: TBtnEditA;
    CGName: TComboBox;
    Label24: TLabel;
    GFOrderNo: TEdit;
    Label33: TLabel;
    JCDanWei: TBtnEditA;
    JCNo: TEdit;
    Label12: TLabel;
    Label16: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    MYKZ: TEdit;
    MYMF: TBtnEditA;
    Label43: TLabel;
    Label3: TLabel;
    MDMFlag: TCheckBox;
    MDKGFlag: TCheckBox;
    HSFlag: TCheckBox;
    BHSFlag: TCheckBox;
    MYMDPrice: TEdit;
    Label32: TLabel;
    Label45: TLabel;
    Label2: TLabel;
    Label10: TLabel;
    Label28: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    MDJChang: TEdit;
    MYMDMoney: TEdit;
    Label4: TLabel;
    Label1: TLabel;
    Note: TEdit;
    RKNO: TEdit;
    ToolButton1: TToolButton;
    Label5: TLabel;
    PMHH: TEdit;
    Button1: TButton;
    AddQty: TEdit;
    Label6: TLabel;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure KHNameBtnClick(Sender: TObject);
    procedure QtyChange(Sender: TObject);
    procedure MDMFlagClick(Sender: TObject);
    procedure MDKGFlagClick(Sender: TObject);
    procedure MYNameBtnClick(Sender: TObject);
    procedure JCDanWeiBtnClick(Sender: TObject);
    procedure MYMDPriceChange(Sender: TObject);
    procedure HSFlagClick(Sender: TObject);
    procedure BHSFlagClick(Sender: TObject);
    procedure MDJChangChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure MYMFBtnClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FSaveFlag: string;
    procedure InitData();
    function SaveData(): Boolean;
    function YFData(FM: string): Boolean;
    { Private declarations }
  public
    canshu1: string;
    PState, CopyInt: Integer;
    FMainId, FSubid, FCGSID: string;
    FRead: string;
    FMYType, FMYTypeFlag, FML, SJLX: string;
    { Public declarations }
  end;

var
  frmLLRKInPutMH_MCG: TfrmLLRKInPutMH_MCG;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_RTFun, U_GYSList, U_BPZdy_LRM, U_CGCX, U_MCP;

{$R *.dfm}
function TfrmLLRKInPutMH_MCG.YFData(FM: string): 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(' where YFTypeId=''' + Trim(FM) + '''');
//    ShowMessage(sql.text);
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd, YFID, 'MH', '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;
      if MDMFlag.Checked = True then
      begin
        FieldByName('SCQty').Value := StrToFloat(Qty.Text);
      end
      else
      begin
        FieldByName('SCQty').Value := StrToFloat(KgQty.Text);
      end;
      FieldByName('SCPS').Value := StrToFloat(PS.Text);
    end
    else
      Edit;
    FieldByName('YFID').Value := Trim(YFID);
    FieldByName('YFTypeId').Value := Trim(FM);
    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 := StrToFloat(Qty.Text);
      FieldByName('SJQty').Value := StrToFloat(Qty.Text);
      FieldByName('QtyUnit').Value := 'M';
    end
    else
    begin
      FieldByName('Qty').Value := StrToFloat(KgQty.Text);
      FieldByName('SJQty').Value := StrToFloat(KgQty.Text);
      FieldByName('QtyUnit').Value := 'KG';
    end;
    FieldByName('PS').Value := StrToFloat(PS.Text);
    FieldByName('YFType').Value := '自动生成';
    FieldByName('Price').Value := StrToFloat(MYMDPrice.Text);
    if HSFlag.Checked = true then
    begin
      FieldByName('HanShui').Value := '含税';
    end
    else
    begin
      FieldByName('HanShui').Value := '不含税';
    end;
    FieldByName('CKNO').Value := trim(FMainid);
    FieldByName('MiQty').Value := StrToFloat(Qty.Text);
    FieldByName('KGQty').Value := StrToFloat(KgQty.Text);
    FieldByName('money').Value := StrToFloat(MYMDMoney.Text);
    FieldByName('JSmoney').Value := StrToFloat(MYMDMoney.Text);
    FieldByName('HSmoney').Value := StrToFloat(MYMDMoney.Text);
    FieldByName('P_CodeName').Value := MYName.Text;
    FieldByName('YFName').Value := '棉采购';
    FieldByName('P_MF').Value := MYMF.Text;
    FieldByName('P_KZ').Value := MYKZ.Text;
    FieldByName('P_Code').Value := MYCode.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_MCG.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmLLRKInPutMH_MCG.InitData();
var
  maxmxno: string;
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select * ');
    sql.Add(' from CK_MYSC_CR   ');
    sql.Add(' where RKNo=''' + Trim(FMainId) + '''');
    sql.Add(' and MYID=''' + Trim(FSubid) + '''');
    Open;
  end;
  if ADOQuery1.IsEmpty = false then
  begin
    SCSHDataNew(ADOQuery1, Panel4, 2);
  end
  else
  begin
    CRTime.Date := SGetServerDate(ADOTemp);
    labMYType.Caption := FMYType;
  end;
  if TBSave.Visible = False then
  begin
    initBtnColor(Panel4, clMenu);
  end;
  if PState = 2 then
  begin
    FSubid := '';
    FMainid := '';
    PS.Text := '';
    MDJChang.Text := '';
    KgQty.Text := '';
    Qty.Text := '';
    MYMDMoney.Text := '';
    MYMDPrice.Text := '';
  end;
  if RKNo.Text = '' then
  begin
    if GetLSNo(ADOCmd, maxmxno, 'RN', 'CK_MYSC_CR', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    RKNo.Text := Trim(maxmxno);
  end;
end;

procedure TfrmLLRKInPutMH_MCG.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_MCG.SaveData(): Boolean;
var
  maxno, maxmxno, maxnoflag, fsj, FMXID: string;
begin
  Result := False;
  if RKNo.Text = '' then
  begin
    if GetLSNo(ADOCmd, maxmxno, 'RN', 'CK_MYSC_CR', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    RKNo.Text := Trim(maxmxno);
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FSubid) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'MH', 'CK_MYSC_CR', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      maxno := Trim(FSubid);
    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('Filler').Value := Trim(DName);
        FieldByName('FillerCode').Value := Trim(DCode);
      end
      else
      begin
        edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditerCode').Value := Trim(DCode);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      RTSetsavedata(ADOCmd, 'CK_MYSC_CR', Panel4, 2);
      FieldByName('MYId').Value := Trim(maxno);
      FieldByName('CRType').Value := '采购入库';
      if Trim(FCGSID) <> '' then
      begin
        FieldByName('CGSID').Value := Trim(FCGSID);
      end;
      FieldByName('CRFlag').Value := '入库';
      FieldByName('CRQtyFlag').Value := 1;
      FieldByName('MYType').Value := Trim(FMYType);
      FieldByName('MYTypeFlag').Value := Trim(FMYTypeFlag);
      if Trim(SJLX) = '新' then
        FieldByName('SJLX').Value := '新';
      if Trim(SJLX) = '旧' then
        FieldByName('SJLX').Value := '旧';
      Post;
    end;
    FMainId := Trim(maxno);
    with ADOCmd do
    begin
      close;
      sql.Clear;
      SQL.Add('update M_ZDY set BPPrice=''' + trim(MYMDPrice.Text) + ''' ');
      if HSFlag.Checked = false then
        sql.Add(',IFHS=''不含税''')
      else
        sql.Add(',IFHS=''含税''');
      sql.Add(' where BPCode=''' + trim(MYCode.Text) + '''');
      sql.Add(' and BPName=''' + trim(MYName.Text) + '''');
      ExecSQL;
    end;
    YFData(maxno);
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmLLRKInPutMH_MCG.TBSaveClick(Sender: TObject);
var
  FReal: Double;
  FInt: Integer;
begin
  ToolBar1.SetFocus;
  if Trim(MYName.Text) = '' then
  begin
    Application.MessageBox('品名不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(KHName.Text) = '' then
  begin
    Application.MessageBox('供应商商不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(MYCode.Text) = '' then
  begin
    Application.MessageBox('编号不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(MYMDPrice.Text) = '' then
  begin
    if Application.MessageBox('单价为空是否继续', '提示', 1) = 2 then
      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_MCG.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ModalResult := 1;
end;

procedure TfrmLLRKInPutMH_MCG.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_MCG.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));
end;

procedure TfrmLLRKInPutMH_MCG.MDMFlagClick(Sender: TObject);
begin
  if MDMFlag.Checked = true then
  begin
    if MDKGFlag.Checked = true then
      MDKGFlag.Checked := false;
    KgQty.ReadOnly := True;
    KgQty.Color := clMenu;
  end
  else
  begin
    if MDKGFlag.Checked = false then
      MDKGFlag.Checked := true;
    KgQty.ReadOnly := false;
    KgQty.Color := clWindow;
  end;
  if MDMFlag.Checked = true then
  begin
    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));
  end;
end;

procedure TfrmLLRKInPutMH_MCG.MDKGFlagClick(Sender: TObject);
begin
  if MDKGFlag.Checked = true then
  begin
    if MDMFlag.Checked = true then
      MDMFlag.Checked := false;
    KgQty.ReadOnly := false;
    KgQty.Color := clWindow;
  end
  else
  begin
    if MDMFlag.Checked = false then
      MDMFlag.Checked := true;
    KgQty.ReadOnly := True;
    KgQty.Color := clMenu;
  end;
  if MDMFlag.Checked = true then
  begin
    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));
  end;
end;

procedure TfrmLLRKInPutMH_MCG.MYNameBtnClick(Sender: TObject);
begin
  if Trim(SJLX) = '旧' then
  begin
    frmBPZDY_LRM := TfrmBPZDY_LRM.create(self);
    with frmBPZDY_LRM do
    begin
      flag := 'MName';
      flagName := '棉';
      ViewFlag := true;
      Panel4.Align := alClient;
      ToolBar3.Visible := false;
      Button1.Visible := False;
      if ShowModal = 1 then
      begin
        MYName.text := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
        MYCode.text := Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
        MYMF.text := Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
        MYKZ.text := Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
        Self.PMHH.text := Trim(ClientDataSet1.fieldbyname('PMHH').AsString);
        MYMDPrice.text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
        Note.text := Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
        MDJChang.SetFocus;
      end;
      free;
    end;
  end
  else if Trim(SJLX) = '新' then
  begin
    frmMCP := TfrmMCP.create(self);
    with frmMCP do
    begin
      flag := 'MName';
      flagName := '棉';
      ViewFlag := true;
      Panel4.Align := alClient;
      ToolBar3.Visible := false;
      ToolBar2.Enabled := false;
      Button1.Visible := False;
      if ShowModal = 1 then
      begin
        MYName.text := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
        MYCode.text := Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
        MYMF.text := Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
        MYKZ.text := Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
        Self.PMHH.text := Trim(ClientDataSet1.fieldbyname('PMHH').AsString);
        MYMDPrice.text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
        Note.text := Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          sql.Add(' select B.KHName,B.KHNo from M_Tree A INNER JOIN KH_Main B on A.CPName =B.KHNameJC where CPID =(');
          sql.Add(' select CPParent from M_Tree where CPID =(select CPID from M_ZDY where BPID =''' + Trim(ClientDataSet1.fieldbyname('BPID').AsString) + '''');
          sql.Add(' ))');
          open;
        end;
        Self.KHName.Text := Trim(ADOTemp.fieldbyname('KHName').AsString);
        Self.KHNo.Text := Trim(ADOTemp.fieldbyname('KHNo').AsString);
        MDJChang.SetFocus;
      end;
      free;
    end;
  end;

end;

procedure TfrmLLRKInPutMH_MCG.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_MCG.MYMDPriceChange(Sender: TObject);
begin
  if MDMFlag.Checked = true then
  begin
    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));
  end;
end;

procedure TfrmLLRKInPutMH_MCG.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_MCG.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_MCG.MDJChangChange(Sender: TObject);
begin
  KgQty.Text := FormatFloat('0.00', strtofloatdef(MYKZ.text, 0) * strtofloatdef(MYMF.text, 0) * strtofloatdef(MDJChang.text, 0) * strtofloatdef(PS.text, 0) / 100000);
  Qty.Text := FloatToStr(strtofloatdef(MDJChang.text, 0) * strtofloatdef(PS.text, 0) + strtofloatdef(AddQty.text, 0));
end;

procedure TfrmLLRKInPutMH_MCG.Tv1DblClick(Sender: TObject);
begin
  if TBSave.Visible = False then
  begin
    ModalResult := 1;
  end;
end;

procedure TfrmLLRKInPutMH_MCG.MYMFBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag := 'MMYKZ';
    flagName := '克重';
    V1Name.Caption := '克重';
    //MainType:=Trim(KHName.Text);
    if ShowModal = 1 then
    begin
      MYMF.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      KgQty.Text := FormatFloat('0.0', strtofloatdef(MYKZ.text, 0) * strtofloatdef(MYMF.text, 0) * strtofloatdef(MDJChang.text, 0) * strtofloatdef(PS.text, 0) / 100000);
      MYMDMoney.Text := FloatToStr(strtofloatdef(MYMDPrice.text, 0) * strtofloatdef(KgQty.text, 0));
    end;
    free;
  end;
end;

procedure TfrmLLRKInPutMH_MCG.ToolButton1Click(Sender: TObject);
begin
  try
    frmCGCX := TfrmCGCX.Create(Application);
    with frmCGCX do
    begin
      ToolButton3.Visible := false;
      ToolButton1.Visible := false;
      ToolButton2.Visible := false;
      if ShowModal = 1 then
      begin
//        self.KHName.Text := frmCGCX.Order_Main.fieldbyname('GYSName').AsString;

        with ADOCmd do
        begin
          close;
          sql.Clear;
          SQL.Add('select KHNo,KHName from KH_Main where KHNameJC =''' + Trim(frmCGCX.Order_Main.fieldbyname('GYSName').AsString) + ''' ');
          open;
        end;
        self.KHNo.Text := Trim(ADOCmd.fieldbyname('KHNo').AsString);
        self.KHName.Text := Trim(ADOCmd.fieldbyname('KHName').AsString);
        self.MYName.Text := frmCGCX.CDS_Sub.fieldbyname('CPName').AsString;
        self.MYKZ.Text := frmCGCX.CDS_Sub.fieldbyname('KZ').AsString;
        self.MYMF.Text := frmCGCX.CDS_Sub.fieldbyname('MF').AsString;
        self.PS.Text := frmCGCX.CDS_Sub.fieldbyname('PS').AsString;
        self.MDJChang.Text := frmCGCX.CDS_Sub.fieldbyname('pichang').AsString;
        self.Qty.Text := frmCGCX.CDS_Sub.fieldbyname('Qty').AsString;
        Self.FCGSID := frmCGCX.CDS_Sub.fieldbyname('CGSID').AsString;
        with ADOCmd do
        begin
          close;
          sql.Clear;
          SQL.Add('select BPCode from M_ZDY where BPName =''' + trim(self.MYName.Text) + ''' ');
          open;
        end;
        self.MYCode.Text := Trim(ADOCmd.fieldbyname('BPCode').AsString);
      end;
    end;
  finally
    frmCGCX.Free;
  end;
end;

procedure TfrmLLRKInPutMH_MCG.Button1Click(Sender: TObject);
begin
  MYMDMoney.ReadOnly := false;
end;

end.

