Beispiel #1
0
        //private void ToListing(string dataTable, string listType, string filter) {
        //    MetaData MElenco = MetaData.GetMetaData(this, dataTable);
        //    int rowsfound = Conn.RUN_SELECT_COUNT(dataTable, filter, true);
        //    if (rowsfound == 0) {
        //        MessageBox.Show("Nessun elemento trovato");
        //        return;
        //    }

        //    if (MElenco == null) return;
        //    MElenco.ContextFilter = filter;
        //    bool result = MElenco.Edit(Meta.LinkedForm.ParentForm, "default", false);
        //    DataRow R = MElenco.SelectOne(listType, filter, null, null);
        //    if (R != null) MElenco.SelectRow(R, listType);
        //}

        private void ToCsv(DataTable T)
        {
            if (T.Rows.Count == 0)
            {
                MessageBox.Show("Nessun elemento trovato");
                return;
            }
            OpenFileDialog FD = new OpenFileDialog();

            FD.Title           = "Seleziona il file CSV da creare";
            FD.AddExtension    = true;
            FD.DefaultExt      = "CSV";
            FD.CheckFileExists = false;
            FD.CheckPathExists = true;
            FD.Multiselect     = false;
            DialogResult DR = FD.ShowDialog();

            if (DR != DialogResult.OK)
            {
                MessageBox.Show("Non è stata scelta la destinazione");
                return;
            }

            try {
                exportclass.dataTableToCommaSeparatedValues(T, true, FD.FileName);
                Process.Start(FD.FileName);
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
            }
        }
Beispiel #2
0
        private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            if (errore)
            {
                return;
            }
            switch (e.Button.Tag.ToString().ToLower())
            {
            case "first":
                crViewer.ShowFirstPage();
                break;

            case "prev":
                crViewer.ShowPreviousPage();
                break;

            case "next":
                crViewer.ShowNextPage();
                break;

            case "last":
                crViewer.ShowLastPage();
                break;

            case "print":
                StampaReport();
                break;

            case "tree":
                if (tbTree.Pushed)
                {
                    crViewer.ToolPanelView = ToolPanelViewType.GroupTree;
                }
                else
                {
                    crViewer.ToolPanelView = ToolPanelViewType.None;
                }
                break;

            case "export":
                if (oneprint)
                {
                    MessageBox.Show("L'esportazione è vietata sulle stampe protette");
                    return;
                }
                try {
                    crViewer.ExportReport();
                }
                catch (Exception E) {
                    errore = true;
                    meta.LogError("Errore esportando una stampa " + elencoparametri, E);
                    QueryCreator.ShowException("Errore esportando la stampa", E);
                }
                break;
            }
        }
Beispiel #3
0
 public void MetaData_AfterClear()
 {
     labExe.Text += sw;
     try {
         Process.Start(sw);
     }
     catch (Exception E) {
         QueryCreator.ShowException(E);
     }
     activated = true;
 }
