Thursday, September 21, 2017

jQuery actual validation with From date and to date validation


jQuery actual validation with From date and to date validation.
1.  If from date is selected then to date will be >= from date
2.  If to date selected first then from date will be <= to date


$(document).ready(function () {
            $("#<%=txtCreateDtFrom.ClientID %>").prop('readonly', true);
            $("#<%=txtCreateDtTo.ClientID %>").prop('readonly', true);
            $("#<%=txtDeadlineFrom.ClientID %>").prop('readonly', true);
            $("#<%=txtDeadlineTo.ClientID %>").prop('readonly', true);

            $(".calendar-drop").datepicker({
                changeMonth: true,
                changeYear: true
            });

            $("#<%=txtCreateDtFrom.ClientID %>").datepicker({
                changeMonth: true,
                changeYear: true,
                beforeShow: function () {
                    dt = $("#<%=txtCreateDtTo.ClientID %>").datepicker('getDate');
                    return { maxDate: dt };
                }
            });
            $("#<%=txtCreateDtTo.ClientID %>").datepicker({
                changeMonth: true,
                changeYear: true,
                beforeShow: function () {
                    dt = $("#<%=txtCreateDtFrom.ClientID %>").datepicker('getDate');
                    return { minDate: dt };
                }
            });

            $("#<%=txtDeadlineFrom.ClientID %>").datepicker({
                changeMonth: true,
                changeYear: true,
                beforeShow: function () {
                    dt = $("#<%=txtDeadlineTo.ClientID %>").datepicker('getDate');
                    return { maxDate: dt };
                }
            });

            $("#<%=txtDeadlineTo.ClientID %>").datepicker({
                changeMonth: true,
                changeYear: true,
                beforeShow: function () {
                    dt = $("#<%=txtDeadlineFrom.ClientID %>").datepicker('getDate');
                    return { minDate: dt };
                }
            });          

});           

Friday, September 15, 2017

SQL Server loop through all records or loop through a set of records without cursor in Stored Proceure/function.



              SELECT * INTO #TEMPRES
              FROM
              (
                     SELECT ROW_NUMBER() OVER(order by (SELECT 1)) AS SerialNo, RES.Column1, RES.Column2
                     FROM (SELECT DISTINCT Column1, Column2
                           FROM teble1 WHERE Column2= 'test' ) AS RES
              ) AS X


              --SELECT * FROM #TEMPRES
              --//// MAKING LOOP OF RECORDS ////
              DECLARE @RowCnt INT = 1
              SELECT @RowCnt=COUNT(*) FROM #TEMPRES
              IF(@RowCnt > 0)
              BEGIN
                     DECLARE @i INT = 1
                     WHILE(@i <= @RowCnt)
                     BEGIN
                                  SELECT ProjectLPDetailsBatchID FROM #TEMPRES WHERE SerialNo = @i    
                           END
                           SET @i = @i + 1
                     END
              END

              DROP TABLE #TEMPRES

Wednesday, August 9, 2017

Sharepoint 2013 left quick navigation accordion by JQuery


for testing add this below code to your Script Editor web part.


<script>
$(function(){
 /*set dynamic css logic*/
 if($('#sideNavBox .menu-item.selected').length){
  //propagates the selected class, up the three.
  $('li.static').removeClass('selected');
  $('#sideNavBox .menu-item.selected').parents('li.static').addClass('selected');

  //collapses top siblings of selected branch
  $('#sideNavBox .menu-item.selected').parents('li.static').last().siblings()
   .find('> ul').hide();
 }
 else $('#sideNavBox .root.static > li.static > ul').hide();

 /*set accordion effect*/
 $('#sideNavBox .root.static > li.static').each(function(){
  if($(this).find('ul').length){
   $(this).addClass('father').click(function(){
    if($(this).children('ul').css('display') != 'none'){
     $(this).removeClass('selected').children('ul').slideUp();
    }
    else {
     /*collapse-siblings*/
     $(this).siblings().removeClass('selected').children('ul').slideUp();

     /*expand*/
     $(this).addClass('selected').children('ul').slideDown();
    }

    /*added: stop event propagation to link nodes*/
    $('a.static').click(function(event) {
        event.stopPropagation();
    });

    /*added*/
    return false;
   });
  }
 });
});

