Exemplo n.º 1
0
 /// <summary>
 /// 点击单元格的内容时发生
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == dataGridView1.Columns["cDel"].Index)
     {
         if (MessageBox.Show(this, "确定要删除吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             object v = dataGridView1.Rows[e.RowIndex].Cells["cName"].Value;
             if (v != null)
             {
                 Norm no = new Norm();
                 if (no.IsRelation(v.ToString()))
                 {
                     MessageBox.Show("该记录已被使用,禁止删除!");
                     return;
                 }
                 bool re = no.Delete(v.ToString());
                 if (re)
                 {
                     MessageBox.Show("删除成功!");
                     BindDGV();
                 }
                 else
                 {
                     MessageBox.Show("删除失败!");
                 }
             }
         }
     }
     else if (e.ColumnIndex == dataGridView1.Columns["cModity"].Index)
     {
         object v = dataGridView1.Rows[e.RowIndex].Cells["cID"].Value;
         if (ValidateService.IsNumber(v))
         {
             Norm no = new Norm();
             no.GetModel((int)v);
             frmGoodsNormUpdate f = new frmGoodsNormUpdate(no);
             f.ShowDialog();
             if (f._isTrue)
             {
                 BindDGV();
             }
         }
     }
 }
Exemplo n.º 2
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == dataGridView1.Columns["cDel"].Index)
     {
         if (MessageBox.Show(this, "确定要删除吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             object v = dataGridView1.Rows[e.RowIndex].Cells["cName"].Value;
             if (v!=null)
             {
                 Norm no = new Norm();
                 if (no.IsRelation(v.ToString()))
                 {
                     MessageBox.Show("该记录已被使用,禁止删除!");
                     return;
                 }
                 bool re = no.Delete(v.ToString());
                 if (re)
                 {
                     MessageBox.Show("删除成功!");
                     BindDGV();
                 }
                 else
                 {
                     MessageBox.Show("删除失败!");
                 }
             }
         }
     }
     else if (e.ColumnIndex == dataGridView1.Columns["cModity"].Index)
     {
         object v = dataGridView1.Rows[e.RowIndex].Cells["cID"].Value;
         if (ValidateService.IsNumber(v))
         {
             Norm no = new Norm();
             no.GetModel((int)v);
             frmGoodsNormUpdate f = new frmGoodsNormUpdate(no);
             f.ShowDialog();
             if (f._isTrue)
             {
                 BindDGV();
             }
         }
     }
 }