private void btnOk_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (string.IsNullOrEmpty(txtIdNum.Text)) { MessageDialog.Show("Invalid Deduction Code", "You have entered an Invalid Code"); txtIdNum.SelectAll(); return; } ; var deduction = new DeductionDataReader().GetItem(txtIdNum.Text); if (deduction == null) { MessageDialog.Show("Invalid Deduction Code", "You have entered an Invalid Code"); txtIdNum.SelectAll(); return; } ItemData = deduction; DialogResult = DialogResult.OK; }
private bool DataIsValid() { if (string.IsNullOrEmpty(txtCode.Text)) { MessageDialog.ShowValidationError(txtCode, "Code must not be blank"); return(false); } if (string.IsNullOrEmpty(txtDescription.Text)) { MessageDialog.ShowValidationError(txtDescription, "Description must not be blank"); return(false); } var reader = new DeductionDataReader(); var findItem = reader.GetItem(txtCode.Text.Trim()); if (findItem != null && findItem.Id != ItemData.Id) { MessageDialog.ShowValidationError(txtCode, "Duplicate Deduction Code Already Exist!"); return(false); } return(true); }
private void btnSearch_Click(object sender, EventArgs e) { try { FlexGrid.Rows.Count = 1; if (!DataSearchIsValid()) { return; } var searchStyle = new SearchStyleEnum(); switch (cboSearchType.Text) { case "Contains": searchStyle = SearchStyleEnum.Contains; break; case "Starts With": searchStyle = SearchStyleEnum.StartsWith; break; case "Ends With": searchStyle = SearchStyleEnum.EndsWith; break; } var reader = new DeductionDataReader(); var items = reader.SearchItem(txtSearch.Text, searchStyle); var deductions = items as IList <Deduction> ?? items.ToList(); if (!deductions.Any()) { MessageDialog.ShowValidationError(txtSearch, "No items match your search"); return; } FlexGrid.Rows.Count = deductions.Count() + 1; var row = 0; foreach (var item in deductions.OrderBy(_ => _.Description)) { row++; FlexGrid[row, "code"] = item.Code; FlexGrid[row, "description"] = item.Description; FlexGrid.Select(1, 0); } FlexGrid.Focus(); } catch (Exception ex) { MessageDialog.ShowError(ex, this); } }