示例#1
0
        private async void WeekGridView_Drop(object sender, DragEventArgs e)
        {
            bool success = false;
            StaffItem si = null;

            try
            {
                string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber"); //which shift
                si = siList.ElementAt(int.Parse(itemIndexString));
                success = true;
            }
            catch
            {
                //string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber2"); //which shift
                //StaffItem si = siList2.ElementAt(int.Parse(itemIndexString));
                success = false;
            }
            if (!success)
            {
                string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber2"); //which shift
                si = siList2.ElementAt(int.Parse(itemIndexString));
            }

            ////////////////////////////////
            //List<StaffItem> temp = (List<StaffItem>)WeekGridView.ItemsSource;
            //temp.ElementAt(0).

            ////////////////////////////////
            FrameworkElement root = Window.Current.Content as FrameworkElement;

            Point position = this.TransformToVisual(root).TransformPoint(e.GetPosition(this));

            int newIndex = 0;

            // check items directly under the pointer
            foreach (var element in VisualTreeHelper.FindElementsInHostCoordinates(position, root))
            {
                // assume horizontal orientation
                var container = element as ContentControl;
                if (container == null)
                {
                    continue;
                }

                int tempIndex = WeekGridView.IndexFromContainer(container);
                if (tempIndex >= 0)
                {

                    newIndex = tempIndex;
                    // adjust index depending on pointer position
                    Point center = container.TransformToVisual(root).TransformPoint(new Point(container.ActualWidth / 2, container.ActualHeight / 2));
                    if (position.Y > center.Y)
                    {
                        newIndex++;
                    }
                    break;
                }
            }
            if (newIndex < 0)
            {
                // if we haven't found item under the pointer, check items in the rectangle to the left from the pointer position
                foreach (var element in GetIntersectingItems(position, root))
                {
                    // assume horizontal orientation
                    var container = element as ContentControl;
                    if (container == null)
                    {
                        continue;
                    }

                    // int tempIndex = WeekGridView.ItemContainerGenerator.IndexFromContainer(container);
                    int tempIndex = WeekGridView.IndexFromContainer(container);
                    if (tempIndex < 0)
                    {
                        // we only need GridViewItems belonging to this GridView control
                        // so skip all elements which are not
                        continue;
                    }
                    Rect bounds = container.TransformToVisual(root).TransformBounds(new Rect(0, 0, container.ActualWidth, container.ActualHeight));

                    if (bounds.Left <= position.X && bounds.Top <= position.Y && tempIndex > newIndex)
                    {
                        //_currentOverGroup = GetItemGroup(container.Content);
                        newIndex = tempIndex;
                        // adjust index depending on pointer position
                        if (position.Y > bounds.Top + container.ActualHeight / 2)
                        {
                            newIndex++;
                        }
                        if (bounds.Right > position.X && bounds.Bottom > position.Y)
                        {
                            break;
                        }
                    }
                }
            }
            if (newIndex < 0)
            {
                newIndex = 0;
            }
            if (newIndex >= empList.Count * 9)
            {
                newIndex = empList.Count * 9 - 1;
            }
            //empList = await User.ReadUsersList();
           // await new MessageDialog(newIndex.ToString()).ShowAsync();
            StaffItem selectedStaffItem = dList.ElementAt(newIndex);
            if (selectedStaffItem.workHours == null)
            {
                if (!String.IsNullOrEmpty(si.workHours.TimeOffReason))
                { //timeOff

                    //            WorkHours wh = new WorkHours() { EmployeeId = empList.ElementAt(SelectedString.i / 9).UserId,TimeOffFrom= SelectedString.date,TimeOffTo=SelectedString.date+new TimeSpan(23,0,0), TimeOffReason="Time Off"};
                    WorkHours wh = new WorkHours();
                    //wh = selectedStaffItem.workHours;
                    wh.TimeOffReason = si.workHours.TimeOffReason;
                    wh.TimeOffFrom = selectedStaffItem.date;
                    wh.TimeOffTo = selectedStaffItem.date + new TimeSpan(23, 0, 0);
                    wh.EmployeeId = empList.ElementAt(selectedStaffItem.i / 9).UserId;

                    //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
                    //myGrid.Opacity = 0.5;

                    await WorkHours.InsertNewWorkHours(wh);
                    fillWeeklyCalendar();


                    //myGrid.Opacity = 1;
                    //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);

                }
                else
                { // Shift
                    //            WorkHours wh = new WorkHours() { EmployeeId = empList.ElementAt(SelectedString.i / 9).UserId, From = SelectedString.date + ts1, To = SelectedString.date + ts2 , OnCallOnly = false, BreakTimeFrom= new TimeSpan(8+count,0,0), BreakTimeTo=new TimeSpan(8+count+1,0,0),TimeOffReason=String.Empty };

                    WorkHours wh = new WorkHours();
                    //wh = selectedStaffItem.workHours;
                    wh.From = selectedStaffItem.date +  si.workHours.From.TimeOfDay;
                    wh.To = (si.workHours.From.TimeOfDay.Hours != 23) ? selectedStaffItem.date +si.workHours.To.TimeOfDay : selectedStaffItem.date.AddDays(1) + si.workHours.To.TimeOfDay;
                    wh.EmployeeId = empList.ElementAt(selectedStaffItem.i / 9).UserId;
                    wh.OnCallOnly = false;
                    wh.BreakTimeFrom = new TimeSpan(si.workHours.From.TimeOfDay.Hours + empList.Count, 0, 0);
                    wh.BreakTimeTo = new TimeSpan(si.workHours.From.TimeOfDay.Hours + empList.Count + 1, 0, 0);
                    wh.TimeOffReason = String.Empty;

                    //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
                    //myGrid.Opacity = 0.5;

                    await WorkHours.InsertNewWorkHours(wh);
                    fillWeeklyCalendar();

                    //myGrid.Opacity = 1;
                    //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);

                }
            }
            else
            {
                await new MessageDialog("Conflict").ShowAsync();
            }

        }
