/************************************************************************************************************* ************************************************************************************************************** **************************************************************************************************************/ /************************************************************************************************************* * -----------------------------------Funktion-zum-Löschen-eines-Benutzers--------------------------------------- **************************************************************************************************************/ private void btnDeleteUser_Click(object sender, EventArgs e) { // ListBoxItem item = (ListBoxItem)this.lstbUsers.SelectedItem; myListView lvi = (myListView)this.lstvUser.SelectedItems[0]; //Wenn der ausgewählte Benutzer der Benutzer ist, der eingeloggt ist if (lvi.ID == m_nUserID) { MessageBox.Show("Sie können sich nicht selbst löschen", "Warnung!"); return; } DialogResult dialogResult = MessageBox.Show("Wollen Sie den Benutzer \"" + lvi.Text + "\" wirklich löschen?", "Löschen", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = "Delete from Benutzer where idBenutzer = @lviID"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSQL; cmd.Parameters.AddWithValue("@lviID", lvi.ID); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Benutzer \"" + lvi.Text + "\" wurde gelöscht.", "Achtung"); this.lstvUser.Items.Remove(lvi); } }
/************************************************************************************************************* ************************************************************************************************************** **************************************************************************************************************/ /************************************************************************************************************* * ---------------------------------------ZUm-Löschen-eines-Eintrages-------------------------------------------- **************************************************************************************************************/ private void btnDeleteLink_Click(object sender, EventArgs e) { if (this.lstvUsedMatchcodes.SelectedItems.Count > 0) { myListView lvi = (myListView)this.lstvUsedMatchcodes.SelectedItems[0]; if (lvi != null) { SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = "Delete from Objektmatchcode Where ID_MatchcodeItem = @lvi"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSQL; cmd.Parameters.AddWithValue("@lvi", lvi.ID); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); this.lstvUsedMatchcodes.Items.Remove(lvi); } } }
/************************************************************************************************************* ************************************************************************************************************** **************************************************************************************************************/ /************************************************************************************************************* * -----------------------------Lädt-die-schon-Verknüpften-Matchcodes-aus-der-Datenbank-------------------------- **************************************************************************************************************/ private void LoadUsedMatchcodesFromDb() { this.lstvUsedMatchcodes.Items.Clear(); SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = ""; if (m_nDocumentID > -1) { strSQL = "Select ObjMC.ID_MatchcodeItem, ObjMC.ID_Dokument, MCI.Bezeichnung, MC.Matchcodename " + "From Objektmatchcode ObjMC " + "join MatchcodeItem MCI on MCI.idMatchcodeItem = ObjMC.ID_MatchcodeItem " + "Join Matchcode MC on MCI.ID_Matchcode = MC.idMatchcode " + "Where ID_Dokument = @m_nDocumentID"; } else { strSQL = "Select ObjMC.ID_MatchcodeItem, ObjMC.ID_Ordner, MCI.Bezeichnung, MC.Matchcodename " + "From Objektmatchcode ObjMC " + "join MatchcodeItem MCI on MCI.idMatchcodeItem = ObjMC.ID_MatchcodeItem " + "join Matchcode MC on MC.idMatchcode = MCI.ID_Matchcode " + "Where ObjMC.ID_Ordner = @m_nFolderID"; } SqlCommand cmd = new SqlCommand(strSQL, con); cmd.Parameters.AddWithValue("@m_nDocumentID", m_nDocumentID); cmd.Parameters.AddWithValue("@m_nFolderID", m_nFolderID); con.Open(); string strMatchcode = ""; string strMatchcodeContainer = ""; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { strMatchcode = reader["Bezeichnung"].ToString(); strMatchcodeContainer = reader["Matchcodename"].ToString(); myListView lvi = new myListView(strMatchcode); lvi.ID = (int)reader["ID_MatchcodeItem"]; lvi.SubItems.Add(strMatchcodeContainer); this.lstvUsedMatchcodes.Items.Add(lvi); } reader.Close(); con.Close(); }
/************************************************************************************************************* ************************************************************************************************************** **************************************************************************************************************/ /************************************************************************************************************* * ----------------------------Funktion-zum-Hinzufügen-eines-neuen-Benutzers------------------------------------- **************************************************************************************************************/ private void btnAddUser_Click(object sender, EventArgs e) { int nMaxUserID = SqlHelper.GetMaxID("idBenutzer", "Benutzer"); nMaxUserID = nMaxUserID + 1; string strPassword = ""; if ((this.tbxUsername.Text != "") && (this.tbxPassword.Text != "")) { strPassword = this.tbxPassword.Text; DateTime today = DateTime.Now; string strDateTimeToday = today.ToString("yyyy-dd-MM HH:mm:ss"); ComboBoxItem itemRights = (ComboBoxItem)this.cmbxRights.SelectedItem; myListView lvi = new myListView(this.tbxUsername.Text); lvi.ID = nMaxUserID; lvi.Rights = itemRights.ID; lvi.SubItems.Add(itemRights.Name); this.lstvUser.Items.Add(lvi); SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = "Insert Into Benutzer values " + "(@nMaxUserID, @itemName, @strPassword, @strDateTimeToday, @strDateTimeToday, 0, @itemRightsID, '', '', '1970.01.01', 0, '', '')"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSQL; string Hash = SqlHelper.GetSHA256Hash(strPassword); //SHA256 Hash von Passwort erzeugen cmd.Parameters.AddWithValue("@nMaxUserID", nMaxUserID); cmd.Parameters.AddWithValue("@itemName", lvi.Text); cmd.Parameters.AddWithValue("@strPassword", Hash); cmd.Parameters.AddWithValue("@strDateTimeToday", strDateTimeToday); cmd.Parameters.AddWithValue("@itemRightsID", itemRights.ID); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }
/************************************************************************************************************* ************************************************************************************************************** **************************************************************************************************************/ /************************************************************************************************************* * -----------------------------------Lädt-die-Benutzer-aus-der-Datenbank---------------------------------------- **************************************************************************************************************/ private void LoadUserFromDb() { SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = "select idBenutzer, Benutzername, ID_Rechte, Bezeichnung From Benutzer Join Rechte On ID_Rechte = idRechte"; SqlCommand cmd = new SqlCommand(strSQL, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); string strUsername = ""; string strRight = ""; while (reader.Read()) { strUsername = reader["Benutzername"].ToString(); strRight = reader["Bezeichnung"].ToString(); if (strUsername != "") { myListView lvi = new myListView(strUsername); lvi.ID = (int)reader["idBenutzer"]; lvi.Rights = (int)reader["ID_Rechte"]; lvi.SubItems.Add(strRight); this.lstvUser.Items.Add(lvi); } } reader.Close(); con.Close(); }
/************************************************************************************************************* * ------------------------Funktion,-um-eine-Verknüpfung-zwischen-Matchcode-und ID-zu-schaffen------------------- **************************************************************************************************************/ private void btnAddLink_Click(object sender, EventArgs e) { ListBoxItem itemListBox = (ListBoxItem)this.lstbAllMatchcodes.SelectedItem; int nMaxObjMatchcodeID = SqlHelper.GetMaxID("idObjektmatchcode", "Objektmatchcode"); nMaxObjMatchcodeID = nMaxObjMatchcodeID + 1; int i = 0; bool bItemExist = false; //Prüft ab, ob ein Element schon in der Liste existiert for (i = 0; i < this.lstvUsedMatchcodes.Items.Count; i++) { this.lstvUsedMatchcodes.Items[i].ToString(); if (itemListBox != null) { if (this.lstvUsedMatchcodes.Items[i].ToString() == itemListBox.Name) { bItemExist = true; } } } //wenn ein Element ausgewählt ist if (itemListBox != null) { //...und es noch nicht existiert if (!bItemExist) { //Wenn es ein Dokument ist if (m_nDocumentID > -1) { SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = "Insert into Objektmatchcode values (@nMaxObjMatchcodeID, @m_nDocumentID, -1, 0, @itemListBoxID)"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSQL; cmd.Parameters.AddWithValue("@nMaxObjMatchcodeID", nMaxObjMatchcodeID); cmd.Parameters.AddWithValue("@m_nDocumentID", m_nDocumentID); cmd.Parameters.AddWithValue("@itemListBoxID", itemListBox.ID); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } else { SqlConnection con = new SqlConnection(); con.ConnectionString = (SqlHelper.GetSqlConnectionString()); string strSQL = "Insert into Objektmatchcode values (@nMaxObjMatchcodeID, -1, @m_nFolderID, 1, @itemListBoxID)"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSQL; cmd.Parameters.AddWithValue("@nMaxObjMatchcodeID", nMaxObjMatchcodeID); cmd.Parameters.AddWithValue("@m_nFolderID", m_nFolderID); cmd.Parameters.AddWithValue("@itemListBoxID", itemListBox.ID); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } // this.lstbUsedMatchcodes.Items.Add(itemListBox); myListView lvi = new myListView(itemListBox.Name); lvi.ID = itemListBox.ID; lvi.SubItems.Add(this.cbxAllMatchcodes.SelectedItem.ToString()); this.lstvUsedMatchcodes.Items.Add(lvi); } else { MessageBox.Show("Element existiert bereits in der Liste", "Warnung"); } } }