⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comdj.pas

📁 delphi作得信息业进销存源码.功能全面,运行稳定.
💻 PAS
📖 第 1 页 / 共 4 页
字号:
			if (ctrTmp is TEdit) then
				if TEdit(ctrTmp).Color = cl3DLight then
					TEdit(ctrTmp).Color := TPanel(ctrTmp.Parent).Color;
			if ctrTmp.Visible and (UpperCase(Copy(ctrTmp.Parent.Name, 1 , 5)) = 'PANEL') then
			begin
				CShape := TShape.Create(self);
				with CShape do
				begin
          Parent := ctrTmp.Parent;
          Top := ctrTmp.Top + ctrTmp.Height;
          Left := ctrTmp.Left;
          Width := ctrTmp.Width;
          Height := 1;
        end;
      end;
    end;
    if (ctrTmp is TLabel) and (ctrTmp.Tag = 1) then
    begin
      CShape := TShape.Create(self);
      with CShape do
      begin
        Parent := ctrTmp.Parent;
        Top := ctrTmp.Top + ctrTmp.Height;
        Left := ctrTmp.Left;
        Width := ctrTmp.Width;
        Height := 1;
      end;
    end;
  end;
  ToolBar2.Left := ControlBar1.Left + ControlBar1.Width - ToolBar2.Width - ToolBar3.Width;
  ToolBar3.Left := ControlBar1.Left + ControlBar1.Width - ToolBar3.Width;
  CanSave := false;
//HaveDetail
  if frmMain.ActiveMDIChild is TfrmComJbzl then
  begin
    strZbDetailTables := TfrmComJbzl(frmMain.ActiveMDIChild).strDetailTables;
    strZbDetailWheres := TfrmComJbzl(frmMain.ActiveMDIChild).strDetailWheres;
  end;
//State
  dsZb.ReadOnly := strState = 'V';
  dsMx.ReadOnly := strState = 'V';
  if (strState = 'A') or (strState = 'I') then
    aNew.Execute;
  if strState = 'V' then
  begin
    aSave.Tag := 1;
    aCancel.Tag := 1;
    aNew.Tag := 1;
    aDel.Tag := 1;
		aInsert.Tag := 1;
    aDelete.Tag := 1;
    DBGrid1.Options := DBGrid1.Options - [dgEditing];
  end
  else
    DBGrid1.Options := DBGrid1.Options + [dgEditing];
  IniRecord;
  if strState = 'V' then
  begin
    DBGrid1.SetFocus;
    DBGrid1.Options := DBGrid1.Options + [dgRowSelect];
  end
  else
    DBEdit1.SetFocus;
  screen.Cursor := crdefault;
end;

//DBGrid1EditButtonClick
procedure TfrmComDj.DBGrid1EditButtonClick(Sender: TObject);
begin
  if strState = 'V' then Exit;
  intGCIdx := DBGrid1.SelectedIndex;
end;

//Form.KeyDown
procedure TfrmComDj.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  intLastEditCol: integer;
  intTop, intLeft: integer;
