mvc+EF 素颜马尾好姑娘i 2022-06-16 13:59 209阅读 0赞 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Data; using System.Net; namespace web.Controllers { [Authorize] public class Member_CostController : Controller { // GET: /Member_Cost/ private Model.XHZ_MemberEntities xhz = new Model.XHZ_MemberEntities(); public ActionResult Index() { return View(); } public JsonResult TodayList() { string m_id = Request["m_id"]; string dt1=Request["dt1"]; string dt2=Request["dt2"]; DateTime? d1=Convert.ToDateTime(dt1); DateTime? d2=Convert.ToDateTime(dt2); var lst = (from s in xhz.v_cost where s.m_id==m_id &&( s.p_time>=d1 && s.p_time<=d2) select s); string count = lst.Count().ToString(); List<Model.v_cost> lt = new List<Model.v_cost>(); foreach (var l in lst) { lt.Add(l); } var grid = new { Rows = lt, Total = count }; return Json(grid, JsonRequestBehavior.AllowGet); } public JsonResult lst() { string m_id = Request["m_id"]; var lst = (from s in xhz.V_member where s.m_id == m_id select s); string count = lst.Count().ToString(); List<Model.V_member> lt = new List<Model.V_member>(); foreach (var l in lst) { lt.Add(l); } var grid = new { Rows = lt, Total = count }; return Json(grid, JsonRequestBehavior.AllowGet); } public ActionResult Add() { return View(); } /// <summary> /// 获取用户ID作为唯一标记 /// </summary> /// <returns></returns> public string getusercookie() { string s = Request.Cookies["name"].Value; return s; } /// <summary> /// 做缓存表用来临时显示客户增加的消费项目,判断有没有相同编码,有的话,数量加1,没有添加一条数据,关闭前有效。 /// </summary> /// <returns>返回JSON格式的信息</returns> public JsonResult CacheList() { int m_id = int.Parse(Request["m_id"]); string m_name = Request["m_name"]; string m_price = Request["m_price"]; int count = 0; if (HttpRuntime.Cache.Get(getusercookie() + "count") != null) { count = Convert.ToInt16(HttpRuntime.Cache.Get(getusercookie() + "count")); } if(m_id!=0) { Cls_pay p = new Cls_pay(); p.p_id = m_id; p.p_name = m_name; p.p_money = Convert.ToDecimal(m_price); p.p_count = "1"; count = count + 1; HttpRuntime.Cache.Insert(getusercookie() + "count", count); HttpRuntime.Cache.Insert(getusercookie() + "paylist" + count, p); } List<Cls_pay> lttt = new List<Cls_pay>(); for (int i = 1; i < count + 1; i++) { Cls_pay c=new Cls_pay(); c = HttpRuntime.Cache.Get(getusercookie() + "paylist" + i) as Cls_pay; lttt.Add(c); } var grid = new { Rows = lttt, Total = lttt.Count() }; return Json(grid, JsonRequestBehavior.AllowGet); } /// <summary> /// 用来负责结算的方法,清除缓存中的数据。 /// </summary> /// <returns></returns> public ActionResult clearcache() { string ys=Request["ys"]; string syjf=Request["syjf"]; string skjf = Request["skjf"]; int count = Convert.ToInt16(HttpRuntime.Cache.Get(getusercookie() + "count")); #region 处理数据到数据库 //List<Cls_pay> lttt = new List<Cls_pay>(); for (int i = 1; i < count + 1; i++) { Cls_pay c=new Cls_pay(); c = HttpRuntime.Cache.Get(getusercookie() + "paylist" + i) as Cls_pay; //lttt.Add(c); int? p_id = c.p_id; string p_name = c.p_name; string p_count = c.p_count; decimal? p_money = c.p_money; // 以下对消费列表类模进行add操作。 Model.t_cost t=new Model.t_cost(); t.ID = t_Cost_Max()+1; string s=Request["m_id"]; t.m_id = s; t.p_id=p_id; t.p_count=int.Parse(p_count); t.p_money=p_money; t.p_time=DateTime.Now.Date; xhz.t_cost.Add(t); xhz.SaveChanges(); }//end for #endregion #region 删除缓存中的数据 HttpRuntime.Cache.Remove(getusercookie() + "count"); for (int i = 1; i < count + 1; i++) { HttpRuntime.Cache.Remove(getusercookie() + "paylist"+i); } return View(); #endregion } /// <summary> /// 用来定义的消费列表的类. /// </summary> public class Cls_pay { public int? p_id {get;set;} public string p_name { get; set; } public string p_count { get; set; } public decimal? p_money { get; set; } } public ActionResult pay() { string s = Request["ysje"]; string ky = Request["ky"]; ViewData["ys"] = s; ViewData["ky"] = ky; string id=Request["m_id"]; ViewData["id"] = id; return View(); } protected int t_Cost_Max() { int max; if (xhz.t_cost.Count() == 0) { max = 0; } else { max = xhz.t_cost.Max(x => x.ID); } return max; } public ActionResult clear() { int count = Convert.ToInt16(HttpRuntime.Cache.Get(getusercookie() + "count")); #region 删除缓存中的数据 HttpRuntime.Cache.Remove(getusercookie() + "count"); for (int i = 1; i < count + 1; i++) { HttpRuntime.Cache.Remove(getusercookie() + "paylist" + i); } return View(); #endregion } } } using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Security; namespace web.Controllers { public class LoginController : Controller { // // GET: /Login/ protected Model.XHZ_MemberEntities xhz = new Model.XHZ_MemberEntities(); public ActionResult Default() { if (User.Identity.IsAuthenticated) { string cookieName = FormsAuthentication.FormsCookieName; HttpCookie authCookie = Request.Cookies[cookieName]; FormsAuthenticationTicket authTicket = null; authTicket = FormsAuthentication.Decrypt(authCookie.Value); string userinfo = authTicket.UserData; } return View(); } public JsonResult login(Model.t_user u) { u.u_name = Request.Form["tname"]; u.u_pwd = Request.Form["tpwd"]; string userName = u.u_name; string pwd = u.u_pwd; var lst = (from s in xhz.t_user where s.u_name == u.u_name && s.u_pwd == u.u_pwd select s); int count = lst.Count(); if (count==1) { #region // //自定义授权 // //创建Forms身份验证票 // FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(userName, false, 300); // //根据Forms身份验证票生成一个加密的客户端身份Cookie值. // string cookieValue = FormsAuthentication.Encrypt(ticket); // //客户端Forms身份验证票名称 // string cookieName = FormsAuthentication.FormsCookieName; // HttpCookie cookie = new HttpCookie(cookieName, cookieValue); // Response.Cookies.Add(cookie); // // Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, false)); FormsAuthentication.RedirectToLoginPage("~/Home/Index"); #endregion FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(userName, false, 360); //加密票据 string ticString = FormsAuthentication.Encrypt(ticket); //输出到客户端 Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, ticString)); //跳转到登录前页面 Response.Cookies.Add(new HttpCookie("OprName", ticString)); //跳转到登录前页面 Response.Cookies.Add(new HttpCookie("name", u.u_name)); count = 1; } return Json(count,JsonRequestBehavior.AllowGet); } public void logout() { FormsAuthentication.SignOut(); Response.Redirect("~/Login/Default"); } } } using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Mvc; namespace web.Controllers { [Authorize] public class PasswordController : Controller { // // GET: /Password/ private Model.XHZ_MemberEntities xhz = new Model.XHZ_MemberEntities(); public ActionResult Index() { return View(); } public JsonResult post() { bool t=false; string pwd = Request.Form["oo_pwd"]; Model.t_user l = xhz.Set<Model.t_user>().SingleOrDefault(x => x.u_pwd == pwd); if (l.u_name != null) { l.u_pwd=Request.Form["on_pwd"]; xhz.SaveChanges(); t = true; } else { t = false; }; return Json(t); } } } @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <script src="~/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="~/Scripts/ligerUI/js/ligerui.min.js" type="text/javascript"></script> <link href="~/Scripts/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css"/> <link href="~/Scripts/ligerUI/skins/ligerui-icons.css" type="text/css"rel="stylesheet" /> <link href="~/Scripts/ligerUI/skins/ext/css/ligerui-dialog.css" rel="stylesheet" type="text/css"/> @* <link href="../../Content/form.css" rel="Stylesheet" type="text/css"/>*@ <title></title> </head> <body> @RenderBody() </body> </html> @{ Layout = "~/Views/Shared/add.cshtml"; } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>增加会员信息</title> <script type="text/javascript"> function jsonDateFormat(jsonDate) {//json日期格式转换为正常格式 try { var d = jsonDate; var dd = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds(); return dd; } catch (ex) { return ""; } } function getlevelData() { var ajaxdata, s; $.ajax({ type: "post", url: "LevelLst", dataType: "json", async: false, success: function (data) { ajaxdata = data; // s = JSON.stringify(ajaxdata); // alert(s); } }); return ajaxdata; } var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象) function f_save() { var form = liger.get("form1"); var data = form.getData(); var dt = jsonDateFormat(data.t_birthday); // alert(liger.toJSON(data.t_birthday)); alert((data.t_birthday)); $.post("../Member/C_add", { t_id: data.t_id, t_name: data.t_name, t_phone: data.t_phone, t_addr: data.t_addr, t_comp: data.t_comp, t_birthday: dt, t_member_level_ID: data.t_member_level_ID }); $.post("../Integral/Add", { t_id: data.t_id}); $(".l-bar-button.l-bar-btnload", window.parent.document).click(); alert("添加成功"); dialog.close(); //关闭dialog } function f_close() { dialog.close(); //关闭dialog } </script> </head> <body> <div id="form1" class="liger-form"> <div class="fields"> <input class="hh" data-type="text" data-label="会员编码" data-name="t_id"/><br /> <input class="hh" data-type="text" data-label="会员名称" data-name="t_name"/><br /> <input class="hh" data-type="text" data-label="手机号码" data-name="t_phone"/><br /> <input class="hh" data-type="text" data-label="地 址" data-name="t_addr"/><br /> <input class="hh" data-type="text" data-label="单 位" data-name="t_comp"/><br /> <input class="hh" data-type="date" data-label="生 日" data-name="t_birthday" /><br /> <div data-label="会员级别" data-type="select" data-name="t_member_level_ID" data-textField="level_name" data-width="200"> <input class="editor" data-data="getlevelData()" data-textField="member_level_name" data-valueField="member_level_ID" /> </div> </div> <div class="buttons"> <input data-text="保存" data-click="f_save" data-width="60"/> <input data-text="关闭" data-click="f_close" data-width="60"/> </div> </div> </body> </html>
还没有评论,来说两句吧...