示例#2
0
        private async void Button_Click_2(object sender, RoutedEventArgs e)//Night
        {
            WorkHours wh = SelectedString.workHours;
            if ((bool)NightShiftCheckBox.IsChecked && wh == null)
            {
                List<WorkHours> whList = await WorkHours.ReadListAsync();
                int count = whList.Where(w => w.From.ToString("MMMM dd, yyyy").Equals(SelectedString.date.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours == 15).Count();

                TimeSpan ts1 = new TimeSpan(23, 0, 0);
                TimeSpan ts2 = new TimeSpan(7, 0, 0);
                wh = new WorkHours() { EmployeeId = empList.ElementAt(SelectedString.i / 9).UserId, From = SelectedString.date + ts1, To = SelectedString.date.AddDays(1) + ts2, OnCallOnly = false, BreakTimeFrom = new TimeSpan(0 + count, 0, 0), BreakTimeTo = new TimeSpan(0 + count + 1, 0, 0), TimeOffReason = String.Empty };

                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
                //myGrid.Opacity = 0.5;

                await WorkHours.InsertNewWorkHours(wh);
                fillWeeklyCalendar();

                //myGrid.Opacity = 1;
                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);

            }
            else if (!(bool)NightShiftCheckBox.IsChecked)
            {

                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
                //myGrid.Opacity = 0.5;

                await WorkHours.DeleteWorkHours(wh);
                fillWeeklyCalendar();

                //myGrid.Opacity = 1;
                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);

            }
        }
示例#3
0
        private async void Button_Click_4(object sender, RoutedEventArgs e) //time off
        {

            WorkHours wh = SelectedString.workHours;
            if ((bool)TimeOffCheckBox.IsChecked && wh == null)
            {
                wh = new WorkHours() { EmployeeId = empList.ElementAt(SelectedString.i / 9).UserId, TimeOffFrom = SelectedString.date, TimeOffTo = SelectedString.date + new TimeSpan(23, 0, 0), TimeOffReason = "Time Off" };

                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
                //myGrid.Opacity = 0.5;

                await WorkHours.InsertNewWorkHours(wh);
                fillWeeklyCalendar();

                //myGrid.Opacity = 1;
                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);


            }
            else if (!(bool)TimeOffCheckBox.IsChecked)
            {

                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
                //myGrid.Opacity = 0.5;

                await WorkHours.DeleteWorkHours(wh);
                fillWeeklyCalendar();

                //myGrid.Opacity = 1;
                //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);

            }
        }
