Example #1
0
        /// <summary>
        /// This Function fetch Calendar detail from Gmail and insert in Appointment Table
        /// </summary>
        /// <param name="_calenderSer"></param>
        private void FetchCalender(CalendarService _calenderSer, Ctx ctx)
        {
            string sqlCategory       = "SELECT APPOINTMENTCATEGORY_ID FROM APPOINTMENTCATEGORY WHERE VALUE='Appointment' AND ISACTIVE='Y'";
            int    appointCategoryID = Util.GetValueOfInt(DB.ExecuteScalar(sqlCategory));

            try
            {
                Google.Apis.Calendar.v3.EventsResource ev = new EventsResource(_calenderSer, _authenticator);
                //ev.List(CalendarList.Id).SingleEvents = true;
                Events e = null;
                try
                {
                    e = ev.List("primary").Fetch(); //Fetch Calendar Events From Gmail which are Primary
                }
                catch (Exception ex)
                {
                    msg.Append(ex.Message);
                }

                if (e.Items == null)
                {
                    msg.Append("no Item Found");
                    return;
                }
                StringBuilder sql = new StringBuilder();

                if (e.Items.Count == 0)
                {
                    msg.Append("no Item Found");
                    return;
                }

                for (int i = 0; i < e.Items.Count; i++)
                {
                    try
                    {
                        VAdvantage.Model.MAppointmentsInfo ainfo = new VAdvantage.Model.MAppointmentsInfo(ctx, 0, null);

                        sql.Clear();
                        sql.Append("select  appointmentsinfo_id From APPOINTMENTSINFO ")
                        .Append(" where utaskid='" + e.Items[i].Id + "' and AD_User_ID=" + AD_User_ID);
                        DataSet ds = DB.ExecuteDataset(sql.ToString());
                        if (ds == null || ds.Tables[0].Rows.Count == 0)
                        {
                            ainfo.SetAD_Org_ID(AD_Org_ID);
                            ainfo.SetAD_Client_ID(AD_Client_ID);
                            ainfo.SetAD_User_ID(AD_User_ID);
                            ainfo.SetIsTask(false);
                            ainfo.SetUTaskID(e.Items[i].Id);
                            ainfo.SetAppointmentCategory_ID(appointCategoryID);
                            ainfo.SetStatus(3);

                            if (e.Items[i].Summary != null)
                            {
                                ainfo.SetSubject(e.Items[i].Summary);
                            }
                            if (e.Items[i].Description != null)
                            {
                                ainfo.SetDescription(e.Items[i].Description);
                            }
                            if (e.Items[i].Location != null)
                            {
                                ainfo.SetLocation(e.Items[i].Location);
                            }


                            if (e.Items[i].Visibility != null)
                            {
                                if (e.Items[i].Visibility.ToString().Equals("Private", StringComparison.OrdinalIgnoreCase))
                                {
                                    ainfo.SetIsPrivate(true);
                                }
                                else
                                {
                                    ainfo.SetIsPrivate(false);
                                }
                            }
                            else
                            {
                                ainfo.SetIsPrivate(false);
                            }

                            if (e.Items[i].Reminders != null)
                            {
                                Event.RemindersData rem = e.Items[i].Reminders;
                                if (rem != null)
                                {
                                    if (rem.Overrides != null)
                                    {
                                        IList <EventReminder> resmim = rem.Overrides;

                                        foreach (EventReminder r in resmim)
                                        {
                                            ainfo.SetReminderInfo(r.Minutes.ToString());
                                        }
                                    }
                                }
                            }
                            if (e.Items[i].Recurrence == null || e.Items[i].Recurrence.Count < 1)
                            {
                                EventDateTime dateStart = e.Items[i].Start;
                                if (dateStart.Date == null)
                                {
                                    DateTime startDate = Convert.ToDateTime(dateStart.DateTime);
                                    ainfo.SetStartDate(startDate.ToUniversalTime());
                                    ainfo.SetAllDay(false);
                                }
                                else
                                {
                                    ainfo.SetStartDate(Convert.ToDateTime(dateStart.Date).ToUniversalTime());
                                    ainfo.SetAllDay(true);
                                }

                                EventDateTime dateend = e.Items[i].End;
                                if (dateend.Date == null)
                                {
                                    DateTime endDate = Convert.ToDateTime(dateend.DateTime);
                                    ainfo.SetEndDate(endDate.ToUniversalTime());
                                    ainfo.SetAllDay(false);
                                }
                                else
                                {
                                    ainfo.SetEndDate(Convert.ToDateTime(dateend.Date).ToUniversalTime());
                                    ainfo.SetAllDay(true);
                                }
                            }
                            else
                            {
                                if (e.Items[i].Recurrence != null && e.Items[i].Recurrence.Count > 0)
                                {
                                    EventDateTime dateStart = e.Items[i].Start;
                                    EventDateTime dateend   = e.Items[i].End;

                                    if (e.Items[i].Start.Date == null)
                                    {
                                        DateTime sdate = Convert.ToDateTime(dateStart.DateTime);
                                        ainfo.SetStartDate(sdate.ToUniversalTime());
                                        ainfo.SetAllDay(false);
                                    }
                                    else
                                    {
                                        DateTime sdate = Convert.ToDateTime(dateStart.Date);
                                        ainfo.SetStartDate(sdate.ToUniversalTime());
                                        ainfo.SetAllDay(true);
                                    }

                                    if (e.Items[i].End.Date == null)
                                    {
                                        ainfo.SetEndDate(Convert.ToDateTime(dateend.DateTime).ToUniversalTime());
                                        ainfo.SetAllDay(false);
                                    }
                                    else
                                    {
                                        ainfo.SetEndDate(Convert.ToDateTime(dateend.Date).ToUniversalTime());
                                        ainfo.SetAllDay(true);
                                    }
                                    string recurenceRule = e.Items[i].Recurrence[0].Replace("RRULE:", "");
                                    ainfo.SetRecurrenceRule(recurenceRule);  //Save Recurrence rule
                                }
                            }
                            if (ainfo.Save())
                            {
                                sql.Clear();
                                sql.Append("Update APPOINTMENTSINFO set LastLocalUpdated=" + SetTime(ainfo.GetUpdated()) +
                                           " , Updated=" + SetTime(ainfo.GetUpdated()) + ", CreatedBY= " + AD_User_ID + ", UpdatedBy=" + AD_User_ID +
                                           ",LastGmailUpdated=" + GlobalVariable.TO_DATE(Convert.ToDateTime(e.Items[i].Updated), false) + " where APPOINTMENTSINFO_ID=" + ainfo.GetAppointmentsInfo_ID());
                                int result = DB.ExecuteQuery(sql.ToString());
                            }
                        }
                    }
                    catch (Exception exq)
                    {
                        msg.Append(exq.Message + " At no. " + i);
                    }
                }
            }
            catch (Exception ex)
            {
                msg.Append(ex.Message);
            }
        }
