Exemple #1
0
        private void FormBilanciamento_Shown(object sender, EventArgs e)
        {
            if (dgvBilanciamento.DataSource != null)
            {
                for (int i = 0; i < dgvBilanciamento.Rows.Count; i++)
                {
                    DataGridViewComboBoxCell cellCombo = new DataGridViewComboBoxCell();

                    string siglaEntita = dgvBilanciamento["SiglaEntita", i].Value.ToString();
                    string siglaInfo   = _dtEntitaGradinoDisp.AsEnumerable()
                                         .Where(r => r["SiglaEntita"].Equals(siglaEntita))
                                         .Select(r => r[1].ToString())
                                         .FirstOrDefault();

                    DefinedNames df = _categoriaNomiDefiniti[dgvBilanciamento["SiglaCategoria", i].Value.ToString()];

                    Dictionary <string, int> gt = OfferteMIHelper.GetGOTODictionary(siglaEntita, siglaInfo, df);

                    if (gt != null)
                    {
                        cellCombo.DataSource    = new BindingSource(gt, null);
                        cellCombo.ValueMember   = "Value";
                        cellCombo.DisplayMember = "Key";
                        dgvBilanciamento[1, i]  = cellCombo;
                    }

                    // seleziono il primo valore della combo
                    //dgvBilanciamento[1, i].Selected = true;
                    //dgvBilanciamento[1, i].Value = gt.First().Key;
                }
            }
        }
