Search This Blog

Loading...

6.10.2008

How-to copy paste faste code in Visual Studio

///
/// This is fake class for quick copy paste. Usage:
/// type HowTo. - the intellisense will display the names you have figured out for each fake method
/// select the name from the list , click in it , right button , G , will get you there ,
/// copy paste the text , Alt + F, C to close and remember to delete the fake call.
///

public class HowTo
{
public static void SettersAndGetters ()
{

//how-to generate those in textpad F8
// how-to Generate member accessors , properties for C# asp.net with textpad
// how-to setters and getters
// find:^(.*)$
// replace:private string s\1 ; \n public string \1 { \n \t\t get { return s\1 ; } \n \t\t set { s\1 = value ; } \n } //comm -- eof \1 property \n\n
//find:^(.*) (.*)$
//private string s\1 ; \n public string \1 { \n \t\t get { return s\1 ; } \n \t\t set { s\1 = value ; } \n } //comm -- eof \1 property \n\n
//
//private \1 _\2 ; \npublic \1 \2 { \n \t\t get { return _\2 ; } \n \t\t set { _\2 = value ; } \n } //eof property \2 \n\n\n
//
////for the constructor
//_\2= this.\2 ;
//
////for the passing to the constuctor
//\1 _\2 ,
} //eof method SettersAndGetters


public static void shortcuts ()
{
string _shortcuts =

@"
//how-to shortcuts
//Ctrl + Shift + F -- recursive find
//Ctrl + H -- find and replace
//Ctrl + M + M -- collapse method
//Ctrl + B --- set a break point
//CTRL + “-” and CTRL + SHIFT + “-” -- web browser like backward and forward in code
//Ctrl + Tab --- shift tabs
//Shift + F5 --- stop debugging
//F5 -- start debugging"

; }


public static void redirectToCurrentUrl () {
string _redirectToCurrentUrl =
@"

Response.Redirect ( System.IO.Path.GetFileName ( System.Web.HttpContext.Current.Request.Url.AbsolutePath ) , false );

" ;
} //eof method


public static void formTypes ()
{
string _formTypes =
@"
//how-to forms 1 - Empty Search Form , 2 - Filled Form , 3 - Empty New form ( new Margin Data , new Project )
//how-to formTypes
//, 4 - filled search form from get by id procedure
// 5 - FilledSearchForm (coming from params)

";
} //eof formTypes

public static void GetTheFileNameWithoutTheExtension ()
{
string s =
@"how-to get the file name requested without the extension in asp.net";
/*debugStart Utils.Debugger.WriteIf ( "My page name without extension is " +
System.IO.Path.GetFileNameWithoutExtension (
System.Web.HttpContext.Current.Request.Url.AbsolutePath ) );
/*debugEnd*/

} //eof methoed


public static void GetThePhysicalRootPathNoExtension ()
{
//how-to get the physical root path on the file system of the application
//string rootPath = Server.MapPath("~"); Utils.Debugger.WriteIf ( "My rootPath is " + rootPath );
} //eof method

public static void AccessConfVariables ()
{
//how-to access conf variables BL.Conf.Instance.Vars [ "varName" ] would give you "theVarName ;
} //eof method

public static void GetRowColumnValue ()
{
//how-to get row column value
//(ds.Tables["TableName"].Rows[0]["ColumnName"] == DBNull.Value ) ? false : (bool)ds.Tables["TableName"].Rows[0]["ColumnName"] ;

} //eof method


public static void GenerateExtendedPropertiesForATable()
{

//table column
//find:^(.*) (.*)$
//Replace:
//EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'title="\2",visible="1",fs="Basic Details",readonly="1"' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'\1', @level2type=N'COLUMN',@level2name=N'\2'
} //eof method



public static void RedirectToTheCurrentURL()
{
//how-to redirect to current url = users.aspx or projects.aspx
//Response.Redirect( System.IO.Path.GetFileName ( System.Web.HttpContext.Current.Request.Url.AbsolutePath ) , false );

} //eof method

public static void THEORY ()
{
//EVENTS AND DELEGATES IN ASP.NET -- http://msdn.microsoft.com/en-us/library/17sde2xt.aspx

} //eof method

public static void CopyMeAsTemplateMethod ()
{ } //eof method

} //eof class HowTo