Example #2
0
        //  private void FetchTasks(TasksService _service, TaskList taskList)
        private void FetchTasks(TasksService _service, string taskList, Ctx ctx)
        {
            string sqlCategory       = "SELECT APPOINTMENTCATEGORY_ID FROM APPOINTMENTCATEGORY WHERE VALUE='Task' AND ISACTIVE='Y'";
            int    appointCategoryID = Util.GetValueOfInt(DB.ExecuteScalar(sqlCategory));
            var    tasks             = _service.Tasks.List(taskList).Fetch();

            if (tasks.Items == null)
            {
                //return "<i>No items</i>";
                return;
            }

            StringBuilder sql = new StringBuilder();

            for (int i = 0; i < tasks.Items.Count; i++)
            {
                sql.Clear();
                sql.Append("select  appointmentsinfo_id From APPOINTMENTSINFO ")
                .Append(" where utaskid='" + tasks.Items[i].Id + "' and AD_User_ID=" + AD_User_ID);
                DataSet ds = DB.ExecuteDataset(sql.ToString());
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    if (tasks.Items[i].Title != null && tasks.Items[i].Title != "" && tasks.Items[i].Completed == null)
                    {
                        VAdvantage.Model.MAppointmentsInfo ainfo = new VAdvantage.Model.MAppointmentsInfo(ctx, 0, null);
                        ainfo.SetAD_Org_ID(AD_Org_ID);
                        ainfo.SetAD_Client_ID(AD_Client_ID);
                        ainfo.SetIsTask(true);
                        ainfo.SetAppointmentCategory_ID(appointCategoryID);
                        if (tasks.Items[i].Completed == null)
                        {
                            ainfo.SetStatus(0);
                        }
                        else
                        {
                            ainfo.SetIsClosed(true);
                            ainfo.SetStatus(10);
                            ainfo.SetTaskStatus(10);
                        }
                        ainfo.SetAD_User_ID(AD_User_ID);
                        ainfo.SetSubject(tasks.Items[i].Title);
                        if (tasks.Items[i].Notes != null)
                        {
                            ainfo.SetDescription(tasks.Items[i].Notes);
                        }
                        ainfo.SetUTaskID(tasks.Items[i].Id);
                        if (tasks.Items[i].Due != null)
                        {
                            if (Convert.ToDateTime(tasks.Items[i].Updated) < Convert.ToDateTime(tasks.Items[i].Due))
                            {
                                ainfo.SetStartDate(Convert.ToDateTime(tasks.Items[i].Updated));
                            }
                            else
                            {
                                ainfo.SetStartDate(Convert.ToDateTime(tasks.Items[i].Due));
                            }
                        }
                        else
                        {
                            ainfo.SetStartDate(Convert.ToDateTime(tasks.Items[i].Updated));
                        }



                        if (tasks.Items[i].Due != null)
                        {
                            ainfo.SetEndDate(Convert.ToDateTime(tasks.Items[i].Due));
                        }
                        else
                        {
                            ainfo.SetEndDate(Convert.ToDateTime(tasks.Items[i].Updated));
                        }

                        if (ainfo.Save())
                        {
                            sql.Clear();
                            sql.Append("Update APPOINTMENTSINFO set LastLocalUpdated=" + SetTime(ainfo.GetUpdated()) +
                                       " , Updated=" + SetTime(ainfo.GetUpdated()) + ", CreatedBY= " + AD_User_ID + ", UpdatedBy=" + AD_User_ID +
                                       ",LastGmailUpdated=" + GlobalVariable.TO_DATE(Convert.ToDateTime(tasks.Items[i].Updated), false) + " where APPOINTMENTSINFO_ID=" + ainfo.GetAppointmentsInfo_ID());
                            int result = DB.ExecuteQuery(sql.ToString());
                        }
                    }
                }
            }
        }