private void simpleButton1_Click(object sender, EventArgs e)
{// 聲明
string goods_id = comboBox1.Text;
string sales_price = textBox1.Text;
string amount = textBox2.Text;
string fact_money = textBox1.Text;
//判斷
if (goods_id == "")
{
MessageBox.Show("商品名稱不能為空.");
return;
}
if (sales_price == "")
{
MessageBox.Show("單價不能為空.");
return;
} if (amount == "")
{
MessageBox.Show("數量不能為空.");
return;
}
//聲明數組
string[] strArriy = new string[4];
strArriy[0] = goods_id;
strArriy[1] = sales_price;
strArriy[2] = amount;
strArriy[3] = sales_price;
if (CheckInlistView(strArriy[0],strArriy[2]))
{//檢查數組
ListViewItem li = new ListViewItem(strArriy[0]);
li.SubItems.Add(strArriy[1]);
li.SubItems.Add(strArriy[2]);
li.SubItems.Add(strArriy[3]);
listView1.Items.Add(li);
return;
}
for (int i = 0; i <listView1.Items.Count; i++)
{ //Goods_name 相同的數量相加。
if (listView1.Items[i].Text == comboBox1.Text)
{
int preNum = Convert.ToInt32(listView1.Items[i].SubItems[2].Text);
int num = Convert.ToInt32(this.textBox2.Text);
string Money = Convert.ToDouble(listView1.Items[i].SubItems[3].Text).ToString();
listView1.Items[i].SubItems[2].Text = (preNum + num).ToString();
listView1.Items[i].SubItems[3].Text = (preNum + num + Money).ToString();
string.Format("{0}", i + 1);
}
}
}
private bool CheckInlistView(string goods, string amount)
{
bool fal = true;
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].SubItems[0].Text == goods && listView1.Items[i].SubItems[2].Text == amount)
{
fal = false;
break;
}
if (listView1.Items[i].SubItems[0].Text == goods)
{
fal = false;
break;
}
}
return fal;
}
private void simpleButton2_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection(str);
myConn.Open();
SqlDataAdapter myd =new SqlDataAdapter("DELETE FORM T_Base_GoodsInfo WHERE '"+Ro+"'",myConn);
dataeew();
}
int Ro = -1;
private void dataeew()
{
Ro = listView1.Columns.Count;
}
}
}