//Method which modifies both the DataBase table and the list of tasks
        protected void Save()
        {
            //Creating the current displayed task for saving
            int priority;

            if (low.Checked == true)
            {
                priority = 1;
            }
            else if (mediu.Checked == true)
            {
                priority = 2;
            }
            else
            {
                priority = 3;
            }
            Task newTask = new Task(name.Text, description.Text, check, new DateTime(date.Year, date.Month + 1, date.DayOfMonth, time.CurrentHour.IntValue(), time.CurrentMinute.IntValue(), 00), priority);

            //Checking whether the task has to be saved or it has to update another task
            if (MainActivity.items.Exists(t => t.name.Equals(name.Text)))
            {
                //Delete the task from the database
                TaskRepository.UpdateTask(newTask);

                //Finding the index in the list of tasks
                int position = 0;
                for (int i = 0; i < MainActivity.items.Count; i++)
                {
                    if (MainActivity.items[i].name.Equals(name.Text))
                    {
                        position = i;
                        break;
                    }
                }

                //Update the task from the list of tasks
                MainActivity.items[position].description = description.Text;
                MainActivity.items[position].deadline    = new DateTime(date.Year, date.Month + 1, date.DayOfMonth, time.CurrentHour.IntValue(), time.CurrentMinute.IntValue(), 00);
                MainActivity.items[position].priority    = priority;
                MainActivity.items[position].status      = check;
            }
            else
            {
                //Save the task to DataBase
                TaskRepository.SaveTask(newTask);

                //Save the task to list of tasks
                MainActivity.items.Add(newTask);
            }
            Finish();
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //string connection = Configuration.GetConnectionString("DefaultConnection");
            // services.AddDbContext<TaskContext>(options => options.UseSqlServer(connection));

            string connection         = "Server = HP\\SQLEXPRESS;Database=TaskManager;Trusted_Connection=True;MultipleActiveResultSets=true";
            var    taskRepository     = new TaskRepository(connection);
            var    employeeRepository = new EmployeeRepository(connection);

            services.AddTransient <IRepository <DAL.Entities.Task>, TaskRepository>(provider => taskRepository);
            services.AddTransient <IRepository <DAL.Entities.Employee>, EmployeeRepository>(provider => employeeRepository);

            services.AddSingleton(provider => new TaskServices(taskRepository));
            services.AddSingleton(provider => new EmployeeService(employeeRepository));

            services.AddMvc();
        }
示例#3
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View view = convertView; // re-use an existing view, if one is available

            if (view == null)        // otherwise create a new one
            {
                view = context.LayoutInflater.Inflate(Resource.Layout.ListView, null);
            }

            view.FindViewById <TextView>(Resource.Id.textName).Text = items[position].name;

            //Set texts
            TextView textName = view.FindViewById <TextView>(Resource.Id.textName);
            TextView date     = view.FindViewById <TextView>(Resource.Id.textDate);
            CheckBox check    = view.FindViewById <CheckBox>(Resource.Id.checkBoxItem);

            textName.Text = items[position].name;
            date.Text     = items[position].deadline.ToString();
            check.Checked = items[position].status;

            if (items[position].priority == 1)
            {
                textName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#13b60d"));
                date.SetBackgroundColor(Android.Graphics.Color.ParseColor("#13b60d"));
            }
            else if (items[position].priority == 2)
            {
                textName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#d45611"));
                date.SetBackgroundColor(Android.Graphics.Color.ParseColor("#d45611"));
            }
            else
            {
                textName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#e11f1f"));
                date.SetBackgroundColor(Android.Graphics.Color.ParseColor("#e11f1f"));
            }

            check.CheckedChange += (sender, e) =>
            {
                //Update
                items[position].status = check.Checked;
                Task aux = new Task(items[position].name, items[position].description, items[position].status, items[position].deadline, items[position].priority);
                TaskRepository.UpdateTask(aux);
            };

            return(view);
        }
        //Method which modifies both the DataBase table and the list of tasks
        protected void Delete()
        {
            //Creating the current displayed task for delete
            int priority;

            if (low.Checked == true)
            {
                priority = 1;
            }
            else if (mediu.Checked == true)
            {
                priority = 2;
            }
            else
            {
                priority = 3;
            }
            Task newTask = new Task(name.Text, description.Text, check, new DateTime(date.Year, date.Month + 1, date.DayOfMonth, time.CurrentHour.IntValue(), time.CurrentMinute.IntValue(), 00), priority);

            //Delete it from DataBase
            TaskRepository.DeleteStock(newTask);

            //Find index of task in list of tasks
            int position = 0;

            for (int i = 0; i < MainActivity.items.Count; i++)
            {
                if (MainActivity.items[i].name.Equals(name.Text))
                {
                    position = i;
                    break;
                }
            }

            //Remove the item from the list of tasks
            MainActivity.items.RemoveAt(position);
            Finish();
        }
