Beispiel #1
0
        public List <QueData> GetQue(QueObj id)

        {
            QueManager userManager = new QueManager();

            return(userManager.GetQue(id));
        }
Beispiel #2
0
        public List <QueData> GetQue(QueObj que)

        {
            List <QueData> lst = new List <QueData>();

            //QueDataWrapper queWrapper = new QueDataWrapper();



            if (que.isUser)

            {
                if (!IsUserExist(que.guid))

                {
                    //Logger.Write("Error user doesnt exists");

                    //queWrapper.Message = "ארעה שגיאה";

                    return(lst);
                }
            }

            else

            {
                if (!IsCustomerExist(que.guid))

                {
                    //Logger.Write("Error customer doesnt exists");

                    //queWrapper.Message = "ארעה שגיאה";

                    return(lst);
                }
            }

            try

            {
                DataBaseRetriever db = new DataBaseRetriever(ConfigManager.ConnectionString);

                string select = "";
                if (que.isUser)
                {
                    select = "Case when g.Name is not null then U.Name + ' ' +g.Name Else U.Name + ' ' + B.Name End ";
                }
                else
                {
                    select = "CASE When B.Id=@CustomerId THEN Case when U.Name + ' ' +g.Name is not null then g.Name Else U.Name End ELSE N'תפוס' END ";
                }

                var sql = @"SELECT A.[CustomerId],A.id,A.[QueType], " + select + @" As [title],A.FromDate As [start],A.ToDate As [end],U.[color] as backgroundColor

                        FROM Que A INNER JOIN Customer B on A.CustomerId = B.Id
                        JOIN UsersActivitiesTypes U ON U.Id = A.QueType
                        Left join [Groups] g on A.GroupId = g.Id
                        WHERE A.UserId = @UserId And EmployeeId = @EmployeeId And FromDate>=@FromDate And ToDate<=@ToDate

                        ORDER BY start asc";



                IEnumerable <QueData> QueDataRows = db.QueryData <QueData>(sql, 1, new { UserId = que.UserId, FromDate = que.FromDate, ToDate = que.ToDate, CustomerId = que.CustomerId, EmployeeId = que.EmployeeId });

                var sqlEmp = "Select * FROM UsersActivity WHERE EmployeeId=@EmployeeId And UserId=@UserId";// And ActiveHourFromNone is not null

                IEnumerable <QueActiveData> BusyQue = db.QueryData <QueActiveData>(sqlEmp, 1, new { EmployeeId = que.EmployeeId, UserId = que.UserId });
                if (BusyQue.Count() > 0)
                {
                    var sqlExtraEmp = "Select * FROM [UserExtraActivity] WHERE EmployeeId=@EmployeeId And UserId=@UserId";// And ActiveHourFromNone is not null
                    IEnumerable <UserExtraActivity> extra             = db.QueryData <UserExtraActivity>(sqlExtraEmp, 1, new { EmployeeId = que.EmployeeId, UserId = que.UserId });
                    List <UserExtraActivity>        userExtraActivity = new List <UserExtraActivity>();
                    foreach (UserExtraActivity extraAct in extra)
                    {
                        UserExtraActivity userExtra = new UserExtraActivity();
                        userExtra = extraAct;
                        userExtraActivity.Add(userExtra);
                    }

                    var totalDays = (que.ToDate - que.FromDate).TotalDays;

                    Dictionary <int, QueActiveData> dicQ = new Dictionary <int, QueActiveData>();
                    foreach (QueActiveData q in BusyQue)
                    {
                        if (!dicQ.ContainsKey(q.ActiveDay))
                        {
                            dicQ.Add(q.ActiveDay, q);
                        }
                    }

                    if (totalDays <= 1)
                    {
                        int currentDay = GetCurrentDay(que.FromDate);
                        if (dicQ.ContainsKey(currentDay))
                        {
                            if (dicQ[currentDay].ActiveHourFromNone.Year != 1 && !HebrewCalendarManager.IsDateInHoliday(que.FromDate) && !IsDateInDateList(que.FromDate, userExtraActivity))
                            {
                                QueData qData = new QueData();
                                qData.start           = dicQ[currentDay].ActiveHourFromNone;
                                qData.end             = dicQ[currentDay].ActiveHourToNone;
                                qData.title           = "תפוס";
                                qData.backgroundColor = "#870A30";
                                lst.Add(qData);
                            }
                        }
                        else
                        {
                            if (!HebrewCalendarManager.IsDateInHoliday(que.FromDate))
                            {
                                QueData qData = new QueData();
                                qData.start           = que.FromDate.Date + new TimeSpan(0, 0, 0);
                                qData.end             = que.FromDate.Date + new TimeSpan(23, 59, 0);
                                qData.title           = "תפוס";
                                qData.backgroundColor = "#870A30";
                                lst.Add(qData);
                            }
                        }
                    }
                    if (totalDays > 6 && totalDays <= 7)
                    {
                        DateTime dt = StartOfWeek(que.FromDate.Date, DayOfWeek.Sunday);
                        for (int i = 1; i <= 7; i++)
                        {
                            if (dicQ.ContainsKey(i))
                            {
                                if (dicQ[i].ActiveHourFromNone.Year != 1 && !HebrewCalendarManager.IsDateInHoliday(dt) && !IsDateInDateList(dt, userExtraActivity))
                                {
                                    QueData qData = new QueData();

                                    TimeSpan tsFrom = new TimeSpan(dicQ[i].ActiveHourFromNone.Hour, dicQ[i].ActiveHourFromNone.Minute, 0);
                                    qData.start = (dt + tsFrom);

                                    TimeSpan tsTo = new TimeSpan(dicQ[i].ActiveHourToNone.Hour, dicQ[i].ActiveHourToNone.Minute, 0);
                                    qData.end             = (dt + tsTo);
                                    qData.title           = "תפוס";
                                    qData.backgroundColor = "#870A30";
                                    lst.Add(qData);
                                }
                            }
                            else
                            {
                                if (!HebrewCalendarManager.IsDateInHoliday(dt) && !IsDateInDateList(dt, userExtraActivity))
                                {
                                    QueData qData = new QueData();
                                    qData.start           = dt + new TimeSpan(0, 0, 0);
                                    qData.end             = dt + new TimeSpan(23, 59, 0);
                                    qData.title           = "תפוס";
                                    qData.backgroundColor = "#870A30";
                                    lst.Add(qData);
                                }
                            }
                            dt = dt.AddDays(1);
                        }
                    }
                    if (totalDays > 7)
                    {
                        var startDate = new DateTime(que.FromDate.Year, que.FromDate.Month, 1);
                        //var endDate = startDate.AddMonths(1).AddDays(-1);
                        for (int i = 0; i < totalDays; i++)
                        {
                            int currentDay = GetCurrentDay(startDate);
                            if (dicQ.ContainsKey(currentDay))
                            {
                                if (dicQ[currentDay].ActiveHourFromNone.Year != 1 && !HebrewCalendarManager.IsDateInHoliday(startDate))
                                {
                                    QueData qData = new QueData();

                                    TimeSpan tsFrom = new TimeSpan(dicQ[currentDay].ActiveHourFromNone.Hour, dicQ[currentDay].ActiveHourFromNone.Minute, 0);
                                    qData.start = (startDate + tsFrom);

                                    TimeSpan tsTo = new TimeSpan(dicQ[currentDay].ActiveHourToNone.Hour, dicQ[currentDay].ActiveHourToNone.Minute, 0);
                                    qData.end = (startDate + tsTo);
                                    string fromHour = dicQ[currentDay].ActiveHourFromNone.Hour.ToString();
                                    string fromMin  = dicQ[currentDay].ActiveHourFromNone.Minute.ToString();
                                    string toHour   = dicQ[currentDay].ActiveHourToNone.Hour.ToString();
                                    string toMin    = dicQ[currentDay].ActiveHourToNone.Minute.ToString();

                                    //fromMin = fromMin=="0" ? fromMin += "00" : fromMin;
                                    //toHour = toHour.EndsWith(":0") ? toHour += "00" : toHour;
                                    //toMin = toMin == "0" ? toMin += "0" : toMin;
                                    qData.title           = "תפוס" + " מ " + fromHour + ":" + fromMin + " עד " + toHour + ":" + toMin;
                                    qData.backgroundColor = "#870A30";
                                    lst.Add(qData);
                                }
                            }
                            else
                            {
                                if (!HebrewCalendarManager.IsDateInHoliday(startDate) && !IsDateInDateList(startDate, userExtraActivity))
                                {
                                    QueData qData = new QueData();
                                    qData.start           = startDate + new TimeSpan(0, 0, 0);
                                    qData.end             = startDate + new TimeSpan(23, 59, 0);
                                    qData.title           = "תפוס";
                                    qData.backgroundColor = "#870A30";
                                    lst.Add(qData);
                                }
                            }
                            startDate = startDate.AddDays(1);
                        }
                    }
                }

                if (QueDataRows.Count() > 0)
                {
                    lst.AddRange(QueDataRows);
                }

                List <QueData> hebList = HebrewCalendarManager.GetHeb(que.FromDate, que.ToDate);
                if (hebList.Count > 0)
                {
                    lst.AddRange(hebList);
                }
            }

            catch (Exception ex)

            {
                Logger.Write("QueManager:GetQue:" + ex);

                //queWrapper.Message = "ארעה שגיאה";
            }



            return(lst);
        }