Exemple #2
0
        private void ChangeSelectionToIncrement(Excel.Range Target)
        {
            // Descrizione Combo / Riga Calcolo
            //offerta_dictionary = new Dictionary<string, int>();
            // SiglaInformazione riga selezionata / SiglaInformazione riga calcolo
            //calcolo_dictionary = new Dictionary<string, string>();

            _gotoDictionary = new Dictionary <string, int>();

            btnApplica.Enabled = false;

            comboBox_VaiA.DataSource     = null;
            comboBox_applicaA.DataSource = null;

            groupQuantità.Visible = false;
            groupPrezzo.Visible   = false;

            lbErrore.Text       = "";
            lbErrore.ForeColor  = Color.Red;
            btnApplica.Enabled  = false;
            _selectionIsCorrect = false;

            if (Target.Rows.Count > 1)
            {
                foreach (Excel.Range row in Target.Rows)
                {
                    if (row.EntireRow.Hidden)
                    {
                        lbErrore.Text = "ERRORE: Nel range selezionato ci sono righe nascoste.";
                        return;
                    }
                }
                lbErrore.ForeColor = Color.DarkOrange;
                lbErrore.Text      = "ATTENZIONE: Nel range selezionato ci sono più righe.";
            }
            foreach (Excel.Range row in Target.Rows)
            {
                if (!_definedNames.IsEditable(row.Row))
                {
                    lbErrore.Text = "ERRORE: Il range selezionato contiene delle righe non modificabili.";
                    return;
                }
            }

            int firstCol = _definedNames.GetFirstCol();

            if (Target.Column < firstCol + Simboli.GetMarketOffsetMI(Workbook.Mercato, Workbook.DataAttiva))
            {
                lbErrore.Text = "ERRORE: Il range selezionato contiene celle appartenenti a mercati chiusi.";
                return;
            }

            /* Controllo se la riga selezionata è corretta per l'operazione richiesta */
            string name_col_row_selected = _definedNames.GetNameByRow(Target.Row).FirstOrDefault();
            string siglaEntita           = name_col_row_selected.Split('.').First();
            string siglaInformazione     = name_col_row_selected.Split('.').Last();

            is_price    = is_Name_Match_Price(name_col_row_selected);
            is_quantity = is_Name_Match_Quantity(name_col_row_selected);

            //DataView definizioneOfferta = Workbook.Repository[DataBase.TAB.DEFINIZIONE_OFFERTA].DefaultView;

            //definizioneOfferta.RowFilter = "SiglaEntita ='" + siglaEntita + "' AND SiglaInformazione = '" + siglaInformazione + "' AND IdMercato = " + Workbook.Mercato.Substring(2, Workbook.Mercato.Length - 2);

            //if (definizioneOfferta.Count == 0)
            //{
            //    lbErrore.Text = "ERRORE: Non ci sono opzioni attive per questa funzione.";
            //    return;
            //}

            //DataView informazioni = Workbook.Repository[DataBase.TAB.ENTITA_INFORMAZIONE].DefaultView;

            //DataTable entitaInformazione = Workbook.Repository[DataBase.TAB.ENTITA_INFORMAZIONE];

            //foreach (DataRowView offerta in definizioneOfferta)
            //{
            //    string desInformazioneCombo = entitaInformazione.AsEnumerable()
            //        .Where(r => r["SiglaEntita"].Equals(offerta["SiglaEntita"])
            //                 && (r["SiglaEntitaRif"] is DBNull || r["SiglaEntitaRif"].Equals(offerta["SiglaEntitaCombo"]))
            //                 && r["SiglaInformazione"].Equals(offerta["SiglaInformazioneCombo"]))
            //        .Select(r => r["DesInformazione"].ToString())
            //        .FirstOrDefault();

            //    object entitaCalcolo = offerta["SiglaEntitaCalcolo"] is DBNull ? offerta["SiglaEntitaCombo"] : offerta["SiglaEntitaCalcolo"];
            //    object infoCalcolo = offerta["SiglaInformazioneCalcolo"] is DBNull ? offerta["SiglaInformazioneCombo"] : offerta["SiglaInformazioneCalcolo"];

            //    _gotoDictionary.Add(desInformazioneCombo, _definedNames.GetRowByName(entitaCalcolo, infoCalcolo));
            //}

            _gotoDictionary = OfferteMIHelper.GetGOTODictionary(siglaEntita, siglaInformazione, _definedNames);

            if (_gotoDictionary == null)
            {
                lbErrore.Text = "ERRORE: Non ci sono opzioni attive per questa funzione.";
                return;
            }

            if (is_price)
            {
                groupQuantità.Visible = false;
                groupPrezzo.Visible   = true;

                comboBox_applicaA.DataSource    = new BindingSource(_gotoDictionary, null);
                comboBox_applicaA.ValueMember   = "Value";
                comboBox_applicaA.DisplayMember = "Key";
                comboBox_applicaA.SelectedIndex = -1;
            }
            else if (is_quantity)
            {
                groupQuantità.Visible = true;
                groupPrezzo.Visible   = false;

                comboBox_VaiA.DataSource    = new BindingSource(_gotoDictionary, null);
                comboBox_VaiA.ValueMember   = "Value";
                comboBox_VaiA.DisplayMember = "Key";
                comboBox_VaiA.SelectedIndex = -1;
            }
            else
            {
                lbErrore.Text = "ERRORE: Il range selezionato non si riferisce a quantità o prezzi.";
                return;
            }

            _selectionIsCorrect = true;

            if (_valuesAreCorrect)
            {
                btnApplica.Enabled = true;
            }

            btnRipristina.Enabled = false;

            _origRng = Target;

            Handler.SaveOriginValues(Target, tableName: ALL_OLD_VALUE);
            if (is_price)
            {
                Excel.Range rng = _ws.Range[_ws.Cells[Target.Row - 2, Target.Column], _ws.Cells[Target.Row - 2, Target.Column + Target.Columns.Count - 1]];
                Handler.SaveOriginValues(rng, tableName: ALL_OLD_VALUE);
            }
            if (is_quantity)
            {
                Excel.Range rng = _ws.Range[_ws.Cells[Target.Row - 1, Target.Column], _ws.Cells[Target.Row - 1, Target.Column + Target.Columns.Count - 1]];
                Handler.SaveOriginValues(rng, tableName: ALL_OLD_VALUE);
            }
        }