Friday, November 27, 2015

sql server mail notification automation command

USE [master]
GO
sp_configure 'show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'Database Mail XPs',1
GO
RECONFIGURE 
GO
-- Create a New Mail Profile for Notifications
EXECUTE msdb.dbo.sysmail_add_profile_sp
       @profile_name = 'DBA_Notifications',
       @description = 'Profile for sending Automated DBA Notifications'
GO
-- Set the New Profile as the Default
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'DBA_Notifications',
    @principal_name = 'public',
    @is_default = 1 ;
GO
-- Create an Account for the Notifications
EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'SQLMonitor',
    @description = 'Account for Automated DBA Notifications',
    @email_address = 'email@domain.com',  -- Change This
    @display_name = 'SQL Monitor',
    @mailserver_name = 'smtp.domain.com'  -- Change This
GO
-- Add the Account to the Profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'DBA_Notifications',
    @account_name = 'SQLMonitor',
    @sequence_number = 1
GO

ASP.NET SocialShare Demo - Compact popup

ASP.NET SocialShare Demo - Compact popup

Thursday, November 26, 2015

session state sql server session installation

http://support.microsoft.com/kb/317604

Steps to activate sql server session state

-for application server IIS Server
- Enable Service ASP.NET State Service
-Restart IIS


for DB server -
open command prompt as administrator
rutn this command


C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe -S . -E -ssadd -sstype p
for your application write the connection string related session

<system.web>
    <sessionState mode="SQLServer" sqlConnectionString="Data Source=sourceInstance;Persist Security Info=True;User ID=sa;Password=psw" cookieless="false" timeout="20" />







Tuesday, November 10, 2015

crystal report Print problem number of users increases or show empty report when generate to pdf

the problem 
when number of users increases when printing crystal report then empty page displayed no report data loaded for all users when trying to print the report 

solution workarround
1- increase the number of current print joblimit to -1




2- Unload report object in page unload event
 protected void Page_Unload(object sender, EventArgs e)
    {
        rdoc.Close();
        rdoc.Dispose();
    }

3- close and dispose report after perform action for exporting pdf from report.
   rdoc.Close();
            rdoc.Dispose();
            GC.Collect();
