Project Name Start with "001"
public string GetProjectClientName(string URL, string ProjectClientName)
{
string strProjectCode = string.Empty;
try
{
DataTable datatable = null;
datatable = new DataTable();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite osite = new SPSite(URL))
{
using (SPWeb oweb = osite.OpenWeb())
{
SPList oSpList = oweb.Lists.TryGetList(Utilities.ListNames.lstProjects);
{
if (oSpList != null)
{
SPQuery oSpQuery = new SPQuery();
oSpQuery.Query = @"<Where>
<Eq>
<FieldRef Name='ProjectClientName' />
<Value Type='Text'>" + ProjectClientName + @"</Value>
</Eq>
</Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
oSpQuery.ViewFields = string.Concat("<FieldRef Name='IBSProjectCode' />");
datatable = oSpList.GetItems(oSpQuery).GetDataTable();
if (datatable != null && datatable.Rows.Count > 0)
{
strProjectCode = Convert.ToString(datatable.Rows[0][0]);
int ProjectCode = Convert.ToInt32(strProjectCode.Substring(strProjectCode.Length - 3));
ProjectCode = ProjectCode + 1;
if (Convert.ToString(ProjectCode).Length == 1)
{
ProjectClientName = GetFirstFourCharacters(Regex.Replace(ProjectClientName.ToUpper(), @"\s+", ""));
ProjectClientName = ProjectClientName + "00" + ProjectCode;
}
else if (Convert.ToString(ProjectCode).Length == 2)
{
ProjectClientName = GetFirstFourCharacters(Regex.Replace(ProjectClientName.ToUpper(), @"\s+", ""));
ProjectClientName = ProjectClientName + "0" + ProjectCode;
}
}
else
{
ProjectClientName = GetFirstFourCharacters(Regex.Replace(ProjectClientName.ToUpper(), @"\s+", ""));
ProjectClientName = ProjectClientName + "001";
}
strProjectCode = ProjectClientName;
}
}
}
}
});
}
catch (Exception ex)
{
throw ex;
}
return strProjectCode;
}
No comments:
Post a Comment