/// <summary> /// 修改库存量 /// </summary> /// <param name="stock"></param> /// <returns></returns> public ActionResult Edit(EneityFramework.Stock stock) { SysLog log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + "修改了编号为" + stock.StockID + "的库存", FK_TypeID = 23, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "StockID,CommodityStockAmount", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; try { EneityFramework.Stock newStock = db.Stock.Find(stock.StockID); newStock.CommodityStockAmount = stock.CommodityStockAmount; db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "成功修改库存" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 修改Action方法 /// </summary> /// <param name="ai">存储当前要修改的数据</param> /// <returns>返回字符串用来判断执行结果</returns> public ActionResult Edit(AdminInfo admin) { SysLog log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + "修改了" + admin.UserName + "的信息", FK_TypeID = 5, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "UserName", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; try { //更新实体 var data = db.AdminInfo.Find(admin.AdminID); data.UserName = admin.UserName; db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "修改成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 添加新的类别信息 /// </summary> /// <param name="type"></param> /// <returns></returns> public ActionResult AddType(Supermarket.EneityFramework.Type type) { SysLog log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + "添加了新的商品类别" + type.TypeName, FK_TypeID = 9, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "TypeName", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; try { db.Type.Add(type); db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "添加成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult IsActivate() { SysLog log = null; try { var state = Convert.ToInt32(Request["state"]); int TypeID = state == 0 ? 14 : 15; log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + (state == 0 ? "上架" : "下架") + "了商品", FK_TypeID = TypeID, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "ProductID,IsDelete", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; Product pro = db.Product.Find(Convert.ToInt32(Request["ProductID"])); pro.IsDelete = state; db.Entry(pro).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功!" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult CheckLogin(string username, string password, string code) { var Admin = db.AdminInfo.FirstOrDefault(p => p.Account == username); SysLog log = null; if (Admin == null) { log = new SysLog { Behavior = username + "登录系统", FK_TypeID = 1, FK_AdminID = null, Parameters = "UserName,Password", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; } else { log = new SysLog { Behavior = username + "登录系统", FK_TypeID = 1, FK_AdminID = Admin.AdminID, Parameters = "UserName,Password", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; } try { if (string.IsNullOrWhiteSpace(Session["nfine_session_verifycode"].ToString()) || code.ToLower() != Session["nfine_session_verifycode"].ToString()) { throw new Exception("验证码错误"); } var data = db.AdminInfo.FirstOrDefault(model => model.Account == username && model.PassWord == password); if (data == null) { throw new Exception("账号或密码错误"); } Session["Admin"] = data; FormsAuthentication.SetAuthCookie("Admin", false); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "登录成功。" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditPurchases(EneityFramework.Purchases pur) { SysLog log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + "修改了编号为" + pur.PurchasesID + "的入库信息", FK_TypeID = 17, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "PurchasesID,PurchasesTotal,Reamrk", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; try { EneityFramework.Purchases newPur = db.Purchases.Find(pur.PurchasesID); newPur.PurchasesTotal = pur.PurchasesTotal; newPur.Reamrk = pur.Reamrk; db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "编辑成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 编辑出库信息 /// </summary> /// <param name="good"></param> /// <returns></returns> public ActionResult Edit(EneityFramework.ReturnGoods good) { SysLog log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + "修改了编号为" + good.ReturnGoodsID + "的出库信息", FK_TypeID = 20, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "ReturnGoodsID,Remark,ReturnAmount", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; try { EneityFramework.ReturnGoods newGood = db.ReturnGoods.Find(good.ReturnGoodsID); newGood.Remark = good.Remark; newGood.ReturnAmount = good.ReturnAmount; db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "编辑成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
private static void TransferRemainingVendors(SupermarketDbMySQL mySqlDbContext) { using (var sqlDbContext = new SupermarketDB()) { var uploadedVendorsIds = sqlDbContext.Vendors.Select(v => v.ID).ToList(); var vendors = mySqlDbContext.Vendors.Where(v => !uploadedVendorsIds.Contains(v.ID)).ToList(); foreach (var vendor in vendors) { sqlDbContext.Vendors.Add(vendor); } sqlDbContext.SaveChanges(); } }
private static void TransferRemainingMeasures(SupermarketDbMySQL mySqlDbContext) { using (var sqlDbContext = new SupermarketDB()) { var uploadedMeasuresIds = sqlDbContext.Measures.Select(m => m.ID).ToList(); var measures = mySqlDbContext.Measures.Where(m => !uploadedMeasuresIds.Contains(m.ID)).ToList(); foreach (var measure in measures) { sqlDbContext.Measures.Add(measure); } sqlDbContext.SaveChanges(); } }
static void AddSupermarket(string name) { using (var db = new SupermarketDB()) { var count = db.Supermarkets.Where(x => x.StoreName == name).Count(); if (count == 0) { var supermarket = new Supermarket.Models.Supermarket { StoreName = name }; db.Supermarkets.Add(supermarket); db.SaveChanges(); } } }
private static void ProductsTransfer(SupermarketDbMySQL mySqlDbContext) { using (var sqlDbContext = new SupermarketDB()) { var uploadedProductsIds = sqlDbContext.Products.Select(p => p.ID).ToList(); var uploadedVendorsIds = sqlDbContext.Vendors.Select(v => v.ID).ToList(); var uploadedMeasuresIds = sqlDbContext.Measures.Select(m => m.ID).ToList(); var newProducts = mySqlDbContext.Products .Include(x => x.Vendor) .Include(x => x.Measure) .Where(p => !uploadedProductsIds.Contains(p.ID)).ToList(); UploadNewProducts(sqlDbContext, uploadedVendorsIds, uploadedMeasuresIds, newProducts); sqlDbContext.SaveChanges(); } }
static void Main() { MongoClient mongoClient = new MongoClient("mongodb://localhost/"); MongoServer mongoServer = mongoClient.GetServer(); MongoDatabase supermarket = mongoServer.GetDatabase("teamwork-sidecar"); MongoCollection expences = supermarket.GetCollection("expences"); using (var db = new SupermarketDB()) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../../../fileVendors-Expenses.xml"); string salePath = "/sales/sale"; XmlNodeList sales = xmlDoc.SelectNodes(salePath); int count = 1; foreach (XmlElement item in sales) { string name = item.GetAttribute("vendor"); Vendor vendor = db.Vendors.First(x => x.VendorName == name); if (vendor != null) { var expencesss = item.SelectNodes("expenses"); foreach (XmlElement expence in expencesss) { string month = expence.GetAttribute("month"); decimal amount = decimal.Parse(expence.InnerText); var vendorExpence = new VendorExpence(); vendorExpence.VendorId = vendor.ID; vendorExpence.Month = month; vendorExpence.Ammount = amount; db.VendorExpence.Add(vendorExpence); // used for MongoDB vendorExpence.Id = count++; AddExpenceToMongoDB(expences, vendorExpence); } } } db.SaveChanges(); } }
/// <summary> /// 删除会员 /// </summary> /// <param name="UserIDs">会员ID</param> /// <returns></returns> public ActionResult Delete(string[] UserIDs) { SysLog log = new SysLog { Behavior = (Session["Admin"] as AdminInfo).UserName + "删除了" + UserIDs.Length + "个会员", FK_TypeID = 7, FK_AdminID = (Session["Admin"] as AdminInfo).AdminID, Parameters = "UserID", IP = Request.UserHostAddress, CheckInTime = DateTime.Now }; try { for (int i = 0; i < UserIDs.Length; i++) { //找到要删除的对象 User info = db.User.Find(Convert.ToInt32(UserIDs[i])); info.IsDelete = 1; } //更新到数据库 db.SaveChanges(); log.IsException = 0; log.Exception = string.Empty; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.success.ToString(), message = "执行删除操作成功!" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { log.IsException = 1; log.Exception = ex.Message; db.SysLog.Add(log); db.SaveChanges(); return(Json(new AjaxResult { state = ResultType.error.ToString(), message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
static void ExtractFromExcel() { DirectoryInfo root = new DirectoryInfo("../../../../ZippedDailyReports"); if (root.GetDirectories().Length == 0) { string zipPath = "../../../../ZippedDailyReports/Daily-Reports.zip"; string extractPath = "../../../../ZippedDailyReports/Daily-Reports"; ZipFile.ExtractToDirectory(zipPath, extractPath); } DirectoryInfo dir = new DirectoryInfo("../../../../ZippedDailyReports/Daily-Reports"); var directories = dir.GetDirectories(); foreach (var directory in directories) { var date = DateTime.Parse(directory.Name); var files = directory.GetFiles(); foreach (var file in files) { string fileName = file.FullName; DataSet sheet = new DataSet(); OleDbConnectionStringBuilder conString = new OleDbConnectionStringBuilder(); conString.Provider = "Microsoft.ACE.OLEDB.12.0"; conString.DataSource = fileName; conString.Add("Extended Properties", "Excel 12.0 Xml;HDR=YES"); using (var dbCon = new OleDbConnection(conString.ConnectionString)) { dbCon.Open(); string command = "SELECT * FROM [Sales$]"; using (var adapter = new OleDbDataAdapter(command, dbCon)) { adapter.Fill(sheet); } } DataTable table = sheet.Tables[0]; string supermarketName = GetSuperMarketName(table); AddSupermarket(supermarketName); int superMarketId = GetSupermarketId(supermarketName); decimal sum = GetSum(table); List <decimal[]> reportData = GetReportData(table); foreach (var report in reportData) { var productId = (int)report[0]; var quantity = (int)report[1]; var unitPrice = report[2]; var reportSum = report[3]; var salesReport = new SaleByDate { Date = date, Sum = reportSum, SupermarketId = superMarketId, ProductId = productId, Quantity = quantity, UnitPrice = unitPrice }; using (var db = new SupermarketDB()) { db.SalesByDate.Add(salesReport); db.SaveChanges(); } } } } }