/// <summary> /// 查询数据 /// </summary> /// <returns></returns> public List <MemberList_DynamicStru> GetData(CommConf options, Dictionary <string, string> Para, ref string count) { string errorMsg; SqliteAccess conn = new SqliteAccess(options.AttriList.FirstOrDefault(o => o.key == "DBLink").value); bool ispara = false; //拼接sql查询条件 string strPara = " where 1=1 and "; foreach (var item in Para) { if (!string.IsNullOrEmpty(item.Value) && item.Key != "page" && item.Key != "limit") { strPara += item.Key + "='" + item.Value + "' and "; ispara = true; } } strPara = strPara.Substring(0, strPara.Length - 4); string strsql = string.Format(@"select * from(select * from (select * from MemberList_Dynamic {0} order by id asc limit {1}) order by id desc limit {2}) order by id asc", strPara, int.Parse(Para["page"]) * int.Parse(Para["limit"]), Para["limit"]); DataTable dt = conn.QueryDt(strsql, out errorMsg); MemberList_DynamicStru obj = new MemberList_DynamicStru(); List <MemberList_DynamicStru> DataList = new List <MemberList_DynamicStru>(); foreach (DataRow item in dt.Rows) { obj = new MemberList_DynamicStru(); obj.id = int.Parse(item["id"].ToString()); obj.username = item["username"].ToString(); obj.sex = item["sex"].ToString(); obj.tel = item["tel"].ToString(); obj.addr = item["addr"].ToString(); obj.states = item["states"].ToString(); DataList.Add(obj); } //是否是条件查询,统计条数 if (ispara == false) { strsql = "select count(*) from MemberList_Dynamic"; } else { strsql = string.Format(@"select count(*) from MemberList_Dynamic {0}", strPara); } DataTable dtcount = conn.QueryDt(strsql, out errorMsg); count = dtcount.Rows[0][0].ToString(); return(DataList); }
/// <summary> /// 接收前端传递来的,待修改页面数据,原样返回 /// </summary> /// <param name="username"></param> /// <param name="sex"></param> /// <param name="tel"></param> /// <param name="addr"></param> /// <param name="Static"></param> /// <returns></returns> public IActionResult MemberEdit(string username, string sex, string tel, string addr, string states) { MemberList_DynamicStru MemberList_Dynamic = new MemberList_DynamicStru(); MemberList_Dynamic.username = username; MemberList_Dynamic.sex = sex; MemberList_Dynamic.tel = tel; MemberList_Dynamic.addr = addr; MemberList_Dynamic.states = states; var resultModel = new MemberList_DynamicViewModel { memberlist_dynamic = MemberList_Dynamic }; return(View(resultModel)); }
/// <summary> /// 编辑数据 /// </summary> /// <returns></returns> public bool UpdateData(CommConf options, MemberList_DynamicStru objstru) { string errorMsg; SqliteAccess conn = new SqliteAccess(options.AttriList.FirstOrDefault(o => o.key == "DBLink").value); string str = string.Format("update MemberList_Dynamic set sex = '{0}', tel = '{1}', addr = '{2}', states = '{3}' where username='******'", objstru.sex, objstru.tel, objstru.addr, objstru.states, objstru.username); int count = conn.Execute(str, out errorMsg); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 新增数据 /// </summary> /// <returns></returns> public bool AddData(CommConf options, MemberList_DynamicStru objstru) { string errorMsg; SqliteAccess conn = new SqliteAccess(options.AttriList.FirstOrDefault(o => o.key == "DBLink").value); string str = string.Format("insert into MemberList_Dynamic (username,sex,tel,addr,states) values('{0}','{1}','{2}','{3}','{4}')", objstru.username, objstru.sex, objstru.tel, objstru.addr, objstru.states); int count = conn.Execute(str, out errorMsg); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 删除数据 /// </summary> /// <returns></returns> public bool DeleteData(CommConf options, MemberList_DynamicStru objstru) { string errorMsg; SqliteAccess conn = new SqliteAccess(options.AttriList.FirstOrDefault(o => o.key == "DBLink").value); string str = string.Format("delete from MemberList_Dynamic where id='{0}'", objstru.id); int count = conn.Execute(str, out errorMsg); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 删除数据,delete /// </summary> /// <param name="id"></param> /// <param name="username"></param> /// <returns></returns> public bool Delete(string id, string username) { MemberList_DynamicStru MemberList_DynamicStru = new MemberList_DynamicStru(); MemberList_DynamicStru.id = Convert.ToInt32(id); MemberList_DynamicStru.username = username; MemberList_DynamicViewModel dataInfo = new MemberList_DynamicViewModel(); if (dataInfo.DeleteData(_appConf, MemberList_DynamicStru)) { return(true); } else { return(false); } }
/// <summary> /// 新增数据,add /// </summary> /// <param name="username"></param> /// <param name="sex"></param> /// <param name="tel"></param> /// <param name="addr"></param> /// <param name="Static"></param> /// <returns></returns> public bool Add(string username, string sex, string tel, string addr, string states) { MemberList_DynamicStru MemberList_DynamicStru = new MemberList_DynamicStru(); MemberList_DynamicStru.username = username; MemberList_DynamicStru.sex = sex; MemberList_DynamicStru.tel = tel; MemberList_DynamicStru.addr = addr; MemberList_DynamicStru.states = states; MemberList_DynamicViewModel dataInfo = new MemberList_DynamicViewModel(); if (dataInfo.AddData(_appConf, MemberList_DynamicStru)) { return(true); } else { return(false); } }