public void Contains(commodity m) { if (myshop.Contains(m)) { Console.WriteLine("存在列表中"); } else { m.ToSting(); } }
public bool Contains(string m) { commodity stu = new commodity(); if (stu.Name.Contains(m)) { //Console.WriteLine("存在列表中"); return(true); } else { stu.ToSting(); return(false); } }
public void Add(commodity m) { myshop.Add(m); }
public void Remove(commodity m) { myshop.Remove(m); }
public bool IsContains(commodity m) { return(myshop.Contains(m)); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("输入格式有误"); } try { commodity[] a = {}; shoppingcart b = new shoppingcart(a); //b.Add(new commodity((string)textBox1.Text, double.Parse(textBox2.Text), int.Parse(textBox3.Text))); int index = this.dataGridView1.Rows.Add(); commodity stu = new commodity((string)textBox1.Text, double.Parse(textBox2.Text), int.Parse(textBox3.Text)); /* if (b.IsContains(new commodity((string)textBox1.Text, double.Parse(textBox2.Text), int.Parse(textBox3.Text)))) * { * index -= 1; * this.dataGridView1.Rows[index].Cells[0].Value = textBox1.Text; * this.dataGridView1.Rows[index].Cells[1].Value = textBox2.Text; * this.dataGridView1.Rows[index].Cells[2].Value += textBox3.Text; * } * else * { * this.dataGridView1.Rows[index].Cells[0].Value = textBox1.Text; * this.dataGridView1.Rows[index].Cells[1].Value = textBox2.Text; * this.dataGridView1.Rows[index].Cells[2].Value = textBox3.Text; * }*/ if (b.Contains(stu.Name)) { MessageBox.Show("该商品已存在,请在原商品中添加"); } else { b.Add(new commodity((string)textBox1.Text, double.Parse(textBox2.Text), int.Parse(textBox3.Text))); } for (int i = 0; i < b.GetLength(); i++) { dataGridView1.Rows[i].Cells[0].Value = b[i].Name; dataGridView1.Rows[i].Cells[1].Value = b[i].Price; dataGridView1.Rows[i].Cells[2].Value = b[i].Number; } } catch { MessageBox.Show("输入格式有误"); } /* DataGridView dgv = (DataGridView)sender; * for (int i = 0; i < dataGridView1.RowCount; i++) * { * if (dgv.Rows[i].Cells[0].Value.ToString().Trim() == dgv.Rows[i].Cells[1].Value.ToString().Trim()) * { * * } * }*/ textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; }