protected void btnSubmit_Click(object sender, EventArgs e) { InventoryItem updateItem = new InventoryItem(); if (hidInventoryId.Value != null && hidInventoryId.Value != "") { updateItem.setInventoryId(Convert.ToInt32(hidInventoryId.Value)); setUpdateItem(updateItem); if (ImageFileUpload.HasFile) { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); updateItem.setImageUrl(ImageFileUpload.FileName); } } else { updateItem.setImageUrl(hidImagePath.Value); } sendItemToDb(updateItem); } else { setUpdateItem(updateItem); if (ImageFileUpload.HasFile) { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); updateItem.setImageUrl(ImageFileUpload.FileName); } else { lblMsg.Text = "There is a problem with your image. It must be .jpg or .png. Please try again."; } sendNewItemToDb(updateItem); } else { lblMsg.Text = "An image file is required, please try again."; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { Boolean success = false; if (IsValid) { InventoryItem inventoryItem = new InventoryItem(); inventoryItem.setProductName(txtProductName.Text); inventoryItem.setProductCount(Convert.ToInt32(txtProductCount.Text)); inventoryItem.setItemsOnHold(Convert.ToInt32(txtItemsOnHold.Text)); inventoryItem.setUnitPrice(Convert.ToDouble(txtUnitPrice.Text)); inventoryItem.setSalePrice(Convert.ToDouble(txtSalePrice.Text)); inventoryItem.setShortDescription(txtShortDescription.Text); inventoryItem.setLongDescription(txtLongDescription.Text); if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); inventoryItem.setImageUrl(ImageFileUpload.FileName); success = InventoryManager.insertNewItem(inventoryItem); } else { lblMsg.Text = "There is a problem with your image. It must be .jpg or .png. Please try again."; } if (success) { InventoryPurchaseInfo purchaseInfo = new InventoryPurchaseInfo(); InventoryItem item = InventoryManager.getItemByName(txtProductName.Text); purchaseInfo.inventoryItemId = item.getInventoryId(); purchaseInfo.manufacturerId = Convert.ToInt32(ddlManufacturer.SelectedValue); purchaseInfo.minInventory = Convert.ToInt32(txtMinumInventory.Text); success = PurchaseManager.addNewInventoryPurchaseInfo(purchaseInfo); } if (success) { lblMsg.Text = "Item successfuly added."; } } }