コード例 #1
0
        /// <summary>
        /// Saves Category/Sub Category related information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtCategory.Text != "" || txtCatCode.Text != "")
            {
                if (cboCategory.Visible)
                {
                    SubCategory subCat = new SubCategory();
                    if (_catId != 0)
                        subCat.LoadByPrimaryKey(_catId);
                    else
                        subCat.AddNew();

                    subCat.CategoryId = Convert.ToInt32(cboCategory.SelectedValue);
                    subCat.SubCategoryName = txtCategory.Text;
                    subCat.Description = txtDescription.Text;
                    subCat.SubCategoryCode = txtCatCode.Text;
                    subCat.Save();
                }
                else
                {
                    Category cat = new Category();
                    if (_catId != 0)
                        cat.LoadByPrimaryKey(_catId);
                    else
                        cat.AddNew();
                    cat.CategoryName = txtCategory.Text;
                    cat.Description = txtDescription.Text;
                    cat.CategoryCode = txtCatCode.Text;
                    cat.Save();
                }

                PopulateCategoryTree();
                ResetCategoryForm();
            }
            else
            {
                if (txtCatCode.Text == "")
                    txtCatCode.BackColor = Color.FromArgb(251, 214, 214);
                if (txtCategory.Text == "")
                    txtCategory.BackColor = Color.FromArgb(251, 214, 214);
            }
        }