public ActionResult ChangePassword(string oldpassword, string password, string confirmPassword) { int id = BLL.UserInfo.CurUser.Id; if(password!=confirmPassword) { ModelState.AddModelError("confirmPassword","两次密码不一致"); return View(); } if(password.Trim()=="") { ModelState.AddModelError("password", "密码不能为空"); return View(); } using (OUContext db = new OUContext()) { OUDAL.Supplier supplier = (from o in db.Suppliers where o.Id == id select o).First(); if (supplier.Password == oldpassword) { supplier.Password = password; db.SaveChanges(); return Redirect("~/Supplier/SupplierView"); } else { ModelState.AddModelError("oldpassword", "旧密码错误"); } }return View(); }
public ActionResult SupplierEdit( FormCollection collection) { int id = 0; int.TryParse(System.Web.HttpContext.Current.User.Identity.Name, out id); OUContext db = new OUContext(); Supplier s = (from o in db.Suppliers where o.Id == id select o).FirstOrDefault(); if(s==null) { return View(s); } if(s.State==(int)SupplierState.往来) { return View("ShowError", "", "已是往来供应商,不能修改资料"); } //collection.Remove(""); TryUpdateModel(s, "", new string[] { }, new string[] { "Name", "Password", "Level", "State","AuditRemark" ,"AccessCode"}, collection); if (ModelState.IsValid) { s.Save(db); db.SaveChanges(); if(id==0) { BLL.Utilities.AddLog(s.Id,Supplier.LogClass, "创建", ""); } else { BLL.Utilities.AddLog(s.Id, Supplier.LogClass, "修改", ""); } return Redirect("SupplierView" ); } return View(s); }
public ActionResult LogOn(ClientWeb.Web.Models.LogOnModel model, string returnUrl) { if (ModelState.IsValid) { OUContext db = new OUContext(); Client s = (from o in db.Clients where o.Name == model.UserName && o.Password == model.Password select o). FirstOrDefault(); if (s == null) { ModelState.AddModelError("", "Error UserName Or Password"); } else { FormsAuthentication.SetAuthCookie((s.Id ).ToString(), false); HttpContext.Session["User"] = null; if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 10 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); } } return View(model); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { OUContext db=new OUContext(); OUDAL.Supplier supplier = (from o in db.Suppliers where model.UserName == o.Name && model.Password == o.Password select o). FirstOrDefault(); if (supplier != null) { FormsAuthentication.SetAuthCookie(supplier.Id.ToString(), false); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("SupplierView", "Supplier"); } } else { ModelState.AddModelError("", "用户名或密码错误"); } } // If we got this far, something failed, redisplay form return View(model); }
public static Product GetProduct(int id) { using (OUContext db = new OUContext()) { return db.Products.Find(id); } }
public string RequestImportItem(OUContext db, string code, int foodId, decimal num, DateTime date, string remark, string action) { FoodMaterialRequest req = (from o in db.FoodMaterialRequests where o.Code == code select o).FirstOrDefault(); if (action == "删除") { if (req == null) return "找不到可以删除的申请"; if (req.TypeId != foodId) return "要删除的记录与原记录不匹配,原料不同"; if(req.State!=(int)FoodMaterialRequestState.未提交)return "要删除的记录状态不允许删除"; req.State = (int)FoodMaterialRequestState.作废; db.SaveChanges(); return ""; } if (action == "修改") { if (req == null) return "找不到可以修改的申请"; if (req.TypeId != foodId) return "要修改的记录与原记录不匹配,原料不同"; if(req.State!=(int)FoodMaterialRequestState.未提交)return "要修改的记录状态不允许修改"; } if (req == null) { req = new FoodMaterialRequest(); db.FoodMaterialRequests.Add(req); req.Code = code; req.TypeId=foodId; } req.Num = num; req.OrderDate = date; req.Remark = remark; req.PersonId = UserInfo.CurUser.Id; req.RequestTime = DateTime.Now; db.SaveChanges(); return ""; }
public static List<Product> GetProducts() { using(OUContext db=new OUContext()) { List<Product> list = (from o in db.Products orderby o.Catalog select o).ToList(); return list; } }
public static List<Asset> GetAssets(int storeid) { using (OUContext db = new OUContext()) { List<Asset> list = (from o in db.Assets where o.StoreId == storeid orderby o.Name select o).ToList(); return list; } }
public static List<Product> GetProducts(int storeid) { using(OUContext db=new OUContext()) { List<Product> list = (from o in db.Products where o.StoreId==storeid orderby o.Catalog select o).ToList(); return list; } }
public static string GetAssetName(int id) { using (OUContext db = new OUContext()) { var asset=db.Assets.Find(id); if(asset!=null) return asset.Name; return ""; } }
public static decimal GetRate() { using(OUContext db=new OUContext()) { var r = (from o in db.ExchangeRates where o.EndDate == null select o).FirstOrDefault(); if (r == null) throw new Exception("Need a Exchange Rate"); return r.Rate; } }
public static string GetName(int id) { using (OUContext db = new OUContext()) { var c = db.Buildings.Find(id); if (c != null) return c.Name; } return ""; }
public static void InitDatabase() { Console.WriteLine("确定删除数据库?按任一键继续..."); Console.ReadKey(); Console.WriteLine("删除中,请稍候..."); System.Data.Entity.Database.SetInitializer<OUContext>(new ContextDropDBInitializer()); OUContext db=new OUContext(); var query = (from o in db.SystemUsers select o).ToList(); Console.WriteLine("Database rebuilded"); }
public static List<SelectListItem> GetCompany() { List<SelectListItem> list = new List<SelectListItem>(); using (OUContext db = new OUContext()) { var query = from c in db.Companies where c.State == 0 orderby c.Name select new IntStringItem() { Value = c.Id, Text = c.Name }; return (from c in query.ToList() select new SelectListItem { Value = c.Value.ToString(), Text = c.Text }).ToList(); } }
public static void AddLog(OUContext db, string person, int id, string logClass, string logAction, string info) { AccessLog a = new AccessLog(); a.KeyId = id; a.AccessClass = logClass; a.AccessAction = logAction; a.AccessInfo = info; a.AccessTime = DateTime.Now; a.AccessPerson = person; db.AccessLogs.Add(a); }
public string RequestImport(Stream fileStream) { using (ExcelPackage package = new ExcelPackage(fileStream)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; StringBuilder sbError=new StringBuilder(); using (OUContext db = new OUContext()) { for (int i = 2; i < 10000; i++) { string code = ImportExcelHelper.ReadString(worksheet.Cells[i, 1]); if (code == "") continue; string foodName=ImportExcelHelper.ReadString(worksheet.Cells[i,2]); int? _foodId=(from o in db.FoodMaterialType where o.Name==foodName select o.Id).FirstOrDefault(); int foodId = 0; ; bool error=false; if(_foodId==null) { sbError.AppendLine(string.Format("第{0}行错误,找不到食材{0}",i,foodName)); error=true; }else { foodId=(int)_foodId; } decimal num=ImportExcelHelper.ReadDecimal(worksheet.Cells[i,3]); if(num<=0) { sbError.AppendLine(string.Format("第{0}行错误,数量不能小于0",i)); error=true; } DateTime? _date= ImportExcelHelper.ReadDateEmpty(worksheet.Cells[i,4]); DateTime date=DateTime.MinValue; if(_date==null) { sbError.AppendLine(string.Format("第{0}行错误,日期格式错误",i)); error=true; }else { date=(DateTime)_date; } if(!error){ string remark=ImportExcelHelper.ReadString(worksheet.Cells[i,5]); string action=ImportExcelHelper.ReadString(worksheet.Cells[i,6]); string result= RequestImportItem(db,code,foodId,num,date,remark,action); if(result!="") { sbError.AppendLine(string.Format("第{0}行错误,{1}",i,result)); } } } } return sbError.ToString(); } }
static void Main(string[] args) { Console.WriteLine("Press any key to drop Database"); Console.Read(); System.Data.Entity.Database.SetInitializer<OUContext>(new ContextDropDBInitializer()); //System.Data.Entity.Database.SetInitializer<OUContext>(new ContextInitializer()); OUContext db = new OUContext(); var query = (from o in db.Materials select o).ToList(); Console.WriteLine("Press any key to Exit"); Console.Read(); }
public static void Add(decimal rate,DateTime date) { using (OUContext db = new OUContext()) { var list = (from o in db.ExchangeRates where o.EndDate == null select o).ToList(); list.ForEach(o=>o.EndDate=date.AddDays(-1)); ExchangeRate r = new ExchangeRate {Rate = rate, BeginDate = date}; db.ExchangeRates.Add(r); db.SaveChanges(); } }
public ActionResult SupplierEdit() { int id = 0; int.TryParse(System.Web.HttpContext.Current.User.Identity.Name, out id); OUContext db = new OUContext(); Supplier s = (from o in db.Suppliers where o.Id == id select o).FirstOrDefault(); if(s==null) { s=new Supplier(); } return View(s); }
/// <summary> /// 未加锁,未自动db.savechanges ,最好用事务包起来 /// </summary> /// <param name="db"></param> /// <param name="name"></param> /// <param name="prefix"></param> /// <returns></returns> public static int GetCurIndex(OUContext db, string name, string prefix) { int i=1; var query=(from o in db.SysCode where o.Name==name && o.Prefix==prefix select o).FirstOrDefault(); if (query==null) { db.SysCode.Add(new SysCode { Name = name, Prefix = prefix, LastIndex = 1 }); }else { query.LastIndex++;i=query.LastIndex; } return i; }
public static Attachment Add(OUContext db, string mastertype, int masterid, HttpPostedFileBase postFile) { Attachment file = new Attachment(); file.FileName = Path.GetFileName(postFile.FileName); file.ContentType = postFile.ContentType; file.Length = postFile.ContentLength; file.Id = Guid.NewGuid(); file.MasterId = masterid; file.MasterType = mastertype; file.Contents = new byte[postFile.ContentLength]; postFile.InputStream.Read(file.Contents, 0, postFile.ContentLength); db.Attachments.Add(file); return file; }
public static List<Product> GetProducts(int storeid,bool isCardLessShine) { using (OUContext db = new OUContext()) { if (isCardLessShine) { return (from o in db.Products where o.StoreId == storeid && o.Catalog == "单次日晒" select o).ToList(); } else { return (from o in db.Products where o.StoreId == storeid && o.Catalog != "单次日晒" select o).ToList(); } } }
public static List<SelectListItem> GetList(string dictName,bool appendblank) { List<SelectListItem> list = new List<SelectListItem>(); if(appendblank==true)list.Add(new SelectListItem{Value="",Text="---"}); using (OUContext db = new OUContext()) { var query=from i in db.DictionaryItems join d in db.Dictionaries on i.DictId equals d.Id where d.Name==dictName orderby i.IndexNum ,i.Name select i; foreach (DictionaryItem c in query) { list.Add(new SelectListItem { Value = c.Name.ToString(), Text = c.Name }); } return list; } }
public static List<SelectListItem> GetUsers(int? defaultValue) { List<SelectListItem> list = new List<SelectListItem>(); using(OUContext db=new OUContext()) { var query = (from o in db.SystemUsers orderby o.Name select new { o.Id, o.Name }); foreach (dynamic o in query) { list.Add(new SelectListItem{ Text=o.Name, Value=o.Id.ToString() ,Selected=defaultValue==o.Id}); } return list; } }
public static void Init() { Functions = new Dictionary<string,int >(); FunctionInts=new Dictionary<int, string>(); using (OUContext db = new OUContext()) { var query = (from o in db.Functions.AsNoTracking() select o) .ToList(); foreach(Function f in query) { if (f.ParentName != "-") f.Name = string.Format("{0}-{1}", f.ParentName, f.Name);//目前只支持2级权限 Functions.Add(f.Name, f.Id); FunctionInts.Add(f.Id,f.Name); } } }
public static Result CardListReport(FormCollection collection, List<int> storeList) { Result result = new Result(); OUContext db = new OUContext(); List<object> parameters = new List<object>(); string sql = CardView.Sql; string sidx = collection["sidx"]; string sord = collection["sord"]; Utilities.AddSqlFilterLike(collection, "CardType", ref sql, "i.CardType", parameters); Utilities.AddSqlFilterLike(collection, "CardId", ref sql, "i.CardId", parameters); Utilities.AddSqlFilterDateGreaterThen(collection, "DateFrom", ref sql, "i.ActiveDate", parameters); Utilities.AddSqlFilterDateLessThen(collection, "DateTo", ref sql, "i.ActiveDate", parameters); Utilities.AddSqlFilterInInts(collection, "State[]", ref sql, "i.State"); string storeFilter = ""; if (storeList.Count > 0) { StringBuilder sb = new StringBuilder(" and i.storeid in ('" + storeList[0].ToString() + "'"); for (int i = 1; i < storeList.Count; i++) { sb.Append(","); sb.Append(storeList[i]); } sb.Append(")"); storeFilter = sb.ToString(); } string strOrder = ""; if (string.IsNullOrEmpty(sidx) == true) { strOrder = "i.ActiveDate"; } else { strOrder = string.Format("{0} {1}", sidx, sord); strOrder.Replace(' ', ','); } sql += string.Format(" {0} order by {1}", storeFilter, strOrder); db.Database.Connection.Open(); var dynamicParams = new DynamicParameters(); parameters.ForEach(o => { var p = o as SqlParameter; dynamicParams.Add(p.ParameterName, p.Value, p.DbType); }); var query = db.Database.Connection.Query<CardView>(sql, param: dynamicParams); var list = query.ToList(); result.success = true; result.obj = new {list = list, sidx = sidx, sord = sord}; return result; }
public static Result RechargeList(string dateFrom, string dateTo, List<int> storeList) { Result result = new Result(); OUContext db = new OUContext(); DateTime d1; DateTime d2; if (DateTime.TryParse(dateFrom, out d1) == false) d1 = new DateTime(1900, 1, 1); if (DateTime.TryParse(dateTo, out d2) == false) d2 = DateTime.Today; d2 = d2.AddDays(1); string storeFilter = ""; if (storeList.Count > 0) { StringBuilder sb = new StringBuilder(" and s.store in ('" + storeList[0].ToString() + "'"); for (int i = 1; i < storeList.Count; i++) { sb.Append(",'"); sb.Append(storeList[i]); sb.Append("'"); } sb.Append(")"); storeFilter = sb.ToString(); } string sql1 = @" declare @d1 datetime ;declare @d2 datetime; set @d1='{0:yyyy-MM-dd}';set @d2='{1:yyyy-MM-dd}' select isnull( d.name,'-') as store,isnull(u.name,'') as sales ,c.cardCode, s.Money ,convert(varchar,s.rechargeTime,20) as rechargetime,s.remark,s.isactiverecharge from CardRecharges s join Cards c on s.CardId=c.CardId left outer join departments d on d.id=s.store left outer join systemusers u on u.id=s.person where s.rechargetime between @d1 and @d2 {2} order by s.rechargetime"; sql1 = string.Format(sql1, d1, d2, storeFilter); db.Database.Connection.Open(); List<CardRechargeReport> list = db.Database.Connection.Query<CardRechargeReport>(sql1).ToList(); result.success = true; result.obj = list; return result; }
public Result LogOn(string userName, string password) { Result result = new Result(); OUContext db = new OUContext(); SystemUser user = (from o in db.SystemUsers where userName == o.Name && password == o.Password && o.State == 0 select o).FirstOrDefault(); if (user != null) { FormsAuthentication.SetAuthCookie(user.Id.ToString(), false); result.success = true; user.Password = ""; ClientUserInfo ui=new ClientUserInfo(); ui.Id = user.Id; ui.Stores=new List<IdName>(); List<Department> departments=(from o in db.DepartmentUsers join p in db.Departments.AsNoTracking() on o.DepartmentId equals p.Id where o.UserId == user.Id select p).ToList(); foreach (var dept in departments) { if(dept.DepartmentType=="门店") { ui.Stores.Add(new IdName{Id = dept.Id,Name = dept.Name}); } } ui.Rights=new List<string>(); int[] rights=(from o in db.RoleUsers join p in db.Roles on o.RoleId equals p.Id join q in db.RoleFunctions on p.Id equals q.RoleId where o.UserId == user.Id select q.FunctionId).ToArray(); for (int i = 0; i < rights.Length;i++ ) { if(Function.FunctionInts.ContainsKey(rights[i])) { ui.Rights.Add( Function.FunctionInts[rights[i]]); } } result.obj = ui; } else { result.obj = "登录失败"; } return result; }
public ActionResult ChangePassword(string oldpassword,string password) { int id = BLL.UserInfo.CurUser.Id; if(password.Length==0) { ModelState.AddModelError("password", "密码不能为空"); } using (OUContext db = new OUContext()) { SystemUser user = (from o in db.SystemUsers where o.Id == id select o).First(); if(user.CheckPassword(oldpassword)==true) { user.Password = password; user.Save(db); db.SaveChanges(); return Redirect("ChangePasswordSuccess"); } else { ModelState.AddModelError("oldpassword", "旧密码错误"); } }return View(); }
public ActionResult ChangePassword(string oldpassword, string password) { int id = BLL.UserInfo.CurUser.Id; if (password.Length == 0) { ModelState.AddModelError("password", "password can not be empty"); } using (OUContext db = new OUContext()) { Client s = (from o in db.Clients where o.Id == id select o).First(); if (s.Password==oldpassword) { s.Password = password; db.SaveChanges(); return Redirect("ChangePasswordSuccess"); } else { ModelState.AddModelError("oldpassword", "wrong old password"); } } return View(); }