//Delete button click event for Document delete. private void btnDeleteText_Click(object sender, EventArgs e) { DialogResult dr = MsgBox.Show("Do You want to Update the Document ?", "Confirmation", "YES", "NO"); if (dr == DialogResult.Yes) { DatabaseNonQuery.InsertUpdateDelete($"Delete from TblText where id='{articleId}'"); MangingFormAndControls.PanelClear(PanelText); ArticleLoader(); MessageBox.Show("File Deleted From Storage", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//Allows user to delete their records. private void DeleteReference(object sender, EventArgs e) { if (UserInfo.id == userId) { DatabaseNonQuery.InsertUpdateDelete($"Delete from TblReference where id ='{id}'"); ShowTableData(); MangingFormAndControls.PanelClear(PanelRefrenceFields); } else { MsgBox.Show("You cannot Delete This Reference.", "Error", "OK", "Cancel"); } }
//Update Button Click Event. private void UpdateText(object sender, EventArgs e) { DialogResult dr = MsgBox.Show("Do You want to Update the Document ?", "Confirmation", "YES", "NO"); if (dr == DialogResult.Yes) { DatabaseNonQuery.InsertUpdateDelete($"Update TblText set Text ='{txtWordEditor.Text}',userID = '{UserInfo.id}', Refs='{txtRefrence.Text}' where id='{articleId}'"); ArticleLoader(); } else { MessageBox.Show("File not Updated", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//Admin's record delete from database. private void DeleteData(object sender, EventArgs e) { DataTable userCheckDT = TabelConnector.DataTableLoader($"Select * from Users Where UserId ='{txtUserId.Text}' or email = '{txtEmail.Text}'"); if (Convert.ToInt32(userCheckDT.Rows[0][0]) == UserInfo.id)//Admin cannot delete his/her own record. { MsgBox.Show($"You Cannot delete yourself", "Restriction", "OK", "Cancel"); } else { DatabaseNonQuery.InsertUpdateDelete($"Delete from Users where id = '{id}'"); ShowTableData(); MessageBox.Show("User removed from the storage", "Update Done", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MangingFormAndControls.PanelClear(panelUserInfo); //After operation all the text boxes are cleared. } }
//Updates saved refrences if the user is trying to update own recoard. private void UpdateReference(object sender, EventArgs e) { if (txtTitle.Text == "" || cmbDocType.SelectedIndex == 0 || txtYear.Text == "" || txtPublisher.Text == "" || txtNameOfSource.Text == "" || txtPageNumber.Text == "")/// { MessageBox.Show("Title, Document type, Year, Publisher, Name of Source, Page Number fields cannot be empty.", "Field Empty", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (UserInfo.id == userId) { DatabaseNonQuery.InsertUpdateDelete($"Update TblReference set Title ='{txtTitle.Text}', Author ='{txtAuthorsList.Text}' , DocumentType = '{cmbDocType.Text}', Year ='{txtYear.Text}', Publisher = '{txtPublisher.Text}' , Abstract = '{txtAbstract.Text}' , NameOfSource = '{txtNameOfSource.Text}' , Issue = '{txtIssue.Text}' , Volume = '{txtVolume.Text}' , PageNumbers = '{txtPageNumber.Text}' , Notes = '{txtNotes.Text}', UserID = '{UserInfo.id}' where id ='{id}'"); ShowTableData(); MangingFormAndControls.PanelClear(PanelRefrenceFields); } else { MsgBox.Show("You cannot Edit This Reference.", "Error", "OK", "Cancel"); } } }
//Saves textbox's data to the database. if the user is not a Guest. private void SaveReference(object sender, EventArgs e) { if (txtTitle.Text == "" || cmbDocType.SelectedIndex == 0 || txtYear.Text == "" || txtPublisher.Text == "" || txtNameOfSource.Text == "" || txtPageNumber.Text == "") { MessageBox.Show("Title, Document type, Year, Publisher, Name of Source, Page Number fields cannot be empty.", "Field Empty", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (UserInfo.loggedIn == true) { DatabaseNonQuery.InsertUpdateDelete($"Insert into TblReference (Title, Author, DocumentType, Year, Publisher, Abstract, NameOfSource, Issue, Volume, PageNumbers, Notes, UserID) values('{txtTitle.Text}','{txtAuthorsList.Text}','{cmbDocType.Text}','{txtYear.Text}','{txtPublisher.Text}','{txtAbstract.Text}','{txtNameOfSource.Text}','{txtIssue.Text}','{txtVolume.Text}','{txtPageNumber.Text}','{txtNotes.Text}','{UserInfo.id}')"); ShowTableData(); MangingFormAndControls.PanelClear(PanelRefrenceFields); } else { //Shows error if it is Guest. MsgBox.Show("Please Signup / Login First", "Operation Fail", "Ok", "Cancel"); } } }
//Update database data with additional admin feature. private void AdminUpdateData(object sender, EventArgs e) { if (txtFirstName.Text == "" || txtUserId.Text == "" || txtEmail.Text == "" || txtPassword.Text == "") { MessageBox.Show("User First Name, UserID, Email, Password cannot be empty", "Field Empty", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DataTable userCheckDT = TabelConnector.DataTableLoader($"Select * from Users Where UserId ='{txtUserId.Text}'"); if (userCheckDT.Rows.Count > 1) { MsgBox.Show($"User Already Registered", "Sign up Error", "OK", "Cancel"); } else { DatabaseNonQuery.InsertUpdateDelete($"Update Users set FirstName ='{txtFirstName.Text}',LastName='{txtLastName.Text}',UserId = '{txtUserId.Text}', Contact = '{txtContact.Text}', Email = '{txtEmail.Text}', Address = '{txtAddress.Text}', Password = '******', UserType = '{cmbUserType.Text}' where id='{id}'"); ShowTableData(); MessageBox.Show("User Information Updated", "Update Done", MessageBoxButtons.OK, MessageBoxIcon.Information); MangingFormAndControls.PanelClear(panelUserInfo); //After operation all the text boxes are cleared. } } }
//Database data insert for data record. private void SaveData(object sender, EventArgs e) { if (txtFirstName.Text == "" || txtUserId.Text == "" || txtEmail.Text == "" || txtPassword.Text == "") { MessageBox.Show("User First Name, UserID, Email, Password cannot be empty", "Field Empty", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DataTable userCheckDT = TabelConnector.DataTableLoader($"Select * from Users Where UserId ='{txtUserId.Text}'"); if (userCheckDT.Rows.Count > 1) { MsgBox.Show($"User Already Registered", "Sign up Error", "OK", "Cancel"); } else //If finds no previous record user's information is inserted to database. { DatabaseNonQuery.InsertUpdateDelete($"Insert into Users(FirstName, LastName, UserId, Contact, Email, Address, Password, UserType) values('{txtFirstName.Text}','{txtLastName.Text}','{txtUserId.Text}','{txtContact.Text}','{txtEmail.Text}','{txtAddress.Text}','{txtPassword.Text}','{cmbUserType.Text}')"); ShowTableData(); MessageBox.Show("User Registration Complete. User Can login now", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); MangingFormAndControls.PanelClear(panelUserInfo); //After operation all the text boxes are cleared. } } }
int RefID; //Get's refrence id from the RefrenceList DataGridView cell click event. // Save Button Click Event and user confirmations.. private void SaveDocument(object sender, EventArgs e) { if (UserInfo.loggedIn == false) { MessageBox.Show("Please Login / Signup First", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult dr = MsgBox.Show("Do You want to save the Document ?", "Confirmation", "YES", "NO"); if (dr == DialogResult.Yes) { DatabaseNonQuery.InsertUpdateDelete($"Insert into TblText(Text,Refs, userid) values('{txtWordEditor.Text}','{txtRefrence.Text}','{UserInfo.id}')"); MessageBox.Show("File Saved to the storage.", "File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); ArticleLoader(); } else { MessageBox.Show("File not Saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }