/// <summary> /// 删除一条数据 /// </summary> /// <param name="tableName"></param> /// <param name="pkName"></param> /// <param name="pkValue"></param> /// <returns></returns> public bool DeleteData(string tableName, string pkName, string pkValue) { if (string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(pkName) || string.IsNullOrWhiteSpace(pkValue)) { return(false); } DataTable dtStruct = GetTableStruct(tableName); bool trueDel = !dtStruct.Columns.Contains("is_del"); bool haveUpdateTime = dtStruct.Columns.Contains("update_time"); string truedelSqlformat = "delete from {0} where {1}='{2}';"; string falsedelSqlformat = "update {0} set is_del='1' " + (haveUpdateTime ? ",update_time=NOW() " : "") + " where {1}='{2}';"; string delSql = string.Format(trueDel ? truedelSqlformat : falsedelSqlformat, tableName, pkName, pkValue); int count = MySQLHelper.ExecuteSql(delSql); if (count > 0) { if (tableName.ToLower() == "tmo_monitor_devicebind") { MemoryCacheHelper.ClearCache("tmo_monitor_devicebind"); } } return(count > 0); }
public int SaveStore() { // do additional work MemoryCacheHelper.ClearCache("GetLoginUserStore"); MemoryCacheHelper.ClearCache("GetAllStores"); MemoryCacheHelper.ClearCache("StoreCache"); return(base.Save()); }
void btnClearCache_Click(object sender, EventArgs e) { //MemoryCacheHelper.GetCacheItem<string>("test", () => "testdata", DateTime.Now.AddHours(1)); bool suc = MemoryCacheHelper.ClearCache(); if (suc) { UserMessageBox.MessageInfo("缓存清理成功"); } else { UserMessageBox.MessageError("缓存清理失败"); } }
private void ClearCache(int storeId) { String key = String.Format("GetCategoriesRelatedItemsCount-StoreId-{0}-Category-{1}", storeId, this.ContentType); MemoryCacheHelper.ClearCache(key); }
public void SaveSetting() { MemoryCacheHelper.ClearCache("GetStoreSettingsFromCache-"); this.Save(); }
/// <summary> /// 根据参数保存修改实体数据 /// </summary> /// <param name="param"></param> /// <returns></returns> public bool SubmitData(FE_SubmitDataParam param) { if (param == null) { return(false); } if (string.IsNullOrWhiteSpace(param.EntityName)) { return(false); } if (param.OperateType != DBOperateType.Add && (string.IsNullOrWhiteSpace(param.PrimaryKey) || string.IsNullOrWhiteSpace(param.PKValue))) { return(false); } if (param.OperateType != DBOperateType.Delete && param.OperateType != DBOperateType.View && (param.SubmitValues == null || param.SubmitValues.Count == 0)) { return(false); } DBOperateType opType = param.OperateType; string entityName = param.EntityName; string pkName = param.PrimaryKey; string pkValue = param.PKValue; Dictionary <string, string> dicParams = new Dictionary <string, string>(); foreach (KeyValuePair <string, object> keyValuePair in param.SubmitValues) { if (!string.IsNullOrWhiteSpace(keyValuePair.Key)) { string value = string.Empty; if (keyValuePair.Value != null) { value = keyValuePair.Value.ToString(); } if (keyValuePair.Key.IndexOf("time", StringComparison.OrdinalIgnoreCase) > 0 || keyValuePair.Key.IndexOf("date", StringComparison.OrdinalIgnoreCase) > 0) { if (value.Contains("午") || value.Contains("星期") || value.Contains("周") || !value.Take(4).All(char.IsNumber)) { value = DateTimeHelper.ToDateTime(value).ToFormatDateTimeStr(); } } dicParams.Add(keyValuePair.Key, value); } } DataTable dtStruct = GetTableStruct(entityName); bool falseDel = dtStruct.Columns.Contains("is_del"); bool autoInputTime = dtStruct.Columns.Contains("input_time") && opType == DBOperateType.Add; if (autoInputTime && !dicParams.ContainsKey("input_time")) { dicParams.Add("input_time", TmoShare.DateTimeNow); } bool autoUpdateTime = dtStruct.Columns.Contains("update_time") && opType != DBOperateType.Delete; if (autoUpdateTime && !dicParams.ContainsKey("update_time")) { dicParams.Add("update_time", DateTimeHelper.DateTimeNowStr); } StringBuilder sbsql = new StringBuilder(); if (opType == DBOperateType.Add) { if (falseDel) { if (dicParams.ContainsKey("is_del")) { dicParams["is_del"] = "0"; } else { dicParams.Add("is_del", "0"); } } sbsql.AppendFormat("insert into {0}(", entityName); int i = 0; foreach (string col in dicParams.Keys) { sbsql.Append(col); if (i < dicParams.Count - 1) { sbsql.Append(","); } i++; } sbsql.Append(") values("); i = 0; foreach (string val in dicParams.Values) { sbsql.AppendFormat("'{0}'", val); if (i < dicParams.Count - 1) { sbsql.Append(","); } i++; } sbsql.Append(");"); } else if (opType == DBOperateType.Update) { sbsql.AppendFormat("update {0} set ", entityName); int i = 0; foreach (var item in dicParams) { sbsql.AppendFormat("{0}='{1}'", item.Key, item.Value); if (i < dicParams.Count - 1) { sbsql.Append(","); } i++; } sbsql.AppendFormat(" where {0}='{1}';", pkName, pkValue); } else if (opType == DBOperateType.Delete) { return(DeleteData(entityName, pkName, pkValue)); } int count = MySQLHelper.ExecuteSqlTran(sbsql.ToString()); if (count > 0) { if (entityName.ToLower() == "tmo_monitor_devicebind") { MemoryCacheHelper.ClearCache("tmo_monitor_devicebind"); } } return(count > 0); }
/// <summary> /// 根据传过来参数添加或修改数据 /// </summary> /// <param name="submitdataEntityParams"></param> /// <returns></returns> public bool SubmitData(string submitdataEntityParams) { List <string> list = StringPlus.GetStrArray(submitdataEntityParams, "_;_"); DBOperateType opType = (DBOperateType)Convert.ToInt32(list[0]); string entityName = list[1]; string pkName = list[2]; string pkValue = list[3]; string dicStr = list[4]; if (string.IsNullOrWhiteSpace(dicStr) && opType != DBOperateType.Delete) { return(false); } Dictionary <string, string> dicParams = new Dictionary <string, string>(); List <string> tmp = StringPlus.GetStrArray(dicStr, "-|-"); for (int i = 0; i < tmp.Count - 1; i++) { List <string> t = StringPlus.GetStrArray(tmp[i], "_|_"); dicParams.Add(t[0], t[1]); } DataTable dtStruct = GetTableStruct(entityName); bool falseDel = dtStruct.Columns.Contains("is_del"); bool autoInputTime = dtStruct.Columns.Contains("input_time") && opType == DBOperateType.Add; if (autoInputTime && !dicParams.ContainsKey("input_time")) { dicParams.Add("input_time", TmoShare.DateTimeNow); } StringBuilder sbsql = new StringBuilder(); if (opType == DBOperateType.Add) { if (falseDel) { if (dicParams.ContainsKey("is_del")) { dicParams["is_del"] = "0"; } else { dicParams.Add("is_del", "0"); } } sbsql.AppendFormat("insert into {0}(", entityName); int i = 0; foreach (string col in dicParams.Keys) { sbsql.Append(col); if (i < dicParams.Count - 1) { sbsql.Append(","); } i++; } sbsql.Append(") values("); i = 0; foreach (string val in dicParams.Values) { sbsql.AppendFormat("'{0}'", val); if (i < dicParams.Count - 1) { sbsql.Append(","); } i++; } sbsql.Append(");"); } else if (opType == DBOperateType.Update) { sbsql.AppendFormat("update {0} set ", entityName); int i = 0; foreach (var item in dicParams) { sbsql.AppendFormat("{0}='{1}'", item.Key, item.Value); if (i < dicParams.Count - 1) { sbsql.Append(","); } i++; } sbsql.AppendFormat(" where {0}='{1}';", pkName, pkValue); } else if (opType == DBOperateType.Delete) { return(DeleteData(entityName, pkName, pkValue)); } int count = MySQLHelper.ExecuteSqlTran(sbsql.ToString()); if (count > 0) { if (entityName.ToLower() == "tmo_monitor_devicebind") { MemoryCacheHelper.ClearCache("tmo_monitor_devicebind"); } } return(count > 0); }