Ejemplo n.º 1
0
        public JsonResult editDict(Dictionary dict)
        {
            using (DBContext db = new DBContext())
            {
                Dictionary oldOne = db.Dictionary.Where(q => q.ID.Equals(dict.ID)).FirstOrDefault();

                if (oldOne == null)
                {
                    dict.CreatorID = UserContext.user.ID;
                    dict.Creator = UserContext.user.DisplayName;

                    db.Dictionary.Add(dict);
                }
                else
                {
                    oldOne.SortOrder = dict.SortOrder;
                    oldOne.Name = dict.Name;

                    //只有子项的值可以修改
                    if (!string.IsNullOrEmpty(oldOne.ParentCode))
                    {
                        oldOne.Code = dict.Code;
                    }

                    oldOne.ModifyTime = DateTime.Now;

                    db.Entry(oldOne).State = EntityState.Modified;
                }
                db.SaveChanges();
            }

            return Json(new { code = 1, msg = "保存成功" });
        }
Ejemplo n.º 2
0
        public PartialViewResult ListOfNumber(string ProductName, string StartDate, string EndDate, int pi = 1)
        {
            using (DBContext db = new DBContext())
            {
                var itemQuery = db.OrderItem.AsQueryable();

                var orderQuery = db.Order.AsQueryable();

                orderQuery = GetOrderQuery(orderQuery, StartDate, EndDate);

                if (!string.IsNullOrEmpty(ProductName)) { itemQuery = itemQuery.Where(q => q.ProductName.Equals(ProductName)); }

                ViewBag.list = (from q in itemQuery
                                join o in orderQuery on q.OrderId equals o.ID
                                group q by new { q.ProductName, q.ProductCode } into s
                                select new CXSL() { ProductName = s.Key.ProductName, ProductCode = s.Key.ProductCode, ProductNumber = s.Sum(p => p.RealNumber) }).OrderByDescending(q => q.ProductNumber).Skip((pi - 1) * 10).Take(10).ToList();

                double totalCount = (from q in itemQuery
                                     join o in orderQuery on q.OrderId equals o.ID
                                     group q by new { q.ProductName } into s
                                     select new { s.Key.ProductName }).Count();

                ViewBag.pager = new Pager()
                {
                    _TotalCount = totalCount,
                    _PageIndex = pi
                };

                return PartialView();
            }
        }
Ejemplo n.º 3
0
        public JsonResult editCourier(Courier courier)
        {
            using (DBContext db = new DBContext())
            {
                Courier oldCourier = db.Courier.Where(q => q.ID.Equals(courier.ID)).FirstOrDefault();

                if (oldCourier == null)
                {
                    Guser user = UserContext.user;

                    Store store = UserContext.store;

                    courier.CreatorID = user.ID;
                    courier.Creator = user.DisplayName;
                    courier.StoreId = store.ID;
                    courier.Status = Status.enable;

                    db.Courier.Add(courier);
                }
                else
                {
                    oldCourier.ModifyTime = DateTime.Now;
                    oldCourier.CourierTel = courier.CourierTel;
                    oldCourier.Status = courier.Status;

                    db.Entry(oldCourier).State = EntityState.Modified;
                }
                db.SaveChanges();
            }

            return Json(new { code = 1, msg = "保存成功" });
        }
