Friday, February 13, 2015

register https in iis

run the following script in Command Prompt as administration  :

makecert -r -pe -n "CN= Monoj-PC " -b 01/01/2000 -e 01/01/2050 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

Solve HTTP Error 404.3 in windows 8

do the following two steps on IIS 8.0
Add new MIME type & HttpHandler
  1. Extension: .svc, MIME type: application/octet-stream
  2. Request path: *.svc, Type: System.ServiceModel.Activation.HttpHandler, Name: svc-Integrated

Saturday, December 20, 2014

Insert xml data in sql server using OPENXML

DECLARE @xml NVARCHAR(max)

SET @xml ='<Delivery><item reqNo="REQ001" code="0001" Qty="25"/><item reqNo="REQ001" code="0002" Qty="35"/></Delivery>'


declare @xml_hndl int    
   
    exec sp_xml_preparedocument @xml_hndl OUTPUT, @xml


Select *

        From
            OPENXML(@xml_hndl, '/Delivery/item', 1)
            With
               (
                 reqNo NVARCHAR(20) '@reqNo',
                 code NVARCHAR(20) '@code',
                 qty money '@Qty'
               )
              

Left Outer Join Example in Entity Framework

public List<RawMaterial> GetRawMaterialInfo()
        {
            using (dbContext = new tPOS_DBEntities())
            {
                var data = from p in dbContext.RawMaterials
                           join q in dbContext.UnitOfMeasures on p.UOM_Receive equals q.Code into rcvUOM
                           from a in rcvUOM.DefaultIfEmpty()
                           join r in dbContext.UnitOfMeasures on p.UOM_Stock equals r.Code into stkUOM
                           from b in stkUOM.DefaultIfEmpty()
                           join s in dbContext.RawMaterials on p.ParentCode equals s.Code
                           select new
                           {
                               p.Code,
                               p.ConvertionRate,
                               p.CreatedBy,
                               p.CreatedDate,
                               p.DriesPrcnt,
                               p.ID,
                               p.Level,
                               p.Name,
                               p.NonExpireItem,
                               p.NonInvItem,
                               p.ParentCode,
                               RecvUOM = a.UOM,
                               p.ROL,
                               p.ROQ,
                               p.StdCPU,
                               p.StockCPU,
                               StockUOM = b.UOM,
                               p.SysCode,
                               p.UOM_Receive,
                               p.UOM_Stock,
                               p.UpdatedBy,
                               p.UpdatedDate,
                               ParentName = s.Name
                           };

                List<RawMaterial> lst = new List<RawMaterial>();
                RawMaterial l;

                foreach (var d in data)
                {
                    l = new RawMaterial();
                    l.Code = d.Code;
                    l.ConvertionRate = d.ConvertionRate;
                    l.CreatedBy = d.CreatedBy;
                    l.CreatedDate = d.CreatedDate;
                    l.DriesPrcnt = d.DriesPrcnt;
                    l.ID = d.ID;
                    l.Level = d.Level;
                    l.Name = d.Name;
                    l.NonExpireItem = d.NonExpireItem;
                    l.NonInvItem = d.NonInvItem;
                    l.ParentCode = d.ParentCode;
                    l.ParentName = d.ParentName;
                    l.RecvUOM = d.RecvUOM;
                    l.ROL = d.ROL;
                    l.ROQ = d.ROQ;
                    l.StdCPU = d.StdCPU;
                    l.StockCPU = d.StockCPU;
                    l.StockUOM = d.StockUOM;
                    l.SysCode = d.SysCode;
                    l.UOM_Receive = d.UOM_Receive;
                    l.UOM_Stock = d.UOM_Stock;
                    l.UpdatedBy = d.UpdatedBy;
                    l.UpdatedDate = d.UpdatedDate;

                    if (l.ParentName != null)
                    {
                        l.FullName = (l.ParentName.Trim().Length != 0 ? l.ParentName + "::" : "") + l.Name;
                    }
                    else
                    {
                        l.FullName = l.Name;
                    }

                    lst.Add(l);
                }
                return lst.OrderBy(p => p.ParentName).OrderBy(p => p.Name).ToList();

            }
        }

