//含有浓度的设置 public static void setValueToUI(DataGridView dgv, DataGridView dgv1, int well_class_index, string well_num) { //MessageBox.Show("调用了赋值函数:" + well_class_index.ToString() + " - " + well_num + " - " + well_conc); for (int i = 0; i < 8; i++) { for (int j = 0; j < 12; j++) { if (dgv.Rows[i].Cells[j].Selected == true) { //Info info = tpl[i, j]; Info info; if (well_class_index == 2) { info = new Info(i, j, "blank", well_num); } else { info = new Info(i, j, "smp", well_num); } dgv.Rows[i].Cells[j].Value = info.well_class + " " + info.well_num; //调整板子的颜色变化 DataReadWrite.changeODBackColor(info.well_class, dgv, info.i, info.j); //set板子 DataReadWrite.changeODBackColor(info.well_class, dgv1, info.i, info.j); //od板子 } } } }
//单击内置模板会载入内置模板 private void cmbTpl_SelectedIndexChanged(object sender, EventArgs e) { string tpl_name = this.cmbTpl.Text;//.SelectedIndex. >= 2) //如果是自定义模板,则啥也不管 if (this.cmbTpl.SelectedIndex == 0) { return; } //实例化内置模板类 InnerTpl form_inner_tpl = new InnerTpl(); //MessageBox.Show(tpl_name); //获取模板内容 Info[,] tpl = form_inner_tpl.getTplByName(tpl_name); //先初始化模板-重置所有方格 DgvCtrl.clearAllCells(this.dataGridView0, this.dataGridView1); //中间信息写到界面上 DataReadWrite.readIntoUI(tpl, this.dataGridView0, this.dataGridView1); }
//删除模板上的数据: private void btnClear_Click(object sender, EventArgs e) { if (this.dataGridView0.SelectedCells.Count == 0) { MessageBox.Show("请先在左侧模板中选择一个孔。", "系统提示"); return; } for (int i = 0; i < 8; i++) { for (int j = 0; j < 12; j++) { if (this.dataGridView0.Rows[i].Cells[j].Selected == true) { this.dataGridView0.Rows[i].Cells[j].Value = ""; //清除颜色 - 调整板子的颜色变化 DataReadWrite.changeODBackColor("", this.dataGridView0, i, j); //set板子 DataReadWrite.changeODBackColor("", this.dataGridView1, i, j); //od板子 } } } //一旦改动,就不是内置模板了,组合框中的值变为自定义 this.cmbTpl.SelectedItem = cmbTpl.Items[0]; }
//解析文件 private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); //openFileDialog1.InitialDirectory = "E:\\"; openFileDialog1.Filter = "mub File(*.mub)|*.mub|All files|*.*"; openFileDialog1.RestoreDirectory = true; openFileDialog1.FilterIndex = 2; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string fName = openFileDialog1.FileName; //调用类文件读取文件,并获取模板信息、OD信息 DataReadWrite dfw = new DataReadWrite(); plate_info = dfw.readFromFile(fName); //获取基本信息 Info[,] tpl = dfw.getTpl(); //模板信息 double[,] od = dfw.getOd(); //OD信息 //输出板子基本信息:标题、日期、单位、模型编号 //this.richTextBox1.Text = ""; /*foreach (string item in plate_info.Keys) * { * string info = this.plate_info[item]; * this.richTextBox1.Text += item + " [:] " + info + "\n"; * }*/ this.textName.Text = plate_info["Name"]; this.dateTimePicker1.Text = plate_info["LabDate"]; this.textLot.Text = plate_info["Lot"]; this.txtUnit.Text = plate_info["Unit"]; //todo 打开文件时曲线类型没处理 this.richTextBox1.Text = plate_info["Note"]; //先初始化模板-重置所有方格 + //清空od数据 DgvCtrl.clearAllCells(this.dataGridView0, this.dataGridView1, true); //从中间数据读取到表格中 DataReadWrite.readIntoUI(tpl, this.dataGridView0, this.dataGridView1); //模板文件 DataReadWrite.readIntoUI(od, this.dataGridView1); //od文件 //this.richTextBox1.Text += DataReadWrite.textDebug; } }
//把数据从UI读取到中间文件 private void readUItoArray() { //清空字典 plate_info = new Dictionary <string, string>(); //重新初始化中间数组 tpl = new Info[8, 12]; od = new double[8, 12]; //string[,] odStr = new string[8, 12];//使用字符数组更好? //读取文件到中间数组 //合法性检测 if (this.textName.Text.Trim() == null) { MessageBox.Show("请输入项目名称!", "系统提示"); return; } if (this.txtUnit.Text.Trim() == null) { MessageBox.Show("请输入单位名称!", "系统提示"); return; } //基本信息-》中间数据 plate_info["SaveTime"] = DateTime.Now.ToString();//保存文件时的时间 plate_info["Name"] = this.textName.Text.Trim(); plate_info["Lot"] = this.textLot.Text.Trim(); plate_info["LabDate"] = this.dateTimePicker1.Text.Trim(); plate_info["Unit"] = this.txtUnit.Text.Trim(); plate_info["Notice"] = "不要随意更改文件内容,否则再次读取时将发生错误。"; plate_info["Curve"] = this.getRadioIndex().ToString();//拟合的模型编号 //tpl-》中间数据 DataReadWrite drw = new DataReadWrite(); //从UI读取到中间数组 tpl = drw.readFromUI(this.dataGridView0, true); od = drw.readFromUI(this.dataGridView1); }
//删除整个模板的背景色 public static void clearAllCells(DataGridView dgv, DataGridView dgv1, bool isClearOD = false) { if (dgv.SelectedCells.Count == 0) { //MessageBox.Show("请先在左侧模板中选择一个孔。", "系统提示");//todo 首次不能提醒,how? return; } for (int i = 0; i < 8; i++) { for (int j = 0; j < 12; j++) { dgv.Rows[i].Cells[j].Value = ""; //清除颜色 - 调整板子的颜色变化 DataReadWrite.changeODBackColor("", dgv, i, j); //set板子 DataReadWrite.changeODBackColor("", dgv1, i, j); //od板子 if (isClearOD) { dgv1.Rows[i].Cells[j].Value = ""; } } } }
//把数据从UI读取到中间文件 private void readUItoArray() { //清空字典 plate_info = new Dictionary<string, string>(); //重新初始化中间数组 tpl = new Info[8, 12]; od = new double[8, 12]; //string[,] odStr = new string[8, 12];//使用字符数组更好? //读取文件到中间数组 //合法性检测 if (this.textName.Text.Trim() == null) { MessageBox.Show("请输入项目名称!", "系统提示"); return; } if (this.txtUnit.Text.Trim() == null) { MessageBox.Show("请输入单位名称!", "系统提示"); return; } //基本信息-》中间数据 plate_info["SaveTime"] = DateTime.Now.ToString();//保存文件时的时间 plate_info["Name"] = this.textName.Text.Trim(); plate_info["Lot"] = this.textLot.Text.Trim(); plate_info["LabDate"] = this.dateTimePicker1.Text.Trim(); plate_info["Unit"] = this.txtUnit.Text.Trim(); plate_info["Notice"] = "不要随意更改文件内容,否则再次读取时将发生错误。"; plate_info["Curve"] = this.getRadioIndex().ToString();//拟合的模型编号 //tpl-》中间数据 DataReadWrite drw = new DataReadWrite(); //从UI读取到中间数组 tpl = drw.readFromUI(this.dataGridView0, true); od = drw.readFromUI(this.dataGridView1); }
//解析文件 private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); //openFileDialog1.InitialDirectory = "E:\\"; openFileDialog1.Filter = "mub File(*.mub)|*.mub|All files|*.*"; openFileDialog1.RestoreDirectory = true; openFileDialog1.FilterIndex = 2; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string fName = openFileDialog1.FileName; //调用类文件读取文件,并获取模板信息、OD信息 DataReadWrite dfw = new DataReadWrite(); plate_info = dfw.readFromFile(fName);//获取基本信息 Info[,] tpl = dfw.getTpl();//模板信息 double[,] od = dfw.getOd();//OD信息 //输出板子基本信息:标题、日期、单位、模型编号 //this.richTextBox1.Text = ""; /*foreach (string item in plate_info.Keys) { string info = this.plate_info[item]; this.richTextBox1.Text += item + " [:] " + info + "\n"; }*/ this.textName.Text = plate_info["Name"]; this.dateTimePicker1.Text = plate_info["LabDate"]; this.textLot.Text = plate_info["Lot"]; this.txtUnit.Text = plate_info["Unit"]; //todo 打开文件时曲线类型没处理 this.richTextBox1.Text = plate_info["Note"]; //先初始化模板-重置所有方格 + //清空od数据 DgvCtrl.clearAllCells(this.dataGridView0, this.dataGridView1,true); //从中间数据读取到表格中 DataReadWrite.readIntoUI(tpl, this.dataGridView0,this.dataGridView1);//模板文件 DataReadWrite.readIntoUI(od, this.dataGridView1);//od文件 //this.richTextBox1.Text += DataReadWrite.textDebug; } }