Tuesday, December 18, 2007

Hiding a Div or lable using java scripts

document.getElementById("lblQ27").style.display = 'none';

Tuesday, November 27, 2007

System.Data.DataTable tblMyPatientValues = new DataTable("tblMyPatientValues"); //defining data column
//1. DataColumn ColumnHeading = new DataColumn();
ColumnHeading.DataType = System.Type.GetType("System.String"); ColumnHeading.ColumnName = "Values1";
//2. DataColumn ColumnValue = new DataColumn();
ColumnValue.DataType = System.Type.GetType("System.String"); ColumnValue.ColumnName = "Values2";


//Assinging values to collumum acordingly //1

DataRow datarow01 = tblMyPatientValues.NewRow();
datarow01[ColumnHeading] = " Total Number of Patients Enrolled:";
datarow01[ColumnValue] = lblNoOfEnrolledPatients.Text;
tblMyPatientValues.Rows.Add(datarow01);

//2a //Assinging values to collumum acordingly
DataRow datarow02a = tblMyPatientValues.NewRow();
datarow02a[ColumnHeading] = " Number of Patients with a completed DOP CRF:"; datarow02a[ColumnValue] = "";
tblMyPatientValues.Rows.Add(datarow02a);
//if you want you can add this datatable to dataSet

To register Asp.net

you have to run the file in DOS mode
aspnet_regiis

Valubale Char Codes

048 -- 0
049 -- 1
050 -- 2
051 -- 3
052 -- 4
053 -- 5
054 -- 6
055 -- 7
056 -- 8
057 -- 9


065 -- A
066 -- B
067 -- C
068 -- D
069 -- E

.
.
.
097 -- a
098 -- b
099 -- c
0100 -- d

Sample Switch Statement

switch (obj24F.CRFSymptoms24F.Ascites)
{
case 1:
rdoAscites1.Checked = true;
break;
case 2:
rdoAscites2.Checked = true;
break;
case 3:
rdoAscites3.Checked = true;
break;
case 4:
rdoAscites4.Checked = true;
break;
}

Tuesday, November 13, 2007

Usefull validation javascripts - Sanjeewa Sapumana

function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode <> 57))
return false;
return true;
}
function ValidateHour(text)
{
//alert(text.value);
if(text.value!='')
{
if(parseInt(text.value) <>24)
{
alert('Invalid Hour value');
text.value='';
text.focus();
return false;
}
}
//return true
}
function ValidateMinutes(text)
{
if(text.value!='')
{
if(text.value < "0" && text.value>60)
{
alert('Invalid minute value');
text.focus();
}
}
}


function isDecimalKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode <> 57) && charCode!=46)
return false;
return true;
}
function CheckDecimalKey(num)
{
if (isNaN(num.value))
{
alert('Invalid value');
num.value='';
}
}

Friday, November 9, 2007

Check if a dbNull value and replace it by zero value

this.CRFType = oDataReader["CRFType"]!=DBNull.Value? Convert.ToInt32(oDataReader["CRFType"]):0;

Monday, November 5, 2007

Creating a mail functionality

public bool SendEmailError(string ErrorMessage)
{
try
{
MailMessage message = new MailMessage();
message.From = ConfigurationManager.AppSettings["MessageFrom"];
message.To = "Sanjeewa@alliontechnologies.com";
message.Subject = "Error occurred caminarSoft.com";
message.BodyFormat = MailFormat.Html;
message.Body = ErrorMessage;
SmtpMail.SmtpServer = ConfigurationManager.AppSettings["SmtpServer"]; SmtpMail.Send(message);
return true;
}
catch (Exception ex)
{
return false;
}
}

Tuesday, October 30, 2007

Delete confirmation using javascript

//Html view code

ImageButton ID="imgbtnSave" runat="server" ImageUrl="Images/btnSaveSO.gif" ValidationGroup="WODueDateValidation" OnClientClick="javascript:return SaveConfirmation()" OnClick="imgbtnSave_Click"