Beispiel #4
0
        private void btnAllega_Click(object sender, EventArgs e)
        {
            if (Meta.IsEmpty)
            {
                return;
            }
            DataRow Curr = DS.mandateattachment.Rows[0];

            openFileDialog1.Title = "Seleziona l'allegato";
            try {
                if (openFileDialog1.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
                return;
            }
            FileStream FS;

            try {
                FS = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            }
            catch (Exception E) {
                QueryCreator.ShowException("Errore nell'apertura del file " + openFileDialog1.FileName, E);
                return;
            }

            int n = (int)FS.Length;

            if (n == 0)
            {
                Curr["attachment"] = DBNull.Value;
                return;
            }
            byte[] ByteArray = new byte[n];
            FS.Read(ByteArray, 0, n);
            if (FS.Length == 0)
            {
                Curr["attachment"] = DBNull.Value;
            }
            FS.Close();
            Curr["attachment"] = ByteArray;
            string fname = Path.GetFileName(openFileDialog1.FileName);

            labAutocertFileName.Text = fname;
            Curr["filename"]         = fname;
        }
Beispiel #5
0
 private void FrmViewReport_Load(object sender, System.EventArgs e)
 {
     try {
         ReportPages = 0;
         ReportPageRequestContext oPageContext = new ReportPageRequestContext();
         ReportPages = ReportDoc.FormatEngine.GetLastPageNumber(oPageContext);
         AbilitaPageNavigator(ReportPages > 1);
     }
     catch (Exception E) {
         meta.LogError("Errore nel calcolo della stampa con i parametri:\r\n" + elencoparametri, E);
         QueryCreator.ShowException("Errore nel calcolo della stampa", E);
         AbilitaPageNavigator(false);
         errore = true;
     }
     isInited = true;
 }
Beispiel #6
0
        public long leggiLong(TextReader tr, int numCifre)
        {
            if (tr.Read(buffer, 0, numCifre) != numCifre)
            {
                QueryCreator.ShowError(form, "ERRORE DURANTE LA LETTURA DEL FILE", "Letti meno byte rispetto al previsto");
            }
            string s = new string(buffer, 0, numCifre);

            try {
                return(long.Parse(s));
            }
            catch (Exception e) {
                QueryCreator.ShowException(form, "ERRORE DURANTE LA LETTURA DI UN LONG DAL FILE\r\n" + s, e);
            }
            return(0);
        }
Beispiel #7
0
 int NumberFromExcelColumn(string column)
 {
     try {
         int    retVal = 0;
         string col    = column.ToUpper();
         for (int iChar = col.Length - 1; iChar >= 0; iChar--)
         {
             char colPiece = col[iChar];
             int  colNum   = colPiece - 64;
             retVal = retVal + colNum * (int)Math.Pow(26, col.Length - (iChar + 1));
         }
         return(retVal);
     }
     catch (Exception E) {
         QueryCreator.ShowException(this, "Errore convertendo numero un riferimento a colonna", E);
         return(20);
     }
 }
Beispiel #8
0
        private void VisualizzaAllegato(string certification)
        {
            if (Meta.IsEmpty)
            {
                return;
            }
            string FilePath         = AppDomain.CurrentDomain.BaseDirectory;
            string prefix           = "SWMOREDURC";
            string filenametodelete = FilePath + prefix + "*.*";

            string[] existingreports = System.IO.Directory.GetFiles(FilePath, prefix + "*.*");
            foreach (string filename in existingreports)
            {
                try{
                    System.IO.File.Delete(filename);
                }
                catch
                { }
            }

            //sw è il nome del file temporaneo che hai creato
            DateTime oggi_dt = DateTime.Now;
            string   oggi    = oggi_dt.Ticks.ToString();

            DataRow Curr = DS.registrydurc.Rows[0];

            byte[] ByteArray  = (byte[])Curr[certification];
            int    offset     = GetOffsetForData(ByteArray);
            string fname      = GetFileName(ByteArray);
            string estensione = Path.GetExtension(fname).Trim();;

            string sw = Path.Combine(FilePath, prefix + oggi.ToString() + estensione);

            try
            {
                ScriviFile(sw, ByteArray, offset);

                System.Diagnostics.Process.Start(sw);
            }
            catch (Exception E)
            {
                QueryCreator.ShowException(E);
            }
        }
Beispiel #9
0
        public object leggiDataAMG(TextReader tr, int numCifre)
        {
            if (tr.Read(buffer, 0, numCifre) != numCifre)
            {
                QueryCreator.ShowError(form, "ERRORE DURANTE LA LETTURA DEL FILE", "Letti meno byte rispetto al previsto");
            }
            string s = new string(buffer, 0, numCifre);

            try {
                return((object)DateTime.ParseExact(s, "yyyyMMdd", DateTimeFormatInfo.CurrentInfo));
            }
            catch (Exception e) {
                if (new string(buffer, 0, numCifre) != "".PadRight(numCifre, '0'))
                {
                    QueryCreator.ShowException(form, "ERRORE DURANTE LA LETTURA DEL FILE: DATA AMG\r\n" + s, e);
                }
                return(DBNull.Value);
            }
        }
Beispiel #10
0
 string ExcelColumnFromNumber(int column)
 {
     try {
         string columnString = "";
         int    columnNumber = column;
         while (columnNumber > 0)
         {
             int  currentLetterNumber = (columnNumber - 1) % 26;
             char currentLetter       = (char)(currentLetterNumber + 65);
             columnString = currentLetter + columnString;
             columnNumber = (columnNumber - (currentLetterNumber + 1)) / 26;
         }
         return(columnString);
     }
     catch (Exception E) {
         QueryCreator.ShowException(this, "Errore convertendo in riferimento a colonna un numero", E);
         return("Z");
     }
 }
Beispiel #11
0
        public int leggiNumerico(TextReader tr, int numCifre)
        {
            if (tr.Read(buffer, 0, numCifre) != numCifre)
            {
                QueryCreator.ShowError(null, "ERRORE DURANTE LA LETTURA DEL FILE", "Letti meno byte rispetto al previsto");
            }
            string s = new string(buffer, 0, numCifre);

            try {
                return(int.Parse(s));
            }
            catch (Exception e) {
                string spazi = "".PadRight(numCifre);
                if (s != spazi)
                {
                    QueryCreator.ShowException(null, "ERRORE DURANTE LA LETTURA DI UN NUMERICO DAL FILE\r\n" + s, e);
                }
                return(0);
            }
        }
Beispiel #12
0
 public object leggiDataGMA(TextReader tr, int numCifre)
 {
     if (tr.Read(buffer, 0, numCifre) != numCifre)
     {
         QueryCreator.ShowError(form, "ERRORE DURANTE LA LETTURA DEL FILE", "Letti meno byte rispetto al previsto");
     }
     try {
         return((object)DateTime.ParseExact(new string(buffer, 0, numCifre), "ddMMyyyy", DateTimeFormatInfo.CurrentInfo));
     }
     catch (Exception e) {
         string s     = new string(buffer, 0, numCifre);
         string zeri  = "".PadRight(numCifre, '0');
         string spazi = "".PadRight(numCifre, ' ');
         if ((s != zeri) && (s != spazi))
         {
             QueryCreator.ShowException(form, "ERRORE DURANTE LA LETTURA DEL FILE: DATA GMA", e);
         }
         return(DBNull.Value);
     }
 }
Beispiel #13
0
        private void btnVisualizza_Click(object sender, EventArgs e)
        {
            string FilePath         = AppDomain.CurrentDomain.BaseDirectory;
            string prefix           = "SWATTACHMENT";
            string filenametodelete = FilePath + prefix + "*.*";

            string[] existingreports = System.IO.Directory.GetFiles(FilePath, prefix + "*.*");
            foreach (string filename in existingreports)
            {
                try {
                    System.IO.File.Delete(filename);
                }
                catch { }
            }

            //sw è il nome del file temporaneo che hai creato
            DateTime oggi_dt = DateTime.Now;
            string   oggi    = oggi_dt.Ticks.ToString();
            DataRow  Curr    = DS.mandateattachment.Rows[0];

            if (Curr["attachment"] == DBNull.Value)
            {
                return;
            }

            byte[] ByteArray  = (byte[])Curr["attachment"];
            int    offset     = 0;
            string fname      = Curr["filename"].ToString();
            string estensione = Path.GetExtension(fname).Trim();

            string sw = Path.Combine(FilePath, prefix + oggi.ToString() + estensione);

            try {
                ScriviFile(sw, ByteArray, offset);

                System.Diagnostics.Process.Start(sw);
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
            }
        }
Beispiel #14
0
        public virtual bool CopyTable(DataAccess Source, DataAccess Dest, CopyContext Ctx, CopyDisplay CD)
        {
            int count = 0;

            QueryHelper QHS = Dest.GetQueryHelper();

            try {
                DataTable Cols = Dest.SQLRunner("sp_columns " + table + ",'" + Dest.GetSys("userdb").ToString() + "'");
                if (Cols.Rows.Count == 0)
                {
                    Cols = Dest.SQLRunner("sp_columns " + table + ",'dbo'");
                }

                if (ClearDestAtStart)
                {
                    Dest.SQLRunner("DELETE FROM " + table);
                }

                if (dontCopy)
                {
                    CD.Comment("Table " + table + " skipped");
                    applied = true;
                    return(true);
                }

                if (skipIfNotEmpty)
                {
                    if (Dest.RUN_SELECT_COUNT(table, null, false) > 0)
                    {
                        CD.Comment("Table " + table + " skipped cause destination is not empty");
                        applied = true;
                        return(true);
                    }
                }

                Comment(Dest, Ctx, CD);
                int not_to_copy = 0;
                int nullskipped = 0;

                int nrows = Source.RUN_SELECT_COUNT(table, filter, false);
                CD.Start(filter == null? table: table + " where " + filter, "copy", nrows);

                string    insert = "INSERT INTO " + table + " VALUES(";//(
                string    s      = "";
                string    err;
                DataTable T   = Dest.CreateTableByName(table, "*");
                string    col = QueryCreator.ColumnNameList(T);


                DataAccess.DataRowReader DRR = new DataAccess.DataRowReader(Source, table, col, null, filter);
                foreach (DataRow row in DRR)
                {
                    CD.Update(1);
                    if (!IsToCopy(row))
                    {
                        not_to_copy++; continue;
                    }
                    if (SkipExtNulls(row, Ctx))
                    {
                        nullskipped++; continue;
                    }

                    Translate(Ctx, row);

                    if (skipduplicates)
                    {
                        int num = Dest.RUN_SELECT_COUNT(table, QHS.CmpKey(row), false);
                        if (num > 0)
                        {
                            continue;
                        }
                    }


                    count++;
                    string values = GetSQLDataValues(row, Cols);
                    s += insert + values;
                    if (count == 10)
                    {
                        Dest.SQLRunner(s, 0, out err);

                        if (err != null)
                        {
                            QueryCreator.ShowError(null, "Errore", err);
                            StreamWriter fsw = new StreamWriter("temp.sql", false, Encoding.Default);
                            fsw.Write(s.ToString());
                            fsw.Close();
                            MessageBox.Show("Errore durante la copia della tabella " + table + "\r\nLo script lanciato si trova nel file 'temp.sql'");
                            CD.Stop(false);
                            return(false);
                        }
                        s     = "";
                        count = 0;
                    }
                }
                if (s != "")
                {
                    Dest.SQLRunner(s, 0, out err);
                    count = 0;
                    if (err != null)
                    {
                        QueryCreator.ShowError(null, "Errore", err);
                        StreamWriter fsw = new StreamWriter("temp.sql", false, Encoding.Default);
                        fsw.Write(s.ToString());
                        fsw.Close();
                        MessageBox.Show("Errore durante la copia di " + table + "\r\nLo script lanciato si trova nel file 'temp.sql'");
                        CD.Stop(false);
                        return(false);
                    }

                    s = "";
                }
                CD.Stop(true);
                if (not_to_copy > 0 || nullskipped > 0)
                {
                    CD.Comment(">>Not to copy:" + not_to_copy.ToString() + "  NullSkipped:" + nullskipped.ToString());
                }
                applied = true;
                return(true);
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
                CD.Stop(false);
                return(false);
            }
        }
Beispiel #15
0
        private void btnGeneraScript_Click(object sender, EventArgs e)
        {
            if (Meta.IsEmpty)
            {
                return;
            }
            Meta.SaveFormData();
            DialogResult r        = saveFileDialog1.ShowDialog(this);
            string       fileName = saveFileDialog1.FileName;

            if (r != DialogResult.OK)
            {
                return;
            }
            btnGeneraScript.Enabled = false;
            DataRow   Curr       = DS.report.Rows[0];
            string    reportName = Curr["reportname"].ToString();
            DataTable tRep       = Conn.CreateTableByName("report", "*");

            Conn.RUN_SELECT_INTO_TABLE(tRep, null, QHS.CmpEq("reportname", reportName), null, false);
            DataTable tRepPar = Conn.CreateTableByName("reportparameter", "*");

            Conn.RUN_SELECT_INTO_TABLE(tRepPar, "number", QHS.CmpEq("reportname", reportName), null, false);
            DataTable tRepAddPar = Conn.CreateTableByName("reportadditionalparam", "*");

            Conn.RUN_SELECT_INTO_TABLE(tRepAddPar, null,
                                       QHS.AppAnd(QHS.CmpEq("reportname", reportName), QHS.IsNull("stop")), null, false);
            DataAccess.AddExtendedProperty(Conn, tRep);
            DataAccess.AddExtendedProperty(Conn, tRepPar);
            DataAccess.AddExtendedProperty(Conn, tRepAddPar);

            DataSet D1 = new DataSet();

            D1.Tables.Add(tRep);
            GeneraSQL.GeneraStrutturaEDati(Conn, D1, fileName, false, UpdateType.insertAndUpdate,
                                           DataGenerationType.onlyData, true);
            D1 = new DataSet();
            D1.Tables.Add(tRepPar);
            GeneraSQL.GeneraStrutturaEDati(Conn, D1, fileName, true, UpdateType.insertAndUpdate,
                                           DataGenerationType.onlyData, true);
            D1 = new DataSet();
            D1.Tables.Add(tRepAddPar);
            GeneraSQL.GeneraStrutturaEDati(Conn, D1, fileName, true, UpdateType.onlyInsert, DataGenerationType.onlyData, true);

            Dictionary <string, bool> spAdded = new Dictionary <string, bool>();

            if (chkScriptSP.Checked)
            {
                ReportDocument ReportDoc   = new ReportDocument();
                string         path        = Meta.GetUsr("localreportdir").ToString();
                string         fName       = txtFile.Text;
                string         repFileName = Path.Combine(path, fName);

                try {
                    // Open a temporary copy of the report.
                    ReportDoc.Load(repFileName, OpenReportMethod.OpenReportByTempCopy);
                    StreamWriter sw     = new StreamWriter(fileName, true);
                    string       spName = getSPName(ReportDoc);
                    sw.Write(GeneraSQL.scriptOneSP(Conn, spName));
                    spAdded.Add(spName, true);


                    //mi scorro tutti i subreport (se presenti) del report principale
                    ReportDefinition repDef = ReportDoc.ReportDefinition;
                    foreach (Section sec in repDef.Sections)
                    {
                        foreach (ReportObject repObj in sec.ReportObjects)
                        {
                            if (repObj.Kind != ReportObjectKind.SubreportObject)
                            {
                                continue;
                            }
                            SubreportObject subRep    = (SubreportObject)repObj;
                            ReportDocument  SubReport = subRep.OpenSubreport(subRep.SubreportName);
                            spName = getSPName(SubReport);
                            if (!spAdded.ContainsKey(spName) && spName != "stampa_logo")
                            {
                                spAdded.Add(spName, true);
                                sw.Write(GeneraSQL.scriptOneSP(Conn, spName));
                            }
                            SubReport.Close();
                        }
                    }
                    ReportDoc.Close();
                    sw.Flush();
                    sw.Close();
                    sw.Dispose();
                }
                catch (Exception ee) {
                    QueryCreator.ShowException(this, "Impossibile caricare il report " + repFileName, ee);
                }
            }

            MessageBox.Show(this, "File salvato in " + fileName, "Avviso");
            btnGeneraScript.Enabled = true;
        }
Beispiel #16
0
        private void btnReportAnalisys_Click(object sender, EventArgs e)
        {
            ReportDocument ReportDoc   = new ReportDocument();
            string         path        = Meta.GetUsr("localreportdir").ToString();
            string         fName       = txtFile.Text;
            string         repFileName = Path.Combine(path, fName);

            try {
                // Open a temporary copy of the report.
                ReportDoc.Load(repFileName, OpenReportMethod.OpenReportByTempCopy);
            }
            catch (Exception ee) {
                QueryCreator.ShowException(this, "Impossibile caricare il report " + repFileName, ee);
                return;
            }
            //ReportDispatcherClass.setReportLogon(ReportDoc, Conn as Easy_DataAccess);

            CrystalDecisions.CrystalReports.Engine.Database crDatabase;
            CrystalDecisions.CrystalReports.Engine.Tables   crTables;
            crDatabase = ReportDoc.Database;
            crTables   = crDatabase.Tables;

            //Nome SP = spName;
            StringBuilder sbParam = new StringBuilder();

            foreach (ParameterFieldDefinition PF in ReportDoc.DataDefinition.ParameterFields)
            {
                //solo se appartengono al report in elaborazione
                if (PF.ReportName != "")
                {
                    continue;
                }
                if (PF.IsLinked())
                {
                    continue;
                }
                //PF.Name @ayear
                //PF.ValueType Numberfield  StringField
                sbParam.AppendLine($"{PF.Name} type:{PF.ValueType}");
            }
            StringBuilder sbFormula = new StringBuilder();

            foreach (FormulaFieldDefinition FFD in ReportDoc.DataDefinition.FormulaFields)
            {
                sbFormula.AppendLine($"{FFD.FormulaName} kind: {FFD.ValueType}");
            }
            StringBuilder sbSP = new StringBuilder();

            sbSP.AppendLine($"Report principale:  {ReportDoc.FilePath}  Stored Procedure: {getSPName(ReportDoc)}");
            //mi scorro tutti i subreport (se presenti) del report principale
            ReportDefinition repDef = ReportDoc.ReportDefinition;

            foreach (Section sec in repDef.Sections)
            {
                foreach (ReportObject repObj in sec.ReportObjects)
                {
                    if (repObj.Kind != ReportObjectKind.SubreportObject)
                    {
                        continue;
                    }
                    SubreportObject subRep    = (SubreportObject)repObj;
                    ReportDocument  SubReport = subRep.OpenSubreport(subRep.SubreportName);
                    sbSP.AppendLine($"SubReport: {SubReport.Name}  Stored Procedure: {getSPName(SubReport)}");
                    SubReport.Close();
                }
            }

            FrmShowParams p = new FrmShowParams(sbParam.ToString(), sbFormula.ToString(), sbSP.ToString(), Conn, getSPName(ReportDoc));

            ReportDoc.Close();
            p.Show(this);
        }
Beispiel #17
0
        private void btnTest_Click(object sender, System.EventArgs e)
        {
            if (Meta.IsEmpty)
            {
                return;
            }
            DialogResult Res = openFileDialog1.ShowDialog(this);

            if (Res != DialogResult.OK)
            {
                return;
            }
            Meta.GetFormData(true);
            DataRow Curr = DS.inputfile.Rows[0];

            string   filename      = openFileDialog1.FileName;
            FileInfo FI            = new FileInfo(filename);
            string   filenamenoext = Path.GetFileNameWithoutExtension(filename);
            string   dir           = Path.GetDirectoryName(filename);
            string   filtertype    = QHC.CmpEq("idfiletype", Curr["idfiletype"]);
            DataRow  CurrType      = DS.filetype.Select(filtertype)[0];
            string   connect       = CurrType["connectionstring"].ToString();

            connect = connect.Replace("%<filenamenoext>%", filenamenoext);
            connect = connect.Replace("%<dir>%", dir);
            connect = connect.Replace("%<filename>%", filename);
            if (Curr["param1"].ToString() != "")
            {
                connect = connect.Replace("%<par1>%", dir);
            }
            if (Curr["param2"].ToString() != "")
            {
                connect = connect.Replace("%<par2>%", dir);
            }
            if (Curr["param3"].ToString() != "")
            {
                connect = connect.Replace("%<par3>%", dir);
            }

            string query = CurrType["querystring"].ToString();

            query = query.Replace("%<filenamenoext>%", filenamenoext);
            query = query.Replace("%<dir>%", dir);
            query = query.Replace("%<filename>%", filename);
            if (Curr["param1"].ToString() != "")
            {
                query = query.Replace("%<par1>%", dir);
            }
            if (Curr["param2"].ToString() != "")
            {
                query = query.Replace("%<par2>%", dir);
            }
            if (Curr["param3"].ToString() != "")
            {
                query = query.Replace("%<par3>%", dir);
            }

            DataSet D = new DataSet();

            try {
                OleDbConnection OleConn = new OleDbConnection(connect);
                OleConn.Open();
                //DataTable T = OleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[]{null,null,null,null});
                //exportclass.DataTableToExcel(T,false);
                OleDbDataAdapter OleAdapter = new OleDbDataAdapter(query, OleConn);

                OleAdapter.Fill(D);
                OleConn.Close();
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
                return;
            }
            if (D.Tables.Count == 0)
            {
                MessageBox.Show("Non ho letto nulla!");
                return;
            }
            exportclass.DataTableToExcel(D.Tables[0], false);
        }
Beispiel #18
0
        private void btnGeneraFileIncassi_Click(object sender, EventArgs e)
        {
            int n = CfgFn.GetNoNullInt32(txtNproceedsTransm.Text);

            if (n == 0)
            {
                MessageBox.Show(this, "E' necessario selezionare un numero per la distinta");
                return;
            }
            int    y = CfgFn.GetNoNullInt32(Conn.GetSys("esercizio"));
            string filterProceedsTransmission = QHS.AppAnd(QHS.CmpEq("yproceedstransmission", y),
                                                           QHS.CmpEq("nproceedstransmission", n));
            object idtreasurer             = Conn.DO_READ_VALUE("proceedstransmission", filterProceedsTransmission, "idtreasurer");
            object flagtransmissionenabled = Conn.DO_READ_VALUE("proceedstransmission", filterProceedsTransmission,
                                                                "flagtransmissionenabled");
            object cfgflagenabletransmission = Conn.DO_READ_VALUE("config", QHS.CmpEq("ayear", y),
                                                                  "flagenabletransmission");

            if (cfgflagenabletransmission != DBNull.Value)
            {
                string cfg_flag = cfgflagenabletransmission.ToString().ToUpper();
                if ((cfg_flag == "S") && (flagtransmissionenabled.ToString().ToUpper() != "S"))
                {
                    MessageBox.Show(this, "La trasmissione della distinta non è stata autorizzata");
                    return;
                }
            }
            EsportazioneDistinteIncasso E = new EsportazioneDistinteIncasso(Conn, y, n);
            XmlDocument D = E.GeneraFileXML();

            string filterTreasurer = QHS.CmpEq("idtreasurer", idtreasurer);
            string fname           = "";
            object savepath        = Conn.DO_READ_VALUE("treasurer", filterTreasurer, "savepath");

            if (savepath != DBNull.Value)
            {
                fname = Path.Combine(savepath.ToString(), Meta.GetSys("esercizio") + "_reversali_" + n.ToString());
            }
            else
            {
                saveFileDialog1.FileName = Meta.GetSys("esercizio") + "_reversali_" + n.ToString();
                DialogResult dialogResult = saveFileDialog1.ShowDialog(this);
                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }
                fname = saveFileDialog1.FileName;
            }

            try {
                XmlWriterSettings xs = new XmlWriterSettings();
                xs.Indent      = true;
                xs.CloseOutput = true;
                xs.Encoding    = Encoding.GetEncoding("ISO-8859-15");
                XmlWriter xw = XmlWriter.Create(fname, xs);
                D.WriteTo(xw);
                xw.Flush();
                xw.Close();
                MessageBox.Show("Salvataggio del file " + fname + " effettuato");
                TreasurerPutFile ftp = new TreasurerPutFile(Conn, idtreasurer);
                ftp.putFile(fname, Meta.GetSys("esercizio") + "_reversali_" + n.ToString());
            }

            catch (Exception e1) {
                QueryCreator.ShowException("Errore nel salvataggio del file " + fname, e1);
                return;
            }


            try {
                XslCompiledTransform xsltransform = new XslCompiledTransform();
                xsltransform.Load(AppDomain.CurrentDomain.BaseDirectory + "ORDINATIVI_TAG_UFFICIO_LE_3.02.XSLT");
                // Terzo metodo creazione da stringta XML
                Stream transformedData = new MemoryStream();
                String xmlString       = D.InnerXml;
                //String xmlString1 = ("<flusso_ordinativi genre='novel' ISBN='1-861001-57-5'>" +
                //                     "<informazioni_versante>Pride And Prejudice</informazioni_versante>" +
                //                     "</flusso_ordinativi>");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlString);

                xsltransform.Transform(doc, null, transformedData);
                transformedData.Seek(0, SeekOrigin.Begin);
                webBrowser1.DocumentStream = transformedData;
            }
            catch (Exception e2) {
                QueryCreator.ShowException("Errore cercando di visualizzare il file " + fname, e2);
                return;
            }

            try {
                bool res = XML_XSD_Validator.Validate(fname,
                                                      AppDomain.CurrentDomain.BaseDirectory + "ORDINATIVI_TAG_UFFICIO_LE_3.02.XSD");
                if (!res)
                {
                    QueryCreator.ShowError(this, "Errore nella validazione dell'xml",
                                           XML_XSD_Validator.GetError());
                    return;
                }
            }
            catch (Exception e3) {
                QueryCreator.ShowException("Errore validando il file " + fname, e3);
                return;
            }


            AggiornaStreamDate("PROCEEDSTRANSMISSION", y, n);

            //try
            //{
            //    Process.Start(fname);
            //}
            //catch (Exception E1)
            //{
            //    QueryCreator.ShowException(E1);
            //}
        }
