Beispiel #1
0
 private void btnAddProduct_Click(object sender, EventArgs e)
 {
     if (IsDigitsOnly(txtAddProductCost.Text) && IsDigitsOnly(txtAddProductSalePrice.Text) && txtAddProductName.Text != "" && txtAddProductTradeMark.Text != "" && txtAddProductModel.Text != "" && txtAddProductDescription.Text != "" && dpAddProductCategory.selectedValue != "")
     {
         Product newProduct = new Product();
         newProduct.CategoryID         = cda.GetList().Where(c => c.Name == dpAddProductCategory.selectedValue).FirstOrDefault().CategoryID;
         newProduct.Name               = txtAddProductName.Text;
         newProduct.TradeMark          = txtAddProductTradeMark.Text;
         newProduct.Model              = txtAddProductModel.Text;
         newProduct.Cost               = Convert.ToDecimal(txtAddProductCost.Text);
         newProduct.SalePrice          = Convert.ToDecimal(txtAddProductSalePrice.Text);
         newProduct.ProductDescription = txtAddProductDescription.Text;
         if (txtAddProductAvatar.Text == "")
         {
             newProduct.PicturePath = "..\\..\\Assets\\ProductAvatars\\star" + ".png";
             if (pda.AddItem(newProduct) == false)
             {
                 lblAddProductAlertFail.Visible = true;
                 lblAddProductAlertFail.BringToFront();
             }
             else
             {
                 lblAddProductAlertSuccess.Visible = true;
                 lblAddProductAlertSuccess.BringToFront();
             }
         }
         else
         {
             newProduct.PicturePath = "..\\..\\Assets\\ProductAvatars\\" + txtAddProductAvatar.Text;
             if (pda.AddItem(newProduct) == false)
             {
                 lblAddProductAlertFail.Visible = true;
                 lblAddProductAlertFail.BringToFront();
             }
             else
             {
                 lblAddProductAlertSuccess.Visible = true;
                 lblAddProductAlertSuccess.BringToFront();
             }
         }
     }
     else
     {
         lblAddProductAlertFail.Visible = true;
         lblAddProductAlertFail.BringToFront();
     }
 }