/// <summary> /// Delete a file from the database /// </summary> /// <param name="incomingFile"> /// The file you wish to delete /// </param> /// <returns> /// A returns a boolean value indicating success or failure. /// </returns> public async Task <bool> DeleteFile(IncomingFileModel incomingFile) { using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString())) { var param = new DynamicParameters(); param.Add("@Id", incomingFile.Id); int result = await connection.ExecuteAsync("spIncomingFile_Delete", param, commandType : CommandType.StoredProcedure); return(result > 0); } }
private void txtRegistrySearch_OnValueChanged(object sender, EventArgs e) { if (txtRegistrySearch.Text.Trim() == string.Empty) { if (selectedFileToUpdate != null) { ResetControls(); selectedFileToUpdate = null; } } }
public void PopulateControls(IncomingFileModel result) { txtRegistryNumber.Text = result.RegistryNumber.ToString(); dtpDateReceived.Value = result.DateReceived; txtPersonSent.Text = result.PersonSent; dtpDateofLetter.Value = result.DateOfLetter; txtReferenceNumber.Text = result?.ReferenceNumber; txtSubject.Text = result.Subject; txtFromDepartment.Text = result.DepartmentSent; txtRemarks.Text = result?.Remarks; txtPdfName.Text = result?.FileName; cboDepartment.SelectedValue = result.Department.Id; }
private void ResetControls() { LoadAllFiles(); dtpDateReceived.Value = DateTime.Now; txtFromDepartment.Text = ""; txtPdfName.Text = ""; txtPersonSent.Text = ""; txtReferenceNumber.Text = ""; txtRemarks.Text = ""; txtSearch.Text = ""; txtSubject.Text = ""; dtpDateofLetter.Value = DateTime.Now; cboDepartment.SelectedIndex = -1; RegistryNumber(); itemsToTake = 0; ToggleNavigationButtons(); selectedFileToUpdate = null; ToggleButtonStates(); }
/// <summary> /// Updates a file /// </summary> /// <param name="incomingFile"> /// The File to update /// </param> /// <returns> /// A boolean value indicating success or failure. /// </returns> public async Task <bool> UpdateFile(IncomingFileModel incomingFile) { using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString())) { var param = new DynamicParameters(); param.Add("@RegistryNumber", incomingFile.RegistryNumber); param.Add("@DateReceived", incomingFile.DateReceived); param.Add("@PersonSent", incomingFile.PersonSent); param.Add("@DateOfLetter", incomingFile.DateOfLetter); param.Add("@ReferenceNumber", incomingFile.ReferenceNumber); param.Add("@Subject", incomingFile.Subject); param.Add("@DepartmentSent", incomingFile.DepartmentSent); param.Add("@FileName", incomingFile.FileName); param.Add("@Remarks", incomingFile.Remarks); param.Add("@DepartmentId", incomingFile.Department.Id); param.Add("@Id", incomingFile.Id); int result = await connection.ExecuteAsync("spIncomingFile_Update", param, commandType : CommandType.StoredProcedure); return(result > 0); } }
/// <summary> /// Creates a new File into the database /// </summary> /// <param name="incomingFile"> /// The file you want to create /// </param> /// <returns> /// The newly created file. /// </returns> public async Task <IncomingFileModel> CreateIncomingFile(IncomingFileModel incomingFile) { using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString())) { var param = new DynamicParameters(); param.Add("@RegistryNumber", incomingFile.RegistryNumber); param.Add("@DateReceived", incomingFile.DateReceived); param.Add("@PersonSent", incomingFile.PersonSent); param.Add("@DateOfLetter", incomingFile.DateOfLetter); param.Add("@ReferenceNumber", incomingFile.ReferenceNumber); param.Add("@Subject", incomingFile.Subject); param.Add("@DepartmentSent", incomingFile.DepartmentSent); param.Add("@FileName", incomingFile.FileName); param.Add("@Remarks", incomingFile.Remarks); param.Add("@DepartmentId", incomingFile.Department.Id); param.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); await connection.ExecuteAsync("spIncomingFile_Create", param, commandType : CommandType.StoredProcedure); incomingFile.Id = param.Get <int>("@Id"); return(incomingFile); } }
private void btnPrevious_Click(object sender, EventArgs e) { btnNext.Enabled = true; if (allFiles.Count() > 0) { //Select the last element and decrease selection by 1 if (itemsToTake == 0) { selectedFileToUpdate = allFiles.Last(); PopulateControls(selectedFileToUpdate); itemsToTake = allFiles.Count(); } else if (itemsToTake <= allFiles.Count()) { selectedFileToUpdate = allFiles.Take(itemsToTake - 1).Last(); PopulateControls(selectedFileToUpdate); itemsToTake--; } } ToggleNavigationButtons(); ToggleButtonStates(); }
private void btnNext_Click(object sender, EventArgs e) { btnPrevious.Enabled = true; if (allFiles.Count() > 0) { //Select the first element and increase selection by 1. if (itemsToTake == 0) { selectedFileToUpdate = allFiles.First(); PopulateControls(selectedFileToUpdate); itemsToTake++; } else if (itemsToTake <= allFiles.Count()) { selectedFileToUpdate = allFiles.Skip(itemsToTake).First(); PopulateControls(selectedFileToUpdate); itemsToTake++; } } ToggleNavigationButtons(); ToggleButtonStates(); }
private void btnRegistrySearch_Click(object sender, EventArgs e) { if (txtRegistrySearch.Text.Trim() != string.Empty) { int registryNumber = 0; if (int.TryParse(txtRegistrySearch.Text.Trim(), out registryNumber)) { if (allFiles.Count() > 0) { selectedFileToUpdate = allFiles.FirstOrDefault(x => x.RegistryNumber == registryNumber); if (selectedFileToUpdate != null) { btnNext.Enabled = true; btnPrevious.Enabled = true; itemsToTake = registryNumber; ToggleNavigationButtons(); //Populate records into controls PopulateControls(selectedFileToUpdate); ToggleButtonStates(); } else { MessageBox.Show("File not Found. Invalid Registry Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No Files Found. Please Register Files", "No Files", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Invalid Registry Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async void btnSave_Click(object sender, EventArgs e) { if (IsValidForm()) { try { string fileName = null; if (txtPdfName.Text.Trim() != string.Empty) { fileName = PdfName(); } //Try to save pdf to folder if (fileName != null) { if (File.Exists(txtPdfName.Text.Trim())) { _pdfSettings.CreateFile(fileName, txtPdfName.Text.Trim()); } else { MessageBox.Show($"The pdf you want to save has been \n moved from the location {txtPdfName.Text.Trim()}\n Please check the file again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //Save the file to the database string[] regNo = txtRegistryNumber.Text.Split('-'); IncomingFileModel fileModel = new IncomingFileModel() { RegistryNumber = int.Parse(regNo[2]), DateReceived = dtpDateReceived.Value, PersonSent = txtPersonSent.Text.Trim().ToLower(), DateOfLetter = dtpDateofLetter.Value, Subject = txtSubject.Text.Trim().ToLower(), DepartmentSent = txtFromDepartment.Text.Trim().ToLower(), Department = (DepartmentModel)cboDepartment.SelectedItem, FileName = fileName }; MessageBox.Show(fileModel.RegistryNumber.ToString()); if (txtReferenceNumber.Text.Trim() != string.Empty) { fileModel.ReferenceNumber = txtReferenceNumber.Text.Trim(); } if (txtRemarks.Text.Trim() != string.Empty) { fileModel.Remarks = txtRemarks.Text.Trim(); } //Save the file to the database await _incomingFile.CreateIncomingFile(fileModel); Logger.WriteToFile(Logger.FullName, "successfully registered a file"); LoadAllFiles(); ResetControls(); if (MessageBox.Show("File information has been successfully saved.\n Do you want to perform another save?", "Save File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { this.Close(); } } catch (Exception ex) { MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }