/// <summary> /// 数据列表转为对象 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <returns>对象</returns> private T List2Object <T>() { string sJson = Angel_DataJson.List2Json(this.lst_colId, this.lst_Value); T Object = Angel_DataJson.json2Object <T>(sJson); return((T)Object); }
/// <summary> /// 插入数据 /// </summary> /// <param name="strJson_obj2Insert"></param> /// <returns></returns> public bool InsertObjectByJson(string strJson_obj2Insert) { //用Json给值列表赋值 //T obj2Insert = C_xJson.json2Object<T>(strJson_obj2Insert); //GetObjValueList<T>(obj2Insert); Angel_DataJson.getValuelistByJsonString(strJson_obj2Insert, lst_colId, out lst_Value); //设定条件 SetCondition(lst_colId[0], lst_Value[0]); //更新DB return(InsertData()); }
/// <summary> /// 用Json字符串更新对象 /// </summary> /// <typeparam name="T">对戏类</typeparam> /// <param name="strJson_obj2Update">Json数据</param> /// <returns>是否成功</returns> public bool InsertObjectByJson <T>(string strJson_obj2Insert) { //用Json给值列表赋值 T obj2Insert = Angel_DataJson.json2Object <T>(strJson_obj2Insert); GetObjValueList <T>(obj2Insert); //设定条件 SetCondition(lst_colId[0], lst_Value[0]); //更新DB return(InsertData()); }
// // 获得数据集的Json字符串 // public void GetDsJson(int total) { this.strDsJson = ""; //this.GetDataset(); if ((ds == null) || (ds.Tables.Count == 0)) { strDsJson = "{ total: 0, rows: [] }"; } else { strDsJson = Angel_DataJson.dataSet2EasyUiDataGridJson(ds, total); } }
/// <summary> /// 修改多个对象的某个属性 /// </summary> /// <param name="str_JsonIdList">["id1","id2"..."idn"]</param> /// <returns></returns> public bool setObjectsAttributById(string str_JsonIdList, string s_attr, string s_value) { bool success = true; List <string> l_str_ids; l_str_ids = Angel_DataJson.json2ObjList <string>(str_JsonIdList); for (int i = 0; i < l_str_ids.Count; i++) { if (!setObjectAttributById(l_str_ids[i], s_attr, s_value)) { return(false); } } return(success); }
/// <summary> /// 删除多个对象 /// </summary> /// <param name="str_JsonIdList">["id1","id2"..."idn"]</param> /// <returns>是否成功</returns> public bool DeleteObjectsById(string str_JsonIdList) { bool success = true; List <string> l_str_ids; l_str_ids = Angel_DataJson.json2ObjList <string>(str_JsonIdList); for (int i = 0; i < l_str_ids.Count; i++) { this.SetCondition("id", l_str_ids[i]); if (!this.DeleteData()) { return(false); } } return(success); }
/// <summary> /// 得到对象列表 /// </summary> /// <typeparam name="T"> 对象类</typeparam> /// <param name="str_Condition">条件</param> /// <returns>对象列表</returns> public List <T> getObjectListByCondition <T>(string str_Condition) { this.strDsJson = ""; // 得到数据集 DataSet ds = Item_db.GetDataSetByCondition(this.tablename, this.lst_colId, str_Condition); // 数据集转Json if (!(ds == null || ds.Tables.Count == 0)) { strDsJson = Angel_DataJson.dataSet2Json(ds); } // 去掉Json串中的表名 // string strMatch = @"^{.*?:"; Regex rx = new Regex(@"^{.*?:", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (rx.IsMatch(strDsJson)) { strDsJson = rx.Replace(strDsJson, ""); } return(Angel_DataJson.json2ObjList <T>(strDsJson)); }
// // 获得对象的Json字符串 // public string GetObjectJson <T>(T obj) { return(Angel_DataJson.Object2Json <T>(obj)); }