C# 在月历的选定日期存储用户输入

C# 在月历的选定日期存储用户输入,c#,winforms,forms,monthcalendar,C#,Winforms,Forms,Monthcalendar,我创建了一个表单,它接受用户输入的两条不同的信息(标题、位置、日期(来自monthCalendar)等),单击Add按钮时,信息存储在当前数组元素中,标题显示在列表框中。选择列表框中的标题后,该特定标题的其余信息将重新填充到相应的文本框中 我一直在努力向前迈进一步,但没有成功。单击Add按钮时,我希望将用户输入保存到monthCalendar上选择的日期。因此,如果用户单击的日期没有保存任何信息,列表框将保持为空。如果某个日期保存了信息,则列表框将显示标题 代码片段: class Meeting

我创建了一个表单,它接受用户输入的两条不同的信息(标题、位置、日期(来自monthCalendar)等),单击Add按钮时,信息存储在当前数组元素中,标题显示在列表框中。选择列表框中的标题后,该特定标题的其余信息将重新填充到相应的文本框中

我一直在努力向前迈进一步,但没有成功。单击Add按钮时,我希望将用户输入保存到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;
    }
}

公共部分类日历表单:表单
{
private MeetingManager mManager;//对业务层对象的引用
私有无效日历保存更改按钮单击(对象发送者,事件参数e)
{
尝试
{
mManager.Title=textBoxTitle.Text;
mManager.Location=textBoxLocation.Text;
mManager.StartTime=maskedstartimetextbox.Text;
mManager.EndTime=maskedEndTimeTextBox.Text;
mManager.Notes=notesTextBox.Text;
mManager.Add();
meetingListBox.Enabled=true;
meetingListBox.Items.Add(mManager);
//单击保存更改后清除文本框
textBoxTitle.Text=”“;
textBoxLocation.Text=”“;
maskedStartTimeTextBox.Text=”“;
maskedEndTimeTextBox.Text=”“;
notesTextBox.Text=“”;
}
捕获(ApplicationException ex)
{
MessageBox.Show(这个,比如Message);
}
}
/// 
///从列表框中选择会议后,将重新填充该会议
///包含存储在数组元素中的信息的空字段
/// 
/// 
/// 
私有作废会议列表框\u选择的索引已更改(对象发件人,事件参数e)
{
MeetingManager m=meetingListBox。选择EdItem作为MeetingManager;
如果(m!=null)
{
textBoxTitle.Text=m.Title;
textBoxLocation.Text=m.位置;
maskedStartTimeTextBox.Text=m.StartTime;
maskedEndTimeTextBox.Text=m.EndTime;
notesTextBox.Text=m.Notes;
}
}

}

嗯,我想你可以试试这样的东西:

class MeetingManager
{
    ...


    //add and implement a find method which returns a Meeting-object if there is a
 //corresponding meeting date (in private Meeting[] meetings;)

    public Meeting MeetingFinder(DateTime meetingTime)
    {
        //if there is a corresponding meeting-object for the date, return the meeting object
        //if there isn't, return null
    }

    ...
}


听起来有点乱。。。你能给我们看一些代码吗?…你到底想要什么?@HaunsTM添加了一些代码。。
class MeetingManager
{
    ...


    //add and implement a find method which returns a Meeting-object if there is a
 //corresponding meeting date (in private Meeting[] meetings;)

    public Meeting MeetingFinder(DateTime meetingTime)
    {
        //if there is a corresponding meeting-object for the date, return the meeting object
        //if there isn't, return null
    }

    ...
}
public partial class CalendarForm : Form
{

    ...

    private void monthCalendar_DateChanged(object sender, DateRangeEventArgs e)
    {
        //which date was selected?
            var selectedDate = monthCalendar.SelectionRange.Start;


        //do we have that date in the meetings?
        var meetingOnTheSelectedDate = mManager.MeetingFinder(selectedDate);

        if(meetingOnTheSelectedDate != null)
        {
            //populate your winform with the data from meetingOnTheSelectedDate
        }
    }

    ...

}