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