//Javascript

function deleteConfirm()
{
if(confirm('Are you sure, you want to delete this item permanently from current Sales Order?'))
{
return true;
}
else
{
return false;

}
}

Sunday, October 28, 2007

Create Comma separate (csv) file type export

//fist you have to import
using RKLib.ExportData;

//Inside the button
try
{
dsSet dsFinishedGoods = new dsSet();
dsSetTableAdapters.uspRPInventoryStatusReport9_8TableAdapter AA = new dsSetTableAdapters.uspRPInventoryStatusReport9_8TableAdapter();
dsSetTableAdapters.uspRPCompanyInfoTableAdapter BB = new dsSetTableAdapters.uspRPCompanyInfoTableAdapter();
AA.Fill(dsFinishedGoods._uspRPInventoryStatusReport9_8);
// Export the details of specified columns to Excel
if (dsFinishedGoods._uspRPInventoryStatusReport9_8.Rows.Count > 0)
{
RKLib.ExportData.Export objExport = new RKLib.ExportData.Export("Web");
//objExport.ExportDetails(dataList, iColumns, sHeaders, Export.ExportFormat.Excel, saveName);
objExport.ExportDetails(dsFinishedGoods._uspRPInventoryStatusReport9_8, Export.ExportFormat.CSV, "FinishedGoods_Report.csv");
}
}
catch (Exception ex)
{
}

Tuesday, October 23, 2007

Replace data value from dataset which is coming from database

dsProductionDocumentList = objProduction.GetProductionDocumentListByProductionStep((int)structures.ProductionStep.Washing);
foreach (DataRow dr in dsProductionDocumentList.Tables[0].Rows)
{
if (dr["Scrap_Qty"] == DBNull.Value Convert.ToInt32(dr["Scrap_Qty"]) == 0)
{
dr["Scrap_Qty"]=string.Empty;
}
}

changing grid view image acording to the values of grid view (using datakey filed)

protected void gvSalesOrder_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow row in gvSalesOrder.Rows)
{
if (gvSalesOrder.DataKeys[row.DataItemIndex].Values[1].ToString().Trim() == "1" gvSalesOrder.DataKeys[row.DataItemIndex].Values[2].ToString().Trim() == "True")
{
ImageButton b = (ImageButton)row.Cells[5].Controls[0];
if (b != null)
{
b.ImageUrl = "~/Images/icoAddWODisabled.gif";
b.OnClientClick = "return false;";
}
}
}
}

Thursday, October 18, 2007

Replace NULL numbers to -1 sample SQL

isnull(WO.Production_Order_Id,-1) IsWOCreated


//

SELECT PO.Id,DueDate,isnull(WO.Production_Order_Id,-1) IsWOCreated
FROM ProductionOrder PO left outer join dbo.WorkOrder WO
on PO.Id =WO.Production_Order_Id

Get the Datakey value from gridview ang change the image acordig to the Data key

foreach (GridViewRow row in gvSalesOrder.Rows)
{
if (gvSalesOrder.DataKeys[row.DataItemIndex].Values[1].ToString().Trim() == "1" gvSalesOrder.DataKeys[row.DataItemIndex].Values[2].ToString().Trim() == "True")
{
ImageButton b = (ImageButton)row.Cells[5].Controls[0];
if (b != null)
{
b.ImageUrl = "~/Images/icoAddWODdisabled.gif";
b.OnClientClick = "return false;";
}
}
}

Wednesday, October 17, 2007

Sample SQL Funcion and how its calling

//FUNCTION

ALTER FUNCTION [dbo].[ufCheckProductionOrderCreated]
(
@Sales_Order_Id int
)
RETURNS int
AS
BEGIN
DECLARE @cReturnValue INT
SELECT @cReturnValue= count(Id) from ProductionOrder where Sales_Order_Id=@Sales_Order_Id
RETURN @cReturnValue
END


//Calling the Function


