private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (this.dgvView.RowCount == 0) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return; } if (NP.MSGB("Do you want to delete BOM ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB)); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction(); try { SqlCommand cmdDel = new SqlCommand(); NP_Cls.SqlDel = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)"; cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value.ToString()); cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr; cmdDel.ExecuteNonQuery(); NP_Cls.SqlDel = "DELETE FROM t_BOMDetail WHERE (BOMCode = @BOMCode)"; //cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value.ToString()); cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr; cmdDel.ExecuteNonQuery(); if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM:t_BOMDetail", NP_Cls.strUsr)) { Tr.Commit(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete Completed !!"); } else { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return; } } catch (Exception ex) { if (oConn.State == ConnectionState.Open) { Tr.Rollback(); } NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (NP.MSGB("Do you want to delete ?") == DialogResult.Yes) { if (this.dgvView.RowCount == 0) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Data Not Found !!"); return; } oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB)); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction(); try { SqlCommand cmdEdit = new SqlCommand(); NP_Cls.SqlDel = "DELETE FROM t_VendorInfoRecordPeriodsDetail WHERE (ValidPeriodDetailCode = @ValidPeriodDetailCode) AND (ValidPeriodCode = @ValidPeriodCode)"; cmdEdit.Parameters.Add("@ValidPeriodDetailCode", SqlDbType.Int).Value = this.dgvView[0, this.dgvView.CurrentRow.Index].Value.ToString(); cmdEdit.Parameters.Add("@ValidPeriodCode", SqlDbType.Int).Value = this.dgvView[1, this.dgvView.CurrentRow.Index].Value.ToString(); cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.SqlDel; cmdEdit.Transaction = Tr; cmdEdit.ExecuteNonQuery(); if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_VendorInfoRecordPeriodsDetail", NP_Cls.strUsr)) { Tr.Commit(); Clear(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete Data Completed !!"); this.btnAdd.Visible = true; this.btnEdit.Visible = false; this.txtScaleQty.Select(); } else { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return; } } catch (Exception ex) { if (oConn.State == ConnectionState.Open) { Tr.Rollback(); } NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } }
private void btnExit_Click(object sender, EventArgs e) { if (this.dQtyChk != 0) { if (NP.MSGB("Qty of Component are not equal Qty of BOM !!\nThe transaction will be reject , Do you want to exit out of save ?") == DialogResult.Yes) { // Delete all Transaction oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB)); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction(); try { SqlCommand cmdDel = new SqlCommand(); NP_Cls.SqlSelect = "SELECT BOMDetailCode FROM t_BOMDetail WHERE (BOMCode = @BOMCode)"; cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = Convert.ToInt32(NP_Cls.hBOM["BOMCode"].ToString()); cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlSelect; cmdDel.Transaction = Tr; SqlDataAdapter da = new SqlDataAdapter(cmdDel); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { NP_Cls.SqlDel = "DELETE FROM t_BOMDetail WHERE (BOMCode = @BOMCode)"; //cmdDel.Parameters.Add("@BOMCode", SqlDbType.Int).Value = this.dgvView["clnBOMCode", this.dgvView.CurrentRow.Index].Value; cmdDel.Parameters.Add("@BOMDetailCode", SqlDbType.Int).Value = this.dgvView["clnBOMDetailCode", this.dgvView.CurrentRow.Index].Value; cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr; cmdDel.ExecuteNonQuery(); NP_Cls.SqlDel = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)"; cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr; cmdDel.ExecuteNonQuery(); if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM:t_BOMDetail", NP_Cls.strUsr)) { Tr.Commit(); this.Close(); } else { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return; } } else // Has Row { NP_Cls.SqlDel = "DELETE FROM t_BOM WHERE (BOMCode = @BOMCode)"; cmdDel.Connection = oConn; cmdDel.CommandText = NP_Cls.SqlDel; cmdDel.Transaction = Tr; cmdDel.ExecuteNonQuery(); if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "t_BOM", NP_Cls.strUsr)) { Tr.Commit(); this.Close(); } else { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return; } } } catch (Exception ex) { if (oConn.State == ConnectionState.Open) { Tr.Rollback(); } NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } // } else { return; } } else { if (NP.MSGB("Do you want to exit this screen ?") == DialogResult.Yes) { this.Close(); } else { return; } } }
private void btnDelete_Click(object sender, EventArgs e) { try { if (NP.ReqField(this.cbDepartment, "Please enter Department: !!") == false) { return; } if (NP.ReqField(this.cbLevel, "Please enter Level: !!") == false) { return; } if (NP.MSGB("Do you want to Delete Data ?") == DialogResult.Yes) { oConn = new SqlConnection(NP.ReadFileDB(NP_Cls.PathDB)); if (oConn.State == ConnectionState.Open) { oConn.Close(); } oConn.Open(); SqlTransaction Tr; Tr = oConn.BeginTransaction(); try { SqlCommand cmdEdit = new SqlCommand(); NP_Cls.sqlUpdate = "DELETE FROM s_Level " + "WHERE (DepartmentCode = @DepartmentCode) AND (AuthLevel = @AuthLevel)"; cmdEdit.Parameters.Add("@DepartmentCode", SqlDbType.NVarChar, 3).Value = this.cbDepartment.SelectedValue; cmdEdit.Parameters.Add("@AuthLevel", SqlDbType.NVarChar, 1).Value = this.cbLevel.Text.Trim(); cmdEdit.Connection = oConn; cmdEdit.CommandText = NP_Cls.sqlUpdate; cmdEdit.Transaction = Tr; cmdEdit.ExecuteNonQuery(); if (NP._TRanSave(oConn, Tr, NP_Cls.NPTranType.Delete, "s_Level", NP_Cls.strUsr)) { Tr.Commit(); DGV(); NP.MSGB(NP_Cls.NPMgsStyle.InfoType, "Delete Completed !!"); } else { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Try agian !!"); return; } Clear(); DGV(); this.cbDepartment.Select(); } catch (Exception ex) { if (oConn.State == ConnectionState.Open) { Tr.Rollback(); } NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Delete : " + ex.Message); return; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } } else { return; } } catch (Exception ex) { NP.MSGB(NP_Cls.NPMgsStyle.WarningType, "Edit : " + ex.Message); return; } }