示例#4
0
        public void fillDragMenuGridView2()
        {
            //List<WorkHours> whList = new List<WorkHours>();
            siList2 = new List<StaffItem>();
            //WorkHours wh = new WorkHours() { From = new DateTime(0001, 01, 01) + new TimeSpan(7, 0, 0), To = new DateTime(0001, 01, 01) + new TimeSpan(15, 0, 0) };
            //StaffItem si = new StaffItem() { workHours = wh, Color = "#99FF99" };
            //siList2.Add(si);
            //WorkHours wh2 = new WorkHours() { From = new DateTime(0001, 01, 01) + new TimeSpan(15, 0, 0), To = new DateTime(0001, 01, 01) + new TimeSpan(23, 0, 0) };
            //StaffItem si1 = new StaffItem() { workHours = wh2, Color = "#99CCFF" };
            //siList2.Add(si1);
            //WorkHours wh3 = new WorkHours() { From = new DateTime(0001, 01, 01) + new TimeSpan(23, 0, 0), To = new DateTime(0001, 01, 01) + new TimeSpan(7, 0, 0) };
            //StaffItem si2 = new StaffItem() { workHours = wh3, Color = "Wheat" };
            WorkHours wh = new WorkHours() { TimeOffReason = "Time Off" };
            StaffItem si = new StaffItem() { workHours = wh };
            siList2.Add(si);
            wh = new WorkHours() { TimeOffReason = "Vacation" };
            si = new StaffItem() { workHours = wh };
            siList2.Add(si);
            wh = new WorkHours() { TimeOffReason = "Business Related" };
            si = new StaffItem() { workHours = wh };
            siList2.Add(si);
            wh = new WorkHours() { TimeOffReason = "Sick Leave" };
            si = new StaffItem() { workHours = wh };
            siList2.Add(si);
            wh = new WorkHours() { TimeOffReason = "Family Emergency" };
            si = new StaffItem() { workHours = wh };
            siList2.Add(si);
            wh = new WorkHours() { TimeOffReason = "Absent" };
            si = new StaffItem() { workHours = wh };
            siList2.Add(si);


            DragMenuGridView2.ItemsSource = siList2;
        }
示例#5
0
 public void fillDragMenuGridView()
 {
     //List<WorkHours> whList = new List<WorkHours>();
     siList = new List<StaffItem>();
     WorkHours wh = new WorkHours() { From = new DateTime(0001, 01, 01) + new TimeSpan(7, 0, 0), To = new DateTime(0001, 01, 01) + new TimeSpan(15, 0, 0) };
     StaffItem si = new StaffItem() { workHours = wh, Color = "#99FF99" };
     siList.Add(si);
     WorkHours wh2 = new WorkHours() { From = new DateTime(0001, 01, 01) + new TimeSpan(15, 0, 0), To = new DateTime(0001, 01, 01) + new TimeSpan(23, 0, 0) };
     StaffItem si1 = new StaffItem() { workHours = wh2, Color = "#99CCFF" };
     siList.Add(si1);
     WorkHours wh3 = new WorkHours() { From = new DateTime(0001, 01, 01) + new TimeSpan(23, 0, 0), To = new DateTime(0001, 01, 01) + new TimeSpan(7, 0, 0) };
     StaffItem si2 = new StaffItem() { workHours = wh3, Color = "Wheat" };
     siList.Add(si2);
     DragMenuGridView.ItemsSource = siList;
 }
示例#6
0
 public static async Task DeleteWorkHours(WorkHours wh)
 {
     await workHours.DeleteAsync(wh);
 }
示例#7
0
 public static async Task UpdateWorkHours(WorkHours u)
 {
     await workHours.UpdateAsync(u);
     //u = (await user.Where(uu => uu.UserId == u.UserId).ToListAsync()).First();
     //return u;
 }
示例#8
0
          public static async Task InsertNewWorkHours(WorkHours whs)
          {

              
              try
              {
                  await workHours.InsertAsync(whs);
              }
              catch (MobileServiceInvalidOperationException e)
              {
                  MessageDialog errormsg = new MessageDialog(e.Response.ReasonPhrase+ "Only the admin is authorized to organize the work hours.");
                    var ignoreAsyncOpResult = errormsg.ShowAsync();
              }

          }