unit U_OrderInPut_New210625;

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, Menus;

type
  TfrmOrderInPut_New210625 = class(TForm)
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    CDS_JGMX: TClientDataSet;
    DSCON: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    Label10: TLabel;
    Label3: TLabel;
    Label14: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label7: TLabel;
    MLConNo: TBtnEditC;
    MLOrderNo: TEdit;
    OrdDate: TDateTimePicker;
    KHName: TBtnEditC;
    MLCodeName: TBtnEditC;
    MLCodeNo: TEdit;
    MLBZNote: TMemo;
    YWY: TBtnEditC;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    v1MLColor: TcxGridDBColumn;
    v1MLColorNo: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    v1MXNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ClientDataSet3: TClientDataSet;
    DataSource3: TDataSource;
    Panel4: TPanel;
    Image2: TImage;
    Button3: TButton;
    Button5: TButton;
    Button6: TButton;
    Button9: TButton;
    Label6: TLabel;
    GYNote: TMemo;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Label2: TLabel;
    BZType: TComboBox;
    v1Column4: TcxGridDBColumn;
    Label8: TLabel;
    MLNote: TMemo;
    Label9: TLabel;
    Label11: TLabel;
    MLMFNote: TEdit;
    JHDate: TDateTimePicker;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    N3: TMenuItem;
    Panel2: TPanel;
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label12: TLabel;
    MianName: TBtnEditC;
    Label13: TLabel;
    WFBName: TBtnEditC;
    Label15: TLabel;
    MianMF: TEdit;
    Label16: TLabel;
    MianKZ: TEdit;
    Label17: TLabel;
    WFBMF: TEdit;
    Label18: TLabel;
    WFBKZ: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(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 YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure V2GXNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure YWYBtnUpClick(Sender: TObject);
    procedure GYNoteDblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Tv3Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure v1MLHXPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure N3Click(Sender: TObject);
    procedure v1Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure MianNameBtnUpClick(Sender: TObject);
    procedure WFBNameBtnUpClick(Sender: TObject);
    procedure MianNameBtnDnClick(Sender: TObject);
    procedure WFBNameBtnDnClick(Sender: TObject);
  private
    procedure InitData();
    function SaveData(): Boolean;
    procedure InitPDJL();
    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo, ISPD: string;
    FXS: Integer;
    canshu1, canshu2: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmOrderInPut_New210625: TfrmOrderInPut_New210625;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_KHList_CX, U_ZDYHelpSel
  ,U_MLMangeRSSel,U_ZdyAttachCP_HX_sel,U_BPZdy_LRM;

{$R *.dfm}
procedure TfrmOrderInPut_New210625.InitPDJL();
var
  i: Integer;
begin

  i := 0;
  with ADOQueryTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from ML_ConMain A inner join ML_ConSub B on A.MLConID=B.MLConID ');
    sql.Add('where exists(select * from TbForBatch X where X.ConSubId=B.CSID and X.MainType=''生产排单'' and X.DName=' + QUOTEDSTR(Trim(DName)) + '  )');
    Open;
  end;
  KHName.Text := ADOQueryTmp.FieldByName('KHName').AsString;
  MLConNo.Text := ADOQueryTmp.FieldByName('ConNO').AsString;
  MLCodeNo.Text := ADOQueryTmp.FieldByName('ConCode').AsString;
  MLCodeName.Text := ADOQueryTmp.FieldByName('ConCodeName').AsString;
  MLOrderNo.Text :=Trim(ADOQueryTmp.FieldByName('YWConNo').AsString)+'-'
                   +Trim(ADOQueryTmp.FieldByName('XHNo').AsString);
  MLOrderNo.Hint:=Trim(ADOQueryTmp.FieldByName('CSID').AsString);
  with ADOQueryTmp do
  begin
    First;
    while not Eof do
    begin
      with Order_Sub do
      begin
        Append;
        FieldByName('ConSubId').Value := ADOQueryTmp.FieldByName('CSID').Value;
        FieldByName('XHNO').Value := IntToStr(i + 1);
        FieldByName('MLColor').Value := ADOQueryTmp.FieldByName('ConColor').Value;
        FieldByName('MLColorNo').Value := ADOQueryTmp.FieldByName('ConColNo').Value;
        FieldByName('MLHX').Value := ADOQueryTmp.FieldByName('ConHX').Value;
        FieldByName('QtyUnit').Value := ADOQueryTmp.FieldByName('QtyUnit').Value;
        FieldByName('Qty').Value := ADOQueryTmp.FieldByName('Qty').Value;
        Post;
      end;
      Next;
    end;
  end;
end;

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

procedure TfrmOrderInPut_New210625.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_OrderZuHe where NewMLID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS20(ADOQuery1, ClientDataSet3);
  SInitCDSData20(ADOQuery1, ClientDataSet3);

  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);
    JHDate.Date:=OrdDate.Date;
    YWY.Text := Trim(DName);
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    JHDate.Date:=OrdDate.Date;
    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;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('NewMLID').Value := '';
        FieldByName('ZHID').Value := '';
        Post;
        Next;
      end;
    end;
  end;
