본문으로 바로가기

[C#] DEVEXPRESS GANTT

category 개발 2018. 8. 17. 14:32

To create an application to enable the Gantt View functionality, follow the instructions below.

Expanded Steps 1-4. Create a New Project.

  1. Create a new Visual C# Windows project.
  2. Drop the SplitContainerControl from the DX.18.1: Navigation & Layout tab in the Toolbox onto the form. Click Dock in Parent Container smart tag to fill the form.
  3. Drop the SchedulerControl control from the DX.18.1: Scheduling tab in the Toolbox onto the right panel of the SplitContainer. Use the smart tag to dock it to fill the container.
  4. Drop the ResourcesTree control from the DX.18.1: Scheduling tab in the Toolbox onto the left panel of the SplitContainer. Click its smart tag and select Dock in Parent Container.

Expanded Steps 5-9. Create a Database.

  1. In the Tools menu of the Visual Studio IDE select Connect to Database.... The Add Connection dialog is invoked.

    Type in a name of the new database file - GantTest, as illustrated in the picture above. Click OK to create a new database and a connection.

  2. In the Server Explorer window right-click the newly created data connection and select New Query to open a Query editor window that allows you to enter and execute scripts for this database.

  3. Switch to the form with the SchedulerControl, select the Scheduler Control, and click the smart tag icon at the top right of the control () to display its actions list. Click the Create Sample Database for Gantt Viewitem to invoke a window that contains SQL script. Click the Copy to Clipboard and Close button.

  4. Switch to the SQLQuery window and paste the script in a window. Click Execute

  5. Next, fill the Resource table with sample data. To do this, copy the script from the Hierarchical Resource Specifics document starting from SET IDENTITY_INSERT. Delete the content of the previous script in the query window, paste the new one and click Execute.

Expanded Steps 9-12. Bind a SchedulerControl to a database.

  1. Use the Project/Add New Data Source menu command in Visual Studio to invoke a Data Source Configuration wizard. Specify the database connection string and include tables for resources, appointments and dependencies (Resources, Tasks and TaskDependencies tables in our example). Specify the name for the dataset - GantTestDataSet.

  2. Click the Scheduler control's smart tag and specify the Appointments table in the GantTestDataSet as the Appointments Data Source.

  3. The Mappings Wizards (Setup Appointment Storage dialog) is invoked automatically. Select the Gantt view mappings checkbox to map fields containing the appointment identifier and Percent Complete value. Use Clear and Generate buttons to generate mappings automatically.

    The picture below illustrates the Mappings Wizard window for appointment mappings.

    Afterwards you can also click the Mappings Wizard... link for the data source to invoke the wizard to make sure that all required mappings are specified.

  4. Click the Scheduler control's smart tag and specify the Resources table in the GantTestDataSet as the Resources Data Source.

    The picture below illustrates the Wizard window invoked for resource mappings. The ParentID field contains the identifier of the parent resource node for the current resource node. It is used to build a resource tree.

  5. Click the Mappings Wizard... link for Resources data source and then Next to navigate to Custom Properties Mapping dialog. Map IdSort field to a corresponding custom property of a resource as illustrated below.

  6. Click the Scheduler control's smart tag and specify the TaskDependencies table in the GantTestDataSet as the AppointmentDependencies Data Source.

    The picture below illustrates the Wizard window invoked for dependency mappings. For more information on dependencies review the Dependencies article.

Expanded Steps 10-11. Adjust ResourcesTree settings.

  1. In Visual Studio Designer, open the ResourcesTree control's smart tag and click Run Designer. The Tree List Designer is invoked. Double-click IdSortId and Description fields in the field list to add them to the list of displayed columns.
  2. If the field list is empty, set the Scheduler Control combo box in the ResourcesTree control's smart tag to (none), then to the schedulerControl1 again. This action forces the Resource Tree to retrieve field names form the SchedulerControl.

  3. Move the IdSort field to the top of the list so it becomes the principal sort field, specify its sort order and hide the IdSort and Id fields by setting their Visible property to false.

Expanded Step 12. Modify Table Adapter settings.

In this example, table adapters are created automatically using Visual Studio wizards. This technique ensures that all Insert, Update and Delete statements are generated automatically and the identity fields are treated properly. Nevertheless, XtraScheduler specifics require modification of the data set, as shown in the following picture.

  1. Set the Read-Only property to false for identity fields in the Appointments and TaskDependencies tables: namely, for the UniqueId field in the Appointments table and for the Id field in the TaskDependencies table.

Expanded Step 13. 스크립트는 아래와 같이.적용.

C#:Form1.cs

/// <summary>

/// 스케줄컨트롤 설정 /// </summary> private void SetScheduleControlInit() { this.tB_PP_1010_TaskDependenciesTableAdapter.Fill(this.dMC_DEVDataSet.TB_PP_1010_TaskDependencies); this.tB_PP_1010_ResourcesTableAdapter.Fill(this.dMC_DEVDataSet.TB_PP_1010_Resources); this.tB_PP_1010_AppointmentsTableAdapter.Fill(this.dMC_DEVDataSet.TB_PP_1010_Appointments); schedulerStorage1.Appointments.CommitIdToDataSource = false; this.tB_PP_1010_AppointmentsTableAdapter.Adapter.RowUpdated += new SqlRowUpdatedEventHandler(appointmentsTableAdapter_RowUpdated); o.ActiveViewType = SchedulerViewType.Gantt; o.GroupType = SchedulerGroupType.Resource; o.GanttView.CellsAutoHeightOptions.Enabled = true; // Hide unnecessary visual elements. o.GanttView.ShowResourceHeaders = false; o.GanttView.NavigationButtonVisibility = NavigationButtonVisibility.Never; //ROW사이즈 결정. o.GanttView.ResourcesPerPage = (this.o.Size.Height - 100) / 30; // 일, 주, 월 축소시 타임 아이콘이 앞뒤에 표시 제거. o.Views.GanttView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never; o.Views.GanttView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never; // 일, 주, 월 축소시 1셀에맞도록표기되는 블럭을 쪼개는 설정 없애기. o.Views.GanttView.AppointmentDisplayOptions.SnapToCellsMode = AppointmentSnapToCellsMode.Disabled; } /// <summary> /// 리소스트리 설정 /// </summary> private void SetResourceTreeInit() { resourcesTree1.OptionsView.ShowAutoFilterRow = true; resourcesTree1.OptionsBehavior.EnableFiltering = true; resourcesTree1.OptionsBehavior.Editable = false; }



        void CommitTask()
        {
            tB_PP_1010_AppointmentsTableAdapter.Update(dMC_DEVDataSet);
            this.dMC_DEVDataSet.AcceptChanges();
        }
        void CommitTaskDependency()
        {
            tB_PP_1010_TaskDependenciesTableAdapter.Update(this.dMC_DEVDataSet);
            this.dMC_DEVDataSet.AcceptChanges();
        }

        int id = 0;
        private void appointmentsTableAdapter_RowUpdated(object sender, SqlRowUpdatedEventArgs e)
        {
            if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
            {
                id = 0;
                using (SqlCommand cmd = new SqlCommand("SELECT @@IDENTITY", tB_PP_1010_AppointmentsTableAdapter.Connection))
                {
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                    e.Row["UniqueId"] = id;
                }
            }
        }

Expanded run.