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); }
public bool Insert(materialBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = "INSERT INTO tbl_material (material_code, material_name, material_cat,material_zero_cost) VALUES (@material_code, @material_name, @material_cat,@material_zero_cost)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@material_code", u.material_code); cmd.Parameters.AddWithValue("@material_name", u.material_name); cmd.Parameters.AddWithValue("@material_cat", u.material_cat); cmd.Parameters.AddWithValue("@material_zero_cost", u.material_zero_cost); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }
public bool Delete(materialBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = "DELETE FROM tbl_material WHERE material_code=@material_code"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@material_code", u.material_code); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }
private bool updateMaterial(string category, string itemCode, string itemName) { materialBLL uMaterial = new materialBLL(); materialDAL dalMaterial = new materialDAL(); //Update data uMaterial.material_cat = category; uMaterial.material_code = itemCode; uMaterial.material_name = itemName; uMaterial.material_zero_cost = 0; bool success = false; if (tool.IfMaterialExists(itemCode)) { success = dalMaterial.Update(uMaterial); } else { success = dalMaterial.Insert(uMaterial); } if (success == true) { //data updated successfully //MessageBox.Show("Material successfully updated "); updateItem(category, itemCode, itemName); } else { //failed to update user MessageBox.Show("Failed to updated material"); } return(success); }