unit U_JGCKInPut;

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, cxGridBandedTableView, cxGridDBBandedTableView,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmJGCKInPut = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    TBSave: TToolButton;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    Label26: TLabel;
    Panel3: TPanel;
    labMYType: TLabel;
    Panel4: TPanel;
    Label13: TLabel;
    CRTime: TDateTimePicker;
    Panel5: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    PS: TEdit;
    Qty: TEdit;
    KgQty: TEdit;
    Panel7: TPanel;
    Panel1: TPanel;
    Label20: TLabel;
    PTID: TEdit;
    Label23: TLabel;
    MYPrice: TEdit;
    Label24: TLabel;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N3: TMenuItem;
    MenuItem2: TMenuItem;
    N4: TMenuItem;
    ImageList1: TImageList;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuery2: TADOQuery;
    Label45: TLabel;
    Label50: TLabel;
    ADOQueryTemp: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label33: TLabel;
    GYSName: TBtnEditA;
    Label22: TLabel;
    MYName: TEdit;
    Label12: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    MYKZ: TEdit;
    MYMF: TEdit;
    Label2: TLabel;
    Label11: TLabel;
    MYHX: TEdit;
    MYColor: TEdit;
    Label4: TLabel;
    MYColorNo: TEdit;
    Label43: TLabel;
    MDMFlag: TCheckBox;
    MDKGFlag: TCheckBox;
    Label1: TLabel;
    Note: TEdit;
    Label3: TLabel;
    ToGYSName: TBtnEditA;
    Panel2: TPanel;
    Panel6: TPanel;
    Label5: TLabel;
    KHNameJC: TBtnEditA;
    Label8: TLabel;
    MLConNo: TEdit;
    Label10: TLabel;
    Label17: TLabel;
    PBBatchNo: TEdit;
    MLOrderNo: TcxButtonEdit;
    Panel8: TPanel;
    Panel9: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column11: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label18: TLabel;
    Label19: TLabel;
    Edit1: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    ToolButton1: TToolButton;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure MDMFlagClick(Sender: TObject);
    procedure MDKGFlagClick(Sender: TObject);
    procedure GYSNameBtnClick(Sender: TObject);
    procedure ToGYSNameBtnClick(Sender: TObject);
    procedure KHNameJCBtnClick(Sender: TObject);
    procedure MLOrderNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitData();
    function  SaveData():Boolean;
    function YFData():Boolean;
    procedure InitDataSel(FFMYID:String);
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FMYType,FMYTypeFlag,FML,FNewMainId,FNewSubid:string;
    { Public declarations }
  end;

var
  frmJGCKInPut: TfrmJGCKInPut;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun, U_GYSList,U_OrderListSel,U_PBCGRKListSel,U_OrderMXSelist,U_JGCKListSel;

{$R *.dfm}
function TfrmJGCKInPut.YFData():Boolean;
var
  CRID,OrdMainId,YFID,FComTaiTou,FCRID,FFactoryName,FFactoryNo:String;
