示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProdcutForm"/> class.
        /// </summary>
        private ProductForm(Product product, IEnumerable<Category> categories, Supermarket superMarket)
        {
            InitializeComponent();

            this._superMarket = superMarket;
            this.Categories = categories;
            this.Product = product;
        }
示例#2
0
 /// <summary>
 /// Sets the product fileds to match argument <see cref="Product"/>.
 /// </summary>
 /// <param name="product">The product.</param>
 private void SetProductFileds(Product product)
 {
     if (product != null)
     {
         this.txbProductName.Text = product.ProductName;
         this.nupPrice.Value = product.Price ?? 0 ;
         this.cmbCategory.SelectedItem = product.Category;
     }
     else
     {
         this.txbProductName.Text = String.Empty;
         this.nupPrice.Value = 0;
     }
 }
示例#3
0
 /// <summary>
 /// Gets an edit product form instance.
 /// </summary>
 /// <param name="product">The product.</param>
 /// <param name="categories">The categories.</param>
 /// <returns></returns>
 internal static ProductForm GetEditProductInstance(Product product, IEnumerable<Category> categories,  Supermarket superMarket)
 {
     return new ProductForm(product, categories, superMarket);
 }
示例#4
0
        /// <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.ValidateProductFields();
            if (validated)
            {
                //in case we are dealing with new
                this._product = this._product ?? new Product();
                this._product.ProductName = this.txbProductName.Text;
                this._product.Price = this.nupPrice.Value;
                this._product.Category = this.cmbCategory.SelectedItem as Category;
                this._product.CategoryID = this._product.Category.Id;

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MessageBox.Show(this, "המידע שהוזן אינו תקין");
            }
        }
示例#5
0
 /// <summary>
 /// Deletes the product from database.
 /// </summary>
 /// <param name="product">The product.</param>
 /// <param name="errorMsg">The error MSG.</param>
 /// <returns>true upon succes, false otherwise</returns>
 public bool DeleteProduct(Product product, out string errorMsg)
 {
     bool success = true;
     bool isExists = this._db.Products.Where(p => p.guid == product.guid).ToList().Count >0;
     if (isExists)
     {
         this._db.Products.Remove(product);
         success = this.SaveChanges(out errorMsg);
     }
     else
     {
         success = false;
         errorMsg = "המוצר לא נמצא במסד הנתונים.";
     }
     return success;
 }
示例#6
0
 /// <summary>
 /// Saves the product to DB.
 /// </summary>
 /// <param name="newProduct">The new product.</param>
 /// <param name="errorMsg">The error MSG.</param>
 /// <returns>true upon succes, false otherwise</returns>
 public bool SaveProduct(Product newProduct, out string errorMsg)
 {
     this._db.Products.Add(newProduct);
     bool success = this.SaveChanges(out errorMsg);
     if (!success)
     {
         this._db.Products.Remove(newProduct);
     }
     return success;
 }
 /// <summary>
 /// Saves the product to DB.
 /// </summary>
 /// <param name="newProduct">The new product.</param>
 /// <param name="errorMsg">The error MSG.</param>
 /// <returns>true upon succes, false otherwise</returns>
 public bool SaveProduct(Product newProduct, out string errorMsg)
 {
     return this._db.SaveProduct(newProduct, out errorMsg);
 }
 /// <summary>
 /// Deletes the product from database.
 /// </summary>
 /// <param name="product">The product.</param>
 /// <param name="errorMsg">The error MSG.</param>
 /// <returns>true upon succes, false otherwise</returns>
 public bool DeleteProduct(Product product, out string errorMsg)
 {
     return this._db.DeleteProduct(product, out errorMsg);
 }
 public EditCommercials(Product prodcut)
 {
     InitializeComponent();
     this._prodcut = prodcut;
     this.BindGridView();
 }