Javascript in CE webpart:
-----------------------------------
function GetDashboardRefreshDetails(dashBoardName) {
//var listURL ="https://team.amat.com/sites/BIM_QA";
//var url ="/_api/Web/Lists/GetByTitle('BIM Search')/Items?$select=Name,ContentType0,link,BusinessOwningFunction,Active&$filter=BusinessOwningFunction eq '"+pageName+"' and Active eq 1";
var url = "http://spqaappweb.amat.com/DashboardRefreshAPI/API/DashboardAPI?dashboardName='"+dashBoardName+"'";
//var url = "http://localhost:50565/Api/DashboardApi";
$.ajax({
url: url,
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
contentType: "application/json; charset=utf-8",
success : function(response) {
Getdata(response);
},
error: function (error) {
// alert(JSON.stringify(error));
}
});
}
function Getdata(response){
if(response.length > 0){}
}
======================================================================
C# controller code:
--------------
public void GetRefreshDetails(string dashboardName)
{
dashboardName = dashboardName.Substring(1, dashboardName.Length - 2);
BAL obj = new BAL();
List<BAL> objList = obj.GetRefreshData(dashboardName);
StringBuilder sb = new StringBuilder();
JavaScriptSerializer js = new JavaScriptSerializer();
var callBackFunction = HttpContext.Current.Request["callback"];
sb.Append(callBackFunction + "(");
sb.Append(js.Serialize(objList));
sb.Append(");");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.End();
// return objList;
}
[WebMethod()]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetToolsCount()
{
ToolsData obj = new ToolsData();
List<ToolsData> objList = obj.GetToolsCount();
StringBuilder sb = new StringBuilder();
JavaScriptSerializer js = new JavaScriptSerializer();
var callBackFunction = HttpContext.Current.Request["callback"];
sb.Append(callBackFunction + "(");
sb.Append(js.Serialize(objList));
sb.Append(");");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.End();
// return objList;
}
}
=====================================================================
C# Modal
------------------
public class ToolsData
{
public string Tools { get; set; }
public string ActiveTools { get; set; }
public string ContractTools { get; set; }
public string WarrantyTools { get; set; }
public string InsatllTools { get; set; }
public string SemiTools { get; set; }
public string DisplayTools { get; set; }
public string VarianTools { get; set; }
public string OtherTools { get; set; }
public string Chambers { get; set; }
public List<ToolsData> GetToolsCount()
{
DataTable dt = new DataTable();
List<ToolsData> objList = new List<ToolsData>();
DAL objDal = new DAL();
dt = objDal.GetToolData();
if (dt != null)
{
foreach (DataRow row in dt.Rows)
{
ToolsData obj = new ToolsData();
obj.Tools = Convert.ToString(row["Tools"]);
obj.ActiveTools = Convert.ToString(row["ActiveTools"]);
obj.ContractTools = Convert.ToString(row["InContractTools"]);
obj.WarrantyTools = Convert.ToString(row["InWarrantyTools"]);
obj.InsatllTools = Convert.ToString(row["InInstallTools"]);
obj.SemiTools = Convert.ToString(row["SemiTools"]);
obj.DisplayTools = Convert.ToString(row["DisplayTools"]);
obj.VarianTools = Convert.ToString(row["VarianTools"]);
obj.OtherTools = Convert.ToString(row["OtherTools"]);
obj.Chambers = Convert.ToString(row["Chambers"]);
objList.Add(obj);
}
}
return objList;
}
}
========================================
C# Data Access
-----------------------
public DataTable GetRefreshData(string dashboardname)
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("DashboardRefreshMatrix", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@dashboardname", dashboardname);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(ds);
if (ds.Tables.Count > 0)
dt = ds.Tables[0];
}
}
return dt;
}
public DataTable GetToolData()
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand("GetToolsData", con))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(ds);
if (ds.Tables.Count > 0)
dt = ds.Tables[0];
}
}
return dt;
}
}
=======================================================================
WebApiConfig.cs file
------------------------
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var jsonpFormatter = new JsonpMediaTypeFormatter(config.Formatters.JsonFormatter);
config.Formatters.Insert(0, jsonpFormatter);
//var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
//config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
}
No comments:
Post a Comment