Tuesday, 10 September 2013

Convert code from c# to javascript

Convert code from c# to javascript

I did some validations in code behind, but i want to do it in client side
with javaScript or jQuery, I'm learning it but this is really hard for me
to do it quickly... and it's a bit pressing!
I need only to convert the function : private bool Cbs_Validating()
private const int MIN_RESERVATION_HOUR = 8;
private const int MAX_RESERVATION_HOUR = 18;
private const int FIRST_LOCAL_NB = 1;
private const int LAST_LOCAL_NB = 4;
protected List<string> choiceList = new List<string>();
protected bool[,] ChoosenTabBool = new bool[MAX_RESERVATION_HOUR + 1,
LAST_LOCAL_NB + 1];
protected List<string> contiguousRanges = new List<string>();
protected int cbsCounter = 0;
protected void GenerateTable()
{
for (int i = MIN_RESERVATION_HOUR; i <= MAX_RESERVATION_HOUR; i++)
{
TableRow row = new TableRow();
this.resTab.Controls.Add(row);
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = i + "h";
row.Controls.Add(headerCell);
for (int j = FIRST_LOCAL_NB; j <= LAST_LOCAL_NB; j++)
{
TableCell cell = new TableCell();
CheckBox cb = new CheckBox();
cb.ID = "cb" + i.ToString() + j.ToString();
cell.Controls.Add(cb);
row.Controls.Add(cell);
}
}
}
protected void CheckCheckedCbs()
{
for (int i = MIN_RESERVATION_HOUR; i <= MAX_RESERVATION_HOUR + 1;
i++)
{
for (int j = FIRST_LOCAL_NB; j <= LAST_LOCAL_NB + 1; j++)
{
Control cont = FindControl("cb" + i.ToString() +
j.ToString());
if (cont != null)
{
if (cont is CheckBox)
{
CheckBox cbox = (CheckBox)cont;
if (cbox.Checked)
{
this.ChoosenTabBool[i, j] = true;
cbsCounter++;
}
}
}
}
}
}
private bool Cbs_Validating()
{
bool retValid = true;
bool flagHoursError = false;
for (int i = MIN_RESERVATION_HOUR; i < MAX_RESERVATION_HOUR + 1; i++)
{
for (int j = FIRST_LOCAL_NB; j < LAST_LOCAL_NB + 1; j++)
{
if (this.ChoosenTabBool[i, j] == true)
{
for (int remainingLoc = 1; remainingLoc <
LAST_LOCAL_NB; remainingLoc++)
{
if (remainingLoc != j)
{
if (this.ChoosenTabBool[i, remainingLoc] == true)
{
retValid = false;
}
}
}
}
}
}
if (retValid)
{
this.lblErrorResTable.Text = "";
int threeNextHours = 0;
for (int i = MIN_RESERVATION_HOUR; i < MAX_RESERVATION_HOUR +
1; i++)
{
for (int j = FIRST_LOCAL_NB; j < LAST_LOCAL_NB + 1; j++)
{
if (this.ChoosenTabBool[i, j] == true)
{
threeNextHours = i + 1;
if (threeNextHours < 19)
{
if (this.ChoosenTabBool[threeNextHours, j] ==
true)
{
threeNextHours = i + 2;
if (threeNextHours < 19)
{
if
(this.ChoosenTabBool[threeNextHours,
j] == true)
{
threeNextHours = i + 3;
if (threeNextHours < 19)
{
if
(this.ChoosenTabBool[threeNextHours,
j] == true)
{
retValid = false;
flagHoursError = true;
}
}
}
}
}
}
}
}
}
}
else
{
this.lblErrorResTable.Text = "Une personne ne peut réserver
plus d'un local pour une plage horaire donnée.";
}
if (flagHoursError)
{
this.lblErrorResTable2.Text = "Un local peut être réservé pour
un maximum de 3 heures consécutives par la même personne.";
}
else
{
this.lblErrorResTable2.Text = "";
}
return retValid;
}`

No comments:

Post a Comment