begin
  case Key of
    VK_RETURN:
      if not (ActiveControl is TDBGrid) then   // not TDBGrid
      begin
        Key := 0;
        if Shift = [ssShift] then
        begin
          Perform(WM_NEXTDLGCTL, 1, 0);
          while (ActiveControl is TDBEdit) and (TDBEdit(ActiveControl).ReadOnly) do
            Perform(WM_NEXTDLGCTL, 1, 0);
        end
        else if Shift = [ssCtrl] then
        begin
          wcTmp := ActiveControl;
          DBGrid1.SetFocus;
        end
        else
        begin
          Perform(WM_NEXTDLGCTL, 0, 0);
          while (ActiveControl is TDBEdit) and (TDBEdit(ActiveControl).ReadOnly) do
            Perform(WM_NEXTDLGCTL, 0, 0);
        end;
      end
      else // is TDBGrid
        if Shift = [ssCtrl] then  // Ctrl + Return
					if wcTmp <> nil then
            wcTmp.SetFocus
          else
            Perform(WM_NEXTDLGCTL, 0, 0)
        else                      // Return
          with TDBGrid(ActiveControl) do
          begin
            if not (Shift = [ssShift]) then
            begin
              for intLastEditCol := FieldCount - 1 downto 0 do
                if not Columns[intLastEditCol].ReadOnly then
                  break;
              if (Columns[SelectedIndex].ReadOnly) or (DBGrid1.EditorMode) then
              begin
                Key := 0;
                repeat
                  SelectedIndex := SelectedIndex + 1;
                until (SelectedIndex >= intLastEditCol) or not (Columns[SelectedIndex].ReadOnly);
              end;
              if (SelectedIndex > intLastEditCol) or ((SelectedIndex = intLastEditCol) and DBGrid1.EditorMode) then
              begin
                DataSource.DataSet.Next;
                if DataSource.DataSet.Eof then
                  Datasource.DataSet.Append;
                for intLastEditCol := 0 to FieldCount - 1 do
                  if not Columns[intLastEditCol].ReadOnly then
                  begin
                    SelectedIndex := intLastEditCol;
                    Break;
                  end;
              end;
            end
            else
              repeat
                SelectedIndex := SelectedIndex - 1;
              until (SelectedIndex <= 0) or not (Columns[SelectedIndex].ReadOnly);
          end;
    VK_F4, VK_DOWN:
      begin
        if ActiveControl is TDBEdit then
          if (Key = VK_F4) or ((Key = VK_DOWN) and (Shift = [ssAlt])) then
          begin
            Key := 0;
            if Assigned(TDBEdit(screen.ActiveControl).OnDblClick) then
              TDBEdit(screen.ActiveControl).Perform(WM_LBUTTONDBLCLK, 0, 0)
            else if TDBEdit(screen.ActiveControl).Field is TStringField then
            begin
              frmSelect.DataSet := TDBEdit(screen.ActiveControl).DataSource.DataSet;
              frmSelect.FieldName := TDBEdit(screen.ActiveControl).DataField;
              frmSelect.ShowModal;
            end
            else if TDBEdit(screen.ActiveControl).Field is TDateTimeField then
            begin
              intTop := screen.ActiveControl.ClientOrigin.y + screen.ActiveControl.Height;
              if intTop + frmSetDate.Height > screen.Height then
                intTop := screen.ActiveControl.ClientOrigin.y - frmSetDate.Height - 2;
              intLeft := screen.ActiveControl.ClientOrigin.x - 2;
              if intLeft + frmSetDate.Width > screen.Width then
                intLeft := screen.Width - frmSetDate.Width - 2;
              frmSetDate.Top := intTop;
              frmSetDate.Left := intLeft;
              frmSetDate.DataSet := TDBEdit(screen.ActiveControl).DataSource.DataSet;
              frmSetDate.FieldName := TDBEdit(screen.ActiveControl).DataField;
              frmSetDate.CurDate := TDBEdit(screen.ActiveControl).Field.AsDateTime;
              frmSetDate.ShowModal;
            end
            else if TDBEdit(screen.ActiveControl).Field is TNumericField then
            begin
              intTop := screen.ActiveControl.ClientOrigin.y + screen.ActiveControl.Height;
              if intTop + frmSetCal.Height > screen.Height then
                intTop := screen.ActiveControl.ClientOrigin.y - frmSetCal.Height - 2;
              intLeft := screen.ActiveControl.ClientOrigin.x - 2;
              if intLeft + frmSetCal.Width > screen.Width then
                intLeft := screen.Width - frmSetCal.Width - 2;
              frmSetCal.Top := intTop;
              frmSetCal.Left := intLeft;
              frmSetCal.DataSet := TDBEdit(screen.ActiveControl).DataSource.DataSet;
              frmSetCal.FieldName := TDBEdit(screen.ActiveControl).DataField;
              frmSetCal.ShowModal;
            end;
          end;
        if ActiveControl is TDBLookupComboBox then
          if (Key = VK_F4) or ((Key = VK_DOWN) and (Shift = [ssAlt])) then
            TDBLookupComboBox(ActiveControl).DropDown;
        if ActiveControl is TDBGrid then
          if (Key = VK_F4) or ((Key = VK_DOWN) and (Shift = [ssAlt])) then
          begin
            Key := 0;
            if DBGrid1.Columns[DBGrid1.SelectedIndex].ButtonStyle = cbsEllipsis then
              DBGrid1EditButtonClick(ActiveControl)
            else if DBGrid1.Columns[DBGrid1.SelectedIndex].Field is TStringField then
            begin
              frmSelect.DataSet := DBGrid1.DataSource.DataSet;
              frmSelect.FieldName := DBGrid1.Columns[DBGrid1.SelectedIndex].FieldName;
              frmSelect.ShowModal;
            end
            else if DBGrid1.Columns[DBGrid1.SelectedIndex].Field is TDateTimeField then
            begin
              intTop := Panel1.ClientOrigin.y;
              intLeft := Panel1.ClientOrigin.x + Panel1.Width - frmSetDate.Width - DBGrid1.Left - 2;
              frmSetDate.Top := intTop;
              frmSetDate.Left := intLeft;
              frmSetDate.DataSet := DBGrid1.DataSource.DataSet;
              frmSetDate.FieldName := DBGrid1.Columns[DBGrid1.SelectedIndex].FieldName;
              frmSetDate.CurDate := DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsDateTime;
              frmSetDate.ShowModal;
            end
            else if DBGrid1.Columns[DBGrid1.SelectedIndex].Field is TNumericField then
            begin
              intTop := Panel1.ClientOrigin.y;
              intLeft := Panel1.ClientOrigin.x + Panel1.Width - frmSetCal.Width - DBGrid1.Left - 2;
              frmSetCal.Top := intTop;
              frmSetCal.Left := intLeft;
              frmSetCal.DataSet := DBGrid1.DataSource.DataSet;
              frmSetCal.FieldName := DBGrid1.Columns[DBGrid1.SelectedIndex].FieldName;
              frmSetCal.ShowModal;
            end;
          end;
      end;
    VK_LEFT, VK_RIGHT:
      if strState = 'V' then
        case Key of
          VK_LEFT:
            begin
              Key := 0;
              TDBGrid(Screen.ActiveControl).Perform(WM_HSCROLL, 0, 0);
            end;
          VK_RIGHT:
            begin
              Key := 0;
              TDBGrid(Screen.ActiveControl).Perform(WM_HSCROLL, 1, 0);
            end;
        end;
  end;
