Esempio n. 1
0
        private int AddSubCategory()
        {
            int ret = 0;

            Cursor.Current = Cursors.WaitCursor;
            ProductSubcategory psc        = new ProductSubcategory();
            string             subCatName = txtSubcategory.Text.Trim();

            try
            {
                int categoryID = 0;
                try
                {
                    categoryID = Int32.Parse(cmbCategories.SelectedValue.ToString());
                }
                catch
                {
                    categoryID = 0;
                }
                if (categoryID > 0)
                {
                    psc.Name = subCatName;
                    psc.ProductCategoryID = categoryID;
                    int pscid = psc.Exists(psc.Name, psc.ProductCategoryID);
                    if (pscid > 0)
                    {
                        DialogResult result = MessageBox.Show("Product Subcategory " + psc.Name + " already exists\nWould you like to update it?", "MICS", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            psc.UpdateProductSubcategory(psc);
                            MessageBox.Show("Record updated successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Record is not saved", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        psc.AddProductSubcategory(psc);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Product Subcategories", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
            }
            finally
            {
                psc = null;
            }
            Cursor.Current = Cursors.Default;
            return(ret);
        }
Esempio n. 2
0
        private void UpdateSubCategory()
        {
            Cursor.Current = Cursors.WaitCursor;
            ProductSubcategory psc        = new ProductSubcategory();
            string             subCatName = txtSubcategory.Text.Trim();
            int subCatID = 0;
            int catID    = 0;

            try
            {
                subCatID = Int32.Parse(lblSubcategoryID.Text.ToString());
                catID    = Int32.Parse(cmbCategories.SelectedValue.ToString());
            }
            catch
            {
                subCatID = 0;
            }
            if (subCatID == 0 || catID == 0)
            {
                Cursor.Current = Cursors.Default;
                return;
            }
            try
            {
                psc.Name = subCatName;
                psc.ProductSubcategoryID = subCatID;
                psc.ProductCategoryID    = catID;
                psc.UpdateProductSubcategory(psc);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Product Subcategories", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
            }
            finally
            {
                psc = null;
            }
            Cursor.Current = Cursors.Default;
        }