Ejemplo n.º 1
0
        private bool CutContent(Microsoft.Office.Tools.Word.RichTextContentControl ctrl)
        {
            int length = 0;

            if (ctrl.Equals(Globals.ThisDocument.txtDescrizione))
            {
                length = ThisDocument.DESCRIZIONE_MAX_LEN;
            }
            else if (ctrl.Equals(Globals.ThisDocument.txtNote))
            {
                length = ThisDocument.NOTE_MAX_LEN;
            }
            else if (ctrl.Equals(Globals.ThisDocument.txtOggetto))
            {
                length = ThisDocument.OGGETTO_MAX_LEN;
            }

            if (ctrl.Text.Length > length)
            {
                if (!_originalControlText.ContainsKey(ctrl.ID))
                {
                    _originalControlText.Add(ctrl.ID, ctrl.Text);
                }
                else
                {
                    _originalControlText[ctrl.ID] = ctrl.Text;
                }

                ctrl.Text = ctrl.Text.Substring(0, Math.Min(ctrl.Text.Length, length));

                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void UncutContent(Microsoft.Office.Tools.Word.RichTextContentControl ctrl)
        {
            ctrl.Text = _originalControlText[ctrl.ID];

            int length = 0;

            if (ctrl.Equals(Globals.ThisDocument.txtDescrizione))
            {
                length = ThisDocument.DESCRIZIONE_MAX_LEN;
            }
            else if (ctrl.Equals(Globals.ThisDocument.txtNote))
            {
                length = ThisDocument.NOTE_MAX_LEN;
            }
            else if (ctrl.Equals(Globals.ThisDocument.txtOggetto))
            {
                length = ThisDocument.OGGETTO_MAX_LEN;
            }

            Globals.ThisDocument.FormatTextOverDimension(ctrl, length, ctrl.Text.Length > length);
        }
Ejemplo n.º 3
0
        private void btnInvia_Click(object sender, RibbonControlEventArgs e)
        {
            object oTrue   = true;
            object oFalse  = false;
            object missing = Missing.Value;

            if (ThisDocument.DB.OpenConnection())
            {
                DataView dv = (ThisDocument.DB.Select("spGetRichiesta", "@IdRichiesta=" + Globals.ThisDocument.lbIdRichiesta.Text + ";@IdStruttura=" + ThisDocument._idStruttura) ?? new DataTable()).DefaultView;
                dv.RowFilter = "IdTipologiaStato <> 7";
                if (dv.Count > 0)
                {
                    MessageBox.Show("Esiste già una richiesta con lo stesso codice. Premere sul tasto di refresh per ottenerne uno nuovo", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (!EmptyFields())
                    {
                        if (isBozza || MessageBox.Show("Sicuro di voler inviare il documento?", "Stampa e invia?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            Globals.ThisDocument.Application.ScreenUpdating = false;

                            ThisDocument.ToNormal(Globals.ThisDocument.lbOggetto);
                            ThisDocument.ToNormal(Globals.ThisDocument.lbDescrizione);

                            Globals.ThisDocument.Application.ScreenUpdating = true;

                            btnRefresh.Enabled = !isBozza;
                            if (!isBozza)
                            {
                                chkIsDraft.Enabled = false;
                            }

                            string saveName = ConfigurationManager.AppSettings["saveNameFormat"];
                            foreach (Match m in Regex.Matches(saveName, @"(\[[^\[\]]*\])"))
                            {
                                try
                                {
                                    Microsoft.Office.Tools.Word.RichTextContentControl c =
                                        (Microsoft.Office.Tools.Word.RichTextContentControl)Globals.ThisDocument.Controls[m.Value.Replace("[", "").Replace("]", "")];
                                    saveName = saveName.Replace(m.Value, c.Text);
                                }
                                catch (ArgumentOutOfRangeException)
                                {
                                }
                            }
                            string name     = Regex.Replace(saveName, @"([^\.\-_a-zA-Z0-9]+)", "_");
                            object savePath = Path.Combine(ConfigurationManager.AppSettings["savePath"], name + ".pdf");
                            object format   = Word.WdSaveFormat.wdFormatPDF;
                            try
                            {
                                if (!isBozza)
                                {
                                    Globals.ThisDocument.SaveAs2(ref savePath, ref format, ref oTrue, ref missing, ref oFalse,
                                                                 ref missing, ref oFalse, ref missing, ref missing, ref oFalse, ref oFalse, ref missing,
                                                                 ref missing, ref missing, ref missing, ref missing, ref missing);
                                }

                                DateTime dataInvio = DateTime.Parse(Globals.ThisDocument.lbDataInvio.Text);
                                //string idApplicazione = Globals.ThisDocument.dropDownStrumenti.DropDownListEntries[1].Value;
                                string idApplicazione = Globals.ThisDocument.dropDownStrumenti.DropDownListEntries.OfType <Microsoft.Office.Interop.Word.ContentControlListEntry>().First(c => c.Text == Globals.ThisDocument.dropDownStrumenti.Text).Value;

                                ThisDocument.DB.Insert("spSaveRichiestaModifica", new QryParams()
                                {
                                    { "@IdRichiesta", Globals.ThisDocument.lbIdRichiesta.Text },
                                    { "@IdStruttura", ThisDocument._idStruttura },
                                    { "@DataInvio", dataInvio.ToString("yyyyMMdd") },
                                    { "@IdTipologiaStato", isBozza ? 7:1 },
                                    { "@IdApplicazione", idApplicazione },
                                    { "@Oggetto", Globals.ThisDocument.txtOggetto.Text.Trim() },
                                    { "@Descr", Globals.ThisDocument.txtDescrizione.Text.Trim() },
                                    { "@Note", Globals.ThisDocument.txtNote.Text.Trim() },
                                    { "@NomeFile", savePath }
                                });

                                if (!isBozza)
                                {
                                    MessageBox.Show("Richiesta presa in carico!", "Perfetto!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Bozza salvata!", "Perfetto!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }

                                if (!isBozza)
                                {
                                    Print();
                                }
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Salvataggio non riuscito... Riprovare più tardi.", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                ThisDocument.DB.CloseConnection();
            }
            else
            {
                MessageBox.Show("Errore nella connessione al DB... Riprovare più tardi.", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }