C # Listview

Source: Internet
Author: User

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;

}

}

}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.