Tuesday, November 11, 2014

Customize controls in javascript - example- A Textbox


/********************************************
** Javascript Functions of iTextBox Control
********************************************/

// Class iTextBox
function iTextBox(sId) {
    //ID passed thru Constructor
    this.ID = sId;

    //Initialize Control
    this.Initialize = function() {
        var objCtl = this.HTMLControl();
        //SetVisible
        if(objCtl.Visible.toLowerCase() == 'false')
            this.SetVisible(false);
        else
            this.SetVisible(true);
        //
        if(this.GetText().indexOf('.') != -1){
            this.SetText(this.GetText());
        }
        this.SetViewState();
    }
   
    this.SelectStart = function(){
        event.cancelBubble = true;
        return true;
    }

    this.IsVisible = function() {
        var objCtl = this.HTMLControl();
        if (objCtl == null) {
            return false;
        } else {
            if (objCtl.style.display == "none") {
                return false;
            } else {
                return true;
            }
        }
    }

    this.SetVisible = function(bFlag) {
        var objCtl = this.HTMLControl();

        if (bFlag){
            objCtl.Visible = 'true';
            objCtl.style.display = "block";
        } else {
            objCtl.Visible = 'false';
            objCtl.style.display = "none";
        }
        this.SetViewState();
    }
   
    this.IsDisplayed = function() {
        var objCtl = this.HTMLControl();
        if (objCtl == null) {
            return false;
        } else {
            if (objCtl.style.visibility == "hidden") {
                return false;
            } else {
                return true;
            }
        }
    }
   
    this.SetDisplayed = function(bFlag) {
        var objCtl = this.HTMLControl();

        if (bFlag) {
            objCtl.Displayed = 'true';
            objCtl.style.visibility = "visible";
        } else {
            objCtl.Displayed = 'false';
            objCtl.style.visibility = "hidden";
        }
        this.SetViewState();
    }

    this.IsEnabled = function() {
        var objCtl = this.HTMLControl();
        if (objCtl == null) {
            return false;
        } else {
            if (objCtl.Enabled.toLowerCase() == 'true') {
                return true;
            } else {
                return false;
            }
        }
    }

    this.SetEnabled = function(bFlag) {
       
        var objCtl = this.HTMLControl();
       
        if (bFlag)
        {
            objCtl.Enabled = 'true';
            objCtl.disabled = false;
        }
        else
        {
            objCtl.Enabled = 'false';
            objCtl.disabled = true;
        }
        //Setting ViewState
        this.SetViewState();
    }

    this.IsReadOnly = function() {
        var objCtl = this.HTMLControl();
        if (objCtl == null) {
            return false;
        } else {
            if (objCtl.TextReadOnly.toLowerCase() == 'true') {
                return true;
            } else {
                return false;
            }
        }
    }

    this.SetReadOnly = function(bFlag) {
        var objCtl = this.HTMLControl();
        if (bFlag){
            objCtl.readOnly = true;
            objCtl.TextReadOnly = 'true';
        }
        else{
            objCtl.readOnly = false;
            objCtl.TextReadOnly = 'false';
        }
        //Setting ViewState
        this.SetViewState();
    }

    this.IsMandatory = function() {
        var oCtl = this.HTMLControl();
        if (oCtl == null) {
            return false;
        } else {
            if (oCtl.Mandatory.toLowerCase() == 'true') {
                return true;
            } else {
                return false;
            }
        }
    }

    this.SetMandatory = function(bFlag) {
        var oCtl = this.HTMLControl();
        if (oCtl == null) {
            return false;
        } else {
            //Set Mandatory
            if (bFlag)
                oCtl.Mandatory = 'true';
            else
                oCtl.Mandatory = 'false';
        }
        this.SetViewState();
    }



    this.SetFocus = function() {
        var objCtl = this.HTMLControl();
        if(objCtl == null)    return false ;
        if( this.IsVisible() == true){
            objCtl.focus();
            objCtl.select();
        }
    }

    this.GetText = function() {
        return this.HTMLControl().value;
    }

    this.SetText = function(sText) {
        var oCtl = this.HTMLControl();
        if((sText.toString().indexOf('.') != -1)&& (oCtl.Precision != -1)){
            var nDiff = 1;
            var sPrec = eval(oCtl.Precision);
            for(var iIdx = 0; iIdx < sPrec; iIdx++){
                nDiff = nDiff * 10;
            }
            //
            sText = Math.floor(sText * nDiff) /nDiff;
        }
        oCtl.value = sText;
        this.SetViewState();
       
    }

    this.GetValue = function() {
        return this.GetText();
    }

    this.SetValue = function(sText) {
        this.SetText(sText);
    }

    /********************************************
    * Functions used by the iTextBox Control
    *******************************************/
    this.HTMLControl = function() {
        try {
            return document.getElementById("itextbox_Control_" + this.ID);
        } catch (e) {
            return null;
        }
    }

    this.HTMLHidden = function() {
        try {
            return document.getElementById("itextbox_Value_" + this.ID);
        } catch (e) {
            return null;
        }
    }

    this.SetViewState = function() {
        var objCtl = this.HTMLControl();
        var objText = this.HTMLHidden();
        if (objCtl.Enabled.toLowerCase() != "true") { // If DisEnabled
            objCtl.className = objCtl.css_Disabled;
        } else {
            objCtl.className = objCtl.css_Normal;
        }

        objText.value = this.IsVisible() + ";" + this.IsEnabled() + ";" + this.IsReadOnly() + ";" + this.IsMandatory() + ";" + escape(this.GetText()) + ";" + this.IsDisplayed();
    }
   
    //To set the status text
    this.Focus = function(sStatusText) {
        try
        {
            this.OnSetStatusText(sStatusText);
        }catch(e) {
        }
    }
   
    this.Change = function() {
        try{
            var objCtl = this.HTMLControl();
            this.SetViewState();
            this.OnChange(objCtl.value);
        }catch(e){
        }
    }
   
    this.KeyDown = function(){
        try{
            var objCtl = this.HTMLControl();
            if (objCtl == null)
                return false;
            if (objCtl.TextReadOnly.toLowerCase() == "true") { // If ReadOnly
                if (event.keyCode == 9 || event.keyCode == 16)
                    return true;
                else
                    event.returnValue = false;
            } else {
                this.OnKeyDown(objCtl.value);
            }
        }catch(e){
        }
    }
   
    this.KeyPress = function() {
        try{
            var objCtl = this.HTMLControl();
            if (objCtl == null)
                return false;
            if (objCtl.TextReadOnly.toLowerCase() == "true") { // If ReadOnly
                if (event.keyCode == 9 || event.keyCode == 16)
                    return true;
                else
                    event.returnValue = false;
            } else {
                this.OnKeyPress(objCtl.value);
            }
        }catch(e){
        }
    }
   
    this.KeyUp = function(){
        try{
            var objCtl = this.HTMLControl();
            if (objCtl == null)
                return false;
            if (objCtl.TextReadOnly.toLowerCase() == "true") { // If ReadOnly
                if (event.keyCode == 9 || event.keyCode == 16)
                    return true;
                else
                    event.returnValue = false;
            } else {
                this.OnKeyUp(objCtl.value);
            }
        }catch(e){
        }
    }
    
    //SetStatusText Event Handler
    this.OnSetStatusText = function(sText) {
    }
   
    // KeyDown Event Handler
    this.OnKeyDown = function(sText){
    }
   
    //KeyPress Event Handler
    this.OnKeyPress = function(sText) {
    }
   
    // KeyUp Event Handler
    this.OnKeyUp = function(sText){
    }
   
    //Change Event Handler
    this.OnChange = function(sText) {
    }
}
/********************************************/

