private void Form1_Load(object sender, EventArgs e) { //读取默认的数据 ReadAndWriteTXT rw = new ReadAndWriteTXT(path, System.IO.FileMode.OpenOrCreate); workList = rw.ReadTXT();//return a Object of workCollection UiDisplay uiDisplay = new UiDisplay(); this.panel1.Controls.Clear(); uiDisplay.SetLableOfALLWork(ref panel1, ref workList, new Point(5, 20)); for (int i = 0; i < tabControl1.TabCount; i++) { myLabel = new Label(); myLabel.Name = "myLabel1" + i.ToString(); myLabel.Text = "平均周转时间:"; tabControl1.TabPages[i].Controls.Add(myLabel); myLabel.Location = new Point(Width - 180, 0); myLabel.Anchor = AnchorStyles.Top & AnchorStyles.Bottom & AnchorStyles.Left; myTextBox = new TextBox(); myTextBox.Name = "myTextBox1" + i.ToString(); myTextBox.Text = "0"; myTextBox.ForeColor = Color.Red; tabControl1.TabPages[i].Controls.Add(myTextBox); myTextBox.Anchor = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left; myTextBox.Location = new Point(Width - 180, 28); myLabel = new Label(); myLabel.Text = "平均带权周转时间:"; myLabel.AutoSize = true; myLabel.Name = "myLabel2" + i.ToString(); tabControl1.TabPages[i].Controls.Add(myLabel); myLabel.Location = new Point(Width - 180, 66); myLabel.Anchor = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left; myTextBox = new TextBox(); myTextBox.Name = "myTextBox2" + i.ToString(); myTextBox.Text = "0"; myTextBox.ForeColor = Color.Red; tabControl1.TabPages[i].Controls.Add(myTextBox); myTextBox.Location = new Point(Width - 180, 94); myTextBox.Anchor = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left; } }
/// <summary> /// 保存数据到TXT中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { ReadAndWriteTXT rw = new ReadAndWriteTXT(path, System.IO.FileMode.Create); string temp = null; for (int i = 0; i < dataGridView1.RowCount - 1; i++) { for (int j = 1; j < dataGridView1.Rows[i].Cells.Count; j++) { if (j == 1) { temp += dataGridView1.Rows[i].Cells[j].Value; } else { temp += "-" + dataGridView1.Rows[i].Cells[j].Value; } } temp += System.Environment.NewLine; } rw.WriteTXT(temp); MessageBox.Show("数据保存成功"); }