end;

procedure TfrmOrderInPut_New210625.FormShow(Sender: TObject);
begin
  readCxGrid('生产计划单1', Tv1, '生产指示单管理');
  InitData();
  if ISPD = '排单' then
    InitPDJL();
end;

function TfrmOrderInPut_New210625.SaveData(): Boolean;
var
  maxno, MXmaxno, forderNo: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOTemp, 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;
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        Edit;
      end;
      FieldByName('NewMLID').Value := Trim(maxno);
      SSetsaveSqlNew(ADOCmd, 'ML_OrderMainNew', ScrollBox1, 2);
      if Trim(MLOrderNo.Hint)<>'' then
      begin
        FieldByName('ConSubId').Value :=Trim(MLOrderNo.Hint);
      end;
      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;
      FMainId:='';
      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(ADOTemp, 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('ConSubId').Value := Trim(Order_Sub.FieldByName('ConSubId').AsString);
          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 ADOCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('update ML_ConSub set ISPD=( case when (select  COUNT(1)  from ML_OrderSubidNew X  where X.ConSubId=CSID)>0 then 1 else 0 end)');
      sql.Add('where exists(select X.MLConID from ML_ConMain X where X.MLConID=ML_ConSub.MLConID and X.ConNO=' + quotedstr(MLConNo.Text) + ') ');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update ML_OrderMainNew Set MianCKQtyMPlan=(select sum(Qty) from ML_OrderSubidNew A where A.NewMLID=ML_OrderMainNew.NewMLID) ');
      sql.Add(' where NewMLID='''+Trim(FMainId)+'''');
      sql.Add(' and isnull(MianName,'''')<>'''' ');

      sql.Add('Update ML_OrderMainNew Set WFBCKQtyMPlan=(select sum(Qty) from ML_OrderSubidNew A where A.NewMLID=ML_OrderMainNew.NewMLID) ');
      sql.Add(' where NewMLID='''+Trim(FMainId)+'''');
      sql.Add(' and isnull(WFBName,'''')<>'''' ');

      sql.Add('Update ML_OrderMainNew Set MianCKQtyM=(select sum(JYLen) from JTJY_New A where A.NewMLID=ML_OrderMainNew.NewMLID and JYType=''成品'') ');
      sql.Add(' where NewMLID='''+Trim(FMainId)+'''');
      sql.Add(' and isnull(MianName,'''')<>'''' ');

      sql.Add('Update ML_OrderMainNew Set WFBCKQtyM=(select sum(JYLen) from JTJY_New A where A.NewMLID=ML_OrderMainNew.NewMLID and JYType=''成品'') ');
      sql.Add(' where NewMLID='''+Trim(FMainId)+'''');
      sql.Add(' and isnull(WFBName,'''')<>'''' ');
      ExecSQL;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmOrderInPut_New210625.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if MLOrderNo.Text = '' then
  begin
    Application.MessageBox('指示单号不能为空', '提示', 0);
    Exit;
  end;
  if Trim(BZType.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_New210625.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_New210625.ToolButton1Click(Sender: TObject);
var
  FName,mvalue,FCaption:string;
begin
  ToolBar2.SetFocus;
  FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  FCaption:=Tv1.Controller.FocusedColumn.Caption;
  mvalue:=Trim(Order_Sub.fieldbyname(FName).AsString);
  if Trim(FCaption)='颜色' then
  begin
    Application.MessageBox('颜色不能一键替换！','提示',0);
    Exit;
  end;
  if Trim(FCaption)='COLOR' then
  begin
    Application.MessageBox('COLOR不能一键替换！','提示',0);
    Exit;
  end;
  if Application.MessageBox(PChar('确定要把所有的<'+Trim(FCaption)+'> 更改为：'+Trim(mvalue)+' 吗？'),'提示',32+4)<>IDYES then Exit;
  with Order_Sub do
  begin
    First;
    while not Eof do
    begin
      Edit;
      FieldByName(FName).Value:=Trim(mvalue);
      Post;
      Next;
    end;
  end;
end;

procedure TfrmOrderInPut_New210625.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);
        KHName.TxtCode := Trim(CDS_HZ.fieldbyname('KHNo').AsString);
      end;
    end;
  finally
    frmKHList_CX.Free;
  end;
end;

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

procedure TfrmOrderInPut_New210625.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_New210625.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_New210625.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_New210625.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_New210625.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_New210625.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_New210625.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_New210625.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_New210625.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;

procedure TfrmOrderInPut_New210625.N1Click(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_New210625.N2Click(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_New210625.Tv3Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  Panel4.Visible:=True;
  Panel4.Refresh;
end;

procedure TfrmOrderInPut_New210625.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

procedure TfrmOrderInPut_New210625.Button3Click(Sender: TObject);
begin
  try
    frmMLMangeRSSel:=TfrmMLMangeRSSel.Create(Application);
    with frmMLMangeRSSel do
    begin
      if ShowModal=1 then
      begin
        with Self.ClientDataSet3 do
        begin
          Edit;
          FieldByName('MLName').Value:=Trim(frmMLMangeRSSel.CDS_Main.fieldbyname('MLName').AsString);
          FieldByName('MLGY').Value:=Trim(frmMLMangeRSSel.CDS_Main.fieldbyname('GYLXName').AsString);
          FieldByName('MLCode').Value:=Trim(frmMLMangeRSSel.CDS_Main.fieldbyname('MLName').AsString);
          FieldByName('MLType').Value:='染色';
          Post;
        end;
      end;
    end;
  finally
    frmMLMangeRSSel.Free;
  end;
end;

procedure TfrmOrderInPut_New210625.v1MLHXPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachCP_HX_Sel:=TfrmZdyAttachCP_HX_Sel.Create(Application);
    with frmZdyAttachCP_HX_Sel do
    begin
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('MLHX').Value:=Trim(frmZdyAttachCP_HX_Sel.CDS_HZ.fieldbyname('zdyName').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachCP_HX_Sel.Free;
  end;
end;

procedure TfrmOrderInPut_New210625.N3Click(Sender: TObject);
var
  FName,mvalue,FCaption:string;
begin
  FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  FCaption:=Tv1.Controller.FocusedColumn.Caption;
  mvalue:=Trim(Order_Sub.fieldbyname(FName).AsString);
  if Application.MessageBox(PChar('确定要把所有的<'+Trim(FCaption)+'> 更改为：'+Trim(mvalue)+' 吗？'),'提示',32+4)<>IDYES then Exit;
  with Order_Sub do
  begin
    First;
    while not Eof do
    begin
      Edit;
      FieldByName(FName).Value:=Trim(mvalue);
      Post;
      Next;
    end;
  end;
end;

procedure TfrmOrderInPut_New210625.v1Column7PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='FeeName';
      flagname:='费用名称';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('FeeName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_New210625.MianNameBtnUpClick(Sender: TObject);
begin
  try
    frmBPZDY_LRM:=TfrmBPZDY_LRM.Create(Application);
    with frmBPZDY_LRM do
    begin
      if ShowModal=1 then
      begin
        MianName.Text:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPName').AsString);
        MianName.TxtCode:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPCode').AsString);
        MianMF.Text:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPMF').AsString);
        MianKZ.Text:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPKZ').AsString);
      end;
    end;
  finally
    frmBPZDY_LRM.Free;
  end;
end;

procedure TfrmOrderInPut_New210625.WFBNameBtnUpClick(Sender: TObject);
begin
  try
    frmBPZDY_LRM:=TfrmBPZDY_LRM.Create(Application);
    with frmBPZDY_LRM do
    begin
      if ShowModal=1 then
      begin
        WFBName.Text:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPName').AsString);
        WFBName.TxtCode:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPCode').AsString);
        WFBMF.Text:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPMF').AsString);
        WFBKZ.Text:=Trim(frmBPZDY_LRM.ClientDataSet1.fieldbyname('BPKZ').AsString);
      end;
    end;
  finally
    frmBPZDY_LRM.Free;
  end;
end;

procedure TfrmOrderInPut_New210625.MianNameBtnDnClick(Sender: TObject);
begin
  MianName.Text:='';
  MianMF.Text:='';
  MianKZ.Text:='';
  MianName.TxtCode:='';
end;

procedure TfrmOrderInPut_New210625.WFBNameBtnDnClick(Sender: TObject);
begin
  WFBName.Text:='';
  WFBMF.Text:='';
  WFBKZ.Text:='';
  WFBName.TxtCode:='';
end;

end.

