private void btnSearch_Click(object sender, EventArgs e) { _productGroupCollection = new ProductGroup.ParameteredCollection(SqlString.Null, cboBrand.SelectedIndex < 1 ? SqlString.Null : cboBrand.SelectedValue.ToString(), cboProductCategory.SelectedIndex < 1 ? SqlString.Null : cboProductCategory.SelectedValue.ToString(), txtProductGroupDescription.Text == string.Empty ? SqlString.Null : txtProductGroupDescription.Text); _productGroupCollection.Load(); bindingSourceProductGroup.DataSource = _productGroupCollection; }
public List <DropDownItem> GetProductGroupDropDownCollection() { var productGroupCollection = new ProductGroup.ParameteredCollection(SqlString.Null, SqlString.Null, SqlString.Null, SqlString.Null); productGroupCollection.Load(); var list = new List <DropDownItem>(productGroupCollection.Count + 1) { new DropDownItem(string.Empty, string.Empty) }; list.AddRange(productGroupCollection.Select(productGroup => new DropDownItem(productGroup.ProductGroupCode.Value, productGroup.ProductGroupDescription.IsNull ? string.Empty : productGroup.ProductGroupDescription.Value))); return(list); }
private void dgvProductGroup_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { try { if (!dgvProductGroup.IsCurrentRowDirty) { return; } if (dgvProductGroup.CurrentRow.Cells["ProductGroupCode"].Value != null) { SqlString productGroupCode = dgvProductGroup.CurrentRow.Cells["ProductGroupCode"].Value.ToString(); if (productGroupCode.IsNull) { dgvProductGroup.Rows[e.RowIndex].ErrorText = "Please select Brand and Product Category"; e.Cancel = true; return; } ProductGroup productGroup = null; // new record if (e.RowIndex >= _productGroupCollection.Count) { var checkProductGroupCollection = new ProductGroup.ParameteredCollection(productGroupCode, SqlString.Null, SqlString.Null, SqlString.Null); checkProductGroupCollection.Load(); if (checkProductGroupCollection.Count > 0) { dgvProductGroup.Rows[e.RowIndex].ErrorText = "Product Group Code already exists"; e.Cancel = true; } else { productGroup = _productGroupCollection.Create(new ProductGroupKey(productGroupCode)); if (dgvProductGroup.CurrentRow.Cells["ProductGroupDescription"].Value != null) { productGroup.ProductGroupDescription = (SqlString)dgvProductGroup.CurrentRow.Cells["ProductGroupDescription"].Value; } _productGroupCollection.Save(productGroup); // when the initial collection is empty // 1. brand in bindingSource is not set to the correct type, so reset the bindingSource.DataSource below // 2. the data moves above need to check for null if (bindingSourceProductGroup.Count == 1) { bindingSourceProductGroup.DataSource = null; bindingSourceProductGroup.DataSource = _productGroupCollection; } else { bindingSourceProductGroup.List[bindingSourceProductGroup.Count - 1] = productGroup; } } } // existing record else { //productGroup = _productGroupCollection[new ProductGroupKey(productGroupCode)]; //productGroup.Save(); productGroup = (ProductGroup)dgvProductGroup.CurrentRow.DataBoundItem; _productGroupCollection.Save(productGroup); _productGroupCollection[new ProductGroupKey(productGroupCode)] = productGroup; } if (ProductGroupCollectionInvalidated != null) { ProductGroupCollectionInvalidated(this, new EventArgs()); } } } catch (Exception ex) { Utility.GetInstance().HandleException(this, ex, e); } }
private void dgvProductGroup_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { try { if (!dgvProductGroup.IsCurrentCellDirty) { return; } if (e.FormattedValue == null) { dgvProductGroup.Rows[e.RowIndex].ErrorText = "Entry is required"; e.Cancel = true; } else { if (dgvProductGroup.Columns[e.ColumnIndex].Name == "Brand" && dgvProductGroup.Rows[e.RowIndex].Cells["ProductCategory"].Value != null) { var formattedValue = e.FormattedValue.ToString(); var productCategoryCode = dgvProductGroup.Rows[e.RowIndex].Cells["ProductCategory"].Value.ToString(); if (formattedValue != "<< select >>" && productCategoryCode != string.Empty) { dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value = (SqlString)string.Format("{0}{1}", formattedValue.Substring(0, 2), productCategoryCode); } } else if (dgvProductGroup.Columns[e.ColumnIndex].Name == "ProductCategory" && dgvProductGroup.Rows[e.RowIndex].Cells["Brand"].Value != null) { var formattedValue = e.FormattedValue.ToString(); var brandCode = dgvProductGroup.Rows[e.RowIndex].Cells["Brand"].Value.ToString(); if (formattedValue != "<< select >>" && brandCode != string.Empty) { dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value = (SqlString)string.Format("{0}{1}", brandCode, formattedValue.Substring(0, 2)); } } if ((dgvProductGroup.Columns[e.ColumnIndex].Name == "Brand" || dgvProductGroup.Columns[e.ColumnIndex].Name == "ProductCategory") && dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value != null && dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value.ToString() != "Null") { var checkProductGroupCollection = new ProductGroup.ParameteredCollection((SqlString)dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value, SqlString.Null, SqlString.Null, SqlString.Null); checkProductGroupCollection.Load(); if (checkProductGroupCollection.Count > 0) { dgvProductGroup.Rows[e.RowIndex].ErrorText = "Product Group already exists"; e.Cancel = true; } if (dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value != null) { var brandCode = dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value.ToString().Substring(0, 2); var productCategoryCode = dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupCode"].Value.ToString().Substring(2, 2); dgvProductGroup.Rows[e.RowIndex].Cells["ProductGroupDescription"].Value = (SqlString)string.Format("{0} - {1}", GetDescription(_brandDropDownCollection, brandCode), GetDescription(_productCategoryDropDownCollection, productCategoryCode)); } } } } catch (Exception ex) { Utility.GetInstance().HandleException(this, ex, e); } }