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 Public Events /// /// evento update valori /// public event EventHandler eh_nuovoValore; #endregion Public Events #region Protected Properties /// /// gruppo selezionato /// protected string gruppoSel { get { return memLayer.ML.StringSessionObj("gruppoSel"); } set { memLayer.ML.setSessionVal("gruppoSel", value); } } /// /// fase selezionata /// protected int idxFaseSel { get { return memLayer.ML.IntSessionObj("idxFaseSel"); } set { memLayer.ML.setSessionVal("idxFaseSel", value); } } /// /// progetto selezionato /// protected int idxProjSel { get { return memLayer.ML.IntSessionObj("idxProjSel"); } set { memLayer.ML.setSessionVal("idxProjSel", value); } } /// /// minuti selezionati nel controllo radio in testa /// protected int minutiSel { get { return memLayer.ML.IntSessionObj("stdMinDurata"); } set { memLayer.ML.setSessionVal("stdMinDurata", value); } } #endregion Protected Properties #region Public Properties /// /// abilitato editing + nuovo + delete + clona /// public bool enableFull { get { bool answ = false; try { answ = memLayer.ML.BoolSessionObj("enableEditComm"); } catch { } return answ; } set { memLayer.ML.setSessionVal("enableEditComm", value); } } /// /// idxDipendente selezionato (0=tutti) /// public int idxDipCurr { get { return memLayer.ML.IntSessionObj("idxDipCurr"); } set { memLayer.ML.setSessionVal("idxDipCurr", value); } } /// /// progetto selezionato.. /// public string idxProgetto { get { return idxProjSel.ToString(); } } /// /// stato attuale del controllo /// public statoControllo stato { get { statoControllo answ = statoControllo.item; try { answ = (statoControllo)memLayer.ML.objSessionObj("statoControlloRA"); } catch { } return answ; } set { memLayer.ML.setSessionVal("statoControlloRA", value); } } /// /// valore datetime selezionato! /// 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:dd/MM/yyyy}", value); lblSubtitle.Text = string.Format("{0:dddd}", value); } } #endregion Public Properties #region Private Methods 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 { // recupero tab timbrature delal giornata... DS_Applicazione.TimbratureDataTable tabTimbrature = DataProxy.DP.taTimb.getByIdxDipPeriodo(DataProxy.idxDipendente, valoreDateTime, valoreDateTime.AddDays(1)); // sono ordinate DEC x cui prendo l'ultima... int numRow = tabTimbrature.Rows.Count; if (numRow > 0) { DS_Applicazione.TimbratureRow riga = tabTimbrature[numRow - 1]; oraStart = Convert.ToDouble(riga.dataOra.Hour + (double)riga.dataOra.Minute / 60); } } catch { } // altrimenti duplico ultima entry utente.. DataProxy.DP.taRA.clonaLastRA_Utente(DataProxy.idxDipendente, valoreDateTime.AddHours(oraStart), durataMinuti); updateControl(); } } /// /// refresh dei controlli /// private void refreshControlli() { bool doDataBound = true; switch (stato) { case statoControllo.edit: doDataBound = true; 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 { } // 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(); } } /// /// fa update del controllo e chiama evento update esterno /// private void updateControl() { grView.SelectedIndex = -1; refreshControlli(); // sollevo evento nuovo valore... if (eh_nuovoValore != null) { eh_nuovoValore(this, new EventArgs()); } } #endregion Private Methods #region Protected Methods /// /// richiesta creazione nuovo record /// /// /// protected void btnNew_Click(object sender, EventArgs e) { createNew(); } /// /// sistemo eventuali "headers" /// /// /// 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"); if (li != null) { 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 { } } /// aggiorno ods progetti... /// /// /// protected void ddlGruppo_SelectedIndexChanged(object sender, EventArgs e) { // salvo in session idxProjSel! DropDownList ddlGrp_int = (DropDownList)sender; gruppoSel = ddlGrp_int.SelectedValue; // 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; } // 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 ddlProj_int = (DropDownList)grView.FooterRow.FindControl("ddlProgetto"); ddlProj_int.SelectedIndex = 0; ddlProj_int.DataBind(); idxProjSel = Convert.ToInt32(ddlProj_int.SelectedValue); DropDownList ddlFase_int = (DropDownList)grView.FooterRow.FindControl("ddlFase"); ddlFase_int.SelectedIndex = 1; ddlFase_int.DataBind(); } 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 ddlProj_int = (DropDownList)grView.Rows[idx].FindControl("ddlProgetto"); ddlProj_int.SelectedIndex = 0; ddlProj_int.DataBind(); idxProjSel = Convert.ToInt32(ddlProj_int.SelectedValue); DropDownList ddlFase_int = (DropDownList)grView.Rows[idx].FindControl("ddlFase"); ddlFase_int.SelectedIndex = 1; ddlFase_int.DataBind(); } catch { } } } /// /// aggiorno ods fasi... /// /// /// 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 { } } } /// /// recupera i dati di un nuovo record contenuti nel footer di un gridView; /// questi devono esses opportunamente nominati (es: txt{0}, dl{0}, ...) /// /// /// 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); } protected void grView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { ddlGruppo.Visible = false; } /// /// generico comando riga /// /// /// 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; } } /// /// riga popolata /// /// /// protected void grView_RowDataBound(object sender, GridViewRowEventArgs e) { // controllo la riga GridViewRow riga = e.Row; if ((grView.EditIndex >= 0 && riga.RowIndex == grView.EditIndex) || grView.ShowFooter) { //pre-seleziono idx progetto x ods fase... DropDownList ddlProj_int = (DropDownList)riga.FindControl("ddlProgetto"); if (idxProjSel >= 0 && (ddlProj_int != null)) { try { ddlProj_int.SelectedValue = idxProjSel.ToString(); } catch { } } DropDownList ddlFase_int = (DropDownList)riga.FindControl("ddlFase"); if (idxFaseSel >= 0 && (ddlFase_int != null)) { try { ddlFase_int.SelectedValue = idxFaseSel.ToString(); } catch { } } } } /// /// riga eliminata /// /// /// protected void grView_RowDeleted(object sender, GridViewDeletedEventArgs e) { updateControl(); ddlGruppo.Visible = false; } /// /// riga in edit /// /// /// protected void grView_RowEditing(object sender, GridViewEditEventArgs e) { grView.SelectedIndex = e.NewEditIndex; int idxRASel = Convert.ToInt32(grView.SelectedDataKey["idxRA"]); // salvo in sessione valori selezionati var tabRAD = DataProxy.DP.taRAExpl.getByKey(idxRASel); if (tabRAD.Rows.Count > 0) { idxFaseSel = tabRAD[0].idxFase; idxProjSel = tabRAD[0].idxProgetto; // imposto gruppo ddlGruppo.Visible = true; ddlGruppo.SelectedValue = tabRAD[0].gruppo; gruppoSel = tabRAD[0].gruppo; } } /// /// effettuato update /// /// /// protected void grView_RowUpdated(object sender, GridViewUpdatedEventArgs e) { updateControl(); ddlGruppo.Visible = false; } 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(); } /// /// richiesta creazione nuovo record /// /// /// protected void lnkNew_Click(object sender, EventArgs e) { ddlGruppo.Visible = true; createNew(); } /// /// completato insert! aggiorno! /// /// /// protected void odsRA_Inserted(object sender, ObjectDataSourceStatusEventArgs e) { stato = statoControllo.item; refreshControlli(); } /// /// intercetto update! /// /// /// protected void odsRA_Updating(object sender, ObjectDataSourceMethodEventArgs e) { DropDownList ddlfase_int = (DropDownList)grView.Rows[grView.EditIndex].FindControl("ddlFase"); e.InputParameters["idxFase"] = ddlfase_int.SelectedValue; } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { refreshControlli(); pnlHeader.Visible = enableFull; lblTitle.Text = string.Format("{0:dd/MM/yyyy}", valoreDateTime); lblSubtitle.Text = string.Format("{0:dddd}", valoreDateTime); ddlGruppo.Visible = false; } } /// /// esegue ricerca progetto/fase x sovrascrivere /// /// /// protected void txtSearchFase_TextChanged(object sender, EventArgs e) { // recupero testo... string search = ""; try { search = ((TextBox)sender).Text.Trim(); } catch { } if (!string.IsNullOrEmpty(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(); } #endregion Protected Methods #region Public Methods /// /// aggiorna /// public void doUpdate() { refreshControlli(); } /// /// formatta la durata in ore secondo web.config (centesimale/ore:min) /// /// /// 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; } /// /// calcola idxProgetto da idxFase /// /// /// public int idxPrjByFase(object idxFase) { int answ = 0; try { answ = DataProxy.DP.taAF.getByIdx(Convert.ToInt32(idxFase))[0].idxProgetto; } catch { } return answ; } /// /// /// effettua traduzione del lemma /// /// /// public string traduci(string lemma) { return user_std.UtSn.Traduci(lemma); } #endregion Public Methods } }