Esempio n. 1
0
        void ConnectToDepartment(string codice, string user, string pwd, DateTime datacontabile)
        {
            string     error;
            DataAccess Conn   = GetVars.GetSystemDataAccess(this, out error);
            MetaMaster master = Page.Master as MetaMaster;

            master?.setUniversita(Session["system_config_nome_universita"] as string);

            if (codice.Trim().Length == 0)
            {
                labExtMessage.Text = "Non è stato selezionato alcun dipartimento";
                return;
            }
            //Attenzione: leggere da XML IP del server e NomeDB
            //Inserire da codice NomeUtente e Password
            string    filterdip = "(codicedipartimento=" + QueryCreator.quotedstrvalue(codice, true) + ")";
            DataTable CodDip    = Conn.RUN_SELECT("codicidipartimenti", "*", null, filterdip, null, true);

            if ((CodDip == null) || (CodDip.Rows.Count == 0))
            {
                //Dati non corretti
                WebLog.Log(this, codice + ": Codice non corretto");
                labExtMessage.Text = "Il codice inserito non è corretto.";
                return;
            }
            if (CodDip.Rows.Count > 1)
            {
                //Attenzione nel DB non è garantita l'unicità dei dati.
                labExtMessage.Text = "Chiedere al Responsabile del servizio " +
                                     "l'assegnazione di un nuovo Codice";
                WebLog.Log(this, "Attenzione !!! Duplicazione di codici per " + codice);
                return;
            }

            string  err  = "";
            DataRow myDr = CodDip.Rows[0];

            Session["Dipartimento"] = myDr["Dipartimento"].ToString();


            //Creo la connessione.
            DataAccess UsrConn = GetVars.CreateUserConn(this, myDr, user, pwd, datacontabile, out err);

            if (UsrConn == null)
            {
                err = "Connessione per l'utente '" + user + "' rifiutata. Controllare Nome Utente e/o Password";
                string err2 = "Connessione al db del dipartimento " + codice +
                              " non riuscita. <br/>" + err;
                labExtMessage.Text = err2;
                WebLog.Log(this, err2);
                return;
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            string  FileName;
            DataRow Rep = Session["ExportRow"] as DataRow;

            if (Rep == null)
            {
                return;
            }

            string MyGuid = Session.SessionID.ToString();
            string str;

            str = DateTime.Now.ToString();
            str = str.Replace("/", "");
            str = str.Replace(".", "");
            str = str.Replace(" ", "");
            //Costruisce il nome del File (AnnoMeseGiornoOraMinutiSecondi)
            //FileName = str.Substring(4,4) + str.Substring(2,2) + str.Substring(0,2) + "h" + str.Substring(8,str.Length - 8);
            string prefix = Session["TipoUtente"] as String;

            if (prefix == "fornitore")
            {
                prefix += "-" + Session["CodiceFornitore"].ToString();
            }
            if (prefix == "responsabile")
            {
                prefix += "-" + Session["CodiceResponsabile"].ToString();
            }
            prefix = GetVars.GetUsrVar(this, "CodiceDipartimento").ToString() + "-" + prefix + "-";
            prefix = prefix.Replace("\\", "");
            prefix = prefix.Replace("/", "");
            prefix = prefix.Replace("*", "");
            prefix = prefix.Replace("?", "");
            prefix = prefix.Replace("$", "");
            prefix = prefix.Replace("%", "");

            MetaMaster MM = Master as MetaMaster;


            FileName = prefix + Rep["procedurename"].ToString() + "-" + System.Guid.NewGuid().ToString();

            DataTable UserPar = (DataTable)Session["UserPar"];

            if (UserPar == null)
            {
                return;
            }
            DataRow Par = UserPar.Rows[0];
            string  errmess;

            Easy_DataAccess Conn = GetVars.GetUserConn(this);


            // Restituisce il percorso fisico locale della cartella ReportPDF  ex: c:\inetpub\wwwroot\.....
            string FilePath = this.MapPath("ReportPDF");

            if (!FilePath.EndsWith("\\"))
            {
                FilePath += "\\";
            }

            string filenametodelete = FilePath + prefix + "*.*";

            string  [] existingreports = System.IO.Directory.GetFiles(
                FilePath, prefix + "*.*");
            foreach (string filename in existingreports)
            {
                System.IO.File.Delete(filename);
            }
            string fileFormat = Rep["fileformat"].ToString();
            string extension  = "";

            switch (fileFormat)
            {
            case "F":
                extension = ".txt";
                break;

            case "T":
                extension = ".txt";
                break;

            case "C":
                extension = ".csv";
                break;

            case "E":
                extension = ".xlsx";
                break;
            }

            string PDFfilePathRedir =   //FilePath +
                                      "ReportPDF/" +
                                      FileName + extension;
            string PDFfilePathToCreate = FilePath +
                                         FileName + extension;


            int          count           = 0;
            const string DummyPrimaryKey = "DummyPrimaryKeyField";
            const string DummyField      = "reportname";


            object[] ReportParams = new object[UserPar.Columns.Count - 2];
            foreach (DataColumn C in UserPar.Columns)
            {
                string colname = C.ColumnName;
                if (colname == DummyPrimaryKey)
                {
                    continue;
                }
                if (colname == DummyField)
                {
                    continue;
                }
                bool Convert = (bool)C.ExtendedProperties["ConvertNullToPerc"];
                Type tipo    = Par.Table.Columns[colname].DataType;
                if (Convert && (tipo == typeof(string)) && (Par[colname].ToString() == ""))
                {
                    Par[colname] = "%";
                }
                ReportParams[count++] = Par[colname];
            }

            int timeout = 300;

            try {
                if (Rep["timeout"] != DBNull.Value)
                {
                    timeout = Convert.ToInt32(
                        Rep["timeout"]) * 60;
                    if (timeout == 0)
                    {
                        timeout = 300;
                    }
                }
            }
            catch {
            }
            string  ExportName = Rep["procedurename"].ToString();
            DataSet Out        = Conn.CallSP(ExportName, ReportParams, true, timeout);


            if ((Out == null) || (Out.Tables.Count == 0))
            {
                string mym = "La stored procedure " + ExportName +
                             " è stata valutata e non ha restituito alcun risultato.";
                //MM.ShowClientMessage(mym, "Avviso",  System.Windows.Forms.MessageBoxButtons.OK);
                Session["CloseWindow"] = true;
                Session["Messaggio"]   = mym;


                Response.Redirect("Messaggio.aspx");
                return;
            }
            if (Out.Tables[0].Rows.Count == 0)
            {
                string mym = "La stored procedure " + ExportName +
                             " è stata valutata e non ha restituito alcun risultato.";
                //MM.ShowClientMessage(mym, "Avviso",       System.Windows.Forms.MessageBoxButtons.OK);

                Session["CloseWindow"] = true;
                Session["Messaggio"]   = mym;
                Session["UserPar"]     = null;
                Session["ExportRow"]   = null;

                Response.Redirect("Messaggio.aspx");
                return;
            }

            DataTable OutTable = Out.Tables[0];

            OutTable.TableName = Rep["description"].ToString();

            string result = null;

            switch (fileFormat)
            {
            case "F": metadatalibrary.exportclass.dataTableToFixedLengthFile(OutTable, false, PDFfilePathToCreate); break;

            case "T": metadatalibrary.exportclass.dataTableToTabulationSeparatedValues(OutTable, false, PDFfilePathToCreate); break;

            case "C": metadatalibrary.exportclass.dataTableToCommaSeparatedValues(OutTable, false, PDFfilePathToCreate); break;

            case "E": result = metadatalibrary.exportclass.DataTableToExcel(OutTable, true, null, null,
                                                                            PDFfilePathToCreate);
                break;
            }
            if (!string.IsNullOrEmpty(result))
            {
                Session["Messaggio"] = result;
                //MM.ShowClientMessage(result, "Avviso", System.Windows.Forms.MessageBoxButtons.OK);
                Session["CloseWindow"] = true;
                Response.Redirect("Messaggio.aspx");
                return;
            }
            //Visualizza il Report in formato PDF
            //WebLog.Log(this,"Visualizza il file in formato PDF");
            Response.Clear();

            Session["UserPar"]   = null;
            Session["ExportRow"] = null;
            Response.Redirect(PDFfilePathRedir);
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Master.SetTitle("WebEasy - Accesso Servizi Dipartimento  ");
            lblMessaggio.Text  = "";
            labExtMessage.Text = "";
            error_dep          = false;
            if (!Page.IsPostBack || Page.Session.IsNewSession)
            {
                Session["utente"]             = "";
                Session["Responsabile"]       = "";
                Session["Fornitore"]          = "";
                Session["CodiceResponsabile"] = null;
                Session["CodiceFornitore"]    = null;
            }
            if (Request != null)
            {
                if (Request.Params["x"] != null && Request.Params["x"].ToString() != "")
                {
                    Session["DepCode"] = Request.Params["x"];
                }
            }
            if (Session["DepCode"] == null || Session["DepCode"].ToString() == "")
            {
                lblMessaggio.Text = "E' necessario chiamare la pagina magazzino_out.aspx con il parametro dep=codice dipartimento";
                WebLog.Log(this, "Parametro dep non fornito.");
                error_dep = true;
                return;
            }

            //if (Session["DoLogon"] == null || !((bool)Session["DoLogon"])) {
            //    lblMessaggio.Text = "Applicazione non inizializzata correttamente.";
            //    WebLog.Log(this, "Applicazione non inizializzata correttamente.");
            //    return;
            //}

            DataSet Cfg = GetVars.GetConfigDataSet(this);

            if (Cfg.Tables[0].Rows.Count == 0)
            {
                lblMessaggio.Text = "Servizio non installato correttamente. Manca il file di configurazione.";
                WebLog.Log(this, "Connessione al db di sistema non riuscita.");
                return;
            }
            MetaMaster MM = Master as MetaMaster;
            //if (MM != null) MM.ShowClientMessage("NINO", false);

            string error;

            DataAccess Conn = GetVars.GetSystemDataAccess(this, out error);

            if (Conn == null)
            {
                //lblMessaggio.Text = "Connessione al DB di sistema non riuscita." + error;
                //Attenzione qui l'errore contiene la password del Database !
                lblMessaggio.Text = "Connessione al DB di sistema non riuscita.";
                WebLog.Log(this, "Connessione al db di sistema non riuscita.");
                return;
            }
            lblMessaggio.Text = "Il servizio Web è attivo";
            GetVars.ClearUserConn(this);
        }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Master.SetTitle("WebEasy - Accesso Servizi Dipartimento  ");
            lblMessaggio.Text  = "";
            labExtMessage.Text = "";



            if (!Page.IsPostBack || Page.Session.IsNewSession)
            {
                Session["utente"]             = "";
                Session["Responsabile"]       = "";
                Session["Fornitore"]          = "";
                Session["CodiceResponsabile"] = null;
                Session["CodiceFornitore"]    = null;
            }

            if (Request != null)
            {
                if (Request.Params["x"] != null && Request.Params["x"].ToString() != "")
                {
                    Session["DepCode"] = Request.Params["x"];
                }
            }

            if (Session["DepCode"] == null || Session["DepCode"].ToString() == "")
            {
                lblMessaggio.Text = "E' necessario chiamare la pagina magazzino_in.aspx con il parametro dep=codice dipartimento";
                WebLog.Log(this, "Parametro dep non fornito.");
                return;
            }

            //if (Session["DoLogon"] == null || !((bool)Session["DoLogon"])) {
            //    lblMessaggio.Text = "Applicazione non inizializzata correttamente.";
            //    WebLog.Log(this, "Applicazione non inizializzata correttamente.");
            //    return;
            //}

            DataSet Cfg = GetVars.GetConfigDataSet(this);

            if (Cfg.Tables[0].Rows.Count == 0)
            {
                lblMessaggio.Text = "Servizio non installato correttamente. Manca il file di configurazione.";
                WebLog.Log(this, "Connessione al db di sistema non riuscita.");
                return;
            }
            MetaMaster MM = Master as MetaMaster;
            //if (MM != null) MM.ShowClientMessage("NINO", false);

            string error;

            DataAccess Conn = GetVars.GetSystemDataAccess(this, out error);

            if (Conn == null)
            {
                //lblMessaggio.Text = "Connessione al DB di sistema non riuscita." + error;
                //Attenzione qui l'errore contiene la password del Database !
                lblMessaggio.Text = "Connessione al DB di sistema non riuscita.";
                WebLog.Log(this, "Connessione al db di sistema non riuscita.");
                return;
            }
            lblMessaggio.Text = "Il servizio Web è attivo";
            GetVars.ClearUserConn(this);
            MetaMaster master = Page.Master as MetaMaster;

            master?.setUniversita(Session["system_config_nome_universita"] as string);

            if (!Page.IsPostBack)
            {
                ldapauth ldpauth = new ldapauth(Conn);
                if (!ldpauth.getconfig())
                {
                    rbTipuUtente.Items.RemoveAt(3);
                }
            }

            //WebLog.Log(this, "Visualizza Login_Servizi");

            DateTime D = DateTime.Now;

            if (IsPostBack)
            {
                if (txtNomeUtente.Text == "")
                {
                    lblMessaggio.Text = "Il nome utente è un campo obbligatorio.";
                    //MM.ShowClientMessage("Il nome utente è un campo obbligatorio.", "Errore",
                    //          System.Windows.Forms.MessageBoxButtons.OK);

                    return;
                }
                if (txtPassword.Text == "")
                {
                    lblMessaggio.Text = "La password è un campo obbligatorio.";
                    //MM.ShowClientMessage("La password è un campo obbligatorio.", "Errore",
                    //        System.Windows.Forms.MessageBoxButtons.OK);

                    return;
                }
            }

            if (IsPostBack && Request != null)
            {
                //Cerco prima nella tabella contatto e poi nella tabella responsabile.
                string NomeUtente = txtNomeUtente.Text;
                string Password   = txtPassword.Text; // Request.Form["txtPassword"].ToString();

                if (rbTipuUtente.SelectedValue == "1" || rbTipuUtente.SelectedValue == "2")
                {
                    //Responsabile o Fornitore
                    ConnectToDepartment(Session["DepCode"].ToString(), null, null, D);
                }

                if (rbTipuUtente.SelectedValue == "3")  //Utente dell'applicazione
                {
                    ConnectToDepartment(Session["DepCode"].ToString(), NomeUtente, txtPassword.Text, D);
                }

                bool ldapauthok = false;

                if (rbTipuUtente.SelectedValue == "4")   // Utente LDAP
                {
                    ldapauth lauth = new ldapauth(Conn);
                    if (!lauth.getconfig())
                    {
                        // Nessuna configurazione LDAP
                        lblMessaggio.Text = lauth.ErrorMsg;
                        return;
                    }
                    else
                    {
                        if (!lauth.Authenticate(NomeUtente, txtPassword.Text))
                        {
                            // autenticazione fallita
                            lblMessaggio.Text = lauth.ErrorMsg;
                            return;
                        }
                        else
                        {
                            // autenticazione LDAP riuscita
                            NomeUtente = lauth.user_decoded;
                            ConnectToDepartment(Session["DepCode"].ToString(), null, null, D);
                            ldapauthok = true;
                        }
                    }
                }



                //Connessione al Server.Database privato del software.
                Easy_DataAccess UsrConn = GetVars.GetUserConn(this);

                if (UsrConn == null)
                {
                    return;                  //Messaggio già viualizzato da ConnectToDepartment()
                }
                QueryHelper QHS = UsrConn.GetQueryHelper();



                string user     = null;
                string forename = null;
                string lastname = null;
                string cf       = null;
                string email    = null;



                if (rbTipuUtente.SelectedValue == "3")
                {
                    if (!CambioDataConsentita(UsrConn, D))
                    {
                        UsrConn.Close();
                        labExtMessage.Text = "Accesso non consentito in tale data \rin base alla gestione della sicurezza.";
                        //                        MM.ShowClientMessage("Accesso non consentito in tale data in base alla gestione della sicurezza.", "Errore",
                        //                                  System.Windows.Forms.MessageBoxButtons.OK);
                        lblMessaggio.Text = "Accesso negato";
                        return;
                    }
                }
                if (UsrConn.Open() == false)
                {
                    //Il Server del Dipartimento non è in rete.
                    //Il servizio non è disponibile in quanto il computer potrebbe essere spento.
                    labExtMessage.Text = "Il Server del Dipartimento non risponde.\r" +
                                         "Potrebbe essere spento o momentaneamente fuori rete. \r" +
                                         "Provi in seguito";
                    txtNomeUtente.ReadOnly = true;
                    WebLog.Log(this, "Il Server del dipartimento non risponde.");
                    return;
                }

                UsrConn.Close();
                Meta_EasyDispatcher Disp = new Meta_EasyDispatcher(UsrConn);
                ApplicationState    APS  = new ApplicationState(Disp, UsrConn);

                string path     = this.MapPath(".");
                string filename = Path.Combine(path, "proxyserver.html");
                if (File.Exists(filename))
                {
                    StreamReader SR      = new StreamReader(filename);
                    string       webauth = SR.ReadToEnd();
                    webauth          = webauth.Replace("\n", "").Replace("\r", "").Trim();
                    APS.webautorithy = webauth;
                    SR.Close();
                }


                APS.SaveApplicationState(this);
                labExtMessage.Text = "Connessione al server effettuata.";

                if (rbTipuUtente.SelectedValue == "1")
                {
                    int countresp = UsrConn.RUN_SELECT_COUNT("manager",
                                                             QHS.CmpEq("userweb", NomeUtente), false);
                    if (countresp > 1)
                    {
                        lblMessaggioPass.Text = "Chiedere al Segreterio Amministrativo l'assegnazione di una nuova login";
                        WebLog.Log(this, "Attenzione !!! Login assegnata a piu responsabili");
                        return;
                    }
                    DataTable Responsabile = UsrConn.RUN_SELECT("manager", "*", null,
                                                                QHS.AppAnd(QHS.CmpEq("userweb", NomeUtente), QHS.CmpEq("passwordweb", Password)), null, false);
                    if (Responsabile.Rows.Count == 0)
                    {
                        //Dati non corretti
                        labExtMessage.Text = "Nome utente o password non sono corretti.";
                        WebLog.Log(this, "Nome Resp:" + NomeUtente + " e password:"******" non corretti");
                        return;
                    }
                    Session["LoginResponsabile"]    = NomeUtente;
                    Session["PasswordResponsabile"] = Password;
                    Session["Responsabile"]         = Responsabile.Rows[0]["title"].ToString();
                    Session["CodiceResponsabile"]   = Responsabile.Rows[0]["idman"];
                    Session["TipoUtente"]           = "responsabile";
                    WebLog.Log(this, "Riconosciuto responsabile: " + Session["Responsabile"].ToString());
                }

                if (rbTipuUtente.SelectedValue == "2")
                {
                    int countforn = UsrConn.RUN_SELECT_COUNT("registryreferenceview",
                                                             QHS.CmpEq("userweb", NomeUtente), false);
                    if (countforn > 1)
                    {
                        lblMessaggioPass.Text = "Chiedere al Segreterio Amministrativo l'assegnazione di una nuova login";
                        WebLog.Log(this, "Attenzione !!! Login assegnata a piu fornitori");
                        return;
                    }
                    DataTable Contatto = UsrConn.RUN_SELECT("registryreferenceview", "*", null,
                                                            QHS.AppAnd(QHS.CmpEq("userweb", NomeUtente), QHS.CmpEq("passwordweb", Password)), null, false);
                    if (Contatto.Rows.Count == 0)
                    {
                        //Dati non corretti
                        labExtMessage.Text = "Nome utente o password non sono corretti.";
                        WebLog.Log(this, "Nome Fornitore:" + NomeUtente + " e password:"******" non corretti");
                        return;
                    }

                    Session["LoginFornitore"]    = NomeUtente;
                    Session["Fornitore"]         = Contatto.Rows[0]["registry"];
                    Session["CodiceFornitore"]   = Contatto.Rows[0]["idreg"];
                    Session["PasswordFornitore"] = Password;
                    Session["TipoUtente"]        = "fornitore";
                    WebLog.Log(this, "Riconosciuto fornitore: " + Session["Fornitore"].ToString());
                }

                if (rbTipuUtente.SelectedValue == "3")
                {
                    Session["TipoUtente"]     = "utente";
                    Session["Utente"]         = NomeUtente;
                    Session["PasswordUtente"] = Password;
                }

                if (ldapauthok || (rbTipuUtente.SelectedValue == "1") ||
                    (rbTipuUtente.SelectedValue == "2") || (rbTipuUtente.SelectedValue == "3"))
                {
                    int    userkind = Convert.ToInt32(rbTipuUtente.SelectedValue);
                    string filter   = QHS.AppAnd(QHS.CmpEq("username", NomeUtente),
                                                 QHS.CmpEq("codicedipartimento", Session["DepCode"].ToString()),
                                                 QHS.CmpEq("userkind", userkind)
                                                 );
                    // prelevare l'idflowchart e poi fare la connecttodepartment
                    DataTable virtualuser = Conn.RUN_SELECT("virtualuser", "*", null, filter, null, false);
                    if (virtualuser != null && virtualuser.Rows.Count != 0)
                    {
                        user     = virtualuser.Rows[0]["sys_user"].ToString();
                        forename = virtualuser.Rows[0]["forename"].ToString();
                        lastname = virtualuser.Rows[0]["surname"].ToString();
                        email    = virtualuser.Rows[0]["email"].ToString();
                        cf       = virtualuser.Rows[0]["cf"].ToString();

                        UsrConn.SetUsr("HasVirtualUser", "S");
                        // Controllare se è anche un responsabile
                        // Vediamo se esiste un manager il cui login="******"
                        // se si, assegnamo le due variabili di responsabile come
                        // nel caso "2"
                        filter = QHS.CmpEq("userweb", virtualuser.Rows[0]["username"].ToString());
                        DataTable manager = UsrConn.RUN_SELECT("manager", "*", null, filter, null, false);
                        if (manager != null && manager.Rows.Count != 0)
                        {
                            Session["Responsabile"]       = manager.Rows[0]["title"].ToString();
                            Session["CodiceResponsabile"] = manager.Rows[0]["idman"];
                        }

                        EasySecurity sec = UsrConn.Security as EasySecurity;
                        UsrConn.externalUser = NomeUtente;
                        sec.SetSys("user", user);
                        sec.SetUsr("usergrouplist", null);
                        sec.CalculateGroupList();
                        sec.RecalcUserEnvironment();
                        sec.ReadAllGroupOperations();
                        sec.SetUsr("forename", forename);
                        sec.SetUsr("surname", lastname);
                        sec.SetUsr("email", email);
                        sec.SetUsr("cf", cf);
                        if (!CambioDataConsentita(UsrConn, D))
                        {
                            labExtMessage.Text = "Accesso non consentito in tale data \rin base alla gestione della sicurezza.";
                            lblMessaggio.Text  = "Accesso negato";
                            return;
                        }
                    }
                    else
                    {
                        if (ldapauthok)
                        {
                            lblMessaggio.Text = "Utente non valido.";
                            return;
                        }
                    }
                }



                if (rbTipuUtente.SelectedValue == "4")
                {
                    Session["TipoUtente"]     = "Utente LDAP";
                    Session["Utente"]         = forename + " " + lastname;
                    Session["PasswordUtente"] = Password;
                }

                StampaReport(UsrConn, cf);


                //Response.Redirect("IndiceReport.aspx");
            }
        }