---------------------------------------------------------
example 
//global variable
  ReportDocument rdoc = new ReportDocument();



  protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["CurrentLanguage"].Value.ToString().IndexOf("en-") == -1)
            hidLang.Value = "ar";
        else
            hidLang.Value = "en";
        if (!Page.IsPostBack)
            BindReport();
    }

    protected void Page_Unload(object sender, EventArgs e)
    {
        rdoc.Close();
        rdoc.Dispose();
    }

    private void BindReport()
    {
        ConnectionInfo conInfo = new ConnectionInfo();
        try
        {
            string stageID = "0";
            DataTable table = new DataTable();
            Patient_Details pdetails = new Patient_Details(db.NullToInt(Request.QueryString["patient_No"]),hidLang.Value);
            string PATIENT_NAME = pdetails.PATIENT_NAME;
            string Nationality = pdetails.NATIONALITY;
            string Patient_Sex = pdetails.SEX;
            string PatientAge = pdetails.AGE;
            //if stageid is not nul this meaning that the report is printed from original workflow else it will be new version of existing one.
            if (Request.QueryString["stageID"] != null)
            {
                stageID = Request.QueryString["stageID"].ToString();
                //call stored procedure according to lang to get translated report or arabic one according to page default language.
                switch (hidLang.Value)
                {
                    case "en":
                        table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report_EN", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality);
                        break;
                    default:
                        table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality);
                        break;
                }
                
            }
            else
            {
                stageID = ((int)Enum_Class.MEDICAL_REPORTS_REQUEST_STATUS_Enum.Complete).ToString();
                if (Request.QueryString["VersionID"] != null)
                {
                     switch (hidLang.Value)
                {
                    case "en":
                        table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report_EN", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality, "@VERSION_ID", Request.QueryString["VERSIONID"].ToString());
                        break;
                    default:
                        table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality, "@VERSION_ID", Request.QueryString["VERSIONID"].ToString());
                        break;
                }
                }
                 
                else
                    Response.Write("Error In parameters Passed to the page , version not exist.");
            }

            if(hidLang.Value=="ar")
            rdoc.Load(Server.MapPath("~\\Reports\\Reports\\Rep_MedicalReport.rpt"));
            else
                rdoc.Load(Server.MapPath("~\\Reports\\Reports\\Rep_MedicalReport_EN.rpt"));
            rdoc.Refresh();
            rdoc.SetDataSource(table);

            //ParameterField p1 = new ParameterField();
            //ParameterField p2 = new ParameterField();
            //p1.Name = "sixty";
            //certificateNo.Name = "certificateNo";
            rdoc.SetParameterValue("Patient_Sex", Patient_Sex);
            rdoc.SetParameterValue("stageID", stageID);
            rdoc.SetParameterValue("PatientAge", PatientAge);

            Draw_CVrystal();


        }
        catch (Exception ex)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            Response.Write(ex.Message);
        }


    }
    private void Draw_CVrystal()
    {
        // throw new NotImplementedException();
        string MyFile;
        string guidname = Guid.NewGuid().ToString("N");
        MyFile = Server.MapPath(("../Reports_Print_Temp/" + (guidname + ".pdf")));
        CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
        ExportOptions CrExportOptions;
        DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
        PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
        DiskOpts.DiskFileName = MyFile;
        CrExportOptions = rdoc.ExportOptions;
        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
        CrExportOptions.ExportDestinationOptions = DiskOpts;
        CrExportOptions.ExportFormatOptions = CrFormatTypeOptions;
        try
        {
            rdoc.Export();
            UserLoginDetail udetail = (UserLoginDetail)Session["UserInfo"];
            if (udetail != null)
            {
                WF_TRANSACTIONS.WORK_FLOWS_REQUESTS_PRINT_HISTORY_INSERT(((int)Enum_Class.WORKFLOWS_Enum.Medical_Report_Request).ToString(), Request.QueryString["rid"].ToString(), udetail.UserID.ToString(), DateTime.Now);
            }
            string docUrl = "../workflows_new/Display_Report.aspx?url=../Reports_Print_Temp/" + guidname + ".pdf";
            rdoc.Close();
            rdoc.Dispose();
            GC.Collect();
            Response.Redirect(docUrl, false);
        }
        catch (Exception ex)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            Response.Write(("<br> the error is: " + ex.Message));
        }
    }







Friday, November 6, 2015

crystal report tashkeel Diacritics remove function using c# to avoid crystal report Problem


when display arabic text includes diacritics (punctuations)
it will not working if you create paragraph direction rtl support
so before passing datasource to crystal report i fixes data using this function


using System.Globalization;
using System;
using System.Data;


/// <summary>
/// the function remove all diacritics from passed text and make it on original format (no tashkeel).
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
    static string RemoveDiacritics(string text)
    {
        var normalizedString = text.Normalize(NormalizationForm.FormD);
        var stringBuilder = new StringBuilder();

        foreach (var c in normalizedString)
        {
            var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
            if (unicodeCategory != UnicodeCategory.NonSpacingMark)
            {
                stringBuilder.Append(c);
            }
        }

        return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
    }

}

---------------------------------------------------------
fix table before bind it to crystal report

  DataTable Original = this.db.ReturnTableS("CRM_Original_Offer_Load_Detail_Print", "@OfferId", Request_No);

        if (Original.Rows.Count > 0)
        {
            for (int i = 0; i < Original.Rows.Count ; i++)
            {
                Original.Rows[i]["A_Name"] = RemoveDiacritics(Original.Rows[i]["A_Name"].ToString());
            }

        }

-------------------------------------------------------------------------