private void UpdateControlAfterTest(bool testResult) { if (testResult == true) { TestData dt = new TestData(); dt.ReadXml("TestData", FilePath.TestDataXml); dt.Columns.Remove("Family"); dt.Columns.Remove("Current"); dt.Columns.Remove("Temp"); dt.Columns.Remove("Time"); this.dataGridViewTestData.DataSource = dt; this.dataGridViewTestData.Columns["Result"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; this.groupBoxStatus.BackColor = Color.Lime; } else { this.groupBoxStatus.BackColor = Color.LightCoral; } this.btnInitial.Enabled = true; this.btnStart.Enabled = true; this.btnTraceView.Enabled = false; this.groupBoxCalibratioon.Enabled = true; this.groupBoxConfig.Enabled = true; this.labelStatus.Text = "测试完成"; }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { try { TestData dt = new TestData(); dt.ReadXml("TestData", FilePath.TestDataXml); if (dt.Rows.Count == 0) { MessageBox.Show("无测试记录!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string folderPath = Application.StartupPath + @"\TestData\"; FolderBrowserDialog dilog = new FolderBrowserDialog(); dilog.Description = "请选择文件夹"; var result = dilog.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { folderPath = dilog.SelectedPath; } string fileExcelPath = folderPath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; FilePath.SaveTableToExcel(dt, fileExcelPath); } catch { MessageBox.Show("Save test data failed."); } }
private void MainForm_Load(object sender, EventArgs e) { try { //load dataGridViewTestData this.dataGridViewTestData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; this.dataGridViewTestData.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridViewTestData.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridViewTestData.AllowUserToAddRows = false; TestData dt = new TestData(); FilePath.TestDataXml = Application.StartupPath + @"\TestData.xml"; dt.ReadXml("TestData", FilePath.TestDataXml); dt.Columns.Remove("Family"); dt.Columns.Remove("Current"); dt.Columns.Remove("Temp"); dt.Columns.Remove("Time"); this.dataGridViewTestData.DataSource = dt; this.dataGridViewTestData.Columns["Result"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; this.btnInitial.Enabled = false; this.btnStart.Enabled = false; //get Production Family string[] member = user.GetProductionFamily(myXml, ref myDataIO, ref dataTable_Family); this.comboBoxFamily.Items.Clear(); if (member == null) { var result = MessageBox.Show("不能连接服务器,是否继续?", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (result == DialogResult.No) { Application.Exit(); } return; } foreach (string one in member) { this.comboBoxFamily.Items.Add(one); } //check IP address address_IP = user.GetIP(); if (address_IP == "") { this.comboBoxFamily.Text = ""; this.comboBoxFamily.Enabled = false; } } catch { var result = MessageBox.Show("连接服务器或导入Config文件出错,请确认,并重启软件。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (result == DialogResult.Yes) { Application.Exit(); } } }
private bool SaveToXml() { try { //save the new test data to xml file. TestData data = new TestData(); data.ReadXml("TestData", FilePath.TestDataXml); int delta = testData.Rows.Count - data.Rows.Count; if (delta == 0) { testData.WriteXml("TestData", FilePath.TestDataXml); return(true); } for (int row = 0; row < data.Rows.Count; row++) { for (int column = 1; column < data.Columns.Count; column++) { if (delta > 0) { data.Rows[row][column] = testData.Rows[row + delta][column]; } else { if (row < -1 * delta) { data.Rows[row][column] = data.Rows[row + testData.Rows.Count][column]; } else { data.Rows[row][column] = testData.Rows[row + delta][column]; } } } } data.WriteXml("TestData", FilePath.TestDataXml); return(true); } catch { return(false); } }