Beispiel #19
0
        private void btnGeneraFilePagamenti_Click(object sender, EventArgs e)
        {
            int n = CfgFn.GetNoNullInt32(txtNPaymentTransmission.Text);

            if (n == 0)
            {
                MessageBox.Show(this, "E' necessario selezionare un numero per la distinta");
                return;
            }
            int y = CfgFn.GetNoNullInt32(Conn.GetSys("esercizio"));

            string filterPaymentTransmission = QHS.AppAnd(QHS.CmpEq("ypaymenttransmission", y),
                                                          QHS.CmpEq("npaymenttransmission", n));
            object idtreasurer             = Conn.DO_READ_VALUE("paymenttransmission", filterPaymentTransmission, "idtreasurer");
            object flagtransmissionenabled = Conn.DO_READ_VALUE("paymenttransmission", filterPaymentTransmission,
                                                                "flagtransmissionenabled");
            object cfgflagenabletransmission = Conn.DO_READ_VALUE("config", QHS.CmpEq("ayear", y),
                                                                  "flagenabletransmission");

            if (cfgflagenabletransmission != DBNull.Value)
            {
                string cfg_flag = cfgflagenabletransmission.ToString().ToUpper();
                if ((cfg_flag == "S") && (flagtransmissionenabled.ToString().ToUpper() != "S"))
                {
                    MessageBox.Show(this, "La trasmissione della distinta non è stata autorizzata");
                    return;
                }
            }
            EsportazioneDistintePagamento E = new EsportazioneDistintePagamento(Conn, y, n);
            XmlDocument D = E.GeneraFileXML();



            if (D == null)
            {
                return;
            }
            string filterTreasurer = QHS.CmpEq("idtreasurer", idtreasurer);
            string fname           = "";
            object savepath        = Conn.DO_READ_VALUE("treasurer", filterTreasurer, "savepath");

            if (savepath != DBNull.Value)
            {
                fname = Path.Combine(savepath.ToString(), Meta.GetSys("esercizio") + "_mandati_" + n.ToString());
            }
            else
            {
                saveFileDialog1.FileName = Meta.GetSys("esercizio") + "_mandati_" + n.ToString();
                DialogResult dialogResult = saveFileDialog1.ShowDialog(this);
                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }
                fname = saveFileDialog1.FileName;
            }
            try {
                XmlWriterSettings xs = new XmlWriterSettings();
                xs.Indent      = true;
                xs.CloseOutput = true;
                xs.Encoding    = Encoding.GetEncoding("ISO-8859-15");
                XmlWriter xw = XmlWriter.Create(fname, xs);
                D.WriteTo(xw);
                xw.Flush();
                xw.Close();
                MessageBox.Show("Salvataggio del file " + fname + " effettuato");
                TreasurerPutFile ftp = new TreasurerPutFile(Conn, idtreasurer);
                ftp.putFile(fname, Meta.GetSys("esercizio") + "_mandati_" + n.ToString());
            }
            catch (Exception e1) {
                QueryCreator.ShowException("Errore nel salvataggio del file " + fname, e1);
                return;
            }

            try {
                XslCompiledTransform xsltransform = new XslCompiledTransform();
                xsltransform.Load(AppDomain.CurrentDomain.BaseDirectory + "ORDINATIVI_TAG_UFFICIO_LE_3.02.XSLT");

                // Secondo metodo, utilizzo di uno stream
                Stream transformedData = new MemoryStream();
                xsltransform.Transform(D, null, transformedData);
                transformedData.Seek(0, SeekOrigin.Begin);
                webBrowser1.DocumentStream = transformedData;
            }
            catch (Exception e2) {
                QueryCreator.ShowException("Errore cercando di visualizzare il file " + fname, e2);
                return;
            }

            try {
                bool res = XML_XSD_Validator.Validate(fname,
                                                      AppDomain.CurrentDomain.BaseDirectory + "ORDINATIVI_TAG_UFFICIO_LE_3.02.XSD");
                if (!res)
                {
                    QueryCreator.ShowError(this, "Errore nella validazione dell'xml",
                                           XML_XSD_Validator.GetError());
                    return;
                }
            }
            catch (Exception e3) {
                QueryCreator.ShowException("Errore validando il file " + fname, e3);
                return;
            }

            AggiornaStreamDate("PAYMENTTRANSMISSION", y, n);
        }
