Ejemplo n.º 1
0
        public bool Delete(Where where) {
 
            using (SqlCommand command = new DbHelper().Command) {
                string sql = $"delete from {Table} where {where.Result};";
                return command.ExecuteNonQueryExt(sql, where) > 0;
            }
        }
Ejemplo n.º 2
0
 public static async Task<List<Model.User>> GetListUser(Where where, string fields, string orderby, int pageIndex,
     int pageSize) {
     return
         await
             Task<List<Model.User>>.Factory.StartNew(
                 () => Dal.GetList(where, fields, orderby, pageIndex, pageSize));
 }
Ejemplo n.º 3
0
     public static string Edit(HttpContext context) {
         if (string.IsNullOrEmpty(App.UserID))
             throw new AuthenticationException("用户未登录");
         string id = context.Request.Form["_id"].ToStringExt();
         if (string.IsNullOrEmpty(id))
             throw new ArgumentNullException("id", "缺少参数_id");
      
         string name = context.Request.Form["name"];
         string sex = context.Request.Form["sex"];
         string birthday = context.Request.Form["birthday"];
         string email = context.Request.Form["email"];
         Where @where = new Where(new Where.Item("ID", "=", id));
 
         FreedomDB.Bridge.Update update = new Update();
         update.Dic = new Dictionary<string, dynamic>() {
             {"Email", email},
             {"Birthday", birthday.StrToDateTime(DateTime.MaxValue)},
             {"Name", name},
             {"Sex", sex.ToInt(0)}
         };
         update.WhereCore = where;
         bool success = Bll.User_Bll.UpdateUser(update);
         ApiInfo apiInfo = new ApiInfo(SystemCode.Error, "更新失败");
         if (success) {
             apiInfo = new ApiInfo(SystemCode.Success, "更新成功");
         }
         return apiInfo.ToJson();
     }
Ejemplo n.º 4
0
        public User GetOne(Where @where, string fields) {
            using (SqlCommand command = new DbHelper().Command) {
                User user = new User();
                string sql = $"select top 1 {fields} from {Table} where {where.Result};";
                IDataReader reader = command.ExecuteReaderExt(sql, where);

                if (reader.Read()) {
                    user = ReaderModel(reader, fields);
                }
                return user;
            }
        }
Ejemplo n.º 5
0
 public int GetRecordCount(Where @where) {
     string sql = $"select count(1) from {Table} where {where.Result};";
     using (SqlCommand command = new DbHelper().Command) {
         command.CommandText = sql;
         command.CommandType=CommandType.Text;
         object objCount = command.ExecuteScalar();
         return objCount.ToInt();
     }
 }
Ejemplo n.º 6
0
        public List<User> GetList(Where where, string fields, string orderby, int pageIndex, int pageSize) {

            string sqlBase = $"select {fields} from {Table} where {@where.Result} ";
            const string sqlPageBase = @"select * from( 
                            select *,ROW_NUMBER() OVER (ORDER BY {1}) as rank from ({0})a 
                          )as t where t.rank between {2} and {3}";

            int startPageIndex = (pageIndex - 1)*pageSize + 1;
            int endPageIndex = pageIndex*pageSize;

            string sqlPage = string.Format(sqlPageBase, sqlBase, orderby, startPageIndex, endPageIndex);
            using (SqlCommand command = new DbHelper().Command) {
                List<User> users = new List<User>();
                IDataReader reader = command.ExecuteReaderExt(sqlPage, where);
                while (reader.Read()) {

                    User user = ReaderModel(reader, fields);
                    users.Add(user);
                }
                return users;
            }
        }
Ejemplo n.º 7
0
 public SqlParameter[] CreateWhereSqlParameters(Where where) {
     List<Where.Item> items = where.WhereItems;
     List<SqlParameter> parameters = items.Select(item => new SqlParameter($"@{item.Field}", item.Value)).ToList();
     return parameters.ToArray();
 }
Ejemplo n.º 8
0
 public static async Task<Model.User> GetOneUser(Where @where, string fields) {
     return await Task<Model.User>.Factory.StartNew(() => Dal.GetOne(where, fields));
 }
