I've written a code that will allow the user to enter data into the program and this will transfer to an excel file. However I dont want anything being added when one of my text boxes is empty.With this code a row is still being added despite my if else conditions.I have debugged and used break points and the txt_LRU != null is true even if txt_LRU is empty or not.Can someone please tell me why this is happening?
private void button_kaydet_Click(object sender, EventArgs e){
//the text that is obtained from the text boxes and combo boxes.
string txt_LRU = this.txtbx_LRUno.Text.ToString();
string txt_yi = this.txtbx_yi.Text.ToString();
string txt_td = this.cmbx_td.Text.ToString();
string txt_toptarih = this.dtp_toplanti.Text.ToString();
string txt_bastarih = this.dtp_bas.Text.ToString();
string txt_teslimtarih = this.dtp_teslim.Text.ToString();
string txt_ilgilinot = this.txtbx_ilgiliNot.Text.ToString();
string txt_acikislem = this.txtbx_acikislem.Text.ToString();
string txt_referedosya = this.txtbx_referedosya.Text.ToString();
string txt_parcano = this.txtbx_parcano2.Text.ToString();
int lru_row = 0;
int kontrol = 0;
//if there is non existing LRU then save the data into a new row in excel
if (kontrol == 0)
{
if (txt_LRU != null || txt_LRU!="")
{
int x = satir_sayisi + 1;
string satir_no = x.ToString();
sheet1.Cells[1][satir_sayisi + 2] = satir_no;
sheet1.Cells[2][satir_sayisi + 2] = txt_LRU;
sheet1.Cells[3][satir_sayisi + 2] = txt_parcano;
sheet1.Cells[4][satir_sayisi + 2] = txt_yi;
sheet1.Cells[5][satir_sayisi + 2] = txt_acikislem;
sheet1.Cells[7][satir_sayisi + 2] = txt_td;
sheet1.Cells[8][satir_sayisi + 2] = txt_toptarih;
sheet1.Cells[9][satir_sayisi + 2] = txt_bastarih;
sheet1.Cells[10][satir_sayisi + 2] = txt_teslimtarih;
sheet1.Cells[11][satir_sayisi + 2] = txt_ilgilinot;
}
else if (txt_LRU == null || txt_LRU == "")
MessageBox.Show("Please add the LRU number ");
}
//to save and close the excel file
uyg.DisplayAlerts = false;
kitap.Save();
kitap.Close();
uyg.DisplayAlerts = true;
uyg.Quit();
DialogResult dialogResult2 = MessageBox.Show("Would you like to see the excel file?", "Bilgilendirme", MessageBoxButtons.YesNo);
if (dialogResult2 == DialogResult.Yes)
{
Process.Start(@"C:\\Users\\casperpc\\Desktop\\hey.xls");
}
else if (dialogResult2 == DialogResult.No)
{
}
}
