Example #1
0
 private void btnMaterialDelete_Click(object sender, EventArgs e)
 {
     if (this.MaterialSelect)
     {
         DialogResult dr = MessageBox.Show(this, "Are you sure, You want to Delete selected Record?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             Material_DL objMaterialDL = new Material_DL(ConnectionStringClass.GetConnection());
             try
             {
                 int x = objMaterialDL.Delete(objSelectedMaterial.MaterialCode);
                 MaterialClear();
                 if (x > 0)
                 {
                     MessageBox.Show(this, "Succesfully Deleted From Database", "Succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     LoadMaterials(Category);
                 }
             }
             catch (SqlException sqlex)
             {
                 if (sqlex.Number == 547)
                 {
                     MessageBox.Show(this, "Selected Material has references to another record or more. System will not allow to delete the record\nPlease contact your System Administrator for further information", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 else
                 {
                     MessageBox.Show(this, "Error occured while deleteing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(this, "Error occured while deleteing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
     {
         MessageBox.Show(this, "Select a Record from the List", "Select a Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }