protected void chkDone_CheckedChanged(object sender, EventArgs e) { MyDataModel context = new MyDataModel(); CheckBox checkbox = (CheckBox)sender; GridViewRow row = (GridViewRow)((checkbox).NamingContainer); int goalID = int.Parse(((Label)row.FindControl("HiddenGoalID")).Text.Trim()); if (checkbox.Checked) { T_GOALservice.GetGoalByID(context, goalID).Done = true; foreach (var task in T_TASKservice.GetTasksByGoalID(context, goalID)) { task.Done = true; } } else { T_GOALservice.GetGoalByID(context, goalID).Done = false; foreach (var task in T_TASKservice.GetTasksByGoalID(context, goalID)) { task.Done = false; } } context.SaveChanges(); BindData(); }
public static void RemoveTaskByID(MyDataModel db, int taskID) { T_TASK taskForDelete = GetTaskByID(db, taskID); db.T_TASK.Remove(taskForDelete); db.SaveChanges(); }
protected void btnDelete_Click(object sender, EventArgs e) { MyDataModel context = new MyDataModel(); foreach (GridViewRow row in GridView1.Rows) { CheckBox chkTask = (CheckBox)row.FindControl("chkGoal"); if (chkTask.Checked) { int goalID = int.Parse(((Label)row.FindControl("HiddenGoalID")).Text.Trim()); IQueryable <T_TASK> tasksForDelete = T_TASKservice.GetTasksByGoalID(context, goalID); if (tasksForDelete.Any()) { foreach (var task in tasksForDelete) { context.T_TASK.Remove(task); } } T_GOAL goalForDelete = T_GOALservice.GetGoalByID(context, goalID); context.T_GOAL.Remove(goalForDelete); context.SaveChanges(); } } BindData(); }
private static void SetDataToACCAUNT() { MyDataModel context = new MyDataModel(); if (!context.T_ACCOUNT.Any()) { List <T_ACCOUNT> states = new List <T_ACCOUNT>() { new T_ACCOUNT() { Email = "*****@*****.**", Password = "******", Active = false }, new T_ACCOUNT() { Email = "*****@*****.**", Password = "******", Active = true }, new T_ACCOUNT() { Email = "*****@*****.**", Password = "******", Active = false }, }; context.T_ACCOUNT.AddRange(states); context.SaveChanges(); } }
protected void btnConfirm_Click(object sender, EventArgs e) { MyDataModel context = new MyDataModel(); tbxEmail.BorderColor = Color.Empty; string email = tbxEmail.Text.Trim(); string password = tbxPassword.Text.Trim(); if (T_ACCOUNTservice.GetAccountByEmail(context, email) != null) { lblConfirmation.Text = Messages.errorMailExists; lblConfirmation.Visible = true; tbxEmail.BorderColor = Color.Red; } else { string name = tbxFirstName.Text; string surname = tbxSecondName.Text; bool isMale = dlstGender.SelectedItem.Text == "Male" ? true : false; T_ACCOUNT newAccount = new T_ACCOUNT() { Email = email, Password = password, Name = name, Surname = surname, IsMale = isMale, Active = true }; context.T_ACCOUNT.Add(newAccount); context.SaveChanges(); lblConfirmation.Text = string.Format("email '{0}' registered successfully", email); lblConfirmation.Visible = true; btnConfirm.Enabled = false; } }
protected void btnSave_Click(object sender, EventArgs e) { MyDataModel context = new MyDataModel(); int goalID; if (!int.TryParse(Request.QueryString["GoalID"], out goalID)) { lblGoalName.Text = Messages.goalName + Messages.errorMissingGoalID; lblGoalName.ForeColor = Color.Red; return; } string taskName = tbxTaskName.Text; if (string.IsNullOrEmpty(taskName)) { taskName = "noname"; } string description = tbxDescription.Text; bool isDone = bool.Parse(dlstDone.SelectedItem.Value); T_GOAL goal = T_GOALservice.GetGoalByID(context, goalID); if (goal == null) { lblGoalName.Text = Messages.goalName + Messages.errorIncorrectGoalID; lblGoalName.ForeColor = Color.Red; return; } int taskID; //create(if TaskID absent) or update task if (int.TryParse(Request.QueryString["TaskID"], out taskID)) { if (!T_TASKservice.IsTaskExists(context, taskID)) { return; } T_TASK task = T_TASKservice.GetTaskByID(context, taskID); task.GoalID = goalID; task.TaskName = taskName; task.Description = description; task.Done = isDone; task.UpdateDate = DateTime.Now; } else { T_TASK newTask = new T_TASK { GoalID = goalID, TaskName = taskName, Description = description, Done = isDone, UpdateDate = DateTime.Now, T_GOAL = goal }; context.T_TASK.Add(newTask); } context.SaveChanges(); Response.Redirect("~/_GoalPage.aspx?GoalID=" + goalID); }
public static T_GOAL AddNewGoal(MyDataModel db, string email, T_ACCOUNT account) { T_GOAL newGoal = new T_GOAL { Email = email, T_ACCOUNT = account, Done = false, GoalName = "New Goal", CreateDate = DateTime.Now }; db.T_GOAL.Add(newGoal); db.SaveChanges(); return(newGoal); }
static void Main(string[] args) { string filename = "test02.TXT"; string[] lines = new string[] { }; if (File.Exists(filename)) { lines = File.ReadAllLines(filename); } foreach (var line in lines) { int num = int.Parse(line.Substring(0, 3)); if (num == 695 || num == 525) { var tick = line.Substring(0, 13); var date1 = line.Substring(13, 4) + "/" + line.Substring(17, 2) + "/" + line.Substring(19, 2) + " 00:00:00"; var date2 = line.Substring(21, 4) + "/" + line.Substring(25, 2) + "/" + line.Substring(27, 2) + " 00:00:00"; DateTime fly, birth; DateTime.TryParse(date1.ToString(), out fly); DateTime.TryParse(date2.ToString(), out birth); //Console.WriteLine(fly); //Console.WriteLine(birth); try { MyDataModel myData = new MyDataModel(); myData.TimeTable.Add(new TimeTable() { TickNumber = tick, FlyingDay = fly, BirthDay = birth }); myData.SaveChanges(); Console.WriteLine("Success"); } catch (Exception ex) { Console.WriteLine(ex); } } } var list = (new MyDataModel()).TimeTable.ToList(); foreach (var item in list) { Console.WriteLine($"{item.Id} {item.TickNumber} {item.FlyingDay} {item.BirthDay}"); } Console.ReadLine(); }
protected void tbxGoalName_TextChanged(object sender, EventArgs e) { int goalID = int.Parse(Request.QueryString["GoalID"]); MyDataModel context = new MyDataModel(); string newGoalName = tbxGoalName.Text; if (string.IsNullOrEmpty(newGoalName)) { newGoalName = "noname"; } T_GOALservice.GetGoalByID(context, goalID).GoalName = newGoalName; context.SaveChanges(); }
protected void btnBack_Click(object sender, EventArgs e) { MyDataModel context = new MyDataModel(); int goalID = int.Parse(lblHiddenGoalID.Text.Trim()); IQueryable <T_TASK> tasks = T_TASKservice.GetTasksByGoalID(context, goalID); T_TASK isFalseDone = T_TASKservice.GetIncompliteTasks(tasks, false).FirstOrDefault(); //created goal have null tasks and t.Done always null T_GOAL currentGoal = T_GOALservice.GetGoalByID(context, goalID); if (currentGoal != null) { if (isFalseDone != null || tasks.Count() == 0) { currentGoal.Done = false; } else { currentGoal.Done = true; } context.SaveChanges(); } Response.Redirect("~/_GoalsPage.aspx"); }