Ejemplo n.º 1
0
        /// <summary>
        /// Handles Delete of an item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolBtnDelete_Click(object sender, EventArgs e)
        {
            DataRow drv = gridView1.GetFocusedDataRow();

            if (drv != null)
            {
                Items            itm    = new Items();
                ProductsCategory proCat = new ProductsCategory();
                int itemId = Convert.ToInt32(drv["ID"]);
                if (!itm.HasTransactions(itemId))
                {
                    if (XtraMessageBox.Show("Are You Sure, You want to delete this Transaction? You will not be able to restore this data.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        proCat.GetCategoryByItem(itemId);
                        foreach (DataRowView drcat in proCat.DefaultView)
                        {
                            ProductsCategory cat = new ProductsCategory();
                            cat.LoadByPrimaryKey(Convert.ToInt32(drcat["ID"]));
                            cat.MarkAsDeleted();
                            cat.Save();
                        }
                        itm.LoadByPrimaryKey(itemId);
                        itm.MarkAsDeleted();
                        itm.Save();
                        XtraMessageBox.Show("Item Deleted!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    XtraMessageBox.Show("Unable to Delete, This Item has been Received or Issued.", "Unable to Delete", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }