Files
GPW/GPW_Commesse/WebUserControls/mod_commAttivitaDesk.ascx.cs
T

666 lines
22 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SteamWare;
using GPW_data;
using System.Data;
namespace GPW_Commesse.WebUserControls
{
public partial class mod_commAttivitaDesk : System.Web.UI.UserControl
{
#region area protected / private
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
refreshControlli();
pnlHeader.Visible = enableFull;
lblTitle.Text = string.Format("{0:dddd dd/MM/yyyy}", valoreDateTime);
}
}
/// <summary>
/// minuti selezionati nel controllo radio in testa
/// </summary>
protected int minutiSel
{
get
{
return memLayer.ML.IntSessionObj("stdMinDurata");
}
set
{
memLayer.ML.setSessionVal("stdMinDurata", value);
}
}
/// <summary>
/// refresh dei controlli
/// </summary>
private void refreshControlli()
{
bool doDataBound = true;
switch (stato)
{
case statoControllo.edit:
doDataBound = true;
//grView.ShowFooter = false;
//grView.SelectedIndex = grView.EditIndex;
//int idxRASel = Convert.ToInt32(grView.SelectedDataKey["idxRA"]);
//// pre-seleziono idx progetto x ods fase...
//idxFaseSel = DataProxy.DP.taRA.getByKey(idxRASel)[0].idxFase;
//idxProjSel = idxPrjByFase(idxFaseSel);
break;
case statoControllo.insert:
grView.ShowFooter = true;
grView.DataBind();
// imposto arrotondato ad ora...
DateTime inizio = valoreDateTime.Date.AddHours(DateTime.Now.Hour);
// imposto durate standard!
int minuti = minutiSel;
if (minuti < 0)
{
minuti = 60;
}
// cerco ultimo valore inserito odierno (se c'è)
try
{
DS_Applicazione.RegAttivitaDataTable tabRA = DataProxy.DP.taRA.getByDipData(idxDipCurr, inizio.Date, inizio.Date.AddDays(1));
inizio = tabRA[tabRA.Rows.Count - 1].fine;
}
catch
{
}
#if false
// provo a leggere valore editato (se c'è...)
try
{
DateTime inizioSel = ((mod_dateTime)grView.FooterRow.FindControl("dtInizio")).valoreDateTime;
if (inizioSel != inizio && inizio != valoreDateTime.Date.AddHours(DateTime.Now.Hour)) inizio = inizioSel;
}
catch
{
}
#endif
// cerco di impostare inizio/fine
try
{
((mod_dateTime)grView.FooterRow.FindControl("dtInizio")).valoreDateTime = inizio;
((mod_dateTime)grView.FooterRow.FindControl("dtFine")).valoreDateTime = inizio.AddMinutes(minuti);
}
catch
{ }
doDataBound = false;
break;
case statoControllo.item:
grView.ShowFooter = false;
// cerco di impostare inizio/fine
if (grView.EditIndex >= 0)
{
if (minutiSel > 0)
{
try
{
//salvo valori selezionati
string descrizione = ((TextBox)grView.Rows[grView.EditIndex].FindControl("txtDescrizione")).Text;
DateTime inizioEdit = ((mod_dateTime)grView.Rows[grView.EditIndex].FindControl("dtInizio")).valoreDateTime;
grView.DataBind();
// reimposto! con durata calcolata
((mod_dateTime)grView.Rows[grView.EditIndex].FindControl("dtInizio")).valoreDateTime = inizioEdit;
((mod_dateTime)grView.Rows[grView.EditIndex].FindControl("dtFine")).valoreDateTime = inizioEdit.AddMinutes(minutiSel);
((TextBox)grView.Rows[grView.EditIndex].FindControl("txtDescrizione")).Text = descrizione;
// DISATTIVO COLLEGAMENTO A DATI...
doDataBound = false;
}
catch
{ }
}
}
break;
default:
break;
}
if (doDataBound)
{
grView.DataBind();
}
}
#if false
/// <summary>
/// salvo in session che il prox comando è clonare...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void imgClona_Click(object sender, ImageClickEventArgs e)
{
ImageButton lbtn = (ImageButton)sender;
int idxRa = 0;
try
{
idxRa = Convert.ToInt32(lbtn.CommandArgument);
}
catch
{ }
// chiamo clona!
DataProxy.DP.taRA.clonaRecord(idxRa);
updateControl();
}
#endif
protected void lnkClona_Click(object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton)sender;
int idxRa = 0;
try
{
idxRa = Convert.ToInt32(lbtn.CommandArgument);
}
catch
{ }
// chiamo clona!
DataProxy.DP.taRA.clonaRecord(idxRa);
updateControl();
}
/// <summary>
/// fa update del controllo e chiama evento update esterno
/// </summary>
private void updateControl()
{
grView.SelectedIndex = -1;
refreshControlli();
// sollevo evento nuovo valore...
if (eh_nuovoValore != null)
{
eh_nuovoValore(this, new EventArgs());
}
}
/// <summary>
/// completato insert! aggiorno!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void odsRA_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
stato = statoControllo.item;
refreshControlli();
}
/// <summary>
/// effettuato update
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
updateControl();
}
/// <summary>
/// riga eliminata
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
updateControl();
}
/// <summary>
/// recupera i dati di un nuovo record contenuti nel footer di un gridView;
/// questi devono esses opportunamente nominati (es: txt{0}, dl{0}, ...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void doInsert()
{
//recupero la riga footer...
int idxDip = DataProxy.idxDipendente;
int idxFase = 0;
DateTime inizio = DateTime.Now;
DateTime fine = DateTime.Now;
string descr = "";
try
{
idxFase = Convert.ToInt32(((DropDownList)grView.FooterRow.FindControl("ddlFase")).SelectedValue);
inizio = ((mod_dateTime)grView.FooterRow.FindControl("dtInizio")).valoreDateTime;
fine = ((mod_dateTime)grView.FooterRow.FindControl("dtFine")).valoreDateTime;
descr = ((TextBox)grView.FooterRow.FindControl("txtDescrizione")).Text;
}
catch
{ }
DataProxy.DP.taRA.Insert(idxDip, idxFase, inizio, fine, descr, 0);
}
/// <summary>
/// riga in edit
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowEditing(object sender, GridViewEditEventArgs e)
{
grView.SelectedIndex = e.NewEditIndex;
int idxRASel = Convert.ToInt32(grView.SelectedDataKey["idxRA"]);
// salvo in sessione valori selezionati
idxFaseSel = DataProxy.DP.taRA.getByKey(idxRASel)[0].idxFase;
idxProjSel = idxPrjByFase(idxFaseSel);
}
/// <summary>
/// riga popolata
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowDataBound(object sender, GridViewRowEventArgs e)
{
// controllo la riga
GridViewRow riga = e.Row;
if (grView.EditIndex >= 0 || grView.ShowFooter)
{
try
{
//pre-seleziono idx progetto x ods fase...
DropDownList ddlProj_int = (DropDownList)riga.FindControl("ddlProgetto");
if (idxProjSel >= 0 && (ddlProj_int != null))
{
ddlProj_int.SelectedValue = idxProjSel.ToString();
}
DropDownList ddlFase_int = (DropDownList)riga.FindControl("ddlFase");
if (idxFaseSel >= 0 && (ddlFase_int != null))
{
ddlFase_int.SelectedValue = idxFaseSel.ToString();
}
}
catch
{ }
}
}
/// <summary>
/// intercetto update!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void odsRA_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
DropDownList ddlfase_int = (DropDownList)grView.Rows[grView.EditIndex].FindControl("ddlFase");
e.InputParameters["idxFase"] = ddlfase_int.SelectedValue;
}
/// <summary>
/// aggiorno ods fasi...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlProgetto_SelectedIndexChanged(object sender, EventArgs e)
{
// salvo in session idxProjSel!
DropDownList ddlProj_int = (DropDownList)sender;
idxProjSel = Convert.ToInt32(ddlProj_int.SelectedValue);
// ricarico dati fasi
odsFase.DataBind();
// se in insert salvo orari e testo...
DateTime inizio = DateTime.Now;
DateTime fine = DateTime.Now;
string descr = "";
if (stato == statoControllo.insert)
{
inizio = ((mod_dateTime)grView.FooterRow.FindControl("dtInizio")).valoreDateTime;
fine = ((mod_dateTime)grView.FooterRow.FindControl("dtFine")).valoreDateTime;
descr = ((TextBox)grView.FooterRow.FindControl("txtDescrizione")).Text;
}
else
{
// se è edit...
int idx = grView.EditIndex;
inizio = ((mod_dateTime)grView.Rows[idx].FindControl("dtInizio")).valoreDateTime;
fine = ((mod_dateTime)grView.Rows[idx].FindControl("dtFine")).valoreDateTime;
descr = ((TextBox)grView.Rows[idx].FindControl("txtDescrizione")).Text;
}
refreshControlli();
// se in insert riporto orari e testo...
if (stato == statoControllo.insert)
{
((mod_dateTime)grView.FooterRow.FindControl("dtInizio")).valoreDateTime = inizio;
((mod_dateTime)grView.FooterRow.FindControl("dtFine")).valoreDateTime = fine;
((TextBox)grView.FooterRow.FindControl("txtDescrizione")).Text = descr;
try
{
DropDownList ddlFase_int = (DropDownList)grView.FooterRow.FindControl("ddlFase");
ddlFase_int.SelectedIndex = 1;
}
catch
{ }
}
else
{
// se è edit...
int idx = grView.EditIndex;
((mod_dateTime)grView.Rows[idx].FindControl("dtInizio")).valoreDateTime = inizio;
((mod_dateTime)grView.Rows[idx].FindControl("dtFine")).valoreDateTime = fine;
((TextBox)grView.Rows[idx].FindControl("txtDescrizione")).Text = descr;
try
{
DropDownList ddlFase_int = (DropDownList)grView.Rows[idx].FindControl("ddlFase");
ddlFase_int.SelectedIndex = 1;
}
catch
{ }
}
}
/// <summary>
/// progetto selezionato
/// </summary>
protected int idxProjSel
{
get
{
return memLayer.ML.IntSessionObj("idxProjSel");
}
set
{
memLayer.ML.setSessionVal("idxProjSel", value);
}
}
/// <summary>
/// fase selezionata
/// </summary>
protected int idxFaseSel
{
get
{
return memLayer.ML.IntSessionObj("idxFaseSel");
}
set
{
memLayer.ML.setSessionVal("idxFaseSel", value);
}
}
/// <summary>
/// generico comando riga
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "Cancel":
stato = statoControllo.item;
updateControl();
break;
case "Insert":
doInsert();
stato = statoControllo.item;
updateControl();
break;
default:
break;
}
}
#endregion
#region area public
/// <summary>
/// idxDipendente selezionato (0=tutti)
/// </summary>
public int idxDipCurr
{
get
{
return memLayer.ML.IntSessionObj("idxDipCurr");
}
set
{
memLayer.ML.setSessionVal("idxDipCurr", value);
}
}
/// <summary>
/// progetto selezionato..
/// </summary>
public string idxProgetto
{
get
{
return idxProjSel.ToString();
}
}
/// <summary>
/// abilitato editing + nuovo + delete + clona
/// </summary>
public bool enableFull
{
get
{
bool answ = false;
try
{
answ = memLayer.ML.BoolSessionObj("enableEditComm");
}
catch
{ }
return answ;
}
set
{
memLayer.ML.setSessionVal("enableEditComm", value);
}
}
/// <summary>
/// stato attuale del controllo
/// </summary>
public statoControllo stato
{
get
{
statoControllo answ = statoControllo.item;
try
{
answ = (statoControllo)memLayer.ML.objSessionObj("statoControlloRA");
}
catch
{ }
return answ;
}
set
{
memLayer.ML.setSessionVal("statoControlloRA", value);
}
}
/// <summary>
/// valore datetime selezionato!
/// </summary>
public DateTime valoreDateTime
{
get
{
DateTime answ = DateTime.Now;
try
{
answ = Convert.ToDateTime(memLayer.ML.objSessionObj("dataRif"));
}
catch
{ }
return answ;
}
set
{
memLayer.ML.setSessionVal("dataRif", value);
lblTitle.Text = string.Format("{0:dddd dd/MM/yyyy}", value);
}
}
/// <summary>
/// evento update valori
/// </summary>
public event EventHandler eh_nuovoValore;
/// <summary>
/// effettua traduzione del lemma
/// </summary>
/// <param name="lemma"></param>
/// <returns></returns>
public string traduci(string lemma)
{
return user_std.UtSn.Traduci(lemma);
}
/// <summary>
/// aggiorna
/// </summary>
public void doUpdate()
{
refreshControlli();
}
/// <summary>
/// calcola idxProgetto da idxFase
/// </summary>
/// <param name="idxFase"></param>
/// <returns></returns>
public int idxPrjByFase(object idxFase)
{
int answ = 0;
try
{
answ = DataProxy.DP.taAF.getByIdx(Convert.ToInt32(idxFase))[0].idxProgetto;
}
catch
{ }
return answ;
}
/// <summary>
/// sistemo eventuali "headers"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlFase_DataBound(object sender, EventArgs e)
{
// cerco eventuali controlli tipo "ancestor" e li disattivo!
DropDownList ddlFase_int = (DropDownList)sender;
ListItem li = new ListItem();
while (li != null)
{
li = ddlFase_int.Items.FindByValue("0");
try
{
li.Attributes.Add("style", "color:gray;");
li.Attributes.Add("disabled", "true");
li.Value = "-1";
li.Text = string.Format("[ {0} ]", li.Text);
}
catch
{ }
}
try
{
ddlFase_int.SelectedIndex = 1;
}
catch
{ }
}
/// <summary>
/// richiesta creazione nuovo record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
createNew();
}
private void createNew()
{
if (grView.Rows.Count > 0)
{
// controllo: se ho righe mostro il footer...
stato = statoControllo.insert;
refreshControlli();
}
else
{
// default: inizia ora la dichiarazione
double oraStart = DateTime.Now.Hour;
int durataMinuti = memLayer.ML.IntSessionObj("stdMinDurata");
// se c'è timbratura ingresso prendo quella come ora inizio...
try
{
DS_Applicazione.TimbratureRow riga = DataProxy.DP.taTimb.getByIdxDipPeriodo(DataProxy.idxDipendente, valoreDateTime, valoreDateTime.AddDays(1))[0];
oraStart = Convert.ToDouble(riga.dataOra.Hour + riga.dataOra.Minute / 60);
}
catch
{ }
// altrimenti duplico ultima entry utente..
DataProxy.DP.taRA.clonaLastRA_Utente(DataProxy.idxDipendente, valoreDateTime.AddHours(oraStart), durataMinuti);
updateControl();
}
}
/// <summary>
/// richiesta creazione nuovo record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lnkNew_Click(object sender, EventArgs e)
{
createNew();
}
/// <summary>
/// esegue ricerca progetto/fase x sovrascrivere
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtSearchFase_TextChanged(object sender, EventArgs e)
{
// recupero testo...
string search = "";
try
{
search = ((TextBox)sender).Text.Trim();
}
catch
{ }
if (search != "")
{
// faccio ricerca x progetto e fase...
GPW_data.DS_Utility.stp_VSProjFasi_searchDataTable tabRes = DataProxy.DP.taVSProjFasiSearch.GetData(search);
if (tabRes.Rows.Count > 0)
{
idxFaseSel = tabRes[0].idxFase;
idxProjSel = tabRes[0].idxProgetto;
}
}
//stato = statoControllo.edit;
//refreshControlli();
//stato = statoControllo.item;
//minutiSel = -1;
refreshControlli();
}
/// <summary>
/// formatta la durata in ore secondo web.config (centesimale/ore:min)
/// </summary>
/// <param name="oreCent"></param>
/// <returns></returns>
public string formatDurata(object oreCent)
{
decimal ore = 0;
try
{
ore = Convert.ToDecimal(oreCent);
}
catch
{ }
string answ = "";
if (memLayer.ML.confReadBool("reviewShowOreMin"))
{
answ = utils.formOreMin(ore);
}
else
{
answ = ore.ToString("0.00");
}
return answ;
}
#endregion
}
}