unit U_OrderInPut_New;

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, cxCurrencyEdit,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxDropDownEdit, cxCheckBox;

type
  TfrmOrderInPut_New = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    MLOrderNo: TEdit;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    Label10: TLabel;
    Label3: TLabel;
    Label14: TLabel;
    OrdDate: TDateTimePicker;
    KHName: TBtnEditC;
    CDS_JGMX: TClientDataSet;
    DSCON: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    MLConNo: TBtnEditC;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    Label4: TLabel;
    MLCodeName: TBtnEditC;
    MLCodeNo: TEdit;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    v1MLColor: TcxGridDBColumn;
    v1MLColorNo: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2GXName: TcxGridDBColumn;
    V2GXNote: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolBar3: TToolBar;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    Label5: TLabel;
    MLNote: TMemo;
    V2GXXHNo: TcxGridDBColumn;
    Label7: TLabel;
    YWY: TBtnEditC;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1MXNote: TcxGridDBColumn;
    Label2: TLabel;
    GYNote: TMemo;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure KHNameBtnUpClick(Sender: TObject);
    procedure KHNameBtnDnClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton3Click(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure v1Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure MLConNoBtnUpClick(Sender: TObject);
    procedure v1PRTCodePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure MLCodeNameBtnUpClick(Sender: TObject);
    procedure V2GXNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure YWYBtnUpClick(Sender: TObject);
    procedure GYNoteDblClick(Sender: TObject);
  private
    procedure InitData();
    function  SaveData():Boolean;
    function  getOrderNo(fconNo:string):string;
    procedure CFSaveData();
    { Private declarations }
  public
    PState,CopyInt,PriceFlag:Integer;
    FMainId,FFMainId,FOrderNo:String;
    FXS:Integer;
    canshu1,canshu2:string;
    fFlileFlag:string;
    { Public declarations }
  end;

var
  frmOrderInPut_New: TfrmOrderInPut_New;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel, U_ZdyAttachment, U_ZdyAttachGYS,
  U_CPManageSel, getpic, U_ZdyAttachCP_HX_sel,U_ContractList_CX,U_KHList_CX,U_GYSList;

{$R *.dfm}
procedure TfrmOrderInPut_New.CFSaveData();
begin
 
end;

function TfrmOrderInPut_New.getOrderNo(fconNo:string):string;
begin

end;

procedure TfrmOrderInPut_New.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('生产计划单1',Tv1,'生产指示单管理');
end;

procedure TfrmOrderInPut_New.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from ML_OrderSubidNew where 1=1 ');
    if PState=1 then
    begin
      sql.Add(' and NewMLID='''+Trim(FMainId)+'''');
    end;
    if PState=0 then
    begin
      sql.Add(' and 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);

  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from ML_GX where 1=1 ');
    if PState=1 then
    begin
      sql.Add(' and NewMLID='''+Trim(FMainId)+'''');
    end;
    if PState=0 then
    begin
      sql.Add(' and 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_JGMX);
  SInitCDSData20(ADOQuery1,CDS_JGMX);

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from ML_OrderMainNew where NewMLID='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  if PState=0 then
  begin
    OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
    YWY.Text:=Trim(DName);
  end
  else
  begin
  end;
  if CopyInt=99 then
  begin
    PState:=0;
    FMainId:='';
    OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
    YWY.Text:=Trim(DName);
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('NewMLID').Value:='';
        FieldByName('NewSubid').Value:='';
        Post;
        Next;
      end;
    end;
  end;
end;

procedure TfrmOrderInPut_New.FormShow(Sender: TObject);
begin
  readCxGrid('生产计划单1',Tv1,'生产指示单管理');
  InitData();
end;

function TfrmOrderInPut_New.SaveData():Boolean;
var
  maxno,MXmaxno,forderNo:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'ML','ML_OrderMainNew',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
      {if GetLSNo(ADOCmd,forderNo,'','ML_OrderMainNew',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
     MLorderNo.Text:=forderNo;}
    end
    else
    begin
      maxno:=Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from ML_OrderMainNew where NewMLID='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
      end
      else begin
        Edit;
      end;
      FieldByName('NewMLID').Value:=Trim(maxno);
      SSetsaveSqlNew(ADOCmd,'ML_OrderMainNew',ScrollBox1,2);
      FieldByName('Status').Value:='未审核';
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      Post;
    end;
    FMainId:=Trim(maxno);
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from ML_OrderMainNew where MLOrderNo='''+Trim(MLOrderNo.Text)+'''');
      Open;
    end;
    if ADOCmd.RecordCount>1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      application.MessageBox('指示单号重复,不能保存','提示');
      exit;
    end;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('NewSubid').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxno,'MS','ML_OrderSubidNew',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(Order_Sub.fieldbyname('NewSubid').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from ML_OrderSubidNew where NewMLID='''+Trim(FMainId)+'''');
          sql.Add(' and NewSubid='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('NewSubid').AsString)='' then
            Append
          else
            Edit;
          FieldByName('NewMLID').Value:=Trim(FMainId);
          FieldByName('NewSubid').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'ML_OrderSubidNew',0);
          fieldbyname('Qty').Value:=Order_Sub.FieldByName('Qty').AsFloat;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('NewSubid').Value:=Trim(maxno);
        Order_Sub.FieldByName('NewMLID').Value:=Trim(FMainId);
        Next;
      end;
    end;
    with CDS_JGMX do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_JGMX.fieldbyname('GXID').AsString)='' then
        begin
          if GetLSNo(ADOCmd,MXmaxno,'GX','ML_GX',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          MXmaxno:=Trim(CDS_JGMX.fieldbyname('GXID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from ML_GX where GXID='''+Trim(MXmaxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if IsEmpty then
            Append
          else
            Edit;
          FieldByName('NewMLID').Value:=Trim(FMainId);
          FieldByName('GXID').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv2,CDS_JGMX,'ML_GX',0);
          Post;
        end;
        CDS_JGMX.Edit;
        CDS_JGMX.FieldByName('GXID').Value:=Trim(maxno);
        CDS_JGMX.FieldByName('NewMLID').Value:=Trim(FMainId);
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmOrderInPut_New.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if MLOrderNo.Text='' then
  begin
    Application.MessageBox('指示单号不能为空','提示',0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmOrderInPut_New.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      fnote:=True;
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('MLColor').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('MLColorNo').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.ToolButton1Click(Sender: TObject);
var
  i:Integer;
begin
  i:=Order_Sub.RecordCount;
  CopyAddRow(Tv1,Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('XHNO').Value:=IntToStr(i+1);
    Post;
  end;
end;

procedure TfrmOrderInPut_New.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Trim(Order_Sub.fieldbyname('NewSubid').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete ML_OrderSubidNew where NewSubid='''+Trim(Order_Sub.fieldbyname('NewSubid').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmOrderInPut_New.KHNameBtnUpClick(Sender: TObject);
begin
  try
    frmKHList_CX:=TfrmKHList_CX.Create(Application);
    with frmKHList_CX do
    begin
      IF self.canshu1<>'高权限' then canshu1:='业务员';
      if ShowModal=1 then
      begin
        KHName.Text:=Trim(CDS_HZ.fieldbyname('KHName').AsString);
      end;
    end;
  finally
    frmKHList_CX.Free;
  end;
end;

procedure TfrmOrderInPut_New.KHNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text:='';
  TBtnEditC(Sender).TxtCode:='';
end;

procedure TfrmOrderInPut_New.v1OrderUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  mvalues:string;
begin
  mvalues:=tv1.Columns[tv1.Controller.FocusedColumn.index].DataBinding.FieldName;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='NewOrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName(mvalues).Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.v1PriceUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceUnit';
      flagname:='价格单位';
      if Trim(DParameters1)<>'高权限' then
      begin
        TBAdd.Visible:=False;
        TBEdit.Visible:=False;
        TBDel.Visible:=False;
      end;

      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.OrdDefStr2BtnUpClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
begin
  fsj:=Trim(TEdit(Sender).Hint);
  FWZ:=Pos('/',fsj);
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.ConNoKeyPress(Sender: TObject; var Key: Char);
var
  ConMainId:string;
begin
  if Key=#13 then
  begin

    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderCon_Main where ConNo like '''+'%'+Trim(MLConNo.Text)+'%'+'''');
      Open;
    end;
    if ADOTemp.RecordCount>1 then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select Top 1* from JYOrderCon_Main where ConNo='''+Trim(MLConNo.Text)+'''');
        Open;
      end;
      if ADOTemp.IsEmpty then Exit;
    end else
    if ADOTemp.RecordCount=1 then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from JYOrderCon_Main where ConNo like '''+'%'+Trim(MLConNo.Text)+'%'+'''');
        Open;
      end;
    end;
    begin
      MLConNo.Text:=Trim(ADOTemp.fieldbyname('ConNo').AsString);
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,ColorName=(select ZdyName from KH_Zdy B where B.Note=A.PRTColor and B.Type=''OrdColor'' ) ');
        SQL.Add(' from JYOrderCon_Sub A where MainId='''+Trim(ConMainId)+'''');
        Open;
      end;
      with ADOTemp do
      begin
        First;
        while not Eof do
        begin
          with Order_Sub do
          begin
            Append;
            FieldByName('PRTColor').Value:=Trim(ADOTemp.fieldbyname('PRTColor').AsString);
            FieldByName('SOrdDefStr4').Value:=Trim(ADOTemp.fieldbyname('SOrdDefStr4').AsString);
            FieldByName('SOrdDefStr3').Value:=Trim(ADOTemp.fieldbyname('SOrdDefStr3').AsString);
            FieldByName('PRTOrderQty').Value:=Trim(ADOTemp.fieldbyname('PRTOrderQty').AsString);
            FieldByName('OrderUnit').Value:=Trim(ADOTemp.fieldbyname('OrderUnit').AsString);
            FieldByName('PRTPrice').Value:=Trim(ADOTemp.fieldbyname('PRTPrice').AsString);
            FieldByName('PriceUnit').Value:=Trim(ADOTemp.fieldbyname('PriceUnit').AsString);
            FieldByName('PRTHX').Value:=Trim(ADOTemp.fieldbyname('PRTHX').AsString);
            FieldByName('XHNO').Value:=Trim(ADOTemp.fieldbyname('XHNO').AsString);
            FieldByName('Sorddefstr10').Value:=Trim(ADOTemp.fieldbyname('Subid').AsString);
            Post;
          end;
          Next;
        end;
      end;
    end;

  end;
end;

procedure TfrmOrderInPut_New.ToolButton3Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  OneKeyPost(Tv1,Order_Sub);
end;

procedure TfrmOrderInPut_New.YCLFactoryBtnUpClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
begin
  fsj:=Trim(TEdit(Sender).Hint);
  FWZ:=Pos('/',fsj);
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      //MainType:=TEdit(Sender).Name;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
begin
  fsj:=Trim(TEdit(Sender).Hint);
  FWZ:=Pos('/',fsj);
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;


procedure TfrmOrderInPut_New.v1Column3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmZdyAttachCP_HX_Sel:=TfrmZdyAttachCP_HX_Sel.create(self);
  with frmZdyAttachCP_HX_Sel do
  begin
    IF showmodal=1 then
    begin
      Order_Sub.Edit;
      Order_Sub.FieldByName('PRTHX').Value:=trim(cds_Hz.FieldByName('ZdyName').asstring);
      Order_Sub.Post;
    end;
    frmZdyAttachCP_HX_Sel.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut_New.MLConNoBtnUpClick(Sender: TObject);
var i:Integer;
begin
  i:=Order_Sub.RecordCount;
  frmContractList_CX:=TfrmContractList_CX.create(self);
  with frmContractList_CX do
  begin
    if showmodal=1 then
    begin
      self.MLconNo.Text:=trim(Order_Main.fieldbyname('conNO').AsString);
      self.MLCodeName.Text:=trim(Order_SubCX.fieldbyname('PrtCodeName').AsString);
      self.MLCodeNo.Text:=trim(Order_SubCX.fieldbyname('PRTCode').AsString);
      self.KHName.Text:=trim(Order_Main.fieldbyname('CustomerNoName').AsString);
      with Order_SubCX do
      begin
        First;
        while not Eof do
        begin
          if FieldByName('Ssel').AsBoolean=true then
          begin
            with Order_Sub do
            begin
              Append;
              FieldByName('XHNo').Value:=i+1;
              FieldByName('MLColor').Value:=Trim(Order_SubCX.fieldbyname('PRTColor').AsString);
              FieldByName('MLColorno').Value:=Trim(Order_SubCX.fieldbyname('SOrdDefStr1').AsString);
              FieldByName('MLHX').Value:=Trim(Order_SubCX.fieldbyname('PRTHX').AsString);
              FieldByName('Qty').Value:=Order_SubCX.fieldbyname('PRTOrderQty').AsFloat;
              FieldByName('QtyUnit').Value:=Trim(Order_SubCX.fieldbyname('OrderUnit').AsString);
              Post;
            end;
          end;
          Next;
        end;
      end;
    end;
    Free;
  end;
end;

procedure TfrmOrderInPut_New.v1PRTCodePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmCPManageSel:=TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal=1 then
    begin
      Order_Sub.Edit;
      Order_Sub.fieldbyname('MLCode').Value:=CDS_Main.fieldbyname('CYNo').asstring;
      Order_Sub.fieldbyname('MLCodeName').Value:=CDS_Main.fieldbyname('CYEName').asstring;
      Order_Sub.fieldbyname('MLColor').Value:=CDS_Main.fieldbyname('CYColor').asstring;
      Order_Sub.fieldbyname('MLColorNo').Value:=CDS_Main.fieldbyname('CYColorNo').asstring;
      Order_Sub.fieldbyname('CYID').Value:=CDS_Main.fieldbyname('CYID').asstring;
      Order_Sub.Post;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut_New.MLCodeNameBtnUpClick(Sender: TObject);
begin
  frmCPManageSel:=TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal=1 then
    begin
      MLCodeNo.Text:=CDS_Main.fieldbyname('CYNo').asstring;
      MLCodeName.Text:=CDS_Main.fieldbyname('CYEName').asstring;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut_New.V2GXNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GXName';
      flagname:='工序名称';
      if Trim(DParameters1)<>'高权限' then
      begin
        TBAdd.Visible:=False;
        TBEdit.Visible:=False;
        TBDel.Visible:=False;
      end;

      if ShowModal=1 then
      begin
        Self.CDS_JGMX.Edit;
        Self.CDS_JGMX.FieldByName('GXName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.ToolButton5Click(Sender: TObject);
begin
  if CDS_JGMX.IsEmpty then exit;
  if application.MessageBox('确定要删除吗','提示',1)=2 then exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete from ML_GX where GXID='''+trim(CDS_JGMX.fieldbyname('GXID').AsString)+'''');
    ExecSQL;
  end;
  CDS_JGMX.Delete;
end;

procedure TfrmOrderInPut_New.ToolButton4Click(Sender: TObject);
var
  i:Integer;
begin
  i:=CDS_JGMX.RecordCount;
  CopyAddRow(Tv2,CDS_JGMX);
  with CDS_JGMX do
  begin
    Edit;
    FieldByName('GXXHNo').Value:=IntToStr(i+1);
    Post;
  end;
end;

procedure TfrmOrderInPut_New.YWYBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YWY';
      flagname:='业务员';
      if Trim(canshu1)<>'高权限' then
      begin
        TBAdd.Visible:=False;
        TBEdit.Visible:=False;
        TBDel.Visible:=False;
      end;
      if ShowModal=1 then
      begin
        YWY.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New.GYNoteDblClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
  i:integer;
begin
  fsj:=Trim(TMemo(Sender).Hint);
  FWZ:=Pos('/',fsj);
  i:=0;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        GYNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              GYNote.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

end.