示例#5
0
 public void SaveTasks()
 {
     TaskRepository.Save(_tasks);
 }
示例#6
0
 public TaskManager()
 {
     _tasks = TaskRepository.Get();
 }
示例#7
0
        //OnCreate
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            //NotificationService
            Intent serviceToStart = new Intent(this, typeof(NotificationService));

            StartService(serviceToStart);

            //MainActivity layout
            SetContentView(Resource.Layout.Main);

            //Find by id
            ListView listView           = FindViewById <ListView>(Resource.Id.listView1);
            Button   buttonNew          = FindViewById <Button>(Resource.Id.buttonNew);
            Button   buttonSortPriority = FindViewById <Button>(Resource.Id.sortPriority);
            Button   buttonSortDate     = FindViewById <Button>(Resource.Id.sortDate);

            //Adapt list
            adapter = new ListAdapter(this, items);
            //set the adapter to build the list
            listView.Adapter = adapter;

            //On button Click starting the new activity
            buttonNew.Click += (sender, e) =>
            {
                Toast.MakeText(this, "Adding new task", ToastLength.Short).Show();
                //Make a list from the DataBase
                var aux = TaskRepository.GetTasks().ToList();

                //intent for the next activity
                Intent intentButtonClick = new Intent(this, typeof(ActivityTaskEdit));

                //start activity via intent waiting for a result
                StartActivityForResult(intentButtonClick, 0);
            };

            //On button click sort list by priority
            buttonSortPriority.Click += (sender, e) =>
            {
                Toast.MakeText(this, "List sorted by Priority", ToastLength.Short).Show();

                List <Task> sortedList = new List <Task>();

                for (int i = 0; i < items.Count;)
                {
                    if (items[i].priority == 3)
                    {
                        sortedList.Insert(0, items[i]);
                        items.RemoveAt(i);
                    }
                    else if (items[i].priority == 2)
                    {
                        sortedList.Insert(sortedList.Count, items[i]);
                        items.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }

                for (int i = 0; i < items.Count;)
                {
                    sortedList.Insert(sortedList.Count, items[i]);
                    items.RemoveAt(i);
                }

                items = sortedList;

                //Adapt list
                adapter = new ListAdapter(this, items);
                //set the adapter to build the list
                listView.Adapter = adapter;
            };
            //On button click sort list by date
            buttonSortDate.Click += (sender, e) =>
            {
                Toast.MakeText(this, "List sorted by Date", ToastLength.Short).Show();

                for (int i = 0; i < items.Count - 1; i++)
                {
                    for (int j = i + 1; j < items.Count; j++)
                    {
                        if (DateTime.Compare(items[i].deadline, items[j].deadline) > 0)
                        {
                            Task aux;
                            aux      = items[i];
                            items[i] = items[j];
                            items[j] = aux;
                        }
                    }
                }

                adapter.NotifyDataSetChanged();
            };

            //On listView item click
            listView.ItemClick += (sender, e) =>
            {
                string s = "Editing task named " + items[e.Position].name;
                Toast.MakeText(this, s, ToastLength.Short).Show();
                //intent for sending the data to the next activity and opening it
                Intent intentOnItemClick = new Intent(this, typeof(ActivityTaskEdit));
                intentOnItemClick.PutExtra("Name", items[e.Position].name);
                intentOnItemClick.PutExtra("Description", items[e.Position].description);
                intentOnItemClick.PutExtra("DateYear", items[e.Position].deadline.Year);
                intentOnItemClick.PutExtra("DateMonth", items[e.Position].deadline.Month);
                intentOnItemClick.PutExtra("DateDay", items[e.Position].deadline.Day);
                intentOnItemClick.PutExtra("DateHour", items[e.Position].deadline.Hour);
                intentOnItemClick.PutExtra("DateMinute", items[e.Position].deadline.Minute);
                intentOnItemClick.PutExtra("Priority", items[e.Position].priority);
                intentOnItemClick.PutExtra("Status", items[e.Position].status);

                //Start next activity via intent waiting for a result
                StartActivityForResult(intentOnItemClick, 0);
            };
        }
 static TaskRepository()
 {
     me = new TaskRepository();
 }