private void dgvProductAttributeList_CellClick(object sender, DataGridViewCellEventArgs e) { if (sender is DataGridView) { DataGridViewCell cell = ((DataGridView)sender).CurrentCell; if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1) { DialogResult result = MessageBox.Show("Bạn có muốn xóa Quy cách sản phẩm này?", "Xoá Quy cách sản phẩm này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvProductAttributeList.Rows[e.RowIndex]; BaseAttributeService baseAttributeService = new BaseAttributeService(); int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id"); ProductAttributeService productAttributeService = new ProductAttributeService(); List <ProductAttribute> productList = productAttributeService.SelectProductAttributeByWhere(x => x.AttributeId == id); if (productList.Count > 0) { MessageBox.Show("Quy cách sản phẩm này đang được sử dụng. Không xóa được!"); } else { if (!baseAttributeService.DeleteBaseAttribute(id)) { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } loadProductAttributeList(); } } } } }
public void loadProductAttributeList() { BaseAttributeService baseAttributeService = new BaseAttributeService(); List <BaseAttribute> baseAttributes = baseAttributeService.GetBaseAttributes(); if (baseAttributes != null) { setUpDataGrid(baseAttributes); } }
public void loadProductAttributeList() { BaseAttributeService baseAttributeService = new BaseAttributeService(); List<BaseAttribute> baseAttributes = baseAttributeService.GetBaseAttributes(); if (baseAttributes != null) { setUpDataGrid(baseAttributes); } }
public void loadDataForEditProductAttribute(int productAttributeId) { this.Text = "Chỉnh sửa quy cách này"; this.btnSave.Text = "Cập nhật"; BaseAttributeService baseAttributeService = new BaseAttributeService(); baseAttribute = baseAttributeService.GetBaseAttribute(productAttributeId); if (baseAttribute != null) { txtDescription.Text = baseAttribute.Description; txtCode.Text = baseAttribute.AttributeCode; txtName.Text = baseAttribute.AttributeName; ckbJambo.Checked = baseAttribute.Jampo; } }
private void btnSave_Click(object sender, EventArgs e) { if (validator1.Validate()) { if (baseAttribute != null && baseAttribute.Id > 0) { baseAttribute.Description = txtDescription.Text; baseAttribute.AttributeName = txtName.Text; baseAttribute.AttributeCode = txtCode.Text; baseAttribute.Jampo = ckbJambo.Checked; BaseAttributeService baseAttributeService = new BaseAttributeService(); bool result = baseAttributeService.UpdateBaseAttribute(baseAttribute); if (result) { MessageBox.Show("Loại quy cách đã được cập nhật vào hệ thống"); ((ProductAttributeList)this.CallFromUserControll).loadProductAttributeList(); this.Close(); } else { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { baseAttribute = new BaseAttribute { AttributeName = txtName.Text, Description = txtDescription.Text, AttributeCode = txtCode.Text, Jampo = ckbJambo.Checked }; BaseAttributeService baseAttributeService = new BaseAttributeService(); bool result = baseAttributeService.AddBaseAttribute(baseAttribute); if (result) { MessageBox.Show("Quy cách được tạo thành công"); ((ProductAttributeList)this.CallFromUserControll).loadProductAttributeList(); this.Close(); } else { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void loadSomeData() { if (productTypes == null) { ProductTypeService productTypeService = new ProductTypeService(); productTypes = productTypeService.GetProductTypes(); } if (productTypes != null) { cmbType.DataSource = productTypes; cmbType.DisplayMember = "TypeName"; cmbType.ValueMember = "Id"; } BaseAttributeService baseAttributeService = new BaseAttributeService(); if (baseAttributes == null) { baseAttributes = baseAttributeService.GetBaseAttributes(); } }
private void LoadAttributes(int productId) { if (productId == 0) { cbmAttrs.Enabled = false; cbmAttrs.SelectedValue = 0; cbmUnits.Enabled = false; cbmUnits.SelectedValue = 0; } else { cbmAttrs.Enabled = true; BaseAttributeService attrService = new BaseAttributeService(); BaseAttribute ba = new BaseAttribute { AttributeName = "Tất cả", Id = 0 }; ProductService productService = new ProductService(); Product p = productService.GetProduct(productId); List <ProductAttribute> pas = p.ProductAttributes.ToList(); attrs = new List <BaseAttribute>(); attrs.Add(ba); foreach (ProductAttribute pa in pas) { attrs.Add(pa.BaseAttribute); } attrs = attrs.OrderBy(a => a.Id).ToList(); if (attrs != null) { cbmAttrs.DataSource = attrs; cbmAttrs.DisplayMember = "AttributeName"; cbmAttrs.ValueMember = "Id"; } LoadUnits(productId, 0); } }
private void LoadAttributes(int productId) { if (productId == 0) { cbmAttrs.Enabled = false; cbmAttrs.SelectedValue = 0; cbmUnits.Enabled = false; cbmUnits.SelectedValue = 0; } else { cbmAttrs.Enabled = true; BaseAttributeService attrService = new BaseAttributeService(); BaseAttribute ba = new BaseAttribute { AttributeName = "Tất cả", Id = 0 }; ProductService productService = new ProductService(); Product p = productService.GetProduct(productId); List<ProductAttribute> pas = p.ProductAttributes.ToList(); attrs = new List<BaseAttribute>(); attrs.Add(ba); foreach (ProductAttribute pa in pas) { attrs.Add(pa.BaseAttribute); } attrs = attrs.OrderBy(a => a.Id).ToList(); if (attrs != null) { cbmAttrs.DataSource = attrs; cbmAttrs.DisplayMember = "AttributeName"; cbmAttrs.ValueMember = "Id"; } LoadUnits(productId, 0); } }
private void dgvProductAttributeList_CellClick(object sender, DataGridViewCellEventArgs e) { if (sender is DataGridView) { DataGridViewCell cell = ((DataGridView)sender).CurrentCell; if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1) { DialogResult result = MessageBox.Show("Bạn có muốn xóa Quy cách sản phẩm này?", "Xoá Quy cách sản phẩm này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvProductAttributeList.Rows[e.RowIndex]; BaseAttributeService baseAttributeService = new BaseAttributeService(); int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id"); ProductAttributeService productAttributeService = new ProductAttributeService(); List<ProductAttribute> productList = productAttributeService.SelectProductAttributeByWhere(x => x.AttributeId == id); if (productList.Count > 0) { MessageBox.Show("Quy cách sản phẩm này đang được sử dụng. Không xóa được!"); } else { if (!baseAttributeService.DeleteBaseAttribute(id)) { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } loadProductAttributeList(); } } } } }