Пример #1
0
 /// <summary>
 /// Create a new Tag object.
 /// </summary>
 /// <param name="tagCode">Initial value of the TagCode property.</param>
 public static Tag CreateTag(global::System.String tagCode)
 {
     Tag tag = new Tag();
     tag.TagCode = tagCode;
     return tag;
 }
Пример #2
0
        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
 /// <summary>
 /// Deprecated Method for adding a new object to the Tags EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTags(Tag tag)
 {
     base.AddObject("Tags", tag);
 }