Exemple #1
0
        bool AggiungiLogin(string login, string password)
        {
            //DataTable T1 = Conn.SQLRunner(
            //    "select DISTINCT loginname = (case when (o.sid = 0x00) then NULL else l.loginname end) " +
            //    " from dbo.sysusers o " +
            //    "left join master.dbo.syslogins l on l.sid = o.sid " +
            //    "where ((o.issqlrole != 1 and o.isapprole != 1 ) or (o.sid = 0x00) " +
            //    "and o.hasdbaccess = 1)and o.isaliased != 1 ");

            DataTable T1 = Conn.SQLRunner(
                "select DISTINCT loginname from master.dbo.syslogins " +
                "where hasaccess = 1 and isntgroup=0");



            //esce se la login è già presente
            if (T1 != null)
            {
                foreach (DataRow R1 in T1.Rows)
                {
                    if (R1["loginname"].ToString().ToUpper() == login.ToUpper())
                    {
                        return(true);
                    }
                }
            }

            string err;
            string dbname = Conn.GetSys("database").ToString();

            Conn.DO_SYS_CMD(//"EXEC sp_addlogin " + QHS.quote(login)+","+QHS.quote(password)
                "CREATE LOGIN [" + login + "] WITH PASSWORD="******"," +
                "DEFAULT_DATABASE = " + dbname + "," +
                "CHECK_EXPIRATION = OFF," +
                "CHECK_POLICY = OFF"
                , out err);
            if (err != null)
            {
                MessageBox.Show("Errore creando la login " + login + ": " + err);
                return(false);
            }
            return(true);
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string FileName;
            string cmd   = Session["AttachmentCommand"] as string;
            string fname = Session["AttachmentFileName"] as string;

            if (cmd == 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("%", "");


            FileName = prefix + "-" + System.Guid.NewGuid().ToString() + fname;

            string errmess;

            Easy_DataAccess Conn = GetVars.GetUserConn(this);
            object          doc  = Conn.DO_SYS_CMD(cmd, true);



            if (doc == null || doc == DBNull.Value)
            {
                Session["Messaggio"]          = "Documento non trovato";
                Session["CloseWindow"]        = true;
                Session["AttachmentCommand"]  = null;
                Session["AttachmentFileName"] = null;
                Response.Redirect("Messaggio.aspx");
                return;
            }


            // 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 PDFfilePathRedir =   //FilePath +
                                      "ReportPDF/" +
                                      FileName;

            string     sw = Path.Combine(FilePath, FileName);
            FileStream FS = new FileStream(sw, FileMode.Create, FileAccess.Write);

            byte[] ByteArray = (byte[])doc;

            int n = ByteArray.Length;

            if (n == 0)
            {
                Session["Messaggio"]          = "Documento non trovato";
                Session["CloseWindow"]        = true;
                Session["AttachmentCommand"]  = null;
                Session["AttachmentFileName"] = null;
                Response.Redirect("Messaggio.aspx");
                return;
            }

            try {
                FS.Write(ByteArray, 0, n);//<<<<<<<<<
                FS.Flush();
                FS.Close();
            }
            catch {
                string mym = "Non è stato possibile completare il salvataggio del file. \r";
                Session["CloseWindow"] = true;
                Session["Messaggio"]   = mym;
                Response.Redirect("Messaggio.aspx");
                return;
            }
            //Visualizza il Report in formato PDF
            //WebLog.Log(this,"Visualizza il file in formato PDF");
            Session["AttachmentCommand"]  = null;
            Session["AttachmentFileName"] = null;

            Response.Redirect(PDFfilePathRedir);
        }