Tuesday, November 27, 2012

Upload and Crop Images with jQuery, JCrop and ASP.NET

Owner of this article is http://www.mikesdotnetting.com

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadAndCrop.aspx.cs" Inherits="UploadAndCrop" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>

</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:Panel ID="pnlUpload" runat="server">
      <asp:FileUpload ID="Upload" runat="server" />
      <br />
      <asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" />
      <asp:Label ID="lblError" runat="server" Visible="false" />
    </asp:Panel>
    <asp:Panel ID="pnlCrop" runat="server" Visible="false">
      <asp:Image ID="imgCrop" runat="server" />
      <br />
      <asp:HiddenField ID="X" runat="server" />
      <asp:HiddenField ID="Y" runat="server" />
      <asp:HiddenField ID="W" runat="server" />
      <asp:HiddenField ID="H" runat="server" />
      <asp:Button ID="btnCrop" runat="server" Text="Crop" OnClick="btnCrop_Click" />
    </asp:Panel>
    <asp:Panel ID="pnlCropped" runat="server" Visible="false">
      <asp:Image ID="imgCropped" runat="server" />
    </asp:Panel>
  </div>
  </form>
</body>
</html>

Some Javascript is required. If you were starting this kind of application from scratch, it would need an awful lot of javascript. However, jQuery's real power is illustrated by just how little javascript this page actually needs. To make use of both jQuery and JCrop, they need to be linked to in the head section of the page, along with the css file that comes as part of the JCrop download. The link to jQuery makes use of the copy available from the Google Ajax API Library for better caching and faster downloading:

<link href="css/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript" src="script/jquery.Jcrop.pack.js"></script>

All that's now needed to activate JCrop is a handful of lines of Javascript, which go within <script> that's in the head of the document below the previous lines:

<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery('#imgCrop').Jcrop({
      onSelect: storeCoords
    });
  });

  function storeCoords(c) {
    jQuery('#X').val(c.x);
    jQuery('#Y').val(c.y);
    jQuery('#W').val(c.w);
    jQuery('#H').val(c.h);
  };

</script>

It really is that simple. Jcrop has been applied to the image that has the id of imgCrop (the one in pnlCrop), and an event handler has been added to the select event of the cropper. This will happen when the user has completed selecting the area of the image they want to keep. The handler makes use of the storeCoords function, which sets the values of the HiddenFields, passing them the x and y coordinates of the top left of the selection relative to the image, and the width and height of the selection. That's all ASP.NET needs to know in order to process the image on the server. Now on to the server-side code.
There are 4 namespaces that need to be referenced in additional to the default ones that a new Web Form brings in:

using System.IO;
using SD = System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

Since we will be working with instances of System.Drawing.Image as well as System.Web.UI.WebControls, which also has an Image class, I have aliased System.Drawing.Image, which will permit me to use a shorthand to reference the System.Drawing.Image classes. The first four lines of the code-behind simply set a variable to point to the file system path of the directory in which uploaded images will be stored, and show an empty Page_Load method:

String path = HttpContext.Current.Request.PhysicalApplicationPath + "images\\";

protected void Page_Load(object sender, EventArgs e)
{}

The next section covers the event handler for the Upload button click:


protected void btnUpload_Click(object sender, EventArgs e)
{
  Boolean FileOK = false;
  Boolean FileSaved = false;

  if (Upload.HasFile)
  {
    Session["WorkingImage"] = Upload.FileName;
    String FileExtension = Path.GetExtension(Session["WorkingImage"].ToString()).ToLower();
    String[] allowedExtensions = { ".png", ".jpeg", ".jpg", ".gif" };
    for (int i = 0; i < allowedExtensions.Length; i++)
    {
      if (FileExtension == allowedExtensions[i])
      {
        FileOK = true;
      }
    }
  }

  if (FileOK)
  {
    try
    {
      Upload.PostedFile.SaveAs(path + Session["WorkingImage"]);
      FileSaved = true;
    }
    catch (Exception ex)
    {
      lblError.Text = "File could not be uploaded." + ex.Message.ToString();
      lblError.Visible = true;
      FileSaved = false;
    }
  }
  else
  {
    lblError.Text = "Cannot accept files of this type.";
    lblError.Visible = true;
  }

  if (FileSaved)
  {
    pnlUpload.Visible = false;
    pnlCrop.Visible = true;
    imgCrop.ImageUrl = "images/" + Session["WorkingImage"].ToString();
  }
}

