Validations -Part ||

public void HCFA24d_05_Leave(object sender, EventArgs e)
{

try{
if (sender.GetType() != new TextBox().GetType()){

DataGridView DGV = (DataGridView)sender;
if (DGV[DGV.CurrentCell.ColumnIndex + 1, DGV.CurrentRow.Index].ReadOnly == true){

if (DGV.CurrentCell.ColumnIndex == DGV.Columns.Count){
DGV.FirstDisplayedScrollingColumnIndex = DGV.CurrentCell.ColumnIndex;
}

else if (DGV.CurrentCell.ColumnIndex + 2 < DGV.Columns.Count){
DGV.FirstDisplayedScrollingColumnIndex = DGV.CurrentCell.ColumnIndex + 2;
}
}
}
}

catch (Exception ex){

throw ex;}
}



public void HCFA24d_HAMN_Leave(object sender, EventArgs e){


try{
if (sender.GetType().BaseType.BaseType.ToString() == new TextBox().GetType().ToString()){

TextBox textBox = (TextBox)sender;
//if ((textBox.Parent.Controls["HCFA24d_HAHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() != "" || textBox.Parent.Controls["HCFA24d_HAHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() == "#") || (textBox.Parent.Controls["HCFA24d_HAMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() != "" || textBox.Parent.Controls["HCFA24d_HAHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() == "#"))//{if (textBox.Parent.Controls["HCFA24d_HAHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() != "" || textBox.Parent.Controls["HCFA24d_HAMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() != "" ){
textBox.Parent.Controls[
"HCFA24d_HAFHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;textBox.Parent.Controls[
"HCFA24d_HAFMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;textBox.Parent.Controls[
"HCFA24d_HATHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;textBox.Parent.Controls[
"HCFA24d_HATMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;}

else{
textBox.Parent.Controls[
"HCFA24d_HAFHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;textBox.Parent.Controls[
"HCFA24d_HAFMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;textBox.Parent.Controls[
"HCFA24d_HATHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;textBox.Parent.Controls[
"HCFA24d_HATMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;}
}

else{
DataGridView DGV = (DataGridView)sender;

if (DGV["HCFA24d_HAHR", DGV.CurrentRow.Index].EditedFormattedValue.ToString() != "" || DGV["HCFA24d_HAMN", DGV.CurrentRow.Index].EditedFormattedValue.ToString() != "" ){
DGV[
"HCFA24d_HAFHR", DGV.CurrentRow.Index].ReadOnly = true;DGV[
"HCFA24d_HAFMN", DGV.CurrentRow.Index].ReadOnly = true;DGV[
"HCFA24d_HATHR", DGV.CurrentRow.Index].ReadOnly = true;DGV[
"HCFA24d_HATMN", DGV.CurrentRow.Index].ReadOnly = true;}

else{
DGV[
"HCFA24d_HAFHR", DGV.CurrentRow.Index].ReadOnly = false;DGV[
"HCFA24d_HAFMN", DGV.CurrentRow.Index].ReadOnly = false;DGV[
"HCFA24d_HATHR", DGV.CurrentRow.Index].ReadOnly = false;DGV[
"HCFA24d_HATMN", DGV.CurrentRow.Index].ReadOnly = false;}
}
}

catch (Exception ex){

throw new Exception(ex.Message);}
}


public void HCFA24d_HAHR_Leave(object sender, EventArgs e){

try{
if (sender.GetType().BaseType.BaseType.ToString() == new TextBox().GetType().ToString()){

TextBox textBox = (TextBox)sender;
if (textBox.Parent.Controls["HCFA24d_HAHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() != "" || textBox.Parent.Controls["HCFA24d_HAMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Text.Trim() != "" ){
textBox.Parent.Controls[
"HCFA24d_HAFHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;textBox.Parent.Controls[
"HCFA24d_HAFMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;textBox.Parent.Controls[
"HCFA24d_HATHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;textBox.Parent.Controls[
"HCFA24d_HATMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = false;}

else{
textBox.Parent.Controls[
"HCFA24d_HAFHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;textBox.Parent.Controls[
"HCFA24d_HAFMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;textBox.Parent.Controls[
"HCFA24d_HATHR_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;textBox.Parent.Controls[
"HCFA24d_HATMN_" + textBox.Name.Substring(textBox.Name.Length - 2, 2)].Enabled = true;}
}


else{
DataGridView DGV = (DataGridView)sender;
if (DGV["HCFA24d_HAHR", DGV.CurrentRow.Index].EditedFormattedValue.ToString() != "" || DGV["HCFA24d_HAMN", DGV.CurrentRow.Index].EditedFormattedValue.ToString() != "" ){
DGV[
"HCFA24d_HAFHR", DGV.CurrentRow.Index].ReadOnly = true;DGV[
"HCFA24d_HAFMN", DGV.CurrentRow.Index].ReadOnly = true;DGV[
"HCFA24d_HATHR", DGV.CurrentRow.Index].ReadOnly = true;DGV[
"HCFA24d_HATMN", DGV.CurrentRow.Index].ReadOnly = true;}

else{
DGV[
"HCFA24d_HAFHR", DGV.CurrentRow.Index].ReadOnly = false;DGV[
"HCFA24d_HAFMN", DGV.CurrentRow.Index].ReadOnly = false;DGV[
"HCFA24d_HATHR", DGV.CurrentRow.Index].ReadOnly = false;DGV[
"HCFA24d_HATMN", DGV.CurrentRow.Index].ReadOnly = false;}
}
}

catch (Exception ex){

throw new Exception(ex.Message);}
}
}
}

Comments