private bool insertMaterial(string category, string itemCode, string itemName) { materialBLL uMaterial = new materialBLL(); materialDAL dalMaterial = new materialDAL(); //Add data uMaterial.material_cat = category; uMaterial.material_code = itemCode; uMaterial.material_name = itemName; uMaterial.material_zero_cost = 0; bool success = dalMaterial.Insert(uMaterial); //If the data is successfully inserted then the value of success will be true else false if (success == true) { //Data Successfully Inserted //MessageBox.Show("Material successfully created"); insertItem(category, itemCode, itemName); } else { //Failed to insert data dalMaterial.Delete(uMaterial); MessageBox.Show("Failed to add new material"); } return(success); }
private void insertMaterial() { //Add data uMaterial.material_cat = cmbCat.Text; uMaterial.material_code = txtItemCode.Text; uMaterial.material_name = txtItemName.Text; if (cbZeroCost.Checked) { uMaterial.material_zero_cost = 1; } else { uMaterial.material_zero_cost = 0; } bool success = dalMaterial.Insert(uMaterial); //If the data is successfully inserted then the value of success will be true else false if (success == true) { //Data Successfully Inserted //MessageBox.Show("Material successfully created"); insertItem(); this.Close(); } else { //Failed to insert data dalMaterial.Delete(uMaterial); MessageBox.Show("Failed to add new material"); } }
private void btnDelete_Click(object sender, EventArgs e) { materialUsedDAL dalMatUsed = new materialUsedDAL(); dalMatUsed.Delete(); DataGridView dgv = dgvItemList; Cursor = Cursors.WaitCursor; // change cursor to hourglass type if (dgv.SelectedRows.Count > 0) { int n = dgv.CurrentCell.RowIndex; DialogResult dialogResult = MessageBox.Show("Are you sure want to delete?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { if (cmbCat.Text.Equals("Part")) { uItem.item_code = dgv.Rows[n].Cells[dalItem.ItemCode].Value.ToString(); trfHistDAL dalTrfHist = new trfHistDAL(); dalTrfHist.Delete(uItem.item_code); bool success = dalItem.Delete(uItem); if (success == true) { //item deleted successfully MessageBox.Show("Item deleted successfully"); uJoin.join_parent_code = uItem.item_code; uJoin.join_child_code = uItem.item_code; dalJoin.itemDelete(uJoin); resetForm(); } else { //Failed to delete item MessageBox.Show("Failed to delete item"); } } else { uMaterial.material_code = dgv.Rows[n].Cells[dalItem.ItemCode].Value.ToString();; bool success = dalMaterial.Delete(uMaterial); if (success) { //item deleted successfully MessageBox.Show("Material deleted successfully"); uItem.item_code = dgv.Rows[n].Cells[dalItem.ItemCode].Value.ToString(); //to-do //update item material to null for all the item using same material //DataTable dtItem = dalItem.itemMaterialSearch(uItem.item_code); bool success2 = dalItem.Delete(uItem); if (success2 == true) { //item deleted successfully MessageBox.Show("Item deleted successfully"); } else { //Failed to delete item MessageBox.Show("Failed to delete item"); } resetForm(); } else { //Failed to delete item MessageBox.Show("Failed to delete material"); } } } } else { MessageBox.Show("Please select a data"); } Cursor = Cursors.Arrow; // change cursor to normal type }