This code should be pretty familiar to anyone who has worked with the FileUpload control before. It simply checks to see if a file has been submitted, and ensures that it is of the right type. Then it saves the file to disk and the name of the file to a Session variable. Once the image has been saved, it is set as the ImageUrl of the Image control which has been targeted by JCrop and makes the containing Panel visible.

The next section covers the event handler for the Crop button:

protected void btnCrop_Click(object sender, EventArgs e)
{
  string ImageName = Session["WorkingImage"].ToString();
  int w = Convert.ToInt32(W.Value);
  int h = Convert.ToInt32(H.Value);
  int x = Convert.ToInt32(X.Value);
  int y = Convert.ToInt32(Y.Value);

  byte[] CropImage = Crop(path + ImageName, w, h, x, y);
  using (MemoryStream ms = new MemoryStream(CropImage, 0, CropImage.Length))
  {
    ms.Write(CropImage, 0, CropImage.Length);
    using(SD.Image CroppedImage = SD.Image.FromStream(ms, true))
    {
      string SaveTo = path + "crop" + ImageName;
      CroppedImage.Save(SaveTo, CroppedImage.RawFormat);
      pnlCrop.Visible = false;
      pnlCropped.Visible = true;
      imgCropped.ImageUrl = "images/crop" + ImageName;
    }
  }
}

This section references the image name from the Session variable, and then declares a number of integers that get their values from the HiddenFields that JCrop wrote to when the user selected the area they wanted to keep.

It then calls a method called Crop() to perform the actual cropping of the image (more of which soon). Crop() returns a byte array, which is written to a MemoryStream so that it can be used and converted back to an Image. This is then prefixed with the word "crop" in its name before being saved to disk and displayed to the user.

The Crop() method is below:

static byte[] Crop(string Img, int Width, int Height, int X, int Y)
{
  try
  {
    using (SD.Image OriginalImage = SD.Image.FromFile(Img))
    {
      using (SD.Bitmap bmp = new SD.Bitmap(Width, Height))
      {
        bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);
        using (SD.Graphics Graphic = SD.Graphics.FromImage(bmp))
        {
          Graphic.SmoothingMode = SmoothingMode.AntiAlias;
          Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
          Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
          Graphic.DrawImage(OriginalImage, new SD.Rectangle(0, 0, Width, Height), X, Y, Width, Height, SD.GraphicsUnit.Pixel);
          MemoryStream ms = new MemoryStream();
          bmp.Save(ms, OriginalImage.RawFormat);
          return ms.GetBuffer();
        }
      }
    }
  }
  catch (Exception Ex)
  {
    throw (Ex);
  }
}

This might at first glance look a little daunting to beginners, but most of the code just sets properties that affect the quality and appearance of the resulting image. What it does is to simply use the original image as a base from which a new image is drawn, and then save it to a MemoryStream object, which is returned as a byte array to be consumed by the calling code above. You should take note of the using blocks that are employed in this method. They ensure that Image, Bitmap and Graphics objects are all disposed of when the method is done. There's nothing worse than finding that your busy web app has slowed to a crawl through unreleased resources.
Oh, and thanks go to my cat, Alfie, for kindly agreeing to model for this exercise.





Note-Original Source From :-http://www.mikesdotnetting.com/Article/95/Upload-and-Crop-Images-with-jQuery-JCrop-and-ASP.NET

Thursday, October 4, 2012

Re -write url in asp.net

Re -write url in asp.net



First Create two hyperlinks in default.aspx page and paste the following
-------------------------------------------------------------------------------------------------------------------------------------------------
<asp:HyperLink  Text="ASP.net" runat="server" ID="link1" NavigateUrl=" "> </asp:HyperLink>
<asp:HyperLink  Text="PHP" runat="server" ID="HyperLink1" NavigateUrl=" "> </asp:HyperLink>


Then create a global.asax file and paste the same under <script>
-------------------------------------------------------------------------------------------------------------------------------------------------
void Application_Start(object sender, EventArgs e) 
    {
        RegisterRoutes(System.Web.Routing.RouteTable.Routes);
    }

    public static void RegisterRoutes(System.Web.Routing.RouteCollection routeCollection)
    {
        routeCollection.MapPageRoute("RouteForCustomer", "soumen/{training}", "~/soumen.aspx");
    }