Ejemplo n.º 9
0
 public static async Task<bool> DeleteUser(Where where) {
     return await Task<bool>.Factory.StartNew(() => Dal.Delete(where));
 }
Ejemplo n.º 10
0
 public static User_Model GetOneUser(Where @where, string fields) {
     return Dal.GetOne(where, fields);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 用于读取数据
 /// </summary>
 /// <param name="command"></param>
 /// <param name="sql"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public static IDataReader ExecuteReaderExt(this System.Data.Common.DbCommand command, string sql, Where where) {
     command.CommandText = sql;
     command.Parameters.AddRange(command.CreateWhereSqlParameters(where));
     return command.ExecuteReader();
 }
Ejemplo n.º 12
0
        public static string List(HttpContext context) {
     
            if (string.IsNullOrEmpty(App.UserID))
                throw new AuthenticationException("用户未登录");
            int pageIndex = context.Request.QueryString["pageIndex"].ToInt(0);
            int pageSize = context.Request.QueryString["pageSize"].ToInt(10);
            FreedomDB.Bridge.Where where = new Where();
            where.Add(new Where.Item("1", "=", "1"));
            var listUser = Bll.User_Bll.GetListUser(where, "*", "ID DESC", pageIndex, pageSize);
            PageJsonTpl<List<XK.Model.User_Model>> listJsonTpl = new PageJsonTpl<List<User_Model>>();
            listJsonTpl.data = listUser;
            listJsonTpl.msg = "";
            listJsonTpl.code = 1;
            listJsonTpl.total = Bll.User_Bll.GetRecordCount(where);
            listJsonTpl.pageindex = pageIndex;

            string extjson = Common.json.JsonHelper<PageJsonTpl<List<XK.Model.User_Model>>>.Serialize2Object(listJsonTpl);
            return extjson;
        }
Ejemplo n.º 13
0
 public static string GetOne(HttpContext context) {
     string id = context.Request.GetValExt("id");
     if (string.IsNullOrEmpty(id))
         throw new ArgumentNullException("id", "缺少参数id");
     Where where = new Where(new Where.Item("ID", "=", id));
     Model.User_Model userModel = Bll.User_Bll.GetOneUser(where, "*");
     JsonTpl<Model.User_Model> jsonTpl = new JsonTpl<User_Model>() {code = SystemCode.Error, msg = "exception"};
     if (userModel.ID > 0) {
         jsonTpl.data = userModel;
         jsonTpl.code = SystemCode.Success;
         jsonTpl.msg = "success";
     }
     return jsonTpl.ToJson();
 }
Ejemplo n.º 14
0
        public static string Delete(HttpContext context) {

            if (string.IsNullOrEmpty(App.UserID))
                throw new AuthenticationException("用户未登录");
            int uid = context.Request.GetValExt("uid").ToInt();
            if (uid < 1)
                throw new ArgumentNullException("uid", "用户ID不能为空");
            Where where=new Where();
            where.Add(new Where.Item("ID", "=", uid));
            bool success = Bll.User_Bll.DeleteUser(where);
            ApiInfo apiInfo = new ApiInfo(SystemCode.Error, "删除失败");
            if (success) {
                apiInfo = new ApiInfo(SystemCode.Success, "删除成功");
            }

            return apiInfo.ToJson();
        }
Ejemplo n.º 15
0
 public static int GetRecordCount(Where where) {
     return Dal.GetRecordCount(where);
 }
Ejemplo n.º 16
0
 public static List<User_Model> GetListUser(Where where, string fields, string orderby, int pageIndex,
     int pageSize) {
     return Dal.GetList(where, fields, orderby, pageIndex, pageSize);
 }
Ejemplo n.º 17
0
 public int GetRecordCount(Where @where) {
     string sql = $"select count(1) total from {Table} where {where.Result};";
     using (SqlCommand command = new DbHelper().Command) {
         command.CommandText = sql;
         command.CommandType = CommandType.Text;
         IDataReader reader = command.ExecuteReaderExt(sql, where);
         if (reader.Read()) {
             object countObj = reader["total"];
             return countObj.ToInt();
         }
         return 0;
     }
 }
Ejemplo n.º 18
0
 public static bool DeleteUser(Where where) {
     return Dal.Delete(where);
 }