Wednesday, November 25, 2009

Some Tricks 'n' Tips

ServicePeriodDescription (a column in table ServicePeriod )
---------------------------------- ---------------------------
January 2009
January 2008
January 2006 --- using the below query it updates the data like jan 09,jan 08,jan 06

update ServicePeriod set ServicePeriodDescription = left(ServicePeriodDescription,3) + ' ' + right(ServicePeriodDescription,2) where ServicePeriodDescription like '%jan%'

----------------------------------------------------------------------------------------------
Declare @qt as varchar(1000)
set @qt = ''''print @qtselect 'insert into program values ',ProgramID, ',', ProgramCode ,',', @qt+ Description + @qt from program
It creates the Insert Script for the table for columns included in the query.
----------------------------------------------------------------------------------------------
Check All check boxes either in grid or form using javascript coded in .cs file
String cbID;
String js;
int i = 0;
js = "";
for(i=2; i<(dataGrid.Items.Count+2); i++)
{
cbID = "dataGrid__" + "ctl" + i + "_chkSelect";
js += "if(document.getElementById('chkSelectAll').checked == true) {
document.getElementById('" + cbID + "').checked = false
}
else
{
document.getElementById('" + cbID + "').checked = true
};"
;}
chkSelectAll.Attributes.Add("onclick", js);

----------------------------------------------------------------------------------------------
Find whether a year is loop year or not
public static bool IsLeapYear (int year)
{
if (DateTime.IsLeapYear(year))
{
return true;
}
else
{
return false;
}}
-------------------------------------------------------------------------------------
Extract Numbers from a combineString c# Code

String str="January2007";

static string ExtractNumbers(string expr)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));
}

static string ExtractText(string expr)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(expr, "[^A-z]"));
}

-------------------------------------------------------------------------------------
Checking only CheckList instead of checking all CheckBoxes in a form

function chkall()
{
for (var n=0; n < document.forms[0].length; n++)
{
if (document.forms[0].elements[n].type=='checkbox'&& document.forms [0].elements[n].name.indexOf('chklstReasonCodes') > -1)
{
document.forms[0].elements[n].checked=true;
}
}
return false;
}

CheckAll

-------------------------------------------------------------------------------------
Getting values from .Net to JavaScript and placing values in DataGrid Controls

//Get the Controls of Grid Using UniqueID* Property

DropDownList ddl = (DropDownList)e.Row.FindControl("ddl");
string strcmbDOBYEARId = ddl.UniqueID;

TextBox txtResult = (TextBox)e.Row.FindControl("txtResult");
string strResult = txtResult.UniqueID;

ddl.Attributes.Add("onchange", "PulltoTextBox('" + strcmbDOBYEARId + "','" + strResult + "')");

function PulltoTextBox(ddlid,txtid)
{
var array = document.getElementById(ddlid);
var array1 = document.getElementsByName(txtid);
var sel="";
sel=array.options[array.selectedIndex].text;
array1[0].value=sel + "-" + array[0].value;
}

-------------------------------------------------------------------------------------

Sunday, November 22, 2009

Some Quotes i like

---In Iife we make some reIationshipsand some are made by god.
---prradhinchey పెదవులు కన్నా దానం chesey చేతులు మిన్న
---All's well that ends వెల్ (which means that problems do not matter so long as the outcome is good).

Wednesday, November 18, 2009

Master Page Related

//TO find Controls from the ContentPlaceHolder
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
mpContentPlaceHolder =(ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if(mpContentPlaceHolder != null)
{
mpTextBox =
(TextBox) mpContentPlaceHolder.FindControl("TextBox1");
if(mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
}

Sunday, November 15, 2009

grid view conditional formatting

http://www.simple-talk.com/content/article.aspx?article=438

//To disp discontinued items in red and the unitsinstoock items less than '0' as blue
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = (DataRowView)e.Row.DataItem;
if (Convert.ToInt32(drv["UnitsInStock"]) == 0)
{
//The current product has 0 items in stock
e.Row.Font.Bold = true; //Make the font bold
e.Row.ForeColor = System.Drawing.Color.Red;
//Set the text color red
if (Convert.ToInt32(drv["UnitsOnOrder"]) > 0)
{
//The current out of stock item has already been ordered
//Make it blue
e.Row.ForeColor = System.Drawing.Color.Blue;
}
}
if ((bool)drv["Discontinued"])
{
//Discontinued product
//Add the image
Image img = new Image();
img.AlternateText = "Discontinued Product";
img.ImageAlign = ImageAlign.AbsMiddle;
img.ImageUrl = "arrow_down.gif";
img.Width = Unit.Pixel(10);
img.Height = Unit.Pixel(11);
e.Row.Cells[0].Controls.Add(img);
//Add the text as a control
e.Row.Cells[0].Controls.Add(new LiteralControl(" " + e.Row.Cells[0].Text));
} }}
-----------------------------------------------------------------------------------
string previousCat = "";
int firstRow = -1;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = ((DataRowView)e.Row.DataItem);
if (previousCat == drv["CategoryName"].ToString())
{
//If it's the same category as the previous one
//Increment the rowspan
if (GridView1.Rows[firstRow].Cells[0].RowSpan == 0)
GridView1.Rows[firstRow].Cells[0].RowSpan = 2;
else
GridView1.Rows[firstRow].Cells[0].RowSpan += 1;
//Remove the cell
e.Row.Cells.RemoveAt(0);
}
else //It's a new category
{
//Set the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;
//Maintain the category in memory
previousCat = drv["CategoryName"].ToString();
firstRow = e.Row.RowIndex;
} }}
-------------------------------------------------------------------------------

Saturday, September 19, 2009

Get paid for the damages to your car

Hello,
My name is Alicia. On the evening of September 5, 2008, my boyfriendand I decided to take advantage of your 3-year no interest offer onnew HDTVs at store #204 in Austin, Texas. We selected a 46" Samsung,which was sent to the front of the store to be loaded into my car.

A helpful employee loaded it into the back of my 2008 Honda Fit.Unfortunately, in this process my car bumper was damaged. Paint wasscraped off, and several gouges were left. As soon as we noticed thedamage, we called the store we had just purchased the TV from, andasked to speak to a supervisor. We were transferred to ConsumerRelations line instead. After speaking to a representative namedRenee about the issue, we were put on hold so that she could "processsome information." We waited approximately 30 minutes on hold beforegiving up and hanging up. We then called store #204 back, and askedagain to speak to a supervisor, and were again transferred to ConsumerRelations and placed on hold for an extended period of time and againnot helped. We were told by the staff member answering the phone atthe store that there were no other options on whom we could speak to,thus I am e-mailing you in attempts to receive some kind of resolutionto this issue.
We have been loyal Best Buy customers for upwards of six years. Wehave easily spent at least $20,000 between us in that time. Needlessto say, we are very disappointed in the lack of customer service wehave received in this matter.
We would like to remain Best Buy customers, and would like to giveyour office the chance to provide the superior customer service wehave received in the past. I am asking that a representative assessand arrange for repair of damages to my bumper. I have includedseveral pictures of the damage.
I look forward to hearing from you in regards to this matter.
Thank you for your time,
Alicia

Drop Dead Letter

(Date)
To Whom It May Concern:
I have been contacted by your company about a debt you allege I owe. I am instructing you not to contact me further in connection with this debt. Under the Fair Debt Collection Practices Act, a federal law, you may not contact me further once I have notified you not to do so.
Sincerely,
(Name)
(Account No.)

Polite Letter Gets Bank Of America To Refund Overdraft Fees

Jenn's checking account with Bank of America recently had a policy change designed to increase overdraft fees, and it worked: sometime between Friday night and Saturday morning she was hit with 6 NSF charges going back the previous 48 hours, because she was about 15 minutes late transferring funds into her account the day before. Technically she had broken the new policy, but Jenn hadn't realized or remembered that there was a policy change and she was taken by surprise. She decided to try to reason with BoA's corporate office about the fees, and explain why she thought they were unfair.

Today, she let us know that her letter worked: "Just got off the phone with BoA Corporate in Boston. They're refunding everything! It pays to write."


We think it's worth looking at her letter as an example of how to present your side of an issue to a large company. Jenn is polite, and her letter is professional and well-written. She makes a point of explaining why she chose to become a BoA customer in the first place, and how she's been an advocate for them in the past—and then points out that this policy change has the effect of ruining her goodwill toward the company by making them "just like every other bank. It's the reason I left Chase."

Of course, Bank of America isn't rescinding the new policy, so it's not like Jenn's letter changed the world or anything. But it does show that it occasionally pays to write a solid letter to the corporate office if you can't resolve your issue at a branch.

May 7, 2008
Dear Mr. Lewis,

I am writing you to lodge a formal complaint about 6 overdraft fees that were recently charged to my account.

I am a dedicated online banker. I love Bank of America’s to-the-minute online status updates. It is just one of the many reasons I switched to BoA from Chase two years ago. I am also an artist, who though salaried, lives to the penny every month to make ends meet. I check my bank account online every single day. Sometimes three or four times a day.

Since joining BoA I have operated under the “as long as there is a positive amount in the account at the end of the day, you won’t get charged an overdraft fee” rule. Up until last week, that was true. I frequently buy a sandwich for lunch at noon if I know I’ll be able to deposit $20 by 5pm. So I was completely shocked to see two overdraft charges show up on a Saturday morning when on Friday night my account was in the black. What’s worse is that the two fees were charged for transactions made on Thursday and so were backdated, thus also overdrafting every transaction I made on Friday accumulating another four $35 fees!

Yesterday I went into the Lincoln & Ashland branch in Chicago, IL to dispute the fact that I was charged overdraft fees on a positive account. My account details were printed and scoured by 3 different CSRs. No one could understand the charges. But no one could do anything about them. They then made a call to Account Services and discovered that apparently the fees were legitimate because of a new rule just instated last month that removes available funds from the account the minute the card is swiped. So because I had bought some lunch just before I transferred money into my account to cover it I was penalized $210 for what amounted to a 15 minute technicality. The CSRs sent me away and told me to plead my case to the customer service number. At the 800-number I was eventually able to talk to “a manager” Jessica, who read me the verbiage that had appeared on customer statements about this change. So, indeed, the charges are apparently my fault. Thankfully, Jessica gave me a courtesy refund for 3 of them, which helps a little.

My complaint is about this new policy. It makes you just like every other bank. It is the reason I left Chase. I thought BoA was different! And I have recommended BoA to MANY of my artist friends because of that flexibility and that, until now, I have had nothing but wonderful experiences with your employees and with my account management.

Unfortunately, the remaining $105 that is now tied up in fees will ensure that my rent check this month bounces which means I will be charged more fees in addition to NSF fees from my rental company, and it is all I had budgeted for food for the first two weeks of this month. The good news is I just got a promotion at work which will, in another month, enable me to pick up and repay this set-back, sign up for automatic deposits, get money into my Savings account that might actually stay there and start to invest in some sort of stability for my future.

I’m just going to have to think long and hard about whether I want to continue doing all of those things with your bank.

Thank you for your time.

Jennifer


Ref:http://consumerist.com/5009230/polite-letter-gets-bank-of-america-to-refund-overdraft-fees

Wednesday, June 3, 2009

Triggerrrrrrrrrrrrrrrrrrrr

/* Commment : Ensure that the same Reasoncode is not used more than once within an ActivityType. Ex: ReasonCodeID=44; ReasonCode=570; Reason=Return to Natural Parent; linked to ActivityType = Trail Discharge ReasonCodeID=69; ReasonCode=570; Reason=Return to Natural Parent; linked to ActivityType = Discharge ReasonCodeID=101; ReasonCode=570; Reason=Return to Natural Parent (other); linked to ActivityType = Trail Discharge --> bad data*/
/* Begin Transaction Insert into ChildActivityReasonCode (ReasonCode, Reason, ReasonGroup, StatusID, ReasonShortDesc, BillingCodeID) Values (570, 'xxx22', 'xxx22', 17, 'xxx22', 1)
Insert into ChildActivityTypeToReasonCode Values (2, @@Identity) Commit Transaction
Begin Transaction Insert into ChildActivityReasonCode (ReasonCode, Reason, ReasonGroup, StatusID, ReasonShortDesc) Values (570, 'yyy', 'yyyy', 17, 'yyy') -- Return to Natural Parent
Insert into ChildActivityTypeToReasonCode Values (2, @@Identity) Commit Transaction
*/
CREATE TRIGGER dbo.trig_ReasonCode_AssertNoDuplicatesWithinActivity ON dbo.ChildActivityTypeToReasonCode
FOR INSERT, UPDATE
AS
BEGIN
DECLARE @reasoncode varchar(50)
DECLARE @activityTypeID int
DECLARE @reasonCodeID int

SELECT @reasoncode = r.Reasoncode, @activityTypeID = i.ChildActivityTypeID, @reasonCodeID = i.ChildActivityReasonCodeIDFROM inserted i
INNER JOIN
dbo.ChildActivityReasonCode r on
i.ChildActivityReasoncodeID = r.ChildActivityReasoncodeID
WHERE r.FlagDeleted = 0
IF ( @reasoncode IS NOT NULL ) AND
EXISTS ( SELECT 'X' FROM dbo.ChildActivityTypeToReasonCode a2r
INNER JOIN
dbo.ChildActivityReasonCode r ON
a2r.ChildActivityReasoncodeID = r.ChildActivityReasoncodeID
WHERE
r.ChildActivityReasonCodeID <> @reasonCodeID
AND a2r.ChildActivityTypeID=@activityTypeID
a2r.ChildActivityTypeID=@activityTypeID
AND Coalesce(r.reasoncode, '-2') = @reasoncode AND r.FlagDeleted = 0 )
BEGIN
RAISERROR ('Duplicate ReasonCode not allowed within an Activity', 16, 1)
ROLLBACK TRANSACTION
END
ELSE
BEGIN
COMMIT TRANSACTION
END
END

Sunday, May 24, 2009

How to get the current user logged into Sharepoint

SPWeb web = SPControl.GetContextWeb(Context);
SPUser sUser = web.CurrentUser;
string str = "Name:" + sUser.Name + "
"; "Login Name :" + sUser.LoginName + "
"; "Email:" + sUser.Email + "
"; "Groups:" + sUser.Groups.Count + "
";
foreach (SPGroup grp in sUser.Groups) { " * " + grp.Name + " total Members:" + grp.Users.Count + "
"; catch (Exception ex) { "No Current User" ;

Getting the Current User Name or ID in SharePoint using SharePoint Designer (no code):
http://blogs.msdn.com/joshuag/archive/2008/06/03/getting-the-current-user-name-or-id-in-sharepoint-using-sharepoint-designer-no-code.aspx

Monday, May 18, 2009

New User Request WF



--- On Wed, 13/5/09, ravi kumar <raviurpal@yahoo.com> wrote:

From: ravi kumar <raviurpal@yahoo.com>
Subject: W
To: raviurpal@yahoo.com
Date: Wednesday, 13 May, 2009, 5:56 PM


Tuesday, May 5, 2009

Updating in Tbl1 col based on cols from Tbl2 and Tbl3

scenario:This query updates the ModuleId,SubModuleID columns in tbl1 based on PQR column by using the values from the two different tables tbl2 and tbl3 i.e. tbl2.ModuleId and tbl3.SubModuleId if PQR column has in the foramt of ModuleName\SubModuleName.

select (select ModuleID from appmodules where Modulename =
substring(permissionssection,0,charindex('\',permissionssection))) as MainModuleID,(select Max(SubModuleID) from appsubmodules where (SubModulename = substring (permissionssection
,charindex('\',permissionssection)+1,len(permissionssection))) or (Replace(SubModulename,' ','') = substring (permissionssection
,charindex('\',permissionssection)+1,len(permissionssection))) ) as SubModuleID,substring(permissionssection,0,charindex('\',permissionssection)) as start,substring (permissionssection ,charindex('\',permissionssection)+1,len(permissionssection)) as endID from securable.

Tuesday, March 24, 2009

Nth Highest salary and Fetching column values for a Id as a single row

declare @vSQL varchar(1000)
declare @n int
set @n=5
set @vSQL='select Top 1 EmpSalary From
(Select Distinct Top ' + convert(varchar, @n) + ' EmpSalary
from EmpsInfo order by EmpSalary desc) a
order by EmpSalary'
exec(@vSQL)



declare @retstr varchar(8000)
select @retstr = COALESCE(@retstr + ',','') + cast(memno as varchar) from sample where sno=1
print @retstr

preparing Insert statement for the ros exst in table -sql server

Declare @qt as varchar(1000)
set @qt = ''''
print @qt
select 'insert into program values ',ProgramID, ',', ProgramCode ,',', @qt+ Description + @qt from program

