2011-07-20 75 views
0

我遇到了我編寫的應用程序的問題。基本上它是一個月曆,是由每月的每一天的面板/列表框組成的。我使用下面的填充我的列表框:刪除或刷新數據表

private void PopulateEventListBoxes(int offsetNumber, int monthDays) 
{ 
    string locationSelected = this.LocationComboBox.Text.ToLower(); 

    for (int i = 0; i <= (monthDays - 1); i++) 
    { 
     DateTime dateSelected = Convert.ToDateTime(m_ArrayDateLabel[offsetNumber + i].Text).Date; 

     var tempCalendar = new Data.DataSet.vwGet_CalendarDetailsDataTable(); 

     switch (locationSelected) 
     { 
      case "all": 
       Data.Manager.CalendarDetailsTableAdapter.FillByDate(tempCalendar, dateSelected); 
       break; 
      default: 
       Data.Manager.CalendarDetailsTableAdapter.FillByDateCity(tempCalendar, dateSelected, locationSelected); 
       break; 
     } 

     foreach (Data.DataSet.vwGet_CalendarDetailsRow row in tempCalendar) 
     { 
      ((ListBox)m_ArrayEventListBox[offsetNumber + i]).Items.Add(row.Name + " - " + row.StatusCode); 
     } 
    } 
} 

我現在用的是var tempCalendar = new Data.DataSet.vwGet_CalendarDetailsDataTable();的數據表,因爲我需要一天的事件加載到每一個列表框的。這些數據來自SQL Server的視圖。

一旦日曆加載,用戶可以通過彈出對話框與日曆細節一天添加/修改/刪除項目的能力。當對話框負載添加/編輯我來填充它是這樣的:

private void SearchForEventsByDate() 
{ 
    switch (m_LocationSelected) 
    { 
     case "all": 
      Data.Manager.CalendarDetailsTableAdapter.FillByDate(DataSetCalendar.vwGet_CalendarDetails, m_DateSelected); 
      CalendarDetailsBindingSource.DataSource = DataSetCalendar.vwGet_CalendarDetails; 
      break; 
     default: 
      Data.Manager.CalendarDetailsTableAdapter.FillByDateCity(DataSetCalendar.vwGet_CalendarDetails, m_DateSelected, m_LocationSelected); 
      CalendarDetailsBindingSource.DataSource = DataSetCalendar.vwGet_CalendarDetails; 
      break; 
    } 

    RefreshRepRecordCount(); 
} 

這一次加載數據,我現在用的電話DataSetCalendar.vwGet_CalendarDetails,而不是數據表的臨時存儲版本時。

我的問題開始發揮作用,如果我請按照下列步驟:

  1. 爲僱員
  2. 添加新的事件刪除我只是說
  3. 嘗試和相同的事件再添加新的事件該員工在同一天 - 該應用程序會拋出GUID已存在於表中的錯誤。

我的表的主鍵是EVENTDATE和EmployeeGuid。如果我在刪除後查詢SQL表,沒有記錄,但我的應用程序仍然認爲該記錄仍然存在。我知道記錄在記憶中。

我曾嘗試以下從內存中刪除,但它不工作:

DataSetCalendar.vwGet_CalendarDetails.FindByEmployeeGUID(SelectedCalendarEvent.EmployeeGUID).Delete(); 
DataSetCalendar.vwGet_CalendarDetails.AcceptChanges(); 

我也用Remove擺脫創紀錄的,但我的應用程序仍然認爲記錄存在嘗試。我不知道還有什麼要做或嘗試。任何幫助都會很棒。

回答

0

我能夠通過添加Clear()

private void SearchForEventsByDate() 
{ 
    switch (m_LocationSelected) 
    { 
     case "all": 
     Data.Manager.Data.SM_T_Employee_Status.Clear(); 
     DataSetCalendar.vwGet_CalendarDetails.Clear(); 

     Data.Manager.CalendarDetailsTableAdapter.FillByDate(DataSetCalendar.vwGet_CalendarDetails, m_DateSelected); 
      CalendarDetailsBindingSource.DataSource = DataSetCalendar.vwGet_CalendarDetails; 
      break; 
     default: 
      Data.Manager.Data.SM_T_Employee_Status.Clear(); 
      DataSetCalendar.vwGet_CalendarDetails.Clear(); 
      Data.Manager.CalendarDetailsTableAdapter.FillByDateCity(DataSetCalendar.vwGet_CalendarDetails, m_DateSelected, m_LocationSelected); 
      CalendarDetailsBindingSource.DataSource = DataSetCalendar.vwGet_CalendarDetails; 
      break; 
    } 

RefreshRepRecordCount(); 
} 
0

你是如何「保存」在客戶端上的日曆嗎?知道這將導致你的答案。這聽起來像你在客戶端有一些類型的緩存。

如果緩存在客戶端,則需要刷新緩存,當您更改在服務器端的數據。

+0

不健全的愚蠢來解決這個問題,但我不是100%肯定。我們正在使用由我的部門中的某個人創建的Winforms模板/框架。我對整個事情的運作方式還很陌生。但是我知道我必須在記憶中刷新它,但是我沒能成功地做到這一點。 – Taryn

+0

詢問問題表明不愚蠢,因爲愚蠢的人不會問問題。不幸的是,至少在許多實現中,關於自主構建的框架是抽象概念並沒有經過深思熟慮。如果cahcing方法被封裝,則必須深入研究框架並確定如何使緩存失效。 –