protected void BtnDone_Click(object sender, EventArgs e) { lblDoneMsg.Text = ""; bool AllValid = true; foreach (GridViewRow row in GridViewSelectedProducts.Rows) { Product product = new Product(); product.P_name = row.Cells[1].Text; product.Purchase_Price = Convert.ToDouble(row.Cells[2].Text); product.Amount = Convert.ToDecimal(((Label)row.FindControl("lblAmount")).Text) * Convert.ToInt32(txtboxAmount.Text); if (!product.IsValidAmount()) { lblDoneMsg.Text += "لا تتوفر كل الكميه المطلوبة من المنتج : " + product.P_name + "<br />"; lblDoneMsg.ForeColor = System.Drawing.Color.Red; AllValid = false; } } #region add new collected product if (AllValid) // add new product with provided info and decrease the used products { if (GridViewSelectedProducts.Rows.Count == 0) { lblDoneMsg.Text = "لا توجد منتجات !"; lblDoneMsg.ForeColor = System.Drawing.Color.Red; } else { lblDoneMsg.Text = ""; GridViewSelectedProducts.EditIndex = -1; BindSelectedProducts(); string m = ""; Product product = new Product(); product.P_name = txtboxP_name.Text; product.Purchase_Price = Convert.ToDouble(txtboxPurchasePrice.Text); product.Special_Price = Convert.ToDouble(txtboxSpecialSellPrice.Text); product.Regulare_Price = Convert.ToDouble(txtboxRegularSellPrice.Text); product.Amount = Convert.ToDecimal(txtboxAmount.Text); product.Description = TxtDesc.Text; if (!product.Add_Product(out m, "Unknown", new DateTime())) { lblDoneMsg.Text = m; lblDoneMsg.ForeColor = System.Drawing.Color.Red; } else { foreach (GridViewRow row in GridViewSelectedProducts.Rows) { product.P_name = row.Cells[1].Text; product.Purchase_Price = Convert.ToDouble(row.Cells[2].Text); product.Amount = Convert.ToDecimal(((Label)row.FindControl("lblAmount")).Text) * Convert.ToInt32(txtboxAmount.Text); if (!product.AddContent(out m, txtboxP_name.Text, Convert.ToDouble(txtboxPurchasePrice.Text))) { lblDoneMsg.Text += m + "هذا الخطأ عند المنتج : " + product.P_name + "<br />"; lblDoneMsg.ForeColor = System.Drawing.Color.Red; AllValid = false; } } if (AllValid) { lblDoneMsg.Text = "تم بنجاح"; lblDoneMsg.ForeColor = System.Drawing.Color.Green; } } } } #endregion }