end;

//Form.Close
procedure TfrmComDj.FormClose(Sender: TObject; var Action: TCloseAction);
begin
	SaveColumnQuery;
	DBNavigator1.DataSource.OnStateChange := nil;
	DBNavigator1.DataSource.OnDataChange := nil;
	DBGrid1.DataSource.OnStateChange := nil;
	DBGrid1.DataSource.OnDataChange := nil;
	RestoreCDSEvents(dsZb, cdsZbEve);
	RestoreCDSEvents(dsMx, cdsMxEve);
	dsMx.Close;
end;

//Form.CloseQuery
procedure TfrmComDj.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if CanSave then
    CanClose := SaveQuery;
end;

//aSave.Execute
procedure TfrmComDj.aSaveExecute(Sender: TObject);
var
  blnPost: boolean;
  i: integer;
begin
  screen.Cursor := crHourGlass;
  try
    if dsMx.State in [dsInsert] then
    begin
      blnPost := True;
      for i := 0 to dsMx.FieldCount - 1 do
        if (strMxKeyFields <> '') and (Pos(UpperCase(dsMx.Fields[i].FieldName) + ';', strMxKeyFields) <> 0) then
          if (dsMx.Fields[i] is TStringField) and (dsMx.Fields[i].AsString = '')
            or (dsMx.Fields[i] is TNumericField) and (dsMx.Fields[i].AsFloat = 0)
            or (dsMx.Fields[i] is TDateTimeField) and (dsMx.Fields[i].value = null) then
            blnPost := false;
      if blnPost then
        dsMx.Post
      else
        dsMx.Cancel;
    end else if dsMx.State in [dsEdit] then
      dsMx.Post;
    if dsZb.State in [dsEdit, dsInsert] then
      dsZb.Post;
    if dsZb.ApplyUpdates(0) > 0 then
      Abort;
    MxBeforeApplyUpdates;
    if dsMx.ApplyUpdates(0) > 0 then
      Abort;
    CanSave := False;
    IniRecord;
  finally
    screen.Cursor := crdefault;
  end;
  if (strState = 'A') or (strState = 'I') then
    strState := 'M';
end;

//aCancel.Execute
procedure TfrmComDj.aCancelExecute(Sender: TObject);
var
  dsebScroll: TDataSetNotifyEvent;
begin
  dsebScroll := dszb.BeforeScroll;
  dszb.BeforeScroll := nil;
  try
    dsMx.CancelUpdates;
    dsZb.CancelUpdates;
    CanSave := false;
    IniRecord;
  finally
    dszb.BeforeScroll := dsebScroll;
  end;
end;

//aPreview.Execute
procedure TfrmComDj.aPreviewExecute(Sender: TObject);
var
  bmMx: TBookMark;
begin
  screen.Cursor := crHourGlass;
  blnPreview := true;
  aExit.ShortCut := 0;
  ReportName := '';
  with dsMx do
  begin
    bmMx := GetBookmark;
    DisableControls;
    LoadPrintForm;
    if rpt1 <> nil then
    begin
      rpt1.Preview;
      rpt1.Free;
      rpt1 := nil;
    end;
    try
      GotoBookmark(bmMx);
    finally
      FreeBookmark(bmMx);
      EnableControls;
    end;
  end;
  aExit.ShortCut := VK_ESCAPE;
  screen.Cursor := crDefault;
end;

//aPrint.Execute
procedure TfrmComDj.aPrintExecute(Sender: TObject);
var
  bmMx: TBookMark;
  iniFile: TIniFile;
begin
  screen.Cursor := crHourGlass;
  blnPreview := false;
  aExit.ShortCut := 0;
  iniFile := TiniFile.Create(ExtractFilePath(Application.ExeName) + 'System\DefRpt.ini');
  ReportName := iniFile.ReadString(self.Name, 'Name', '');
  iniFile.Free;
  with dsMx do
  begin
    bmMx := GetBookmark;
    DisableControls;
    LoadPrintForm;
    if rpt1 <> nil then
    begin
      rpt1.Print;
      rpt1.Free;
      rpt1 := nil;
    end;
    try
      GotoBookmark(bmMx);
    finally
      FreeBookmark(bmMx);
      EnableControls;
    end;
  end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -