http://dotnetspeaks.com/DisplayArticle.aspx?ID=49
Saturday, 29 October 2011
Friday, 28 October 2011
Custom Validator
<asp:CustomValidator runat="server" ID="cvCurrentDate" SetFocusOnError="true" ClientValidationFunction="ValidateAuditCurrentDate"
Display="None" ValidationGroup="save"></asp:CustomValidator>
//modified by raveesh malhotra on september 30
function ValidateAuditCurrentDate(source, args) {
var StartDate = document.getElementById('<%= txtStartDate.ClientID %>').value;
var EndDate = document.getElementById('<%= txtEndDate.ClientID %>').value;
var CurrentDate = new Date();
CurrentDate= CurrentDate.format('dd-mmm-yyyy')
var StartDateday = StartDate.substring(0,2);
var StartDatemonth = StartDate.substring(3,6);
var StartDateyear = StartDate.substring(7,11);
var EndDateday= EndDate.substring(0,2);
var EndDatemonth = EndDate.substring(3,6);
var EndDateyear = EndDate.substring(7,11);
var CurrentDateday = CurrentDate.substring(0,2);
var CurrentDatemonth = CurrentDate.substring(3,6);
var CurrentDateyear = CurrentDate.substring(7,11);
StartDatemonth=changeFormatStringtoNumber(StartDatemonth);
EndDatemonth=changeFormatStringtoNumber(EndDatemonth);
CurrentDatemonth=changeFormatStringtoNumber(CurrentDatemonth);
var StartDate=new Date(StartDateyear,StartDatemonth,StartDateday);
var EndDate = new Date(EndDateyear, EndDatemonth, EndDateday);
var CurrentDate = new Date(CurrentDateyear, CurrentDatemonth,CurrentDateday );
if (StartDate != "" || EndDate != "")
{
if(StartDate < CurrentDate || EndDate< CurrentDate || StartDate > EndDate)
{
args.IsValid = false;
return;
}
}
args.IsValid = true;
}
Display="None" ValidationGroup="save"></asp:CustomValidator>
//modified by raveesh malhotra on september 30
function ValidateAuditCurrentDate(source, args) {
var StartDate = document.getElementById('<%= txtStartDate.ClientID %>').value;
var EndDate = document.getElementById('<%= txtEndDate.ClientID %>').value;
var CurrentDate = new Date();
CurrentDate= CurrentDate.format('dd-mmm-yyyy')
var StartDateday = StartDate.substring(0,2);
var StartDatemonth = StartDate.substring(3,6);
var StartDateyear = StartDate.substring(7,11);
var EndDateday= EndDate.substring(0,2);
var EndDatemonth = EndDate.substring(3,6);
var EndDateyear = EndDate.substring(7,11);
var CurrentDateday = CurrentDate.substring(0,2);
var CurrentDatemonth = CurrentDate.substring(3,6);
var CurrentDateyear = CurrentDate.substring(7,11);
StartDatemonth=changeFormatStringtoNumber(StartDatemonth);
EndDatemonth=changeFormatStringtoNumber(EndDatemonth);
CurrentDatemonth=changeFormatStringtoNumber(CurrentDatemonth);
var StartDate=new Date(StartDateyear,StartDatemonth,StartDateday);
var EndDate = new Date(EndDateyear, EndDatemonth, EndDateday);
var CurrentDate = new Date(CurrentDateyear, CurrentDatemonth,CurrentDateday );
if (StartDate != "" || EndDate != "")
{
if(StartDate < CurrentDate || EndDate< CurrentDate || StartDate > EndDate)
{
args.IsValid = false;
return;
}
}
args.IsValid = true;
}
Wednesday, 19 October 2011
ExecuteReader
public static SqlDataReader ExecuteReader(SqlConnection NewConnection, CommandType cmdType, string cmdText, params SqlParameter[] cmdParams)
{
try
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, NewConnection, null, cmdType, cmdText, cmdParams);
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
cmd.Dispose();
return rdr;
}
catch (SqlException ex)
{
throw ex;
}
}
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParams)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParams != null)
{
foreach (SqlParameter objParams in cmdParams)
cmd.Parameters.Add(objParams);
}
}
{
try
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, NewConnection, null, cmdType, cmdText, cmdParams);
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
cmd.Dispose();
return rdr;
}
catch (SqlException ex)
{
throw ex;
}
}
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParams)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParams != null)
{
foreach (SqlParameter objParams in cmdParams)
cmd.Parameters.Add(objParams);
}
}
Pay Dollar - Payment Gateway
protected string BaseURL
{
get
{
string baseUrl = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "") +
Request.ApplicationPath;
if (!baseUrl.EndsWith("/"))
{
baseUrl = baseUrl + "/";
}
return baseUrl;
}
if (Session["ShoppingCart"] != null)
{
DataTable dt = (DataTable)Session["ShoppingCart"];
decimal orderTotal = Convert.ToDecimal(dt.Compute("Sum(SubTotal)", "SubTotal > 0"));
decimal shipping = Convert.ToDecimal(ConfigurationManager.AppSettings["shipingcharge"]);
string merchantId = ConfigurationManager.AppSettings["merchantId"];//The merchant ID we provide to you
string orderRef = DateTime.Now.Ticks.ToString();//Merchant‘s Order Reference Number
string currCode = "344";//The currency of the payment
string amount = (orderTotal + shipping).ToString();//The total amount your want to charge the customer (up to 2 decimal place)
string paymentType = "N";//The payment type:“N” – Normal Payment (Sales)“H” – Hold Payment (Authorize only)
string lang = "E";//The language of the payment page
string failUrl = BaseURL + "Fail.aspx";//A Web page address you want us to redirect upon the transaction being rejected by us (For display purpose only. DO NOT use this URL to update your system. Please use DataFeed for this purpose.)
string successUrl = BaseURL + "orderconfirmed.aspx"; //A Web page address you want us to redirect upon the transaction being accepted by us (For display purpose only. DO NOT use this URL to update your system. Please use DataFeed for this purpose.)
string errorUrl = BaseURL + "Error.aspx"; //A Web page address you want us to redirect when unexpected error occur (e.g. parameter incorrect) (For display purpose only. DO NOT use this URL to update your system. Please use DataFeed for this purpose.)
string secureHashSecret = "bZe67kcltBHsrmW9EvnnscrdMuNc1HPU";//offered by paydollar
string secureHash = null;
bool isSecureHash = false;
if (isSecureHash)
{//if secureHash is used
SHAPaydollarSecure sha1 = new SHAPaydollarSecure();
secureHash = sha1.generatePaymentSecureHash(merchantId, orderRef, currCode, amount, paymentType, secureHashSecret);
}
string Url = "https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp";
string formId = "myForm1";
StringBuilder htmlForm = new StringBuilder();
htmlForm.AppendLine("<html>");
htmlForm.AppendFormat("<body onload='document.forms[\"{0}\"].submit()'>", formId);
htmlForm.AppendFormat("<form id='{0}' method='POST' action='{1}'>", formId, Url);
htmlForm.AppendFormat("<input type='hidden' name='merchantId' value='{0}'/>", merchantId);
htmlForm.AppendFormat("<input type='hidden' name='amount' value='{0}' />", amount);
htmlForm.AppendFormat("<input type='hidden' name='orderRef' value='{0}' />", orderRef);
htmlForm.AppendFormat("<input type='hidden' name='currCode' value='{0}' />", currCode);
htmlForm.AppendFormat("<input type='hidden' name='successUrl' value='{0}' />", successUrl);
htmlForm.AppendFormat("<input type='hidden' name='failUrl' value='{0}' />", failUrl);
htmlForm.AppendFormat("<input type='hidden' name='errorUrl' value='{0}' />", errorUrl);
htmlForm.AppendFormat("<input type='hidden' name='payType' value='{0}' />", paymentType);
htmlForm.AppendFormat("<input type='hidden' name='lang' value='{0}' />", lang);
htmlForm.AppendFormat("<input type='hidden' name='secureHash' value='{0}' /> ", secureHash);
htmlForm.AppendLine("</form>");
htmlForm.AppendLine("</body>");
htmlForm.AppendLine("</html>");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(htmlForm.ToString());
HttpContext.Current.Response.End();
}
/**/
//InsertDetail();
//Response.Redirect("orderconfirmed.aspx");
}
{
get
{
string baseUrl = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "") +
Request.ApplicationPath;
if (!baseUrl.EndsWith("/"))
{
baseUrl = baseUrl + "/";
}
return baseUrl;
}
if (Session["ShoppingCart"] != null)
{
DataTable dt = (DataTable)Session["ShoppingCart"];
decimal orderTotal = Convert.ToDecimal(dt.Compute("Sum(SubTotal)", "SubTotal > 0"));
decimal shipping = Convert.ToDecimal(ConfigurationManager.AppSettings["shipingcharge"]);
string merchantId = ConfigurationManager.AppSettings["merchantId"];//The merchant ID we provide to you
string orderRef = DateTime.Now.Ticks.ToString();//Merchant‘s Order Reference Number
string currCode = "344";//The currency of the payment
string amount = (orderTotal + shipping).ToString();//The total amount your want to charge the customer (up to 2 decimal place)
string paymentType = "N";//The payment type:“N” – Normal Payment (Sales)“H” – Hold Payment (Authorize only)
string lang = "E";//The language of the payment page
string failUrl = BaseURL + "Fail.aspx";//A Web page address you want us to redirect upon the transaction being rejected by us (For display purpose only. DO NOT use this URL to update your system. Please use DataFeed for this purpose.)
string successUrl = BaseURL + "orderconfirmed.aspx"; //A Web page address you want us to redirect upon the transaction being accepted by us (For display purpose only. DO NOT use this URL to update your system. Please use DataFeed for this purpose.)
string errorUrl = BaseURL + "Error.aspx"; //A Web page address you want us to redirect when unexpected error occur (e.g. parameter incorrect) (For display purpose only. DO NOT use this URL to update your system. Please use DataFeed for this purpose.)
string secureHashSecret = "bZe67kcltBHsrmW9EvnnscrdMuNc1HPU";//offered by paydollar
string secureHash = null;
bool isSecureHash = false;
if (isSecureHash)
{//if secureHash is used
SHAPaydollarSecure sha1 = new SHAPaydollarSecure();
secureHash = sha1.generatePaymentSecureHash(merchantId, orderRef, currCode, amount, paymentType, secureHashSecret);
}
string Url = "https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp";
string formId = "myForm1";
StringBuilder htmlForm = new StringBuilder();
htmlForm.AppendLine("<html>");
htmlForm.AppendFormat("<body onload='document.forms[\"{0}\"].submit()'>", formId);
htmlForm.AppendFormat("<form id='{0}' method='POST' action='{1}'>", formId, Url);
htmlForm.AppendFormat("<input type='hidden' name='merchantId' value='{0}'/>", merchantId);
htmlForm.AppendFormat("<input type='hidden' name='amount' value='{0}' />", amount);
htmlForm.AppendFormat("<input type='hidden' name='orderRef' value='{0}' />", orderRef);
htmlForm.AppendFormat("<input type='hidden' name='currCode' value='{0}' />", currCode);
htmlForm.AppendFormat("<input type='hidden' name='successUrl' value='{0}' />", successUrl);
htmlForm.AppendFormat("<input type='hidden' name='failUrl' value='{0}' />", failUrl);
htmlForm.AppendFormat("<input type='hidden' name='errorUrl' value='{0}' />", errorUrl);
htmlForm.AppendFormat("<input type='hidden' name='payType' value='{0}' />", paymentType);
htmlForm.AppendFormat("<input type='hidden' name='lang' value='{0}' />", lang);
htmlForm.AppendFormat("<input type='hidden' name='secureHash' value='{0}' /> ", secureHash);
htmlForm.AppendLine("</form>");
htmlForm.AppendLine("</body>");
htmlForm.AppendLine("</html>");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(htmlForm.ToString());
HttpContext.Current.Response.End();
}
/**/
//InsertDetail();
//Response.Redirect("orderconfirmed.aspx");
}
Wednesday, 12 October 2011
Useful jQuery code examples for ASP.NET Controls
http://jquerybyexample.blogspot.com/search/label/jQuery%20With%20ASP.NET
http://jquerybyexample.blogspot.com/2011/03/useful-jquery-code-examples-for-aspnet.html
http://jquerybyexample.blogspot.com/2011/03/useful-jquery-code-examples-for-aspnet.html
Tuesday, 11 October 2011
Use of sql Bulk copy
public Int16 ImportIUploadQuestionnaire(OM_UploadQuestionnaire objUploadQuestionnaire)
{
using (SqlConnection cn = OceanManager.SQLHelper.GetSQLConnection(Databases.AuditSystem))
{
using (SqlBulkCopy copy = new SqlBulkCopy(cn))
{
copy.ColumnMappings.Add("UserID", "UserID");
copy.ColumnMappings.Add("CheckList", "CheckList");
copy.ColumnMappings.Add("Question", "Question");
copy.ColumnMappings.Add("Guidance", "Guidance");
copy.ColumnMappings.Add("Priority", "Priority");
copy.ColumnMappings.Add("Rank", "Rank");
copy.ColumnMappings.Add("QuestionType", "QuestionType");
copy.ColumnMappings.Add("Task", "Task");
copy.ColumnMappings.Add("AuditType", "AuditType");
copy.ColumnMappings.Add("AuditName", "AuditName");
copy.DestinationTableName = TABLE_QuestionnaireUpload;
copy.WriteToServer(objUploadQuestionnaire.ImportDatTable);
}
cn.Close();
cn.Dispose();
}
return 1;
}
{
using (SqlConnection cn = OceanManager.SQLHelper.GetSQLConnection(Databases.AuditSystem))
{
using (SqlBulkCopy copy = new SqlBulkCopy(cn))
{
copy.ColumnMappings.Add("UserID", "UserID");
copy.ColumnMappings.Add("CheckList", "CheckList");
copy.ColumnMappings.Add("Question", "Question");
copy.ColumnMappings.Add("Guidance", "Guidance");
copy.ColumnMappings.Add("Priority", "Priority");
copy.ColumnMappings.Add("Rank", "Rank");
copy.ColumnMappings.Add("QuestionType", "QuestionType");
copy.ColumnMappings.Add("Task", "Task");
copy.ColumnMappings.Add("AuditType", "AuditType");
copy.ColumnMappings.Add("AuditName", "AuditName");
copy.DestinationTableName = TABLE_QuestionnaireUpload;
copy.WriteToServer(objUploadQuestionnaire.ImportDatTable);
}
cn.Close();
cn.Dispose();
}
return 1;
}
Get Data from Excel and Save into database in c#
protected void btnupload_Click(object sender, EventArgs e)
{
String ExtFileName = Path.GetExtension(fileuploader.FileName);
String FileName = fileuploader.FileName;
String FilePath = Server.MapPath("~/Auditsystem/AuditAdmin/") + FileName;
GenerateAccountExcel(FilePath);
}
private string GenerateAccountExcel(String filePath)
{
string strSQL = string.Empty;
string retValue = string.Empty;
DataTable dtExcel = null;
System.Data.OleDb.OleDbConnection dbConn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0;HDR=YES'");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
try
{
strSQL = "SELECT * FROM [Questionnaire$]";
System.Data.OleDb.OleDbCommand cmd = null;
System.Data.OleDb.OleDbDataAdapter daExcel = null;
dbConn.Open();
dtExcel = new DataTable();
cmd = new System.Data.OleDb.OleDbCommand(strSQL, dbConn);
daExcel = new System.Data.OleDb.OleDbDataAdapter(cmd);
dtExcel.Columns.Add("UserID", typeof(String), "123");
daExcel.Fill(dtExcel);
int dsExcelRecordCount = 0;
dsExcelRecordCount = dtExcel.Rows.Count;
if (dsExcelRecordCount == 0)
{
retValue = "No records to update in excel file";
}
else
{
BLL_UploadQuestionnaire objUploadQuestionnaire = null;
int Result = 0;
objUploadQuestionnaire = new BLL_UploadQuestionnaire();
Result = objUploadQuestionnaire.ImportIUploadQuestionnaire(
new OM_UploadQuestionnaire
{
ImportDatTable = dtExcel
});
GetUploadQuestionnaire("123");
}
}
catch (Exception ex)
{
retValue = ex.Message + " :Error while importing Data.";
}
finally
{
dbConn.Close();
dbConn.Dispose();
}
return retValue;
}
{
String ExtFileName = Path.GetExtension(fileuploader.FileName);
String FileName = fileuploader.FileName;
String FilePath = Server.MapPath("~/Auditsystem/AuditAdmin/") + FileName;
GenerateAccountExcel(FilePath);
}
private string GenerateAccountExcel(String filePath)
{
string strSQL = string.Empty;
string retValue = string.Empty;
DataTable dtExcel = null;
System.Data.OleDb.OleDbConnection dbConn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0;HDR=YES'");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
try
{
strSQL = "SELECT * FROM [Questionnaire$]";
System.Data.OleDb.OleDbCommand cmd = null;
System.Data.OleDb.OleDbDataAdapter daExcel = null;
dbConn.Open();
dtExcel = new DataTable();
cmd = new System.Data.OleDb.OleDbCommand(strSQL, dbConn);
daExcel = new System.Data.OleDb.OleDbDataAdapter(cmd);
dtExcel.Columns.Add("UserID", typeof(String), "123");
daExcel.Fill(dtExcel);
int dsExcelRecordCount = 0;
dsExcelRecordCount = dtExcel.Rows.Count;
if (dsExcelRecordCount == 0)
{
retValue = "No records to update in excel file";
}
else
{
BLL_UploadQuestionnaire objUploadQuestionnaire = null;
int Result = 0;
objUploadQuestionnaire = new BLL_UploadQuestionnaire();
Result = objUploadQuestionnaire.ImportIUploadQuestionnaire(
new OM_UploadQuestionnaire
{
ImportDatTable = dtExcel
});
GetUploadQuestionnaire("123");
}
}
catch (Exception ex)
{
retValue = ex.Message + " :Error while importing Data.";
}
finally
{
dbConn.Close();
dbConn.Dispose();
}
return retValue;
}
how to use Classic Ajax
function SendAjaxRequestProcDescription() {
var oXMLHTTP = null;
if (window.XMLHttpRequest)
oXMLHTTP = new XMLHttpRequest();
else if (window.ActiveXObject)
oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var sURL = "PatientDetails.aspx?proccode=" + $("#ContentPlaceHolder2_txtLeftProcCode").val()
var nocache = "&nocache=" + new Date();
oXMLHTTP.open("Get", sURL + nocache, false);
oXMLHTTP.send(null);
$("#ContentPlaceHolder2_txtLeftProcDescription").val(oXMLHTTP.responseText);
return false;
}
if (Request.QueryString["proccode"] != null)
{
}
var oXMLHTTP = null;
if (window.XMLHttpRequest)
oXMLHTTP = new XMLHttpRequest();
else if (window.ActiveXObject)
oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var sURL = "PatientDetails.aspx?proccode=" + $("#ContentPlaceHolder2_txtLeftProcCode").val()
var nocache = "&nocache=" + new Date();
oXMLHTTP.open("Get", sURL + nocache, false);
oXMLHTTP.send(null);
$("#ContentPlaceHolder2_txtLeftProcDescription").val(oXMLHTTP.responseText);
return false;
}
if (Request.QueryString["proccode"] != null)
{
}
Subscribe to:
Posts (Atom)