private void btnAdd_Click(object sender, EventArgs e) { RepoSpareTool[] repoSpareTools = new RepoSpareTool[] { }; List <RepoSpareTool> ktls = repoSpareTools.ToList(); if (textBox1.Text != "" && numericUpDown1.Value != 0) { ktls.Add(this.getOneInput(textBox1, numericUpDown1)); } if (textBox2.Text != "" && numericUpDown2.Value != 0) { ktls.Add(this.getOneInput(textBox2, numericUpDown2)); } if (textBox3.Text != "" && numericUpDown3.Value != 0) { ktls.Add(this.getOneInput(textBox3, numericUpDown3)); } if (textBox4.Text != "" && numericUpDown4.Value != 0) { ktls.Add(this.getOneInput(textBox4, numericUpDown4)); } if (textBox5.Text != "" && numericUpDown5.Value != 0) { ktls.Add(this.getOneInput(textBox5, numericUpDown5)); } repoSpareTools = ktls.ToArray(); insertValue2Db(repoSpareTools); }
private RepoSpareTool[] GetRepoSpareToolFromGrid() { RepoSpareTool[] repoSpareTool = new RepoSpareTool[] { }; List <RepoSpareTool> ktls = repoSpareTool.ToList(); //遍历 DataGridView 所有行 int row = dataGridView1.Rows.Count; //得到总行数 int cell = dataGridView1.Rows[0].Cells.Count; //得到总列数 for (int i = 0; i < row; i++) //得到总行数并在之内循环 { if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].EditedFormattedValue)) { ktls.Add(new RepoSpareTool { SpareToolModel = dataGridView1.Rows[i].Cells[1].Value.ToString(), Num = int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()), AddTime = dataGridView1.Rows[i].Cells[3].Value.ToString(), }); } } return(ktls.ToArray()); }