private void button_Update_Click(object sender, EventArgs e) { if (dataGridView_Switch.SelectedRows.Count > 0) { int vLuHao = (int)numericUpDown_LuHao.Value; DataRow[] vSelectRows = SwitchTable.Select(string.Format("LuHao={0}", vLuHao)); if (vSelectRows.Length == 0) { if (textBox_MingCheng.Text != "") { int vId = (int)dataGridView_Switch.SelectedRows[0].Cells["Column_ID"].Value; DataRow vRow = SwitchTable.Rows.Find(vId); vLuHao = (int)numericUpDown_LuHao.Value; vRow["LuHao"] = vLuHao; vRow["MinCheng"] = textBox_MingCheng.Text; vRow["LeiXing"] = comboBox_LeiXing.Text; WatchHouseConfig.saveWatchHouseData(); //SwitchTable.AcceptChanges(); } else { MessageBox.Show("请输入名称", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("存在相同的路号", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("没有选择的开关", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_Add_Click(object sender, EventArgs e) { int vLuHao = (int)numericUpDown_LuHao.Value; DataRow[] vSelectRows = SwitchTable.Select(string.Format("LuHao={0}", vLuHao)); if (vSelectRows.Length == 0) { if (textBox_MingCheng.Text != "") { DataRow vNewRow = SwitchTable.NewRow(); vNewRow["DianYuanID"] = DianYuanID; vNewRow["LuHao"] = vLuHao; vNewRow["MinCheng"] = textBox_MingCheng.Text; vNewRow["LeiXing"] = comboBox_LeiXing.Text; SwitchTable.Rows.Add(vNewRow); //SwitchTable.AcceptChanges(); } else { MessageBox.Show("请输入名称", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("存在相同的路号", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }