C# 如何通过从组合框中选择产品来删除整个阵列?
这是我目前的水族馆库存更新销售代码。我没有为“删除”按钮编写任何代码,因为我不知道如何执行C# 如何通过从组合框中选择产品来删除整个阵列?,c#,visual-studio-2010,combobox,C#,Visual Studio 2010,Combobox,这是我目前的水族馆库存更新销售代码。我没有为“删除”按钮编写任何代码,因为我不知道如何执行 namespace Project_Aquarium { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] product = new string[10]; float[] retailprice = n
namespace Project_Aquarium
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] product = new string[10];
float[] retailprice = new float[10];
float[] costprice = new float[10];
int[] quantity = new int[10];
int[] totalSold = new int[10];
private void btnCheck_Click(object sender, EventArgs e)
{
for (int i = 0; i < product.Length; i++)
{
if (cbProduct.SelectedIndex.Equals(i))
{
lblRetail.Text = retailprice[i].ToString();
lblCost.Text = costprice[i].ToString();
lblInStock.Text = quantity[i].ToString();
lblSold.Text = totalSold[i].ToString();
}
}
}
private void btnCheckClear_Click(object sender, EventArgs e)
{
lblRetail.Text = "";
lblCost.Text = "";
lblInStock.Text = "";
lblSold.Text = "";
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (cbProduct.Items.Count < 10)
{
string name = txtProductAdd.Text;
float cost_price, retail_price;
int totalQty;
string searchProduct = txtProductAdd.Text;
if (float.TryParse(txtRetailAdd.Text, out retail_price) == false)
{
MessageBox.Show("Please Enter Retail Price.");
txtRetailAdd.Clear();
txtRetailAdd.Focus();
}
else if (float.TryParse(txtCostAdd.Text, out cost_price) == false)
{
MessageBox.Show("Please Enter Cost Price");
txtCostAdd.Clear();
txtCostAdd.Focus();
}
else if (int.TryParse(txtQuantityAdd.Text, out totalQty) == false)
{
MessageBox.Show("Please Enter Quantity of Product.");
txtQuantityAdd.Clear();
txtQuantityAdd.Focus();
}
else
for (int i = 0; i < product.Length; i++)
{
if (searchProduct == product[i])
{
MessageBox.Show("Store Already Has This Product.");
break;
}
else if (product[i] == null && searchProduct != product[i])
{
product[i] = name;
retailprice[i] = retail_price;
costprice[i] = cost_price;
quantity[i] = totalQty;
MessageBox.Show(txtProductAdd.Text
+ " was added. "
+ "Quantity is: "
+ txtQuantityAdd.Text);
break;
}
}
cbProduct.Items.Add(name);
cbProductDelete.Items.Add(name);
cbProductEdit.Items.Add(name);
cbProductSold.Items.Add(name);
}
else
{
MessageBox.Show("Storage space has exceeded.");
}
}
private void btnClear_Click(object sender, EventArgs e)
{
txtProductAdd.Text = "";
txtCostAdd.Clear();
txtRetailAdd.Clear();
txtQuantityAdd.Clear();
txtProductAdd.Focus();
}
private void btnSold_Click(object sender, EventArgs e)
{
string searchFish = cbProductSold.Text;
int foundIndex = -1;
int sold = 0;
if (cbProductSold.SelectedItem == null)
{
MessageBox.Show("Please Select A Product.");
}
else if (txtQuantitySEdit.Text == "")
{
MessageBox.Show("Please enter a value for quantity.");
txtQuantitySEdit.Focus();
}
else if (int.TryParse(txtQuantitySEdit.Text, out sold) == false)
{
MessageBox.Show("Please enter a numeric value for quantity.");
txtQuantitySEdit.Focus();
}
else
{
for (int i = 0; i < product.Length; i++)
{
if (searchFish == product[i])
{
foundIndex = i;
break;
}
}
}
if (quantity[foundIndex] < sold)
{
MessageBox.Show("There is not enough fish to be sold. Current product chosen quantity is: "
+ quantity[foundIndex]);
}
else if (foundIndex != -1)
{
totalSold[foundIndex] = totalSold[foundIndex] + sold;
quantity[foundIndex] = quantity[foundIndex] - sold;
lblNettPrice.Text = costprice[foundIndex].ToString("");
lblQuantityChosen.Text = sold.ToString("");
lblTotalPrice.Text = CalculateTotalPrice(sold, costprice[foundIndex]).ToString("C");
}
}
private float CalculateTotalPrice(int sold, float costprice)
{
float nettPrice;
nettPrice = sold * costprice;
return nettPrice;
}
private void btnSave_Click(object sender, EventArgs e)
{
string foundProduct = txtProductEdit.Text;
string editName = txtProductEdit.Text;
float editCost, editRetail;
int editQty;
int editSold;
editName = txtProductEdit.Text;
editRetail = float.Parse(txtRetailEdit.Text);
editCost = float.Parse(txtCostEdit.Text);
editQty = int.Parse(txtQuantityEdit.Text);
editSold = int.Parse(txtSoldEdit.Text);
for (int i = 0; i < product.Length; i++)
{
product[i] = editName;
retailprice[i] = editRetail;
costprice[i] = editCost;
quantity[i] = editQty;
totalSold[i] = editSold;
MessageBox.Show(product[i]
+ " Has Been Updated.");
break;
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
}
private void btnSelectEditProduct_Click(object sender, EventArgs e)
{
for (int i = 0; i < product.Length; i++)
{
if (cbProductEdit.SelectedIndex.Equals(i))
{
txtProductEdit.Text = product[i].ToString();
txtRetailEdit.Text = retailprice[i].ToString();
txtCostEdit.Text = costprice[i].ToString();
txtQuantityEdit.Text = quantity[i].ToString();
txtSoldEdit.Text = totalSold[i].ToString();
}
}
}
}
}
名称空间项目\u水族馆
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
字符串[]产品=新字符串[10];
浮动[]零售价=新浮动[10];
浮动[]成本价格=新浮动[10];
整数[]数量=新整数[10];
整数[]总销售额=新整数[10];
私有void b检查\u单击(对象发送者,事件参数e)
{
对于(int i=0;ipublic class Product
{
public string ProductName{ get; set; }
public float RetailPrice{ get; set; }
public float CostPrice{ get; set; }
public int Quantity{ get; set; }
public int TotalSold{ get; set; }
}
private List<Products> myProducts = new List<Products>();
Product product = new Product{ ProductName = "Something", RetailPrice = 10.26f,...};
myProducts.Add(product);
foreach(var product in myProducts)
{
if(product.ProductName == "ProductToRemove")
{
myProducts.Remove(product);
break;//Must else you'll get an exception
}
}