Latest Posts

Saturday, January 3, 2015

AngularJs Bootstrap TreeView

<!DOCTYPE html>



<html ng-app="plunker">
<head>
   <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js"></script>
    <script src="http://ci.angularjs.org/job/angularui-bootstrap/ws/dist/ui-bootstrap-tpls-0.1.1-SNAPSHOT.js"></script>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" />
     @*<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">*@


   
    <script src="~/Script/app/Home/DialogDeomoCtrl.js"></script>
    <link href="~/CSS/stytree.css" rel="stylesheet" />
</head>
<body>
    <div ng-controller="DialogDemoCtrl" >
        <div class="span5 article-tree">
            <div ng-style="{'overflow': 'auto'}" >

                <script type="text/ng-template" id="tree_item_renderer" >

            <span  ng-click="nodeClicked(data)"  >
         
             <i class="{{ switcher( isLeaf(data), '', 'icon-minus-sign' )}}"></i> 
            {{showNode(data)}}
            </span>
             <a href="">{{data.name + ' Edit'}}</a> 
            
            <ul class="some" ng-show="data.show">       
           
            <li ng-repeat="data in data.nodes" class="parent_li"  ng-include="'tree_item_renderer'" tree-node></li>
            </ul>
            </script>

                <div class="tree well">



                    <ul>
                        <li ng-repeat="data in displayTree" ng-include="'tree_item_renderer'" data-ng-click="loadconfig()"></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

</body>
</html>







angular.module('plunker', ['ui.bootstrap', 'ngResource']);
function DialogDemoCtrl($scope, $dialog, $resource) {

    //$scope.isExecuted = false;
   
   
    //buildEmptyTree();
    $scope.title = "visible";
    $scope.count = 0;
    $scope.loadconfig = function () {
        if ($scope.count == 0)
        {
            treeConfig();
            $scope.count = 1;
        }
        console.log('load: ' + new Date().getMilliseconds());
       
    }
    
    read('getvalue', { id: 123 });
    $scope.selectedNode = "";
   


    $scope.showNode = function (data) {

        //console.log(data);

        return data.name;

    };

    $scope.isClient = function (selectedNode) {

        if (selectedNode == undefined) {
            return false;
        }

        if (selectedNode.device_name != undefined) {
            return true;
        }

        return false;
    };
    
    function read(action, params) {
        console.log('read: ' + new Date().getMilliseconds());
        var resource = $resource('api/Home/' + action, params, { action: { method: 'GET', isArray: true } });
        resource.action(params).$promise.then(function (d) {
            $scope.displayTree = d;

        });
    };


}

function treeConfig() {



    var title = $('.tree li:has(ul)').find('.parent_li').find(' > span').attr('title');
    if (title == undefined) {
        // alert(title + "   out");
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
    }

    $('.tree li.parent_li > span').on('click', function (e) {
        var children = $(this).parent('li.parent_li').find(' > ul > li');
        if (children.is(":visible")) {
            var title = $(this).attr('title');
            //   alert(title + "   visible");
            if (title == "Collapse this branch") {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            }
        } else if (children.is(":hidden")) {
            var title = $(this).attr('title');
            //   alert(title + "   hidden");
            if (title == "Expand this branch") {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
        }
        e.stopPropagation();

    });
}




.tree {
    min-height:20px;
    padding:19px;
    margin-bottom:20px;
    background-color:#fbfbfb;
    border:1px solid #999;
    -webkit-border-radius:4px;
    -moz-border-radius:4px;
    border-radius:4px;
    -webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
    -moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
    box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05)
}
.tree li {
    list-style-type:none;
    margin:0;
    padding:10px 5px 0 5px;
    position:relative
}
.tree li::before, .tree li::after {
    content:'';
    left:-20px;
    position:absolute;
    right:auto
}
.tree li::before {
    border-left:1px solid #999;
    bottom:50px;
    height:100%;
    top:0;
    width:1px
}
.tree li::after {
    border-top:1px solid #999;
    height:20px;
    top:25px;
    width:25px
}
.tree li span {
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    border:1px solid #999;
    border-radius:5px;
    display:inline-block;
    padding:3px 8px;
    text-decoration:none
}
.tree li.parent_li>span {
    cursor:pointer
}
.tree>ul>li::before, .tree>ul>li::after {
    border:0
}
.tree li:last-child::before {
    height:30px
}
.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span {
    background:#eee;
    border:1px solid #94a0b4;
    color:#000
}

Tuesday, October 21, 2014

URL Rewrite

void Application_BeginRequest(object sender, EventArgs e)
    {
        string URL_Path = Request.Path.ToLower();

        if (URL_Path.StartsWith("/news/"))
        {
            URL_Path = URL_Path.Trim('/');
            string NewsID = URL_Path.Substring(URL_Path.IndexOf("/"));
            HttpContext MyContext = HttpContext.Current;
            MyContext.RewritePath("/default.aspx?News=" + NewsID);
        }

    }

Thursday, October 17, 2013