Friday, June 6, 2014

Copy files using Powershell

#=====================================================================================================#
#    Copyright 2014 Robert Stacks
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .
#
#=====================================================================================================#
# Original Author: Robert Stacks
# Date: 2/3/2014
# Updated:
# Version: 1.0
#
# Purpose:
# Simple script to copy files from one computer or server to another in the same domain.  Example can
# also email a simple report of files copied.  Created to move some files hourly and only email when
# something was moved.
#
# Many of the user variables are set with $TRUE or $FALSE for on or off.
#
# Will not work across different domains.  Account used to run task from task manager must be a domain
# user with enough rights on both systems to read and write.
#
# Update Notes:
#
#=====================================================================================================#
 
# Email Settings
$fromAddr = "From@domain.com" # Enter the FROM address for the e-mail alert
$toAddr = "To@domain.com" # Enter the TO address for the e-mail alert
$smtpsrv = "mail.domain.com" # Enter the FQDN or IP of a SMTP relay
 
# Files to Copy and where they are going
# Local Files should be in the formate of C:\Folder\* for Files only or C:\Folder to copy the folder as well
$Localfiles = "C:\Folder\*"
# Remote Path should be UNC path with admin share example \\hostname\c$\pathtocopyto
$Remotefiles = "\\hostname\c$\pathtocopyto"
 
