Exemplo n.º 1
0
        private bool EmptyFields()
        {
            if (Globals.ThisDocument.txtOggetto.Text == "" || Globals.ThisDocument.txtDescrizione.Text == "")
            {
                MessageBox.Show("Alcuni campi obbligatori non sono stati compilati. Compilare i campi evidenziati!", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Globals.ThisDocument.Application.ScreenUpdating = false;

                ThisDocument.ToNormal("Oggetto", Word.WdColorIndex.wdBlack, "*");
                ThisDocument.ToNormal("Descrizione", Word.WdColorIndex.wdBlack, "*");

                if (Globals.ThisDocument.txtOggetto.Text == "")
                {
                    ThisDocument.Highlight("Oggetto", Word.WdColorIndex.wdRed, "*");
                }

                if (Globals.ThisDocument.txtDescrizione.Text == "")
                {
                    ThisDocument.Highlight("Descrizione", Word.WdColorIndex.wdRed, "*");
                }

                Globals.ThisDocument.Application.ScreenUpdating = true;

                return(true);
            }

            Globals.ThisDocument.Application.ScreenUpdating = false;

            ThisDocument.ToNormal("Oggetto", Word.WdColorIndex.wdBlack, "*");
            ThisDocument.ToNormal("Descrizione", Word.WdColorIndex.wdBlack, "*");

            Globals.ThisDocument.Application.ScreenUpdating = true;

            return(false);
        }
Exemplo n.º 2
0
        public void btnInvia_Click(Office.IRibbonControl control)
        {
            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).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 (_chkIsDraft || MessageBox.Show("Sicuro di voler inviare il documento?", "Stampa e invia?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            Globals.ThisDocument.Application.ScreenUpdating = false;

                            ThisDocument.ToNormal("Oggetto", Word.WdColorIndex.wdBlack, "*");
                            ThisDocument.ToNormal("Descrizione", Word.WdColorIndex.wdBlack, "*");

                            Globals.ThisDocument.Application.ScreenUpdating = true;

                            _btnRefreshEnabled = !_chkIsDraft;
                            if (!_chkIsDraft)
                            {
                                _chkIsDraftEnabled = false;
                            }
                            this.ribbon.InvalidateControl("chkIsDraft");
                            this.ribbon.InvalidateControl("btnRefresh");

                            string saveName = ConfigurationManager.AppSettings["saveNameFormat"];
                            foreach (Match m in Regex.Matches(saveName, @"(\[[^\[\]]*\])"))
                            {
                                try
                                {
                                    Control c = (Control)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 (!_chkIsDraft)
                                {
                                    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.cmbStrumento.DropDownListEntries[0].Value;

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

                                ThisDocument._db.Insert("spSaveRichiestaModifica", parameters);

                                if (!_chkIsDraft)
                                {
                                    Print();
                                }
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Salvataggio non riuscito... Riprovare più tardi.", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                ThisDocument._db.CloseConnection();
            }
            else
            {
                MessageBox.Show("Salvataggio non riuscito... Riprovare più tardi.", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo 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);
            }
        }