Tuesday, September 9, 2014

Conver rows to dynamic columns in sql server 2008

DECLARE @denominationList NVARCHAR(MAX)

SELECT @denominationList = STUFF(
    (SELECT '],[' + CONVERT(NVARCHAR(20),VALUE)
    FROM Gift_Denomination WHERE IsInactive = 0
    FOR XML PATH('')),1,2,'') +']'


DECLARE @sql NVARCHAR(max)

SET @sql =
'SELECT * FROM (
    SELECT  ShopId, ShopName,Value, 0 IssueQty FROM dbo.ShopList s, Gift_Denomination d
            WHERE LEFT(s.ShopId,1) = ''G'' AND  d.IsInactive = 0
) as SourceTable
PIVOT
(
    MAX(IssueQty)
    FOR Value IN ('+@denominationList+')
) AS PivotTable order by shopid'

EXECUTE (@sql)

Thursday, August 7, 2014

Jquery Is not working After Postback

use the following code:

<script type="text/javascript">
        //On UpdatePanel Refresh
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm != null) {
            prm.add_endRequest(function (sender, e) {
                if (sender._postBackSettings.panelsToUpdate != null) {
                    $("#ContentPlaceHolder1_txtDownPayment").blur(function () {                       
                        var ttl = $("#ContentPlaceHolder1_txtPrice").val();
                        var booking = $("#ContentPlaceHolder1_txtBookingAmount").val();
                        var downPayment = $("#ContentPlaceHolder1_txtDownPayment").val();

                        var remain = ttl - booking - downPayment;

                        $("#ContentPlaceHolder1_txtRemaingAmount").val(remain);                      
                    });
                }
            });
        };
    
    </script>

Wednesday, May 14, 2014

Numeric Textbox in WPF

public class TextBoxHelpers : DependencyObject
    {
        public static bool GetIsNumeric(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsNumericProperty);
        }

        public static void SetIsNumeric(DependencyObject obj, bool value)
        {
            obj.SetValue(IsNumericProperty, value);
        }

        // Using a DependencyProperty as the backing store for IsNumeric.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsNumericProperty =
         DependencyProperty.RegisterAttached("IsNumeric", typeof(bool), typeof(TextBoxHelpers), new PropertyMetadata(false, new PropertyChangedCallback((s, e) =>
         {
             TextBox targetTextbox = s as TextBox;
             if (targetTextbox != null)
             {
                 if ((bool)e.OldValue && !((bool)e.NewValue))
                 {
                     targetTextbox.PreviewTextInput -= targetTextbox_PreviewTextInput;

                 }
                 if ((bool)e.NewValue)
                 {
                     targetTextbox.PreviewTextInput += targetTextbox_PreviewTextInput;
                     targetTextbox.PreviewKeyDown += targetTextbox_PreviewKeyDown;
                 }
             }
         })));

        static void targetTextbox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = e.Key == Key.Space;
        }

        static void targetTextbox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            TextBox tb = sender as TextBox;

            Char newChar = e.Text.ToString()[0];
            if (newChar != '.')
            {
                e.Handled = !Char.IsNumber(newChar);
            }
            else
            {
                e.Handled = tb.Text.Contains('.');
            }
        }
    }

xaml Page:

xmlns:ui="clr-namespace:Reluce.ServiceTracker.Helpers"  

<TextBox
            Name="txtQty"
            Grid.Row="4"
            Grid.Column="1"
            Margin="2"
            HorizontalAlignment="Left"           
            FontSize="12"
            AcceptsReturn="False"
            Width="120" 
            ui:TextBoxHelpers.IsNumeric="True"