private void newEntity() { string error = ""; string where = context.Request["filter"] ?? ""; string entityName = context.Request["entityName"]; Type entityType = Provider.GetEntityType(entityName); if (entityType != null) { IDatabaseEntity entity = Provider.CreateEntity(entityType); if (!string.IsNullOrEmpty(where)) { FilterParser filterParser = new FilterParser(where, entityName); where = filterParser.GetWhere(); foreach (var item in filterParser.GetNameValuePairs()) { entity.SetMemberValue(item.Key, item.Value); } } context.Response.Write(@"{ success: true, data: " + entity.ToJSON() + "}"); return; } else { error = "Entity tipi bulunamadı."; } context.Response.Write(@"{ success: false, errorMessage: " + error.ToJS() + "}"); }
private void getList() { string entityName = context.Request["entityName"]; string where = context.Request["extraFilter"] ?? ""; string orderBy = (context.Request["sort"] ?? "") + " " + (context.Request["dir"] ?? ""); if (orderBy != null) { orderBy = orderBy.Replace("__", "."); } string page = String.IsNullOrEmpty(context.Request["start"]) ? "0" : context.Request["start"]; string limit = String.IsNullOrEmpty(context.Request["limit"]) ? "20" : context.Request["limit"]; int fieldNo = 0; while (context.Request.Form["f_" + fieldNo] != null) { string op = context.Request.Form["o_" + fieldNo]; string field = context.Request.Form["f_" + fieldNo]; string val = context.Request.Form["c_" + fieldNo]; where += (where == "" ? "" : " AND ") + field + op + val; fieldNo++; } FilterParser filterParser = new FilterParser(where, entityName); where = filterParser.GetWhere(); object[] parameters = filterParser.GetParams(); DataTable dt = Provider.ReadList(Provider.GetEntityType(entityName), Int32.Parse(page) / Int32.Parse(limit), Int32.Parse(limit), orderBy, where, parameters); int totalCount = Provider.ReadListTotalCount(Provider.GetEntityType(entityName), where, parameters); List <string> jsonItems = new List <string>(); foreach (DataRow dr in dt.Rows) { string jsonItem = "{"; foreach (DataColumn dc in dr.Table.Columns) { jsonItem += string.Format("{0}:{1},", dc.ColumnName.Replace(".", "__").ToJS(), dr[dc].ToJS()); } jsonItem = jsonItem.Remove(jsonItem.Length - 1, 1); jsonItem += "}"; jsonItems.Add(jsonItem); } string res = "{root:[" + string.Join(",", jsonItems.ToArray()) + "], totalCount:" + totalCount + "}"; context.Response.Write(res); }
private void getEntityList() { string entityName = context.Request["entityName"]; string orderBy = context.Request["orderBy"] ?? "OrderNo"; string orderAsc = context.Request["orderAsc"] ?? "1"; Type tip = Provider.GetEntityType(entityName); string filter = context.Request["filter"] ?? ""; FilterParser filterParser = new FilterParser(filter, entityName); filter = filterParser.GetWhere(); string where = "where " + (String.IsNullOrEmpty(filter) ? "1=1" : "(" + filter + ")"); IDatabaseEntity[] entities = currentDatabase.ReadList(tip, "select * from [" + entityName + "] " + where + " order by " + orderBy + (orderAsc == "1" ? "" : " desc"), filterParser.GetParams()).SafeCastToArray <IDatabaseEntity>(); context.Response.Write(entities.ToJSON()); }
private void getGridList() { string entityName = context.Request["entityName"]; string where = context.Request["extraFilter"] ?? ""; string orderBy = context.Request["orderBy"] ?? ""; string page = String.IsNullOrEmpty(context.Request["page"]) ? "0" : context.Request["page"]; string limit = String.IsNullOrEmpty(context.Request["limit"]) ? "20" : context.Request["limit"]; int fieldNo = 0; Type entityType = Provider.GetEntityType(entityName); BaseEntity sampleEntity = Provider.CreateEntity(entityType); while (context.Request.Form["f_" + fieldNo] != null) { string op = context.Request.Form["o_" + fieldNo]; string field = context.Request.Form["f_" + fieldNo]; string val = context.Request.Form["c_" + fieldNo]; where += (where == "" ? "" : " AND ") + field + op + val; fieldNo++; } if (!string.IsNullOrWhiteSpace(context.Request.Form["search"])) { string search = context.Request.Form["search"]; if (!search.Contains("%")) { search = "%" + search + "%"; } where += " AND " + sampleEntity.GetNameColumn() + "like" + search; } FilterParser filterParser = new FilterParser(where, entityName); where = filterParser.GetWhere(); DataTable dt = Provider.ReadList(entityType, Int32.Parse(page), Int32.Parse(limit), orderBy, where, filterParser.GetParams()); context.Response.Write("<table class=\"bk-grid\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n"); if (dt != null) { context.Response.Write("\t<tr>\n"); foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "_CinarRowNumber") { continue; //*** } string columnName = dc.ColumnName; string columnTitle = Provider.TranslateColumnName(entityName, columnName); context.Response.Write("\t\t<th id=\"h_" + dc.ColumnName + "\">" + columnTitle + "</th>\n"); } context.Response.Write("\t</tr>\n"); } if (dt != null) { if (dt.Rows.Count == 0) { context.Response.Write("\t<tr><td style=\"padding:30px;text-align:center\" colspan=\"50\">" + Provider.GetResource("No record") + "</td></tr>\n"); } else { for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; context.Response.Write("\t<tr id=\"r_" + dr[0] + "\">\n"); foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "_CinarRowNumber") { continue; //*** } object valObj = dr[dc.ColumnName]; string dispVal = ""; if (dr.IsNull(dc)) { dispVal = ""; } else if (dc.DataType == typeof(Boolean)) { dispVal = ((bool)valObj) ? Provider.GetResource("Yes") : Provider.GetResource("No"); } else if (dc.DataType == typeof(String)) { string str = Regex.Replace(valObj.ToString(), "<.*?>", string.Empty); if (str.Length > 50) { dispVal = CMSUtility.HtmlEncode(str.StrCrop(50)); // str.Substring(0, 50) + "..." } else { dispVal = str; } } else if (dc.DataType == typeof(DateTime)) { dispVal = ((DateTime)valObj).ToString(Provider.Configuration.DefaultDateFormat); } else { dispVal = valObj.ToString(); } context.Response.Write("\t\t<td value=\"" + CMSUtility.HtmlEncode(valObj) + "\">" + dispVal + "</td>\n"); } context.Response.Write("\t</tr>\n"); } } } context.Response.Write("</table>"); }
private void saveEntity() { string id = context.Request["Id"]; string where = context.Request["filter"]; string entityName = context.Request["entityName"]; int mid = 0; if (!Int32.TryParse(id, out mid)) { context.Response.Write("{success:false, errorMessage:'ID geçersiz!'}"); return; } // bu istisnai durum, sadece konfigürasyon veritabanına kaydedilmiyor if (entityName == "Configuration") { Provider.Configuration.SetFieldsByPostData(context.Request.Form); Provider.Configuration.Save(); context.Response.Write("{success:true}"); return; } // entitiyi kaydedelim BaseEntity entity = null; if (mid > 0) { entity = (BaseEntity)Provider.Database.Read(Provider.GetEntityType(entityName), mid); } else { entity = Provider.CreateEntity(entityName); } entity.SetFieldsByPostData(context.Request.Form); if (!string.IsNullOrEmpty(where)) { FilterParser filterParser = new FilterParser(where, entityName); where = filterParser.GetWhere(); foreach (var item in filterParser.GetNameValuePairs()) { if (string.IsNullOrEmpty(context.Request.Form[item.Key])) { entity.SetMemberValue(item.Key, item.Value); } } } entity.Save(); // entitiye ait Lang kayıtlarını kaydedelim Type langEntityType = Provider.GetEntityType(entityName + "Lang"); if (langEntityType != null) { Dictionary <int, NameValueCollection> langEntities = new Dictionary <int, NameValueCollection>(); Dictionary <int, string> langEntityFieldSum = new Dictionary <int, string>(); for (int i = 0; i < context.Request.Form.Count; i++) { string key = context.Request.Form.GetKey(i); if (key.Contains("_lang_")) { string[] parts = key.Split(new string[] { "_lang_" }, StringSplitOptions.None); int langId = int.Parse(parts[1]); string fieldName = parts[0]; string fieldVal = context.Request.Form[key]; if (!langEntities.ContainsKey(langId)) { langEntities.Add(langId, new NameValueCollection()); } langEntities[langId].Add(fieldName, fieldVal); if (!langEntityFieldSum.ContainsKey(langId)) { langEntityFieldSum.Add(langId, ""); } langEntityFieldSum[langId] += fieldVal; } } // içi boş olan langEntitileri kaldıralım foreach (var item in langEntityFieldSum) { if (item.Value.Trim() == "") { langEntities.Remove(item.Key); } } foreach (var item in langEntities) { BaseEntity langEntity = (BaseEntity)Provider.Database.Read(langEntityType, entityName + "Id = {0} AND LangId={1}", entity.Id, item.Key); if (langEntity == null) { langEntity = Provider.CreateEntity(langEntityType); } langEntity.SetFieldsByPostData(item.Value); langEntity.SetMemberValue(entityName + "Id", entity.Id); langEntity.SetMemberValue("LangId", item.Key); langEntity.Save(); } } context.Response.Write("{success:true}"); }