/// <summary> /// 保存 /// </summary> /// <returns></returns> public string Save2() { string Orgcode = System.Web.HttpContext.Current.Request.Params["Orgcode"]; string data = System.Web.HttpContext.Current.Request.Params["data"]; Dictionary <string, object> dicWhere = new Dictionary <string, object>(); new CreateCriteria(dicWhere).Add(ORMRestrictions <string> .Eq("Orgcode", Orgcode)); IList <ProjectThresholdModel> projectThresholdModels = ProjectThresholdService.Find(dicWhere).Data; List <long> phidList = projectThresholdModels.ToList().Select(x => x.PhId).ToList(); List <ProjectThresholdModel> SaveData = new List <ProjectThresholdModel>(); if (data.EndsWith("|")) { data = data.Substring(0, data.Length - 1); } String[] Items = data.Split('|'); foreach (String item in Items) { //取到item,即序列化对象 String[] attrs = item.Split(':'); if (string.IsNullOrEmpty(attrs[0]) || attrs[0] == "0") { var p1 = new ProjectThresholdModel(); p1.Orgcode = attrs[1]; p1.FThreshold = attrs[2]; p1.ProjTypeId = attrs[3]; p1.ProjTypeName = attrs[4]; p1.Orgid = long.Parse(attrs[5]); p1.PersistentState = PersistentState.Added; SaveData.Add(p1); } else { if (phidList.Contains(long.Parse(attrs[0]))) { phidList.Remove(long.Parse(attrs[0])); } var p1 = projectThresholdModels.ToList().Find(x => x.PhId == long.Parse(attrs[0])); p1.FThreshold = attrs[2]; p1.ProjTypeId = attrs[3]; p1.ProjTypeName = attrs[4]; p1.PersistentState = PersistentState.Modified; SaveData.Add(p1); } } if (phidList.Count > 0) { foreach (var phid in phidList) { var p1 = projectThresholdModels.ToList().Find(x => x.PhId == phid); p1.PersistentState = PersistentState.Deleted; SaveData.Add(p1); } } SavedResult <Int64> savedresult = ProjectThresholdService.Save <Int64>(SaveData, ""); return(DataConverterHelper.SerializeObject(savedresult)); }
/// <summary> /// 保存数据 /// </summary> /// <returns>返回Json串</returns> public string Save() { string projectthresholdformData = System.Web.HttpContext.Current.Request.Form["projectthresholdformData"]; var projectthresholdforminfo = DataConverterHelper.JsonToEntity <ProjectThresholdModel>(projectthresholdformData); SavedResult <Int64> savedresult = new SavedResult <Int64>(); try { savedresult = ProjectThresholdService.Save <Int64>(projectthresholdforminfo.AllRow, ""); } catch (Exception ex) { savedresult.Status = ResponseStatus.Error; savedresult.Msg = ex.Message.ToString(); } return(DataConverterHelper.SerializeObject(savedresult)); }