private void cbColumnNames_SelectedIndexChanged(object sender, EventArgs e) { if (selectedAttributeSet == null) { selectedAttributeSet = new AttributePropertyParent(); } selectedAttributeSet.basePriceColumn = cbColumnNames.Text; }
public ArrayList getAttributeSetProperties(Supplier s, AttributePropertyParent parent) { ArrayList properties = new ArrayList(); query = "SELECT propertyID, stockCode, skuCode, propertyName, position FROM attribute_properties WHERE attributeSetID = " + parent.attributeSetID + " ORDER BY position"; DataTable dt = db.read(query); for (int i = 0; i < dt.Rows.Count; i++) { properties.Add(bindAttributeSetProperties(dt.Rows[i])); } return(properties); }
public void deleteSet(Supplier s, AttributePropertyParent set) { ArrayList queries = new ArrayList(); queries.Add("DELETE FROM supplier_attributes WHERE attributeSetID = " + set.attributeSetID); queries.Add("DELETE FROM attribute_properties WHERE attributeSetID = " + set.attributeSetID); try { db.writeTransaction(queries); } catch (Exception ee) { throw; } }
public void deleteFullAttributeSet(AttributePropertyParent attributeSet) { ArrayList queries = new ArrayList(); query = "DELETE FROM supplier_attributes WHERE attributeSetID = " + attributeSet.attributeSetID; queries.Add(query); query = "DELETE FROM attribute_properties WHERE attributeSetID = " + attributeSet.attributeSetID; queries.Add(query); try { db.writeTransaction(queries); } catch (Exception ee) { throw new Exception("Unable to delete attribute set: " + ee.Message); } }
private void dgvItems_RowEnter(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { //check if this row is a parent attribute, and display the child properties string sku = dgvItems.Rows[e.RowIndex].Cells["code"].Value.ToString(); selectedAttributeSet = findParentAttribute(sku); if (selectedAttributeSet != null) { //sets the parent stock code lblParentStockCode.Text = selectedAttributeSet.stockCode; //clears the currently highlighted children foreach (DataGridViewRow row in dgvItems.Rows) { if (row.DefaultCellStyle.BackColor == Color.Aquamarine) { row.DefaultCellStyle.BackColor = Color.White; } } //sets the base price column string basePriceColumn = selectedAttributeSet.basePriceColumn; cbColumnNames.SelectedValue = basePriceColumn; //get the items in this attribute set ArrayList properties = attrMethods.getAttributeSetProperties(selectedSupplier, selectedAttributeSet); foreach (AttributeProperty prop in properties) { //find the child items and change the color foreach (DataGridViewRow row in dgvItems.Rows) { if (row.Cells["code"].Value.ToString() == prop.stockCode) { row.DefaultCellStyle.BackColor = Color.Aquamarine; } } } } } }
private void setParentToolStripMenuItem_Click(object sender, EventArgs e) { //remove the current colouring foreach (DataGridViewRow row in dgvItems.Rows) { row.DefaultCellStyle.BackColor = Color.White; } AttributePropertyParent newParent = new AttributePropertyParent(); newParent.attributeSetName = lblAttributeSet.Text; newParent.stockCode = dgvItems.Rows[selectedRowIndex].Cells["code"].Value.ToString(); newParent.propertyName = InputBox.ShowDialog("Property Name", "Property Name", newParent.propertyName); newParent.skuCode = dgvItems.Rows[selectedRowIndex].Cells["skuCode"].Value.ToString(); newParent.basePriceColumn = cbColumnNames.Text; fullAttributeSets.Add(newParent); lblParentStockCode.Text = newParent.stockCode; selectedAttributeSet = newParent; dgvItems.Rows[selectedRowIndex].DefaultCellStyle.BackColor = Color.SkyBlue; }
public List <AttributePropertyParent> getFullAttributeSet(Supplier s, string attributeName) { query = "SELECT attributeSetID, attributeName, basePriceColumn, parentPropertyName, parentPropertyCode, parentPropertySKUCode FROM supplier_attributes WHERE attributeName = '" + attributeName + "' AND supplierID = " + s.supplierID; DataTable dt = db.read(query); List <AttributePropertyParent> parentProperties = new List <AttributePropertyParent>(); for (int i = 0; i < dt.Rows.Count; i++) { AttributePropertyParent prop = new AttributePropertyParent(); if (dt.Rows.Count == 0) { return(null); } prop.attributeSetID = int.Parse(dt.Rows[i]["attributeSetID"].ToString()); prop.attributeSetName = dt.Rows[i]["attributeName"].ToString(); prop.basePriceColumn = dt.Rows[i]["basePriceColumn"].ToString(); prop.propertyName = dt.Rows[i]["parentPropertyName"].ToString(); prop.stockCode = dt.Rows[i]["parentPropertyCode"].ToString(); prop.skuCode = dt.Rows[i]["parentPropertySKUCode"].ToString(); query = "SELECT propertyID, stockCode, skuCode, position, propertyName FROM attribute_properties WHERE attributeSetID = " + prop.attributeSetID; DataTable dtChildren = db.read(query); List <AttributeProperty> childrenProperties = new List <AttributeProperty>(); for (int ji = 0; ji < dtChildren.Rows.Count; ji++) { childrenProperties.Add(bindAttributeSetProperties(dtChildren.Rows[ji])); } prop.childrenProperties = childrenProperties; parentProperties.Add(prop); } return(parentProperties); }
private void removeChildToolStripMenuItem1_Click(object sender, EventArgs e) { selectedAttributeSet = findParentAttribute(lblParentStockCode.Text); if (selectedAttributeSet == null) { MessageBox.Show("Please select a parent first"); return; } string sku = dgvItems.Rows[selectedRowIndex].Cells["code"].Value.ToString(); if (sku == selectedAttributeSet.stockCode) { //this is a parent - get confirmation as this action is destructive if (MessageBox.Show("Are you sure you wish to delete this parent and all child properties? This action cannot be undone", "Confirmation", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } try { attrMethods.deleteFullAttributeSet(selectedAttributeSet); } catch (Exception ee) { MessageBox.Show(ee.Message); return; } //clears the currently highlighted children foreach (AttributeProperty props in selectedAttributeSet.childrenProperties) { foreach (DataGridViewRow row in dgvItems.Rows) { if ((row.Cells["code"].Value.ToString() == props.stockCode && row.DefaultCellStyle.BackColor == Color.Aquamarine) || row.Cells["code"].Value.ToString() == selectedAttributeSet.stockCode) { row.DefaultCellStyle.BackColor = Color.White; } } } //remove the parent out of the collection fullAttributeSets.Remove(selectedAttributeSet); selectedAttributeSet = new AttributePropertyParent(); } else { //this is a parent - get confirmation as this action is destructive if (MessageBox.Show("Are you sure you wish to delete this child properties? This action cannot be undone", "Confirmation", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } AttributeProperty childProperty = findChildAttribute(sku); selectedAttributeSet.childrenProperties.Remove(childProperty); if (childProperty.propertyID != null) { attrMethods.deleteChildProperties(childProperty); } dgvItems.Rows[selectedRowIndex].DefaultCellStyle.BackColor = Color.White; } }