//Salveaza private void saveActivityButton_Click(object sender, EventArgs e) { if (messageRichTextBox.Text.Length == 0) { ShowNotifyMessage("Completeaza rubrica pentru mesaj.", 1); messageRichTextBox.Focus(); return; } if (!activityStarted) idleTimer.Start(); chooseButton.Enabled = (choose == 0); saveActivityButton.Enabled = false; ActivityBox box = new ActivityBox(); Activity activity = new Activity(); activity.User_id = user.Id; activity.Project_id = selectedProject.Id; activity.Start_time = DateTime.Now; activity.Description = messageRichTextBox.Text.Trim(); activity.Duration = 0; activity.Task_id = 0; if (choose == 1)//START { activityStarted = true; activity.Type = 1; connection.ActivityInsert(activity); workTimer.Start();//merge munca pauseTimer.Stop();//nu merge pauza statusProjectLabel.Text = "ACTIV"; statusProjectLabel.ForeColor = Color.Green; box.HeaderColor = Color.ForestGreen; box.HeaderText = selectedProject.Name;// +nowTime; startButton.Enabled = true; pauseButton.Enabled = true; } else//PAUZA { activityStarted = false;//cod nou!!! activity.Type = 0; connection.ActivityInsert(activity); workTimer.Stop();//merge munca pauseTimer.Start();//nu merge pauza statusProjectLabel.Text = "PAUZĂ"; statusProjectLabel.ForeColor = Color.Red; box.HeaderColor = Color.Red; box.HeaderText = "PAUZĂ";// +nowTime; startButton.Enabled = true; pauseButton.Enabled = true; } string moment = BoxDateTime(DateTime.Now); box.DateText = moment.Substring(0, 5); box.TimeText = moment.Substring(6); box.BodyText = messageRichTextBox.Text.Trim(); int count = myActPanel.Controls.Count; Point p1 = new Point(3, 3 + count * 85); Point p2 = new Point(3, 3 + (nBox++) * 85); box.Location = (count > nBox) ? p1 : p2; myActPanel.Controls.Add(box.ShowControl); myActPanel.Controls[myActPanel.Controls.Count - 1].Focus(); messageRichTextBox.Text = String.Empty; }
public void ActivityInsert(Activity A) { //extrag ultima activitate a userului curent string query = "SELECT * FROM activity WHERE user_id = @user_id ORDER BY id DESC LIMIT 1"; MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue("@user_id", A.User_id); DataSet dataset = new DataSet(); MySqlDataAdapter adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); if (dataset.Tables[0].Rows.Count == 0)//nu exista activitati { if(A.Type == 0) { Msg.Show("Nu există activități incepute, deci nu poți insera o activitate de tip 'pauză'."); return; } } else { /*----- preiau datele pentru update -----*/ //fac update numai daca ultima activitate are duration = 0; DataRow row = dataset.Tables[0].Rows[0]; long duration = Convert.ToInt64(row["duration"].ToString()); if (duration == 0) { int id = Convert.ToInt32(row["id"].ToString()); DateTime startTime = Convert.ToDateTime(row["start_time"].ToString()); long newDuration = (long)((TimeSpan)(DateTime.Now - startTime)).TotalSeconds; query = "UPDATE activity SET duration = @newDuration WHERE id = @id"; command = new MySqlCommand(query, connection); command.Parameters.AddWithValue("@newDuration", newDuration); command.Parameters.AddWithValue("@id", id); command.ExecuteNonQuery(); } } /*----- inserez activitatea noua -----*/ this.Insert(A); command.Dispose(); adapter.Dispose(); dataset.Dispose(); }
//Timerul pentru systemul de inactivitate private void idleTimer_Tick(object sender, EventArgs e) { TagLastInputInfo lastInput = new TagLastInputInfo(); lastInput.cbSize = (uint)Marshal.SizeOf(lastInput); lastInput.dwTime = 0; if (GetLastInputInfo(ref lastInput)) { int idleTime = Environment.TickCount - lastInput.dwTime; //label14.Text = ((float)(idleTime / 1000.0)).ToString() + " s"; bool passed = (int)(idleTime / 1000.0) > inactivTimeValue; if (activityStarted && passed) { idleTime = 0; activityStarted = false; idleTimer.Stop(); connection.ActivityStop(user.Id, inactivTimeValue); chooseButton.Enabled = true; saveActivityButton.Enabled = false; ActivityBox box = new ActivityBox(); Activity activity = new Activity(); activity.User_id = user.Id; activity.Project_id = selectedProject.Id; activity.Start_time = DateTime.Now; activity.Description = string.Format("[Aplicatie]: Activitate oprită. Motiv: inactiv > {0} minute", inactivTimeValue / 60); activity.Duration = 0; activity.Task_id = 0; activity.Type = 0; connection.ActivityInsert(activity); workTimer.Stop(); pauseTimer.Start(); statusProjectLabel.Text = "PAUZĂ"; statusProjectLabel.ForeColor = Color.Red; box.HeaderColor = Color.Red; box.HeaderText = "PAUZĂ";// +nowTime; startButton.Enabled = true; pauseButton.Enabled = true; string moment = BoxDateTime(DateTime.Now); box.DateText = moment.Substring(0, 5); box.TimeText = moment.Substring(6); box.BodyText = string.Format("[Aplicatie]: Activitate oprită. Motiv: inactiv > {0} minute", inactivTimeValue / 60); int count = myActPanel.Controls.Count; Point p1 = new Point(3, 3 + count * 85); Point p2 = new Point(3, 3 + (nBox++) * 85); box.Location = (count > nBox) ? p1 : p2; myActPanel.Controls.Add(box.ShowControl); myActPanel.Controls[myActPanel.Controls.Count - 1].Focus(); } } }
private void Insert(Activity A) { string query = "INSERT INTO activity(user_id, project_id, start_time, description, type, duration, task_id) VALUES(@user_id, @project_id, @start_time, @description, @type, @duration, @task_id)"; MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue("@user_id", A.User_id); command.Parameters.AddWithValue("@project_id", A.Project_id); command.Parameters.AddWithValue("@start_time", A.Start_time); command.Parameters.AddWithValue("@description", A.Description); command.Parameters.AddWithValue("@type", A.Type); command.Parameters.AddWithValue("@duration", A.Duration);//duration = 0 command.Parameters.AddWithValue("@task_id", A.Task_id); command.ExecuteNonQuery(); command.Dispose(); }