Ejemplo n.º 4
0
        public JsonResult getArea(string levelType, string pId, string key, int page = 1)
        {
            using (DBContext db = new DBContext())
            {
                var query = db.Area.AsQueryable();

                query = query.Where(q => q.LevelType.Equals(levelType));

                if (!string.IsNullOrEmpty(pId)) { query = query.Where(q => q.ParentId.Equals(pId)); }

                if (!string.IsNullOrEmpty(key)) { query = query.Where(q => q.Name.Contains(key) || q.Pinyin.Contains(key)); }

                ArrayList results = new ArrayList();

                List<Area> list = query.OrderBy(q => q.CityCode).Skip((page - 1) * 10).Take(10).ToList();

                foreach (var item in list)
                {
                    results.Add(new { id = item.ID, name = item.Name, code = item.CityCode });
                }

                int total = query.Count();

                return Json(new { results = results, total = total, pageSize = 10 }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 5
0
        public JsonResult editNumber(StoreProduct product)
        {
            using (DBContext db = new DBContext())
            {
                Store store = UserContext.store;

                //判断是否已存在相同商品
                StoreProduct sameProduct = db.StoreProduct.Where(q => q.ProductID.Equals(product.ProductID) && q.StoreID.Equals(store.ID) && !q.ID.Equals(product.ID)).FirstOrDefault();

                if (sameProduct != null) { return Json(new { code = -1, msg = "已存在相同商品" }); }

                StoreProduct oldOne = db.StoreProduct.Where(q => q.ID.Equals(product.ID)).FirstOrDefault();

                if (oldOne == null)
                {
                    product.ID = StringUtil.UniqueID();
                    product.StoreID = store.ID;

                    db.StoreProduct.Add(product);
                }
                else
                {
                    oldOne.ProductNumber = product.ProductNumber;
                    oldOne.OnlinePrice = product.OnlinePrice;
                    oldOne.OfflinePrice = product.OfflinePrice;

                    db.Entry(oldOne).State = EntityState.Modified;
                }
                db.SaveChanges();
            }

            return Json(new { code = 1, msg = "保存成功" });
        }
Ejemplo n.º 6
0
        public ActionResult Index(string key, int pi = 1)
        {
            using (DBContext db = new DBContext())
            {
                var query = db.Product.AsQueryable();

                if (!string.IsNullOrEmpty(key)) { query = query.Where(q => q.ProductName.Contains(key) || q.ProductCode.Contains(key)); }

                if (UserContext.store == null)
                {
                    //管理员只维护并查看总店的商品
                    query = query.Where(q => q.StoreId == null);
                }
                else
                {
                    //分店可以查看总店在市商品并维护自己添加的商品
                    query = query.Where(q => ((q.StoreId == null && q.Status == Status.enable) || q.StoreId.Equals(UserContext.store.ID)));
                }

                PagedList<Product> cards = query.OrderByDescending(q => q.ModifyTime).ToPagedList(pi, 10);

                if (null == cards)
                    cards = new PagedList<Product>(new List<Product>(), 10, 0);

                if (Request.IsAjaxRequest())
                    return PartialView("List", cards);

                return View(cards);
            }
        }
Ejemplo n.º 7
0
        public PartialViewResult ListOfDetail(string storeId, string StartDate, string EndDate, string storeType, int pi = 1)
        {
            using (DBContext db = new DBContext())
            {
                var orderQuery = db.Order.AsQueryable();

                orderQuery = SetQuery(orderQuery, storeId, StartDate, EndDate);

                var storeQuery = db.Store.AsQueryable();

                if (!string.IsNullOrEmpty(storeType)) { StoreType type = (StoreType)Convert.ToInt16(storeType); storeQuery = storeQuery.Where(q => q.StoreType == type); }

                ViewBag.list = (from q in db.OrderItem
                                join o in orderQuery on q.OrderId equals o.ID
                                join t in storeQuery on o.StoreId equals t.ID
                                group q by new { o.StoreId, o.StoreName, q.ProductName, q.ProductCode } into s
                                orderby new { s.Key.StoreName, s.Key.ProductName }
                                select new PSMX() { StoreName = s.Key.StoreName, ProductName = s.Key.ProductName, ProductCode = s.Key.ProductCode, ProductNumber = s.Sum(p => p.RealNumber) }).Skip((pi - 1) * 10).Take(10).ToList();

                double totalCount = (from q in db.OrderItem
                                     join o in orderQuery on q.OrderId equals o.ID
                                     join t in storeQuery on o.StoreId equals t.ID
                                     group q by new { o.StoreId, o.StoreName, q.ProductName, q.ProductCode } into s
                                     select new { s.Key.StoreId, s.Key.ProductCode }).Count();

                ViewBag.pager = new Pager()
                {
                    _TotalCount = totalCount,
                    _PageIndex = pi
                };

                return PartialView();
            }
        }
Ejemplo n.º 8
0
        public JsonResult editItem(OrderItem item)
        {
            using (DBContext db = new DBContext())
            {
                //判断订单是否存在
                Order order = db.Order.Where(q => q.ID.Equals(item.OrderId)).FirstOrDefault();

                if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); }

                if (order.Status == OrderStatus.Sended) { return Json(new { code = -2, msg = "订单已发货,无法修改" }); }

                if (order.Status == OrderStatus.Reject) { return Json(new { code = -3, msg = "订单已被驳回,无法修改" }); }

                OrderItem oldItem = db.OrderItem.Where(q => q.ID.Equals(item.ID)).FirstOrDefault();

                if (oldItem == null)
                {
                    return Json(new { code = -4, msg = "找不到对应商品" });
                }

                oldItem.Discount = item.Discount;
                oldItem.RealNumber = item.RealNumber;

                db.Entry(oldItem).State = EntityState.Modified;

                db.SaveChanges();
            }

            decimal pay = Order.RefreshPay(item.OrderId);

            return Json(new { code = 1, msg = "保存成功", pay = pay });
        }
Ejemplo n.º 9
0
        public FileResult Export(string OrderCode, string StoreId, string Tel, string StartDate, string EndDate, string Status)
        {
            using (DBContext db = new DBContext())
            {
                var query = db.Order.AsQueryable();

                Store store = UserContext.store;

                StoreId = store == null ? StoreId : store.ID;

                query = SetQuery(query, OrderCode, StoreId, Tel, StartDate, EndDate, Status);

                //获取list数据
                var list = query.OrderByDescending(q => q.SubmitTime).ToList();

                //创建Excel文件的对象
                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                //添加一个sheet
                NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");

                //给sheet1添加第一行的头部标题
                NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
                row1.CreateCell(0).SetCellValue("订单号");
                row1.CreateCell(1).SetCellValue("采购单位");
                row1.CreateCell(2).SetCellValue("负责人");
                row1.CreateCell(3).SetCellValue("联系电话");
                row1.CreateCell(4).SetCellValue("下单时间");
                row1.CreateCell(5).SetCellValue("订单金额");
                row1.CreateCell(6).SetCellValue("订单状态");

                string status = string.Empty;
                //将数据逐步写入sheet1各个行
                for (int i = 0; i < list.Count; i++)
                {
                    switch (list[i].Status)
                    {
                        case OrderStatus.BeforeSend: status = "待发货"; break;
                        case OrderStatus.BeforeSubmit: status = "待提交"; break;
                        case OrderStatus.Reject: status = "驳回"; break;
                        case OrderStatus.Sended: status = "已发货"; break;
                    }

                    NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
                    rowtemp.CreateCell(0).SetCellValue(list[i].OrderCode);
                    rowtemp.CreateCell(1).SetCellValue(list[i].StoreName);
                    rowtemp.CreateCell(2).SetCellValue(list[i].Creator);
                    rowtemp.CreateCell(3).SetCellValue(list[i].Tel);
                    rowtemp.CreateCell(4).SetCellValue(list[i].SubmitTime.ToString());
                    rowtemp.CreateCell(5).SetCellValue(list[i].Paid.ToString());
                    rowtemp.CreateCell(6).SetCellValue(status);
                }

                DateTime now = DateTime.Now;
                // 写入到客户端 
                return ExportExcel(book, now.ToString("yyMMddHHmmssfff"));
            }
        }
Ejemplo n.º 10
0
        public string getMap(string city)
        {
            using (DBContext db = new DBContext())
            {
                var list = db.Store.Where(q => q.City.Equals(city)).ToList();

                return new JavaScriptSerializer().Serialize(list);
            }
        }
Ejemplo n.º 11
0
        public ActionResult getTable()
        {
            using (DBContext db = new DBContext())
            {
                List<GuserRole> roles = db.GuserRole.ToList();

                return PartialView("List", roles);
            }
        }
Ejemplo n.º 12
0
        public FileResult Export(string StoreId, string StartDate, string EndDate, int pi = 1)
        {
            using (DBContext db = new DBContext())
            {
                var storeQuery = db.Store.AsQueryable();

                if (!string.IsNullOrEmpty(StoreId)) { storeQuery = storeQuery.Where(q => q.ID.Equals(StoreId)); }

                var orderQuery = db.AppOrder.AsQueryable();

                DateTime now = DateTime.Now;
                //不选择开始日期默认为本月1号
                DateTime start = string.IsNullOrEmpty(StartDate) ? DateTime.Parse(string.Format("{0}/{1}/{2}", now.Year.ToString(), now.Month.ToString(), "01")) : DateTime.Parse(StartDate);
                DateTime end = string.IsNullOrEmpty(EndDate) ? now : DateTime.Parse(EndDate).AddDays(1);

                if (start > end)
                {
                    DateTime temp = DateTime.MinValue;
                    temp = end;
                    end = start;
                    start = temp;
                }

                orderQuery = orderQuery.Where(q => q.CreateTime.CompareTo(start) > 0 && q.CreateTime.CompareTo(end) < 0 && q.Status == 5);

                var list = (from q in storeQuery
                            join o in orderQuery on q.ID equals o.StoreId into o_join
                            from os in o_join.DefaultIfEmpty()
                            group new { q.StoreName, os.Payable } by new { q.StoreName } into s
                            select new PSJE() { StoreName = s.Key.StoreName, Pay = s.Sum(p => p.Payable == null ? 0 : p.Payable) }).OrderByDescending(q => q.Pay).ToList();

                //创建Excel文件的对象
                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                //添加一个sheet
                NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");

                //给sheet1添加第一行的头部标题
                NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
                row1.CreateCell(0).SetCellValue("采购单位");
                row1.CreateCell(1).SetCellValue("销售额");

                string status = string.Empty;
                //将数据逐步写入sheet1各个行
                for (int i = 0; i < list.Count; i++)
                {
                    NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
                    rowtemp.CreateCell(0).SetCellValue(list[i].StoreName);
                    rowtemp.CreateCell(1).SetCellValue(list[i].Pay.ToString());
                }

                // 写入到客户端 
                return ExportExcel(book, now.ToString("yyMMddHHmmssfff"));
            }
        }
Ejemplo n.º 13
0
        public ActionResult Index()
        {
            HttpRequest request = System.Web.HttpContext.Current.Request;
            HttpCookie cookie = request.Cookies["session-cookie-name"];

            if (cookie == null) { return View(); }

            string cookieAccountId = cookie["cookie-account-id-key"];

            if (string.IsNullOrEmpty(cookieAccountId))
            {
                cookie.Expires = DateTime.Now.AddDays(-1);
                System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

                return View();
            }

            using (var db = new DBContext())
            {
                Guser user = db.Guser.Include("Role").Where(q => q.ID.Equals(cookieAccountId)).FirstOrDefault();

                if (user == null || user.Status == Status.disable || Convert.ToInt32(user.Role.RoleVal) == 0)
                {
                    cookie.Expires = DateTime.Now.AddDays(-1);
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

                    return View();
                }

                UserContext.user = user;

                List<Store> stores = db.Store.Where(q => q.UserId.Equals(user.ID)).OrderBy(q => q.StoreCode).ToList();

                if (stores.Count > 0)
                {
                    Store selectStore = stores[0];

                    UserContext.store = selectStore;

                    stores.RemoveAt(0);

                    UserContext.stores = stores;
                }

                List<Menu> menus = XmlHelper.XmlDeserializeFromFile<List<Menu>>(Server.MapPath("~/route.config"), Encoding.UTF8);

                MenuContext.menus = menus;

                string url = GetFirstMenu(menus, Convert.ToInt32(user.Role.RoleVal));

                return RedirectToAction("Index", url);
            }
        }
Ejemplo n.º 14
0
        public PartialViewResult List(string Province, string City, string Country, string StoreId, string StartDate, string EndDate, int pi = 1)
        {
            using (DBContext db = new DBContext())
            {
                var storeQuery = db.Store.AsQueryable();

                if (!string.IsNullOrEmpty(Province)) { storeQuery = storeQuery.Where(q => q.Province.Equals(Province)); }

                if (!string.IsNullOrEmpty(City)) { storeQuery = storeQuery.Where(q => q.City.Equals(City)); }

                if (!string.IsNullOrEmpty(Country)) { storeQuery = storeQuery.Where(q => q.Country.Equals(Country)); }

                if (!string.IsNullOrEmpty(StoreId)) { storeQuery = storeQuery.Where(q => q.ID.Equals(StoreId)); }

                var offQuery = db.OfflineSell.AsQueryable();

                var olQuery = db.AppOrder.AsQueryable();

                DateTime now = DateTime.Now;
                //不选择开始日期默认为本月1号
                DateTime start = string.IsNullOrEmpty(StartDate) ? DateTime.Parse(string.Format("{0}/{1}/{2}", now.Year.ToString(), now.Month.ToString(), "01")) : DateTime.Parse(StartDate);
                DateTime end = string.IsNullOrEmpty(EndDate) ? now : DateTime.Parse(EndDate).AddDays(1);

                if (start > end)
                {
                    DateTime temp = DateTime.MinValue;
                    temp = end;
                    end = start;
                    start = temp;
                }

                offQuery = offQuery.Where(q => q.XFRQ.CompareTo(start) > 0 && q.XFRQ.CompareTo(end) < 0 && q.bFinish == Finish.YJS);

                olQuery = olQuery.Where(q => q.CreateTime.CompareTo(start) > 0 && q.CreateTime.CompareTo(end) < 0 && q.Status == 5);

                ViewBag.list = (from q in storeQuery
                                join off in offQuery on q.ID equals off.StationID into off_join
                                from o in off_join.DefaultIfEmpty()
                                join ol in olQuery on q.ID equals ol.StoreId into ol_join
                                from l in ol_join.DefaultIfEmpty()
                                group new { q.StoreName, o.JE, l.Payable } by new { q.StoreName } into s
                                select new PSJE() { StoreName = s.Key.StoreName, Pay = s.Sum(p => (p.JE == null ? 0 : p.JE) + (p.Payable == null ? 0 : p.Payable)) }).OrderByDescending(q => q.Pay).Skip((pi - 1) * 10).Take(10).ToList();

                ViewBag.pager = new Pager()
                {
                    _TotalCount = storeQuery.Count(),
                    _PageIndex = pi
                };
            }

            return PartialView();
        }
Ejemplo n.º 15
0
        public JsonResult signIn(string account, string pwd, string remeberMe)
        {
            string returnUrl = string.Empty;

            using (var db = new DBContext())
            {
                string _pass = StringUtil.Md5Encrypt(pwd);

                Guser user = db.Guser.Include("Role").Where(q => q.Account.Equals(account) && q.PassWord.Equals(_pass)).FirstOrDefault();

                if (user == null) { return Json(new { code = -1, msg = "用户名或密码错误" }); }

                if (user.Status == Status.disable) { return Json(new { code = -2, msg = "此用户已禁用,请联系管理员" }); }

                int roleVal = Convert.ToInt32(user.Role.RoleVal);

                if (roleVal == 0) { return Json(new { code = -3, msg = "此用户角色未分配权限,请联系管理员" }); }

                UserContext.user = user;

                List<Store> stores = db.Store.Where(q => q.UserId.Equals(user.ID)).OrderBy(q => q.StoreCode).ToList();

                if (stores.Count > 0)
                {
                    Store selectStore = stores[0];

                    UserContext.store = selectStore;

                    stores.RemoveAt(0);

                    UserContext.stores = stores;
                }

                List<Menu> menus = XmlHelper.XmlDeserializeFromFile<List<Menu>>(Server.MapPath("~/route.config"), Encoding.UTF8);

                MenuContext.menus = menus;

                //暂时设置为自动保存自动登录
                remeberMe = "";
                if (!string.IsNullOrEmpty(remeberMe))
                {
                    HttpCookie cookie = new HttpCookie("session-cookie-name");
                    cookie["cookie-account-id-key"] = UserContext.user.ID;
                    cookie.Expires = DateTime.Now.AddDays(7);
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
                }

                returnUrl = GetFirstMenu(menus, roleVal);
            }

            return Json(new { code = 1, msg = "登录成功", url = returnUrl });
        }
Ejemplo n.º 16
0
        public object queryViewDialog(string productId)
        {
            using (DBContext db = new DBContext())
            {
                Product product = db.Product.Where(q => q.ID.Equals(productId)).FirstOrDefault();

                if (product == null) { return Json(new { code = -1, msg = "找不到指定商品" }); }

                ViewBag.product = product;

                return PartialView("View");
            }
        }
Ejemplo n.º 17
0
        public JsonResult editItem(OrderItem item)
        {
            using (DBContext db = new DBContext())
            {
                //判断订单是否存在
                Order order = db.Order.Where(q => q.ID.Equals(item.OrderId)).FirstOrDefault();

                if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); }

                if (order.Status > OrderStatus.BeforeSubmit && UserContext.store != null) { return Json(new { code = -2, msg = "您没有权限修改已提交过的订单" }); }

                if (order.Status == OrderStatus.Sended) { return Json(new { code = -3, msg = "订单已发货,无法修改" }); }

                if (order.Status == OrderStatus.Reject) { return Json(new { code = -4, msg = "订单已被驳回,无法修改" }); }

                //判断订单中是否已有此样商品
                OrderItem sameItem = db.OrderItem.Where(q => q.OrderId.Equals(item.OrderId) && q.ProductId.Equals(item.ProductId) && !q.ID.Equals(item.ID)).FirstOrDefault();

                if (sameItem != null) { return Json(new { code = -5, msg = "订单中已有相同商品" }); }

                OrderItem oldItem = db.OrderItem.Where(q => q.ID.Equals(item.ID)).FirstOrDefault();

                if (oldItem == null)
                {
                    Product product = db.Product.Where(q => q.ID.Equals(item.ProductId)).FirstOrDefault();

                    if (product == null) { return Json(new { code = -6, msg = "抱歉,找不到对应商品" }); }

                    item.ID = StringUtil.UniqueID();
                    item.ProductCode = product.ProductCode;
                    item.ProductName = product.ProductName;
                    item.Price = product.Price;
                    item.RealNumber = item.OrderNumber;

                    db.OrderItem.Add(item);
                }
                else
                {
                    oldItem.OrderNumber = item.OrderNumber;
                    oldItem.RealNumber = item.OrderNumber;

                    db.Entry(oldItem).State = EntityState.Modified;
                }

                db.SaveChanges();
            }

            Order.RefreshPay(item.OrderId);

            return Json(new { code = 1, msg = "保存成功" });
        }