#Enable or Disable Script functions
$EmailAlerts = $TRUE # Turn e-mail alerts on or off. $FALSE or 0 = off
$TestfromPrompt = $FALSE # Turn on output from command line.  $FALSE or 0 = no output
$RemoveFilesafterCopy = $TRUE # Remove files after files have been copied over?
 
#===========================#
#Main Script                #
#===========================#
 
#Get the names of the files we want to transfer
$files = Get-childitem "$Localfiles" |foreach { $_.Name}
 
if ($files -ne $null)
{
 
   #Generates output to command line if Value = True
   if ($TestfromPrompt -eq $TRUE)
   {
    Write-Host "These are the files being copied"
    $files
   }
 
#Copy files to remote computer
copy-item -path "$Localfiles" -Destination "$Remotefiles" -Recurse
 
   #Remove Files if Value = True
   if ($RemoveFilesafterCopy -eq $TRUE)
   {
    #Remove Files after they have been moved
    Remove-Item "$Localfiles"
   }
    
   #Send Email Alert if Value = True
   if ($EmailAlerts -eq $TRUE)
   {
    $date = Get-Date -Format g
    Send-MailMessage -To $toAddr -From $fromAddr -Subject "$date Files Copied" -Body "The Following Files were moved" + $files -SmtpServer $smtpsrv
   }
}
 
==========*=================*------------------------------*------------------
 
 
 ------------
SetFSO = CreateObject("Scripting.FileSystemObject")
strSourcePath = "C:\Data\Folder1\"
strDestinationPath = "\\Server2\d$\Folder2\"

File1 = "y-GDetail.txt"
File2 = "a-GrpHeader.txt"
File3 = "z-GrpDetail.txt"

CurrentDate = Year(Now) & Month(Now) & Day(Now)

NewFile1 = strDestinationPath & Left(File1, Len(File1)-4) & CurrentDate & Right(File1, 4)
NewFile2 = strDestinationPath & Left(File2, Len(File2)-4) & CurrentDate & Right(File2, 4)
NewFile3 = strDestinationPath & Left(File3, Len(File3)-4) & CurrentDate & Right(File3, 4)

fso.CopyFilestrSourcePath & File1, NewFile1
fso.CopyFilestrSourcePath & File2, NewFile2
fso.CopyFilestrSourcePath & File3, NewFile3

Iffso.FileExists(strDestinationPath & NewFile1) And_
    fso.FileExists(strDestinationPath & NewFile2) And_
    fso.FileExists(strDestinationPath & NewFile3) Then
    
    SetobjEmail = CreateObject("CDO.Message")
    objEmail.From = "admin1@fabrikam.com"
    objEmail.To = "admin2@fabrikam.com"
    objEmail.Subject = "3 Files Copied to Server2"
    objEmail.Textbody = "3 Files Copied to Server2 at : " & Now
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smarthost"
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
Else
    MsgBox"Copy Failed"
EndIf

MsgBox"Completed"

Friday, May 30, 2014

IE11 Issues - Dropdown List - Overlay

http://stackoverflow.com/questions/18053645/dropdownlist-styling-in-internet-explorer

 dropdownlist styling in Internet explorer

I have some problems with the way IE renders my DropDownList. In Firefox it looks as it should and thats the way I wanted displayed in IE too. Here is a screenshot of the dropdownlist in Firefox:
Firefox
screenshot in IE:
IE
I want the dropdown to expand vertically up until where the dropdownlist is, I don't want the dropdown to go below the existing dropdown control. Is there some trick how to do that with css? Thanks in advance, Laziale






5 Answers

