public List <ActivityData> GetsmmActivities(string company, string responsible)
        {
            List <ActivityData> actList = new List <ActivityData>();

            if (isTest)
            {
                WebOutlookCrmST.smmActivities.SMMACTIVITIESDataTable actDataTable = serviceSTG.GetsmmActivities(company, responsible);
                foreach (WebOutlookCrmST.smmActivities.SMMACTIVITIESRow row in actDataTable)
                {
                    ActivityData actData = new ActivityData(row);
                    actList.Add(actData);
                }
            }
            else
            {
                //company = "VAR";
                //responsible = "NRend";
                object[] results = serviceLIV.GetsmmActivities2(company, responsible);

                WebOutlookCrm.smmActivities.SMMACTIVITIESDataTable actDataTable = new WebOutlookCrm.smmActivities.SMMACTIVITIESDataTable();
                //actDataTable.DataSet.EnforceConstraints = false;
                //actDataTable = ((WebOutlookCrm.smmActivities.SMMACTIVITIESDataTable)(results[0]));
                try
                {
                    actDataTable =
                        serviceLIV.GetsmmActivities(company, responsible);
                }
                catch (ConstraintException ex)
                {
                    DataRow[] rowErrors = actDataTable.GetErrors();
                    System.Diagnostics.Debug.WriteLine("smmActivities Errors:"
                                                       + rowErrors.Length);

                    for (int i = 0; i < rowErrors.Length; i++)
                    {
                        System.Diagnostics.Debug.WriteLine(rowErrors[i].RowError);

                        foreach (DataColumn col in rowErrors[i].GetColumnsInError())
                        {
                            System.Diagnostics.Debug.WriteLine(col.ColumnName
                                                               + ":" + rowErrors[i].GetColumnError(col));
                        }
                    }
                }

                foreach (WebOutlookCrm.smmActivities.SMMACTIVITIESRow row in actDataTable)
                {
                    ActivityData actData = new ActivityData(row);
                    actList.Add(actData);
                }
            }

            return(actList);
        }
        public void SetAppointment(string _company, string _responsibleEployee)
        {
            bool isUpdateOutlookEntryID = false;
            int  taskProirity           = 0;
            int  sensitivity            = 0;
            int  activityTimeType       = 0;
            bool noSync    = false;
            bool noAddList = false;

            deletedCRMItemCounter = 0;
            updatedCRMItemCounter = 0;
            savedCRMItemCounter   = 0;

            insertedOutlookItemCounter = 0;
            deletedOutlookItemCounter  = 0;

            WebOutlookCrm.smmActivities.SMMACTIVITIESDataTable smmAct = service.GetsmmActivities(_company, _responsibleEployee);

            Outlook.AppointmentItem oAppointment = null;
            Outlook.Folder          calFolder    = null;

            //Outlook.NameSpace ns = outlookApp.GetNamespace("MAPI");
            //Outlook.MAPIFolder calFolder = ns.GetFolderFromID(outlookCalendarID, outlookCalendarStoreID);


            calFolder = GetFolder(outlookCalendarID, outlookCalendarStoreID);

            //Outlook.MAPIFolder folder = calFolder;

            foreach (WebOutlookCrm.smmActivities.SMMACTIVITIESRow item in smmAct)
            {
                if (log)
                {
                    service.WriteInfo("++++++WebService: foreach SetAppointment");
                    service.WriteInfo("++++++WebService: ActNumber: " + item.ACTIVITYNUMBER);
                }
                noSync       = false;
                noAddList    = false;
                oAppointment = null;
                bool insert = false;
                oAppointment = GetAppointment(item.OUTLOOKENTRYID, outlookCalendarStoreID);

                if (oAppointment == null)
                {
                    if (log)
                    {
                        service.WriteInfo("++++++WebService: oAppointment == null");
                        service.WriteInfo("++++++WebService: ActNumber: " + item.ACTIVITYNUMBER);
                    }

                    if (string.IsNullOrEmpty(item.OUTLOOKENTRYID))
                    {
                        isUpdateOutlookEntryID = true;
                        insert       = true;
                        oAppointment = (Outlook.AppointmentItem)calFolder.Items.Add(Outlook.OlItemType.olAppointmentItem);

                        if (log)
                        {
                            service.WriteInfo("++++++WebService: string.IsNullOrEmpty(item.OUTLOOKENTRYID)");
                            service.WriteInfo("++++++WebService: ActNumber: " + item.ACTIVITYNUMBER);
                            service.WriteInfo("++++++WebService: noSync: " + noSync);
                        }

                        //oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
                    }
                    else
                    {
                        // ez az ág mikor nem találja az outlookban viszont van OutlikEntryID-ja tehát az outlookból lett törölve
                        if (log)
                        {
                            service.WriteInfo("++++++WebService: string.IsNullOrEmpty(item.OUTLOOKENTRYID) != ");
                            service.WriteInfo("++++++WebService: ActNumber: " + item.ACTIVITYNUMBER);
                        }

                        noSync    = true;
                        insert    = false;
                        noAddList = service.DeleteActivity(item.OUTLOOKENTRYID, comapny);
                        //System.Windows.Forms.MessageBox.Show("The " + item.ACTIVITYNUMBER + " activities deleted!");
                        if (log)
                        {
                            service.WriteInfo("++++++WebService: " + "The " + item.ACTIVITYNUMBER + " activities deleted!");
                        }
                        deletedCRMItemCounter++;
                    }
                }
                else
                {
                    insert = false;

                    if (log)
                    {
                        service.WriteInfo("++++++WebService: oAppointment != null");
                        service.WriteInfo("++++++WebService: ActNumber: " + item.ACTIVITYNUMBER);
                    }

                    isUpdateOutlookEntryID = false;

                    if (oAppointment.LastModificationTime > item.MODIFIEDDATETIME.ToLocalTime())
                    {
                        if (IsdifferentRecord(oAppointment, item))
                        {
                            if (log)
                            {
                                service.WriteInfo("++++++WebService: oAppointment.LastModificationTime > item.MODIFIEDDATETIME.ToLocalTime()");
                                service.WriteInfo("++++++WebService: " + oAppointment.LastModificationTime + " " + item.MODIFIEDDATETIME.ToLocalTime());
                                service.WriteInfo("++++++WebService: ActNumber: " + item.ACTIVITYNUMBER);
                            }

                            taskProirity     = 0;
                            sensitivity      = 0;
                            activityTimeType = 0;

                            OutlookMgt.TASKPRIORITYConvertOutlookOlImportanceToInt(ref taskProirity, oAppointment);
                            OutlookMgt.SENSITIVITYConvertOutlookOlSensitivityToInt(ref sensitivity, oAppointment);
                            OutlookMgt.ACTIVITYTIMETYPEConvertOutlookOlBusyStatusToInt(ref activityTimeType, oAppointment);

                            noSync = service.UpdateActivity(oAppointment.Start.ToUniversalTime(),
                                                            oAppointment.End.ToUniversalTime(),
                                                            empId,
                                                            oAppointment.AllDayEvent,
                                                            oAppointment.BillingInformation,
                                                            oAppointment.Body,
                                                            oAppointment.Subject,
                                                            oAppointment.Categories,
                                                            taskProirity,
                                                            oAppointment.Location,
                                                            oAppointment.Mileage,
                                                            oAppointment.ReminderSet,
                                                            oAppointment.ReminderMinutesBeforeStart,
                                                            oAppointment.Resources,
                                                            oAppointment.ResponseRequested,
                                                            sensitivity,
                                                            activityTimeType,
                                                            networkAlias,
                                                            comapny,
                                                            oAppointment.EntryID,
                                                            item.ACTIVITYNUMBER);
                            if (log)
                            {
                                service.WriteInfo("++++++WebService: " + "The " + item.ACTIVITYNUMBER + " activities updated!");
                            }
                            updatedCRMItemCounter++;
                        }
                    }
                }

                if (!noSync)
                {
                    try
                    {
                        if (IsdifferentRecord(oAppointment, item))
                        {
                            if (log)
                            {
                                service.WriteInfo("++++++WebService: Create new appointment from activity: " + item.ACTIVITYNUMBER);
                            }

                            oAppointment.Subject            = item.PURPOSE.ToString();
                            oAppointment.Start              = Convert.ToDateTime(item.STARTDATETIME.ToLocalTime());
                            oAppointment.AllDayEvent        = Convert.ToBoolean(item.ALLDAY);
                            oAppointment.BillingInformation = item.BILLINGINFORMATION;
                            oAppointment.Body       = item.USERMEMO.ToString();
                            oAppointment.Categories = item.OUTLOOKCATEGORIES;
                            oAppointment.End        = Convert.ToDateTime(item.ENDDATETIME.ToLocalTime());
                            OutlookMgt.TASKPRIORITYConvertIntToOutlookOlImportance(item.TASKPRIORITY, ref oAppointment);
                            oAppointment.Location    = item.LOCATION;
                            oAppointment.Mileage     = item.MILEAGE;
                            oAppointment.ReminderSet = Convert.ToBoolean(item.REMINDERACTIVE);
                            oAppointment.ReminderMinutesBeforeStart = item.REMINDERMINUTES;
                            oAppointment.Resources         = item.OUTLOOKRESOURCES;
                            oAppointment.ResponseRequested = Convert.ToBoolean(item.RESPONSEREQUESTED);

                            OutlookMgt.SENSITIVITYIntToConvertOutlookOlSensitivity(item.SENSITIVITY, ref oAppointment);
                            OutlookMgt.ACTIVITYTIMETYPEConvertIntToOutlookOlBusyStatus(item.ACTIVITYTIMETYPE, ref oAppointment);

                            oAppointment.Save();

                            if (log)
                            {
                                service.WriteInfo("++++++WebService: Appointment saved.");
                                service.WriteInfo("++++++WebService: oAppointment Entry ID: " + oAppointment.EntryID);
                                service.WriteInfo("++++++WebService: CalFolder Store ID:" + calFolder.StoreID);
                            }
                            if (isUpdateOutlookEntryID)
                            {
                                service.UpdateActivityOutlookEntryId(item.ACTIVITYNUMBER, comapny, oAppointment.EntryID);
                            }

                            if (insert)
                            {
                                insertedOutlookItemCounter++;
                            }
                            else
                            {
                                savedOutlookItemCounter++;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Windows.Forms.MessageBox.Show(e.Message);
                    }
                }

                if (!noAddList)
                {
                    if (oAppointment.EntryID != null)
                    {
                        smmActivitiList.Add(oAppointment.EntryID, item.ACTIVITYNUMBER);
                    }
                }
            }

            this.SearchAppointments(calFolder);
        }