0
我已經創建了一個表單,用於接受用戶輸入信息的幾個不同部分(標題,位置,日期(從月份日曆等)。),點擊添加按鈕時信息存儲在當前的數組元素中,標題顯示在列表框中。當選擇列表框中的標題時,該特定標題的其餘信息將重新填充到相應的文本框中。在月曆上的選定日期存儲用戶輸入
我一直在試圖讓這一步進一步沒有成功。當單擊添加按鈕時,我想將用戶輸入保存到monthCalendar上選擇的日期。因此,如果用戶點擊沒有保存信息的日期,則列表框仍爲空。如果有日期保存的信息,則列表框將顯示標題。
代碼片段:
class MeetingManager
{
private Meeting[] meetings;
public int currentIndex;
public int maxIndex;
private string title;
private string location;
private string startTime;
private string endTime;
private string notes;
public MeetingManager()
{
meetings = new Meeting[10];
currentIndex = -1;
maxIndex = -1;
}
// excluded getter/setters + basic error checking
public void Add()
{
try
{
if (maxIndex >= meetings.Length - 1)
{
throw new ApplicationException("YOU CAN ONLY CREATE 10 MEETINGS");
}
else
{
maxIndex++;
currentIndex = maxIndex;
Meeting temp = new Meeting(Title, Location, StartTime, EndTime, Notes);
meetings[maxIndex] = temp;
Title = meetings[maxIndex].Title;
Location = meetings[maxIndex].Location;
StartTime = meetings[maxIndex].StartTime;
EndTime = meetings[maxIndex].EndTime;
Notes = meetings[maxIndex].Notes;
}
}
catch (ApplicationException ex)
{
throw ex; // toss it up to the presentation
}
}
public void Add(string title, string location, string startTime, string endTime, string notes)
{
try
{
Title = title;
Location = location;
StartTime = startTime;
EndTime = endTime;
Notes = notes;
Add();
}
catch (ApplicationException ex)
{
throw ex;
}
}
public override string ToString()
{
return Title;
}
}
public partial class CalendarForm : Form
{
private MeetingManager mManager; // reference to business layer object
private void calendarSaveChangesButton_Click(object sender, EventArgs e)
{
try
{
mManager.Title = textBoxTitle.Text;
mManager.Location = textBoxLocation.Text;
mManager.StartTime = maskedStartTimeTextBox.Text;
mManager.EndTime = maskedEndTimeTextBox.Text;
mManager.Notes = notesTextBox.Text;
mManager.Add();
meetingListBox.Enabled = true;
meetingListBox.Items.Add(mManager);
//clears the textBoxes after clickng saveChanges
textBoxTitle.Text = "";
textBoxLocation.Text = "";
maskedStartTimeTextBox.Text = "";
maskedEndTimeTextBox.Text = "";
notesTextBox.Text = "";
}
catch (ApplicationException ex)
{
MessageBox.Show(this, ex.Message);
}
}
/// <summary>
/// When a meeting is selected from the listBox, it re-populates
/// the empty fields with the information stored in the array element
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void meetingListBox_SelectedIndexChanged(object sender, EventArgs e)
{
MeetingManager m = meetingListBox.SelectedItem as MeetingManager;
if (m != null)
{
textBoxTitle.Text = m.Title;
textBoxLocation.Text = m.Location;
maskedStartTimeTextBox.Text = m.StartTime;
maskedEndTimeTextBox.Text = m.EndTime;
notesTextBox.Text = m.Notes;
}
}
}
聽起來有點亂...你能告訴我們一些代碼嗎? – 2013-03-02 21:47:02
...究竟是什麼要求? – 2013-03-02 21:53:45
@HaunsTM已添加一些編碼。 – PrgmRNoob 2013-03-02 22:10:40