unit U_GYSList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxDropDownEdit, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxSkinsCore,    
   dxSkinDarkRoom,  
     
     
     
    
    
    
   dxSkinOffice2013White,  
    dxSkinSharpPlus, 
  dxSkinSpringTime,   
  dxSkinsDefaultPainters,   
   dxSkinscxPCPainter;

type
  TfrmGYSList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    ToolButton3: TToolButton;
    Panel1: TPanel;
    Label9: TLabel;
    KHNameJC: TEdit;
    v1KHNo: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Label2: TLabel;
    KHNo: TEdit;
    v1Column1: TcxGridDBColumn;
    Label34: TLabel;
    KHType: TBtnEditC;
    v1KHLXR: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure KHTypeBtnDnClick(Sender: TObject);
    procedure KHTypeBtnUpClick(Sender: TObject);
  private
    DQdate: TDateTime;
    XZKHTYpe, canshu1: string;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmGYSList: TfrmGYSList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmGYSList.FormDestroy(Sender: TObject);
begin
  frmGYSList := nil;
end;

procedure TfrmGYSList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmGYSList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;

end;

procedure TfrmGYSList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('供应商登记', Tv1, '供应商管理');

end;

procedure TfrmGYSList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select *,zjm=dbo.getpinyin(KHName)  ');
      sql.Add(' from KH_Main A  ');
      sql.Add(' where isnull(KHFlag,'''')=''GYS'' and isnull(Valid,'''')=''Y''');
      {if Trim(canshu1)<>'高权限' then
      begin
        SQL.Add(' and A.FZR like '''+'%'+trim(DName)+'%'+'''');
      end;}
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    TBFind.Click;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmGYSList.InitForm();
begin
  ReadCxGrid(self.Caption, Tv1, '贸易生产管理');
  KHType.Visible := true;
  label34.Visible := true; 
  canshu1 := Trim(DParameters1);
 
  InitGrid();

end;

procedure TfrmGYSList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmGYSList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(canshu1) = '' then
  begin
    if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
    begin
      Application.MessageBox('不能操作他人的数据!', '提示', 0);
      Exit;
    end;
  end;
end;

procedure TfrmGYSList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
  begin
    Application.MessageBox('不能操作他人的数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmGYSList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update ZH_KH_Info Set Valid=''N'' where ZKId=''' + Trim(Order_Main.fieldbyname('ZKId').AsString) + '''');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmGYSList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGYSList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmGYSList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGYSList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmGYSList.N1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf';
  SDofilter(ADOQueryMain, ' OrderNoM=''' + Trim(Order_Main.fieldbyname('OrderNoM').AsString) + '''');
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  Porderno := Trim(Order_Main.fieldbyname('OrderNoM').AsString);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf'), '提示', 0);
  end;
  SDofilter(ADOQueryMain, '');
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  Order_Main.Locate('ordernoM', Porderno, []);
end;

procedure TfrmGYSList.N2Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf';
  SDofilter(ADOQueryMain, ' OrderNoM=''' + Trim(Order_Main.fieldbyname('OrderNoM').AsString) + '''');
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  Porderno := Trim(Order_Main.fieldbyname('OrderNoM').AsString);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf'), '提示', 0);
  end;
  SDofilter(ADOQueryMain, '');
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  Order_Main.Locate('ordernoM', Porderno, []);
end;

procedure TfrmGYSList.ToolButton3Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmGYSList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmGYSList.Tv1DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

procedure TfrmGYSList.KHTypeBtnDnClick(Sender: TObject);
begin
  KHType.Text := '';
  KHType.TxtCode := '';
end;

procedure TfrmGYSList.KHTypeBtnUpClick(Sender: TObject);
begin
 
  TBFind.Click;
end;

end.

