private void SetControl(bool visiblecontrol, DataRowView drv, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)e.Item.Cells[5].FindControl("UserMeseGiorno1");
            if (visiblecontrol == false)
            {
                _UMG.Visible = false;
                return;
            }

            string funz = "ImpostaGiorni(this.value,'" + _UMG.cmbGiorni.ClientID + "')";

            _UMG.cmbMesi.Attributes.Add("onchange", funz);

            // Controllo se sono già stati impostati il giorno ed il mese

            if (drv.Row["DATA"].ToString() != "")
            {
                DateTime mese_girono = Convert.ToDateTime(drv.Row["DATA"].ToString());


                string mese   = mese_girono.Month.ToString();
                string giorno = mese_girono.Day.ToString();

                _UMG.cmbMesi.SelectedValue = mese;

                //Richiamo la funzione che imposta i giorni del mese in esame
                ImpostaGiorni(mese, _UMG.cmbGiorni);

                _UMG.cmbGiorni.SelectedValue = giorno;
            }
            else
            {
                ImpostaGiorni(_UMG.cmbMesi.SelectedValue, _UMG.cmbGiorni);
            }
        }
        private void GetDati(DataGrid Ctrl)
        {
            Hashtable _HS = null;

            if (Session["DatiListP"] != null)
            {
                _HS = (Hashtable)Session["DatiListP"];
            }
            else
            {
                return;
            }

            foreach (DataGridItem o_Litem in Ctrl.Items)
            {
                string id = o_Litem.Cells[5].Text;

                if (_HS.ContainsKey(id))
                {
                    DettailList _campi = (DettailList)_HS[id];
                    WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)o_Litem.Cells[3].FindControl("UserMeseGiorno1");

                    _UMG.cmbMesi.SelectedValue = _campi.Mese;

                    //Richiamo la funzione che imposta i giorni del mese in esame
                    ImpostaGiorni(_campi.Mese, _UMG.cmbGiorni);

                    _UMG.cmbGiorni.SelectedValue = _campi.Giorno;
                }
            }                   //end for
        }
        private void SetDati()
        {
            Hashtable _HS = new Hashtable();

            if (Session["DatiList"] != null)
            {
                _HS = (Hashtable)Session["DatiList"];
            }


            foreach (DataGridItem o_Litem in DataGridRicerca.Items)
            {
                DataGridField _campi = new DataGridField();

                _campi.idbl = Int32.Parse(o_Litem.Cells[2].Text);

                System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)o_Litem.Cells[1].FindControl("ChkSel");

                if (_HS.ContainsKey(_campi.idbl))
                {
                    _HS.Remove(_campi.idbl);
                }

                System.Web.UI.WebControls.Label lbl = (System.Web.UI.WebControls.Label)o_Litem.Cells[7].FindControl("LblAddetto");

                if (cb.Checked)
                {
                    _campi.idditta    = Int32.Parse(o_Litem.Cells[3].Text);
                    _campi.idservizio = Int32.Parse(o_Litem.Cells[5].Text);

                    WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)o_Litem.Cells[9].FindControl("UserMeseGiorno1");

                    //Imposto tutti i combo delle date del datagrid con la data impostata
                    if (chkAbilitaData.Checked)
                    {
                        _UMG.cmbMesi.SelectedValue = UserMeseGiorno2.cmbMesi.SelectedValue;
                        ImpostaGiorni(_UMG.cmbMesi.SelectedValue, _UMG.cmbGiorni);
                        _UMG.cmbGiorni.SelectedValue = UserMeseGiorno2.cmbGiorni.SelectedValue;
                    }

                    lbl.Text = cmbsAddettoMod.SelectedItem.Text;

                    _campi.mesegiorno = _UMG.cmbMesi.SelectedValue.PadLeft(2, Convert.ToChar("0")) + _UMG.cmbGiorni.SelectedValue.PadLeft(2, Convert.ToChar("0"));
                    _campi.idaddetto  = Int32.Parse(cmbsAddettoMod.SelectedValue);
                    _HS.Add(_campi.idbl, _campi);
                }

                else
                {
                    //Re-Imposto il valore di Default
                    lbl.Text = o_Litem.Cells[10].Text;
                }
            }

            Session.Remove("DatiList");
            Session.Add("DatiList", _HS);
            LblElementiSelezionati.Text = "Elementi Selezionati - " + _HS.Count.ToString() + " -";
            txtTotSelezionati.Text      = _HS.Count.ToString();
        }
        private void DataGridRicerca_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)(e.Item.DataItem);

                SetControl(true, drv, e);
                WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)e.Item.Cells[5].FindControl("UserMeseGiorno1");
                _UMG.cmbGiorni.Enabled = false;
                _UMG.cmbMesi.Enabled   = false;
                DropDownList dropd = (DropDownList)e.Item.Cells[7].Controls[1];
                foreach (DataRow Dr in DtAddetti.Rows)
                {
                    dropd.Items.Add(new ListItem(Dr["nome"].ToString() + " " + Dr["cognome"].ToString(), Dr["ID"].ToString()));
                }

                dropd.SelectedValue = drv.Row["ADDETTO_ID"].ToString();
            }
        }
        private void DataGridRicerca_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) ||
                (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                //Imposto la funzione client per caricare i giorno a tutti i combi del mese
                WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)e.Item.Cells[9].FindControl("UserMeseGiorno1");
                string funz = "ImpostaGiorni(this.value,'" + _UMG.cmbGiorni.ClientID + "')";
                _UMG.cmbMesi.Attributes.Add("onchange", funz);

                // Controllo se sono già stati impostati il giorno ed il mese
                string mese_girono = e.Item.Cells[8].Text;
                if (HttpUtility.HtmlDecode(mese_girono).Trim() != "")
                {
                    string mese   = mese_girono.Substring(0, 2);
                    string giorno = mese_girono.Substring(2, 2);

                    mese   = Int16.Parse(mese).ToString();
                    giorno = Int16.Parse(giorno).ToString();

                    _UMG.cmbMesi.SelectedValue = mese;

                    //Richiamo la funzione che imposta i giorni del mese in esame
                    ImpostaGiorni(mese, _UMG.cmbGiorni);

                    _UMG.cmbGiorni.SelectedValue = giorno;
                }
                else
                {
                    ImpostaGiorni(_UMG.cmbMesi.SelectedValue, _UMG.cmbGiorni);
                }

                // Controllo se sono già stato impostato l'addetto
                string addetto = e.Item.Cells[10].Text;
                if (HttpUtility.HtmlDecode(addetto).Trim() != "")
                {
                    Label lbladdetto = (Label)e.Item.Cells[7].FindControl("LblAddetto");
                    lbladdetto.Text = addetto;
                }
            }
        }
        private void SaveDati(DataGrid Ctrl)
        {
            Hashtable _HS = null;

            if (Session["DatiListP"] != null)
            {
                _HS = (Hashtable)Session["DatiListP"];
            }
            else
            {
                _HS = new Hashtable();
            }


            foreach (DataGridItem o_Litem in Ctrl.Items)
            {
                string id = o_Litem.Cells[5].Text;

                if (_HS.ContainsKey(id))
                {
                    _HS.Remove(id);
                }

                if (this.e_Page == "ottimizza")
                {
                    DettailList _campi = new DettailList();
                    WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)o_Litem.Cells[3].FindControl("UserMeseGiorno1");

                    _campi.id     = id;
                    _campi.Mese   = _UMG.cmbMesi.SelectedValue;
                    _campi.Giorno = _UMG.cmbGiorni.SelectedValue;
                    _HS.Add(_campi.id, _campi);
                }
            }                   //end for

            Session.Remove("DatiListP");
            Session.Add("DatiListP", _HS);
        }
        private void DataGridRicerca_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Dettaglio")
            {
                foreach (DataGridItem cella in DataGridRicerca.Items)
                {
                    ImageButton a = (ImageButton)cella.Cells[0].Controls[0].FindControl("lnkDett");
                    a.Visible = false;

                    DataGridRicerca.Columns[1].Visible = true;
                    ImageButton lnkAnn = (ImageButton)cella.Cells[1].Controls[0].FindControl("lnkAnn");
                    lnkAnn.Visible = false;

                    WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)e.Item.Cells[5].FindControl("UserMeseGiorno1");
                    _UMG.cmbGiorni.Enabled = true;
                    _UMG.cmbMesi.Enabled   = true;
                    txtOldDD.Text          = _UMG.cmbGiorni.SelectedValue;
                    txtOldMM.Text          = _UMG.cmbMesi.SelectedValue;
                }

                ImageButton buttannulla = (ImageButton)e.Item.Cells[0].Controls[0].FindControl("lnkAnn");
                buttannulla.Visible  = true;
                buttannulla.ImageUrl = "../../images/annulla.gif";

                ImageButton butt = (ImageButton)e.Item.Cells[0].Controls[0].FindControl("lnkDett");
                butt.Visible     = true;
                butt.ImageUrl    = "../../images/salva.gif";
                butt.CommandName = "Aggiorna";

                DropDownList ddl = (DropDownList)e.Item.Cells[7].Controls[0].FindControl("cmdAddetto");
                ddl.Enabled        = true;
                txtOldAddetto.Text = ddl.SelectedValue;
            }
            else if (e.CommandName == "Aggiorna")
            {
                foreach (DataGridItem cella in DataGridRicerca.Items)
                {
                    ImageButton a = (ImageButton)cella.Cells[0].Controls[0].FindControl("lnkDett");
                    a.Visible = true;
                    WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)e.Item.Cells[5].FindControl("UserMeseGiorno1");
                    _UMG.cmbGiorni.Enabled = false;
                    _UMG.cmbMesi.Enabled   = false;
                }

                DataGridRicerca.Columns[1].Visible = false;

                DropDownList ddl = (DropDownList)e.Item.Cells[7].Controls[0].FindControl("cmdAddetto");
                ddl.Enabled = false;

                ImageButton butt = (ImageButton)e.Item.Cells[0].Controls[0].FindControl("lnkDett");
                butt.ImageUrl    = "../../images/edit.gif";
                butt.CommandName = "Dettaglio";

                WebControls.UserMeseGiorno _UMG_UP = (WebControls.UserMeseGiorno)e.Item.Cells[5].FindControl("UserMeseGiorno1");

                string pmsd            = e.Item.Cells[6].Text;
                string addetto         = ddl.SelectedValue;
                string data            = _UMG_UP.cmbGiorni.SelectedValue + "/" + _UMG_UP.cmbMesi.SelectedValue + "/" + txtAnno.Text;
                string edificio        = txtId_bl.Text;
                string anno            = txtAnno.Text;
                string apparecchiatura = txtEQ.Text;

                txtOldDD.Text      = "";
                txtOldMM.Text      = "";
                txtOldAddetto.Text = "";

                int esito = Ottimizza(pmsd, addetto, data, edificio, anno, apparecchiatura);
            }

            else
            {
                foreach (DataGridItem cella in DataGridRicerca.Items)
                {
                    ImageButton a = (ImageButton)cella.Cells[0].Controls[0].FindControl("lnkDett");
                    a.Visible = true;
                    WebControls.UserMeseGiorno _UMG = (WebControls.UserMeseGiorno)e.Item.Cells[5].FindControl("UserMeseGiorno1");
                    _UMG.cmbGiorni.Enabled       = false;
                    _UMG.cmbMesi.Enabled         = false;
                    _UMG.cmbMesi.SelectedValue   = txtOldMM.Text;
                    _UMG.cmbGiorni.SelectedValue = txtOldDD.Text;
                }

                DataGridRicerca.Columns[1].Visible = false;

                DropDownList ddl = (DropDownList)e.Item.Cells[7].Controls[0].FindControl("cmdAddetto");
                ddl.Enabled = false;

                ddl.SelectedValue = txtOldAddetto.Text;

                ImageButton butt = (ImageButton)e.Item.Cells[0].Controls[0].FindControl("lnkDett");
                butt.ImageUrl    = "../../images/edit.gif";
                butt.CommandName = "Dettaglio";
            }
        }