Private void simplebutton#click (object sender, EventArgs e)
{// Declaration
String goods_id = comboBox1.Text;
String sales_price = textBox1.Text;
String amount = textBox2.Text;
String fact_money = textBox1.Text;
// Judge
If (goods_id = "")
{
MessageBox. Show ("the product name cannot be blank .");
Return;
}
If (sales_price = "")
{
MessageBox. Show ("the unit price cannot be blank .");
Return;
} If (amount = "")
{
MessageBox. Show ("Quantity cannot be blank .");
Return;
}
// Declare an array
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])
{// Check the Array
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 ++)
{// Add the same number of Goods_name values.
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;
}
}
}