private IEnumerable <ObjectData> GetList() { var Ioc = AtawIocContext.Current; List <PlugModel> list = new List <PlugModel>(); var sourceList = Ioc.PlugInModelList.ToList(); // var if (KeyValues != null && KeyValues.Count() > 0) { sourceList = sourceList.Where(a => (KeyValues.ToList().Contains(a.Key))).ToList(); } if (!ForeignKeyValue.IsEmpty()) { } string _tableName = this.RegName + "_SEARCH"; if (PostDataSet != null && PostDataSet.Tables[_tableName] != null && PostDataSet.Tables[_tableName].Rows.Count > 0) { DataRow row = PostDataSet.Tables[_tableName].Rows[0]; sourceList = WhereFilter(sourceList, row).ToList(); } List <PlugInModel> regList = new List <PlugInModel>(); if (Pagination != null) { regList = sourceList.Skip((Pagination.PageIndex) * Pagination.PageSize).Take(Pagination.PageSize).ToList(); } else { Pagination = new Pagination().FormDataTable(PostDataSet.Tables["PAGER"]); //Pagination.PageSize = //regList = source.ToList(); } Pagination.TotalCount = sourceList.Count; int i = 0; regList.ForEach((a) => { list.Add( new PlugModel() { RegName = a.Key + i.ToString(), BassClassName = a.BaseType.Name, Desc = a.Description, DllPath = a.InstanceType.Module.ScopeName, InstanceClassName = a.InstanceType.Name, Author = a.Author, CreateDate = a.CreateDate.Value <string>() } ); i++; }); return(list.OrderBy(a => a.DllPath).ThenBy(a => a.BassClassName).ThenBy(a => a.Author)); }
public void SetKeyValue(string key, string value) { bool IsMatch(PointOfSaleKeyValue posKv) => string.Equals(posKv.Key, key, StringComparison.OrdinalIgnoreCase); var cnt = KeyValues.Count(IsMatch); if (cnt > 1) { foreach (var kv in KeyValues.Where(IsMatch).ToArray()) { KeyValues.Remove(kv); } } else if (cnt == 1) { KeyValues.First(IsMatch).SetValue(value); } else { KeyValues.Add(new PointOfSaleKeyValue(key, value)); } }
private string SetWhereByKeyValue(DynamicParameters sqlList) { string where = "AND ("; int flag = 0; foreach (string val in KeyValues) { string parm = val.Replace("-", "_"); flag++; if (flag == KeyValues.Count()) { where = where + string.Format(CultureInfo.CurrentCulture, "{0} = @{1}", PrimaryKey, parm); } else { where = where + string.Format(CultureInfo.CurrentCulture, "{0} = @{1} OR ", PrimaryKey, parm); } sqlList.Add(string.Format("@{0}", parm), val); } where = where + ")"; return(where); }
private void InternalInitialize(DataSet dataSet, int pageSize, string keyValue, string foreignKeyValue, string tableName, string primaryKey, string foreignKey, bool isFillEmpty, DataFormConfig dataFormConfig) { // ColumnLegalHashTable = new HashSet<string>(); this.DataFormConfig = dataFormConfig; UniqueList = this.DataFormConfig.Columns.Where(a => a.IsUniqueKey).Select(a => a.Name).ToList(); //SingleUploadColumns = this.DataFormConfig.Columns.FindAll( // a => (a.ControlType == ControlType.SingleImageUpload || a.ControlType == ControlType.SingleFileUpload) && (a.Upload != null && a.Upload.HasKey)).ToList(); //MultiUploadColumns = this.DataFormConfig.Columns.FindAll( // a => (a.ControlType == ControlType.MultiImageUpload || a.ControlType == ControlType.MultiFileUpload) && (a.Upload != null && a.Upload.HasKey)).ToList(); MomeryColumns = this.DataFormConfig.Columns.FindAll( a => (a.ControlType == ControlType.Momery && !a.RegName.IsEmpty()) ).ToList(); this.KeyValues = new List <string>(); this.IsFillEmpty = isFillEmpty; this.PostDataSet = dataSet; this.KeyValue = keyValue; if (dataSet != null) { var _dtPageSys = dataSet.Tables["PAGE_SYS"]; if (_dtPageSys != null && _dtPageSys.Rows.Count > 0) { if (_dtPageSys.Columns.Contains("PageStyle")) { this.PageStyle = _dtPageSys.Rows[0]["PageStyle"].Value <PageStyle>(); } } var dt = dataSet.Tables["_KEY"]; if (dt != null && dt.Rows.Count > 0) { List <string> keyValueList = new List <string>(); foreach (DataRow row in dt.Rows) { string _key = row["KeyValue"].ToString(); keyValueList.Add(_key); } KeyValues = keyValueList; } } // if (dataSet.Tables["PAGE"]) if (RegName.IsEmpty()) { fRegName = tableName; } if (PrimaryKey.IsEmpty()) { PrimaryKey = primaryKey; } if (ForeignKey.IsEmpty()) { ForeignKey = foreignKey; } if (!ForeignKey.IsEmpty()) { if (foreignKeyValue.IsEmpty()) { this.ForeignKeyValue = KeyValues.Count() == 1 ? KeyValues.First() : foreignKeyValue; } else { this.ForeignKeyValue = foreignKeyValue; } } if (dataSet != null) { this.Pagination = new Pagination().FormDataTable(dataSet.Tables["PAGER"]); } else { this.Pagination = new Pagination() { //TableName = RegName, DataTime = DateTime.Now, PageSize = pageSize } }; this.Pagination.TableName = RegName; if (this.Pagination.PageSize == 0) { this.Pagination.PageSize = pageSize; } if (this.Pagination.PageSize == 0) { this.Pagination.PageSize = 20; } }
private void SetSqlSelect() { string where = ""; DynamicParameters sqlList = new DynamicParameters(); if (KeyValues.Count() == 0) { string searchTable = RegName + "_SEARCH"; if (PostDataSet != null && PostDataSet.Tables[searchTable] != null && PostDataSet.Tables[searchTable].Rows.Count > 0) { DataRow row = PostDataSet.Tables[searchTable].Rows[0]; where = WhereStringBuilder(row, sqlList); } else { if (IsFillEmpty) { where = " AND 1=2 "; } } } else { //当外键也为空的时候 if (ForeignKeyValue.IsEmpty()) { where = SetWhereByKeyValue(sqlList); } else { where = string.Format(" AND {0}=@{0}", ForeignKey); sqlList.Add(string.Format("@{0}", ForeignKey), ChangeForeignKeyValue(ForeignKeyValue));//获取子表过滤条件 } } where = SetWhereFilterSqlByFormConfig(where); where = AdditionalConditionSql(where); string countSql = string.Format(CultureInfo.CurrentCulture, "SELECT COUNT(*) FROM {0} WHERE 1=1 {1}", SetSelectTable(RegName), where); Pagination.TotalCount = DbContext.QueryObject <int>(countSql, sqlList); string _selectStr = SetSelectSql(); string orderName = PrimaryKey + " DESC "; if (Order.IsEmpty()) { if (XmlColumns.Contains("CREATE_TIME")) { orderName = "CREATE_TIME DESC "; } if (XmlColumns.Contains("UPDATE_TIME")) { orderName = "UPDATE_TIME DESC "; } } else { orderName = Order; } if (!Pagination.SortName.IsEmpty()) { if (Pagination.IsASC) { orderName = Pagination.SortName + " ASC"; } else { orderName = Pagination.SortName + " DESC"; } } paraList = new DynamicParameters(); paraList = sqlList; //foreach (var qsql in sqlList)//对象克隆,防止参数重复 //{ // SqlParameter sqlP = new SqlParameter(); // qsql.ObjectClone(sqlP); // paraList.Add(sqlP); //} sql = string.Format(CultureInfo.CurrentCulture, PAGE_SQL, _selectStr, orderName, SetSelectTable(RegName), where); paraList.Add("@skip", Pagination.PageIndex); paraList.Add("@pageSize", Pagination.PageSize); }