/// <summary> /// Creates a category. /// </summary> /// <param name="supermarket">The Supermarket that the category sort will be for.</param> /// <param name="catName">Name of the category.</param> /// <param name="sortValue">The sort value for category.</param> /// <returns>the category with a sort value for specified supermarket</returns> private static Category CreateCategory(Supermarket supermarket, string catName, int sortValue) { //creating the category Category cat = new Category() { Name = catName }; //creating the sort CategorySort catSort = new CategorySort() { Category = cat, Supermarket = supermarket, SortValue = sortValue, SupermarketId = supermarket.Id }; //assigning the sort cat.CategorySorts.Add(catSort); return cat; }
/// <summary> /// Gets an edit category form instance. /// </summary> /// <param name="category">The Category.</param> /// <param name="categories">The categories.</param> /// <returns></returns> internal static CategoryForm GetEditCategoryInstance(Category category, Supermarket superMarket) { return new CategoryForm(category, superMarket); }
/// <summary> /// Sets the category fileds to match argument <see cref="Category"/>. /// </summary> /// <param name="category">The category.</param> private void SetCategoryFileds(Category category) { if (category != null) { this.txbCategoryName.Text = category.Name; CategorySort sort = category.GetSortBySuperMarket(this._superMarket); this.nupSortValue.Value = sort.SortValue; } else { this.txbCategoryName.Text = String.Empty; this.nupSortValue.Value = 0; } }
/// <summary> /// Initializes a new instance of the <see cref="ProdcutForm"/> class. /// </summary> private CategoryForm(Category category, Supermarket superMarket) { InitializeComponent(); this._superMarket = superMarket; this.Category = category ?? new CategoryNullObject(); }
/// <summary> /// Handles the Click event of the btnOk control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnOk_Click(object sender, EventArgs e) { bool validated = this.ValidateCategoryFields(); if (validated) { //in case we are dealing with new this._category = this._category ?? new Category(); this._category.Name = this.txbCategoryName.Text; this._category.GetSortBySuperMarket(this._superMarket).SortValue = (int)this.nupSortValue.Value; this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show(this, "המידע שהוזן אינו תקין"); } }