예제 #1
0
 /// <summary>
 /// Inserez o activitate si o actualizez pe ultima, daca exista si daca are duration = 0.
 /// </summary>
 /// <param name="A">Activitatea care trebuie inserata.</param>
 public static void ActivityInsert(Activity A)
 {
     //extrag ultima activitate a userului curent
     string query = string.Format("SELECT * FROM {0} WHERE user_id = @user_id ORDER BY id DESC LIMIT 1", Globals.TABLE_ACTIVITY);
     DataSet dataset = new DataSet();
     MySqlCommand command = null;
     MySqlDataAdapter adapter = new MySqlDataAdapter(query, connection);
     adapter.SelectCommand.Parameters.AddWithValue("@user_id", A.User_id);
     adapter.Fill(dataset);
     if (dataset.Tables[0].Rows.Count == 0)//nu exista activitati
     {
         if (A.Type == 0)
         {
             MessageBox.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 = string.Format("UPDATE {0} SET duration = @newDuration WHERE id = @id", Globals.TABLE_ACTIVITY);
             command = new MySqlCommand(query, connection);
             command.Parameters.AddWithValue("@newDuration", newDuration);
             command.Parameters.AddWithValue("@id", id);
             command.ExecuteNonQuery();
         }
     }
     /*----- inserez activitatea noua -----*/
     Insert(A);
     Destroy(adapter, dataset, command);
 }
예제 #2
0
 //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();
     chooseProjectButton.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;
         Conexiune.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;
         startActivityButton.Enabled = true;
         pauseActivityButton.Enabled = true;
     }
     else//PAUZA
     {
         activityStarted = false;//cod nou!!!
         activity.Type = 0;
         Conexiune.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;
         startActivityButton.Enabled = true;
         pauseActivityButton.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;
 }
예제 #3
0
 /// <summary>
 /// Insereaza o activitate noua in baza de date.
 /// </summary>
 /// <param name="A">Activitatea care trebuie adaugata in baza de date.</param>
 private static void Insert(Activity A)
 {
     string query = string.Format("INSERT INTO {0}(user_id, project_id, start_time, description, type, duration, task_id) VALUES(@user_id, @project_id, @start_time, @description, @type, @duration, @task_id)", Globals.TABLE_ACTIVITY);
     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();
     Destroy(command);
 }
예제 #4
0
 //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();
             Conexiune.ActivityStop(user.Id, inactivTimeValue);
             chooseProjectButton.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;
             Conexiune.ActivityInsert(activity);
             workTimer.Stop();
             pauseTimer.Start();
             statusProjectLabel.Text = "PAUZĂ";
             statusProjectLabel.ForeColor = Color.Red;
             box.HeaderColor = Color.Red;
             box.HeaderText = "PAUZĂ";// +nowTime;
             startActivityButton.Enabled = true;
             pauseActivityButton.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();
         }
     }
 }