//添加 private void button1_Click(object sender, EventArgs e) { string PhysicalPath = this.textBox1.Text; string StorageName = this.textBox2.Text; int numsum; if (tb_num.Text == string.Empty || tb_num == null) { numsum = 0; } else { numsum = Convert.ToInt32(tb_num.Text); } if (PhysicalPath == string.Empty || PhysicalPath == "") { MessageBox.Show("物理路径不能为空!"); return; } if (this.button1.Text == "添加") { string sqlstr = string.Format("insert into Storage(PhysicalPath,DeviceID,Num)" + "values('{0}','{1}',{2})", PhysicalPath, StorageName, numsum); int num = DBHLper.GetExecuteNonQuery(sqlstr); if (num > 0) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("不能添加相同的数据!"); } } //修改 else { string sqlstr = string.Format("update Storage set PhysicalPath='{0}' " + ",DeviceID='{1}',num={2} where S_ID={3}", PhysicalPath, StorageName, numsum, dgid); int num = DBHLper.GetExecuteNonQuery(sqlstr); if (num > 0) { MessageBox.Show("修改成功!"); this.button1.Text = "添加"; } } textBox1.Text = string.Empty; textBox2.Text = string.Empty; tb_num.Text = string.Empty; freshen(); }
private void ToolStripMenuItem_Click(object sender, EventArgs e) { //dgid = Convert.ToInt32(dataGridView1.Rows[Countid].Cells["S_ID"].Value.ToString()); foreach (DataGridViewRow item in dataGridView1.SelectedRows) { ids += dataGridView1.Rows[item.Index].Cells["S_ID"].Value.ToString() + ","; } string[] idlist = ids.Split(','); //if (dgid <= 0) //{ // MessageBox.Show("未选中任何行!"); // return; //} int num = 0; if (MessageBox.Show("是否删除?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { foreach (var item in idlist) { string sqlstr = string.Format("Delete From Storage where S_ID ={0}", item); num = DBHLper.GetExecuteNonQuery(sqlstr); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } MessageBox.Show("删除成功!"); freshen(); } else { return; //MessageBox.Show("n"); } }