unit U_FanYangList_Other;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxButtonEdit, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, ComCtrls, ToolWin, ExtCtrls,
  StdCtrls, BtnEdit, cxContainer, cxTextEdit, cxCurrencyEdit, ADODB,
  DBClient,strutils;

type
  TFrmFanYangList_Other = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label7: TLabel;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label2: TLabel;
    Label6: TLabel;
    Label16: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label29: TLabel;
    Label45: TLabel;
    Label48: TLabel;
    OrdDate: TDateTimePicker;
    OrdDefDate1: TDateTimePicker;
    OrdDefStr3: TEdit;
    OrdDefStr2: TBtnEditA;
    MPRTCodeName: TBtnEditA;
    OrdDefStr1: TBtnEditA;
    CustomerNoName: TBtnEditA;
    RanFactory: TBtnEditA;
    PBFactory: TBtnEditA;
    MPRTKZ: TBtnEditA;
    MPRTMF: TBtnEditA;
    MPRTCode: TBtnEditA;
    OrdQty1: TcxCurrencyEdit;
    Label4: TLabel;
    Note: TMemo;
    OrdDefNote1: TMemo;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    CustomerNo: TEdit;
    MPRTspec: TEdit;
    Label27: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    OrdDefDate3: TDateTimePicker;
    Label17: TLabel;
    fromMainID: TEdit;
    orderNO: TBtnEditA;
    OrdDefDate2: TDateTimePicker;
    Label5: TLabel;
    OrdDefStr4: TEdit;
    Label8: TLabel;
    MPRTCF: TEdit;
    Label9: TLabel;
    OrdDefStr5: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure MPRTCodeBtnClick(Sender: TObject);
    procedure OrdDefNote1DblClick(Sender: TObject);
    procedure CustomerNoNameBtnClick(Sender: TObject);
    procedure MPRTCodeNameBtnClick(Sender: TObject);
    procedure OrdDefStr1BtnClick(Sender: TObject);
    procedure OrdDefStr2BtnClick(Sender: TObject);
    procedure MPRTMFBtnClick(Sender: TObject);
    procedure MPRTKZBtnClick(Sender: TObject);
    procedure PBFactoryBtnClick(Sender: TObject);
    procedure RanFactoryBtnClick(Sender: TObject);
    procedure orderNOBtnClick(Sender: TObject);
  private
    procedure initGrid();
    procedure SaveData();
    { Private declarations }
  public
    FMainid: string;
    CopyInt: integer;
    { Public declarations }
  end;

var
  FrmFanYangList_Other: TFrmFanYangList_Other;

implementation

uses U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel, U_ZdyAttachment,
  U_FanYangList_sel;

{$R *.dfm}

procedure TFrmFanYangList_Other.SaveData();
var MaxNo,ForederNo: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOQueryCmd,FMainId,'FO','JYOrderFY_Other',3,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrderFY_Other where MainId='''+Trim(FMainId)+'''');
      Open;
      if isempty then
      begin
        Append;
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('Filltime').Value:=SGetServerDateTime(ADOQueryTmp);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTmp);
      end;
      FieldByName('OrderNo').Value:=Trim(orderNo.text);
      FieldByName('MainId').Value:=Trim(FMainid);
      FieldByName('Status').Value:='0';
      SSetsaveSqlNew(ADOQueryCmd,'JYOrderFY_Other',Panel1,2);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.messagebox('保存成功','提示');
    ModalResult:=1;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示');
  end;
end;

procedure TFrmFanYangList_Other.initGrid();
begin
  with AdoqueryCmd do
  begin
    close;
    sql.clear;
    sql.add('select * from JYOrderFY_Other where Mainid='''+trim(FMainid)+''' ');
    open;
    if not isempty then
    begin
      SCSHDataNew(AdoqueryCmd,Panel1,2);
      OrderNO.Text:=Trim(fieldbyname('ORDERno').AsString);
    end;
  end;
end;

procedure TFrmFanYangList_Other.FormCreate(Sender: TObject);
begin
  Panel1.Align:=alClient;
end;

procedure TFrmFanYangList_Other.FormShow(Sender: TObject);
begin

  ordDate.datetime:=SGetServerDateTime(ADOQueryTmp);
  OrdDefDate1.DateTime:=ordDate.datetime;
  OrdDefDate2.DateTime:=ordDate.datetime;
  OrdDefDate3.DateTime:=ordDate.datetime;
  OrdDefDate1.Checked:=false;
  OrdDefDate2.Checked:=false;
  OrdDefDate3.Checked:=false;
  initGrid();
end;

procedure TFrmFanYangList_Other.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TFrmFanYangList_Other.TBSaveClick(Sender: TObject);
begin
  if trim(OrderNo.Text)='' then
  begin
    application.MessageBox('放样单号不能为空','提示');
    exit;
  end;
  if trim(CustomerNo.Text)='' then
  begin
    application.MessageBox('客户简称不能为空','提示');
    exit;
  end;
  if trim(CustomerNoName.Text)='' then
  begin
    application.MessageBox('客户不能为空','提示');
    exit;
  end;
  if trim(OrdDefStr1.Text)='' then
  begin
    application.MessageBox('业务组不能为空','提示');
    exit;
  end;


  SaveData();
end;

procedure TFrmFanYangList_Other.MPRTCodeBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTCode';
      flagname:='产品编号';;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.OrdDefNote1DblClick(Sender: TObject);
var i: integer;
begin

end;

procedure TFrmFanYangList_Other.CustomerNoNameBtnClick(Sender: TObject);
begin

  try
    frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      fkhType:='';
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(CDS_HZ.fieldbyname('ZDYName').AsString);
       // CustomerNoName.TxtCode:=Trim(CDS_HZ.fieldbyname('ZDYCode').AsString);
        CustomerNo.Text:=Trim(CDS_HZ.fieldbyname('ZDYNameZ').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TFrmFanYangList_Other.MPRTCodeNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTCodeName';
      flagname:='产品名称';;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.OrdDefStr1BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YEWUZU';
      flagname:='业务组';;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.OrdDefStr2BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SHENGCHANZU';
      flagname:='生产组';;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.MPRTMFBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTMF';
      flagname:='门幅';
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.MPRTKZBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTKZ';
      flagname:='克重';
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.PBFactoryBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Factory';
      flagname:='坯布厂';
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.RanFactoryBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Factory';
      flagname:='染厂';
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmFanYangList_Other.orderNOBtnClick(Sender: TObject);
begin
  FrmFanYangList_sel:=TFrmFanYangList_sel.create(self);
  with FrmFanYangList_sel do
  begin
    If showmodal=1 then
    begin
      self.orderNO.text:=Order_Main.fieldbyname('orderNo').asstring;
      self.fromMainID.Text:=Order_Main.fieldbyname('MainID').asstring;
      self.CustomerNo.Text:=Order_Main.fieldbyname('CustomerNo').asstring;
      self.CustomerNoName.Text:=Order_Main.fieldbyname('CustomerNoName').asstring;
      self.MPRTCode.Text:=Order_Main.fieldbyname('MPRTCode').asstring;
      self.MPRTCodeName.Text:=Order_Main.fieldbyname('MPRTCodeName').asstring;
      self.OrdDefStr1.Text:=Order_Main.fieldbyname('OrdDefStr1').asstring;
      self.MPRTMF.Text:=Order_Main.fieldbyname('MPRTMF').asstring;
      self.MPRTKZ.Text:=Order_Main.fieldbyname('MPRTKZ').asstring;
    end;
    free;
  end;
end;

end.