</script>

Referenced from: http://borderingdotnet.blogspot.in/2013/04/accordion-left-navigation-for.html

---------- updated on 5-march-2018-----

$(function(){
 /*set dynamic css logic*/
 if($('#sideNavBox .menu-item.selected').length){
  //propagates the selected class, up the three.
  $('li.static').removeClass('selected');
  $('#sideNavBox .menu-item.selected').parents('li.static').addClass('selected');

  //collapses top siblings of selected branch
  $('#sideNavBox .menu-item.selected').parents('li.static').last().siblings()
   .find('> ul').hide();
 
   $('a.static').click(function(event) {
        event.stopPropagation();
    });
 }
 else $('#sideNavBox .root.static > li.static > ul').hide();

 /*set accordion effect*/
 $('#sideNavBox .root.static > li.static').each(function(){
  if($(this).find('ul').length){
   $(this).addClass('father').click(function(){
    if($(this).children('ul').css('display') != 'none'){
     $(this).removeClass('selected').children('ul').slideUp();
    }
    else {
     /*collapse-siblings*/
     $(this).siblings().removeClass('selected').children('ul').slideUp();

     /*expand*/
     $(this).addClass('selected').children('ul').slideDown();
    }

    /*added: stop event propagation to link nodes*/
    $('a.static').click(function(event) {
        event.stopPropagation();
    });

    /*added*/
    return false;
   });
  }
 });

});







Wednesday, June 21, 2017

Numeric and decimal textbox validation by jQuery, c# Asp.Net



Numeric and decimal textbox validation by jQuery, c# Asp.Net
Refer jQuery and give class name of textbox. For the class name validate the Numeric and Decimal.

  $(document).ready(function () {

            $(".numericOnly").keypress(function (e) {
                if (String.fromCharCode(e.keyCode).match(/[^0-9]/g)) return false;
            });
            $(".numericOnly").focusout(function (e) {
                if (isNaN($(this).val())) {
                    $(this).val('');
                }
                else {
                }
            });
            $(".decimalOnly").keypress(function (e) {
                if (String.fromCharCode(e.keyCode).match(/[^0-9.]/g)) return false;
            });
            $(".decimalOnly").focusout(function (e) {
                if (isNaN($(this).val())) {
                    $(this).val('');
                }
                else {
                }
            });

        });

-------------- TEXTBOXES ----------------

<asp:TextBox ID="SAMPLE1" runat="server" class="numericOnly"></asp:TextBox>
<asp:TextBox ID="Sample2" runat="server" CssClass="decimalOnly"></asp:TextBox>

Thursday, April 20, 2017

BULK insert in sql server from c# via XML

  
AS TEXT NO NEED TO SAVE ANY FILE...