Ejemplo n.º 18
0
        public JsonResult editStore(Store store)
        {
            using (DBContext db = new DBContext())
            {
                //判断店名是否重复
                Store sameName = db.Store.Where(q => q.StoreName.Equals(store.StoreName) && !q.ID.Equals(store.ID)).FirstOrDefault();

                if (sameName != null) { return Json(new { code = -1, msg = "门店名称已被注册" }); }

                Store oldStore = db.Store.Where(q => q.ID.Equals(store.ID)).FirstOrDefault();

                if (oldStore == null)
                {
                    //生成流水号
                    int code = db.Store.Count() == 0 ? 80000 : Convert.ToInt32(db.Store.Max(q => q.StoreCode)) + 1;

                    store.StoreCode = code.ToString();
                    store.CreatorID = UserContext.user.ID;
                    store.Creator = UserContext.user.DisplayName;
                    store.Name = store.StoreName;
                    store.Status = Status.enable;

                    db.Store.Add(store);
                }
                else
                {
                    oldStore.ModifyTime = DateTime.Now;
                    oldStore.Name = store.StoreName;
                    oldStore.UserId = store.UserId;
                    oldStore.Address = store.Address;
                    oldStore.Lng = store.Lng;
                    oldStore.Lat = store.Lat;
                    oldStore.Presider = store.Presider;
                    oldStore.Tel = store.Tel;
                    oldStore.StoreType = store.StoreType;
                    oldStore.Discount = store.Discount;
                    oldStore.Alipay = store.Alipay;
                    oldStore.WeiXin = store.WeiXin;
                    oldStore.Bank = store.Bank;
                    oldStore.BankName = store.BankName;
                    oldStore.BankAccount = store.BankAccount;
                    oldStore.Status = store.Status;

                    db.Entry(oldStore).State = EntityState.Modified;
                }
                db.SaveChanges();
            }

            return Json(new { code = 1, msg = "保存成功" });
        }
Ejemplo n.º 19
0
        public ActionResult Index(string OrderCode, string StoreId, string Tel, string StartDate, string EndDate, int pi = 1)
        {
            using (DBContext db = new DBContext())
            {
                var query = db.Order.AsQueryable();

                if (!string.IsNullOrEmpty(OrderCode)) { query = query.Where(q => q.OrderCode.Contains(OrderCode)); }

                if (!string.IsNullOrEmpty(Tel)) { query = query.Where(q => q.Tel.Contains(Tel)); }

                DateTime now = DateTime.Now;
                //不选择开始日期默认为本月1号
                DateTime start = string.IsNullOrEmpty(StartDate) ? DateTime.Parse(string.Format("{0}/{1}/{2}", now.Year.ToString(), now.Month.ToString(), "01")) : DateTime.Parse(StartDate);
                DateTime end = string.IsNullOrEmpty(EndDate) ? now : DateTime.Parse(EndDate);

                if (start > end)
                {
                    DateTime temp = DateTime.MinValue;
                    temp = end;
                    end = start;
                    start = temp;
                }

                //只显示代发货的订单
                query = query.Where(q => q.SubmitTime.CompareTo(start) > 0 && q.SubmitTime.CompareTo(end) < 0 && q.Status == OrderStatus.BeforeSend);

                Store store = UserContext.store;

                if (store == null)
                {
                    query = query.Where(q => q.Status != 0);

                    if (!string.IsNullOrEmpty(StoreId)) { query = query.Where(q => q.StoreId.Contains(StoreId)); }
                }
                else
                {
                    query = query.Where(q => q.StoreId.Equals(store.ID));
                }

                PagedList<Order> cards = query.OrderByDescending(q => q.ModifyTime).ToPagedList(pi, 10);

                if (null == cards)
                    cards = new PagedList<Order>(new List<Order>(), 10, 0);

                if (Request.IsAjaxRequest())
                    return PartialView("List", cards);

                return View(cards);
            }
        }
