unit U_YGYPZZChkList_GBL;

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, cxPC, ActnMan, ActnColorMaps,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP,IniFiles;

type
  TfrmYGYPZZChkList_GBL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    TBView: TToolButton;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ADOQuery1: TADOQuery;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxStyle2: TcxStyle;
    ADOQuery2: TADOQuery;
    v1GSBiaoTi: TcxGridDBColumn;
    Panel1: TPanel;
    Label4: TLabel;
    GSBiaoTi: TEdit;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    Label3: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1filltime: TcxGridDBColumn;
    v1FBType: TcxGridDBColumn;
    v1ZDNote: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    TFB: TToolButton;
    TCXFB: TToolButton;
    v1Ssel: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure TFBClick(Sender: TObject);
    procedure TCXFBClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    FDEPT,FDPName: string;
    lstPat: TStringList;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure setstatus();
    procedure SaveData();
    procedure ReadINIFile10();
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    { Public declarations }
  end;

var
  frmYGYPZZChkList_GBL: TfrmYGYPZZChkList_GBL;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp, U_YGYPInPut,
  U_ZDYHelpSel,U_YGYPInPut_YGFJDJ,U_YGYPInPut_GBLDJ;  

{$R *.dfm}

procedure TfrmYGYPZZChkList_GBL.setstatus();
begin
  
end;

procedure TfrmYGYPZZChkList_GBL.SaveData();
var
  maxno:String;
begin
  if GetLSNo(ADOQueryTemp,maxno,'ZD','OA_YG_GSGZZD',4,1)=False then
  begin
    Application.MessageBox('取最大号失败!','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from OA_YG_GSGZZD where ZDID='''+Trim(maxno)+'''');
    Open;
    if isempty then
    begin
      append;
      fieldbyname('filler').AsString:=trim(DName);
      fieldbyname('filltime').AsDateTime:=SGetServerDate(ADOQuery2);
      fieldbyname('ZDID').Value:=trim(maxno);
      fieldbyname('DeptType').Value:=trim(FDPName);
      fieldbyname('GSBiaoTi').Value:=trim(Order_Main.fieldbyname('GSBiaoTi').AsString);
      post;
    end;
  end;
end;

procedure TfrmYGYPZZChkList_GBL.FormDestroy(Sender: TObject);
begin
  frmYGYPZZChkList_GBL:=nil;
end;

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

procedure TfrmYGYPZZChkList_GBL.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  canshu1:=Trim(DParameters1);
end;

procedure TfrmYGYPZZChkList_GBL.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('公司内部信息列表',Tv1,'OA管理');
end;

procedure TfrmYGYPZZChkList_GBL.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * ');
      sql.Add(' from OA_YG_GSGZZD A');
      sql.add(' inner join OA_Chk B on B.Mainid=A.ZDID ');
      sql.Add(' where B.Chker='''+trim(DName)+''' ');
      sql.add(' and isnull(A.FBType,'''')<>''会议开会''');
      if cxTabControl1.tabindex<>0 then
      begin
        sql.add(' and A.filltime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.filltime<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(B.Chkstatus,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.add(' and isnull(B.Chkstatus,'''')=''申请通过''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGYPZZChkList_GBL.InitForm();
begin
  ReadCxGrid('公司内部信息列表',Tv1,'OA管理');
  //setstatus();
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  InitGrid();
end;

procedure TfrmYGYPZZChkList_GBL.TBFindClick(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

function TfrmYGYPZZChkList_GBL.DelData():Boolean;
begin
  
end;

procedure TfrmYGYPZZChkList_GBL.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('公司规章制度列表',cxGrid1);
end;

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

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

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

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

procedure TfrmYGYPZZChkList_GBL.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmYGYPInPut_GBLDJ:=TfrmYGYPInPut_GBLDJ.create(self);
  with frmYGYPInPut_GBLDJ do
  begin
    ToolBar1.Visible:=False;
    FCLID:=trim(Order_Main.fieldbyname('ZDID').AsString);
    if showModal=1 then
    begin
      
    end;
    free;
  end;
end;

procedure TfrmYGYPZZChkList_GBL.CustomerNoNameChange(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmYGYPZZChkList_GBL.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TBView.Click;
end;

procedure TfrmYGYPZZChkList_GBL.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmYGYPZZChkList_GBL.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmYGYPZZChkList_GBL.ReadINIFile10();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmYGYPZZChkList_GBL.TFBClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  toolbar1.SetFocus;
  if order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  try
    with Order_Main do
    begin
      first;
      while not eof do
      begin
        if fieldbyname('Ssel').AsBoolean=True then
        begin
          if trim(Canshu1)='高权限' then
          begin
            with ADOQueryCmd do
            begin
              Close;
              SQL.Clear;
              sql.Add('Update OA_Chk Set ');
              sql.Add('ChkTime=getdate(),Chkstatus=''申请通过'' ');
              sql.Add('where Mainid='''+trim(Order_Main.fieldbyname('ZDID').AsString)+''' ');
              sql.add('and OAType=''发布管理''');
              ExecSQL;
            end;
          end
          else
          begin
            with ADOQueryCmd do
            begin
              Close;
              SQL.Clear;
              sql.Add('Update OA_Chk Set ');
              sql.Add(' ChkTime=getdate(),Chkstatus=''申请通过'' ');
              sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+''' ');
              ExecSQL;
            end;
          end;
          with ADOQueryCmd do
          begin
            close;
            sql.clear;
            sql.add('select A.* from OA_Chk A ');
            sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('ZDID').AsString)+''' ');
            sql.add('and isnull(A.Chkstatus,'''')<>''申请通过'' ');
            sql.add('and isnull(A.OAType,'''')=''发布管理''');
            open;
          end;
          if ADOQueryCmd.IsEmpty then
          begin
            with ADOQueryMain do
            begin
              close;
              sql.Clear;
              sql.add('update OA_YG_GSGZZD set ');
              sql.add('FBStatus=''申请通过'' ');
              sql.Add(' where ZDID='''+trim(Order_Main.fieldbyname('ZDID').AsString)+'''');
              execsql;
            end;
            {with ADOQueryMain do
            begin
              close;
              sql.Clear;
              sql.add('update OA_YG_DangAn set ');
              sql.add('isnull(YDID,'''')=''1'' ');
              sql.Add(' where LiZhiFlag=0');
              execsql;
            end;}
          end;
        end;
        next;
      end;
    end;
    application.MessageBox('审核成功','提示');
    initGrid();
  except;
    application.MessageBox('审核失败','提示');
    exit;
  end;
end;

procedure TfrmYGYPZZChkList_GBL.TCXFBClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  toolbar1.SetFocus;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('Update OA_YG_GSGZZD Set FBStatus=''已发布''');
      sql.Add(' where ZDID='''+trim(Order_Main.fieldbyname('ZDID').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('Update OA_Chk set Chkstatus=''''');
      sql.Add(' where CKID='''+Order_Main.fieldbyname('CKID').AsString+'''');
      sql.Add(' and isnull(OAType,'''')=''发布管理'' ');
      ExecSQL;
    end;
    initGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmYGYPZZChkList_GBL.cxTabControl1Change(Sender: TObject);
begin
  inItGrid();
end;

end.
