unit U_OrderWJGInPut;

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
  TfrmOrderWJGInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    CDS_JGMX: TClientDataSet;
    DSCON: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    Panel2: TPanel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2GXXHNo: TcxGridDBColumn;
    V2GXName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    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;
    MLNote: TMemo;
    YWY: TBtnEditC;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    v1MLColor: TcxGridDBColumn;
    v1MLColorNo: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    v1MXNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    PopupMenu3: TPopupMenu;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    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;
    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 ToolButton4Click(Sender: TObject);
    procedure YWYBtnUpClick(Sender: TObject);
    procedure GYNoteDblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure Tv3Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Button3Click(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
  frmOrderWJGInPut: TfrmOrderWJGInPut;
  newh: hwnd;

implementation

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

{$R *.dfm}
procedure TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('生产计划单1', Tv1, '生产指示单管理');
end;

procedure TfrmOrderWJGInPut.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);
    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;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('NewMLID').Value := '';
        FieldByName('ZHID').Value := '';
        Post;
        Next;
      end;
    end;
  end;
end;

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

function TfrmOrderWJGInPut.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);
      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;
      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('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 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;
    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;

    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.KHNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.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 TfrmOrderWJGInPut.MenuItem2Click(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 TfrmOrderWJGInPut.MenuItem3Click(Sender: TObject);
var
  i: Integer;
begin
  i := ClientDataSet3.RecordCount;
  with ClientDataSet3 do
  begin
    Append;
    FieldByName('XHNO').Value := IntToStr(i + 1);
    Post;
  end;
end;

procedure TfrmOrderWJGInPut.Tv3Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  Panel4.Visible:=True;
  Panel4.Refresh;
end;

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

procedure TfrmOrderWJGInPut.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;

end.