Dropdown lists are essentially controlled by the browser. Limited styling does work sometimes, but it's completely untrustworthy cross-browser. The reason for this is that they're often actually using the operating system's rendering for the dropdown.
If you want full control over your dropdown, you have to draw it yourself from scratch using <ul>'s and <li>'s, make the dropdown trigger an <a> tag and use javascript to toggle visibility of the <ul> and transfer chosen values.
JavaScript plugins exist which take an existing dropdown & do something comparable to this to it. I don't know one which matches your request exactly, but something like a JQueryUI autocomplete in combobox mode (http://jqueryui.com/autocomplete) may give you a good starting point to style from.
share|improve this answer

    
i support the above solution. We need to build our own dropdown by using unordered list and use hover event on li to display the dropdown . This can be done through pure css. I don't think so we need any javascript plugin. –  user2594152 Sep 12 '13 at 6:09
add comment
This is just the way that drop-down menus work in Internet Explorer 10 and up (as well as in Windows Store apps): when the menu opens, the selected item overlays the drop-down control, which other items appearing above and below it. Presumably, Microsoft made this change so that the menu is more touch friendly.
I browsed through the list of CSS properties supported by Internet Explorer, but I didn't notice any that affect the position of the menu. So if this behavior is unacceptable, you will need to eschew the native operating system control in favor of an HTML/CSS-based drop-down menu, such as jQuery Selectmenu or Telerik's RadDropDownList.
share|improve this answer

add comment
Refer - IE10 Select box issue
This is the default behavior for this control in Internet Explorer 10. Depending on the number of items in the list and the size of the screen, other browsers will display the menu differently as well - though I think IE10 is the only browser that will balance the number of items above and below the select element when the dropdown is opened.
share|improve this answer

add comment
The reason for this is that every browser has a different implementation for select boxes. It's almost impossible to implement a nice crossbrowser supported select box. The only way to do a 'secure' implementation is to hide the select box and replace it with a custom select list implementation.
I would highly recommend to use an already existing component. If you already use jQuery, have a look at Select2.
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.
I use it since a couple of months on my page and I can say that it's absolutely great.
share|improve this answer

add comment
This jsfiddle is not final but you will have no choice to have your own custom select list if you have it to appear the same in every broswer.
The example in my jsfiddle is the easiest way for me to implement a select list. By using <input type="radio" />radio button, it is easy to customize it via css and to get the selected value.
Just take a look at it.
share|improve this answer


Friday, April 18, 2014

Code Generation in C#.net – T4Template in Visual Studio



Code Generation in C#.net – T4Template in Visual Studio
Problem Statement:
Need to create more number of *.cs file with [TestClass] and [TestMethod]
Mostly the code remains constant. Only few parameters changes.

Consider creating and testing [TestClass] and [TestMethod] to be written for all Continents, Countries, and States.

Solution:
Using a template to generate *.cs files with static code and only substituting the lookup values for all Continents, Countries, and States.

1.       Create  a class to hold configurable values

// Holds the single record with all values
    public partial class TestRecord
    {
        public string Regulationstate { get; set; }
        public string Authorityname { get; set; }

        public int rulecount { get; set; }

        public string Conti { get; set; }
        public string Country { get; set; }
        public string State { get; set; }

        private string mname;
        public String Methodname
        {
            get { return mname; }
            set { mname = String.Concat(Regulationstate, Authorityname, Conti, Country, State, Methodname, "()"); }

        }

        public TestRecord(string regulationstate, string authorityname, string conti, string country, string state)
        {
            Conti = conti;
            Country = country;
            State = state;
            Methodname = String.Concat(Conti, Country, State, Methodname, "()");
            Regulationstate = regulationstate;
            Authorityname = authorityname;
        }
    }


2. To hold the collection of TestRecord

