如何在VS2010中解决此问题?

时间:2015-10-23 13:10:30

标签: c# visual-studio-2010 outlook

我正在尝试创建一个Room Finder - 我在网站上看到的Outlook 2007加载项。

Room Finder - Outlook 2007 Add-in

但是我得到了一个我无法解决的错误。任何人都可以帮助我。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Interop.Outlook;

namespace Outlook2007AddIn
{
    partial class RoomFinderFormRegion
    {
        #region Form Region Factory

        [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Appointment)]
        [Microsoft.Office.Tools.Outlook.FormRegionName("Outlook2007AddIn.RoomFinderFormRegion")]
        public partial class RoomFinderFormRegionFactory
        {

            private string[] rooms = new string[] {
             "Conf Room 1",
             "Conf Room 2",
         };
            // Occurs before the form region is initialized.
            // To prevent the form region from appearing, set e.Cancel to true.
            // Use e.OutlookItem to get a reference to the current Outlook item.
            private void RoomFinderFormRegionFactory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
            {
            }
        }

        #endregion

        // Occurs before the form region is displayed.
        // Use this.OutlookItem to get a reference to the current Outlook item.
        // Use this.OutlookFormRegion to get a reference to the form region.
        private void RoomFinderFormRegion_FormRegionShowing(object sender, System.EventArgs e)
        {
        }

        // Occurs when the form region is closed.
        // Use this.OutlookItem to get a reference to the current Outlook item.
        // Use this.OutlookFormRegion to get a reference to the form region.
        private void RoomFinderFormRegion_FormRegionClosed(object sender, System.EventArgs e)
        {
        }

        private void btnSuggest_Click(object sender, EventArgs e)
        {
            try
            {
                var item = (Outlook.AppointmentItem)this.OutlookItem;
                var mapi = Globals.ThisAddIn.Application.GetNamespace("MAPI");
                mapi.Logon();
                // get appointment time info
                DateTime startOn = item.Start;
                DateTime endOn = item.End;
                //TODO: sort rooms based on floor, user preferences & people count
                string identifiedRoom = string.Empty;
                foreach (var room in rooms)
                {
                    //get meeting room's calendar properties
                    var resource = mapi.CreateRecipient(room);
                    bool isFree = resource.AddressEntry.GetFreeBusy(startOn, endOn);
                    if (isFree)
                    {
                        identifiedRoom = room;
                        break;
                    }
                }
                mapi.Logoff();
                if (!string.IsNullOrEmpty(identifiedRoom))
                {
                    item.Resources = identifiedRoom;
                    item.Location = identifiedRoom;
                }
                else
                {
                    MessageBox.Show("No rooms found for this time period! Please consider scheduling the appointment at another time.");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(string.Format("Error: {0}", ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation));
            }
        }
    }
}
public static class AppointmentHelper
{
    private const int DEFAULT_INTERVAL = 30;
    public static bool GetFreeBusy(this AddressEntry addressEntry, DateTime start, DateTime end)
    {
        string freeBusyInfo = addressEntry.GetFreeBusy(start.Date, DEFAULT_INTERVAL, false);
        int position = (int)start.TimeOfDay.TotalMinutes / DEFAULT_INTERVAL;
        TimeSpan ts = (end - start);
        int blocks = (int)ts.TotalMinutes / DEFAULT_INTERVAL;
        return freeBusyInfo.Substring(position, blocks).All(c => c.Equals('0'));
    }
}
  

错误1名称' rooms'在当前上下文中不存在c:\ visual studio 2010 \ Projects \ RoomFinder \ Outlook2007AddIn \ RoomFinderFormRegion.cs 62 38 Outlook2007AddIn

我有点失落。

2 个答案:

答案 0 :(得分:1)

将其拉出更高的范围

private string[] rooms = new string[] {
         "Conf Room 1",
         "Conf Room 2",
     };

您拥有RoomFinderFormRegionFactory成员,并且应该是RoomFinderFormRegion的成员。

答案 1 :(得分:1)

在我看来,房间的变量包含在特定方法中。要使类可以被类中的所有方法访问,它需要是整个类的全局变量。

private string[] rooms = new string[]partial class RoomFinderFormRegion移到M = dlmread(filename,delimiter,[R1 C1 R2 C2])下面的区域,它应该可以正常工作