private void DeleteButton_Click(object sender, EventArgs e) { tssStatus.Text = "Ready"; Unit unit = GetCurrent(); if (unit == null) { return; } DialogResult result = MessageBox.Show($"Are you sure, you want to delete unit '{unit.Code}'?", "Delete", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { bool success = _repository.Remove(unit.Id); if (success) { UnitsBindingSource.RemoveCurrent(); tssStatus.Text = "Deleted successfully!"; } else { tssStatus.Text = "Error occured while deleting."; } } else { tssStatus.Text = "Cancelled!"; } }
private void CancelButton_Click(object sender, EventArgs e) { UnitErrors.Clear(); RestoreFromDatabase(); UnitsBindingSource.CancelEdit(); UnitsBindingSource.ResetBindings(false); grpUnits.Enabled = true; }
private void SearchText_TextChanged(object sender, EventArgs e) { if (txtSearch.Text == string.Empty) { UnitsBindingSource.RemoveFilter(); } else { string searchTerm = txtSearch.Text.ToLower(); (UnitsBindingSource.DataSource as BindingListView <Unit>).ApplyFilter( u => u.Code.ToLower().Contains(searchTerm) || u.UnitName.ToLower().Contains(searchTerm) || (u.UnitDesc == null ? false : u.UnitDesc.ToLower().Contains(searchTerm)) ); } }
private void SaveButton_Click(object sender, EventArgs e) { txtCode_Validated(this, null); txtName_Validated(this, null); if (!string.IsNullOrEmpty(UnitErrors.GetError(txtCode)) || !string.IsNullOrEmpty(UnitErrors.GetError(txtName))) { return; } bool success; bool isAdding = false; Unit unit = GetCurrent(); if (unit.Id == 0) { isAdding = true; success = _repository.Add(AppConfig.CurrentCompany.Id, unit) > 0; } else { success = _repository.Update(unit.Id, unit); } if (success) { UnitsBindingSource.EndEdit(); tssStatus.Text = "Saved successfully!"; grpUnits.Enabled = true; if (isAdding) { btnAdd.PerformClick(); } } else { tssStatus.Text = "Error: Error occured while saving."; } }
private void AddButton_Click(object sender, EventArgs e) { UnitsBindingSource.AddNew(); txtCode.Focus(); grpUnits.Enabled = false; }