//COllection of TestRecord List

    partial class TestRecordList : IEnumerable
    {

        public List<TestRecord> mdt { get; set; }

        public TestRecordList()
        {
            this.mdt = FillTestList().ToList<TestRecord>();
        }


        public IEnumerable<TestRecord> FillTestList()
        {
            List<TestRecord> testlist = new List<TestRecord>
            {
                new TestRecord("Asiacode","SoutEast","asia_test","india_test","tamilnadu_test"),
                new TestRecord("Asiacode","SoutEast","assd_ia","srilanfd_ka","codf_lombo"),
                new TestRecord("Asiacode","SoutEast","asia","pakistadf_n","Islamabdf_ad"),
                  new TestRecord("UKcode","London","asiad_d","pakisdf_tan","Islamafd_bad"),
                    new TestRecord("UKcode","Licester","asDD_ia","paDF_kistan","Islafdf_mabad"),
                      new TestRecord("USAcode","sss","asiDD_a","pakistan","Islamafd_bad"),
            };
            return testlist;
        }

        public IEnumerator GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }


2.  Create a new file RuntimeTempalte(*.tt) file using Add item to project in VS2013

3.  Kindly note the Name of the *.tt template is  TestRecordList (same as class) and marked as partial class

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.Xml" #>


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

 <# var ite = mdt.Select(x => x.Regulationstate).Distinct().ToList();#>
 

 <#foreach(var i in ite)
 {#>

 [TestClass]
 public class <#= i #> {

<# foreach(TestRecord  item in mdt)
{
if(item.Regulationstate ==i)
{#>

[TestMethod]
public void <#=item.Methodname#>
{
//select top 1000
//from Dataworks
//where
// statecode = "<#=item.Regulationstate#>";
//caption1= "<#=item.Conti#>";
//and caption2= "<#=item.Country#>";
//and caption3= "<#=item.State#>";

string caption1= "<#=item.Conti#>";
string caption2= "<#=item.Country#>";
string caption3= "<#=item.State#>";
}

<#}#>



<#}#>
}
<#}#>


4.  Write a small Console Application to Generate and export  to test.cs within the project.


    class Program
    {
        static void Main(string[] args)
        {

            TestRecordList ts = new TestRecordList();

            string content = ts.TransformText();

            string path = @"..\..\Op\test.cs";
            System.IO.File.WriteAllText(path, content);
        }
    }



5.       Output file generated is below



using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class Asiacode
{


    [TestMethod]
    public void asia_testindia_testtamilnadu_test()
    {
        //select top 1000
        //from Dataworks
        //where
        // statecode = "Asiacode";
        //caption1= "asia_test";
        //and caption2= "india_test";
        //and caption3= "tamilnadu_test";

        string caption1 = "asia_test";
        string caption2 = "india_test";
        string caption3 = "tamilnadu_test";
    }
    [TestMethod]
    public void asiasrilankacolombo()
    {
        //select top 1000
        //from Dataworks
        //where
        // statecode = "Asiacode";
        //caption1= "asia";
        //and caption2= "srilanka";
        //and caption3= "colombo";

        string caption1 = "asia";
        string caption2 = "srilanka";
        string caption3 = "colombo";
    }
    [TestMethod]
    public void asiapakistanIslamabad()
    {
        //select top 1000
        //from Dataworks
        //where
        // statecode = "Asiacode";
        //caption1= "asia";
        //and caption2= "pakistan";
        //and caption3= "Islamabad";

        string caption1 = "asia";
        string caption2 = "pakistan";
        string caption3 = "Islamabad";
    }
}
[TestClass]
public class UKcode
{

    [TestMethod]
    public void asiapakistanIslamabad()
    {
        //select top 1000
        //from Dataworks
        //where
        // statecode = "UKcode";
        //caption1= "asia";
        //and caption2= "pakistan";
        //and caption3= "Islamabad";

        string caption1 = "asia";
        string caption2 = "pakistan";
        string caption3 = "Islamabad";
    }
    [TestMethod]
    public void asiapakistanIslamabad()
    {
        //select top 1000
        //from Dataworks
        //where
        // statecode = "UKcode";
        //caption1= "asia";
        //and caption2= "pakistan";
        //and caption3= "Islamabad";

        string caption1 = "asia";
        string caption2 = "pakistan";
        string caption3 = "Islamabad";
    }


}

[TestClass]
public class USAcode
{
    [TestMethod]
    public void asiapakistanIslamabad()
    {
        //select top 1000
        //from Dataworks
        //where
        // statecode = "USAcode";
        //caption1= "asia";
        //and caption2= "pakistan";
        //and caption3= "Islamabad";

        string caption1 = "asia";
        string caption2 = "pakistan";
        string caption3 = "Islamabad";
    }
}