Ejemplo n.º 20
0
        public JsonResult editProduct(Product product)
        {
            using (DBContext db = new DBContext())
            {
                //判断编号是否重复
                Product sameCode = db.Product.Where(q => q.ProductCode.Equals(product.ProductCode) && !q.ID.Equals(product.ID)).FirstOrDefault();

                if (sameCode != null) { return Json(new { code = -1, msg = "商品编号已被注册" }); }

                Product oldProduct = db.Product.Where(q => q.ID.Equals(product.ID)).FirstOrDefault();

                if (oldProduct == null)
                {
                    product.CreatorID = UserContext.user.ID;
                    product.Creator = UserContext.user.DisplayName;
                    product.Name = product.ProductName;
                    product.Status = Status.enable;
                    product.StoreId = UserContext.store.ID;

                    db.Product.Add(product);
                }
                else
                {
                    if (UserContext.store != null && UserContext.store.ID != oldProduct.StoreId) { return Json(new { code = -2, msg = "抱歉,您没有权限修改本商品" }); }

                    if (!string.IsNullOrEmpty(oldProduct.DocId) && !oldProduct.DocId.Equals(product.DocId))
                    {
                        string basePath = string.Format(@"{0}Upload\", Server.MapPath("/"));

                        Doc.delete(oldProduct.DocId, basePath);
                    }

                    oldProduct.ModifyTime = DateTime.Now;
                    oldProduct.ProductCode = product.ProductCode;
                    oldProduct.Name = product.ProductName;
                    oldProduct.ProductType = product.ProductType;
                    oldProduct.Price = product.Price;
                    oldProduct.AllowReturn = product.AllowReturn;
                    oldProduct.Remark = product.Remark;
                    oldProduct.DocId = product.DocId;
                    oldProduct.Status = product.Status;

                    db.Entry(oldProduct).State = EntityState.Modified;
                }
                db.SaveChanges();
            }

            return Json(new { code = 1, msg = "保存成功" });
        }
Ejemplo n.º 21
0
        public static void delete(string id, string basePath)
        {
            using (DBContext db = new DBContext())
            {
                Doc doc = db.Doc.Where(q => q.ID.Equals(id)).FirstOrDefault();

                if (doc == null) { return; }

                DirectoryInfo dir = new DirectoryInfo(string.Format("{0}{1}", basePath, doc.DirPath));
                dir.Delete(true);

                db.Doc.Remove(doc);
                db.SaveChanges();
            }
        }
Ejemplo n.º 22
0
        public FileResult ExportDetail(string storeId, string StartDate, string EndDate, string storeType)
        {
            using (DBContext db = new DBContext())
            {
                var orderQuery = db.Order.AsQueryable();

                orderQuery = SetQuery(orderQuery, storeId, StartDate, EndDate);

                var storeQuery = db.Store.AsQueryable();

                if (!string.IsNullOrEmpty(storeType)) { StoreType type = (StoreType)Convert.ToInt16(storeType); storeQuery = storeQuery.Where(q => q.StoreType == type); }

                var list = (from q in db.OrderItem
                            join o in orderQuery on q.OrderId equals o.ID
                            join t in storeQuery on o.StoreId equals t.ID
                            group q by new { o.StoreId, o.StoreName, q.ProductName, q.ProductCode } into s
                            orderby new { s.Key.StoreName, s.Key.ProductName }
                            select new PSMX() { StoreName = s.Key.StoreName, ProductName = s.Key.ProductName, ProductCode = s.Key.ProductCode, ProductNumber = s.Sum(p => p.RealNumber) }).ToList();

                //创建Excel文件的对象
                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                //添加一个sheet
                NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");

                //给sheet1添加第一行的头部标题
                NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
                row1.CreateCell(0).SetCellValue("分店");
                row1.CreateCell(1).SetCellValue("商品名称");
                row1.CreateCell(2).SetCellValue("商品编号");
                row1.CreateCell(3).SetCellValue("采购总数");

                string status = string.Empty;
                //将数据逐步写入sheet1各个行
                for (int i = 0; i < list.Count; i++)
                {
                    NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
                    rowtemp.CreateCell(0).SetCellValue(list[i].StoreName);
                    rowtemp.CreateCell(1).SetCellValue(list[i].ProductName);
                    rowtemp.CreateCell(2).SetCellValue(list[i].ProductCode);
                    rowtemp.CreateCell(3).SetCellValue(list[i].ProductNumber);
                }

                DateTime now = DateTime.Now;
                // 写入到客户端 
                return ExportExcel(book, now.ToString("yyMMddHHmmssfff"));
            }
        }
Ejemplo n.º 23
0
        public JsonResult delOrder(string orderId)
        {
            using (DBContext db = new DBContext())
            {
                Order order = db.Order.Where(q => q.ID.Equals(orderId)).FirstOrDefault();

                if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); }

                db.OrderItem.RemoveRange(db.OrderItem.Where(q => q.OrderId.Equals(orderId)));

                db.Order.Remove(order);

                db.SaveChanges();

                return Json(new { code = 1, msg = "删除成功" });
            }
        }