Monday, March 23, 2009

Regular expression for a Foramt 'XX99999X'

function validationForXYZ()
{

var iKeyCode,strKey;
if(window.event)
iKeyCode = window.event.keyCode;

if ((iKeyCode > 96) && (iKeyCode < keycode =" iKeyCode-32;" ikeycode =" window.event.keyCode;" strkey =" String.fromCharCode(iKeyCode);" obj =" document.getElementById('txtAgencyCIN');" value =" obj.value.toUpperCase();" xyzval =" obj.value" validchars =" /^[A-Z]{1,2}$/;">=3) && (XYZVal.length <= 7)) //checking next 5 chars of numbers
validChars = /^[A-Z]{2}[0-9]{1,5}$/;
else if (XYZVal.length ==8)
validChars = /^[A-Z]{2}[0-9]{5}[A-Z]$/; //again last two if chars
else
return false;
if(!validChars.test(XYZVal))
{
alert("Invalid XYZ format: If present, it must be 8 characters in the format: 'XX99999X'. (eg. AB74819R)");
return false;
}

}

Saturday, March 21, 2009

Expand/Collapse GV

http://www.codeproject.com/KB/webforms/GridViewExpandCollapse.aspx

Friday, March 20, 2009

options for a Question and Tips of DataTable and DataView

