Saturday, July 24, 2010

User Ctrl PPL Picker....!

selectionset="User" showcreatebuttoninactivedirectoryaccountcreationmode="false"
showentitydisplaytextintextbox="true" validatorenabled="true">




protected void AddUserBtn_Click(object sender, EventArgs e)
{
try
{
if (userPPE.ResolvedEntities.Count > 0)
{
PickerEntity tempEntity = ((PickerEntity)userPPE.ResolvedEntities[0]);
string userID = tempEntity.Key;
string userEmailID = string.Empty;
string userName = string.Empty;

if (tempEntity.EntityData["Email"] != null)
{
userEmailID = tempEntity.EntityData["Email"].ToString();
}

if (tempEntity.EntityData["Name"] != null)
{
userName = tempEntity.EntityData["Name"].ToString();
}

SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb web = SPContext.Current.Web;
web.Groups["UsersGroup"].AddUser(userID, userEmailID, userName, "");
msgLbl.Text = "User added successfully to the UsersGroups....";
});
}
}
catch (Exception ex)
{
msgLbl.Text = ExceptionMsg;
LogException.WriteToFile(System.DateTime.Now.ToString() + ex.Message + ex.Source.ToString() + ex.StackTrace.ToString());
}
}
------------------------------------------------------

Fill Users Group in DropDown


SPUserCollection grpMgrUsers = hulWeb.Groups["AO"].Users;
if (grpMgrUsers != null)
{
if (grpMgrUsers.Count > 0)
{
foreach (SPUser usr in grpMgrUsers)
{
if (string.Compare(usr.Name, "System Account", true) != 0)
{
basisProjMgrDDL.Items.Add(new ListItem(usr.Name, usr.LoginName));
}
}
}
-----------------------------------------------------

Redirect URL (Cancel)


public string RedirectURL()
{
if (Context.Request.QueryString["Source"] != "")
{
return Context.Request.QueryString["Source"];
}
return "/";
}

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








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

PCar Stuff......................!

SPSite site = new SPSite(SiteURL);

SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;

SPList poolCarRequest = web.Lists["Pool Car Request"];

SPQuery query = new SPQuery();

//This below Query will return will return todays previous reuquested car.
query.Query = "" + date.Year + "-" + date.Month + "-" + date.Day + "";

//st.WriteLine("1 "+lip["Pool Car Name"].ToString());
SPListItemCollection lic = poolCarRequest.GetItems(query);

if (lic.Count == 0)
{
return true;
}
else if (lic[0]["Car Name"].ToString() == "Pool Car 1")
{
return false;
}
else
{
return true;
}

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

public DataSet GetDriverDetails(string carName)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Driver Name");
dt.Columns.Add(dc);
dc = new DataColumn("Driver Mobile No");
dt.Columns.Add(dc);
dc = new DataColumn("Vehicle No");
dt.Columns.Add(dc);
if (carName != null && carName != "")
{

SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite site = new SPSite(SiteURL);
SPWeb web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

SPList poolCar = web.Lists["Pool Cars"];

SPQuery query = new SPQuery();
query.Query = "" + carName + "";

//st.WriteLine("1 "+lip["Pool Car Name"].ToString());
SPListItemCollection lic = poolCar.GetItems(query);
if (lic.Count != 0)
{
dr = dt.NewRow();
dr["Driver Name"] = lic[0]["Driver Name"].ToString();
dr["Driver Mobile No"] = lic[0]["Driver Mobile No"].ToString();
dr["Vehicle No"] = lic[0]["Vehicle No"].ToString();
dt.Rows.Add(dr);
}
else
{
dr = dt.NewRow();
dr["Driver Name"] = "";
dr["Driver Mobile No"] = "";
dr["Vehicle No"] = "";
dt.Rows.Add(dr);
}
});
}
else
{
dr = dt.NewRow();
dr["Driver Name"] = "";
dr["Driver Mobile No"] = "";
dr["Vehicle No"] = "";
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
return ds;
}


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


SPSite site = new SPSite(SiteURL);

SPWeb web = site.OpenWeb();

SPList liApprovers = web.Lists["Admin Approvers"];
SPQuery query = new SPQuery();
query.Query = "Pool Car Request Approver";
SPListItemCollection lic = liApprovers.GetItems(query);

Name = lic[0]["Approver"].ToString().Substring(lic[0]["Approver"].ToString().IndexOf("#") + 1);

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

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