public static ItemDetail GetItemData(int ItemId) { string imagefolder = "/img/"; ItemDetail objItemDetail = new ItemDetail(); Items objItem = new Items(); DataTable objmainDT = new DataTable(); DataRow[] objMainRow = null; if (ItemId != 0) { objmainDT = (DataTable)HttpContext.Current.Session["ItemData"]; objMainRow = objmainDT.Select("menu_id_generator='" + ItemId + "'"); } DataTable dtVendors = new DataTable(); dtVendors = SQL.BLL.GetVendorsList(1, 1000, "", "id", 1); DataRow newRowVendor = dtVendors.NewRow(); newRowVendor["id_vendors_generator"] = "-1"; newRowVendor["nama_vendors"] = "-Select Vendor-"; dtVendors.Rows.InsertAt(newRowVendor, 0); dtVendors.AcceptChanges(); objItemDetail.Vendor = new CommonObjects[dtVendors.Rows.Count]; int intCount = 0; foreach (DataRow drw in dtVendors.Rows) { objItemDetail.Vendor[intCount] = new CommonObjects(); objItemDetail.Vendor[intCount].Value = drw["id_vendors_generator"].ToString(); objItemDetail.Vendor[intCount].Text = drw["nama_vendors"].ToString(); objItemDetail.Vendor[intCount].DefaultValue = ItemId != 0 ? objMainRow[0]["alias_vendors"].ToString() : objItemDetail.Vendor[0].Value; intCount++; } DataTable dtItemCategory = new DataTable(); dtItemCategory = SQL.BLL.GetCategoryList(1, 1000, "", "id", 1); DataRow newItemCategory = dtItemCategory.NewRow(); newItemCategory["Alias"] = "-1"; newItemCategory["Category"] = "-Category-"; dtItemCategory.Rows.InsertAt(newItemCategory, 0); dtItemCategory.AcceptChanges(); objItemDetail.Categoty = new CommonObjects[dtItemCategory.Rows.Count]; intCount = 0; foreach (DataRow drw in dtItemCategory.Rows) { objItemDetail.Categoty[intCount] = new CommonObjects(); objItemDetail.Categoty[intCount].Value = drw["Alias"].ToString(); objItemDetail.Categoty[intCount].Text = drw["Category"].ToString(); objItemDetail.Categoty[intCount].DefaultValue = ItemId != 0 ? objMainRow[0]["Category"].ToString() : objItemDetail.Categoty[0].Value; intCount++; } int Price; bool IsRecommendItem; objItemDetail.ItemName = ItemId != 0 ? objMainRow[0]["nama_menu"].ToString() : ""; objItemDetail.UrlAlias = ItemId != 0 ? objMainRow[0]["alias_menu"].ToString() : ""; objItemDetail.Description = ItemId != 0 ? objMainRow[0]["deskripsi_menu"].ToString() : ""; if (ItemId != 0) { int.TryParse(Convert.ToString(objMainRow[0]["harga_menu"]), out Price); objItemDetail.Price = Price; } objItemDetail.Tags = ItemId != 0 ? objMainRow[0]["tags"].ToString() : ""; if (ItemId != 0) { bool.TryParse(Convert.ToString(objMainRow[0]["is_recommended"]), out IsRecommendItem); objItemDetail.IsRecommendItem = IsRecommendItem; } objItemDetail.ItemImageUrl = ItemId != 0 ? imagefolder + objMainRow[0]["media_photo"].ToString() : ""; DataTable dt = objItem.GetTags(); string tags = ""; foreach (DataRow dr in dt.Rows) { if (tags == "") { if (ItemId != 0 && objMainRow[0]["tags"].ToString().IndexOf(dr["alias"].ToString()) != -1) { tags = dr["alias"].ToString() + "✓" + "^" + dr["nama_tag"].ToString(); } else { tags = dr["alias"].ToString() + "^" + dr["nama_tag"].ToString(); } } else { if (ItemId != 0 && objMainRow[0]["tags"].ToString().IndexOf(dr["alias"].ToString()) != -1) { tags += "," + dr["alias"].ToString() + "✓" + "^" + dr["nama_tag"].ToString(); } else { tags += "," + dr["alias"].ToString() + "^" + dr["nama_tag"].ToString(); } } } objItemDetail.Tags = tags; return objItemDetail; }
public static string GetItems(int PageIndex, int PageSize, string SortCol, string SortDir, string SearchFilter) { Items objItems = new Items(); Hashtable objHT = new Hashtable(); string totalRecords = ""; string totalDisplayRecords = ""; int count = 0; string rowClass = ""; var sb = new StringBuilder(); string outputJson = string.Empty; DataTable dtItems = new DataTable(); string SortBy = "menu_id_generator"; int SortDirection = 1; if (SortCol == "0") { SortBy = "menu_id_generator"; } else if (SortCol == "1") { SortBy = "nama_vendors"; } else if (SortCol == "2") { SortBy = "nama_menu"; } else if (SortCol == "2") { SortBy = "harga_menu"; } if (SortDir == "asc") { SortDirection = 1; } else { SortDirection = 0; } dtItems = objItems.GetItems(PageIndex, PageSize, SearchFilter, SortBy, SortDirection); HttpContext.Current.Session["ItemData"] = dtItems; if (dtItems.Rows.Count > 0) { for (int i = 0; i < dtItems.Rows.Count; i++) { if (totalRecords.Length == 0) { totalRecords = dtItems.Rows[i]["TotalCount"].ToString(); totalDisplayRecords = dtItems.Rows[i]["TotalCount"].ToString(); } sb.Append("{"); sb.AppendFormat(@"""id"": ""{0}""", count++); sb.Append(","); sb.AppendFormat(@"""DT_RowClass"": ""{0}""", rowClass); sb.Append(","); sb.AppendFormat(@"""0"": ""{0}""", "<div style='text-overflow: ellipsis; width: 80px;overflow: hidden;'><nobr>" + dtItems.Rows[i]["menu_id_generator"].ToString().Replace("\"", "\\" + "\"") + "</nobr></div>"); sb.Append(","); sb.AppendFormat(@"""1"": ""{0}""", "<div style='text-overflow: ellipsis; width: 130px;overflow: hidden;'><nobr>" + dtItems.Rows[i]["nama_vendors"].ToString().Replace("\"", "\\" + "\"") + "</nobr></div>"); sb.Append(","); sb.AppendFormat(@"""2"": ""{0}""", "<div style='text-overflow: ellipsis; width: 140px;overflow: hidden;'><nobr>" + dtItems.Rows[i]["nama_menu"].ToString().Replace("\"", "\\" + "\"") + "</nobr></div>"); sb.Append(","); sb.AppendFormat(@"""3"": ""{0}""", "<div style='text-overflow: ellipsis; width: 80px;overflow: hidden;'><nobr>" + dtItems.Rows[i]["harga_menu"].ToString().Replace("\"", "\\" + "\"") + "</nobr></div>"); sb.Append(","); sb.AppendFormat(@"""4"": ""{0}""", "<div><a href='javascript:void(0)' data-id='" + dtItems.Rows[i]["menu_id_generator"].ToString().Replace("\"", "\\" + "\"") + "' class='items-dialy-promo' data-toggle='tooltip' data-title='Dialy Promo " + dtItems.Rows[i]["nama_menu"].ToString().Replace("\"", "\\" + "\"") + "'><i class='fa fa-usd fa-border'></i></a><a href='javascript:void(0)' onclick='javascript:RecommendItem(" + dtItems.Rows[i]["id"].ToString() + ")' class='' data-toggle='tooltip' data-title='Item was recommended' ><i class='fa fa-thumbs-up fa-border fa-black'></i></a><a href='javascript:void(0)' data-id='" + dtItems.Rows[i]["menu_id_generator"].ToString().Replace("\"", "\\" + "\"") + "' class='edit' data-toggle='tooltip' data-title='Update Data " + dtItems.Rows[i]["nama_menu"].ToString().Replace("\"", "\\" + "\"") + "'><i class='fa fa-pencil-square-o fa-border'></i></a><a href='javascript:void(0)' data-id='" + dtItems.Rows[i]["menu_id_generator"].ToString().Replace("\"", "\\" + "\"") + "' class='delete' data-toggle='tooltip' data-title='Delete data " + dtItems.Rows[i]["nama_menu"].ToString().Replace("\"", "\\" + "\"") + "'><i class='fa fa-trash-o fa-border'></i></a></div>"); sb.Append("},"); } outputJson = sb.Remove(sb.Length - 1, 1).ToString(); sb.Clear(); sb.Append("{"); sb.Append(@"""sEcho"": "); sb.AppendFormat(@"""{0}""", sEcho++); sb.Append(","); sb.Append(@"""iTotalRecords"": "); sb.Append(totalRecords); sb.Append(","); sb.Append(@"""iTotalDisplayRecords"": "); sb.Append(totalDisplayRecords); sb.Append(", "); sb.Append(@"""aaData"": [ "); sb.Append(outputJson); sb.Append("]}"); outputJson = sb.ToString(); } else { sb.Append("{"); sb.Append(@"""sEcho"": "); sb.AppendFormat(@"""{0}""", sEcho++); sb.Append(","); sb.Append(@"""iTotalRecords"": 0"); sb.Append(","); sb.Append(@"""iTotalDisplayRecords"": 0"); sb.Append(", "); sb.Append(@"""aaData"": [ "); sb.Append("]}"); outputJson = sb.ToString(); } return outputJson; }