private void button1_Click(object sender, EventArgs e)
        {
            DataSet dsData = GetDataSet();

            String xmlData = ConvertDataTableToXML(dsData.Tables[0]);
            SqlConnection conn = new SqlConnection("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            SqlCommand command = new SqlCommand("sp_InsertData '" + xmlData + "'", conn);

conn.Open();

           
            command.ExecuteNonQuery();
            conn.Close();
        }

        private static DataSet GetDataSet()
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable("Table");

            dt.Columns.Add("Name", Type.GetType("System.String"));
            dt.Columns.Add("Address", Type.GetType("System.String"));
            dt.Columns.Add("Phone", Type.GetType("System.String"));

            DataRow dr = dt.NewRow();
            dr["Name"] = "Franklin";
            dr["Address"] = "Hosur";
            dr["Phone"] = "46945616";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["Name"] = "SAMRAj Gill";
            dr["Address"] = "DT-HOSUR";
            dr["Phone"] = "78971651";
            dt.Rows.Add(dr);

            ds.Tables.Add(dt);
            return ds;
        }

        private static string ConvertDataTableToXML(DataTable dtData)
        {
            DataSet dsData = new DataSet();
            StringBuilder sbSQL;
            StringWriter swSQL;
            string XMLformat;
            try
            {
                sbSQL = new StringBuilder();
                swSQL = new StringWriter(sbSQL);
                dsData.Merge(dtData, true, MissingSchemaAction.AddWithKey);
                dsData.Tables[0].TableName = "SampleDataTable";
                foreach (DataColumn col in dsData.Tables[0].Columns)
                {
                    col.ColumnMapping = MappingType.Attribute;
                }
                dsData.WriteXml(swSQL, XmlWriteMode.WriteSchema);
                XMLformat = sbSQL.ToString();
                return XMLformat;
            }
            catch (Exception sysException)
            {
                throw sysException;
            }
        }





//////////////STORED PROCEDURE ////////
USE [TestDBbyAshwinSh]
GO
/****** Object:  StoredProcedure [dbo].[sp_InsertData]    Script Date: 04/20/2017 15:44:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_InsertData]
(@xmlString VARCHAR(MAX))
AS
BEGIN
    DECLARE @xmlHandle INT
   
  
    DECLARE @stagingTable TABLE
    (
        [Name] VARCHAR(50),
        [Address] VARCHAR(50),
        [Phone] VARCHAR(50)
    )
   
    EXEC sp_xml_preparedocument @xmlHandle output, @xmlString
   
  
    INSERT INTO @stagingTable
    SELECT   [Name] ,
        [Address],
        [Phone]
    FROM OPENXML (@xmlHandle, '/NewDataSet/SampleDataTable',1)
        WITH ([Name] varchar(50) '@Name',
            [Address] varchar(50) '@Address',
            [Phone] varchar(50) '@Phone'
             )


    INSERT INTO SampleData ([Name],
            [Address],
            [Phone])
    (SELECT [Name] ,
        [Address],
        [Phone]
    FROM @stagingTable)

    EXEC sp_xml_removedocument @xmlHandle

END

REFERENCE LINK in code project

========new experience========
DECLARE @SET1 NVARCHAR(MAX)

SET @SET1 ='<NewDataSet>

  <SampleDataTable ReferenceType="2 Opportunity" ReferenceId="10241" ReferenceUrl="https://jquery.com/" />
  <SampleDataTable ReferenceType="3 Opportunity" ReferenceId="12546" ReferenceUrl="http:/" />
  <SampleDataTable ReferenceType="Lorem ipsum" ReferenceId="74158" ReferenceUrl="http:///" />
  <SampleDataTable ReferenceType="Demo Ref type" ReferenceId="84766" ReferenceUrl="#" />
  <SampleDataTable ReferenceType="1 Opportunity" ReferenceId="85263" ReferenceUrl="#" />
  <SampleDataTable />
</NewDataSet>'


DECLARE @XMLDocPointer INT
  

  EXEC sp_xml_preparedocument @XMLDocPointer OUTPUT, @SET1
  BEGIN TRANSACTION   
    
    
--INSERT INTO dbo.IMDb_ProjectReferences     (ProjectID ,ReferenceType, ReferenceID ,ReferenceURL)
         select '1', ReferenceType ,ReferenceId ,ReferenceUrl
           from    
 OPENXML(@XMLDocPointer,'/NewDataSet/SampleDataTable',1)with(
ReferenceType  NVARCHAR(100) ,ReferenceId BIGINT ,ReferenceUrl NVARCHAR(100) ) 

EXEC sp_xml_removedocument @XMLDocPointer