Thursday, December 24, 2015
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
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
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());
}
}
-------------------------------------------------------------------------
Wednesday, November 4, 2015
crystal report problem empty report install service pack 1 for visual studio 2010
http://www.crystaladvice.com/crystalreports/crystal-reports-2010-sp1
Friday, October 30, 2015
search datatable using viewstate without go to database every postback and search using dataview filter option example using c#
first time you should fill viewstate with your database table.
public static string EscapeLikeValue(string valueWithoutWildcards)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < valueWithoutWildcards.Length; i++)
{
char c = valueWithoutWildcards[i];
if (c == '*' || c == '%' || c == '[' || c == ']')
sb.Append("[").Append(c).Append("]");
else if (c == '\'')
sb.Append("''");
else
sb.Append(c);
}
return sb.ToString();
}
---------------------------------------------private void LoadData(){try{DataTable TblSections = new DataTable();if (ViewState["Pusers"] == null){if (this.currentRequest.REQUEST_ID != null){TblSections = workflowGetData.WORK_FLOWS_PERMISSION_MANAGERIAL_GET_STAGE_USERS(this.currentRequest.WORK_FLOW_ID.ToString(), this.currentRequest.WORK_FLOW_TYPE.ToString(), this.currentRequest.CURRENT_STAGE_IDs[0].ToString(), "");ViewState["Pusers"] = TblSections;//else// TblSections = workflowGetData.WORK_FLOWS_PERMISSION_MANAGERIAL_GET_STAGE_USERS_BY_REQUEST_ID(hid_workflow_id.Value, hid_workflow_type.Value, hid_stage_id.Value, "", hid_request_id.Value);}}elseTblSections = (DataTable)ViewState["Pusers"];DataView DV = new DataView();DV = TblSections.DefaultView;if (TXT_USER_ID.Text.Length > 0)DV.RowFilter = "USER_ID=" + TXT_USER_ID.Text;if (TXT_USER_FULL_NAME.Text.Length > 0)DV.RowFilter = String.Format("emp_name LIKE '*{0}*'", EscapeLikeValue(TXT_USER_FULL_NAME.Text));GV_USERS.DataSource = TblSections;GV_USERS.DataBind();}catch (Exception ex){basepage.FormShowMessage(lblmessage, Enum_Class.MessageStatus.failure, Resources.GlobalErrorMessages.Error_GeneralException);}}
public static string EscapeLikeValue(string valueWithoutWildcards)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < valueWithoutWildcards.Length; i++)
{
char c = valueWithoutWildcards[i];
if (c == '*' || c == '%' || c == '[' || c == ']')
sb.Append("[").Append(c).Append("]");
else if (c == '\'')
sb.Append("''");
else
sb.Append(c);
}
return sb.ToString();
}
Wednesday, October 28, 2015
Json pass object to webmethod using c#
javascript function:
function Archive_insert_Save_DB(saved_Doc_Extension) {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
var datajsonparam = {
hidLibrary: $('#hidLibrary').prop('value'),
hidFormID: $("#hidFormID").prop('value'),
hidProfileID: "" + $("#hidProfileID").prop('value'),
hidDocID: $("#hidDocID").prop('value'),
hidDocName: $("#hidDocName").prop('value'),
hidIsVersion: $("#hidIsVersion").prop('value'),
hidDocComment: $("#hidDocComment").prop('value'),
hidFTPGuidName: $("#hidFTPGuidName").prop('value'),
hidUserID: $("#hidUserID").prop('value'),
HidMRTYPE: $("#HidMRTYPE").prop('value'),
hidDOC_DATE_EN: $("#hidDOC_DATE_EN").prop('value'),
hidDOC_DATE_AR: $("#hidDOC_DATE_AR").prop('value'),
saved_Doc_Extension: saved_Doc_Extension
};
$.ajax({
type: "POST",
url: "scan.aspx/Add_Document_DB_Operations",
data: JSON.stringify({ DocumentDetails: datajsonparam }),
//'{"hidLibrary" : "' + $("#hidFTPServer").prop('value') + '" ,"lang" : "' + lang + "hidLibrary" : "' + $("#hidFTPServer").prop('value') }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$("#hidDocID").val(result.d);
alert("تمت عملية الأرشفة بنجاح - Archive Operation Succeeded");
window.opener.location.reload();
window.close();
},
error: function (x, e) { alert(x.responseText); }
});
}
--------------------------------------------------------------------
[WebMethod]
public static string Add_Document_DB_Operations(DocumentDetail DocumentDetails)
{
if (DocumentDetails.hidIsVersion.Length > 0)
{
//insert document in table doc_Versions
string doc_version_ID = archive_Class.Doc_Versions_INSERT(DocumentDetails.hidDocID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
//update main version to the new version inserted
archive_Class.Doc_Versions_Set_AS_Main_Doc(int.Parse(DocumentDetails.hidDocID), int.Parse(doc_version_ID));
//update main document in table profile_docs to the name of the new version file
archive_Class.Profile_Docs_UPDATE_Phisical_File_Name(int.Parse(DocumentDetails.hidDocID), DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
try
{
archive_Class.Archive_History_Insert(int.Parse(DocumentDetails.hidLibrary), int.Parse(DocumentDetails.hidFormID), int.Parse(DocumentDetails.hidProfileID), int.Parse(DocumentDetails.hidDocID), int.Parse(doc_version_ID),
Convert.ToInt32(ArchiveOperations.DocVersion_Add),
Convert.ToInt32(DocumentDetails.hidUserID), " تم عمل مسح ضوئي لوثيقة الإصدار رقم : " + doc_version_ID.ToString() + " عنوان الوثيقة : " + DocumentDetails.hidDocName);
}
catch (Exception ex)
{ Elmah.ErrorSignal.FromCurrentContext().Raise(ex); }
}
else
{
if (DocumentDetails.HidMRTYPE.Length > 0)
DocumentDetails.hidDocID = archive_Class.Profile_Docs_INSERT_MR(DocumentDetails.hidProfileID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID, DocumentDetails.HidMRTYPE, DocumentDetails.hidDOC_DATE_EN, DocumentDetails.hidDOC_DATE_AR);
else
//insert documents in db in table profile_Docs
DocumentDetails.hidDocID = archive_Class.Profile_Docs_INSERT(DocumentDetails.hidProfileID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
//insert new version for the document and make it as main doc version
archive_Class.Doc_Versions_INSERT(DocumentDetails.hidDocID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
//try
//{
archive_Class.Archive_History_Insert(int.Parse(DocumentDetails.hidLibrary), int.Parse(DocumentDetails.hidFormID), int.Parse(DocumentDetails.hidProfileID), int.Parse(DocumentDetails.hidDocID), 0,
Convert.ToInt32(ArchiveOperations.Document_Add),
Convert.ToInt32(DocumentDetails.hidUserID), " تم عمل مسح ضوئي للوثيقة رقم : " + DocumentDetails.hidDocID + " عنوان الوثيقة : " + DocumentDetails.hidDocName);
//}
//catch (Exception ex)
//{ Elmah.ErrorSignal.FromCurrentContext().Raise(ex); }
}
// _ArchiveClass.CreateArchiveFolders(DocumentDetails.hidLibrary, DocumentDetails.hidFormID, DocumentDetails.hidProfileID, DocumentDetails.hidDocID);
//ftp "/" + hidLibraryID.Value + "/" + hidFormID.Value + "/" + hidProfileID.Value + "/" + row.Cells[0].Text + "/" + phisicalname);
Doc_Server doc_srv = new Doc_Server(int.Parse(DocumentDetails.hidDocID.ToString()));
string controlSavedPath="/" + DocumentDetails.hidLibrary + "/" + DocumentDetails.hidFormID + "/" + DocumentDetails.hidProfileID + "/" + DocumentDetails.hidFTPGuidName + ".pdf";
doc_srv.ftpRelativeFilePath = "/" + DocumentDetails.hidLibrary + "/" + DocumentDetails.hidFormID + "/" + DocumentDetails.hidProfileID + "/" + DocumentDetails.hidDocID + "/";
FTP_Handler.CreateFTP_Directories(doc_srv);
FTP_Handler.ftp_Move_File_afterSave(doc_srv, controlSavedPath, doc_srv.ftpRelativeFilePath, DocumentDetails.hidFTPGuidName + ".pdf");
//}
//catch (Exception ex)
//{
// Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
// var message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
// string script = "alert('" + ex.Message + "');";
// Page.ClientScript.RegisterStartupScript(this.GetType(), "sctipKey", script, true);
//}
return DocumentDetails.hidDocID;
}
}
---------------------------------------------------------------------------
Class
public class DocumentDetail
{
public string hidLibrary { get; set; }
public string hidFormID { get; set; }
public string hidProfileID { get; set; }
public string hidDocID { get; set; }
public string hidDocName { get; set; }
public string hidIsVersion { get; set; }
public string hidDocComment { get; set; }
public string hidFTPGuidName { get; set; }
public string hidUserID { get; set; }
public string HidMRTYPE { get; set; }
public string hidDOC_DATE_EN { get; set; }
public string hidDOC_DATE_AR { get; set; }
public string hidVersionID { get; set; }
public string saved_Doc_Extension { get; set; }
}
}
function Archive_insert_Save_DB(saved_Doc_Extension) {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
var datajsonparam = {
hidLibrary: $('#hidLibrary').prop('value'),
hidFormID: $("#hidFormID").prop('value'),
hidProfileID: "" + $("#hidProfileID").prop('value'),
hidDocID: $("#hidDocID").prop('value'),
hidDocName: $("#hidDocName").prop('value'),
hidIsVersion: $("#hidIsVersion").prop('value'),
hidDocComment: $("#hidDocComment").prop('value'),
hidFTPGuidName: $("#hidFTPGuidName").prop('value'),
hidUserID: $("#hidUserID").prop('value'),
HidMRTYPE: $("#HidMRTYPE").prop('value'),
hidDOC_DATE_EN: $("#hidDOC_DATE_EN").prop('value'),
hidDOC_DATE_AR: $("#hidDOC_DATE_AR").prop('value'),
saved_Doc_Extension: saved_Doc_Extension
};
$.ajax({
type: "POST",
url: "scan.aspx/Add_Document_DB_Operations",
data: JSON.stringify({ DocumentDetails: datajsonparam }),
//'{"hidLibrary" : "' + $("#hidFTPServer").prop('value') + '" ,"lang" : "' + lang + "hidLibrary" : "' + $("#hidFTPServer").prop('value') }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$("#hidDocID").val(result.d);
alert("تمت عملية الأرشفة بنجاح - Archive Operation Succeeded");
window.opener.location.reload();
window.close();
},
error: function (x, e) { alert(x.responseText); }
});
}
--------------------------------------------------------------------
[WebMethod]
public static string Add_Document_DB_Operations(DocumentDetail DocumentDetails)
{
if (DocumentDetails.hidIsVersion.Length > 0)
{
//insert document in table doc_Versions
string doc_version_ID = archive_Class.Doc_Versions_INSERT(DocumentDetails.hidDocID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
//update main version to the new version inserted
archive_Class.Doc_Versions_Set_AS_Main_Doc(int.Parse(DocumentDetails.hidDocID), int.Parse(doc_version_ID));
//update main document in table profile_docs to the name of the new version file
archive_Class.Profile_Docs_UPDATE_Phisical_File_Name(int.Parse(DocumentDetails.hidDocID), DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
try
{
archive_Class.Archive_History_Insert(int.Parse(DocumentDetails.hidLibrary), int.Parse(DocumentDetails.hidFormID), int.Parse(DocumentDetails.hidProfileID), int.Parse(DocumentDetails.hidDocID), int.Parse(doc_version_ID),
Convert.ToInt32(ArchiveOperations.DocVersion_Add),
Convert.ToInt32(DocumentDetails.hidUserID), " تم عمل مسح ضوئي لوثيقة الإصدار رقم : " + doc_version_ID.ToString() + " عنوان الوثيقة : " + DocumentDetails.hidDocName);
}
catch (Exception ex)
{ Elmah.ErrorSignal.FromCurrentContext().Raise(ex); }
}
else
{
if (DocumentDetails.HidMRTYPE.Length > 0)
DocumentDetails.hidDocID = archive_Class.Profile_Docs_INSERT_MR(DocumentDetails.hidProfileID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID, DocumentDetails.HidMRTYPE, DocumentDetails.hidDOC_DATE_EN, DocumentDetails.hidDOC_DATE_AR);
else
//insert documents in db in table profile_Docs
DocumentDetails.hidDocID = archive_Class.Profile_Docs_INSERT(DocumentDetails.hidProfileID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
//insert new version for the document and make it as main doc version
archive_Class.Doc_Versions_INSERT(DocumentDetails.hidDocID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
//try
//{
archive_Class.Archive_History_Insert(int.Parse(DocumentDetails.hidLibrary), int.Parse(DocumentDetails.hidFormID), int.Parse(DocumentDetails.hidProfileID), int.Parse(DocumentDetails.hidDocID), 0,
Convert.ToInt32(ArchiveOperations.Document_Add),
Convert.ToInt32(DocumentDetails.hidUserID), " تم عمل مسح ضوئي للوثيقة رقم : " + DocumentDetails.hidDocID + " عنوان الوثيقة : " + DocumentDetails.hidDocName);
//}
//catch (Exception ex)
//{ Elmah.ErrorSignal.FromCurrentContext().Raise(ex); }
}
// _ArchiveClass.CreateArchiveFolders(DocumentDetails.hidLibrary, DocumentDetails.hidFormID, DocumentDetails.hidProfileID, DocumentDetails.hidDocID);
//ftp "/" + hidLibraryID.Value + "/" + hidFormID.Value + "/" + hidProfileID.Value + "/" + row.Cells[0].Text + "/" + phisicalname);
Doc_Server doc_srv = new Doc_Server(int.Parse(DocumentDetails.hidDocID.ToString()));
string controlSavedPath="/" + DocumentDetails.hidLibrary + "/" + DocumentDetails.hidFormID + "/" + DocumentDetails.hidProfileID + "/" + DocumentDetails.hidFTPGuidName + ".pdf";
doc_srv.ftpRelativeFilePath = "/" + DocumentDetails.hidLibrary + "/" + DocumentDetails.hidFormID + "/" + DocumentDetails.hidProfileID + "/" + DocumentDetails.hidDocID + "/";
FTP_Handler.CreateFTP_Directories(doc_srv);
FTP_Handler.ftp_Move_File_afterSave(doc_srv, controlSavedPath, doc_srv.ftpRelativeFilePath, DocumentDetails.hidFTPGuidName + ".pdf");
//}
//catch (Exception ex)
//{
// Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
// var message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
// string script = "alert('" + ex.Message + "');";
// Page.ClientScript.RegisterStartupScript(this.GetType(), "sctipKey", script, true);
//}
return DocumentDetails.hidDocID;
}
}
---------------------------------------------------------------------------
Class
public class DocumentDetail
{
public string hidLibrary { get; set; }
public string hidFormID { get; set; }
public string hidProfileID { get; set; }
public string hidDocID { get; set; }
public string hidDocName { get; set; }
public string hidIsVersion { get; set; }
public string hidDocComment { get; set; }
public string hidFTPGuidName { get; set; }
public string hidUserID { get; set; }
public string HidMRTYPE { get; set; }
public string hidDOC_DATE_EN { get; set; }
public string hidDOC_DATE_AR { get; set; }
public string hidVersionID { get; set; }
public string saved_Doc_Extension { get; set; }
}
}
money conversion class using vb.net
Imports Microsoft.VisualBasic
Imports System
Public Class Conversion
Dim Ma, Mi, N, B, R As String
Dim result As String
Public Function BADRMEDIA(ByVal X As Double) As String
Ma = " ريا ل"
Mi = " هلله"
N = Int(X)
B = Val(Right(Format(X, "000000000000.00"), 2))
R = SFormatNumber(N)
If R <> "" And B > 0 Then result = R & Ma & " و " & B & Mi
If R <> "" And B = 0 Then result = R & Ma
If R = "" And B <> 0 Then result = B & Mi
BADRMEDIA = result
End Function
Public Function SFormatNumber(ByVal X As Double) As String
Dim letter1 As String = String.Empty
Dim letter2 As String = String.Empty
Dim letter3 As String = String.Empty
Dim letter4 As String = String.Empty
Dim letter5 As String = String.Empty
Dim letter6 As String = String.Empty
Dim c As String = Format(Math.Floor(X), "000000000000")
Dim C1 As Double = Val(Mid(c, 12, 1))
Select Case C1
Case Is = 1 : letter1 = "واحد"
Case Is = 2 : letter1 = "اثنان"
Case Is = 3 : letter1 = "ثلاثة"
Case Is = 4 : letter1 = "اربعة"
Case Is = 5 : letter1 = "خمسة"
Case Is = 6 : letter1 = "ستة"
Case Is = 7 : letter1 = "سبعة"
Case Is = 8 : letter1 = "ثمانية"
Case Is = 9 : letter1 = "تسعة"
End Select
Dim C2 As Double = Val(Mid(c, 11, 1))
Select Case C2
Case Is = 1 : letter2 = "عشر"
Case Is = 2 : letter2 = "عشرون"
Case Is = 3 : letter2 = "ثلاثون"
Case Is = 4 : letter2 = "اربعون"
Case Is = 5 : letter2 = "خمسون"
Case Is = 6 : letter2 = "ستون"
Case Is = 7 : letter2 = "سبعون"
Case Is = 8 : letter2 = "ثمانون"
Case Is = 9 : letter2 = "تسعون"
End Select
If letter1 <> "" And C2 > 1 Then letter2 = letter1 + " و" + letter2
If letter2 = "" Or letter2 Is Nothing Then
letter2 = letter1
End If
If C1 = 0 And C2 = 1 Then letter2 = letter2 + "ة"
If C1 = 1 And C2 = 1 Then letter2 = "احدى عشر"
If C1 = 2 And C2 = 1 Then letter2 = "اثنى عشر"
If C1 > 2 And C2 = 1 Then letter2 = letter1 + " " + letter2
Dim C3 As Double = Val(Mid(c, 10, 1))
Select Case C3
Case Is = 1 : letter3 = "مائة"
Case Is = 2 : letter3 = "مئتان"
Case Is > 2 : letter3 = Left(SFormatNumber(C3), Len(SFormatNumber(C3)) - 1) + "مائة"
End Select
If letter3 <> "" And letter2 <> "" Then letter3 = letter3 + " و" + letter2
If letter3 = "" Then letter3 = letter2
Dim C4 As Double = Val(Mid(c, 7, 3))
Select Case C4
Case Is = 1 : letter4 = "الف"
Case Is = 2 : letter4 = "الفان"
Case 3 To 10 : letter4 = SFormatNumber(C4) + " آلاف"
Case Is > 10 : letter4 = SFormatNumber(C4) + " الف"
End Select
If letter4 <> "" And letter3 <> "" Then letter4 = letter4 + " و" + letter3
If letter4 = "" Then letter4 = letter3
Dim C5 As Double = Val(Mid(c, 4, 3))
Select Case C5
Case Is = 1 : letter5 = "مليون"
Case Is = 2 : letter5 = "مليونان"
Case 3 To 10 : letter5 = SFormatNumber(C5) + " ملايين"
Case Is > 10 : letter5 = SFormatNumber(C5) + " مليون"
End Select
If letter5 <> "" And letter4 <> "" Then letter5 = letter5 + " و" + letter4
If letter5 = "" Then letter5 = letter4
Dim C6 As Double = Val(Mid(c, 1, 3))
Select Case C6
Case Is = 1 : letter6 = "مليار"
Case Is = 2 : letter6 = "ملياران"
Case Is > 2 : letter6 = SFormatNumber(C6) + " مليار"
End Select
If letter6 <> "" And letter5 <> "" Then letter6 = letter6 + " و" + letter5
If letter6 = "" Then letter6 = letter5
SFormatNumber = letter6
End Function
End Class
Imports System
Public Class Conversion
Dim Ma, Mi, N, B, R As String
Dim result As String
Public Function BADRMEDIA(ByVal X As Double) As String
Ma = " ريا ل"
Mi = " هلله"
N = Int(X)
B = Val(Right(Format(X, "000000000000.00"), 2))
R = SFormatNumber(N)
If R <> "" And B > 0 Then result = R & Ma & " و " & B & Mi
If R <> "" And B = 0 Then result = R & Ma
If R = "" And B <> 0 Then result = B & Mi
BADRMEDIA = result
End Function
Public Function SFormatNumber(ByVal X As Double) As String
Dim letter1 As String = String.Empty
Dim letter2 As String = String.Empty
Dim letter3 As String = String.Empty
Dim letter4 As String = String.Empty
Dim letter5 As String = String.Empty
Dim letter6 As String = String.Empty
Dim c As String = Format(Math.Floor(X), "000000000000")
Dim C1 As Double = Val(Mid(c, 12, 1))
Select Case C1
Case Is = 1 : letter1 = "واحد"
Case Is = 2 : letter1 = "اثنان"
Case Is = 3 : letter1 = "ثلاثة"
Case Is = 4 : letter1 = "اربعة"
Case Is = 5 : letter1 = "خمسة"
Case Is = 6 : letter1 = "ستة"
Case Is = 7 : letter1 = "سبعة"
Case Is = 8 : letter1 = "ثمانية"
Case Is = 9 : letter1 = "تسعة"
End Select
Dim C2 As Double = Val(Mid(c, 11, 1))
Select Case C2
Case Is = 1 : letter2 = "عشر"
Case Is = 2 : letter2 = "عشرون"
Case Is = 3 : letter2 = "ثلاثون"
Case Is = 4 : letter2 = "اربعون"
Case Is = 5 : letter2 = "خمسون"
Case Is = 6 : letter2 = "ستون"
Case Is = 7 : letter2 = "سبعون"
Case Is = 8 : letter2 = "ثمانون"
Case Is = 9 : letter2 = "تسعون"
End Select
If letter1 <> "" And C2 > 1 Then letter2 = letter1 + " و" + letter2
If letter2 = "" Or letter2 Is Nothing Then
letter2 = letter1
End If
If C1 = 0 And C2 = 1 Then letter2 = letter2 + "ة"
If C1 = 1 And C2 = 1 Then letter2 = "احدى عشر"
If C1 = 2 And C2 = 1 Then letter2 = "اثنى عشر"
If C1 > 2 And C2 = 1 Then letter2 = letter1 + " " + letter2
Dim C3 As Double = Val(Mid(c, 10, 1))
Select Case C3
Case Is = 1 : letter3 = "مائة"
Case Is = 2 : letter3 = "مئتان"
Case Is > 2 : letter3 = Left(SFormatNumber(C3), Len(SFormatNumber(C3)) - 1) + "مائة"
End Select
If letter3 <> "" And letter2 <> "" Then letter3 = letter3 + " و" + letter2
If letter3 = "" Then letter3 = letter2
Dim C4 As Double = Val(Mid(c, 7, 3))
Select Case C4
Case Is = 1 : letter4 = "الف"
Case Is = 2 : letter4 = "الفان"
Case 3 To 10 : letter4 = SFormatNumber(C4) + " آلاف"
Case Is > 10 : letter4 = SFormatNumber(C4) + " الف"
End Select
If letter4 <> "" And letter3 <> "" Then letter4 = letter4 + " و" + letter3
If letter4 = "" Then letter4 = letter3
Dim C5 As Double = Val(Mid(c, 4, 3))
Select Case C5
Case Is = 1 : letter5 = "مليون"
Case Is = 2 : letter5 = "مليونان"
Case 3 To 10 : letter5 = SFormatNumber(C5) + " ملايين"
Case Is > 10 : letter5 = SFormatNumber(C5) + " مليون"
End Select
If letter5 <> "" And letter4 <> "" Then letter5 = letter5 + " و" + letter4
If letter5 = "" Then letter5 = letter4
Dim C6 As Double = Val(Mid(c, 1, 3))
Select Case C6
Case Is = 1 : letter6 = "مليار"
Case Is = 2 : letter6 = "ملياران"
Case Is > 2 : letter6 = SFormatNumber(C6) + " مليار"
End Select
If letter6 <> "" And letter5 <> "" Then letter6 = letter6 + " و" + letter5
If letter6 = "" Then letter6 = letter5
SFormatNumber = letter6
End Function
End Class
Saturday, October 3, 2015
sql server recursion recursive function example to get complex name string from parent and child in table hikel
USE [AccountingSqlTest]
GO
/****** Object: UserDefinedFunction [dbo].[HIKEL_GET_NAME_BY_HIKEL_ID] Script Date: 10/03/2015 22:37:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[HIKEL_GET_NAME_BY_HIKEL_ID]
(
@HIKEL_ID INT
)
RETURNS NVARCHAR(1000)
AS
BEGIN
DECLARE @HIKEL_NAME AS NVARCHAR(1000);
--GET ALL ROWS RELATED PASSED HIKEL ID ACCORDING TO @HIKEL_ID PASSED
WITH NAME_TREE AS (
SELECT HIKEL_ID ,PARENT_ID, HIKEL_NAME,HIKEL_NAME_EN
FROM HIKEL
WHERE HIKEL_ID = @HIKEL_ID -- THIS IS THE STARTING POINT YOU WANT IN YOUR RECURSION SMALL HIKEL
UNION ALL
SELECT C.HIKEL_ID ,C.PARENT_ID,C.HIKEL_NAME ,C.HIKEL_NAME_EN
FROM HIKEL C
JOIN NAME_TREE P ON P.PARENT_ID = C.HIKEL_ID -- THIS IS THE RECURSION
)
SELECT DISTINCT @HIKEL_NAME= SUBSTRING(
(SELECT ','+ T.HIKEL_NAME AS [text()]
FROM NAME_TREE T
WHERE T.PARENT_ID IS NOT NULL
ORDER BY T.PARENT_ID ASC
FOR XML PATH ('')
), 2, 1000)
RETURN @HIKEL_NAME
END
GO
/****** Object: UserDefinedFunction [dbo].[HIKEL_GET_NAME_BY_HIKEL_ID] Script Date: 10/03/2015 22:37:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[HIKEL_GET_NAME_BY_HIKEL_ID]
(
@HIKEL_ID INT
)
RETURNS NVARCHAR(1000)
AS
BEGIN
DECLARE @HIKEL_NAME AS NVARCHAR(1000);
--GET ALL ROWS RELATED PASSED HIKEL ID ACCORDING TO @HIKEL_ID PASSED
WITH NAME_TREE AS (
SELECT HIKEL_ID ,PARENT_ID, HIKEL_NAME,HIKEL_NAME_EN
FROM HIKEL
WHERE HIKEL_ID = @HIKEL_ID -- THIS IS THE STARTING POINT YOU WANT IN YOUR RECURSION SMALL HIKEL
UNION ALL
SELECT C.HIKEL_ID ,C.PARENT_ID,C.HIKEL_NAME ,C.HIKEL_NAME_EN
FROM HIKEL C
JOIN NAME_TREE P ON P.PARENT_ID = C.HIKEL_ID -- THIS IS THE RECURSION
)
SELECT DISTINCT @HIKEL_NAME= SUBSTRING(
(SELECT ','+ T.HIKEL_NAME AS [text()]
FROM NAME_TREE T
WHERE T.PARENT_ID IS NOT NULL
ORDER BY T.PARENT_ID ASC
FOR XML PATH ('')
), 2, 1000)
RETURN @HIKEL_NAME
END
----------------------------------------------------------------------------------------------------------------
create FUNCTION [dbo].[HikelGetChilds]
(
@id INT
)
RETURNS table
AS
return (
WITH ret AS(
SELECT id ,ParentId, name ,MnagerId
FROM DEPARTMENTS
WHERE ID = @id
UNION ALL
SELECT d.id ,d.ParentId,d. name ,d.MnagerId
FROM DEPARTMENTS d INNER JOIN
ret r ON d.ParentId = r.ID
)
SELECT *
FROM ret
)
-------------------------------------------------------------------------------------------------------------------------
ALTER FUNCTION [dbo].[HikelGetParents]
(
@id INT
)
RETURNS table
AS
return (
--GET ALL ROWS RELATED PASSED HIKEL ID ACCORDING TO @id PASSED
WITH NAME_TREE AS (
SELECT id ,ParentId, name ,MnagerId
FROM DEPARTMENTS
WHERE id = @id -- THIS IS THE STARTING POINT YOU WANT IN YOUR RECURSION SMALL HIKEL
UNION ALL
SELECT C.id ,C.parentid,C.name ,c.MnagerId
FROM DEPARTMENTS C
JOIN NAME_TREE P ON P.parentid = C.id -- THIS IS THE RECURSION
)
SELECT DISTINCT *
FROM NAME_TREE T
WHERE T.parentid IS NOT NULL
)
create FUNCTION [dbo].[HikelGetChilds]
(
@id INT
)
RETURNS table
AS
return (
WITH ret AS(
SELECT id ,ParentId, name ,MnagerId
FROM DEPARTMENTS
WHERE ID = @id
UNION ALL
SELECT d.id ,d.ParentId,d. name ,d.MnagerId
FROM DEPARTMENTS d INNER JOIN
ret r ON d.ParentId = r.ID
)
SELECT *
FROM ret
)
-------------------------------------------------------------------------------------------------------------------------
ALTER FUNCTION [dbo].[HikelGetParents]
(
@id INT
)
RETURNS table
AS
return (
--GET ALL ROWS RELATED PASSED HIKEL ID ACCORDING TO @id PASSED
WITH NAME_TREE AS (
SELECT id ,ParentId, name ,MnagerId
FROM DEPARTMENTS
WHERE id = @id -- THIS IS THE STARTING POINT YOU WANT IN YOUR RECURSION SMALL HIKEL
UNION ALL
SELECT C.id ,C.parentid,C.name ,c.MnagerId
FROM DEPARTMENTS C
JOIN NAME_TREE P ON P.parentid = C.id -- THIS IS THE RECURSION
)
SELECT DISTINCT *
FROM NAME_TREE T
WHERE T.parentid IS NOT NULL
)
---------------------------------------------------------------------------------------------------------------------
Saturday, September 19, 2015
sql server unique constraint
to create unique constraint
ALTER TABLE hikel
ADD CONSTRAINT UQ_ConstraintforHikelLookups UNIQUE (HIKEL_TYPE ,COMP_ID ,BRANCH_ID ,SECTOR_ID ,SECTION_ID,PROJECT_ID);
ALTER TABLE hikel
ADD CONSTRAINT UQ_ConstraintforHikelLookups UNIQUE (HIKEL_TYPE ,COMP_ID ,BRANCH_ID ,SECTOR_ID ,SECTION_ID,PROJECT_ID);
Sunday, August 30, 2015
sql server rebuild and reorganize indexs
run the following code
SET NOCOUNT ON;
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @partitioncount bigint;
DECLARE @schemaname nvarchar(130);
DECLARE @objectname nvarchar(130);
DECLARE @indexname nvarchar(130);
DECLARE @partitionnum bigint;
DECLARE @partitions bigint;
DECLARE @frag float;
DECLARE @command nvarchar(4000);
DECLARE @dbid smallint;
-- Conditionally select tables and indexes from the sys.dm_db_index_physical_stats function
-- and convert object and index IDs to names.
SET @dbid = DB_ID();
SELECT
[object_id] AS objectid,
index_id AS indexid,
partition_number AS partitionnum,
avg_fragmentation_in_percent AS frag, page_count
INTO #work_to_do
FROM sys.dm_db_index_physical_stats (@dbid, NULL, NULL , NULL, N'LIMITED')
WHERE avg_fragmentation_in_percent > 10.0 -- Allow limited fragmentation
AND index_id > 0 -- Ignore heaps
AND page_count > 25; -- Ignore small tables
-- Declare the cursor for the list of partitions to be processed.
DECLARE partitions CURSOR FOR SELECT objectid,indexid, partitionnum,frag FROM #work_to_do;
-- Open the cursor.
OPEN partitions;
-- Loop through the partitions.
WHILE (1=1)
BEGIN
FETCH NEXT
FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
IF @@FETCH_STATUS < 0 BREAK;
SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)
FROM sys.objects AS o
JOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.object_id = @objectid;
SELECT @indexname = QUOTENAME(name)
FROM sys.indexes
WHERE object_id = @objectid AND index_id = @indexid;
SELECT @partitioncount = count (*)
FROM sys.partitions
WHERE object_id = @objectid AND index_id = @indexid;
-- 30 is an arbitrary decision point at which to switch between reorganizing and rebuilding.
IF @frag < 30.0
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE';
IF @frag >= 30.0
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD';
IF @partitioncount > 1
SET @command = @command + N' PARTITION=' + CAST(@partitionnum AS nvarchar(10));
EXEC (@command);
PRINT N'Executed: ' + @command;
END
-- Close and deallocate the cursor.
CLOSE partitions;
DEALLOCATE partitions;
-- Drop the temporary table.
DROP TABLE #work_to_do;
GO
Reference
http://blogs.msdn.com/b/joaol/archive/2008/01/28/script-to-rebuild-and-reorganize-database-indexes-sql-server-2005.aspx
SET NOCOUNT ON;
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @partitioncount bigint;
DECLARE @schemaname nvarchar(130);
DECLARE @objectname nvarchar(130);
DECLARE @indexname nvarchar(130);
DECLARE @partitionnum bigint;
DECLARE @partitions bigint;
DECLARE @frag float;
DECLARE @command nvarchar(4000);
DECLARE @dbid smallint;
-- Conditionally select tables and indexes from the sys.dm_db_index_physical_stats function
-- and convert object and index IDs to names.
SET @dbid = DB_ID();
SELECT
[object_id] AS objectid,
index_id AS indexid,
partition_number AS partitionnum,
avg_fragmentation_in_percent AS frag, page_count
INTO #work_to_do
FROM sys.dm_db_index_physical_stats (@dbid, NULL, NULL , NULL, N'LIMITED')
WHERE avg_fragmentation_in_percent > 10.0 -- Allow limited fragmentation
AND index_id > 0 -- Ignore heaps
AND page_count > 25; -- Ignore small tables
-- Declare the cursor for the list of partitions to be processed.
DECLARE partitions CURSOR FOR SELECT objectid,indexid, partitionnum,frag FROM #work_to_do;
-- Open the cursor.
OPEN partitions;
-- Loop through the partitions.
WHILE (1=1)
BEGIN
FETCH NEXT
FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
IF @@FETCH_STATUS < 0 BREAK;
SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)
FROM sys.objects AS o
JOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.object_id = @objectid;
SELECT @indexname = QUOTENAME(name)
FROM sys.indexes
WHERE object_id = @objectid AND index_id = @indexid;
SELECT @partitioncount = count (*)
FROM sys.partitions
WHERE object_id = @objectid AND index_id = @indexid;
-- 30 is an arbitrary decision point at which to switch between reorganizing and rebuilding.
IF @frag < 30.0
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE';
IF @frag >= 30.0
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD';
IF @partitioncount > 1
SET @command = @command + N' PARTITION=' + CAST(@partitionnum AS nvarchar(10));
EXEC (@command);
PRINT N'Executed: ' + @command;
END
-- Close and deallocate the cursor.
CLOSE partitions;
DEALLOCATE partitions;
-- Drop the temporary table.
DROP TABLE #work_to_do;
GO
Reference
http://blogs.msdn.com/b/joaol/archive/2008/01/28/script-to-rebuild-and-reorganize-database-indexes-sql-server-2005.aspx
Monday, August 24, 2015
how to trace wcf from client side
the link below describe
https://msdn.microsoft.com/en-us/library/ms732023(v=vs.110).aspx
1- add this section to your web.config file in application consume wcf service.
https://msdn.microsoft.com/en-us/library/ms732023(v=vs.110).aspx
1- add this section to your web.config file in application consume wcf service.
configuration> <system.diagnostics> <trace autoflush="true" /> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> <listeners> <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "SdrConfigExample.e2e" /> </listeners> </source> </sources> </system.diagnostics>
<system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> <trace enabled="true"/> </system.web>
- add this section to your web.config file in application consume wcf service.
Monday, June 22, 2015
delete Elmah errors older than 7 days stored procedure
CREATE PROCEDURE ELMAH_DELETE_OLDERRORS
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM ELMAH_Error
--SELECT * FROM ELMAH_Error
where TimeUtc < dateadd(DAY,-7,getdate());
END
GO
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM ELMAH_Error
--SELECT * FROM ELMAH_Error
where TimeUtc < dateadd(DAY,-7,getdate());
END
GO
Tuesday, May 19, 2015
Tuesday, April 28, 2015
iis asp.net security issues to prevent hacking using configuration file settings
1- Prevent X-Frame and enable X-XSS-Protection
using configuration file settings
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge,chrome=1" />
<add name="X-Frame-Options " value="DENY" />
<add name=" X-XSS-Protection" value="1" />
</customHeaders>
</httpProtocol>
https://blog.veracode.com/2014/03/guidelines-for-setting-security-headers/
2-prevent X-frame in file global.ascx
Protected Sub Application_BeginRequest()
Response.AddHeader("X-Frame-Options", "DENY")
End Sub
3-
Sunday, April 26, 2015
calendar get year umalqura using c#
CultureInfo arCulture = new CultureInfo("ar-SA");
System.Threading.Thread.CurrentThread.CurrentCulture = arCulture;
arCulture.DateTimeFormat.Calendar = new UmAlQuraCalendar();
int yearr =arCulture.Calendar.GetYear(DateTime.Now );
System.Threading.Thread.CurrentThread.CurrentCulture = arCulture;
arCulture.DateTimeFormat.Calendar = new UmAlQuraCalendar();
int yearr =arCulture.Calendar.GetYear(DateTime.Now );
Wednesday, April 22, 2015
set master page dynamically to content page according to language value
To set Master Page dynamically according to language value field from cookie for example you should handle the event in Page_PreInit event before controls rendered for the page
exmaple :
void Page_PreInit(Object sender, EventArgs e)
{
if (Request.Cookies["CurrentLanguage"].Value.ToString().IndexOf("en-") == -1)
this.MasterPageFile = "~/Print.master";
else
this.MasterPageFile = "~/PrintEN.master";
}
exmaple :
void Page_PreInit(Object sender, EventArgs e)
{
if (Request.Cookies["CurrentLanguage"].Value.ToString().IndexOf("en-") == -1)
this.MasterPageFile = "~/Print.master";
else
this.MasterPageFile = "~/PrintEN.master";
}
Tuesday, April 21, 2015
sql server pivot table example cross table using to display yearly report
example
BEGIN
DECLARE @YEAR INT;
SET @YEAR = 2014;
WITH BaseQuery AS(
Select R.OVR_REQUEST_ID AS RID, Month(R.CREATE_DATE) as REQUEST_Month,
Year(R.CREATE_DATE) as [Year] ,
C.CATEGORY_NAME
from OVR_REQUEST R
inner join OVR_CATEGORIES C on R.CATEGORY_ID =C.CATEGORY_ID
)
SELECT CATEGORY_NAME , [1] AS [January],[2] AS [February],
[3] AS [March],[4] AS [April],[5] AS [May],[6] AS [June],
[7] AS [July], [8] AS [August],[9] AS [September],
[10] AS [October], [11] AS [November],[12] AS [December]
FROM BaseQuery
PIVOT(SUM(RID) FOR REQUEST_Month IN ([1],[2],[3],[4],[5],
[6],[7],[8],[9],[10],[11],[12])) AS PVT
WHERE YEAR=@YEAR
ORDER BY January DESC
END
output
Another Example
Select CATEGORY_NAME ,[Year] ,[Month], sum(OVR_REQUEST_ID) REQUES_TOTAL from
(
Select R.OVR_REQUEST_ID, Month(R.CREATE_DATE) as [Month], Year(R.CREATE_DATE) as [Year] ,C.CATEGORY_NAME
from OVR_REQUEST R
inner join OVR_CATEGORIES C on R.CATEGORY_ID =C.CATEGORY_ID
--where date >= '2-1-2014' and date <= '2-28-2014'
) as a
Group by CATEGORY_NAME ,[Year],[Month]
BEGIN
DECLARE @YEAR INT;
SET @YEAR = 2014;
WITH BaseQuery AS(
Select R.OVR_REQUEST_ID AS RID, Month(R.CREATE_DATE) as REQUEST_Month,
Year(R.CREATE_DATE) as [Year] ,
C.CATEGORY_NAME
from OVR_REQUEST R
inner join OVR_CATEGORIES C on R.CATEGORY_ID =C.CATEGORY_ID
)
SELECT CATEGORY_NAME , [1] AS [January],[2] AS [February],
[3] AS [March],[4] AS [April],[5] AS [May],[6] AS [June],
[7] AS [July], [8] AS [August],[9] AS [September],
[10] AS [October], [11] AS [November],[12] AS [December]
FROM BaseQuery
PIVOT(SUM(RID) FOR REQUEST_Month IN ([1],[2],[3],[4],[5],
[6],[7],[8],[9],[10],[11],[12])) AS PVT
WHERE YEAR=@YEAR
ORDER BY January DESC
END
output
Another Example
Select CATEGORY_NAME ,[Year] ,[Month], sum(OVR_REQUEST_ID) REQUES_TOTAL from
(
Select R.OVR_REQUEST_ID, Month(R.CREATE_DATE) as [Month], Year(R.CREATE_DATE) as [Year] ,C.CATEGORY_NAME
from OVR_REQUEST R
inner join OVR_CATEGORIES C on R.CATEGORY_ID =C.CATEGORY_ID
--where date >= '2-1-2014' and date <= '2-28-2014'
) as a
Group by CATEGORY_NAME ,[Year],[Month]
Wednesday, April 15, 2015
asp.net default submit button behavior control using panel
put your search controls inside panel then assign default button for this panel
<asp:Panel runat="server" ID="pnl_Search" DefaultButton="BTN_SEARCH">
//your controls and buttons
</asp:panel>
<asp:Panel runat="server" ID="pnl_Search" DefaultButton="BTN_SEARCH">
//your controls and buttons
</asp:panel>
asp.net textbox fire button click using jquery function
<script type="text/javascript">
$(document).ready(function () {
$('#<%=TXT_REQUEST_REPORT_NO.ClientID %>').keypress(function (event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13') {
$("#<%= BTN_SEARCH.ClientID %>").trigger('click');
parent.$.colorbox.close();
// return false;
}
});
});
</script>
$(document).ready(function () {
$('#<%=TXT_REQUEST_REPORT_NO.ClientID %>').keypress(function (event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13') {
$("#<%= BTN_SEARCH.ClientID %>").trigger('click');
parent.$.colorbox.close();
// return false;
}
});
});
</script>
Monday, April 6, 2015
sql server close all connections to current database database in use error
use master
ALTER DATABASE mwa SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--do you stuff here
ALTER DATABASE mwa SET MULTI_USER
ALTER DATABASE mwa SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--do you stuff here
ALTER DATABASE mwa SET MULTI_USER
Friday, April 3, 2015
sql server get stored procedures updated in specific period
use your database
SELECT *
name,
create_date,
modify_date
FROM sys.procedures
WHERE modify_date >= '20150301'
--- get all objects changes in period
SELECT
*
FROM sys.all_objects
WHERE modify_date >= '20150301'
SELECT *
name,
create_date,
modify_date
FROM sys.procedures
WHERE modify_date >= '20150301'
--- get all objects changes in period
SELECT
*
FROM sys.all_objects
WHERE modify_date >= '20150301'
Tuesday, March 24, 2015
Set mime types for web fonts in IIS
A typical @font-face declaration includes a .eot file, a .svg file, a .ttf file and a .woff file. If your IIS does not serve any of the previous file types, you need to set the appropriate mime type.
Simply add the following MIME type declarations via IIS Manager (HTTP Headers tab of website properties):
Simply add the following MIME type declarations via IIS Manager (HTTP Headers tab of website properties):
.eot application/vnd.ms-fontobject .ttf application/octet-stream .svg image/svg+xml .woff application/font-woff
If you do not have access to the IIS Manager, you can add these declarations in your Web.config file, in the <system.webServer> section.
<system.webServer> <staticContent> <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" /> <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" /> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> <mimeMap fileExtension=".woff" mimeType="application/font-woff" /> </staticContent> </system.webServer> |
Friday, March 13, 2015
restore sql server .bak and .trn series full backup and transaction log files restore process
script to restore .bak file and following transaction log files taken after this full backup script
Use Master
--Alter Database HBDB
--SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE HBDB FROM DISK = 'C:\last backup\HBDB_backup_2015_03_13_142615_7466371.bak' WITH NORECOVERY
RESTORE LOG HBDB FROM DISK = 'C:\last backup\HBDB_backup_2015_03_13_143001_3743946.trn' WITH NORECOVERY
GO
RESTORE LOG HBDB FROM DISK = 'C:\last backup\HBDB_backup_2015_03_13_143301_4693971.trn'
GO
ANOTHER EXAMPLE
Use Master
RESTORE DATABASE archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_220000_9391391.bak' WITH REPLACE , NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_222001_5446562.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_224001_1110761.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_230001_6931427.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_232001_3078836.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_234001_9216614.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_000001_5006193.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_002001_0712952.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_004001_6475144.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_010001_2411629.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_012001_8776987.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_014001_4470268.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_020001_0546277.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_022001_6839213.trn'
Use Master
--Alter Database HBDB
--SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE HBDB FROM DISK = 'C:\last backup\HBDB_backup_2015_03_13_142615_7466371.bak' WITH NORECOVERY
RESTORE LOG HBDB FROM DISK = 'C:\last backup\HBDB_backup_2015_03_13_143001_3743946.trn' WITH NORECOVERY
GO
RESTORE LOG HBDB FROM DISK = 'C:\last backup\HBDB_backup_2015_03_13_143301_4693971.trn'
GO
ANOTHER EXAMPLE
Use Master
RESTORE DATABASE archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_220000_9391391.bak' WITH REPLACE , NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_222001_5446562.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_224001_1110761.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_230001_6931427.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_232001_3078836.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_20_234001_9216614.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_000001_5006193.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_002001_0712952.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_004001_6475144.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_010001_2411629.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_012001_8776987.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_014001_4470268.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_020001_0546277.trn' WITH NORECOVERY
RESTORE LOG archive_Test FROM DISK = 'E:\Production DBs Backups\HOSPITAL_DB\HOSPITAL_DB_backup_2015_03_21_022001_6839213.trn'
Sunday, March 8, 2015
Thursday, March 5, 2015
sql server Compare Time Field between interval
declare @ts1 as time;
SELECT @ts1 = CAST('08:00:00 AM' AS TIME);
declare @ts2 as time;
SELECT @ts2 =CAST('12:00:00 PM' AS TIME);
select * from tasks.dbo.Tasks_PerHour_view
where jobtime between CONVERT(time(0), @ts1) and CONVERT(time(0), @ts2)
SELECT @ts1 = CAST('08:00:00 AM' AS TIME);
declare @ts2 as time;
SELECT @ts2 =CAST('12:00:00 PM' AS TIME);
select * from tasks.dbo.Tasks_PerHour_view
where jobtime between CONVERT(time(0), @ts1) and CONVERT(time(0), @ts2)
Friday, February 27, 2015
sql server restore database error Exclusive access could not be obtained because the database is in use
To solve this error
use Master
alter database Hospital_db_22_02 set offline with rollback immediate
alter database Hospital_db_22_02
set online
go
Wednesday, February 18, 2015
runtime error the type x exists in both x and y
i got this error in web site run under version 4 framework for user control assembly at runtime
Solution :
add this property to web.config file
<compilation debug="false" targetFramework="4.0" batch="false">
Explain for solution :
http://stackoverflow.com/questions/2596118/asp-net-error-the-type-foo-exists-in-both-temp1-dll-and-temp2-dll-pt-2
http://www.sellsbrothers.com/Posts/Details/1995
Solution :
add this property to web.config file
<compilation debug="false" targetFramework="4.0" batch="false">
Explain for solution :
http://stackoverflow.com/questions/2596118/asp-net-error-the-type-foo-exists-in-both-temp1-dll-and-temp2-dll-pt-2
http://www.sellsbrothers.com/Posts/Details/1995
Friday, February 6, 2015
EXMAPLE : WITH USERNAME AND PASSWORD
NET USE \\10.10.10.X\emp_identification_letters /u:mosbah P@$$w0rd
NET USE \\10.10.10.X\Catalog /u:mosbah P@$$w0rd
robocopy /MIR D:\MWA_STORE\TENDERS_STORE \\10.10.10.X\Catalog
robocopy /MIR D:\MWA_STORE\EMP_IDENTIFICATION_LETTERS \\10.10.10.X\emp_identification_letters
break
-----------------------------------------------------------------------------------------------------------------------
robocopy /MIR D:\MWA_STORE\TENDERS_STORE M
robocopy /MIR D:\MWA_STORE\EMP_IDENTIFICATION_LETTERS N
break
--pause
-----------------------------------------------------------------------------------------------------
synchronize using shared storage passing username and password for security issue
note : the task should run with user has permission to shared storage and local server
NET USE \\10.5.39.100\Backups\ARC_STORE_BACKUPS\Doc_Server2 Backups /user:.\sqluser P@$$w0rd
Robocopy "F:\Doc_Server2" "\\10.5.39.100\Backups\ARC_STORE_BACKUPS\Doc_Server2 Backups" /MIR /FFT /Z /XA:H /W:5
NET USE \\10.5.39.100\Backups\ARC_STORE_BACKUPS\Doc_Server2 Backups /delete
NET USE \\10.5.39.100\Backups\ARC_STORE_BACKUPS\Doc_Server1 Backups /user:.\sqluser P@$$w0rd
Robocopy "E:\Doc_Server1" "\\10.5.39.100\Backups\ARC_STORE_BACKUPS\Doc_Server1 Backups" /MIR /FFT /Z /XA:H /W:5
NET USE \\10.5.39.100\Backups\ARC_STORE_BACKUPS\Doc_Server1 Backups /delete
Monday, January 26, 2015
sql server shrink command
USE HOSPITAL_DB
select name,recovery_model_desc from sys.databases
ALTER DATABASE HOSPITAL_DB SET RECOVERY simple
DBCC SHRINKFILE (CDCDataStore , 1)
--get datafiles from database to use in shrinkfile dbcc command
SELECT file_id, name
FROM sys.database_files;
select name,recovery_model_desc from sys.databases
ALTER DATABASE HOSPITAL_DB SET RECOVERY simple
DBCC SHRINKFILE (CDCDataStore , 1)
--get datafiles from database to use in shrinkfile dbcc command
SELECT file_id, name
FROM sys.database_files;
Monday, January 19, 2015
Temp Directory Delete Patch File Command
to delete temp directory files older than 2 days put the following command in .bat file
and create scheduled task to run it every day once
forfiles -p C:\Doc_Server_Temp\ -d -2 -c "cmd /c del @path"
where C:\Doc_Server_Temp\ is the temp directory you want to delete its files.
Monday, January 5, 2015
Eclips Error : java was started by returned exit code=13 java 8
http://www.ashout.com/fix-java-started-returned-exit-code13-eclipse/
Eclips.ini file
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140603-1326
--product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
--showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jre8\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx512m
Eclips.ini file
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140603-1326
--product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
--showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jre8\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx512m
Subscribe to:
Posts (Atom)