/// <summary> /// 创建或更新索引 travelpart /// </summary> /// <param name="parts"></param> /// <returns></returns> public static int NewTravelPartIndex(TravelParts parts) { var docs = new List <SolrInputDocument>(); var doc = new SolrInputDocument(); doc.Add("id", new SolrInputField("id", "travelparts_" + parts.Id)); doc.Add("TravelId", new SolrInputField("TravelId", parts.TravelId)); doc.Add("UserId", new SolrInputField("UserId", parts.UserId)); doc.Add("PartType", new SolrInputField("PartType", parts.PartType)); doc.Add("Description", new SolrInputField("Description", parts.Description)); doc.Add("PartUrl", new SolrInputField("PartUrl", parts.PartUrl)); doc.Add("Longitude", new SolrInputField("Longitude", parts.Longitude)); doc.Add("Latitude", new SolrInputField("Latitude", parts.Latitude)); doc.Add("Height", new SolrInputField("Height", parts.Height)); doc.Add("Area", new SolrInputField("Area", parts.Area)); doc.Add("CreateTime", new SolrInputField("CreateTime", parts.CreateTime)); docs.Add(doc); var result = updateOperations.Update(CoreName, "/update", new UpdateOptions() { OptimizeOptions = optimizeOptions, Docs = docs }); var header = binaryResponseHeaderParser.Parse(result); return(header.Status); //返回状态码。0表示成功 }
public string AddTravelPart(FormCollection collection) { var travelIdStr = collection.Get("travelId"); var userIdStr = collection.Get("userId"); var partType = collection.Get("partType"); var description = collection.Get("description"); var partUrl = collection.Get("partUrl"); var longitude = collection.Get("longitude"); var latitude = collection.Get("latitude"); var area = collection.Get("address"); if (string.IsNullOrEmpty(userIdStr)) { return(HttpRequestResult.StateNotNull); } if (string.IsNullOrEmpty(description) && string.IsNullOrEmpty(partUrl)) { return(HttpRequestResult.StateNotNull); } var model = new TravelParts(); { model.UserId = Int32.Parse(userIdStr); if (!string.IsNullOrEmpty(travelIdStr)) { var travelId = Int32.Parse(travelIdStr); if (travelId > 0) { model.TravelId = travelId; } } model.PartType = Int32.Parse(partType); model.Description = description; model.PartUrl = partUrl; if (!string.IsNullOrEmpty(longitude) && !string.IsNullOrEmpty(latitude)) { model.Longitude = decimal.Parse(longitude); model.Latitude = decimal.Parse(latitude); } if (!string.IsNullOrEmpty(area)) { model.Area = area; } model.CreateTime = DateTime.Now; model.IsDelete = false; }; var flag = _travelPartsBll.Add(model); if (flag > 0) { return(HttpRequestResult.StateOk); } else { return(HttpRequestResult.StateError); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(TravelParts model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TravelParts set "); strSql.Append("TravelId=@TravelId,"); strSql.Append("UserId=@UserId,"); strSql.Append("PartType=@PartType,"); strSql.Append("Description=@Description,"); strSql.Append("PartUrl=@PartUrl,"); strSql.Append("Longitude=@Longitude,"); strSql.Append("Latitude=@Latitude,"); strSql.Append("Height=@Height,"); strSql.Append("Area=@Area,"); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("IsDelete=@IsDelete"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@TravelId", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@PartType", SqlDbType.TinyInt, 1), new SqlParameter("@Description", SqlDbType.VarChar, -1), new SqlParameter("@PartUrl", SqlDbType.VarChar, 100), new SqlParameter("@Longitude", SqlDbType.Decimal, 9), new SqlParameter("@Latitude", SqlDbType.Decimal, 9), new SqlParameter("@Height", SqlDbType.Decimal, 9), new SqlParameter("@Area", SqlDbType.NVarChar, 100), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@IsDelete", SqlDbType.Bit, 1), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.TravelId; parameters[1].Value = model.UserId; parameters[2].Value = model.PartType; parameters[3].Value = model.Description; parameters[4].Value = model.PartUrl; parameters[5].Value = model.Longitude; parameters[6].Value = model.Latitude; parameters[7].Value = model.Height; parameters[8].Value = model.Area; parameters[9].Value = model.CreateTime; parameters[10].Value = model.IsDelete; parameters[11].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(TravelParts model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TravelParts("); strSql.Append("TravelId,UserId,PartType,Description,PartUrl,Longitude,Latitude,Height,Area,CreateTime,IsDelete)"); strSql.Append(" values ("); strSql.Append("@TravelId,@UserId,@PartType,@Description,@PartUrl,@Longitude,@Latitude,@Height,@Area,@CreateTime,@IsDelete)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@TravelId", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@PartType", SqlDbType.TinyInt, 1), new SqlParameter("@Description", SqlDbType.VarChar, -1), new SqlParameter("@PartUrl", SqlDbType.VarChar, 100), new SqlParameter("@Longitude", SqlDbType.Decimal, 9), new SqlParameter("@Latitude", SqlDbType.Decimal, 9), new SqlParameter("@Height", SqlDbType.Decimal, 9), new SqlParameter("@Area", SqlDbType.NVarChar, 100), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@IsDelete", SqlDbType.Bit, 1) }; parameters[0].Value = model.TravelId; parameters[1].Value = model.UserId; parameters[2].Value = model.PartType; parameters[3].Value = model.Description; parameters[4].Value = model.PartUrl; parameters[5].Value = model.Longitude; parameters[6].Value = model.Latitude; parameters[7].Value = model.Height; parameters[8].Value = model.Area; parameters[9].Value = model.CreateTime; parameters[10].Value = model.IsDelete; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public TravelParts GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,TravelId,UserId,PartType,Description,PartUrl,Longitude,Latitude,Height,Area,CreateTime,IsDelete from TravelParts "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; TravelParts model = new TravelParts(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public TravelParts DataRowToModel(DataRow row) { TravelParts model = new TravelParts(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["TravelId"] != DBNull.Value && row["TravelId"].ToString() != "") { model.TravelId = int.Parse(row["TravelId"].ToString()); } if (row["UserId"] != null && row["UserId"].ToString() != "") { model.UserId = int.Parse(row["UserId"].ToString()); } if (row["PartType"] != null && row["PartType"].ToString() != "") { model.PartType = int.Parse(row["PartType"].ToString()); } if (row["Description"] != null) { model.Description = row["Description"].ToString(); } if (row["PartUrl"] != null) { model.PartUrl = row["PartUrl"].ToString(); } if (row["Longitude"] != null && row["Longitude"].ToString() != "") { model.Longitude = decimal.Parse(row["Longitude"].ToString()); } if (row["Latitude"] != null && row["Latitude"].ToString() != "") { model.Latitude = decimal.Parse(row["Latitude"].ToString()); } if (row["Height"] != null && row["Height"].ToString() != "") { model.Height = decimal.Parse(row["Height"].ToString()); } if (row["Area"] != null) { model.Area = row["Area"].ToString(); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["IsDelete"] != null && row["IsDelete"].ToString() != "") { if ((row["IsDelete"].ToString() == "1") || (row["IsDelete"].ToString().ToLower() == "true")) { model.IsDelete = true; } else { model.IsDelete = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(TravelParts model) { return dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(TravelParts model) { return dal.Add(model); }