how-to add programatically TemplateField to run commands on GridView

Add the following in your App_Code folder
===========================copy paste start
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace GUI.Controls
{
///
/// Summary description for GvTemplate
///

public class GvTemplate : ITemplate
{
ListItemType _templateType;
string _columnName;
string _toolTip;
string _itemButtonName;
public GvTemplate (ListItemType type , string columnName , string toolTip , string itemButtonName )
{
_templateType = type;
this._columnName = columnName;
this._itemButtonName = itemButtonName;
this._toolTip = toolTip;
} //eof constructor


void ITemplate.InstantiateIn ( System.Web.UI.Control container )
{
switch (_templateType)
{
case ListItemType.Header :

Label lab = new Label ();
lab.Text = _columnName ;
container.Controls.Add( lab ) ;
break ;
case ListItemType.Item :
Button but = new Button ();
but.DataBinding += new EventHandler ( butDataBinding );
but.ToolTip = _toolTip;
but.Visible = true;
but.Text = "Include"; //todo: parametrize
container.Controls.Add ( but );
break;
} //eof switch _templateTyp

} //eof method InstantiateIn

void butDataBinding ( object sender , EventArgs e )
{
Button but = (Button) sender;
GridViewRow container = (GridViewRow) but.NamingContainer;
object dataValue = DataBinder.Eval ( container.DataItem , _columnName );
if (dataValue != null && dataValue != DBNull.Value)
{
but.ID = dataValue.ToString () ;
but.CommandName = "selectItem"; //todo:parametrize
but.CommandArgument = System.Convert.ToString ( dataValue );
but.Click += new EventHandler ( ClickSelectItem );
}
} //eof method butDataBinding


protected void but_Command ( Object sender , CommandEventArgs e )
{
}

protected void ClickSelectItem ( Object sender , EventArgs e )
{
Button but = (Button) sender ;
Utils.Debugger.WriteIf ( "I have been clicked by " + but.ID );
new Page ().Session [ "global.ClickedItemId" ] = but.ID;
} //eof method edit_button_Click

} //eof class
} //eof namespace GUI.Controls


===========================copy paste end

//In code behind create dynamically your gridview :

GridView gv = new GridView();

//add the handler (only if AutoEvenFireUp is false otherwize it will trigger it twice
gv.RowCommand += new GridViewCommandEventHandler ( RowCommand );

//add the TemplateField
TemplateField colField = new TemplateField ();
colField.HeaderTemplate = new GUI.Controls.GvTemplate
( ListItemType.Header , rdsForReportGv.Tables [ 0 ].Columns [ 0 ].Caption ,
itemButtonToolTip , itemButtonName );


colField.ItemTemplate = new GUI.Controls.GvTemplate (
ListItemType.Item , rdsForReportGv.Tables [ 0 ].Columns [ 0 ].Caption ,
itemButtonToolTip , itemButtonName );
gv.Columns.Add ( colField );


//implement the event handler for a row

protected void RowCommand ( Object sender , GridViewCommandEventArgs e )
{

string _commandName = e.CommandName;

switch (_commandName)
{
case "selectItem":
Utils.Debugger.WriteIf ( "I am in selectedItem" );
Utils.Debugger.WriteIf ( "My command argument is " + e.CommandArgument.ToString () );
Utils.Debugger.WriteIf ( "My command source is " + e.CommandSource.ToString () );
Utils.Debugger.WriteIf ( "My command name is " + e.CommandName );
break;
case "somethingElse":
Utils.Debugger.WriteIf ( "I amd in something else " );
break;
} //eof switch

}

6.02.2008

How-to generate extended properties for sql server 2005 with textpad

table column
find:^(.*) (.*)$
Replace:
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'title="\2",visible="1",fs="Basic Details",readonly="1"' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'\1', @level2type=N'COLUMN',@level2name=N'\2'

Blog Archive

My Blog List

Video Bar

Loading...

About Me

My Photo
Yordan Georgiev
It is one thing to know what to want, second to really want it, third to know how to do it, fourth to be skillful to do it, fifth to actually do it and last but not least to go on without regrets after having done it. LinkedIn Profile
View my complete profile