예제 #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.RowIndex < this.tasks.Count)
            {
                if (e.ColumnIndex == 4)
                {
                    ProjectHours task         = this.tasks[e.RowIndex];
                    TaskEditForm taskEditForm = new TaskEditForm(e.RowIndex, task, this.projectName, this.employee);
                    taskEditForm.EditEventHandler += TaskEditForm_EditEventHandler;
                    taskEditForm.Show();
                }
                else if (e.ColumnIndex == 5)
                {
                    Project project = this.db.Projects.Include(p => p.ProjectMonths).First(p => p.ProjectName == this.projectName);
                    if (project.ProjectStatus == "C")
                    {
                        MessageBox.Show($"The project is finished!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    ProjectHours task = this.tasks[e.RowIndex];
                    if (project.ProjectMonths.Any(pm => pm.ProjectMonth == task.ProjectTaskdate.Month && pm.ProjectYear == task.ProjectTaskdate.Year))
                    {
                        ProjectMonths projectMonth = project.ProjectMonths
                                                     .First(pm => pm.ProjectMonth == task.ProjectTaskdate.Month && pm.ProjectYear == task.ProjectTaskdate.Year);
                        if (projectMonth.ProjectMonthStatus == "C")
                        {
                            MessageBox.Show("This month is finished for the project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    DialogResult result = MessageBox.Show("Are you sure you want to delete this task ?", "Delete Task", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        var args = new DeleteEventArgs()
                        {
                            Task = task
                        };

                        DeleteEventHandler?.Invoke(this, args);
                        dataGridView1.Rows.RemoveAt(e.RowIndex);

                        MessageBox.Show(
                            $"Task was successfully deleted from {this.projectName}!",
                            "Successful Task Deletion",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information
                            );
                    }
                }
            }
        }
        private static void ChangedEvent(IntPtr userData, NotificationType type, IntPtr operationList, int num)
        {
            IntPtr operationType;
            IntPtr uniqueNumber;
            IntPtr notification;

            NotificationEventArgs       eventargs;
            NotificationDeleteEventArgs deleteargs;

            for (int i = 0; i < num; i++)
            {
                uniqueNumber  = IntPtr.Zero;
                operationType = IntPtr.Zero;
                notification  = IntPtr.Zero;

                Interop.NotificationEventListener.GetOperationData(operationList + (i * Marshal.SizeOf <NotificationOperation>()), NotificationOperationDataType.Type, out operationType);
                Interop.NotificationEventListener.GetOperationData(operationList + (i * Marshal.SizeOf <NotificationOperation>()), NotificationOperationDataType.UniqueNumber, out uniqueNumber);
                Interop.NotificationEventListener.GetOperationData(operationList + (i * Marshal.SizeOf <NotificationOperation>()), NotificationOperationDataType.Notification, out notification);

                if (operationType == IntPtr.Zero)
                {
                    Log.Error(LogTag, "unable to get operationType");
                    continue;
                }

                Log.Info(LogTag, "type : " + ((int)operationType).ToString());
                Log.Info(LogTag, "Add : " + (AddEventHandler == null ? "0" : AddEventHandler.GetInvocationList().Length.ToString()));
                Log.Info(LogTag, "update: " + (UpdateEventHandler == null ? "0" : UpdateEventHandler.GetInvocationList().Length.ToString()));
                Log.Info(LogTag, "delete : " + (DeleteEventHandler == null ? "0" : DeleteEventHandler.GetInvocationList().Length.ToString()));

                switch ((int)operationType)
                {
                case (int)NotificationOperationType.Insert:
                    if (notification != IntPtr.Zero)
                    {
                        try
                        {
                            eventargs = NotificationEventArgsBinder.BindObject(notification, false);
                            AddEventHandler?.Invoke(null, eventargs);
                        }
                        catch (Exception e)
                        {
                            Log.Error(LogTag, e.Message);
                        }
                    }

                    break;

                case (int)NotificationOperationType.Update:
                    if (notification != IntPtr.Zero)
                    {
                        try
                        {
                            eventargs = NotificationEventArgsBinder.BindObject(notification, false);
                            UpdateEventHandler?.Invoke(null, eventargs);
                        }
                        catch (Exception e)
                        {
                            Log.Error(LogTag, e.Message);
                        }
                    }

                    break;

                case (int)NotificationOperationType.Delete:
                    if (uniqueNumber != IntPtr.Zero)
                    {
                        try
                        {
                            deleteargs = NotificationDeleteEventArgsBinder.BindObject((int)uniqueNumber);
                            DeleteEventHandler?.Invoke(null, deleteargs);
                        }
                        catch (Exception e)
                        {
                            Log.Error(LogTag, e.Message);
                        }
                    }

                    break;

                default:
                    Log.Info(LogTag, "Event : " + (int)operationType);
                    break;
                }
            }
        }