SO.ShipAddressState,
SO.ShipAddressPostalCode,
SO.ShipAddressCountry,
C.Customer_Name,dbo.ufCheckProductionOrderCreated(SO.Sales_Order_No) as IsProdOrderCreated
FROM SalesOrder SO, Customers C
WHERE
C.CustomerID=SO.Customer_No

END

Friday, October 12, 2007

Assign value to the Listbox which is in dataset

string ReasonList = dsSalesReturnDetails.Tables[0].Rows[0]["Reason_For_Return"].ToString();
string[] selected = ReasonList.Split(',');
for (int i = 0; i < selected.Length; i++)
{
for (int x = 0; x< chkReason.Items.Count; x++)
{
if (chkReason.Items[x].Value == selected[i])
{
chkReason.Items[x].Selected = true;
break;
}
}
}

Friday, October 5, 2007

Some Valueble Javascript Validation Code

//Check if Numbers entering//
------------------------------

function isNumberKey(evt)
{ var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode <> 57) )
return false;

return true;
}

//Check if pressing decimal keys//
-----------------------------------

function isDecimalKey(evt)
{

var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode <> 57) && charCode!=46)
return false;
return true;

}

function CheckDecimalKey(num)
{ if (isNaN(num.value))
{

alert('Invalid value');
num.value='';
}
}

//Delete confirmation//
-----------------------

function deleteConfirm() {
if(confirm('Are you sure, you want to delete this record?'))
{
return true;
}
else
{
return false;
}
}

//Max length restriction //
---------------------------
function MaxLengthRestrict(text,long) {
var maxlength = new Number(long);
// max length.
if (text.value.length > maxlength)
{
//return false;
text.value = text.value.substring(0,maxlength);
alert("Allowed only " + long + " characters");
}
}

//

---------------------------------------------------
how to call the event on c# code
======================

onkeypress="return isNumberKey(event);">

Wednesday, October 3, 2007

how to insert default value to a object

objPackingSlip.Weight = txtWeight.Text != string.Empty ? Convert.ToDecimal(txtWeight.Text) : 0;

Monday, October 1, 2007

How to give client script msg box

ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "");

Sunday, September 30, 2007

using a populated dataset (one row of data) display data ina table

dsPickListDetails = objPackingList.GetPickListDetails(PickListId);
lblHeight.Text = dsPickListDetails.Tables[0].Rows[0]["Height"].ToString();

Saturday, September 29, 2007

Bind dorop down to dataset object easyly

private void BindDropDowns(string dataTextField, string dataValueField, DataSet ds, DropDownList dropDownListID)
{
try
{

dropDownListID.DataSource = ds;
dropDownListID.DataTextField = dataTextField;
dropDownListID.DataValueField = dataValueField;
dropDownListID.DataBind();
}

catch (Exception ex)
{

}

}
//To call the method


BindDropDowns("Id", "Id", dsApprovedPickList, ddlPickListNo);

Example of How to join 3 tables using inner join

alter PROCEDURE uspGetPickListDetails
@PickListId int
AS
BEGIN
SELECT PL.Weight, PL.Length,PL.Height, PL.Width, f.Carrier_Name, f.Phone,
s.SO_No, s.BillingAddress, s.ShippingAddress
FROM PickList pl inner join FreightCarriers f
on PL.ShippingMethod=f.Carrier_No inner join salesorder s on
PL.Sales_Order_No=s.Sales_Order_No where PL.Id=@PickListId
END

Friday, September 28, 2007

Sql Query Which give ID not in another table

SELECT PL.id from PL
WHERE PL.Id
not in(select PS.ListNo from PS)

Thursday, September 27, 2007

Wednesday, September 19, 2007

Format date fome the database (not front end)

(cast(year([Due_Date]) as varchar)+'-'+cast(month([Due_Date]) as varchar)+'-'+ cast(day([Due_Date]) as varchar)) AS [Due_Date],

Monday, September 17, 2007

Assign default value to a object is when assign default value to object is when dbnull type value is incoming

