public void addSoftware() { if (tb_new_soft.Text.Trim() != "" && tb_new_model.Text.Trim() != "" && tb_new_version.Text.Trim() != "") { hailyEntities db = new hailyEntities(); software _software_add = new software(); _software_add.name = tb_new_soft.Text; _software_add.model = tb_new_model.Text; //默认授予新用户的软件模块使用 _software_add.version = tb_new_version.Text; db.software.Add(_software_add); db.SaveChanges(); MessageBox.Show("软件添加成功!"); FormMain formMain = new FormMain("softwareControlPage"); formMain.Show(); this.Close(); } else if (tb_new_soft.Text.Trim() == "") { MessageBox.Show("请输入软件名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_new_model.Text.Trim() == "" && tb_new_soft.Text.Trim() != "") { MessageBox.Show("请输入模块名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_new_soft.Text.Trim() != "" && tb_new_model.Text.Trim() != "" && tb_new_version.Text.Trim() == "") { MessageBox.Show("请输入版本号!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public FormUpdateSoftware(software soft) { InitializeComponent(); soft_main = soft; tb_up_software.Text = soft.name; tb_up_model.Text = soft.model; tb_up_version.Text = soft.version; }
void DataGridViewX1_software_CellContentClick(object sender, DataGridViewCellEventArgs e) { String _softwareName = dgv_soft.Rows[e.RowIndex].Cells["column_software"].Value.ToString(); software _software = new software(); _software.name = dgv_soft.Rows[e.RowIndex].Cells["column_software"].Value.ToString(); _software.model = dgv_soft.Rows[e.RowIndex].Cells["column_software_model"].Value.ToString(); _software.version = dgv_soft.Rows[e.RowIndex].Cells["column_software_version"].Value.ToString(); if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { if (dgv_soft.Columns[e.ColumnIndex].Name == "btnUpdate") //修改 { FormUpdateSoftware formUpdateSoftware = new FormUpdateSoftware(_software); formUpdateSoftware.Show(); this.Hide(); } if (dgv_soft.Columns[e.ColumnIndex].Name == "btnRemove") //移除 { //从数据库《软件信息表》中删除记录 var softwareInfoList = from u in db.software where u.name == _softwareName select u; software _softwareInfo = softwareInfoList.FirstOrDefault(); if (_softwareInfo != null) { DialogResult result = MessageBox.Show("确定移除软件模块“" + _softwareName + ":" + _softwareInfo.model + "," + _softwareInfo.version + "”?", "提示窗口", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { db.software.Remove(_softwareInfo); db.SaveChanges(); MessageBox.Show("已移除软件模块" + _softwareName + ":" + _softwareInfo.model + "," + _softwareInfo.version); dgv_soft.DataSource = null; dgv_soft.Columns.Clear(); UpdateSoftware(); SetHeaderSoftware(); } else if (result == DialogResult.No) { //不进行操作,关闭提示窗即可 } } else { MessageBox.Show("移除软件失败!"); } } } ////修改软件信息 //if (column == 3) //{ // FormUpdateSoftware formUpdateSoftware = new FormUpdateSoftware(list_soft_control[row]); // formUpdateSoftware.Show(); // this.Hide(); //} ////移除软件信息 //if (column == 4) //{ // //从数据库《软件信息表》中删除记录 // var softwareInfoList = from u in db.software // where u.name == _softwareName // select u; // software _softwareInfo = softwareInfoList.FirstOrDefault(); // if (_softwareInfo != null) // { // DialogResult result = MessageBox.Show("确定移除软件模块“" + _softwareName+":"+_softwareInfo.model +","+_softwareInfo.version+ "”?", "提示窗口", MessageBoxButtons.YesNo, MessageBoxIcon.Information); // if (result == DialogResult.Yes) // { // db.software.Remove(_softwareInfo); // db.SaveChanges(); // MessageBox.Show("已移除软件模块" + _softwareName); // dgv_soft.Rows.Clear(); // list_soft_control.Clear(); // //刷新 软件管理页面 // initSoftwarePage(); // } // else if (result == DialogResult.No) // { // //不进行操作,关闭提示窗即可 // } // } // else // { // MessageBox.Show("移除软件失败!"); // } //} }