lblQ.Text = "what is the result of the following equation?";
Panel1.Controls.Add(lblQ);
rdOptions.Items.Add(First(dt.Rows[intOpt][2].ToString()));
rdOptions.RepeatDirection = RepeatDirection.Horizontal;
rdOptions.RepeatLayout = RepeatLayout.Table;
rdOptions.RepeatColumns = 2;
rdOptions.Width = 400;
rdOptions.CellSpacing = 3;
rdOptions.CellPadding = 3;
Panel1.Controls.Add(rdOptions);


Rowfilter on DT using DataView
-------------------------------
DataView dvSearchResults = dt.DefaultView;
dvSearchResults.RowFilter = "Name LIKE " + "'" + lastname + "%" + "'";

Removing the rows in the column 'Name' containing "Unknown"
------------------------------------------------------------
DataRow[] unknownRecords=ResultsTable.Select("Name='Unknown *'");
foreach(DataRow drUnknownRecs in unknownRecords)
ResultsTable.Rows.Remove(drUnknownRecs);

Querying using DataRow[] object and select Method(XYZ- col name)
--------------------------------------------------
DataRow[] flagDeletedRecords=dtChildActivity.Select("XYZ=1");

Like Operator in DataTable using DataTable.Select
------------------------------------------------
Select("Code LIKE '" + lastWord + "%'" );