Update Pannel

 
<asp:ScriptManager EnablePartialRendering="true"
 ID="ScriptManager1" runat="server"></asp:ScriptManager>
 <asp:UpdatePanel ID="UpdatePanel2" runat="server"
 UpdateMode="Conditional">
 <ContentTemplate>
 <asp:Label ID="Label2" runat="server" ForeColor="red" />
 </ContentTemplate>
 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
 </Triggers>
 </asp:UpdatePanel>

 <asp:UpdatePanel ID="UpdatePanel1" runat="server"
 UpdateMode="Conditional">
 <ContentTemplate>
 <asp:Label ID="Label1" runat="server" /><br />
 <asp:Button ID="Button1" runat="server"
 Text="Update Both Panels" OnClick="Button1_Click" />
 <asp:Button ID="Button2" runat="server"
 Text="Update This Panel" OnClick="Button2_Click" />
 </ContentTemplate>
 </asp:UpdatePanel>

Tuesday, October 15, 2013

sql reader

public DataTable ExecuteRreader(string sp_name, Dictionary<string, object> parameters)
    {
        using (SqlConnection sqlConnection = new SqlConnection(connectionString))
        {
            SqlCommand sqlCommand = new SqlCommand(sp_name, sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            if (parameters != null)
            {
                foreach (KeyValuePair<string, object> parameter in parameters)
                    sqlCommand.Parameters.AddWithValue(parameter.Key, parameter.Value);
            }
            DataTable dataTable = new DataTable();
            sqlConnection.Open();
            using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
            {
                dataTable.Load(sqlDataReader);
            }
            return dataTable;
        }
    }

Sunday, October 13, 2013

autocomplete WebMothod with select event

 <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
    </script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">
    </script>
    <link type="text/css" rel="Stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript">
$(document).ready(function() {
   $("#nameText").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "Default4.aspx/getdatas",
                    data: "{strterm: '" + request.term + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.label ,
                                value: item.record,
                                id: item.type,
                                first: item.key,
                                last: item.key
                            }
                        }))
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            },
            select: function (event, ui) {
             $("#TextBox1").val(ui.item.id);
            },
            minLength: 1
        }).data("ui-autocomplete")._renderItem = function (ul, item) {
        return $("<li></li>")
            .data("item.autocomplete", item)
            .append("<a>" + item.label + item.value + item.id + item.first + "</a>")
            .appendTo(ul);
        };
});
</script>

autocomplete jquery with select event

 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
    </script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">
    </script>
    <link type="text/css" rel="Stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script type="text/javascript">
    $(function () {

var availableItems = [{
    value: "recent",
    label: "Recent",
    classN: "heading"
}, {
    value: "all",
    label: "All",
    classN: "all"
}, {
    value: "lorem",
    label: "Lorem",
    classN: "lorem"
}, ];

$(".post-to").autocomplete({
    source: availableItems,
    minLength: 0,
    focus: function (event, ui) {
        $('.post-to').val(ui.item.label);
        alert(ui.item.label);
        return false;
    },
    select: function (event, ui) {
        alert(ui.item.label);
        return false;
    }
}).on("focus", function () {
    $(this).autocomplete("search", '');
}).data("ui-autocomplete")._renderItem = function (ul, item) {
        return $("<li></li>")
            .data("item.autocomplete", item)
            //instead of <span> use <a>
            .append("<a class='" + item.classN + "'></a><a>" + item.label + "</a>")
            .appendTo(ul);
};
});
    </script>

Wednesday, September 4, 2013

Crystal Report bind from source code

<div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="True" Height="1039px" 
            Width="901px" />
    </div>



using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;

 private ReportDocument rpt;
    protected void Page_Load(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
        string connection = @"DATA SOURCE=JOSE-PC\SQLEXPRESS;DATABASE=MedicalDB;Integrated Security=True;";
        using (SqlConnection sqlConnection = new SqlConnection(connection))
        {
            string query = "SELECT * FROM [MedicalDB].[dbo].[CrystalReport]";
            SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataSet ds = new DataSet();
            sqlDataAdapter.Fill(ds);
            // ds.Tables[0].Rows[0]["Photo"] = (byte[])System.IO.File.ReadAllBytes(Server.MapPath("Penguins.jpg"));
            rpt.SetDataSource( ds.Tables[0]);
            CrystalReportViewer1.ReportSource = rpt;
            CrystalReportViewer1.RefreshReport();
        }
    }
    private void ConfigureCrystalReports()
    {
        rpt = new ReportDocument();
        string reportPath = Server.MapPath("CrystalReport.rpt");
        rpt.Load(reportPath);
        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.DatabaseName = "MedicalDB";
        connectionInfo.IntegratedSecurity = true;
        //connectionInfo.UserID = "";
        //connectionInfo.Password = "user123";
        SetDBLogonForReport(connectionInfo, rpt);
    }
    private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
    {
        Tables tables = reportDocument.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            TableLogOnInfo tableLogonInfo = table.LogOnInfo;
            tableLogonInfo.ConnectionInfo = connectionInfo;
            table.ApplyLogOnInfo(tableLogonInfo);
        }
    } 

byte[] imgdata = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(path));


create dataset and add fields to CrystalReport.rpt