Hi all i write the below code to delete the selected employees if all conditions are true as follows
if(max())
{
if(seq()
{
b_rsltcnt=true;
}
else
{
if(dbseq()
{
b_rsltcnt=false;
}
else
{
}
}
If my condition works then i will write the below code
if (b_rsltcnt)
{
foreach (int iEmpID1 in oAdmin.odictAddValues.Keys)
{
oAdmin.EmpID = iEmpID1;
foreach (int iPayPeriodIDs1 in oAdmin.odictAddValues[iEmpID1].lstPayPeriodID)
{
lstdictPayPeriodID.Add(iPayPeriodIDs1);
}
foreach (DateTime dtPaymentYear1 in Admin.odictAddValues[iEmpID1].lstPaymentDate)
{
lstdictDateTime.Add(dtPaymentYear1);
}
foreach (int iPayYears1 in oAdmin.odictAddValues[iEmpID1].lstPayYear)
{
lstdictPayYear.Add(iPayYears1);
}
for (int ipayID = 0; ipayID < lstdictPayPeriodID.Count; ipayID++)
{
oAdmin.Payperiodnumber = lstdictPayPeriodID[ipayID];
for (int ipayDate = idtcnt; ipayDate < lstdictDateTime.Count; ipayDate++)
{
oAdmin.PaymentDate = lstdictDateTime[ipayDate];
idtcnt++;
break;
}
for (int ipayYear1 = iPayYearcnt; ipayYear1 < lstdictPayYear.Count; ipayYear1++)
{
oAdmin.PayYear = lstdictPayYear[ipayYear1];
iPayYearcnt++;
break;
}
mlocal_strStoredProcName = "usp_delete_payroll";
if (oAdmin.deletePayRoll(mlocal_strStoredProcName))
{
oMsg.Message = "Deleted Sucessfully";
oMsg.AlertMessageBox(out m_locallblMessage);
Page.Controls.Add(m_locallblMessage);
oAdmin.FedTaxID = ddlFedTaxID.SelectedValue;
oAdmin.PayFrequency = ddlPaymentType.SelectedValue.ToString();
mlocal_strStoredProcName = "uspSearchPayRoll";
oAdmin.getPayRollDetails(out mlocal_ds, mlocal_strStoredProcName);
grdPayroll.DataSource = mlocal_ds;
grdPayroll.DataBind();
if (mlocal_ds != null)
{
btnDelete.Visible = true;
}
else
btnDelete.Visible = false;
}
}
}
}
My class file consists of delete code as follows
<pre lang="c#">public bool deletePayRoll(string storeproc)
{
m_bFlag = false;
this.m_oConn = Utilities.GetConnection();
try
{
if (m_oConn.State != ConnectionState.Open)
{
m_oConn.Open();
m_oSqlTrans = m_oConn.BeginTransaction();
}
m_oCmd = new MySqlCommand(storeproc, m_oConn);
m_oCmd.CommandType = CommandType.StoredProcedure;
m_oCmd.Transaction = m_oSqlTrans;
m_oCmd.Parameters.AddWithValue("_EmpId", EmpID);
m_oCmd.Parameters.AddWithValue("_FedTaxID", FedTaxID);
m_oCmd.Parameters.AddWithValue("_payperiodnumber", Payperiodnumber);
m_oCmd.Parameters.AddWithValue("_payyear", PayYear);
m_oCmd.Parameters.AddWithValue("_paymentdate", PaymentDate);
if (m_oCmd.ExecuteNonQuery() > 0)
{
m_oSqlTrans.Commit();
m_bFlag = true;
}
}
catch (MySqlException oSqlEx)
{
m_oSqlTrans.Rollback();
m_sbErrMsg.Length = 0;
m_sbErrMsg = Utilities.SqlErrorMessage(oSqlEx);
m_oErrlog.Add(m_sbErrMsg.ToString(), DateTime.Now);
}
catch (Exception oEx)
{
m_sbErrMsg = Utilities.ErrorMessage(oEx);
m_oErrlog.Add(m_sbErrMsg.ToString(), DateTime.Now);
}
finally
{
m_oConn.Close();
}
return m_bFlag;
}
Assume that i have 5 records to delete and all my conditions as per written are always true. For suppose among 5 records 4 deleted successfully and while coming to 5th one i had some connection issues or some other issues and assume that an Exception causes will all the previously deleted records will be rollbacked or not