searching for a word in a column

searching for word Manager in the column 'Job Title' and make it bold if it have



=CONCATENATE("<DIV",IF(ISERROR(SEARCH("Manager",[Job Title],1))," "," style='font-weight:bold;'"),">",[First Name]," ",[Last Name],"</DIV>")







Restoring the Quick Launch Bar in Web Part Pages

You'll notice that when creating Web Part Pages in SharePoint 2007 that the Quick Launch Bar is not included in the template. Here are the quick instructions (that require SharePoint Designer) to restore the Quick Launch Bar:
Open the web part page in SharePoint designer
Find and delete the following two lines:

asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"
asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"

Save the file

SPSite and SPWeb

using(SPSite oSiteCollection = new SPSite("http://Server_Name"))
{
using(SPWeb oWebsite = oSiteCollection.OpenWeb("Website_URL"))
{
using(SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
{
...
}
}
}

Wednesday, February 25, 2009

Tuesday, February 17, 2009

SP JS


<script type="text/javascript" language="javascript">

function PreSaveAction()

{

var date1 = getFieldAttribute("INPUT","DateTimeFieldDate","Start Time");

var date2 = getFieldAttribute("INPUT","DateTimeFieldDate","End Time");

var arrDate1 = date1.value.split("/");

var useDate1 = new Date(arrDate1[2], arrDate1[1]-1, arrDate1[0]);

var arrDate2 = date2.value.split("/");

var useDate2 = new Date(arrDate2[2], arrDate2[1]-1, arrDate2[0]);

if(useDate1 > useDate2)

{

alert("Please select valid End Date");

return false; // Cancel the item save process

}

return true; // OK to proceed with the save item

}



function getFieldAttribute(tagName, identifier, title)

{

var len = identifier.length;

var tags = document.getElementsByTagName(tagName);

for (var i=0; i < tags.length; i++)

{

var tempString = tags[i].id;

if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))

return tags[i];

}

}



