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

📄 office11grouprowstyledemomain.cpp

📁 DevExpress ExpressQuantumGrid Suite v5.9 Full Source
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include "shellapi.hpp"
#pragma hdrstop

#include "Office11GroupRowStyleDemoMain.h"
#include "Office11GroupRowStyleDemoData.h"
#include "AboutDemoForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxClasses"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDBData"
#pragma link "cxEdit"
#pragma link "cxFilter"
#pragma link "cxGraphics"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridDBTableView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxStyles"
#pragma link "cxButtons"
#pragma link "cxCheckBox"
#pragma link "cxContainer"
#pragma link "cxGridCardView"
#pragma link "cxGridDBCardView"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxMaskEdit"
#pragma link "cxSpinEdit"
#pragma link "cxTextEdit"
#pragma link "cxLookAndFeels"
#pragma link "cxCalendar"
#pragma link "cxDropDownEdit"
#pragma link "cxDataStorage"
#pragma link "cxImageComboBox"
#pragma resource "*.dfm"


const cxHoursPerDay   = 24;
const cxMinsPerDay    = cxHoursPerDay * 60;

TDateTime IncADay(const TDateTime AValue, const ANumberOfDays)
{
  return (AValue + ANumberOfDays);
}

TDateTime IncAHour(const TDateTime AValue, const __int64 ANumberOfHours)
{
  return ((double)AValue * cxHoursPerDay + ANumberOfHours) / cxHoursPerDay;
}

System::TDateTime IncAMinute(const System::TDateTime AValue,
  const __int64 ANumberOfMinutes)
{
  return ((double)AValue * cxMinsPerDay + ANumberOfMinutes) / cxMinsPerDay;
}

int DaysBetweenDates(const TDateTime ANow, const TDateTime AThen)
{
  if (ANow > AThen)
    return (int)(ANow - AThen);
  else
    return (int)(AThen - ANow);
}


