private void LoadData() { if (!string.IsNullOrEmpty(_productGroupId)) { _productGroup = _productGroupService.GetProductGrouprById(_productGroupId); txtProductGroupID.Text = _productGroupId; txtProductGroupName.Text = _productGroup.ProductGroupName; txtDescription.Text = _productGroup.Description; checkActive.Checked = _productGroup.Active; } else { txtProductGroupID.Text = _productGroupService.NextId(); } }
private void bbiDeleteProductGroup_ItemClick(object sender, ItemClickEventArgs e) { DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { foreach (var rowHandle in gridView1.GetSelectedRows()) { var productGroupId = gridView1.GetRowCellValue(rowHandle, "ProductGroupID"); if (productGroupId != null) { ProductGroup productGroup = _productGroupService.GetProductGrouprById(productGroupId.ToString()); if (productGroup != null) { try { _productGroupService.Delete(productGroupId.ToString()); } catch (Exception ex) { MessageBoxHelper.ShowMessageBoxError(ex.Message); } } } } LoadData(); } else { EnableButtonUpdateAndDelete(false); } }
/// <summary> /// Lưu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtProductGroupID.Text)) { XtraMessageBox.Show("Mã Nhóm hàng không được để trống !", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProductGroupID.Focus(); } else if (string.IsNullOrEmpty(txtProductGroupName.Text)) { XtraMessageBox.Show("Tên Nhóm Hàng không được để trống !", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProductGroupName.Focus(); } else { ProductGroup productGroup = _productGroupService.GetProductGrouprById(_productGroupId); if (productGroup != null) { productGroup.ProductGroupName = txtProductGroupName.Text; productGroup.Description = txtDescription.Text; productGroup.IsActive = checkActive.Checked; productGroup.ModifyDate = DateTime.Now; productGroup.UpdateBy = null; } try { _productGroupService.Update(productGroup); InsertSysLog(txtProductGroupName.Text); XtraMessageBox.Show("Sửa thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information); btnClose_Click(sender, e); } catch (Exception ex) { XtraMessageBox.Show(string.Format("Lỗi {0}", ex.Message), "THÔNG BÁO"); } } }
/// <summary> /// Xóa /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItemDelete_ItemClick(object sender, ItemClickEventArgs e) { DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { foreach (var rowHandle in gridView1.GetSelectedRows()) { var productGroupId = gridView1.GetRowCellValue(rowHandle, "ProductGroupID"); if (productGroupId != null) { ProductGroup productGroup = _productGroupService.GetProductGrouprById(productGroupId.ToString()); if (productGroup != null) { try { _productGroupService.Delete(productGroupId.ToString()); } catch (Exception ex) { XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } LoadProductGroups(); } else { EnableButtonUpdateAndDelete(false); } //if (!string.IsNullOrEmpty(ProductGroupId)) //{ // ProductGroup productGroup = _productGroupService.GetProductGrouprById(ProductGroupId); // if (productGroup != null) // { // DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa thông tin Nhóm Hàng : " + productGroup.ProductGroupName +" này không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); // if (result == DialogResult.Yes) // { // try // { // _productGroupService.Delete(ProductGroupId); // LoadProductGroups(); // // ProductGroupId == null // EnableButtonUpdateAndDelete(false); // } // catch (Exception ex) // { // XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO", // MessageBoxButtons.OK, MessageBoxIcon.Error); // } // } // } //} //else // XtraMessageBox.Show("Vui lòng chọn một Nhóm Hàng cần sửa!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); }