예제 #1
0
        private void cbCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            HierachicalName = string.Empty;
            if (null != cbCategories.SelectedItem)
            {
                ESPCategory category = cbCategories.SelectedItem as ESPCategory;
                if (null == category)
                {
                    return;
                }

                HierachicalName = category.Name;
            }

            if (HierachicalName != string.Empty)
            {
                txtCategoryName.Text = HierachicalName + "-" + RemoveTone(txtCategoryTitle.Text);
            }
            else
            {
                txtCategoryName.Text = RemoveTone(txtCategoryTitle.Text);
            }

            if (Mode != EditorMode.None)
            {
                btnCategory_Save.Enabled = (txtCategoryName.Text.Length > 0 ||
                                            txtCategoryTitle.Text.Length > 0);
            }
        }
예제 #2
0
 private bool SaveCategory(ESPCategory category)
 {
     try
     {
         if (Mode == EditorMode.AddNew)
         {
             DB.Categories.Add(category);
         }
         else
         {
             var curCats = DB.ChangeTracker.Entries <ESPCategory>();
             var curCat  = curCats.Where(e => e.Entity.Id == category.Id).Select(e => e.Entity).FirstOrDefault();
             if (null != curCat)
             {
                 curCat.Name   = category.Name;
                 curCat.Title  = category.Title;
                 curCat.Parent = category.Parent;
             }
         }
         DB.SaveChanges();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
     return(true);
 }
예제 #3
0
        private bool DeleteCategory(ESPCategory category)
        {
            if (null == category)
            {
                return(false);
            }

            try
            {
                var curCats = DB.ChangeTracker.Entries <ESPCategory>();
                var curCat  = curCats.Where(e => e.Entity.Name == category.Name).Select(e => e.Entity).FirstOrDefault();
                if (null != curCat)
                {
                    DB.Categories.Remove(curCat);
                    DB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }

            return(true);
        }
예제 #4
0
        private bool LoadCategoriesOfParent(ESPCategory parentobj, IQueryable <ESPCategory> categories, ref int level)
        {
            int item = -1;

            level += 4;
            foreach (var cat in categories)
            {
                cat.DisplayName  = (new string(' ', level)) + cat.Title;
                cat.ParentObject = parentobj;
                item             = cbCategories.Items.Add(cat);
                item             = lbCategories.Items.Add(cat);
                var categories2 = DB.Categories.Where(e => e.Parent == cat.Id).OrderBy(e => e.Name);
                LoadCategoriesOfParent(cat, categories2, ref level);
            }
            level -= 4;
            return(true);
        }
예제 #5
0
        private void lbCategories_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Delete:
            {
                if (null == lbCategories.SelectedItems)
                {
                    return;
                }

                bool bChanged = false;
                foreach (var obj in lbCategories.SelectedItems)
                {
                    ESPCategory category = obj as ESPCategory;
                    if (DeleteCategory(category))
                    {
                        bChanged = true;
                    }
                }

                if (!bChanged)
                {
                    return;
                }

                Mode = EditorMode.None;
                btnCategory_Save.Enabled = false;

                cbCategories.SelectedIndex = -1;
                txtCategoryName.ReadOnly   = (Mode == EditorMode.None);
                txtCategoryTitle.ReadOnly  = (Mode == EditorMode.None);

                LoadCategories();
            }
            break;

            default:
                break;
            }
        }
예제 #6
0
        private void btnCategory_Save_Click(object sender, EventArgs e)
        {
            long        parentid       = 0;
            ESPCategory parentCategory = cbCategories.SelectedItem as ESPCategory;

            if (null != parentCategory)
            {
                parentid = parentCategory.Id;
            }

            ESPCategory category = new ESPCategory(txtCategoryName.Text, txtCategoryTitle.Text, parentid);

            if (Mode == EditorMode.Edit)
            {
                category.Id = long.Parse(txtCategoryID.Text);
            }

            if (!ValidateCategory(category))
            {
                txtCategoryTitle.Focus();
                return;
            }

            if (!SaveCategory(category))
            {
                return;
            }
            MessageBox.Show("Saved!", "Category information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            Mode = EditorMode.None;
            btnCategory_Save.Enabled = false;

            txtCategoryName.ReadOnly  = (Mode == EditorMode.None);
            txtCategoryTitle.ReadOnly = (Mode == EditorMode.None);
            cbCategories.Enabled      = (Mode != EditorMode.None);

            LoadCategories();
            btnCategory_New.Focus();
        }
예제 #7
0
        private void lbCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            Mode = EditorMode.None;
            btnCategory_Save.Enabled = false;

            cbCategories.SelectedIndex = -1;
            txtCategoryName.Text       = string.Empty;
            txtCategoryTitle.Text      = string.Empty;
            txtCategoryID.Text         = "0";

            txtCategoryName.ReadOnly  = (Mode == EditorMode.None);
            txtCategoryTitle.ReadOnly = (Mode == EditorMode.None);
            cbCategories.Enabled      = (Mode != EditorMode.None);

            if (null == lbCategories.SelectedItem)
            {
                return;
            }

            ESPCategory selCat = lbCategories.SelectedItem as ESPCategory;

            if (selCat == null)
            {
                return;
            }

            ESPCategory parentCat = selCat.ParentObject;

            if (null != parentCat)
            {
                cbCategories.SelectedIndex = cbCategories.FindStringExact(parentCat.DisplayName);
            }

            txtCategoryID.Text    = selCat.Id.ToString();
            txtCategoryName.Text  = selCat.Name;
            txtCategoryTitle.Text = selCat.Title;
        }
예제 #8
0
        private bool ValidateCategory(ESPCategory category)
        {
            if ((category == null) || (category.Name == string.Empty))
            {
                MessageBox.Show("Invalid information.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (category.Id != 0)
            {
                if (category.Parent == category.Id)
                {
                    MessageBox.Show("Invalid parent category.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            if (Mode == EditorMode.AddNew)
            {
                var cates = DB.Categories.Where(e => e.Name == category.Name /* || e.Title == category.Title*/).FirstOrDefault();
                if (null != cates)
                {
                    MessageBox.Show("Already exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                cates = DB.Categories.Where(e => e.Parent == category.Parent && (e.Name == category.Name || e.Title == category.Title)).FirstOrDefault();
                if (null != cates)
                {
                    MessageBox.Show("Duplicate children.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(true);
        }