當前位置:編程學習大全網 - 源碼下載 - devexpress tilebar control 怎麽綁定數據庫

devexpress tilebar control 怎麽綁定數據庫

這裏,我的解決辦法是,建兩個map,壹個從index 到uid,壹個相反。

然後,初始化時,以數據庫裏的信息來裝載。

當用戶需要改變時,在彈出的對話框前,對數據做點手腳,這樣看起來就壹直對了。

代碼

declare two map:

[csharp] view plain copy

int[] arLabelToWorkTypeId ;

Dictionary<int, int> mapWorktypeId2LabelIndex=null;

load labes from database when from load:

[csharp] view plain copy

private void Your_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'schedulerDBDataSet.Resources' table. You can move, or remove it, as needed.

this.resourcesTableAdapter.Fill(this.schedulerDBDataSet.Resources);

// TODO: This line of code loads data into the 'schedulerDBDataSet.Appointments' table. You can move, or remove it, as needed.

this.appointmentsTableAdapter.Fill(this.schedulerDBDataSet.Appointments);

InitializeLabels();

//////////////////////////////////////////////////////////////////////////

schedulerControl.ActiveViewType = DevExpress.XtraScheduler.SchedulerViewType.Timeline;

schedulerControl.GroupType = SchedulerGroupType.Resource;

AdjustResourceHeaders();

cbView.EditValue = schedulerControl.ActiveViewType;

cbGrouping.EditValue = schedulerControl.GroupType;

}

private void InitializeLabels()

{

this.workTypeTableAdapter.Fill(this.schedulerDBDataSet.WorkType);

DataTable labels = this.schedulerDBDataSet.WorkType;

if (labels.Rows.Count == 0)

return;

schedulerControl.Storage.Appointments.Labels.Clear();

schedulerControl.Storage.Appointments.Labels.BeginUpdate();

arLabelToWorkTypeId = new int[labels.Rows.Count];

mapWorktypeId2LabelIndex = new Dictionary<int, int>();

for (int i = 0; i < labels.Rows.Count; i++)

{

Color color = Color.FromArgb(Int32.Parse(labels.Rows[i]["Color"].ToString()));

string dislayName = labels.Rows[i]["name"].ToString();

string menuCaption = labels.Rows[i]["name"].ToString();

AppointmentLabel aptLabel = new AppointmentLabel(color, dislayName, menuCaption);

schedulerControl.Storage.Appointments.Labels.Add(aptLabel);

arLabelToWorkTypeId[i] = int.Parse(labels.Rows[i]["WorktypeID"].ToString());

mapWorktypeId2LabelIndex.Add(arLabelToWorkTypeId[i],i);

}

schedulerControl.Storage.Appointments.Labels.EndUpdate();

}

[csharp] view plain copy

private void schedulerControl_EditAppointmentFormShowing(object sender, AppointmentFormEventArgs e)

{

DevExpress.XtraScheduler.SchedulerControl scheduler = ((DevExpress.XtraScheduler.SchedulerControl)(sender));

//appoint make a copy

DevExpress.XtraScheduler.Appointment tmpAppointment = e.Appointment;

//converty to worktype

int originalId = tmpAppointment.LabelId;

int labelIdx=0;

if (true == mapWorktypeId2LabelIndex.TryGetValue(tmpAppointment.LabelId,out labelIdx))

{

tmpAppointment.LabelId = labelIdx;

}

DevExpress.XtraScheduler.Demos.Modules.CustomAppointmentForm form = new DevExpress.XtraScheduler.Demos.Modules.CustomAppointmentForm(scheduler, tmpAppointment, e.OpenRecurrenceForm);

try

{

e.DialogResult = form.ShowDialog();

if (DialogResult.OK == e.DialogResult)

{

e.Appointment.LabelId = arLabelToWorkTypeId[tmpAppointment.LabelId];

}

else

{

e.Appointment.LabelId = originalId;

}

e.Handled = true;

}

finally

{

form.Dispose();

}

}

//新生成壹個

private void schedulerControl_InitNewAppointment(object sender, AppointmentEventArgs e)

{

//賦到第壹個值

e.Appointment.LabelId = arLabelToWorkTypeId[0];

}

  • 上一篇:MFCE程序源代碼
  • 下一篇:Iphone 6 plus剛買的,有個小卡。這正常嗎?
  • copyright 2024編程學習大全網