begin
  Result:=False;
  FFactoryName:=Trim(GYSName.Text);
  FFactoryNo:=Trim(GYSName.TxtCode);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YS_Money_KC where FactoryNo='+quotedstr(Trim(FFactoryNo)));
    sql.Add(' and KCType=''GYS'' ');
    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:='GYS';
      Post;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where FactoryNo='+quotedstr(Trim(FFactoryNo)));
    sql.Add(' and YFTypeId='''+Trim(FMainId)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd,YFID,'JG','YS_Money_CR',4,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;
      FieldByName('SCQty').Value:=strtofloatdef(Qty.text,0);
      FieldByName('SCPS').Value:=strtofloatdef(PS.text,0);
    end
    else
    Edit;
    FieldByName('YFID').Value:=Trim(YFID);
    FieldByName('YFTypeId').Value:=Trim(FMainid);
    FieldByName('CRID').Value:=StrToInt(CRID);
    FieldByName('YFName').Value:='加工费';
    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.Date;
    if MDMFlag.Checked=True then
    begin
      FieldByName('Qty').Value:=Strtofloatdef(Qty.text,0);
      FieldByName('QtyUnit').Value:='M';
    end
    else
    begin
      FieldByName('Qty').Value:=Strtofloatdef(KGQty.text,0);
      FieldByName('QtyUnit').Value:='KG';
    end;
    FieldByName('PS').Value:=Strtofloatdef(PS.text,0);
    FieldByName('YFType').Value:='自动生成';
    
    FieldByName('CKNO').Value:=trim(FMainid);
    FieldByName('SJQty').Value:=Strtofloatdef(Qty.text,0);
    FieldByName('MiQty').Value:=Strtofloatdef(Qty.text,0);
    FieldByName('KGQty').Value:=Strtofloatdef(KGQty.text,0);
    FieldByName('P_CodeName').Value:=Trim(MYName.text);
    FieldByName('P_MF').Value:=Trim(MYMF.text);
    FieldByName('P_KZ').Value:=Trim(MYKZ.Text);
    FieldByName('P_Color').Value:=Trim(MYColor.Text);
    FieldByName('P_ColorNo').Value:=Trim(MYColorNo.Text);
    FieldByName('P_HX').Value:=Trim(MYHX.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 TfrmJGCKInPut.TBCloseClick(Sender: TObject);
begin
  Close;
end;


procedure TfrmJGCKInPut.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*,KM.KHNameJC,B.MLConNo,B.MLOrderNo ');
    sql.Add(' from CK_MYSC_CR A  ');
    sql.Add(' left join ML_OrderMainNew B on A.MainId=B.NewMLID');
    sql.Add(' left join KH_Main KM on KM.KHNO=B.KHNO ');
    sql.Add(' where MYID='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel4,2);
  SCSHDataNew(ADOQuery1,Panel5,2);
  SCSHDataNew(ADOQuery1,Panel4,0);
  MDMFlag.Checked:=ADOQuery1.FieldByName('MDMflag').AsBoolean;
  MDKGFlag.Checked:=ADOQuery1.FieldByName('MDKGFlag').AsBoolean;
  FNewMainId:=Trim(ADOQuery1.fieldbyname('MainId').AsString);
  FNewSubid:=Trim(ADOQuery1.fieldbyname('SubId').AsString);
  if PState=0 then
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
  end;
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MYSC_CR_MX where MYID='''+Trim(FMainId)+'''');
    open;
  end;
  SCreateCDS20(ADOQuery1,ClientDataSet1);
  SInitCDSData20(ADOQuery1,ClientDataSet1);
end;
procedure TfrmJGCKInPut.InitDataSel(FFMYID:String);
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*,KM.KHNameJC,B.MLConNo,B.MLOrderNo ');
    sql.Add(' from CK_MYSC_CR A  ');
    sql.Add(' left join ML_OrderMainNew B on A.MainId=B.NewMLID');
    sql.Add(' left join KH_Main KM on KM.KHNO=B.KHNO ');
    sql.Add(' where MYID='''+Trim(FFMYID)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel4,2);
  SCSHDataNew(ADOQuery1,Panel5,2);
  SCSHDataNew(ADOQuery1,Panel4,0);
  MDMFlag.Checked:=ADOQuery1.FieldByName('MDMflag').AsBoolean;
  MDKGFlag.Checked:=ADOQuery1.FieldByName('MDKGFlag').AsBoolean;
  FNewMainId:=Trim(ADOQuery1.fieldbyname('MainId').AsString);
  FNewSubid:=Trim(ADOQuery1.fieldbyname('SubId').AsString);
  CRTime.Date:=SGetServerDate(ADOTemp);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MYSC_CR_MX where MYID='''+Trim(FFMYID)+'''');
    open;
  end;
  SCreateCDS20(ADOQuery1,ClientDataSet1);
  SInitCDSData20(ADOQuery1,ClientDataSet1);
  with ClientDataSet1 do
  begin
    First;
    while not Eof do
    begin
      edit;
      FieldByName('MYID').Value:=Null;
      FieldByName('MXID').Value:=Null;
      Post;
      Next;
    end;
  end;
  ToGYSName.Text:='';ToGYSName.TxtCode:='';
end;




procedure TfrmJGCKInPut.FormShow(Sender: TObject);
begin
  InitData();

end;

function TfrmJGCKInPut.SaveData():Boolean;
var
  maxno,maxmxno,maxnoflag,fsj,FMXID:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'JG','CK_MYSC_CR',4,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end else
    begin
      maxno:=Trim(FMainId);
    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;
      end;
      FieldByName('MYId').Value:=Trim(maxno);
      FieldByName('CRType').Value:='加工码单';
      FieldByName('CRFlag').Value:='入库';
      FieldByName('CRQtyFlag').Value:=1;
      if Trim(FMainId)='' then
      begin

      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditerCode').Value:=Trim(DCode);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      RTSetsavedata(ADOCmd,'CK_MYSC_CR',Panel4,2);
      RTSetsavedata(ADOCmd,'CK_MYSC_CR',Panel5,2);
      FieldByName('MDMflag').Value:=MDMFlag.Checked;
      FieldByName('MDKGflag').Value:=MDKGflag.Checked;
      FieldByName('MYType').Value:='加工费';
      FieldByName('MYTypeFlag').Value:=Trim(FMYTypeFlag);
      FieldByName('MainId').Value:=Trim(FNewMainId);
      FieldByName('SubId').Value:=Trim(FNewSubid);
      Post;
    end;
    FMainId:=Trim(maxno);
    YFData();
    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,'MX','CK_MYSC_CR_MX',4,1)=False then
          begin
            ClientDataSet1.EnableControls;
            Application.MessageBox('取加工码单明细数据最大号失败','提示',0);
            Exit;
          end;
        end else
        begin
          maxmxno:=Trim(FMXID);
        end;
        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
          if Trim(FMXID)='' then
          begin
            Append;
            FieldByName('Filler').Value:=Trim(DName);
          end else
          begin
            Edit;
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
            FieldByName('Editer').Value:=Trim(DName);
          end;
          FieldByName('MYID').Value:=Trim(FMainId);
          FieldByName('MXID').Value:=Trim(maxmxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,ClientDataSet1,'CK_MYSC_CR_MX',0);
          Post;
        end;
        Edit;
        FieldByName('MYID').Value:=Trim(FMainId);
        FieldByName('MXID').Value:=Trim(maxmxno);
        Post;
        Next;
      end;
    end;
    ClientDataSet1.EnableControls;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' UPdate CK_MYSC_CR Set MXHZQty=(select Sum(MQty) from CK_MYSC_CR_MX A where A.MYID=CK_MYSC_CR.MYID) ');
      sql.Add(' ,MXHZKgQty=(select Sum(KgQty) from CK_MYSC_CR_MX A where A.MYID=CK_MYSC_CR.MYID) ');
      sql.Add(' ,MXHZPS=(select Count(*) from CK_MYSC_CR_MX A where A.MYID=CK_MYSC_CR.MYID) ');
      sql.Add(' where MYID='''+Trim(FMainId)+'''');
      sql.Add(' Update CK_MYSC_CR Set QtyChaE=isnull(MXHZQty,0)-isnull(Qty,0),KgQtyChaE=isnull(MXHZKgQty,0)-isnull(KgQty,0),PSChaE=isnull(MXHZPS,0)-isnull(PS,0) ');
      sql.Add(' where MYID='''+Trim(FMainId)+'''');
      ExecSQL;
    end;
    if Trim(ToGYSName.Text)='云翔仓库' then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' UPdate ML_OrderSubidNew Set HCPS=(select sum(PS) from CK_MYSC_CR A where A.SubID=ML_OrderSubidNew.NewSubid) ');
        if MDMFlag.Checked then
        begin
          sql.Add(' ,HCQty=(select sum(Qty) from CK_MYSC_CR A where A.SubID=ML_OrderSubidNew.NewSubid) ');
        end;
        if MDKGFlag.Checked then
        begin
          sql.Add(' ,HCQty=(select sum(KgQty) from CK_MYSC_CR A where A.SubID=ML_OrderSubidNew.NewSubid) ');
        end;
        sql.Add(' where NewSubid='''+Trim(FNewSubid)+'''');
        ExecSQL;
      end;
    end;
    if Trim(FMYType)='染色' then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' exec P_Update_PBKC :PBBatchNo,:JGCNO');
        Parameters.ParamByName('PBBatchNo').Value:=Trim(PBBatchNo.Text);
        Parameters.ParamByName('JGCNO').Value:=Trim(GYSName.TxtCode);
        ExecSQL;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmJGCKInPut.TBSaveClick(Sender: TObject);
var
  FReal:Double;
  FInt:Integer;
begin
  ToolBar1.SetFocus;
  if Trim(GYSName.Text)='' then
  begin
    Application.MessageBox('供应商不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  if (MDMFlag.Checked=False) and (MDKGFlag.Checked=False) then
  begin
    Application.MessageBox('请选择计价方式','提示',0);
    Exit;
  end;
  if MDMFlag.Checked then
  begin
    if Trim(Qty.Text)='' then
    begin
      Application.MessageBox('米数不能为空!','提示',0);
      Exit;
    end;
  end;
  if MDKGFlag.Checked then
  begin
    if Trim(KgQty.Text)='' then
    begin
      Application.MessageBox('公斤数不能为空!','提示',0);
      Exit;
    end;
  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 Trim(PBBatchNo.Text)='' then
  begin
    Application.MessageBox('坯布联系号不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet1.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;





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


procedure TfrmJGCKInPut.MDMFlagClick(Sender: TObject);
begin

  if MDMFlag.Checked=true then
  begin
    if MDKGFlag.Checked=true then
    MDKGFlag.Checked:=false;
  end
  else
  begin
    if MDKGFlag.Checked=false then
    MDKGFlag.Checked:=true;
  end;

end;

procedure TfrmJGCKInPut.MDKGFlagClick(Sender: TObject);
begin
  
  if MDKGFlag.Checked=true then
  begin
    if MDMFlag.Checked=true then
    MDMFlag.Checked:=false;
  end
  else
  begin
    if MDMFlag.Checked=false then
    MDMFlag.Checked:=true;
  end;
end;

procedure TfrmJGCKInPut.GYSNameBtnClick(Sender: TObject);
begin
 { if Trim(FMYType)='染色' then
  begin
    try
      frmPBCGRKListSel:=TfrmPBCGRKListSel.Create(Application);
      with frmPBCGRKListSel do
      begin
        if ShowModal=1 then
        begin
          Self.GYSName.Text:=Trim(frmPBCGRKListSel.Order_Main.fieldbyname('JCDanWeiJC').AsString);
          Self.GYSName.TxtCode:=Trim(frmPBCGRKListSel.Order_Main.fieldbyname('JCKHNo').AsString);
          Self.MYName.Text:=Trim(frmPBCGRKListSel.Order_Main.fieldbyname('MYName').AsString);
          Self.PBBatchNo.Text:=Trim(frmPBCGRKListSel.Order_Main.fieldbyname('PBBatchNo').AsString);
        end;
      end;
    finally
      frmPBCGRKListSel.Free;
    end;
  end else
  begin
    try
      frmGYSList:=TfrmGYSList.Create(Application);
      with frmGYSList do
      begin
        if ShowModal=1 then
        begin
          Self.GYSName.Text:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString);
          Self.GYSName.TxtCode:=Trim(frmGYSList.Order_Main.fieldbyname('KHNo').AsString);
        end;
      end;
    finally
      frmGYSList.Free;
    end;
  end; }

end;

procedure TfrmJGCKInPut.ToGYSNameBtnClick(Sender: TObject);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        Self.ToGYSName.Text:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString);
        Self.ToGYSName.TxtCode:=Trim(frmGYSList.Order_Main.fieldbyname('KHNo').AsString);
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmJGCKInPut.KHNameJCBtnClick(Sender: TObject);
begin
  {try
    frmOrderListSel:=TfrmOrderListSel.Create(Application);
    with frmOrderListSel do
    begin
      if ShowModal=1 then
      begin
        FNewMainId:=Trim(frmOrderListSel.Order_Main.fieldbyname('NewMLID').AsString);
        Self.MLConNo.Text:=Trim(frmOrderListSel.Order_Main.fieldbyname('MLConNo').AsString);
        Self.MLOrderNo.Text:=Trim(frmOrderListSel.Order_Main.fieldbyname('MLOrderNo').AsString);
        Self.KHNameJC.Text:=Trim(frmOrderListSel.Order_Main.fieldbyname('KHNameJC').AsString);
      end;
    end;
  finally
    frmOrderListSel.Free;
  end; }
end;

procedure TfrmJGCKInPut.MLOrderNoPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  {try
    frmOrderMXSelist:=TfrmOrderMXSelist.Create(Application);
    with frmOrderMXSelist do
    begin
      if ShowModal=1 then
      begin
        Self.MLOrderNo.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLOrderNo').AsString);
        Self.MLConNo.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLConNo').AsString);
        Self.MYColor.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLColor').AsString);
        Self.MYColorNo.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLColorNo').AsString);
        Self.MYHX.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLHX').AsString);
        Self.MYHX.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLHX').AsString);
        Self.MYHX.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('MLHX').AsString);
        Self.KHNameJC.Text:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('KHNameJC').AsString);
        Self.FNewMainId:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('NewMLID').AsString);
        Self.FNewSubid:=Trim(frmOrderMXSelist.Order_Main.fieldbyname('NewSubid').AsString);
      end;
    end;
  finally
    frmOrderMXSelist.Free;
  end; }
end;

procedure TfrmJGCKInPut.Edit1KeyPress(Sender: TObject;
  var Key: Char);
var
  Freal:Double;
begin
  if Key=#13 then
  begin
    if Trim(Edit1.Text)<>'' then
    begin
      if TryStrToFloat(Edit1.Text,Freal)=False then
      begin
        Application.MessageBox('明细数量非法数字!','提示',0);
        Exit;
      end;
      with ClientDataSet1 do
      begin
        Append;
        FieldByName('HSQty').Value:=Trim(Edit1.Text);
        if MDMFlag.Checked then
        begin
          FieldByName('MQty').Value:=Trim(Edit1.Text);
        end;
        if MDKGFlag.Checked then
        begin
          FieldByName('KgQty').Value:=Trim(Edit1.Text);
        end;
        Post;
      end;
      Edit1.Text:='';
    end;
  end;
end;

procedure TfrmJGCKInPut.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if ClientDataSet1.IsEmpty then Exit;
  if Trim(ClientDataSet1.fieldbyname('MXID').AsString)='' then
  begin
    ClientDataSet1.Delete;
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
      sql.Add(' UPdate CK_MYSC_CR Set MXHZQty=(select Sum(MQty) from CK_MYSC_CR_MX A where A.MYID=CK_MYSC_CR.MYID) ');
      sql.Add(' ,MXHZKgQty=(select Sum(KgQty) from CK_MYSC_CR_MX A where A.MYID=CK_MYSC_CR.MYID) ');
      sql.Add(' ,MXHZPS=(select Count(*) from CK_MYSC_CR_MX A where A.MYID=CK_MYSC_CR.MYID) ');
      sql.Add(' where MYID='''+Trim(FMainId)+'''');
      ExecSQL;
    end;
    ClientDataSet1.Delete;
  end;
end;

procedure TfrmJGCKInPut.ToolButton1Click(Sender: TObject);
begin
  try
    frmJJGCKListSel:=TfrmJJGCKListSel.Create(Application);
    with frmJJGCKListSel do
    begin
      if ShowModal=1 then
      begin
        InitDataSel(frmJJGCKListSel.Order_Main.fieldbyname('MYID').AsString);
      end;
    end;
  finally
    frmJJGCKListSel.Free;
  end;
end;

end.
