private void button4_Click(object sender, EventArgs e) { button4.Enabled = false; button6.Enabled = true; Tovar pr1 = new Tovar(textBox1.Text, textBox3.Text, Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox4.Text)); prod.Add(pr1); curent.Add(pr1); textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; comboBox1.Text = ""; /*Покраска*/ //tab1 int f = 0; int i; for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { f = 0; i = 0; do { if (prod[i].code == dataGridView1.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) { dataGridView1.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; f = 1; } } i++; if (f == 0) dataGridView1.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } while (i < 7); } //tab2 for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { i = 0; do { if (prod[i].code == dataGridView2.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) dataGridView2.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; else dataGridView2.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } i++; } while (i < 7); } //tab3 for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { i = 0; do { if (prod[i].code == dataGridView3.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) dataGridView3.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; else dataGridView3.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } i++; } while (i < 7); } //tab4 for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { i = 0; do { if (prod[i].code == dataGridView4.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) dataGridView4.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; else dataGridView3.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } i++; } while (i < 7); } }
private void Form1_Load(object sender, EventArgs e) { label6.Visible = false; label7.Visible = false; label8.Visible = false; label9.Visible = false; label10.Visible = false; label11.Visible = false; textBox1.Visible = false; textBox3.Visible = false; textBox4.Visible = false; button4.Visible = false; button5.Visible = false; button6.Visible = false; textBox2.Visible = false; comboBox1.Visible = false; Tovar pr1 = new Tovar("Соль","A2-2",20,40); prod.Add(pr1); Tovar pr2 = new Tovar("Сахар", "A2-4", 40, 50); prod.Add(pr2); Tovar pr7 = new Tovar("Гречка", "B4-2", 40, 48); prod.Add(pr7); Tovar pr6 = new Tovar("Сыр", "C4-4", 40, 145); prod.Add(pr6); Tovar pr3 = new Tovar("Семга", "D2-1", 50, 200); prod.Add(pr3); Tovar pr4 = new Tovar("Горбуша", "D2-1", 20, 300); prod.Add(pr4); Tovar pr5 = new Tovar("Горбуша", "D3-2", 20, 300); prod.Add(pr5); int i = 0; //tab1 for (int x = 0; x < 6; x++) { DataGridViewButtonColumn Column = new DataGridViewButtonColumn(); Column.FlatStyle = FlatStyle.Flat; dataGridView1.Columns.Add(Column); dataGridView1.Columns[x].Width = 85; } for (int x = 0; x < 4; x++) { dataGridView1.Rows.Add("A1-" + (x + 1).ToString(), "A2-" + (x + 1).ToString(), "A3-" + (x + 1).ToString(), "A4-" + (x + 1).ToString(), "A5-" + (x + 1).ToString(), "A6-" + (x + 1).ToString()); } //tab2 for (int x = 0; x < 6; x++) { DataGridViewButtonColumn Column = new DataGridViewButtonColumn(); Column.FlatStyle = FlatStyle.Flat; dataGridView2.Columns.Add(Column); dataGridView2.Columns[x].Width = 85; } for (int x = 0; x < 4; x++) { dataGridView2.Rows.Add("B1-" + (x + 1).ToString(), "B2-" + (x + 1).ToString(), "B3-" + (x + 1).ToString(), "B4-" + (x + 1).ToString(), "B5-" + (x + 1).ToString(), "B6-" + (x + 1).ToString()); } //tab3 for (int x = 0; x < 6; x++) { DataGridViewButtonColumn Column = new DataGridViewButtonColumn(); Column.FlatStyle = FlatStyle.Flat; dataGridView3.Columns.Add(Column); dataGridView3.Columns[x].Width = 85; } for (int x = 0; x < 4; x++) { dataGridView3.Rows.Add("C1-" + (x + 1).ToString(), "C2-" + (x + 1).ToString(), "C3-" + (x + 1).ToString(), "C4-" + (x + 1).ToString(), "C5-" + (x + 1).ToString(), "C6-" + (x + 1).ToString()); } //tab4 for (int x = 0; x < 6; x++) { DataGridViewButtonColumn Column = new DataGridViewButtonColumn(); Column.FlatStyle = FlatStyle.Flat; dataGridView4.Columns.Add(Column); dataGridView4.Columns[x].Width = 85; //dataGridView1.Rows[x].Cells[x].Style.BackColor = Color.Red; } for (int x = 0; x < 4; x++) { dataGridView4.Rows.Add("D1-" + (x + 1).ToString(), "D2-" + (x + 1).ToString(), "D3-" + (x + 1).ToString(), "D4-" + (x + 1).ToString(), "D5-" + (x + 1).ToString(), "D6-" + (x + 1).ToString()); } /*Покраска*/ //tab1 int f=0; for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { f = 0; i = 0; do { if (prod[i].code == dataGridView1.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) { dataGridView1.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; f=1; } } i++; if (f == 0) dataGridView1.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } while (i < 7); } //tab2 for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { i = 0; do { if (prod[i].code == dataGridView2.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) dataGridView2.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; else dataGridView2.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } i++; } while (i < 7); } //tab3 for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { i = 0; do { if (prod[i].code == dataGridView3.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) dataGridView3.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; else dataGridView3.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } i++; } while (i < 7); } //tab4 for (int n = 1; n <= 4; n++) for (int m = 1; m <= 6; m++) { i = 0; do { if (prod[i].code == dataGridView4.Rows[n - 1].Cells[m - 1].Value.ToString()) { if (prod[i].kol != 0) dataGridView4.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.Red; else dataGridView3.Rows[n - 1].Cells[m - 1].Style.BackColor = Color.White; } i++; } while (i < 7); } }