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", "");