unit U_XHGZListInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, cxContainer,
  cxLabel, StdCtrls, cxCheckBox, ExtCtrls, Menus, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinscxPCPainter, cxNavigator;

type
  TfrmXHGZListInPut = class(TForm)
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxgrd1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    V2Column1: TcxGridDBColumn;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    CRTime: TDateTimePicker;
    ZJJE: TEdit;
    Label2: TLabel;
    Panel1: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ToolBar2: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolBar3: TToolBar;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    DataSource1: TDataSource;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    v1Column4: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    v1Column2: TcxGridDBColumn;
    N4: TMenuItem;
    Panel3: TPanel;
    lblYGName: TLabel;
    Button2: TButton;
    Panel4: TPanel;
    lblBC: TLabel;
    CDS_YG: TClientDataSet;
    V2Column3: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    v1Column9: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    N5: TMenuItem;
    V2Column5: TcxGridDBColumn;
    ToolButton9: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure v1Column10PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column6PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column13PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column21PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure TV2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure lblBCClick(Sender: TObject);
    procedure CRTimeChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGZSub(MGZMainId: string);
    procedure InitGZHZ();
    procedure InitYGGZ();
    procedure InitGrid();
  public
    { Public declarations }
    FBCId, FCRTime, FBanCi: string;
  end;

var
  frmXHGZListInPut: TfrmXHGZListInPut;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_ZdyAttachGYS, U_ZdyAttachCP,
  U_ZdyAttachCP_HX_Sel, U_ZDYHelpTouJu, U_XHGZInPut, U_YGListMoresel,
  U_KouKuanInPut, U_ZDYHelpSel, U_WorkDetail;

{$R *.dfm}
procedure TfrmXHGZListInPut.InitGrid();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select ZJJE= SUM(B.Money)  ');
    sql.Add(',CRTime=' + QUOTEDSTR(Trim(FCRTime)));
    sql.Add(',BanCi=' + QUOTEDSTR(Trim(FBanCi)));
    sql.Add(' from  GZListMain A inner join GZListSub B on A.GZMainID=B.GZMainID ');
    sql.Add(' where A.CRTime=' + QUOTEDSTR(Trim(FCRTime)));
    sql.Add(' and A.BanCi=' + QUOTEDSTR(Trim(FBanCi)));
    Open;
  end;
  SCSHDataNew(ADOQueryTemp, ScrollBox1, 2);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(',YGGZ=(select SUM(X.Money) from GZListSub X where A.GZMainID=X.GZMainID)');
    sql.Add(',JTQty=(select count(X.Money) from GZListSub X where A.GZMainID=X.GZMainID)');
    sql.Add(' from GZListMain A ');
    sql.Add(' where A.CRTime=' + QUOTEDSTR(Trim(FCRTime)));
    sql.Add(' and A.BanCi=' + QUOTEDSTR(Trim(FBanCi)));
    sql.Add(' order by A.YGCode,A.YGName');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Main);
  SInitCDSData20(ADOQueryTemp, CDS_Main);
end;

procedure TfrmXHGZListInPut.InitYGGZ();
var
  maxno: string;
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from GZListMain A');
    sql.Add(' where A.CRTime= (select top 1 CRTime from GZListMain X where CRTime<getdate() order by CRTime desc)');
    sql.Add(' and not exists (select X.YGCode  from GZListMain X where X.CRTime=' + quotedstr(FCRTime));
    sql.Add(' and X.YGCode=A.YGCode and X.YGName=A.YGName and X.BanCi=A.BanCi and  X.YGGongZhong=A.YGGongZhong)');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_YG);
  SInitCDSData20(ADOQueryTemp, CDS_YG);
  with CDS_YG do
  begin
    CDS_YG.First;
    while not CDS_YG.Eof do
    begin
      with ADOQueryTemp do
      begin
        sql.Add('select * from GZListMain');
        sql.Add('where CRTime=' + QuotedStr(Trim(FCRTime)));
        sql.Add('and FBanCi=' + QuotedStr(CDS_YG.FieldByName('BanCi').AsString));
        sql.Add('and YGName' + QuotedStr(CDS_YG.FieldByName('YGName').AsString));
        sql.Add(', YGName' + QuotedStr(CDS_YG.FieldByName('YGCode').AsString));
        sql.Add(', YGGongZhong' + QuotedStr(CDS_YG.FieldByName('YGGongZhong').AsString));
      end;
      if ADOQueryTemp.IsEmpty then
      begin
        if GetLSNo(ADOQueryCmd, maxno, 'GZM', 'GZListMain', 4, 1) = False then
        begin
          Application.MessageBox('生成流水号异常！', '提示', 0);
          exit;
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('insert into GZListMain(GZMainID,CRTime,BanCi,YGName,YGCode,YGGongZhong) ');
          sql.Add('values(' + QuotedStr(maxno));
          sql.Add(',' + QuotedStr(Trim(FCRTime)));
          sql.Add(',' + QuotedStr(CDS_YG.FieldByName('BanCi').AsString));
          sql.Add(',' + QuotedStr(CDS_YG.FieldByName('YGName').AsString));
          sql.Add(',' + QuotedStr(CDS_YG.FieldByName('YGCode').AsString));
          sql.Add(',' + QuotedStr(CDS_YG.FieldByName('YGGongZhong').AsString));
          sql.Add(' )');
          ExecSQL;
        end;
      end;
      CDS_YG.Next;
    end;
  end;