//this help you to assign default value to object is when giv en dbnull type
objPackingSlip.sent_To = (dr["sent_To"]!=DBNull.Value)? Convert.ToInt32(dr["sent_To"]):0;

Implement mail functionality link using a hypelink

//just a little code but somes may time usefull

lnkSupport.NavigateUrl = "mailto:support@Abcdef.com";

Thursday, September 13, 2007

Getting Values from asp.net data grid view

//fist you should define keyvalue filed with seperated commas
row["Product_No"] = gvPOReceivingItems.DataKeys[i].Values[0].ToString();

Friday, September 7, 2007

Send the mail using Threading

string sException;
sException = ex.ToString();
SendEmail myMail = new SendEmail();
myMail.SendEmailError(sException + " Time: " + DateTime.Now.ToString());
Thread thread = new System.Threading.Thread(new ThreadStart(sendMailFunction));
//SendMailWithProjectDetails(workOrderId, projectDetailMail)));
thread.Priority = ThreadPriority.Highest;
thread.Start();
Response.Redirect("DefaultErrorPage.aspx");

Thursday, September 6, 2007

Handling row edit Event in dataGrid


protected void gvProductionDocumentList_RowEditing(object sender, GridViewEditEventArgs e)

{

Response.Redirect("WashingEdit.aspx?Id=" + gvProductionDocumentList.DataKeys[e.NewEditIndex].Value, false);

}

Wednesday, September 5, 2007

Format DataGrid data format without time

//add this text from html view
DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="False"

Tuesday, July 10, 2007

Make password fileld not clear when the page is post back


protected void Page_Load(object sender, EventArgs e)
{
//to preserve pasword text at the pose back
txtPword.Attributes.Add("Value", txtPword.Text.ToString());

}

//in the pasword box prerender event
protected void txtPword_PreRender(object sender, EventArgs e)
{
txtPword.Attributes["Value"] = txtPword.Text;
}

Tuesday, July 3, 2007

Reading binary data from Sql sever Database C# Code

//Define Memory Stream
MemoryStream msMemoryStreams = new MemoryStream();
DBConnection conn = new DBConnection();
SqlDataReader sdrReader;
sdrReader = conn.GetDownloadFile("GetFilesDownlod", Convert.ToInt32(DownloadID));
sdrReader.Read();
// Reading the IMAGE data filed data to byte array
// sdrReader.GetBytes(XXX, 0, null, 0, int.MaxValue) , XXX defines the colum number (Zero based)for image data ;see SQL query


byte[] byteData = new Byte[(sdrReader.GetBytes(3, 0, null, 0, int.MaxValue))];
sdrReader.GetBytes(3, 0, byteData, 0, byteData.Length);
//Get the file name
// sdrReader.GetString(XXX) , XXX defines the colum number (Zero based) for file name ;see SQL query

string strOutputFileName = sdrReader.GetString(0);
//get file extension from sqldatareader

string Extension = "." + sdrReader["Extension"].ToString();
strOutputFileName = strOutputFileName+Extension;
msMemoryStreams.Write(byteData, 0, byteData.Length);
//Convert the memorystream to an array of bytes.
byte[] byteArray = msMemoryStreams.ToArray();
//Clean up the memory msMemoryStreams

msMemoryStreams.Flush();
msMemoryStreams.Close();
// Clear all content output from the buffer msMemoryStreams
Response.Clear();
// Add a HTTP header to the output msMemoryStreams that specifies the default filename
// for the browser's download dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + strOutputFileName);
// Add a HTTP header to the output msMemoryStreams that contains the
// content length(File Size). This lets the browser know how much data is being transfered


Response.AddHeader("Content-Length", byteArray.Length.ToString());
// Set the HTTP MIME type of the output msMemoryStreams
Response.ContentType = sdrReader["ContentType"].ToString();
sdrReader.Close();
// Write the data out to the client.

Response.BinaryWrite(byteArray);
//to stoping adding unwanted html coding

Response.End();