</script>



<script type="text/javascript" language="javascript">

function makeReadOnly()

{

var firstName = document.getElementById("urn:schemas-microsoft-com:office:office#FirstName");



var elements = document.body.getElementsByTagName("*");

for(index=0; index<elements.length; ++index)

{

if(elements[index].title == "Title")

{

elements[index].readOnly = true;

alert("Title");

}



}

}

_spBodyOnLoadFunctionNames.push("makeReadOnly()");

</script>


HCFPT-K86VV-DCKH3-87CCR-FM6HW

Thursday, January 1, 2009

Custom Field Type Definition

A field type definition is an XML file named on the pattern fldtypes*.xml that is deployed to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML. The field types that ship with Windows SharePoint Services 3.0 are located in the FLDTYPES.XML file. A field definition file contains the information that Windows SharePoint Services needs to correctly render the field, including its column header, on a list view page (such as AllItems.aspx). It also typically provides information used to render the field on the view list item page (such as DispForm.aspx). The name and description of the field type, as it appears on such UI pages as the Customize [list] page, the New Site Column, and the Create Column pages, is also configured in the field type definition. Most importantly, the definition contains information about the assembly that contains the compiled field type.
Most field type properties are required by virtually any field type, such as the name and description properties. But a field type definition can also declare and define special properties of the field type that are relevant only to columns made from fields of that particular type. These are called variable field type properties. The values of these properties are set whenever a column is created based on the field type.
In order to recognize a custom field type, Windows SharePoint Services 3.0 must have a field type definition in a fldtypes*.xml file. You create these files in Microsoft Visual Studio as part of a custom field type project. For example, if you had a field type definition for a field type that defined an American Social Security number, you might name the XML file fldtypes_ssn_MyCompany.xml.
Field Types Definition Example
The following example defines two custom field types.




SocialSecurityNumber
Text
Social Security Number
Social Security Number (123456789, 123-45-6789)

TRUE

AdventureWorks.FieldTypes.SSNField, AdventureWorks.FieldTypes,
Version=1.0.0.0,Culture=neutral,PublicKeyToken=90734cc53324b79c







USAddress
MultiColumn
US Address
US Address(12345 NE 123 St. Redmond, WA 98052)

TRUE

AdventureWorks.FieldTypes.USAddressField, AdventureWorks.FieldTypes,
Version=1.0.0.0,Culture=neutral,PublicKeyToken=90734cc53324b79c



MaxLength="50" DisplaySize="15" Type="Text">
Redmond

MaxLength="2" DisplaySize="2" Type="Text">
WA

DisplaySize="5" Type="Text">
98052










]]>