Exemplo n.º 1
0
    private static void LogIt(bool emailAlso, string info, string[] logFiles, bool logSingleLine = false)
    {
        String txtOutput  = string.Empty;
        String htmlOutput = string.Empty;

        if (logSingleLine)
        {
            txtOutput  += "[" + DateTime.Now.ToString("dd MMM HH:mm:ss.fff") + "] " + info + Environment.NewLine;
            htmlOutput += "[" + DateTime.Now.ToString("dd MMM HH:mm:ss.fff") + "] " + info + Environment.NewLine;
        }
        else
        {
            System.Web.HttpContext context = System.Web.HttpContext.Current;

            string Database = System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Session == null || System.Web.HttpContext.Current.Session["DB"] == null ?  "" : System.Web.HttpContext.Current.Session["DB"].ToString();
            string ConnStr  = System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Session == null || System.Web.HttpContext.Current.Session["DB"] == null ? "" : DBBase.GetConnectionString();


            string site = System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Session == null || System.Web.HttpContext.Current.Session["SystemVariables"] == null ?
                          "" :
                          ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Site"].Value;


            string siteType = string.Empty;
            try
            {
                if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session != null && System.Web.HttpContext.Current.Session["SystemVariables"] != null)
                {
                    int siteTypeID = Convert.ToInt32(System.Web.HttpContext.Current.Session["SiteTypeID"]);
                    if (siteTypeID == 1)
                    {
                        siteType = "Clinic";
                    }
                    if (siteTypeID == 2)
                    {
                        siteType = "Aged Care";
                    }
                    if (siteTypeID == 3)
                    {
                        siteType = "GP";
                    }
                }
            }
            catch (Exception) { } // make sure this doesn't crash the logging



            // create text error output

            txtOutput += "------------------------" + Environment.NewLine;
            txtOutput += "• DateTime : " + DateTime.Now.ToString("ddd dd MMM   HH:mm:ss.fff") + ": " + Environment.NewLine;
            txtOutput += "• Machine : " + Environment.MachineName + ": " + Environment.NewLine;
            txtOutput += "• URL : " + (context != null ? context.Request.Url.AbsoluteUri : "NO URL") + ": " + Environment.NewLine;
            txtOutput += "• IP : " + (context != null ? context.Request.UserHostAddress + " (" + GetIPCountry(context.Request.UserHostAddress.ToString()) + ")" : "NO IP") + ": " + Environment.NewLine;

            try
            {
                txtOutput += "• User: [ID:] " + (context == null || context.Session["StaffID"] == null ? string.Empty : context.Session["StaffID"]) + " [Name:] " + (context == null || context.Session["StaffFullnameWithoutMiddlename"] == null ? string.Empty : context.Session["StaffFullnameWithoutMiddlename"]) + Environment.NewLine;
            }
            catch (Exception ex)
            {
                txtOutput += Environment.NewLine;
                txtOutput += Environment.NewLine;
                txtOutput += Environment.NewLine;

                txtOutput += "FAILURE TO GET USER ID AND USERNAME FROM SESSION - THREW AN ERROR:" + Environment.NewLine;
                txtOutput += ex.ToString() + Environment.NewLine;

                txtOutput += Environment.NewLine;
                txtOutput += Environment.NewLine;
                txtOutput += Environment.NewLine;
            }

            txtOutput += "• Database : " + Database + " (" + site + ")" + Environment.NewLine;
            txtOutput += "• Site     : " + siteType + Environment.NewLine;
            //txtOutput += "• ConnStr  : " + ConnStr + Environment.NewLine;
            txtOutput += "• " + DateTime.Now.ToString("dd MMM HH:mm:ss.fff") + Environment.NewLine + Environment.NewLine;
            txtOutput += info + Environment.NewLine;
            txtOutput += "------------------------" + Environment.NewLine;


            // create html error output

            htmlOutput += "<hr>" + Environment.NewLine;

            htmlOutput += "<table>" + Environment.NewLine;
            htmlOutput += "<tr><td>DateTime</td><td><b>" + DateTime.Now.ToString("ddd dd MMM   HH:mm:ss.fff") + "</b></td></tr>" + Environment.NewLine;
            htmlOutput += "<tr><td>Machine</td><td><b>" + Environment.MachineName + "</b></td></tr>" + Environment.NewLine;
            htmlOutput += "<tr><td>URL</td><td>" + (context != null ? context.Request.Url.AbsoluteUri : "NO URL") + "</td></tr>" + Environment.NewLine;
            htmlOutput += "<tr><td>IP</td><td>" + (context != null ? context.Request.UserHostAddress + " (" + GetIPCountry(context.Request.UserHostAddress.ToString()) + ")" : "NO IP") + "</td></tr>" + Environment.NewLine;

            try
            {
                htmlOutput += "<tr><td>User</td><td><b>" + (context.Session["StaffFullnameWithoutMiddlename"] == null ? string.Empty : context.Session["StaffFullnameWithoutMiddlename"]) + " [ID: " + (context.Session["StaffID"] == null ? string.Empty : context.Session["StaffID"]) + "]" + "</b></td></tr>" + Environment.NewLine;
            }
            catch (Exception ex)
            {
                htmlOutput += "<tr><td>User</td><td><font color=\"red\">" +
                              "FAILURE TO GET USER ID AND USERNAME FROM SESSION - THREW AN ERROR:<br>" + ex.ToString().Replace(Environment.NewLine, "<br />" + Environment.NewLine) +
                              "</font></td></tr>" + Environment.NewLine;
            }


            htmlOutput += "<tr><td>Database</td><td><b>" + Database + " (" + site + ")</b></td></tr>" + Environment.NewLine;
            htmlOutput += "<tr><td>Site</td><td><b>" + siteType + "</b></td></tr>" + Environment.NewLine;
            //htmlOutput += "<tr><td>ConnStr</td><td><b>" + ConnStr + "</b></td></tr>" + Environment.NewLine;
            htmlOutput += "</table>" + Environment.NewLine;
            htmlOutput += "<br /><br />" + Environment.NewLine;

            htmlOutput += info.Replace(Environment.NewLine, "<br>" + Environment.NewLine) + "<br />" + Environment.NewLine;
            htmlOutput += "<hr>" + Environment.NewLine;
        }

        foreach (string logFile in logFiles)
        {
            WriteToFile(txtOutput, logFile);
        }

        if (emailAlso)
        {
            Emailer.SimpleErrorEmail(htmlOutput, true);
        }
    }