end;

procedure TfrmXHGZListInPut.InitGZHZ();
begin
  with CDS_Main do
  begin
    Edit;
    if TV1.DataController.Summary.FooterSummaryValues[7] <> NULL then
      FieldByName('YGGZ').Value := TV1.DataController.Summary.FooterSummaryValues[7]
    else
      FieldByName('YGGZ').Value := 0;
    if TV1.DataController.Summary.FooterSummaryValues[11] <> NULL then
      FieldByName('JTQty').Value := TV1.DataController.Summary.FooterSummaryValues[11]
    else
      FieldByName('JTQty').Value := 0;
    Post;
  end;

  if TV2.DataController.Summary.FooterSummaryValues[0] <> NULL then
    ZJJE.Text := TV2.DataController.Summary.FooterSummaryValues[0]
  else
    ZJJE.Text := '0';
end;

procedure TfrmXHGZListInPut.InitGZSub(MGZMainId: string);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* , BZMoney=(isnull(TXBZMoney,0)+isnull(CLBZMoney,0)) from GZListSub   A ');
    sql.Add(' where A.GZMainID=' + QUOTEDSTR(Trim(MGZMainId)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sub);
  SInitCDSData20(ADOQueryTemp, CDS_Sub);
end;

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

procedure TfrmXHGZListInPut.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid('绣花工日工资', Tv1, '工资管理');
  CRTime.DateTime := SGetServerDate10(ADOQueryTemp);
  if FBanCi = '白班' then
  begin
    lblBC.Caption := FBanCi;
    lblBC.Font.Color := clRed;
  end
  else
  begin
    lblBC.Caption := FBanCi;
    lblBC.Font.Color := clBlue;
  end;
  InitGrid();
  InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));

end;

procedure TfrmXHGZListInPut.v1Column10PropertiesEditValueChanged(Sender: TObject);
begin
  with CDS_Sub do
  begin
    Edit;
    FieldByName('ElseWage').Value := StrToFloat(TcxTextEdit(Sender).EditingText);
    FieldByName('Money').Value := FieldByName('OutputWage').AsFloat + FieldByName('ElseWage').AsFloat - FieldByName('KKMoney').AsFloat;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmXHGZListInPut.v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  price1: Double;
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ElseWageName';
      flagname := '其他工资项目';
      fnote := True;
      V1Note.Caption := '单价';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ElseWageName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          if TryStrToFloat(Trim(frmZDYHelp.ClientDataSet1.fieldbyname('Note').AsString), price1) then
            FieldByName('Price1').Value := price1
          else
            FieldByName('Price1').Value := 0;

        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXHGZListInPut.v2Column6PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FPDTiaoXian, FISM, FHXName: string;
  FMiShu, AZhenShu, FZhenShu, FPrice, FMoney, FOutputWage, FElseWage, FKKMoney: Double;
