1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
| using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Cra2aerow
{
public class currentsInfo
{
public int month; //mois de janvier = 0 a decembre = 11
public int monthLen; // nombre de jours dans le mois
public int firstDayType;
public currentsInfo()
{
DateTime date = DateTime.Today;
this.month = date.Month;
monthLen = DateTime.DaysInMonth(date.Year, date.Month); //assigne le nombre de jours dans le mois
firstDayType = (int)date.DayOfWeek - (date.Day % 7); //trouve le premier jour du mois (lun=0, mar=1,....)
}
}
public class halfDay //objet representant une demi journee
{
public enum Period { am = 0, pm }; // period = matin ou apres midi
public Period period;
public int dayNb; //numero du jours de 1 au nobre de jours dans le mois
public int dayType; //jours de la semaine de dimance = 0 a samedi = 6 (systeme anglo-saxon)
public enum daysFR { dimanche = 0, lundi, mardi, mercredi, jeudi, vendredi, samedi }
public halfDay()
{
}
public halfDay(halfDay source) //constructeur (de demi journee) par copie
{
this.dayNb = source.dayNb;
this.dayType = source.dayType;
this.period = source.period;
}
public String getPeriod()
{
if (period == Period.am)
return ("am");
else
return ("pm");
}
public bool isWorked() //return true si le jour n'est pas un week-end et n'est pas ferie
{//ajouter les jours feries via une liste calendrier
if (this.dayType == (int)halfDay.daysFR.samedi || dayType == (int)halfDay.daysFR.dimanche)
return (false);
return (true);
}
}
public partial class v2cra : System.Web.UI.UserControl
{
private ArrayList buildArrayDays(currentsInfo datesInfo) //cree un arraylist avec toutes les demi journees du mois
{
ArrayList days = new ArrayList();
halfDay hDay;
for (int count = 0; count < datesInfo.monthLen; count++)
{
hDay = new halfDay();
hDay.dayNb = count + 1;
hDay.dayType = (datesInfo.firstDayType + hDay.dayNb) % 7;
hDay.period = halfDay.Period.am;
days.Add(hDay);
hDay = new halfDay(hDay);
hDay.period = halfDay.Period.pm;
days.Add(hDay);
}
return (days);
}
protected void loadForm() //construit le tableau du formulaire a partir des objets de demi journees
{
currentsInfo datesInfo = new currentsInfo();
ArrayList days = buildArrayDays(datesInfo);
int listLen = days.Count;
TableRow line;
TableCell cell;
DropDownList ddl;
CheckBox ChB;
HtmlButton btn;
TBLForm.BorderWidth = 2;
TBLForm.CellSpacing = 0;
for (int count = 0; count < listLen; count++) //ajoute chaque lignes
{
line = new TableRow();
if (!(((halfDay)days[count]).isWorked()))//set les couleurs de fond des lignes selon types de jours
line.BackColor = System.Drawing.Color.Gray;
else if ((count % 2) != 1)
line.BackColor = System.Drawing.Color.Yellow;
else
line.BackColor = System.Drawing.Color.YellowGreen;
cell = new TableCell(); // ajoute le numero du jour
cell.Controls.Add(new LiteralControl(((halfDay)days[count]).dayNb.ToString()));
line.Cells.Add(cell);
cell = new TableCell();// ajoute am/pm
cell.Controls.Add(new LiteralControl(((halfDay)days[count]).getPeriod()));
line.Cells.Add(cell);
cell = new TableCell();// ajoute lla check-box
ChB = new CheckBox();
if ((((halfDay)days[count]).isWorked()))
ChB.Checked = true; // les jours ouvres sont coches par defaut (voir specs)
cell.Controls.Add(ChB);
line.Cells.Add(cell);
cell = new TableCell();// ajoute la drop down list des clients
ddl = new DropDownList();
cell.Controls.Add(ddl);
line.Cells.Add(cell);
cell = new TableCell();// ajoute la drop down list des projets
ddl = new DropDownList();
cell.Controls.Add(ddl);
line.Cells.Add(cell);
cell = new TableCell();// ajoute l'input de saisie libre
cell.Width = 150;
cell.Controls.Add(new HtmlInputText());
line.Cells.Add(cell);
TBLForm.Rows.Add(line);
}
}
public void btnSave_clic(object sender, EventArgs e)
{
toto.Text = TBLForm.Rows[0].Cells[0].Controls[0].GetType().ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) // si premier affichage de la page, il faut builder le formulaire
loadForm();
}
}
} |
Partager