コード例 #1
0
ファイル: ActionTypes.cs プロジェクト: harindaka/MyDay
        private void Add()
        {
            try
            {
                string item = txtItem.Text.Trim();
                if (!String.IsNullOrEmpty(item))
                {
                    using (MyDayData db = new MyDayData())
                    {

                        var query = from ts in db.ActionTypes
                                    where ts.ActionTypeCode == item
                                    select new { ActionType = ts.ActionTypeCode };

                        if (query.FirstOrDefault() == null)
                        {
                            ActionType newItem = new ActionType { ActionTypeCode = item };
                            db.AddToActionTypes(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
ファイル: MyDayData.Designer.cs プロジェクト: harindaka/MyDay
 /// <summary>
 /// Create a new ActionType object.
 /// </summary>
 /// <param name="actionTypeCode">Initial value of the ActionTypeCode property.</param>
 public static ActionType CreateActionType(global::System.String actionTypeCode)
 {
     ActionType actionType = new ActionType();
     actionType.ActionTypeCode = actionTypeCode;
     return actionType;
 }
コード例 #4
0
ファイル: MyDayData.Designer.cs プロジェクト: harindaka/MyDay
 /// <summary>
 /// Deprecated Method for adding a new object to the ActionTypes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToActionTypes(ActionType actionType)
 {
     base.AddObject("ActionTypes", actionType);
 }