Exemplo n.º 1
0
 private void addButton_Click(object sender, EventArgs e)
 {
     string name = contNameTextBox.Text;
     string email = contEmailTextBox.Text;
     string password = contPasswordTextBox.Text;
     int type = 0;
     if (adminRadioButton.Checked) type = 0;
     else if (leaderRadioButton.Checked) type = 1;
     else if (developerRadioButton.Checked) type = 2;
     int teamId = (contTeamComboBox.SelectedItem as Team).Id;
     if ((name != String.Empty) && (email != String.Empty) && (password != String.Empty))
     {
         User usr = new User(name, email, password, new DateTime(), type, teamId, 0, 0, false, false);
         if (Conexiune.AddUser(usr))
         {
             ShowNotifyMessage("Utilizatorul a fost adăugat cu succes!", true);
             contNameTextBox.Text = String.Empty;
             contEmailTextBox.Text = String.Empty;
             contPasswordTextBox.Text = String.Empty;
             contNameTextBox.Focus();
         }
         else
         {
             ShowNotifyMessage("Exista deja un utilizator cu același email!", false);
             contEmailTextBox.Focus();
             contEmailTextBox.SelectAll();
         }
     }
     else
     {
         ShowNotifyMessage("Trebuie să completezi toate câmpurile!", false);
         contNameTextBox.Focus();
     }
 }
Exemplo n.º 2
0
 public WorkWindow(User user, LoginWindow logWin)
 {
     InitializeComponent();
     SetColors();
     this.loginWindow = logWin;
     this.user = user;
     toolTip = new ToolTip();
     toolTip.IsBalloon = true;
     manageMenuLabel.Visible = (user.Type == (int)UserType.Admin);
     myActivityMenuButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);
     teamActivityMenuButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);
     projectsMenuButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);
     tasksMenuButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);
     InitializePanelNo1();//activitatile mele
     InitializePanelNo2();//activitatile echipei
     InitializePanelNo3();//proiecte
     InitializePanelNo4();//task-uri
     InitializePanelNo5();//profil
     ChangeColorShowPanel(1);//selectez primul panel cand se deschide forma
     /*-----preluare setari-----*/
     int inactiv = 300;//default
     bool show = true;//default
     if (File.Exists("settings.ini"))
     {
         StreamReader fin = new StreamReader("settings.ini");
         string line;
         while ((line = fin.ReadLine()) != null)
         {
             int poz = line.IndexOf('=');
             if (line.Contains(settings[0]))
                 inactiv = Convert.ToInt32(line.Substring(poz + 1));
             else if (line.Contains(settings[1]))
                 show = Convert.ToBoolean(line.Substring(poz + 1));
         }
         fin.Close();
     }
     empWindow = new EmployeesWindow(user);
     empWindow.Show();
     showEmployeesCheckBox.Checked = show;
     inactivTimeValue = inactiv;
     this.BringToFront();
     this.Focus();
 }
Exemplo n.º 3
0
 private void logareButton_Click(object sender, EventArgs e)
 {
     string email = emailTextBox.Text;
     string parola = passwordTextBox.Text;
     user = Conexiune.Login(email, parola);
     if (user != null)
     {
         this.Hide();
         WorkWindow ww = new WorkWindow(user, this);
         ww.Show();
     }
     else
     {
         string text = "Ai greșit adresa de email sau parola. Incearcă din nou!";
         string caption = "EROARE";
         MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         emailTextBox.Focus();
     }
 }
Exemplo n.º 4
0
 public EmployeesWindow(User user)
 {
     InitializeComponent();
     this.user = user;
     unknown = CompanyWorkManagement.Properties.Resources.unknown as Image;
 }
