예제 #1
0
        private void Add()
        {
            try
            {
                string item = txtItem.Text.Trim();
                if (!String.IsNullOrEmpty(item))
                {
                    using (MyDayData db = new MyDayData())
                    {

                        var query = from ts in db.TaskStatuses
                                    where ts.TaskStatusCode == item
                                    select new { TaskStatus = ts.TaskStatusCode };

                        if (query.FirstOrDefault() == null)
                        {
                            TaskStatus newItem = new TaskStatus { TaskStatusCode = item };
                            db.AddToTaskStatuses(newItem);
                            db.SaveChanges();
                            this.SetStatus("Item was added successfully");

                            this.PopulateList();

                            txtItem.Text = "";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.SetStatus(ex);
                this.PopulateList();
            }
            finally
            {
                txtItem.Focus();
            }
        }
예제 #2
0
파일: Action.cs 프로젝트: harindaka/MyDay
        private void Save()
        {
            try
            {
                using (MyDayData db = new MyDayData())
                {
                    string projectCode = txtProject.Text.Trim();
                    string taskCode = txtTask.Text.Trim();
                    string taskTypeCode = txtTaskType.Text.Trim();
                    string taskStatusCode = txtTaskStatus.Text.Trim();
                    decimal? estEff = null;
                    string estEffStr = txtEstEffort.Text.Trim();
                    if (!String.IsNullOrEmpty(estEffStr))
                        estEff = Convert.ToDecimal(estEffStr);

                    string action = txtAction.Text.Trim();
                    DateTime actionStartTime = dtpActionDate.Value.Date.Add(dtpActionTimeFrom.Value.Subtract(dtpActionTimeFrom.Value.Date));
                    DateTime actionEndTime = dtpActionDate.Value.Date.Add(dtpActionTimeTo.Value.Subtract(dtpActionTimeTo.Value.Date));
                    string actionTypeCode = txtActionType.Text.Trim();
                    Dictionary<string, string> actionTags = tpTags.GetTags();

                    if (pbNewProject.Visible)
                    {
                        Project newProject = new Project();
                        newProject.ProjectCode = projectCode;
                        db.AddToProjects(newProject);
                    }

                    if (pbNewTaskType.Visible)
                    {
                        TaskType newTaskType = new TaskType();
                        newTaskType.TaskTypeCode = taskTypeCode;
                        db.AddToTaskTypes(newTaskType);
                    }

                    if (pbNewTaskStatus.Visible)
                    {
                        TaskStatus newTaskStatus = new TaskStatus();
                        newTaskStatus.TaskStatusCode = taskStatusCode;
                        db.AddToTaskStatuses(newTaskStatus);
                    }

                    if (pbNewActionType.Visible)
                    {
                        ActionType newActionType = new ActionType();
                        newActionType.ActionTypeCode = actionTypeCode;
                        db.AddToActionTypes(newActionType);
                    }

                    if (pbNewTask.Visible)
                    {
                        Task newTask = new Task();
                        newTask.ProjectCode = projectCode;
                        newTask.TaskCode = taskCode;
                        newTask.TaskTypeCode = taskTypeCode;
                        newTask.TaskStatusCode = taskStatusCode;
                        newTask.EstimatedEffortHours = estEff;
                        db.AddToTasks(newTask);
                    }
                    else
                    {
                        var query = from t in db.Tasks
                                    where t.ProjectCode.Equals(projectCode, StringComparison.InvariantCultureIgnoreCase)
                                    && t.TaskCode.Equals(taskCode, StringComparison.InvariantCultureIgnoreCase)
                                    select t;

                        Task currentTask = query.First();
                        currentTask.TaskTypeCode = taskTypeCode;
                        currentTask.TaskStatusCode = taskStatusCode;
                        currentTask.EstimatedEffortHours = estEff;
                    }

                    MyDay.Data.Action actionEnt = null;
                    if (lblActionCode.Text == "(New)")
                    {
                        actionEnt = new MyDay.Data.Action();
                        actionEnt.ProjectCode = projectCode;
                        actionEnt.TaskCode = taskCode;
                        actionEnt.ActionTypeCode = actionTypeCode;
                        actionEnt.FromTime = actionStartTime;
                        actionEnt.ToTime = actionEndTime;
                        actionEnt.ActionComments = action;
                        db.AddToActions(actionEnt);
                    }
                    else
                    {
                        long actionCode = Convert.ToInt64(lblActionCode.Text);

                        var query = from t in db.Actions
                                    where t.ActionCode == actionCode
                                    select t;

                        actionEnt = query.First();
                        actionEnt.ActionTypeCode = actionTypeCode;
                        actionEnt.FromTime = actionStartTime;
                        actionEnt.ToTime = actionEndTime;
                        actionEnt.ActionComments = action;
                    }

                    using (var txn = db.BeginTransaction())
                    {
                        db.SaveChanges();

                        var query = from t in db.ActionTags
                                    where t.ActionCode == actionEnt.ActionCode
                                    select t;

                        foreach (var row in query)
                            db.DeleteObject(row);

                        foreach (KeyValuePair<string, string> tag in actionTags)
                        {
                            if (tag.Value.EndsWith("(New)") && !tag.Key.Equals(tag.Value))
                            {
                                MyDay.Data.Tag newTag = new Tag();
                                newTag.TagCode = tag.Key;
                                db.AddToTags(newTag);
                            }

                            MyDay.Data.ActionTag actionTagEnt = new ActionTag();
                            actionTagEnt.ActionCode = actionEnt.ActionCode;
                            actionTagEnt.TagCode = tag.Key;
                            db.AddToActionTags(actionTagEnt);
                        }

                        db.SaveChanges();

                        txn.Commit();
                    }
                }

                this.ResetControls(true);
                this.SetStatus("The specified Action was saved successfully");
            }
            catch (Exception ex)
            {
                this.SetStatus(ex);
            }
        }
예제 #3
0
        private void Delete()
        {
            try
            {
                if (dgvItems.SelectedRows.Count > 0)
                {
                    List<string> selections = new List<string>();
                    foreach (DataGridViewRow row in dgvItems.SelectedRows)
                        selections.Add(Convert.ToString(row.Cells[0].Value));

                    using (MyDayData db = new MyDayData())
                    {
                        var query = from ts in db.TaskStatuses
                                    where selections.Contains(ts.TaskStatusCode)
                                    select ts;

                        if (query.FirstOrDefault() != null)
                        {
                            foreach (var row in query)
                                db.TaskStatuses.DeleteObject(row);

                            db.SaveChanges();
                            this.SetStatus("Selected items were deleted successfully");

                            this.PopulateList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.SetStatus(ex);
                this.PopulateList();
            }
            finally
            {
                txtItem.Focus();
            }
        }