begin
  mvalue := Trim(TcxTextEdit(Sender).EditingText);
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Sub do
  begin
    edit;
    fieldbyname(FFieldName).value := mvalue;
    Post;
    FMiShu := fieldbyname('MiShu').AsFloat;
    FZhenShu := fieldbyname('ZhenShu').AsFloat;
    FElseWage := fieldbyname('ElseWage').AsFloat;
    FKKMoney := fieldbyname('KKMoney').AsFloat;
    FPDTiaoXian := Trim(fieldbyname('PDTiaoXian').AsString);
    FISM := trim(fieldbyname('ISM').AsString);
    FHXName := trim(fieldbyname('HXName').AsString);
  end;
  if FISM = '是' then
  begin
    FPrice := 0.5;
    FOutputWage := FMiShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end
  else
  begin
    if FPDTiaoXian = '是' then
    begin
      FPrice := 3.2;
    end
    else
    begin
      if Pos('横条', FHXName) > 0 then
      begin
        if FZhenShu < 33 then
          FPrice := 2.5
        else
          FPrice := 2.6;
      end
      else
      begin
        //if FMiShu<200 then
        begin
          with ADOQueryTemp do
          begin
            Close;
            SQL.Clear;
            SQL.Add('select * from KH_ZDY_TJList where ZdyName=''' + Trim(Self.CDS_Sub.fieldbyname('TouJu').AsString) + ''' ');
            Open;
          end;
          AZhenShu := ADOQueryTemp.fieldbyname('LJZhenShu').AsFloat;
          if FZhenShu < AZhenShu then
            FPrice := ADOQueryTemp.fieldbyname('Price1').AsFloat
          else
            FPrice := ADOQueryTemp.fieldbyname('Price2').AsFloat;
        end;
      end;
    end;
    FOutputWage := FZhenShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  if CDS_Sub.FieldByName('IFCLBZ').AsString = '是' then
  begin
    with CDS_Sub do
    begin
      edit;
      FieldByName('CLBZQty').Value := FZhenShu * 0.2;
      post;
    end;
    FOutputWage := FZhenShu * 1.2 * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('Price').Value := FPrice;
    FieldByName('OutputWage').Value := FOutputWage;
    FieldByName('Money').Value := FMoney - FKKMoney;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmXHGZListInPut.v1Column13PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FQty1, FPrice1, FMoney, FElseWage, FOutputWage, FKKMoney: Double;
begin
  mvalue := Trim(TcxTextEdit(Sender).EditingText);
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Sub do
  begin
    edit;
    fieldbyname(FFieldName).value := mvalue;
    Post;
    FQty1 := fieldbyname('Qty1').AsFloat;
    FPrice1 := fieldbyname('Price1').AsFloat;
    FOutputWage := fieldbyname('OutputWage').AsFloat;
    FKKMoney := fieldbyname('KKMOney').AsFloat;
  end;
  FElseWage := FQty1 * FPrice1;
  FMoney := FElseWage + FOutputWage;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('ElseWage').Value := FElseWage;
    FieldByName('Money').Value := FMoney - FKKMoney;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmXHGZListInPut.v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'XHNote';
      flagname := '备注信息';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('Note').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXHGZListInPut.v1Column21PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FPDTiaoXian, FISM, FHXName: string;
  FMiShu, AZhenShu, FZhenShu, FPrice, FMoney, FOutputWage, FElseWage, FKKMoney: Double;
begin
  mvalue := Trim(TcxTextEdit(Sender).EditingText);
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Sub do
  begin
    edit;
    fieldbyname(FFieldName).value := mvalue;
    Post;
    FPrice := fieldbyname('Price').AsFloat;
    FMiShu := fieldbyname('MiShu').AsFloat;
    FZhenShu := fieldbyname('ZhenShu').AsFloat;
    FElseWage := fieldbyname('ElseWage').AsFloat;
    FKKMoney := fieldbyname('KKMoney').AsFloat;
    FPDTiaoXian := Trim(fieldbyname('PDTiaoXian').AsString);
    FISM := trim(fieldbyname('ISM').AsString);
    FHXName := trim(fieldbyname('HXName').AsString);
  end;
  if FISM = '是' then
  begin
    FOutputWage := FMiShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end
  else
  begin
    FOutputWage := FZhenShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  if CDS_Sub.FieldByName('IFCLBZ').AsString = '是' then
  begin
    with CDS_Sub do
    begin
      edit;
      FieldByName('CLBZQty').Value := FZhenShu * 0.2;
      post;
    end;
    FOutputWage := FZhenShu * 1.2 * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('Price').Value := FPrice;
    FieldByName('OutputWage').Value := FOutputWage;
    FieldByName('Money').Value := FMoney - FKKMoney;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmXHGZListInPut.ToolButton3Click(Sender: TObject);
var
  maxno, str: string;
begin

  try
    frmYGListMoresel := TfrmYGListMoresel.Create(Application);
    with frmYGListMoresel do
    begin
      FCRTime := Self.FCRTime;
      FBanCi := Self.FBanCi;

      if ShowModal = 1 then
      begin
        with Order_FZ do
        begin
          First;
          while not Eof do
          begin
            with ADOQueryCmd do
            begin
              sql.Add('select * from GZListMain');
              sql.Add('where CRTime=' + QuotedStr(Self.FCRTime));
              sql.Add('and FBanCi=' + QuotedStr(Self.FBanCi));
              sql.Add('and YGName' + QuotedStr(Order_FZ.FieldByName('ZDYName').AsString));
              sql.Add(', YGName' + QuotedStr(Order_FZ.FieldByName('Note').AsString));
              sql.Add(', YGGongZhong' + QuotedStr(Order_FZ.FieldByName('note1').AsString));
            end;
            if ADOQueryCmd.IsEmpty then
            begin
              if GetLSNo(ADOQueryCmd, maxno, 'GZM', 'GZListMain', 4, 1) = False then
              begin
                Application.MessageBox('生成流水号异常！', '提示', 0);
                exit;
              end;
              with ADOQueryCmd do
              begin
                Close;
                SQL.Clear;
                sql.Add('insert into GZListMain(GZMainID,CRTime,BanCi,YGName,YGCode,YGGongZhong) ');
                sql.Add('values(' + QuotedStr(maxno));
                sql.Add(',' + QuotedStr(Self.FCRTime));
                sql.Add(',' + QuotedStr(FBanCi));
                sql.Add(',' + QuotedStr(Order_FZ.FieldByName('zdyname').AsString));
                sql.Add(',' + QuotedStr(Order_FZ.FieldByName('Note').AsString));
                sql.Add(',' + QuotedStr(Order_FZ.FieldByName('Note1').AsString));
                sql.Add(' )');
                ExecSQL;
              end;
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmYGListMoresel.Free;
  end;
  InitGrid();
  InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
  InitGZHZ();
end;

procedure TfrmXHGZListInPut.ToolButton5Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  try
    frmXHGZInPut := TfrmXHGZInPut.Create(Application);
    with frmXHGZInPut do
    begin
      PState := 0;
      FMainID := Trim(CDS_Main.fieldbyname('GZMainID').AsString);
      if ShowModal = 1 then
      begin
        InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
        InitGZHZ();
      end;
    end;
  finally
    frmXHGZInPut.Free;
  end;
end;

procedure TfrmXHGZListInPut.ToolButton6Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if Trim(CDS_Sub.fieldbyname('GZSubID').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;

    try
      ADOQueryCmd.Connection.BeginTrans;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' delete GZListSub where GZSubID=''' + Trim(CDS_Sub.fieldbyname('GZSubID').AsString) + '''');
        ExecSQL;
      end;
      ADOQueryCmd.Connection.CommitTrans;
      CDS_Sub.Delete;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('删除异常!', '提示', 0);
    end;
  end
  else
  begin
    CDS_Sub.Delete;
  end;
end;

procedure TfrmXHGZListInPut.ToolButton4Click(Sender: TObject);
begin
  if not CDS_Sub.IsEmpty then
  begin
    Application.MessageBox('请先删除明细数据!', '提示', 0);
    Exit;
  end;
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' delete GZListMain where GZMainID=''' + Trim(CDS_Main.fieldbyname('GZMainID').AsString) + '''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('删除异常!', '提示', 0);
  end;

end;

procedure TfrmXHGZListInPut.TV2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  lblYGName.Caption := Trim(CDS_Main.fieldbyname('YGName').AsString);
  InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
end;

procedure TfrmXHGZListInPut.ToolButton7Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  try
    frmXHGZInPut := TfrmXHGZInPut.Create(Application);
    with frmXHGZInPut do
    begin
      PCopyInt := 1;
      FMainID := Trim(CDS_Main.fieldbyname('GZMainID').AsString);
      FSubId := Trim(CDS_Sub.fieldbyname('GZSubID').AsString);
      if ShowModal = 1 then
      begin
        InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
        InitGZHZ();
      end;
    end;
  finally
    frmXHGZInPut.Free;
  end;
end;

procedure TfrmXHGZListInPut.ToolButton8Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  try
    frmXHGZInPut := TfrmXHGZInPut.Create(Application);
    with frmXHGZInPut do
    begin
      PState := 1;
      FMainID := Trim(CDS_Main.fieldbyname('GZMainID').AsString);
      FSubId := Trim(CDS_Sub.fieldbyname('GZSubID').AsString);
      if ShowModal = 1 then
      begin
        InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
        InitGZHZ();
      end;
    end;
  finally
    frmXHGZInPut.Free;
  end;
end;

procedure TfrmXHGZListInPut.N1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=''半天'',QJQty=0.5 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '半天';
      fieldbyname('QJQty').Value := 0.5;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;

end;

procedure TfrmXHGZListInPut.N2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=''一天'',QJQty=1 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '一天';
      fieldbyname('QJQty').Value := 1;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;
end;

procedure TfrmXHGZListInPut.N3Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=null,QJQty=0 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '';
      fieldbyname('QJQty').Value := 0;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;
end;

procedure TfrmXHGZListInPut.N4Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=''休假'',QJQty=0 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '休假';
      fieldbyname('QJQty').Value := 0;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;
end;

procedure TfrmXHGZListInPut.Button2Click(Sender: TObject);
begin
  WriteCxGrid('绣花工日工资', Tv1, '工资管理');
  Close;
end;

procedure TfrmXHGZListInPut.lblBCClick(Sender: TObject);
begin
  if lblBC.Caption = '白班' then
  begin
    FBanCi := '晚班';
    lblBC.Caption := '晚班';
    lblBC.Font.Color := clBlue;
  end
  else
  begin
    FBanCi := '白班';
    lblBC.Caption := '白班';
    lblBC.Font.Color := clRed;
  end;
  InitGrid();
  InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
  InitGZHZ();
end;

procedure TfrmXHGZListInPut.CRTimeChange(Sender: TObject);
begin
  FCRTime := Trim(FormatDateTime('yyyy-MM-dd', CRTime.DateTime));
  InitGrid();
  InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
  InitGZHZ();
end;

procedure TfrmXHGZListInPut.ToolButton1Click(Sender: TObject);
begin
  InitYGGZ();
  InitGrid();
  InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
  InitGZHZ();
end;

procedure TfrmXHGZListInPut.ToolButton2Click(Sender: TObject);
begin

  if CDS_Main.IsEmpty then
    Exit;

  try
    frmKouKuanInPut := TfrmKouKuanInPut.Create(Application);
    with frmKouKuanInPut do
    begin
      PState := 0;
      FMainID := Trim(CDS_Main.fieldbyname('GZMainID').AsString);
      if ShowModal = 1 then
      begin
        InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
        InitGZHZ();
      end;
    end;
  finally
    frmKouKuanInPut.Free;
  end;
end;

procedure TfrmXHGZListInPut.N5Click(Sender: TObject);
var
  FKHNote: string;
  FKHFenShu, i: Integer;
begin
  if CDS_Main.IsEmpty then
    exit;
  FKHNote := '';
  FKHFenShu := 0;
  i := 0;
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := 'KHNote';
      flagname := '考核条款';

      V1Note.Visible := True;
      V1Note.Caption := '扣分';

      if ShowModal = 1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean = True then
            begin
              FKHFenShu := FKHFenShu + FieldByName('Note').AsInteger;
              i := i + 1;
              FKHNote := FKHNote + inttostr(i) + '.' + trim(FieldByName('ZDYName').AsString) + ':' + FieldByName('Note').AsString + '; ';
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET KHNote=' + quotedstr(Trim(FKHNote)) + ',KHFenShu= ' + inttostr(FKHFenShu));
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('KHNote').Value := FKHNote;
      fieldbyname('KHFenShu').Value := FKHFenShu;
      Post;
    end;
  except
    application.MessageBox('考核失败！', '提示信息', 0);
  end;
end;

procedure TfrmXHGZListInPut.ToolButton9Click(Sender: TObject);
begin
  try
    frmWorkDetail := TfrmWorkDetail.Create(Application);
    with frmWorkDetail do
    begin
      FMainID := Trim(CDS_Main.fieldbyname('GZMainID').AsString);
      CXDate := Self.CRTime.Date;

      if ShowModal = 1 then
      begin
        lblYGName.Caption := Trim(CDS_Main.fieldbyname('YGName').AsString);
        InitGZSub(Trim(CDS_Main.fieldbyname('GZMainID').AsString));
      end;
    end;
  finally
    frmWorkDetail.Free;
  end;

end;

end.