Exemplo n.º 2
0
    public static int Insert(int letter_id, int letter_print_history_send_method_id, int booking_id, int patient_id, int organisation_id, int register_referrer_id, int staff_id, int health_card_action_id, string doc_name, byte[] doc_contents)
    {
        //string sql = "INSERT INTO LetterPrintHistory (letter_id,patient_id,organisation_id,referrer_id,staff_id) VALUES (" + "" + letter_id + "," + "" + (patient_id == -1 ? "NULL" : patient_id.ToString()) + "," + (organisation_id == 0 ? "NULL" : organisation_id.ToString()) + "," + (referrer_id == -1 ? "NULL" : referrer_id.ToString()) + "," + (staff_id == -1 ? "NULL" : staff_id.ToString()) + ");SELECT SCOPE_IDENTITY();";
        //return Convert.ToInt32(DBBase.ExecuteSingleResult(sql));

        string sql = "INSERT INTO LetterPrintHistory (letter_id,letter_print_history_send_method_id,booking_id,patient_id,organisation_id,register_referrer_id,staff_id,health_card_action_id,doc_name,doc_contents) VALUES (@letter_id, @letter_print_history_send_method_id, @booking_id, @patient_id, @organisation_id, @register_referrer_id, @staff_id, @health_card_action_id, @doc_name, @doc_contents);SELECT SCOPE_IDENTITY();";

        object result = null;

        using (System.Data.SqlClient.SqlConnection _con = new System.Data.SqlClient.SqlConnection(DBBase.GetConnectionString()))
        {
            using (System.Data.SqlClient.SqlCommand _cmd = new System.Data.SqlClient.SqlCommand(sql, _con))
            {
                System.Data.SqlClient.SqlParameter _letter_id = _cmd.Parameters.Add("@letter_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _letter_print_history_send_method_id = _cmd.Parameters.Add("@letter_print_history_send_method_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _booking_id            = _cmd.Parameters.Add("@booking_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _patient_id            = _cmd.Parameters.Add("@patient_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _organisation_id       = _cmd.Parameters.Add("@organisation_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _register_referrer_id  = _cmd.Parameters.Add("@register_referrer_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _staff_id              = _cmd.Parameters.Add("@staff_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _health_card_action_id = _cmd.Parameters.Add("@health_card_action_id", SqlDbType.Int);
                System.Data.SqlClient.SqlParameter _doc_name              = _cmd.Parameters.Add("@doc_name", SqlDbType.VarChar);
                System.Data.SqlClient.SqlParameter _doc_contents          = _cmd.Parameters.Add("@doc_contents", SqlDbType.VarBinary);

                _letter_id.Value = letter_id;
                _letter_print_history_send_method_id.Value = letter_print_history_send_method_id;
                _booking_id.Value            = booking_id == -1   ? (object)DBNull.Value : booking_id;
                _patient_id.Value            = patient_id == -1   ? (object)DBNull.Value : patient_id;
                _organisation_id.Value       = organisation_id == 0   ? (object)DBNull.Value : organisation_id;
                _register_referrer_id.Value  = register_referrer_id == -1   ? (object)DBNull.Value : register_referrer_id;
                _staff_id.Value              = staff_id == -1   ? (object)DBNull.Value : staff_id;
                _health_card_action_id.Value = health_card_action_id == -1   ? (object)DBNull.Value : health_card_action_id;
                _doc_name.Value              = doc_name;
                _doc_contents.Value          = doc_contents == null ? (object)DBNull.Value : doc_contents;

                _con.Open();
                result = _cmd.ExecuteScalar();
                _con.Close();
            }
        }

        return(Convert.ToInt32(result));
    }