Monday, July 28, 2014

MVC numeric text box

<script>
function ValidateNumber(e) {
            var evt = (e) ? e : window.event;
            var charCode = (evt.keyCode) ? evt.keyCode : evt.which;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
            return true;
        };
</script>

And to call the function in the text box
@Html.TextBoxFor(model => model.Vendor.Mobile, new { @class = "form-control", @maxlength = "10",onkeydown="return ValidateNumber(event);"})

Thursday, July 24, 2014

3 dropdown list to choose the date of birth.

<%= Html.DropDownList("month", Enumerable.Range(1, 12).Select(i => new SelectListItem { Value = i.ToString(), Text = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i)}), "-- Month --") %>

          <%= Html.DropDownList("day", Enumerable.Range(1, 31).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString()}), "-- Day --") %>

                    <%= Html.DropDownList("year", Enumerable.Range(1920, n+1).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString()}), "-- Year --")%>

Monday, July 21, 2014

Trigger Example


Create trigger [dbo].[trgDeleteStagingProducts]
on [dbo].[Vendor_Product]
after insert
as
begin
 DECLARE @VendorProductGUID varchar(50)    
   
    SELECT @VendorProductGUID = I.VendorProductGUID        
      FROM INSERTED I
Delete from Vendor_Product_Stagging where VendorProductGUID = @VendorProductGUID;
end

Saving List of Object in SqlServer by XML

CREATE proc [dbo].[BCKUP_usp_AddUserProducts]
@ProductXml xml

as

insert into dbo.Vendor_Product
(
VendorProductGUID
,ProductGUID
,ProductName
,MRP
,SellingPrice
,Description
,UnitValue
,UnitId
,BarCode
,VendorId
,AddedDate
,ProductImage
,Active
)

SELECT
   Product.value('(VendorProductGUID)[1]', 'varchar(50)') AS 'VendorProductGUID',
   Product.value('(ProductGUID)[1]', 'uniqueidentifier') AS 'ProductGUID',
   Product.value('(ProductName)[1]', 'varchar(50)') AS 'ProductName',
   Product.value('(MRP)[1]', 'money') AS 'MRP',
   Product.value('(SellingPrice)[1]', 'money') AS 'SellingPrice',
   Product.value('(Description)[1]', 'varchar(max)') AS 'Description',
   Product.value('(UnitValue)[1]', 'float') AS 'UnitValue',
   Product.value('(UnitId)[1]', 'tinyint') AS 'UnitId',
   Product.value('(BarCode)[1]', 'varchar(50)') AS 'BarCode',
   Product.value('(VendorId)[1]', 'uniqueidentifier') AS 'VendorId',
   Product.value('(AddedDate)[1]', 'DateTime') AS 'AddedDate',
   Product.value('(ProductImage)[1]', 'int') AS 'ProductImage',
   Product.value('(Active)[1]', 'bit') AS 'Active'
FROM
   @ProductXml.nodes('/ArrayOfVendorProduct/VendorProduct') AS AOC(Product)


/* Following statement is for removing entries from other table , not relevant*/

delete from Vendor_Product_Stagging where VendorProductGUID in
(
SELECT
  Product.value('(VendorProductGUID)[1]', 'varchar(50)') AS 'VendorProductGUID'
  FROM  @ProductXml.nodes('/ArrayOfVendorProduct/VendorProduct') AS AOC(Product)
)