Ejemplo n.º 24
0
        public JsonResult queryTree(string roleId)
        {
            ArrayList zNodes = new ArrayList();

            GuserRole role = null;

            if (!string.IsNullOrEmpty(roleId))
            {
                DBContext db = new DBContext();

                role = db.GuserRole.Where(q => q.ID.Equals(roleId)).FirstOrDefault();
            }

            addNodes(zNodes, MenuContext.menus, "0", role);

            return Json(new { code = 1, tree = new JavaScriptSerializer().Serialize(zNodes) });
        }
Ejemplo n.º 25
0
        public object queryDialog(string id)
        {
            using (DBContext db = new DBContext())
            {
                if (!string.IsNullOrEmpty(id))
                {
                    StoreProduct product = db.StoreProduct.Include("Product").Where(q => q.ID.Equals(id)).FirstOrDefault();

                    if (product == null) { return Json(new { code = -1, msg = "找不到指定商品" }); }

                    ViewBag.product = product;

                    return PartialView("Edit");
                }

                return PartialView("Add");
            }
        }
Ejemplo n.º 26
0
        public object queryDialog(string id)
        {
            using (DBContext db = new DBContext())
            {
                if (!string.IsNullOrEmpty(id))
                {
                    Dictionary dict = db.Dictionary.Where(q => q.ID.Equals(id)).FirstOrDefault();

                    if (dict == null) { return Json(new { code = -1, msg = "找不到指定参数" }); }

                    ViewBag.dict = dict;

                    return PartialView("Edit");
                }

                return PartialView("Add");
            }
        }