Now since because you are passing like a value "training" you just need to make the url of same kind , so that the global.asax page can track it.

Now paste the below code under default.aspx file
-------------------------------------------------------------------------------------------------------------------------------------------------

link1.NavigateUrl =  Page.GetRouteUrl("RouteForCustomer", new { training = "ASP.net"});
HyperLink1.NavigateUrl = Page.GetRouteUrl("RouteForCustomer", new { training = "PHP" });


Now add a page soumen.aspx here i have added one. and paste the underlying lines
--------------------------------------------------------------------------------------------------------------------------------------------------
string category = Page.RouteData.Values["training"] as string;
lbl.Text = category;


thats it.

Wednesday, September 19, 2012

C# DateTime Format

Many DateTime formats are available. C# programs use the ToString method on the DateTime type. ToString receives many useful formats. These formats have confusing syntax forms. Correct formatting of dates and times is essential to many programs.

Format string

To start, we see an example of how you can use a specific formatting string with DateTime and ToString to obtain a special DateTime string. This is useful when interacting with other systems, or when you require a precise format.

Program that uses DateTime format [C#]  using System;  class Program
{static void Main()
{ DateTime time = DateTime.Now;// Use current time
string format = "MMM ddd d HH:mm yyyy"; // Use this format
Console.WriteLine(time.ToString(format)); // Write to console } }
Output Feb Fri 27 11:41 2009 Format string pattern MMM
three-letter month ddd display three-letter day of the WEEK d
display day of the MONTH HH display two-digit hours on 24-hour scale mm
display two-digit minutes yyyy display four-digit year

Note: The letters in the format string above specify the output you want to display. The final comment shows what the MMM, ddd, d, HH, mm, and yyyy will do.

Modify format


Continuing on, we see how you can modify the DateTime format string in the above example to get different output with ToString. We change some of the fields so the resulting value is shorter.

Program that uses different format [C#]
using System;
class Program {static void Main()
{ DateTime time = DateTime.Now; // Use current time string format = "M d h:mm yy";
// Use this format Console.WriteLine(time.ToString(format)); // Write to console } }
Output 2 27 11:48 09 Format string pattern M display one-digit month number
[changed] d display one-digit day of the MONTH [changed] h
display one-digit hour on 12-hour scale [changed] mm
display two-digit minutes yy display two-digit year
[changed]

Format string usages. You will also need to specify a format string when using DateTime.ParseExact and DateTime.ParseExact. This is because those methods require a custom pattern to parse.



Next you can use a single character with ToString or DateTime.ParseExact to specify a preset format available in the framework. These are standard formats and useful in many programs. They can eliminate typos in the custom format strings.

Program that tests formats [C#]
using System;
class Program {
static void Main()
{ DateTime now = DateTime.Now;
Console.WriteLine(now.ToString("d"));
Console.WriteLine(now.ToString("D"));
Console.WriteLine(now.ToString("f"));
Console.WriteLine(now.ToString("F"));
Console.WriteLine(now.ToString("g"));
Console.WriteLine(now.ToString("G"));
Console.WriteLine(now.ToString("m"));
Console.WriteLine(now.ToString("M"));
Console.WriteLine(now.ToString("o"));
Console.WriteLine(now.ToString("O"));
Console.WriteLine(now.ToString("s"));
Console.WriteLine(now.ToString("t"));
Console.WriteLine(now.ToString("T"));
Console.WriteLine(now.ToString("u"));
Console.WriteLine(now.ToString("U"));
Console.WriteLine(now.ToString("y"));
Console.WriteLine(now.ToString("Y"));} }
Output
d 2/27/2009 D
Friday, February 27, 2009 f
Friday, February 27, 2009 12:11 PM F
Friday, February 27, 2009 12:12:22 PM g
2/27/2009 12:12 PM G 2/27/2009 12:12:22 PM m
February 27 M February 27 o 2009-02-27T12:12:22.1020000-08:00 O
2009-02-27T12:12:22.1020000-08:00 s 2009-02-27T12:12:22 t
12:12 PM T 12:12:22 PM u 2009-02-27 12:12:22Z U
Friday, February 27, 2009 8:12:22 PM y February, 2009 Y February, 2009

Date strings

Here we see the ToLongDateString, ToLongTimeString, ToShortDateString, and ToShortTimeString methods on DateTime. These methods are equivalent to the lowercase and uppercase D and T methods shown in the example above.

Program that uses ToString methods [C#]
using System; class Progra{ static void Main()
{ DateTime now = DateTime.Now; Console.WriteLine(now.ToLongDateString());
// Equivalent to D Console.WriteLine(now.ToLongTimeString());
// Equivalent to T Console.WriteLine(now.ToShortDateString());
// Equivalent to d Console.WriteLine(now.ToShortTimeString());
// Equivalent to t
Console.WriteLine(now.ToString()); } }
Output ToLongDateString
Friday, February 27, 2009 ToLongTimeString
12:16:59 PM ToShortDateString 2/27/2009 ToShortTimeString
12:16 PM ToString 2/27/2009 12:16:59 PM

SOURCE-http://www.dotnetperls.com/datetime-format

Tuesday, September 11, 2012

Add fck editor in php

include "fckeditor/fckeditor.php"; //Top of the page


where you need the edior

$FCKeditor = new FCKeditor('FCKeditor1');
$FCKeditor->BasePath = 'fckeditor/';
$FCKeditor->Value = $content;
$FCKeditor->Height = '400px';
$FCKeditor->Create();
?>

Monday, September 10, 2012

To find the second highest salary from a table 

select top 1 name,id from tbltest where name not in (select top 1 name from tbltest order by name desc) order by name desc

Same if you want to select the nth highest salary from a table 

select top 1 name,id from tbltest where name not in (select top n name from tbltest order by name desc) order by name desc

Thursday, August 30, 2012

Convert number into words in SQL server

Create a function named InWords 


CREATE FUNCTION  [dbo].[InWords] (@intNumberValue bigint)
RETURNS VARCHAR(2000)
AS
BEGIN
  DECLARE @strNumberString VARCHAR(9)
  DECLARE @strReturn VARCHAR(2000)
  DECLARE @intUnits SMALLINT
  -- Create table of number groups
  DECLARE @tblNumberGroups TABLE (Units SMALLINT, Hundreds SMALLINT, Tens SMALLINT)
   -- Handle errors and 'quick wins'
  IF @intNumberValue IS NULL RETURN NULL
  IF ISNUMERIC(@intNumberValue)=0 RETURN NULL
  IF @intNumberValue = 0 RETURN 'ZERO'
  IF @intNumberValue < 0
  BEGIN
    SET @strReturn='MINUS '
    SET @intNumberValue=ABS(@intNumberValue)
  END
  SET @intUnits =0
  -- Populate table of number groups
  WHILE (@intNumberValue % 1000) > 0 OR  (@intNumberValue/1000) >0
  BEGIN
    INSERT INTO @tblNumberGroups (Units, Hundreds, Tens) VALUES (@intUnits, (@intNumberValue % 1000)/100, (@intNumberValue % 1000) % 100 )
    SELECT @intNumberValue = CAST (@intNumberValue / 1000 AS INTEGER)
    SET @intUnits = @intUnits + 1
  END
  -- Remove last unit added
  SET @intUnits = @intUnits-1
  -- Concatenate text number by reading number groups in reverse order
  SELECT @strReturn = ISNULL(@strReturn,' ') +
  ISNULL(
  ISNULL((CASE Hundreds
    WHEN 1 THEN 'ONE HUNDRED '
    WHEN 2 THEN 'TWO HUNDRED '
    WHEN 3 THEN 'THREE HUNDRED '
    WHEN 4 THEN 'FOUR HUNDRED '
    WHEN 5 THEN 'FIVE HUNDRED '
    WHEN 6 THEN 'SIX HUNDRED '
    WHEN 7 THEN 'SEVEN HUNDRED '
    WHEN 8 THEN 'EIGHT HUNDRED '
    WHEN 9 THEN 'NINE HUNDRED '
  END),' ') +
  CASE WHEN (Hundreds >0 OR Units<@intUnits) AND Tens > 0   THEN ' AND ' ELSE ' ' END +
  ISNULL((CASE Tens / 10
    WHEN 2 THEN 'TWENTY '
    WHEN 3 THEN 'THIRTY '
    WHEN 4 THEN 'FORTY '
    WHEN 5 THEN 'FIFTY '
    WHEN 6 THEN 'SIXTY '
    WHEN 7 THEN 'SEVENTY '
    WHEN 8 THEN 'EIGHTY '
    WHEN 9 THEN 'NINETY '
  END),' ') +
  ISNULL((CASE Tens
    WHEN 10 THEN 'TEN '
    WHEN 11 THEN 'ELEVEN '
    WHEN 12 THEN 'TWELVE '
    WHEN 13 THEN 'THIRTEEN '
    WHEN 14 THEN 'FOURTEEN '
    WHEN 15 THEN 'FIFTEEN '
    WHEN 16 THEN 'SIXTEEN '
    WHEN 17 THEN 'SEVENTEEN '
    WHEN 18 THEN 'EIGHTEEN '
    WHEN 19 THEN 'NINETEEN '
  END),' ') +
  COALESCE(
    CASE WHEN Tens %10 =1 AND Tens / 10  <> 1 THEN 'ONE ' END,
    CASE WHEN Tens %10 =2 AND Tens / 10  <> 1 THEN 'TWO ' END,
  CASE WHEN Tens %10 =3 AND Tens / 10  <> 1 THEN 'THREE ' END,
  CASE WHEN Tens %10 =4 AND Tens / 10  <> 1 THEN 'FOUR ' END,
    CASE WHEN Tens %10 =5 AND Tens / 10  <> 1 THEN 'FIVE ' END,
    CASE WHEN Tens %10 =6 AND Tens / 10  <> 1 THEN 'SIX ' END,
    CASE WHEN Tens %10 =7 AND Tens / 10  <> 1 THEN 'SEVEN ' END,
    CASE WHEN Tens %10 =8 AND Tens / 10  <> 1 THEN 'EIGHT ' END,
    CASE WHEN Tens %10 =9 AND Tens / 10  <> 1 THEN 'NINE ' END,
  ' ')+
  COALESCE(
   CASE WHEN Units=1 AND (Hundreds>0 OR Tens>0) THEN 'THOUSAND ' END,
    CASE WHEN Units=2 AND (Hundreds>0 OR Tens>0) THEN 'MILLION ' END,
   CASE WHEN Units=3 AND (Hundreds>0 OR Tens>0) THEN 'BILLION ' END,
   CASE WHEN Units=4 AND (Hundreds>0 OR Tens>0) THEN 'TRILLION ' END,
  ' ')
   ,' ')
  FROM @tblNumberGroups
  ORDER BY units DESC
 
  -- Get rid of all the spaces
  WHILE CHARINDEX('  ', @strReturn)>0
   BEGIN
      SET @strReturn = REPLACE(@strReturn,'  ',' ')
   END
  SET @strReturn = LTRIM(RTRIM(@strReturn))
  RETURN @strReturn
END
GO




Now execute the query to call the function with the given parameters and get the result
select  dbo.InWords(-234973555459)
---------------------------------------------------------------
MINUS TWO HUNDRED AND THIRTY FOUR BILLION NINE HUNDRED AND SEVENTY THREE MILLION FIVE HUNDRED AND FIFTY FIVE THOUSAND FOUR HUNDRED AND FIFTY NINE


For more you can visit
http://stackoverflow.com/questions/4245330/sql-query-for-retrieving-numeric-value-and-printing-as-words


Wednesday, August 29, 2012

Convert Numeric value in words in PHP

function convert_number($number)
{
if (($number < 0) || ($number > 999999999))
{
throw new Exception("Number is out of range");
}

$Gn = floor($number / 1000000); /* Millions (giga) */
$number -= $Gn * 1000000;
$kn = floor($number / 1000); /* Thousands (kilo) */
$number -= $kn * 1000;
$Hn = floor($number / 100); /* Hundreds (hecto) */
$number -= $Hn * 100;
$Dn = floor($number / 10); /* Tens (deca) */
$n = $number % 10; /* Ones */

$res = "";

if ($Gn)
{
$res .= convert_number($Gn) . " Million";
}

if ($kn)
{
$res .= (empty($res) ? "" : " ") .
convert_number($kn) . " Thousand";
}

if ($Hn)
{
$res .= (empty($res) ? "" : " ") .
convert_number($Hn) . " Hundred";
}

$ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen",
"Nineteen");
$tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
"Seventy", "Eigthy", "Ninety");

if ($Dn || $n)
{
if (!empty($res))
{
$res .= " and ";
}

if ($Dn < 2)
{
$res .= $ones[$Dn * 10 + $n];
}
else
{
$res .= $tens[$Dn];

if ($n)
{
$res .= "-" . $ones[$n];
}
}
}

if (empty($res))
{
$res = "zero";
}

return $res;
}

Get Query string values from Javascript

function QuseryStringValue(QID) {

// Fetch the query string.
var QStringOriginal = window.location.search.substring(1);

// Change the case as querystring id values normally case insensitive.
QString = QStringOriginal.toLowerCase();
var qsValue = '';

// QueryString ID.
QID = QID.toLowerCase();
// Start & end point of the QueryString Value.
var qsStartPoint = QString.indexOf(QID);
if (qsStartPoint != -1) {

qsValue = QStringOriginal.substring(qsStartPoint + QID.length + 1);
// Search for '&' in the query string;
var qsEndPoint = qsValue.indexOf('&');
if (qsEndPoint != -1) {

// retrive the QueryString value & Return it.
qsValue = qsValue.substring(0, qsEndPoint);

}
else if (qsValue.indexOf('#') != -1) {

// Search for '#' in the query string;
qsEndPoint = qsValue.indexOf('&');
// retrive the QueryString value & Return it.
qsValue = qsValue.substring(0, qsEndPoint);

}
else {

qsValue = qsValue.substring(0);

}

}

return qsValue;
}

Saturday, August 18, 2012

If your are having a problem with "DbContext" class in Entity coding.
Please download the dll from http://packages.nuget.org/v1/package/download/entityframework/4.3.0
and remane  "EntityFramework.4.3.0.nupkg" to "EntityFramework.4.3.0.nupkg.rar".
Add the dll reference into your project and go on .

thanks

Thursday, May 10, 2012

add ToolStripMenuItem in ContextMenuStrip

 Dim n As New NotifyIcon
  Dim icon1 As New Icon("1.ico")
        n.Icon = icon1

        n.Visible = True

Private Sub DisplayContextMenus()

        Dim _ContextMenu As New ContextMenuStrip, cMenuMod As New ToolStripMenuItem, cMenuSubMod As New ToolStripMenuItem, MenuForm As New ToolStripMenuItem
        Dim dtModule As New DataTable
        Dim dtSubModule As New DataTable
        Dim dtForm As New DataTable
        'Addition of User Privilege Menus
        dtModule = _CDALMenu.Dotask("GET_MODULE_BY_USER_ID", 0, 0, modgrocery.iUserid, "", 0)
        For i As Integer = 0 To dtModule.Rows.Count - 1
            cMenuMod = New ToolStripMenuItem
            With cMenuMod
                .Text = "&" & dtModule.Rows(i)("mod_name").ToString
                .Name = dtModule.Rows(i)("mod_name").ToString
            End With
            'Addition of User Privilege SubMenus
            dtSubModule = _CDALMenu.Dotask("GET_SUBMODULE_BY_MODID_USER_ID", dtModule.Rows(i)("mod_id").ToString, 0, modgrocery.iUserid, "", 0)
            For j As Integer = 0 To dtSubModule.Rows.Count - 1
                cMenuSubMod = New ToolStripMenuItem
                With cMenuSubMod
                    .Text = "&" & dtSubModule(j)("smd_name").ToString
                    .Name = dtSubModule(j)("smd_name").ToString
                End With
                dtForm = _CDALMenu.Dotask("GET_FORM_BY_SUBMODID_USER_ID", 0, dtSubModule.Rows(j)("smd_id").ToString, modgrocery.iUserid, "", 0)
                For k As Integer = 0 To dtForm.Rows.Count - 1
                    MenuForm = New ToolStripMenuItem
                    With MenuForm
                        .Text = "&" & dtForm(k)("frm_name").ToString
                        .Name = dtForm(k)("frm_name").ToString
                    End With

                    ' cMenuSubMod.DropDownItems.Add(MenuForm.ToString, Nothing, New System.EventHandler(AddressOf SelectedChildMenu_OnClick))
                    ' cMenuSubMod.Items.Add(MenuForm)
                    cMenuSubMod.DropDownItems.Add(MenuForm.ToString, Nothing, New System.EventHandler(AddressOf SelectedChildMenu_OnClick))
                    cMenuMod.DropDownItems.Add(cMenuSubMod)
                    'cMenuSubMod.MenuItems.Add(MenuForm)
                    'cMenuMod.i.Add(cMenuSubMod)
                    '_ContextMenu.MenuItems.Add(
                Next
            Next
            _ContextMenu.Items.Add(cMenuSubMod)
            ' _ContextMe'nu.Items.Add(
        Next
        n.ContextMenuStrip = _ContextMenu
    End Sub

Sunday, May 6, 2012

Extract from zip file in PHP

<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
    echo 'ok';
    $zip->extractTo('ex');
    $zip->close();
} else {
    echo 'failed, code:' . $res;
}
?>

Sunday, April 15, 2012

GET ALL CONTROL INSIDE FORM AND SET CONTROLS PROPERTY

Public Shared Function GetControls(ByVal form As Control) As List(Of Control)
Dim controlList = New List(Of Control)()
For Each childControl As Control In form.Controls
' Recurse child controls.
controlList.AddRange(GetControls(childControl))
controlList.Add(childControl)
Next
Return controlList
End Function


Private Sub SetControls(ByVal _controls As List(Of Control), ByRef dtControrName As DataTable)
Dim cControl As Control

For Each cControl In _controls
If (TypeOf cControl Is Button) Then

For i As Integer = 0 To dtControrName.Rows.Count - 1

If (cControl.Name = dtControrName.Rows(i)(0).ToString) Then
cControl.Enabled = True
Exit For
Else
cControl.Enabled = False
End If
Next
End If

Next cControl
End Sub


Dim controlList = New List(Of Control)()
controlList = GetControls(_form)//Parametar formname
SetControls(controlList, dtGET_FORM_PERMISSION)

Friday, April 13, 2012

Dynamic css file change

1. Create a html file

and put the codes




Dynamic css file changing







-A    A    A+
Soumen Ghosh





2. And create 3 css files with different font size and name them

"style1.css" write body { text-align: center; font-size:9px; }
"style2.css" write body { text-align: center; font-size:20px; }
"style3.css" write body { text-align: center; font-size:36px; }

Textbox eocus change on enter key press

Private Sub txtModiulname_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtModiulname.KeyDown
If e.KeyCode = Keys.Enter Then
Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
End If
End Sub

Auto Clear Textbox Control

$(document).ready(function () {
  $('.autoclear').autoclear();
});

<form method="post">
  <label for="name">Name:</label><input type="text" id="name" name="name" title="John Smith" value="<?php echo $_POST['name']; ?>" class="autoclear"/>
  <label for="email">Email:</label><input type="text" id="email" name="email" title="your@yourdomain.com" value="<?php echo $_POST['email']; ?>" class="autoclear"/>
  <label for="about">About:</label><textarea id="about" name="about" title="Tell us a little bit about yourself..." class="autoclear"><?php echo $_POST['about']; ?>
  <input type="submit" value="Submit"/><input type="reset" value="Reset"/>
</form>

Wednesday, March 28, 2012

Make image proportionately small from url link asp.net

int width = 0;
int height = 0;

//
var webClient = new System.Net.WebClient();
byte[] image = webClient.DownloadData("http://static.livedemo00.template-help.com/wt_38438/images/page4_img2b.jpg");
//

//byte[] image = FileUpload1.FileBytes;

Int32.TryParse("100", out width);
Int32.TryParse("100", out height);
ImageHandler imageHandler = new ImageHandler();
bool maintainAR = true;
//calling CreateThumbnail Method to create thumb images
//it returns Bitmap Image.
Bitmap bmp = imageHandler.CreateThumbnail(image, maintainAR, width, height);
if (bmp != null)
{
//creating a file name with guid.
string fileName = Guid.NewGuid().ToString() + ".jpg";
//saving in current root folder.
bmp.Save(Server.MapPath(fileName));
//set image controls ImageUrl to saved Image, this is to view the thumbnail image
Image1.ImageUrl = fileName;
}
else
{
//exception part
if (imageHandler.havException)
{
Response.Write(imageHandler.ExceptionMessage);
}
}

Tuesday, March 27, 2012

Image upload through FCK editor - Solution

Steps to make it working.

1. Add





in web.config file.

this path represents the path you want are uploading the image

2. change

var _FileBrowserLanguage = 'aspx'; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx'; // asp | aspx | cfm | lasso | perl | php | py

in fckconfig.js file. for .net only.

3. put the absolute path like

UserFilesAbsolutePath = "C:\\Users\\soumen\\Desktop\\web\\fckeditor\\editor\\images\\UserFilesUpload";


in connector.aspx under "\fckeditor\editor\filemanager\connectors\aspx"

Monday, March 19, 2012

http://biggani.com

http://biggani.com

Encode decode in PHP



class Encryption {
var $skey = "kuntal"; // you can change it

public function safe_b64encode($string) {

$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}

public function safe_b64decode($string) {
$data = str_replace(array('-','_'),array('+','/'),$string);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
return base64_decode($data);
}

public function encode($value){

if(!$value){return false;}
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv);
return trim($this->safe_b64encode($crypttext));
}

public function decode($value){

if(!$value){return false;}
$crypttext = $this->safe_b64decode($value);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}
}

?>

seo free article sub mission directory

http://pravalikadesigns.com/articles-sites-list.html

Tuesday, February 14, 2012

Only digit in text box in vb.net

Public Function TrapKey(ByVal KCode As String) As Boolean

If (KCode >= 48 And KCode <= 57) Or KCode = 8 Or KCode = 46 Then

'The AsCII values for numbers are between 48 to 57 and ASCII value 8 is for BackSpace.

TrapKey = False

Else

TrapKey = True

End If

End Function

Monday, January 23, 2012

Populate Tree view in vb.net from data base(parent child realation)

Private Sub Filltree()
Dim DSNWind As DataSet


Dim oRead As System.IO.StreamReader
Dim EntireFile As String
oRead = IO.File.OpenText(Application.StartupPath() + "/connection.txt")
EntireFile = oRead.ReadToEnd()
'end soumen
Dim connectionString As String = EntireFile
Dim conn As New SqlConnection(connectionString)
Dim dadagdetails As New SqlDataAdapter("select dd.dagdeatilsid,'Land type--'+l.landtype+',Satak--'+cast(dd.quantity as varchar) as [Details]from tblDagdetails as dd inner join tbllandtype as l on dd.landtype=l.landtypeid where dd.dagid='" + cmbDag.SelectedValue.ToString() + "'", conn)
Dim daowner As New SqlDataAdapter("select * from tblowner ", conn)
Dim daownerrealation As New SqlDataAdapter("select * from tblOwner", conn)
DSNWind = New DataSet

dadagdetails.Fill(DSNWind, "dagdetails")
daowner.Fill(DSNWind, "owner")
daownerrealation.Fill(DSNWind, "ownerrealation")


'DSNWind = New DataSet()
' DSNWind = db.GetDataSet("select dd.dagdeatilsid,'Land type--'+l.landtype+',Satak--'+cast(dd.quantity as varchar) as [Details]from tblDagdetails as dd inner join tbllandtype as l on dd.landtype=l.landtypeid where dd.dagid='" + cmbDag.SelectedValue.ToString() + "'", "dagdetails")
' DSNWind = db.GetDataSet("select * from tblowner ", "owner") 'where dagdetailsid=
' DSNWind = db.GetDataSet("select * from tblOwner ", "ownerrealation") 'where


'Create a data relation object to facilitate the relationship between the Customers and Orders data tables.
DSNWind.Relations.Add("tblDagdetails", DSNWind.Tables("dagdetails").Columns("dagdeatilsid"), DSNWind.Tables("owner").Columns("dagdetailsid"))
DSNWind.Relations.Add("tblOwner", DSNWind.Tables("owner").Columns("ownerid"), DSNWind.Tables("ownerrealation").Columns("parentid"), False)
'''''''''''''''''''''''


TreeView1.Nodes.Clear()
Dim i, n As Integer
Dim parentrow As DataRow
Dim ParentTable As DataTable
ParentTable = DSNWind.Tables("dagdetails")

For Each parentrow In ParentTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item(1))
TreeView1.Nodes.Add(parentnode)
''''populate child'''''
'''''''''''''''''''''''
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode()
For Each childrow In parentrow.GetChildRows("tblDagdetails")
childnode = parentnode.Nodes.Add(childrow(3)) ' & " " & childrow(1) & " " & childrow(2))
childnode.Tag = childrow("dagdetailsid")
''''populate child2''''
''''''''''''''''''''''''''
Dim childrow2 As DataRow
Dim childnode2 As TreeNode
childnode2 = New TreeNode()
For Each childrow2 In childrow.GetChildRows("tblOwner")
childnode2 = childnode.Nodes.Add(childrow2(3))

Next childrow2
''''''''''''''''''''''''

Next childrow
'''''''''''''''
Next parentrow

End Sub