Exemplo n.º 5
0
 public bool IsEqualTo(User A)
 {
     return ((this.Id == A.Id) && (this.Email == A.Email));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Actualizeaza profilul unui user.
 /// </summary>
 /// <param name="user">Userul care a carui profil trebuie actualizat.</param>
 /// <param name="type">Tipul de actualizare (nume, parola, poza).</param>
 public static void ProfileUpdate(User user, ProfileUpdateType type)
 {
     string query = null;
     MySqlParameter parameter = null;
     switch(type)
     {
         case ProfileUpdateType.NameUpdate:
             query = string.Format("UPDATE {0} SET name = @name WHERE id = @id", Globals.TABLE_USER);
             parameter = new MySqlParameter("@name", user.Name);
             break;
         case ProfileUpdateType.PasswordUpdate:
             query = string.Format("UPDATE {0} SET password = @password WHERE id = @id", Globals.TABLE_USER);
             parameter = new MySqlParameter("@password", user.Password);
             break;
         case ProfileUpdateType.PhotoUpdate:
             query = string.Format("UPDATE {0} SET image = @image WHERE id = @id", Globals.TABLE_USER);
             parameter = new MySqlParameter("@image", user.Image);
             break;
         default:
             return;
     }
     MySqlCommand command = new MySqlCommand(query, connection);
     command.Parameters.Add(parameter);
     command.Parameters.AddWithValue("@id", user.Id);
     command.ExecuteNonQuery();
     Destroy(command);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Adauga un user nou in baza de date
 /// </summary>
 /// <param name="user"></param>
 /// <returns>True daca s-a adaugat cu succes, false daca exista sau daca a aparut vreo eroare.</returns>
 public static bool AddUser(User user)
 {
     try
     {
         if (UserAlreadyExists(user.Email))
             return false;
         string query = string.Format("INSERT INTO {0}(name, email, password, last_login, type, team_id, worktime, pausetime, status, image) VALUES (@name, @email, @password, @last_login, @type, @team_id, @worktime, @pausetime, @status, @image)", Globals.TABLE_USER);
         MySqlCommand command = new MySqlCommand(query, connection);
         command.Parameters.AddWithValue("@name", user.Name);
         command.Parameters.AddWithValue("@email", user.Email);
         command.Parameters.AddWithValue("@password", user.Password);
         command.Parameters.AddWithValue("@last_login", user.LoginTime);
         command.Parameters.AddWithValue("@type", user.Type);
         command.Parameters.AddWithValue("@team_id", user.Team_id);
         command.Parameters.AddWithValue("@worktime", 0);
         command.Parameters.AddWithValue("@pausetime", 0);
         command.Parameters.AddWithValue("@status", false);
         command.Parameters.AddWithValue("@image", false);
         command.ExecuteNonQuery();
         Destroy(command);
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Realizeaza logout-ul userului, il face offline si actualizeaza timpul cat a lucrat si cat a facut pauza.
 /// </summary>
 /// <param name="user">Userul ale carui date trebuie actualizate la logout.</param>
 /// <param name="started"></param>
 public static void Logout(User user, bool started)
 {
     DataSet dataset = null;
     MySqlDataAdapter adapter = null;
     string query = string.Format("UPDATE {0} SET worktime = @worktime, pausetime = @pausetime, status = @status WHERE email = @email", Globals.TABLE_USER);
     MySqlCommand command = new MySqlCommand(query, connection);
     command.Parameters.AddWithValue("@worktime", user.Worktime);
     command.Parameters.AddWithValue("@pausetime", user.Pausetime);
     command.Parameters.AddWithValue("@status", user.Status);
     command.Parameters.AddWithValue("@email", user.Email);
     command.ExecuteNonQuery();
     if (started)
     {
         DataRow row;
         //updatez ultima activitate
         query = string.Format("SELECT * FROM {0} WHERE user_id = @user_id ORDER BY id DESC LIMIT 1", Globals.TABLE_ACTIVITY);
         dataset = new DataSet();
         adapter = new MySqlDataAdapter(query, connection);
         adapter.SelectCommand.Parameters.AddWithValue("@user_id", user.Id);
         adapter.Fill(dataset);
         if (dataset.Tables[0].Rows.Count > 0)
         {
             row = dataset.Tables[0].Rows[0];
             /*----- preiau datele pentru update -----*/
             int id = Convert.ToInt32(row["id"].ToString());
             DateTime startTime = Convert.ToDateTime(row["start_time"].ToString());
             long duration = Convert.ToInt64(row["duration"].ToString());
             long newDuration = (long)((TimeSpan)(DateTime.Now - startTime)).TotalSeconds;
             /*----- fac update-ul -----*/
             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();
         }
     }
     Destroy(adapter, dataset, command);
 }