using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using ETS_Data; namespace ETS_WS.WebUserControls { public partial class mod_inputDati : System.Web.UI.UserControl { /// /// variabile x decidere se mostrare pannello metadati /// public bool showTMD { get { return utils.obj.BoolSessionObj("showTMD"); } set { utils.obj.setSessionVal("showTMD", value); } } /// /// evento richiesta salvataggio files /// public event EventHandler eh_newData; /// /// caricamento pagina /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { showTMD = false; rblProto.SelectedIndex = 0; setDate(); updateVisual(); } tacCommesse.eh_valSelezionato += new EventHandler(tacCommesse_eh_valSelezionato); tacFasi.eh_valSelezionato += new EventHandler(tacFasi_eh_valSelezionato); tacFonti.eh_valSelezionato += new EventHandler(tacFonti_eh_valSelezionato); saveProto(); } private void setDate() { txtDataDoc.Text = DateTime.Now.ToShortDateString(); txtDataRic.Text = DateTime.Now.ToShortDateString(); } /// /// imposto valori secondari /// /// /// void tacFonti_eh_valSelezionato(object sender, EventArgs e) { updateVisual(); txtOggetto.Focus(); } /// /// imposto valori secondari /// /// /// void tacFasi_eh_valSelezionato(object sender, EventArgs e) { updateVisual(); tacFonti.setFocus(); } /// /// imposto valori secondari /// /// /// void tacCommesse_eh_valSelezionato(object sender, EventArgs e) { updateVisual(); tacFasi.setFocus(); } /// /// aggiorna tutti i valori visualizzati /// public void updateVisual() { pnlTemplateMetaDati.Visible = showTMD; showProto(); saveMetaData(); if (WebShipUtils.mng.metaPresent) { imgNewTMD.ImageUrl = "~/images/addTMD_m.png"; } else { imgNewTMD.ImageUrl = "~/images/addDisTMD_m.png"; } imgNewTMD.Enabled = WebShipUtils.mng.metaPresent; txtNomeTMD.Visible = WebShipUtils.mng.metaPresent; } /// /// cambio selezione protocollo/senza protocollo /// /// /// protected void rblProto_SelectedIndexChanged(object sender, EventArgs e) { updateVisual(); } /// /// controlla visualizzazione protocollo /// private void showProto() { // decido se mostrare il protocollo... bool showProto = false; try { showProto = Convert.ToBoolean(rblProto.SelectedValue); } catch { } #if false //clbProto.Visible = showProto; #endif lblNumProto.Visible = showProto; if (showProto) { saveProto(); } } /// /// salva negli oggetti il protocollo /// private void saveProto() { int nrProto = 0; int anno = DateTime.Now.Year; try { nrProto = utils.obj.taCalcProto.GetData()[0].nextProto; anno = utils.obj.taCalcProto.GetData()[0].Anno; } catch { } lblNumProto.Text = string.Format("{0}-{1}", nrProto, anno); #if false //clbProto.text4copy = lblNumProto.Text; //clbProto.text4btn = "Copia"; #endif } /// /// cambio selezione IN/OUT /// /// /// protected void rblInOut_SelectedIndexChanged(object sender, EventArgs e) { updateVisual(); } /// /// /// /// /// protected void txtOggetto_TextChanged(object sender, EventArgs e) { updateVisual(); txtDataDoc.Focus(); } /// /// metodo lettura/scrittura oggetto metadati public /// public docMetaDataSet metaDatiDoc { get { docMetaDataSet answ = new docMetaDataSet(); // popolo! try { answ.reqProto = Convert.ToBoolean(rblProto.SelectedValue); } catch { answ.reqProto = false; } answ.InOut = rblInOut.SelectedValue; answ.commessa = utils.cleanPathName(tacCommesse.valore); answ.fase = utils.cleanPathName(tacFasi.label); answ.fonte = utils.cleanPathName(tacFonti.label); answ.oggetto = utils.cleanPathName(txtOggetto.Text); try { answ.dataDoc = Convert.ToDateTime(txtDataDoc.Text); } catch { answ.dataDoc = DateTime.Now; } try { answ.dataRic = Convert.ToDateTime(txtDataRic.Text); } catch { answ.dataRic = DateTime.Now; } answ.isRed = chkIsRed.Checked; answ.path = WebShipUtils.path(answ); // calcolo i tags... List tags = new List(); foreach (ListItem tag in cblTags.Items) { if (tag.Selected) { tags.Add(tag.Value); } } answ.tags = tags; // restituisco oggetto return answ; } set { // decodificare valori e inserire in selettori... docMetaDataSet currData = value; rblProto.SelectedValue = currData.reqProto.ToString(); ; rblInOut.SelectedValue = currData.InOut; tacCommesse.valore = currData.commessa; tacCommesse.label = currData.commessa; tacFasi.label = currData.fase; tacFonti.label = currData.fonte; txtOggetto.Text = currData.oggetto; txtDataDoc.Text = currData.dataDoc.ToShortDateString(); txtDataRic.Text = currData.dataRic.ToShortDateString(); chkIsRed.Checked = currData.isRed; // calcolo i tags "da accendere"... if (currData.tags.Count > 0) { cblTags.DataBind(); foreach (string tag in currData.tags) { cblTags.Items.FindByValue(tag).Selected = true; } } } } /// /// salva in sesione i metadati /// private void saveMetaData() { // salvo il solo oggetto globale metadati... WebShipUtils.mng.currMetaData = metaDatiDoc; if (eh_newData != null) { eh_newData(this, new EventArgs()); } } /// /// aggiornamento data doc /// /// /// protected void txtDataDoc_TextChanged(object sender, EventArgs e) { saveMetaData(); // aggiorno updateVisual(); txtDataRic.Focus(); } /// /// update x check tipo classificazione "RED" /// /// /// protected void chkIsRed_CheckedChanged(object sender, EventArgs e) { updateVisual(); } /// /// update dei tags selezionati /// /// /// protected void cblTags_SelectedIndexChanged(object sender, EventArgs e) { updateVisual(); } /// /// mostra/nasconde menù template metadati /// /// /// protected void img_Click(object sender, ImageClickEventArgs e) { showTMD = !showTMD; updateVisual(); } /// /// aggiunge un nuovo tempalte metadati x l'utente... /// /// /// protected void imgNewTMD_Click(object sender, ImageClickEventArgs e) { // salvo il template metadati... string setName = txtNomeTMD.Text.Trim(); if (setName != "") { // elimino eventuale velore vecchio SE nuovo = selected! if (dlElencoTemplate.SelectedValue == setName) { WebShipUtils.mng.eliminaTemplateMedatati(utils.obj.currUserId, dlElencoTemplate.SelectedValue); } // salvo! WebShipUtils.mng.salvaTemplateMedatati(utils.obj.currUserId, setName, metaDatiDoc); } dlElencoTemplate.DataBind(); } /// /// carica metadati da template! /// /// /// protected void imgLoad_Click(object sender, ImageClickEventArgs e) { txtNomeTMD.Text = dlElencoTemplate.SelectedValue; docMetaDataSet metaDatiTemplate= WebShipUtils.mng.recuperaTemplateMedatati(utils.obj.currUserId, dlElencoTemplate.SelectedValue); // modifica vers 126: data ricezione e data doc impostate a correnti COMUNQUE metaDatiTemplate.dataDoc = DateTime.Now; metaDatiTemplate.dataRic = DateTime.Now; // salvo metadati! metaDatiDoc = metaDatiTemplate; updateVisual(); } /// /// elimina il template metadati... /// /// /// protected void imgDeleteTemplate_Click(object sender, ImageClickEventArgs e) { txtNomeTMD.Text = ""; WebShipUtils.mng.eliminaTemplateMedatati(utils.obj.currUserId, dlElencoTemplate.SelectedValue); dlElencoTemplate.DataBind(); updateVisual(); } /// /// aggiorno dataRic /// /// /// protected void txtDataRic_TextChanged(object sender, EventArgs e) { saveMetaData(); // aggiorno updateVisual(); cblTags.Focus(); } protected void imgNoLink_Click(object sender, ImageClickEventArgs e) { // inserisco commessa "empty" dell'anno string commessa = string.Format("0000-{0}", DateTime.Now.Year); tacCommesse.valore = commessa; tacCommesse.label = commessa; // aggiorno visualizzazione! updateVisual(); } } }