Ejemplo n.º 27
0
        public object queryDialog(string roleId)
        {
            using (DBContext db = new DBContext())
            {
                if (!string.IsNullOrEmpty(roleId))
                {
                    GuserRole role = db.GuserRole.Where(q => q.ID.Equals(roleId)).FirstOrDefault();

                    if (role == null) { return Json(new { code = -1, msg = "找不到指定角色" }); }

                    ViewBag.role = role;

                    return PartialView("Edit");
                }

                return PartialView("Add");
            }
        }
Ejemplo n.º 28
0
        public object queryDialog(string courierId)
        {
            using (DBContext db = new DBContext())
            {
                if (!string.IsNullOrEmpty(courierId))
                {
                    Courier courier = db.Courier.Include("Store").Where(q => q.ID.Equals(courierId)).FirstOrDefault();

                    if (courier == null) { return Json(new { code = -1, msg = "找不到指定送餐员" }); }

                    ViewBag.courier = courier;

                    return PartialView("Edit");
                }

                return PartialView("Add");
            }
        }
Ejemplo n.º 29
0
        public static decimal RefreshPay(string id)
        {
            using (DBContext db = new DBContext())
            {
                Order order = db.Order.Where(q => q.ID.Equals(id)).FirstOrDefault();

                decimal pay = db.OrderItem.Where(q => q.OrderId.Equals(id)).Sum(q => q.Price * q.RealNumber * q.Discount);

                order.Payable = pay;
                order.Paid = pay;

                db.Entry(order).State = EntityState.Modified;

                db.SaveChanges();

                return pay;
            }
        }
Ejemplo n.º 30
0
        public JsonResult checkOrder(string orderId, string checkremark)
        {
            using (DBContext db = new DBContext())
            {
                Order order = db.Order.Where(q => q.ID.Equals(orderId)).FirstOrDefault();

                if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); }

                if (order.Status != OrderStatus.Sended) { return Json(new { code = -2, msg = "非已发货状态的订单不能驳回" }); }

                order.ModifyTime = DateTime.Now;
                order.RejectReason = checkremark;
                order.Status = OrderStatus.Checked;

                db.SaveChanges();
            }

            return Json(new { code = 1, msg = "对账成功" });
        }