Beispiel #20
0
        private void GeneraFile(bool Mandati)
        {
            DataRow rTesoriere = HelpForm.GetLastSelected(DS.treasurer);

            if (rTesoriere == null)
            {
                HelpForm.FocusControl(cmbIstitutoCassiere);
                MessageBox.Show(this, "Scegliere l'istituto cassiere");
                return;
            }
            string idbank = rTesoriere["idbank"].ToString();
            bool   res    = false;

            foreach (string s in new string[] { "03111", "03067", "01030", "02008", "01010" })
            {
                if (s == idbank)
                {
                    res = true;
                }
            }
            if (!res)
            {
                if (MessageBox.Show(
                        "Questa maschera non dovrebbe essere usata con il cassiere selezionato. Usare, invece, la maschera alla voce di menu Cassiere - Trasmissione e Importazione Distinte XML. " +
                        " Si desidera proseguire comunque l''elaborazione?", "Errore",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            string sp_export = Mandati ? rTesoriere["spexportexp"].ToString() : rTesoriere["spexportinc"].ToString();

            if (sp_export == "")
            {
                MessageBox.Show(this,
                                "Nella configurazione del tesoriere non è impostata la sp da chiamare per generare il file");
                return;
            }
            string flagMultiExp = rTesoriere["flagmultiexp"].ToString();
            int    da           = CfgFn.GetNoNullInt32(txtDa.Text);
            int    a            = CfgFn.GetNoNullInt32(txtA.Text);

            if (flagMultiExp == "S")
            {
                if (da == 0)
                {
                    HelpForm.FocusControl(txtDa);
                    MessageBox.Show(this, "Specificare il numero della prima distinta che si vuole trasmettere");
                    return;
                }
                if (a == 0)
                {
                    HelpForm.FocusControl(txtA);
                    MessageBox.Show(this, "Specificare il numero dell'ultima distinta che si vuole trasmettere");
                    return;
                }
            }
            else
            {
                if (da == 0)
                {
                    HelpForm.FocusControl(txtDa);
                    MessageBox.Show(this, "Specificare il numero della distinta che si vuole trasmettere");
                    return;
                }
            }
            // Controlla che il cassiere della/e distinta/e sia uguale a quello scelto nel combo.
            string Filter = "";

            if (Mandati)
            {
                if (flagMultiExp == "S")
                {
                    for (int i = da; i <= a; i++)
                    {
                        Filter = QHS.AppAnd(QHS.CmpEq("ypaymenttransmission", Meta.GetSys("esercizio")),
                                            QHS.CmpEq("npaymenttransmission", i));
                        object idtreasurer = Meta.Conn.DO_READ_VALUE("paymenttransmission", Filter, "idtreasurer");
                        if (idtreasurer == null)
                        {
                            MessageBox.Show(this,
                                            "La distinta n." + i.ToString() + " non è presente su db", "Errore");
                            return;
                        }
                        if (idtreasurer.ToString() != rTesoriere["idtreasurer"].ToString())
                        {
                            MessageBox.Show(this,
                                            "La distinta n." + i.ToString() + " ha un Cassiere diverso da quello selezionato!");
                            return;
                        }

                        object flagtransmissionenabled = Meta.Conn.DO_READ_VALUE("paymenttransmission", Filter,
                                                                                 "flagtransmissionenabled");
                        object cfgflagenabletransmission = Meta.Conn.DO_READ_VALUE("config",
                                                                                   QHS.CmpEq("ayear", Meta.GetSys("esercizio")), "flagenabletransmission");

                        if (cfgflagenabletransmission != DBNull.Value)
                        {
                            string cfg_flag = cfgflagenabletransmission.ToString().ToUpper();
                            if ((cfg_flag == "S") && (flagtransmissionenabled.ToString().ToUpper() != "S"))
                            {
                                MessageBox.Show(this, "La trasmissione della distinta non è stata autorizzata");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    Filter = QHS.AppAnd(QHS.CmpEq("ypaymenttransmission", Meta.GetSys("esercizio")),
                                        QHS.CmpEq("npaymenttransmission", da));
                    object idtreasurer = Meta.Conn.DO_READ_VALUE("paymenttransmission", Filter, "idtreasurer");
                    if (idtreasurer == null)
                    {
                        MessageBox.Show(this,
                                        "La distinta n." + da.ToString() + " non è presente su db", "Errore");
                        return;
                    }
                    if (idtreasurer.ToString() != rTesoriere["idtreasurer"].ToString())
                    {
                        MessageBox.Show(this,
                                        "La distinta n." + da.ToString() + " ha un Cassiere diverso da quello selezionato!");
                        return;
                    }
                    object flagtransmissionenabled = Meta.Conn.DO_READ_VALUE("paymenttransmission", Filter,
                                                                             "flagtransmissionenabled");
                    object cfgflagenabletransmission = Meta.Conn.DO_READ_VALUE("config",
                                                                               QHS.CmpEq("ayear", Meta.GetSys("esercizio")), "flagenabletransmission");

                    if (cfgflagenabletransmission != DBNull.Value)
                    {
                        string cfg_flag = cfgflagenabletransmission.ToString().ToUpper();
                        if ((cfg_flag == "S") && (flagtransmissionenabled.ToString().ToUpper() != "S"))
                        {
                            MessageBox.Show(this, "La trasmissione della distinta non è stata autorizzata");
                            return;
                        }
                    }
                }
            }
            else
            {
                if (flagMultiExp == "S")
                {
                    for (int i = da; i <= a; i++)
                    {
                        Filter = QHS.AppAnd(QHS.CmpEq("yproceedstransmission", Meta.GetSys("esercizio")),
                                            QHS.CmpEq("nproceedstransmission", i));
                        object idtreasurer = Meta.Conn.DO_READ_VALUE("proceedstransmission", Filter, "idtreasurer");
                        if (idtreasurer == null)
                        {
                            MessageBox.Show(this,
                                            "La distinta n." + i.ToString() + " non è presente su db", "Errore");
                            return;
                        }
                        if (idtreasurer.ToString() != rTesoriere["idtreasurer"].ToString())
                        {
                            MessageBox.Show(this,
                                            "La distinta n." + i.ToString() + " ha un Cassiere diverso da quello selezionato!");
                            return;
                        }

                        object flagtransmissionenabled = Meta.Conn.DO_READ_VALUE("proceedstransmission", Filter,
                                                                                 "flagtransmissionenabled");
                        object cfgflagenabletransmission = Meta.Conn.DO_READ_VALUE("config",
                                                                                   QHS.CmpEq("ayear", Meta.GetSys("esercizio")), "flagenabletransmission");

                        if (cfgflagenabletransmission != DBNull.Value)
                        {
                            string cfg_flag = cfgflagenabletransmission.ToString().ToUpper();
                            if ((cfg_flag == "S") && (flagtransmissionenabled.ToString().ToUpper() != "S"))
                            {
                                MessageBox.Show(this, "La trasmissione della distinta non è stata autorizzata");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    Filter = QHS.AppAnd(QHS.CmpEq("yproceedstransmission", Meta.GetSys("esercizio")),
                                        QHS.CmpEq("nproceedstransmission", da));
                    object idtreasurer = Meta.Conn.DO_READ_VALUE("proceedstransmission", Filter, "idtreasurer");
                    if (idtreasurer == null)
                    {
                        MessageBox.Show(this,
                                        "La distinta n." + da.ToString() + " non è presente su db", "Errore");
                        return;
                    }
                    if (idtreasurer.ToString() != rTesoriere["idtreasurer"].ToString())
                    {
                        MessageBox.Show(this,
                                        "La distinta n." + da.ToString() + " ha un Cassiere diverso da quello selezionato!");
                        return;
                    }
                    object flagtransmissionenabled = Meta.Conn.DO_READ_VALUE("proceedstransmission", Filter,
                                                                             "flagtransmissionenabled");
                    object cfgflagenabletransmission = Meta.Conn.DO_READ_VALUE("config",
                                                                               QHS.CmpEq("ayear", Meta.GetSys("esercizio")), "flagenabletransmission");

                    if (cfgflagenabletransmission != DBNull.Value)
                    {
                        string cfg_flag = cfgflagenabletransmission.ToString().ToUpper();
                        if ((cfg_flag == "S") && (flagtransmissionenabled.ToString().ToUpper() != "S"))
                        {
                            MessageBox.Show(this, "La trasmissione della distinta non è stata autorizzata");
                            return;
                        }
                    }
                }
            }

            object[] parametri = flagMultiExp == "S"
                ? new object[] { Meta.GetSys("esercizio"), da, a }
                : new object[] { Meta.GetSys("esercizio"), da };
            DataSet result = Meta.Conn.CallSP(sp_export, parametri, false, 300);

            if ((result == null) || (result.Tables.Count == 0))
            {
                MessageBox.Show(this, "La sp non ha restituito risultati");
                return;
            }
            DataTable t = result.Tables[0];

            dataGrid1.TableStyles.Clear();
            dataGrid1.DataSource = null;
            if (t.Columns.Contains("message"))
            {
                t.Columns["message"].Caption = "Spiegazione errore";
                HelpForm.SetDataGrid(dataGrid1, t);
                formatgrids FF = new formatgrids(dataGrid1);
                FF.AutosizeColumnWidth();
                MessageBox.Show(this, "Ci sono degli errori, pertanto non è stato generato il file!");
                return;
            }
            if (txtCartella.Text == "")
            {
                DialogResult dr = folderBrowserDialog1.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    txtCartella.Text = folderBrowserDialog1.SelectedPath;
                }
                else
                {
                    folderBrowserDialog1.SelectedPath = txtCartella.Text;
                    HelpForm.FocusControl(txtCartella);
                    MessageBox.Show(this, "Specificare il percorso del file");
                    return;
                }
            }

            string nomeFile = Mandati
                ? Meta.GetSys("esercizio") + "_mandato" + "_" + da
                : Meta.GetSys("esercizio") + "_reversale" + "_" + da;

            if (flagMultiExp == "S")
            {
                if (da != a)
                {
                    nomeFile = Mandati
                        ? Meta.GetSys("esercizio") + "_mandati"
                        : Meta.GetSys("esercizio") + "_reversali";
                    for (int i = da; i <= a; i++)
                    {
                        nomeFile += "_" + i;
                    }
                }
            }
            txtFile.Text = Path.Combine(txtCartella.Text, nomeFile + "." + fileExtension);
            try {
                StreamWriter sw = new StreamWriter(txtFile.Text, false, Encoding.Default);
                foreach (DataRow r in t.Rows)
                {
                    sw.WriteLine(r[0]);
                }
                sw.Flush();
                sw.Close();
                sw.Dispose();
            }
            catch (Exception e1) {
                QueryCreator.ShowException("Errore nel salvataggio del file " + txtFile.Text, e1);
                return;
            }

            int year = CfgFn.GetNoNullInt32(Meta.GetSys("esercizio"));

            if (flagMultiExp == "S")
            {
                if (da != a)
                {
                    for (int i = da; i <= a; i++)
                    {
                        if (Mandati)
                        {
                            AggiornaStreamDate("PAYMENTTRANSMISSION", year, i);
                        }
                        else
                        {
                            AggiornaStreamDate("PROCEEDSTRANSMISSION", year, i);
                        }
                    }
                }
            }

            if (Mandati)
            {
                AggiornaStreamDate("PAYMENTTRANSMISSION", year, da);
            }
            else
            {
                AggiornaStreamDate("PROCEEDSTRANSMISSION", year, da);
            }

            MessageBox.Show(this, "File della trasmissione salvato in " + txtFile.Text);
        }
Beispiel #21
0
        private void ReadCurrentSheet()
        {
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            //m_objExcel.Visible = true;
            Microsoft.Office.Interop.Excel.Workbook  xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            try {
                xlWorkBook = xlApp.Workbooks.Open(fileName, 0,
                                                  false /* impostare a false se non è readonly */,
                                                  5,
                                                  "", "", true,
                                                  Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
                                                  "\t",  //delimiter
                                                  false, //editable
                                                  false, //Notify
                                                  0, true, 1, 0);
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nell'apertura del file " + fileName, E);
                return;
            }
            try {
                xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nella lettura del primo elemento del file excel ", E);
                return;
            }


            bool ok = true;

            try {
                ok = ExcelGetSheet(xlWorkSheet);  // bisogna salvare i dati
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nella elaborazione del file excel ", E);
                return;
            }

            try {
                xlWorkBook.Close(true, misValue, misValue);
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nel salvataggio del file excel ", E);
                return;
            }

            try {
                xlApp.Quit();
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nell'uscita dall'applicazioneexcel ", E);
                return;
            }

            try {
                releaseObject(xlApp);
                releaseObject(xlWorkBook);
                releaseObject(xlWorkSheet);
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nel rilascio delle risorse excel ", E);
                return;
            }



            if (ok)
            {
                MessageBox.Show(this, "Il File " + fileName + " è stato importato. Si può procedere con la generazione del modello F24EP");
            }
            else
            {
                MessageBox.Show(this, "L'esame del file " + fileName + " ha fatto rilevare degli errori");
                mData.Clear();
            }
        }
Beispiel #22
0
        public override bool CopyTable(DataAccess Source, DataAccess Dest, CopyContext Ctx, CopyDisplay CD)
        {
            applied = false;
            int         count = 0;
            QueryHelper QHS   = Dest.GetQueryHelper();

            try {
                DataTable Cols = Dest.SQLRunner("sp_columns " + table + ",'" + Dest.GetSys("userdb").ToString() + "'");
                if (Cols.Rows.Count == 0)
                {
                    Cols = Dest.SQLRunner("sp_columns " + table + ",'dbo'");
                }
                Comment(Dest, Ctx, CD);


                int nrows = Source.RUN_SELECT_COUNT(table, filter, false);
                CD.Start(filter == null ? table : table + " where " + filter, "copy", nrows);



                string    insert = "INSERT INTO surplus VALUES(";//(
                string    s      = "";
                string    err;
                DataTable T   = Dest.CreateTableByName(table, "*");
                string    col = QueryCreator.ColumnNameList(T);


                DataAccess.DataRowReader DRR = new DataAccess.DataRowReader(Source, "surplus", col, null, filter);

                foreach (DataRow row in DRR)
                {
                    CD.Update(1);
                    if (!IsToCopy(row))
                    {
                        continue;                  // copia quelle che NON sono da inserire
                    }
                    Translate(Ctx, row);

                    string    delete = "";
                    DataTable T2     = Dest.RUN_SELECT("surplus", "*", null, QHS.CmpEq("ayear", row["ayear"]), null, false);

                    if (T2.Rows.Count > 0)
                    {
                        DataRow RR = T2.Rows[0];
                        foreach (DataColumn CR in T2.Columns)
                        {
                            string field = CR.ColumnName;
                            if (CR.DataType == typeof(decimal))
                            {
                                if (RR[field] == DBNull.Value)
                                {
                                    continue;
                                }
                                if (row[field] == DBNull.Value)
                                {
                                    row[field] = RR[field];
                                }
                                else
                                {
                                    row[field] = CfgFn.GetNoNullDecimal(row[field]) + CfgFn.GetNoNullDecimal(RR[field]);
                                }
                            }
                        }
                        delete = "delete from surplus where " + QHS.CmpEq("ayear", row["ayear"]) + "\n\r";
                    }
                    row["locked"] = "S";
                    count++;
                    string values = GetSQLDataValues(row, Cols);
                    s += delete + insert + values;
                    if (count == 1)    //è necessario farlo una riga alla volta
                    {
                        Dest.SQLRunner(s, 0, out err);

                        if (err != null)
                        {
                            QueryCreator.ShowError(null, "Errore", err);
                            StreamWriter fsw = new StreamWriter("temp.sql", false, Encoding.Default);
                            fsw.Write(s.ToString());
                            fsw.Close();
                            MessageBox.Show("Errore durante la copia della tabella " + table + "\r\nLo script lanciato si trova nel file 'temp.sql'");
                            CD.Stop(false);
                            return(false);
                        }
                        s     = "";
                        count = 0;
                    }
                }
                if (s != "")
                {
                    Dest.SQLRunner(s, 0, out err);
                    count = 0;
                    if (err != null)
                    {
                        QueryCreator.ShowError(null, "Errore", err);
                        StreamWriter fsw = new StreamWriter("temp.sql", false, Encoding.Default);
                        fsw.Write(s.ToString());
                        fsw.Close();
                        MessageBox.Show("Errore durante la copia di " + table + "\r\nLo script lanciato si trova nel file 'temp.sql'");
                        CD.Stop(false);
                        return(false);
                    }

                    s = "";
                }
                CD.Stop(true);
                applied = true;
                return(true);
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
                CD.Stop(false);
                return(false);
            }
        }
Beispiel #23
0
        void SalvaAllegato(string certification)
        {
            // Legge il file indicato dall'utente e lo scrive nel DB in 'durccertification' o in 'selfcertification'
            if (Meta.IsEmpty)
            {
                return;
            }
            if (!Meta.GetFormData(true))
            {
                return;
            }
            DialogResult dialogResult;

            try {
                dialogResult = opendlg.ShowDialog(this);
            }
            catch (Exception E) {
                QueryCreator.ShowException("Errore nella selezione  del file", E);
                return;
            }
            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }
            DataRow Curr = HelpForm.GetLastSelected(DS.registrydurc);

            if (Curr == null)
            {
                return;
            }
            FileStream FS;

            try {
                FS = new FileStream(opendlg.FileName, FileMode.Open, FileAccess.Read);
            }
            catch (Exception e) {
                QueryCreator.ShowException("Errore nell'apertura del file", e);
                return;
            }
            string estensione = Path.GetExtension(FS.Name);

            if (FS == null)
            {
                return;
            }
            int n = (int)FS.Length;

            if (n == 0)
            {
                return;
            }
            int namelen = LengthForFileName(opendlg.FileName);

            try
            {
                byte[] ByteArray = new byte[n + namelen];
                FS.Read(ByteArray, namelen, n);
                if (FS.Length == 0)
                {
                    Curr[certification] = DBNull.Value;
                }
                FS.Close();
                SetBytesForFileName(opendlg.FileName, ByteArray);
                Curr[certification] = ByteArray;
            }
            catch { }
            AbilitaDisabilitaAllegati();
        }
Beispiel #24
0
        private void CSV_Click(object menusender, EventArgs e)
        {
            if (menusender == null)
            {
                return;
            }
            if (!(typeof(MenuItem).IsAssignableFrom(menusender.GetType())))
            {
                return;
            }
            object sender = ((MenuItem)menusender).Parent.GetContextMenu().SourceControl;

            if (!(typeof(DataGrid).IsAssignableFrom(sender.GetType())))
            {
                return;
            }
            DataGrid G   = (DataGrid)sender;
            object   DDS = G.DataSource;

            if (DDS == null)
            {
                return;
            }
            if (!typeof(DataSet).IsAssignableFrom(DDS.GetType()))
            {
                return;
            }
            string DDT = G.DataMember;

            if (DDT == null)
            {
                return;
            }
            DataTable T = ((DataSet)DDS).Tables[DDT];

            if (T == null)
            {
                return;
            }

            OpenFileDialog FD = new OpenFileDialog();

            FD.Title           = "Seleziona il file da creare";
            FD.AddExtension    = true;
            FD.DefaultExt      = "CSV";
            FD.CheckFileExists = false;
            FD.CheckPathExists = true;
            FD.Multiselect     = false;
            DialogResult DR = FD.ShowDialog();

            if (DR != DialogResult.OK)
            {
                return;
            }



            try {
                string       S   = exportclass.DataTableToCSV(T, true);
                StreamWriter SWR = new StreamWriter(FD.FileName, false, Encoding.Default);
                SWR.Write(S);
                SWR.Close();
                SWR.Dispose();
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
            }
            Process.Start(FD.FileName);
        }
Beispiel #25
0
        /// <summary>
        /// Manda in stampa il documento
        /// </summary>
        /// <param name="ShowPrintDialog">True vuol dire che sono in anteprima, ricompare
        /// il PrintDialog</param>
        public bool StampaReport()
        {
            if (errore)
            {
                return(false);
            }
            if (printerName == null)
            {
                return(false);
            }
            if (ReportDoc == null)
            {
                return(false);
            }
            if (oneprint && printed)
            {
                MessageBox.Show("Una sola copia della stampa è ammessa.");
                return(false);
            }
            //se in anteprima mostro il printDialog con tutte le proprietà impostate
            //in precedenza

            PrintDialog pd = new PrintDialog();

            pd.PrinterSettings             = new PrinterSettings();
            pd.PrinterSettings.PrinterName = printerName;


            string papersize = ModuleReport["papersize"].ToString();



            //pd.Document = pdoc;
            //pd.PrinterSettings = pdoc.PrinterSettings;

            ReportPages = 1;
            ReportPageRequestContext oPageContext = new ReportPageRequestContext();

            operating = true;

            try {
                ReportPages = ReportDoc.FormatEngine.GetLastPageNumber(oPageContext);
            }
            catch (Exception E) {
                QueryCreator.ShowException("Errore nel calcolo del numero totale delle pagine", E);
                errore    = true;
                operating = false;
                return(false);
            }

            if (ReportPages < 1)
            {
                ReportPages = 1;
            }

            pd.AllowCurrentPage = false;
            pd.AllowSomePages   = (ReportPages > 1) && (!oneprint);
            pd.AllowSelection   = false;
            if (pd.AllowSomePages)   //pdoc.PrinterSettings != null &&

            {
                pd.PrinterSettings.FromPage = 1;
                pd.PrinterSettings.ToPage   = ReportPages;
            }

            pd.AllowPrintToFile = !oneprint;

            if (papersize.ToUpper() != "ASK")
            {
                setPrintDocument(pd.PrinterSettings, pd.PrinterSettings.DefaultPageSettings);
            }

            if (pd.ShowDialog(this) != DialogResult.OK)
            {
                operating = false;
                return(false);
            }

            //Reimposto il formato carta
            //setPrintDocument(ref pdoc);

            //pdoc.PrinterSettings = pd.PrinterSettings;

            //pdoc.PrinterSettings.Collate = pd.PrinterSettings.Collate;
            //if (pdoc.PrinterSettings != null) {
            pd.PrinterSettings.Collate = (pd.PrinterSettings.Copies > 1) &&
                                         (pd.PrinterSettings.ToPage > pd.PrinterSettings.FromPage);
            //}


            //imposto la stampante selezionata
            try {
                //ReportDoc.PrintOptions.PrinterName = pdoc.DefaultPageSettings.PrinterSettings.PrinterName;
                ReportDoc.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName;
            }
            catch (Exception E) {
                operating = false;
                QueryCreator.ShowException("La stampante selezionata (" + printerName + ") non è valida", E);
                errore = true;
                return(false);
            }

            //Se non sono in anteprima stampo direttamente
            try {
                ReportDoc.PrintToPrinter(pd.PrinterSettings, pd.PrinterSettings.DefaultPageSettings, false);
                //ReportDoc.PrintToPrinter(pdoc.PrinterSettings.Copies,
                //    (pdoc.PrinterSettings.Copies > 1) &&
                //    (pdoc.PrinterSettings.ToPage > pdoc.PrinterSettings.FromPage), //pdoc.PrinterSettings.Collate,
                //    pdoc.PrinterSettings.FromPage,
                //    pdoc.PrinterSettings.ToPage);
                printed   = true;
                operating = false;
                return(true);
            }
            catch (Exception E) {
                errore    = true;
                operating = false;
                if (!E.ToString().Contains("OnStartPrint") && !E.ToString().Contains("OnEndPage"))
                {
                    meta.LogError("Errore nella stampa\r\n" + elencoparametri, E);
                }
                QueryCreator.ShowException(
                    QueryCreator.GetPrintable(
                        "Si è verificato un errore in fase di invio dei dati alla stampante.\n" +
                        "Controllare che il server di stampa sia acceso ed accessibile dal proprio computer."), E);
                return(false);
            }
        }
Beispiel #26
0
        bool ExcelGetSheet(Microsoft.Office.Interop.Excel.Worksheet w)
        {
            bool ok          = true;
            int  ColumnCount = 0;
            int  RowCount    = 0;

            try {
                ColumnCount = w.UsedRange.Columns.Count;
                RowCount    = w.UsedRange.Rows.Count;
            }
            catch (Exception E) {
                QueryCreator.ShowException(this, "Errore nella rilevazione dell'area usata", E);
                return(false);
            }
            int nrigacorrente = 2;

            while (true)   // escludo l'intestazione
            {
                string lastcol = ExcelColumnFromNumber(tracciato_f24.Length);
                string row = nrigacorrente.ToString();
                string errore = "";
                string err = "";
                object o_cod_tributo = null, o_sigla_prov = null, o_cod_catastale = null, o_anno_rif = null, o_mese_rif = null,
                       o_importoadebito = null, o_importoacredito = null, o_codice_regione = null, denom = null;
                o_cod_tributo = GetVal(w, nrigacorrente, 1, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                if (o_cod_tributo == DBNull.Value)
                {
                    break;
                }

                denom = GetVal(w, nrigacorrente, 2, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_sigla_prov = GetVal(w, nrigacorrente, 3, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_cod_catastale = GetVal(w, nrigacorrente, 4, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_anno_rif = GetVal(w, nrigacorrente, 5, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_mese_rif = GetVal(w, nrigacorrente, 6, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_importoadebito = GetVal(w, nrigacorrente, 7, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_importoacredito = GetVal(w, nrigacorrente, 8, out errore); if (errore != "")
                {
                    err = err + " " + errore;
                }
                o_codice_regione = "";

                string cod_tributo = ""; if (o_cod_tributo != null)
                {
                    cod_tributo = o_cod_tributo.ToString();
                }
                string sigla_prov = ""; if (o_sigla_prov != null)
                {
                    sigla_prov = o_sigla_prov.ToString();
                }
                string cod_catastale = ""; if (o_cod_catastale != null)
                {
                    cod_catastale = o_cod_catastale.ToString();
                }

                Microsoft.Office.Interop.Excel.Range ErrCell;
                int ntryh = 0;
                while (true)
                {
                    ntryh++;
                    try {
                        ErrCell = w.Range[ExcelColumnFromNumber(8) + nrigacorrente.ToString(),
                                          ExcelColumnFromNumber(8) + nrigacorrente.ToString()];
                        break;
                    }
                    catch (Exception E) {
                        if (ntryh == 10)
                        {
                            throw E;
                        }
                        Thread.Sleep(100 * ntryh);
                    }
                }

                ntryh = 0;
                while (true)
                {
                    ntryh++;
                    try {
                        ErrCell.Font.Color = 255;
                        break;
                    }
                    catch (Exception E) {
                        if (ntryh == 10)
                        {
                            throw E;
                        }
                        Thread.Sleep(100 * ntryh);
                    }
                }


                ErrCell.Value2 = ""; //Azzera eventuale vecchio contenuto

                if ((cod_tributo.ToUpper() != "127E") && (cod_tributo.ToUpper() != "128E") && (cod_tributo.ToUpper() != "384E") && (cod_tributo.ToUpper() != "385E") && (cod_tributo.ToUpper() != "381E"))
                {
                    err           += " Valore non previsto nella decodifica del campo codice tributo";
                    ErrCell.Value2 = err;
                    nrigacorrente++;
                    ok = false;
                    continue;
                }

                cod_tributo = cod_tributo.ToUpper();
                if ((cod_tributo == "384E") || (cod_tributo == "385E") || (cod_tributo.ToUpper() == "127E") || (cod_tributo.ToUpper() == "128E"))
                {
                    string errori = null;
                    bool   found  = CheckProvincia(sigla_prov.Trim(), out errori);

                    if ((!found) && (errori != ""))
                    {
                        err           += " " + errori;
                        ErrCell.Value2 = err;
                        nrigacorrente++;
                        ok = false;
                        continue;
                    }
                }
                if ((cod_tributo == "384E") || (cod_tributo == "385E") || (cod_tributo.ToUpper() == "127E") || (cod_tributo.ToUpper() == "128E"))
                {
                    bool found = CheckComune(denom.ToString().Trim(), sigla_prov, cod_catastale, out errore, out o_cod_catastale);
                    if ((!found) && (errore != ""))
                    {
                        err           += " " + errore;
                        ErrCell.Value2 = err;
                        nrigacorrente++;
                        ok = false;
                        continue;
                    }
                }

                if (cod_tributo == "381E")
                {
                    if (denom == DBNull.Value || denom == null || denom.ToString() == "")
                    {
                        err           += " Regione fiscale non valorizzata ma obbligatoria";;
                        ErrCell.Value2 = err;
                        nrigacorrente++;
                        ok = false;
                    }
                    else
                    {
                        bool found = CheckRegione(denom.ToString().Trim(), out errore, cod_catastale, out o_codice_regione);

                        if ((!found) && (errore != ""))
                        {
                            err           += " " + errore;
                            ErrCell.Value2 = err;
                            nrigacorrente++;
                            ok = false;
                            continue;
                        }
                    }
                }
                if ((CfgFn.GetNoNullInt32(o_anno_rif) <= CfgFn.GetNoNullInt32(Meta.GetSys("esercizio")) - 10) ||
                    (CfgFn.GetNoNullInt32(o_anno_rif) > CfgFn.GetNoNullInt32(Meta.GetSys("esercizio"))))
                {
                    err           += " Anno di riferimento errato";
                    ErrCell.Value2 = err;
                    nrigacorrente++;
                    ok = false;
                    continue;
                }

                if ((CfgFn.GetNoNullInt32(o_mese_rif) <= 0) || (CfgFn.GetNoNullInt32(o_mese_rif) > 12))
                {
                    err           += " Mese di riferimento errato";
                    ErrCell.Value2 = err;
                    nrigacorrente++;
                    ok = false;
                    continue;
                }
                if (CfgFn.GetNoNullDecimal(o_importoadebito) < 0)
                {
                    errore = " Valore non previsto per il campo importo a debito" + " di valore " +
                             o_importoadebito.ToString().Trim() + " : inserire un importo maggiore di zero";
                    err           += " " + errore;
                    ErrCell.Value2 = err;
                    nrigacorrente++;
                    ok = false;
                    continue;
                }
                if (CfgFn.GetNoNullDecimal(o_importoadebito) < 0)
                {
                    errore = " Valore non previsto per il campo importo a credito" + " di valore " +
                             o_importoadebito.ToString().Trim() + " : inserire un importo maggiore di zero";
                    err           += " " + errore;
                    ErrCell.Value2 = err;
                    nrigacorrente++;
                    ok = false;
                    continue;
                }


                if (!ok)  //shouldn't happen
                {
                    ErrCell.Value2 = err;
                    nrigacorrente++;
                    continue;
                }

                if (ok)
                {
                    DataRow[] tributo = tributi.Select(QHC.CmpEq("cod_tributo", cod_tributo));
                    if (tributo.Length == 1)
                    {
                        // ricerca in mData se c'è già una riga

                        string filterRow = QHC.AppAnd(QHC.CmpEq("codicetributo", cod_tributo),
                                                      QHC.CmpEq("riferimentoB", getStringaDiLunghezzaN(o_anno_rif, 4)));

                        if ((cod_tributo == "384E") || (cod_tributo == "385E") || (cod_tributo.ToUpper() == "127E") || (cod_tributo.ToUpper() == "128E"))
                        {
                            filterRow = QHC.AppAnd(filterRow, QHC.CmpEq("codice", o_cod_catastale));
                        }
                        else
                        {
                            filterRow = QHC.AppAnd(filterRow, QHC.CmpEq("codice", o_codice_regione));
                        };                                                                              // 381E

                        if (CfgFn.GetNoNullInt32(o_mese_rif) > 9)
                        {
                            filterRow = QHC.AppAnd(filterRow, QHC.CmpEq("riferimentoA", "00" + getStringaDiLunghezzaN(o_mese_rif, 2)));
                        }
                        else
                        {
                            filterRow = QHC.AppAnd(filterRow, QHC.CmpEq("riferimentoA", "000" + getStringaDiLunghezzaN(o_mese_rif, 2)));
                        };                                                                                                                 // 381E

                        DataRow[] mDataRow = mData.Select(filterRow);
                        if (mDataRow.Length > 0)
                        {
                            DataRow dr = mDataRow[0];
                            dr["importoadebito"]  = CfgFn.GetNoNullDecimal(dr["importoadebito"]) + CfgFn.GetNoNullDecimal(o_importoadebito);
                            dr["importoacredito"] = CfgFn.GetNoNullDecimal(dr["importoacredito"]) + CfgFn.GetNoNullDecimal(o_importoacredito);
                        }
                        else
                        {
                            DataRow dr;
                            dr                  = mData.NewRow();
                            dr["tiporiga"]      = tributo[0]["tiporiga"];
                            dr["estremi"]       = DBNull.Value;
                            dr["codicetributo"] = cod_tributo;
                            if ((cod_tributo == "384E") || (cod_tributo == "385E") || (cod_tributo.ToUpper() == "127E") || (cod_tributo.ToUpper() == "128E"))
                            {
                                dr["codice"] = o_cod_catastale;
                            }
                            else
                            {
                                dr["codice"] = o_codice_regione; // 381E
                            }
                            if (CfgFn.GetNoNullInt32(o_mese_rif) > 9)
                            {
                                dr["riferimentoA"] = "00" + getStringaDiLunghezzaN(o_mese_rif, 2);
                            }
                            else
                            {
                                dr["riferimentoA"] = "000" + getStringaDiLunghezzaN(o_mese_rif, 2);
                            }

                            dr["riferimentoB"] = getStringaDiLunghezzaN(o_anno_rif, 4);

                            dr["importoadebito"]  = o_importoadebito;
                            dr["importoacredito"] = CfgFn.GetNoNullDecimal(o_importoacredito);
                            mData.Rows.Add(dr);
                        }
                    }
                }
                nrigacorrente++;
            }
            if (ok)
            {
                MessageBox.Show(this, "Elaborate " + nrigacorrente.ToString() + " righe.");
            }
            return(ok);
        }
Beispiel #27
0
        private void GeneraFileUltimaDistinta(bool Mandati)
        {
            DataRow rTesoriere = HelpForm.GetLastSelected(DS.treasurer);

            if (rTesoriere == null)
            {
                HelpForm.FocusControl(cmbIstitutoCassiere);
                MessageBox.Show(this, "Scegliere l'istituto cassiere");
                return;
            }
            string sp_export = Mandati ? rTesoriere["spexportexp"].ToString() : rTesoriere["spexportinc"].ToString();

            if (sp_export == "")
            {
                MessageBox.Show(this,
                                "Nella configurazione del tesoriere non è impostata la sp da chiamare per generare il file");
                return;
            }

            string Filter = "";
            int    nDoc   = 0;

            if (Mandati)
            {
                Filter = QHS.AppAnd(QHS.CmpEq("ypaymenttransmission", Meta.GetSys("esercizio")),
                                    QHS.CmpEq("idtreasurer", rTesoriere["idtreasurer"]));
                nDoc =
                    CfgFn.GetNoNullInt32(Meta.Conn.DO_READ_VALUE("paymenttransmission", Filter,
                                                                 "MAX(npaymenttransmission)"));
            }
            else
            {
                Filter = QHS.AppAnd(QHS.CmpEq("yproceedstransmission", Meta.GetSys("esercizio")),
                                    QHS.CmpEq("idtreasurer", rTesoriere["idtreasurer"]));
                nDoc =
                    CfgFn.GetNoNullInt32(Meta.Conn.DO_READ_VALUE("proceedstransmission", Filter,
                                                                 "MAX(nproceedstransmission)"));
            }
            if (nDoc == 0)
            {
                MessageBox.Show(this, "Non vi sono distinte.");
                return;
            }

            object[] parametri = new object[] { Meta.GetSys("esercizio"), nDoc };
            DataSet  result    = Meta.Conn.CallSP(sp_export, parametri, false, 300);

            if ((result == null) || (result.Tables.Count == 0))
            {
                MessageBox.Show(this, "La sp non ha restituito risultati");
                return;
            }
            DataTable t = result.Tables[0];

            dataGrid1.TableStyles.Clear();
            dataGrid1.DataSource = null;
            if (t.Columns.Contains("message"))
            {
                t.Columns["message"].Caption = "Spiegazione errore";
                HelpForm.SetDataGrid(dataGrid1, t);
                formatgrids FF = new formatgrids(dataGrid1);
                FF.AutosizeColumnWidth();
                MessageBox.Show(this, "Ci sono degli errori, pertanto non è stato generato il file!");
                return;
            }
            if (txtCartella.Text == "")
            {
                DialogResult dr = folderBrowserDialog1.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    txtCartella.Text = folderBrowserDialog1.SelectedPath;
                }
                else
                {
                    folderBrowserDialog1.SelectedPath = txtCartella.Text;
                    HelpForm.FocusControl(txtCartella);
                    MessageBox.Show(this, "Specificare il percorso del file");
                    return;
                }
            }

            string nomeFile = Mandati
                ? Meta.GetSys("esercizio") + "_mandato" + "_" + nDoc
                : Meta.GetSys("esercizio") + "_reversale" + "_" + nDoc;

            txtFile.Text = Path.Combine(txtCartella.Text, nomeFile + "." + fileExtension);
            try {
                StreamWriter sw = new StreamWriter(txtFile.Text, false, Encoding.Default);
                foreach (DataRow r in t.Rows)
                {
                    sw.WriteLine(r[0]);
                }
                sw.Flush();
                sw.Close();
                sw.Dispose();
            }
            catch (Exception e1) {
                QueryCreator.ShowException("Errore nel salvataggio del file " + txtFile.Text, e1);
                return;
            }
            MessageBox.Show(this, "File della trasmissione salvato in " + txtFile.Text);
        }