TOffice11GroupRowStyleDemoMainForm *Office11GroupRowStyleDemoMainForm;
//---------------------------------------------------------------------------
__fastcall TOffice11GroupRowStyleDemoMainForm::TOffice11GroupRowStyleDemoMainForm(TComponent* Owner)
  : TForm(Owner)
{
  AddRecordsIntoTable();
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::miAboutClick(TObject *Sender)
{
  ShowAboutDemoForm();
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::miExitClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------


void __fastcall TOffice11GroupRowStyleDemoMainForm::tvMailDataControllerCompare(
      TcxCustomDataController *ADataController, int ARecordIndex1,
      int ARecordIndex2, int AItemIndex, const Variant &V1,
      const Variant &V2, int &Compare)
{
  if (((AItemIndex == tvMailSent->Index) && (tvMailSent->GroupIndex != -1)) ||
      ((AItemIndex == tvMailReceived->Index) && (tvMailReceived->GroupIndex != -1)))
    Compare = GetDateValueIndex(V1) - GetDateValueIndex(V2);
  else
    Compare = VarCompare(V1, V2);
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::tvMailSentGetDisplayText(
      TcxCustomGridTableItem *Sender, TcxCustomGridRecord *ARecord,
      AnsiString &AText)
{
  if(dynamic_cast<TcxGridGroupRow*>(ARecord) != 0)
    AText = GetGroupDateDisplayText(ARecord->Values[Sender->Index]);
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::tvMailStylesGetContentStyle(
      TcxCustomGridTableView *Sender, TcxCustomGridRecord *ARecord,
      TcxCustomGridTableItem *AItem, TcxStyle *&AStyle)
{
  if (dynamic_cast<TcxGridDataRow*>(ARecord) != 0){
    if (ARecord->Values[tvMailIcon->Index] == 0)
      AStyle = Office11GroupRowStyleDemoDataDM->UnreadStyle;
  }
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::miOffice11GroupRowStyleClick(TObject *Sender)
{
  ((TMenuItem*)Sender)->Checked = !((TMenuItem*)Sender)->Checked;
  tvMail->OptionsView->GroupRowStyle =
    (TcxGridGroupRowStyle)((TMenuItem*)Sender)->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::miAlwaysExpandedGroupsClick(TObject *Sender)
{
  ((TMenuItem*)Sender)->Checked = !((TMenuItem*)Sender)->Checked;
  if (((TMenuItem*)Sender)->Checked)
    tvMail->DataController->Options =
      tvMail->DataController->Options << dcoGroupsAlwaysExpanded;
  else
    tvMail->DataController->Options =
      tvMail->DataController->Options >> dcoGroupsAlwaysExpanded;
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::miGroupBySortingClick(TObject *Sender)
{
  ((TMenuItem*)Sender)->Checked = !((TMenuItem*)Sender)->Checked;
  tvMail->OptionsCustomize->GroupBySorting = ((TMenuItem*)Sender)->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::AddRecordIntoTable(int ARecordIndex)
{
  tvMail->DataController->SetValue(ARecordIndex, tvMailImportance->Index, GetImportance());
  tvMail->DataController->SetValue(ARecordIndex, tvMailIcon->Index, GetIcon());
  tvMail->DataController->SetValue(ARecordIndex, tvMailAttachment->Index, GetIcon());
  tvMail->DataController->SetValue(ARecordIndex, tvMailFrom->Index,
    Office11GroupRowStyleDemoDataDM->tblPersonsFullName->Text);
  tvMail->DataController->SetValue(ARecordIndex, tvMailSubject->Index, GetSubject());
  TDateTime ASent = GetSent();
  tvMail->DataController->SetValue(ARecordIndex, tvMailReceived->Index, GetReceived(ASent));
  tvMail->DataController->SetValue(ARecordIndex, tvMailSent->Index, ASent);
}
//---------------------------------------------------------------------------

void __fastcall TOffice11GroupRowStyleDemoMainForm::AddRecordsIntoTable()
{
  const RecordCount = 5;
  Randomize();
  tvMail->BeginUpdate();
  tblPersons()->DisableControls();
  try{
    tvMail->DataController->RecordCount = tblPersons()->RecordCount * RecordCount;
    tblPersons()->First();
    while (!tblPersons()->Eof){
      for (int J = 0; J < RecordCount; J++)
        AddRecordIntoTable((tblPersons()->RecNo - 1) * RecordCount + J);
      tblPersons()->Next();
    }
  }
  __finally{
    tblPersons()->EnableControls();
    tvMail->EndUpdate();
  }
}
//---------------------------------------------------------------------------

int TOffice11GroupRowStyleDemoMainForm::GetImportance()
{
  int Result = random(10);
  if (Result > 2)
    Result = 1;
  return Result;
}
//---------------------------------------------------------------------------

int TOffice11GroupRowStyleDemoMainForm::GetIcon()
{
  int Result = random(4);
  if (Result > 1)
    Result = 1;
  return Result;
}
//---------------------------------------------------------------------------

TDateTime TOffice11GroupRowStyleDemoMainForm::GetSent()
{
  TDateTime Result = Now();
  if(random(6) == 1)
    return Result;
  Result = IncADay(Result, -random(50));
  Result = IncAHour(Result, -random(4));
  Result = IncAMinute(Result, -random(60));
  return Result;
}
//---------------------------------------------------------------------------

TDateTime TOffice11GroupRowStyleDemoMainForm::GetReceived(TDateTime ASent)
{
  return IncAMinute(ASent, 10 + random(120));
}
//---------------------------------------------------------------------------

String TOffice11GroupRowStyleDemoMainForm::GetSubject()
{
  const Count = 21;
  const String Subjects[Count] = {
    "Implementing the Developer Express MasterView control into an Accounting System.",
    "Web Edition: Data Entry Page. The date validation issue.",
    "Payables Due Calculator. It is ready for testing.",
    "Web Edition: Search Page. It is ready for testing.",
    "Main Menu: Duplicate Items. Somebody has to review all the menu items in the system.",
    "Receivables Calculator. Where can I find the complete specs",
    "Ledger: Inconsistency. Please fix it.",
    "Receivables Printing. It is ready for testing.",
    "Screen Redraw. Somebody has to look at it.",
    "Email System. What library are we going to use?",
    "Adding New Vendors Fails. This module doesn't work properly!",
    "History. Will we track the sales history in our system?",
    "Main Menu: Add a File menu. File menu is missing!!!",
    "Currency Mask. The current currency mask is extremely inconvenient.",
    "Drag & Drop. In the schedule module drag & drop is not available.",
    "Data Import. What competitors databases will we support?",
    "Reports. The list of incomplete reports.",
    "Data Archiving. This features is still missing in our application",
    "Email Attachments. How to add multiple attachments? I can't see how to do it.",
    "Check Register. We are using different paths for different modules.",
    "Data Export. Our customers asked for export into Excel"};
  return Subjects[random(Count)];
}
//---------------------------------------------------------------------------

int __fastcall TOffice11GroupRowStyleDemoMainForm::GetDateValueIndex(TDateTime ADate)
{
  int ADaysBetween = DaysBetweenDates(Date(), (int)ADate);
  if (ADaysBetween == 0)
    return DateValueIndexToday;
  else
    if (ADaysBetween == 1)
      return DateValueIndexYesterday;
    else
      if (ADaysBetween < 7)
        return DateValueIndexLastWeek;
      else
        if (ADaysBetween < 14)
          return DateValueIndexTwoWeeksAgo;
        else
          return DateValueIndexOlder;
}
//---------------------------------------------------------------------------

String  __fastcall TOffice11GroupRowStyleDemoMainForm::GetGroupDateDisplayText(TDateTime ADate)
{
  const String DisplayText[] =
    {"Today", "Yesterday", "Last Week", "Two Weeks Ago", "Older"};
  return DisplayText[GetDateValueIndex(ADate)];
}
//---------------------------------------------------------------------------

TDataSet* __fastcall TOffice11GroupRowStyleDemoMainForm::tblPersons()
{
  return Office11GroupRowStyleDemoDataDM->tblPersons;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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