public ResultContent Put(Field field) { if (field == null) { return(new ResultContent(false, MSG.GetInstance().INVALID_DATA, null)); } try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //更新 if (conn.Update <Field>(field)) { var updateField = conn.Get <Field>(field.id); return(new ResultContent(true, updateField)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent GetBySender(int sender_id, int limit, int offset) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { var strSql = "SELECT * FROM tb_user_task WHERE sender_id = @sender_id ORDER BY create_date LIMIT @limit OFFSET @offset"; //查询 var tasks = conn.Query <Task>(strSql, new { sender_id = sender_id, limit = limit, offset = offset }); if (tasks.Any <Task>()) { return(new ResultContent(true, tasks)); } else { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent GetAll(int farm_id) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { var strSql = "SELECT * FROM tb_field WHERE farm_id = @farm_id"; //查询 var fields = conn.Query <Field>(strSql, new { farm_id = farm_id }); if (fields.Any <Field>()) { return(new ResultContent(true, fields)); } else { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Get(string mobile) { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { try { //参数检查 if (mobile.Length != 11 || !Regex.IsMatch(mobile, @"^[0-9]*[0-9][0-9]*$")) { return(new ResultContent(false, MSG.GetInstance().INVALID_MOBILE, null)); } //查询用户 var strSql = "SELECT * FROM tb_user WHERE mobile=@mobile"; var res = conn.QueryFirstOrDefault <User>(strSql, new { mobile = mobile }); //用户不存在创建用户 if (res == null) { User newUser = new User() { name = mobile, mobile = mobile }; conn.Insert(newUser); res = conn.QueryFirstOrDefault <User>(strSql, new { mobile = mobile }); } //生成Token String token = SunGolden.Encryption.DEncrypt.Encrypt(mobile + "," + DateTime.Now.AddDays(30)); return(new ResultContent(true, new Auth(res, token))); } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } } }
public ResultContent Post(Task task) { if (task == null) { return(new ResultContent(false, MSG.GetInstance().INVALID_DATA, null)); } try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { var strSql = "SELECT * FROM tb_user_task WHERE farm_id=@farm_id AND sender_id=@sender_id AND receiver_id=@receiver_id AND type_id=@type_id"; var res = conn.QueryFirstOrDefault <User>(strSql, new { farm_id = task.farm_id, sender_id = task.sender_id, receiver_id = task.receiver_id, type_id = task.type_id }); if (res != null) { return(new ResultContent(false, MSG.GetInstance().ALREADY_EXISTS, null)); } if (conn.Insert <Task>(task) > 0) { strSql = "SELECT MAX(id) FROM tb_user_task"; var max = conn.Query <int>(strSql); var newTask = conn.Get <Task>(max.First()); return(new ResultContent(true, newTask)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Post(Farm farm) { if (farm == null) { return(new ResultContent(false, MSG.GetInstance().INVALID_DATA, null)); } try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { if (conn.Insert <Farm>(farm) > 0) { var strSql = "SELECT MAX(id) FROM tb_farm"; var res = conn.Query <int>(strSql); var newFarm = conn.Get <Farm>(res.First()); var owener = conn.Get <User>(newFarm.owner); owener.farm_id = newFarm.id; conn.Update <User>(owener); return(new ResultContent(true, newFarm)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Post(Field field) { if (field == null) { return(new ResultContent(false, MSG.GetInstance().INVALID_DATA, null)); } try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { if (conn.Insert <Field>(field) > 0) { var strSql = "SELECT MAX(id) FROM tb_field"; var res = conn.Query <int>(strSql); var newField = conn.Get <Field>(res.First()); return(new ResultContent(true, newField)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Get(string prov, string city, string county) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //查询 string strSql = "SELECT * FROM tb_farm WHERE province = @province AND city = @city AND county = @county"; var farms = conn.Query <Farm>(strSql, new { province = prov, city = city, county = county }); if (farms.Any <Farm>()) { return(new ResultContent(true, farms)); } else { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Get(int farm_id, DateTime start, DateTime end) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //查询 string strSql = "SELECT * FROM tb_field_live WHERE farm_id = @farm_id AND collect_date BETWEEN @start AND @end"; var fieldLives = conn.Query <FieldLive>(strSql, new { farm_id = farm_id, start = start, end = end }); if (fieldLives.Any <FieldLive>()) { return(new ResultContent(true, fieldLives)); } else { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Delete(int id) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //删除 if (conn.Delete(new Field() { id = id })) { return(new ResultContent(true, null)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Get(int farm_id) { try { using (System.Data.IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //查询农场所有地块 var strSql = "SELECT * FROM tb_field WHERE farm_id = @farm_id"; var fields = conn.Query <Field>(strSql, new { farm_id = farm_id }); if (!fields.Any <Field>()) { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } else { //dic_rsi_type var rsiTypes = conn.GetAll <dic_rsi_type>(); if (!rsiTypes.Any <dic_rsi_type>()) { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } else { var rsis = new List <RSI>(); foreach (Field field in fields) { foreach (dic_rsi_type type in rsiTypes) { var strSql1 = "SELECT * FROM tb_field_rsi WHERE field_id = @field_id AND type_id=@type_id ORDER BY product_date DESC LIMIT 1 OFFSET 0"; var rsi = conn.QueryFirstOrDefault <RSI>(strSql1, new { field_id = field.id, type_id = type.id }); if (rsi != null) { rsis.Add(rsi); } } } if (rsis.Count < 1) { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } return(new ResultContent(true, rsis)); } } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Post(List <String> base64Strs) { if (base64Strs == null || base64Strs.Count < 1) { return(new ResultContent(false, MSG.GetInstance().INVALID_DATA, null)); } try { var path = System.Web.HttpContext.Current.Server.MapPath("~"); var folder = @"img\" + DateTime.Now.ToString("yyyyMMdd") + "\\"; var folderName = path + "\\" + folder; if (!Directory.Exists(folderName)) { Directory.CreateDirectory(folderName); } var urls = new List <string>(); foreach (string str in base64Strs) { using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(str))) { using (Bitmap bitmap = new Bitmap(memoryStream)) { if (bitmap == null) { return(new ResultContent(false, MSG.GetInstance().INVALID_DATA, null)); } var file = DateTime.Now.ToFileTime().ToString() + ".jpg"; var fileName = folderName + file; //BitmapUtils.Compress(bitmap, fileName, 0); bitmap.Save(fileName, ImageFormat.Jpeg); urls.Add((folder + file).Replace(@"\", "/")); } } } return(new ResultContent(true, urls)); } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Put(User user) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //查询用户 if (conn.Update <User>(user)) { var updateUser = conn.Get <User>(user.id); return(new ResultContent(true, updateUser)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Get(int type, int limit, int offset) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { var strSql = "SELECT * FROM tb_news WHERE news_type = @news_type ORDER BY news_date LIMIT @limit OFFSET @offset"; var news = conn.Query <News>(strSql, new { news_type = type, limit = limit, offset = offset }); if (news.Any <News>()) { return(new ResultContent(true, news)); } else { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Put(Task task) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //更新 if (conn.Update <Task>(task)) { var updateTask = conn.Get <Task>(task.id); return(new ResultContent(true, updateTask)); } else { return(new ResultContent(false, MSG.GetInstance().UNKNOWN_ERROR, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
public ResultContent Get(int id) { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { //查询 var field = conn.Get <Field>(id); if (field != null) { return(new ResultContent(false, field)); } else { return(new ResultContent(false, MSG.GetInstance().DATA_NOT_FOUND, null)); } } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }
/// <summary> /// 执行成功时使用该构造器,默认添加成功消息 /// </summary> /// <param name="status">执行状态</param> /// <param name="data">数据反馈</param> public ResultContent(bool status, object data) { this.status = status; this.msg = MSG.GetInstance().SUCCEED; this.data = data; }
public ResultContent Get() { try { using (IDbConnection conn = DbConnection.OpenConnection(ConnectionType.PostgreSQL)) { Dic dics = new Dic(); //crop_type var crop = conn.GetAll <dic_crop_type>(); if (crop.Any <dic_crop_type>()) { dics.dic_crop = crop.ToList <dic_crop_type>(); } //disease_type var disease = conn.GetAll <dic_disease_type>(); if (disease.Any <dic_disease_type>()) { dics.dic_disease = disease.ToList <dic_disease_type>(); } //growth_type var growth = conn.GetAll <dic_growth_type>(); if (growth.Any <dic_growth_type>()) { dics.dic_growth = growth.ToList <dic_growth_type>(); } //dic_moisture_type var moisture = conn.GetAll <dic_moisture_type>(); if (moisture.Any <dic_moisture_type>()) { dics.dic_moisture = moisture.ToList <dic_moisture_type>(); } //dic_news_type var news = conn.GetAll <dic_news_type>(); if (news.Any <dic_news_type>()) { dics.dic_news = news.ToList <dic_news_type>(); } //dic_pest_type var pest = conn.GetAll <dic_pest_type>(); if (pest.Any <dic_pest_type>()) { dics.dic_pest = pest.ToList <dic_pest_type>(); } //dic_phenophase var phenophase = conn.GetAll <dic_phenophase>(); if (phenophase.Any <dic_phenophase>()) { dics.dic_phenophase = phenophase.ToList <dic_phenophase>(); } //dic_rsi_type var rsi = conn.GetAll <dic_rsi_type>(); if (rsi.Any <dic_rsi_type>()) { dics.dic_rsi = rsi.ToList <dic_rsi_type>(); } return(new ResultContent(true, dics)); } } catch (Exception ex) { //TODO:记录日志 return(new ResultContent(false, MSG.GetInstance().SERVER_ERROR, null)); } }