In my form Load event I check two conditions and give a message if one of them or both are true but whenever the main form is hidden and then showed up the message appears again and this happens every time the main form is showed after it was hidden so the Load event is executed each time ..I just want that message to be showed only once if the conditions are true
This is my Load event codes
private void Form1_Load(object sender, EventArgs e)
{
try
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
SqlCommand cmd = new SqlCommand("select clientData.Id,clientData.clientName,clientData.clientPhone,clientData.clientMobile,clientData.clientEmail,clientData.clientPage,marketingData.marketingBy,marketingData.marketingFor,marketingData.marketingCities,marketingData.marketingDurations,marketingData.marketingStartsFrom,marketingData.marketingEndsIn,marketingData.adDate,marketingData.adImage,priceAndProfits.marketingCost from clientData inner join marketingData on clientData.Id = marketingData.m_Id inner join priceAndProfits on clientData.Id = priceAndProfits.p_Id where marketingData.marketingStartsFrom >= getdate()", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
upComing = true;
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
if (DateTime.Now.Day >= 25 && DateTime.Now.Day < 31)
{
try
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
SqlCommand cmd = new SqlCommand("select clientData.Id,clientData.clientName,clientData.clientMobile,clientData.clientPage,marketingData.marketingBy,priceAndProfits.marketingCost,priceAndProfits.marketingPrice,priceAndProfits.marketingProfit,priceAndProfits.dollarPrice,priceAndProfits.payment from clientData inner join marketingData on clientData.Id = marketingData.m_Id inner join priceAndProfits on clientData.Id = priceAndProfits.p_Id where clientData.isDebtor=1", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt2);
if (dt2.Rows.Count > 0)
{
debt = true;
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
if (debt == true || upComing == true)
{
MessageBox.Show("يرجى مراجعة الإشعارات");
}
}