Exemple #1
0
        public static List<data> FindData(FindDataEntity entity)
        {
            List<data> result = new List<data>();
            string sql = string.Format("SELECT TOP 10 * FROM [{0}] ", entity.TableName);
            List<SqlParameter> parasList = new List<SqlParameter>();
            if (entity.FilterItems != null && entity.FilterItems.Count > 0)
            {
                string whereStr = string.Empty;
                for (int i = 0; i < entity.FilterItems.Count; i++)
                {
                    if (i == 0)
                    {
                        whereStr += string.Format(" [{0}] =@{0}", entity.FilterItems[i].Name);
                    }
                    else
                    {
                        whereStr += string.Format(" AND [{0}] = @{0}", entity.FilterItems[i].Name);
                    }
                    parasList.Add(new SqlParameter("@" + entity.FilterItems[i].Name, entity.FilterItems[i].Value));

                }


                sql += " WHERE " + whereStr;
            }

            DataSet ds = SQLHelper.ExecuteQuery(GetConnection(), CommandType.Text, sql, parasList.ToArray());
            if (ds.Tables.Count > 0)
            {
                DataTable table = ds.Tables[0];
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRow dr = table.Rows[i];
                    data dataItem = new data();
                    List<dataItem> items = new List<dataItem>();
                    for (int j = 0; j < table.Columns.Count; j++)
                    {
                        dataItem item = new dataItem();
                        item.name = table.Columns[j].ColumnName;
                        item.value = dr[j].ToString();
                        items.Add(item);
                    }
                    dataItem.items = items;
                    result.Add(dataItem);
                }
            }


            return result;
        }
 public SyncResult FindData(FindDataEntity entity)
 {
     SyncResult result = new SyncResult();
     try
     {
         result.result = 1;
         result.datas = SQLHelper.FindData(entity);
     }
     catch (Exception ex)
     {
         result.result = 0;
         result.message = ex.ToString();
     }
     return result;
 }