Exemple #1
0
        public ActionResult BuyOrderDetail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的验货单编号"));
            }

            int oId = 0;
            int.TryParse(id,out oId);
            string uid = HttpContext.User.Identity.Name;
            BBuyOrder order = null;
            if (oId <= 0)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的验货单编号"));
            }
            try
            {
                UserManager userMgr = new UserManager(int.Parse(uid), null);
                BUser user = userMgr.CurrentUser;
                BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
                order = buyManager.GetBuyOrderFullInfo(oId);
            }
            catch (KMJXCException kex)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message));
            }
            catch
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误"));
            }
            return View(order);
        }
Exemple #2
0
        public ActionResult EnterDetail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的入库单编号"));
            }

            int eId = 0;
            int.TryParse(id,out eId);

            if (eId <= 0)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的入库单编号"));
            }
            string uid = HttpContext.User.Identity.Name;
            BEnterStock stock = null;
            UserManager userMgr = new UserManager(int.Parse(uid), null);
            BUser user = userMgr.CurrentUser;
            try
            {
                StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
                stock = stockManager.GetEnterStockFullInfo(eId);
            }
            catch (KMJXCException kex)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message));
            }
            catch
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误"));
            }
            return View(stock);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            string user_id = filterContext.HttpContext.User.Identity.Name;
            if (string.IsNullOrEmpty(user_id)) {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=登录信息过期,请重新登录");
            }
            //Verify if the cookie user is a valid user
            UserManager userMgr = new UserManager(int.Parse(user_id),null);
            BUser user = userMgr.CurrentUser;

            if (user == null)
            {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=登录信息丢失,请重新登录并授权");
            }

            //Verify if logon user already has access token in db
            KuanMaiEntities db = new KuanMaiEntities();

            Access_Token token = (from t in db.Access_Token where t.User_ID == user.ID && t.Mall_Type_ID == user.Type.ID select t).FirstOrDefault<Access_Token>();

            if (token == null) {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=没有授权信息,请登录并授权");
            }

            //Verify if the existed access token is expired
            long timeNow = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
            if (timeNow >= token.Request_Time + token.Expirse_In)
            {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=授权信息已经过期,请重新登录并授权");
            }
        }
        public ApiMessage GetAdminActions()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            List<BAdminCategoryAction> actions = new List<BAdminCategoryAction>();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            PermissionManagement permissionMgt = new PermissionManagement(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int role_id = 0;
            int.TryParse(request["role"],out role_id);
            try
            {
                actions = permissionMgt.GetActionsByCategory(role_id);
                message.Item = actions;
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch
            {
            }
            finally
            {

            }
            return message;
        }
Exemple #5
0
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return Redirect("/Home/Error?message="+HttpUtility.UrlEncode("请输入正确的产品ID"));
            }

            int product_id = 0;
            int.TryParse(id, out product_id);
            if (product_id == 0)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的产品ID"));
            }
            BProduct product = null;
            string user_id = HttpContext.User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            Shop MainShop = userMgr.Main_Shop;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                product = pdtManager.GetProductFullInfo(product_id);
            }
            catch (KMJXCException kex)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message));
            }
            catch
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误"));
            }
            return View(product);
        }
Exemple #6
0
 public ActionResult Dashboard()
 {
     string user_id = HttpContext.User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     ShopManager shopManager = new ShopManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission, userMgr);
     BShopStatistic statistic = shopManager.GetShopStatistic(0, true);
     return View(statistic);
 }
Exemple #7
0
 public ActionResult New()
 {
     string user_id = HttpContext.User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     Shop MainShop = userMgr.Main_Shop;
     ShopCategoryManager cateMgr = new ShopCategoryManager(userMgr.CurrentUser, MainShop, userMgr.CurrentUserPermission);
     List<BCategory> categories = cateMgr.GetCategories(0);
     ViewData["category"] = categories;
     return View();
 }
Exemple #8
0
        public ActionResult Child()
        {
            string user_id = HttpContext.User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ShopManager shopManager = new ShopManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission, userMgr);

            List<Mall_Type> mtypes = shopManager.GetMallTypes();
            ViewData["t"] = "";
            return View(mtypes);
        }
Exemple #9
0
        public BSyncTime GetLastSyncTime()
        {
            BSyncTime time = new BSyncTime();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            SalesManager saleManager = new SalesManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);

            time = saleManager.GetSyncTime();
            return time;
        }
Exemple #10
0
        public ApiMessage CreateExpressFees()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ShopManager shopManager = new ShopManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission, userMgr);

            string jsonStr = request["express"];

            jsonStr = HttpUtility.UrlDecode(jsonStr);

            JObject json = JObject.Parse(jsonStr);
            int express_id = (int)json["id"];
            BShopExpress express = new BShopExpress() { ID = express_id };
            express.IsDefault = false;
            JArray fees = (JArray)json["fees"];
            if (fees.Count > 0)
            {
                express.Fees = new List<BExpressFee>();
            }

            for (int i = 0; i < fees.Count; i++)
            {
                JObject o = (JObject)fees[i];
                int pid = (int)o["pid"];
                int cid = (int)o["cid"];
                double fee = (double)o["fee"];
                int hid = (int)o["hid"];
                BExpressFee feeObj = new BExpressFee() { Fee = fee, Province = new BArea() { ID = pid }, City = new BArea() { ID = cid }, StoreHouse = new BStoreHouse { ID = hid } };
                express.Fees.Add(feeObj);
            }

            try
            {
                shopManager.CreateExpressFees(express);
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }

            return message;
        }
Exemple #11
0
        public JsonResult Delete()
        {
            JsonResult res = new JsonResult();
            ApiMessage message = new ApiMessage() { Status = "ok" };
            string user = HttpContext.User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user), null);
            ImageManager imgMgr = new ImageManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            res.Data = message;
            int imgId = 0;
            int.TryParse(Request["image_id"], out imgId);

            try
            {
                KM.JXC.DBA.Image image = null;
                if (!imgMgr.DeleteImage(imgId, out image))
                {
                    message.Status = "failed";
                }
                else
                {
                    //Delete image from disk
                    string rootPath = Request.PhysicalApplicationPath;
                    string filePath = rootPath + image.Path;
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                        message.Status = "ok";
                    }
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }
            finally
            {
            }

            return res;
        }
Exemple #12
0
        public PQGridData GetUsers()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);

            int page = 1;
            int pageSize = 30;
            int total = 0;

            int.TryParse(request["page"],out page);
            int.TryParse(request["pageSize"],out pageSize);
            data.data = userMgr.GetUsers(page, pageSize, out total);
            data.totalRecords = total;
            return data;
        }
Exemple #13
0
        public ApiMessage AddNewPropValue()
        {
            ApiMessage message = new ApiMessage();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            Shop MainShop = userMgr.Main_Shop;
            ShopCategoryManager cateMgr = new ShopCategoryManager(userMgr.CurrentUser, MainShop, userMgr.CurrentUserPermission);
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string propId = request["prop_id"];
            string propValues = request["prop_values"];
            if (!string.IsNullOrEmpty(propValues))
            {
                string[] values = propValues.Split(',');
                List<string> vs = new List<string>();

                if (values != null && values.Length > 0)
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        vs.Add(values[i]);
                    }
                }

                try
                {
                    if (cateMgr.AddNewPropValue(int.Parse(propId), vs))
                    {
                        message.Status = "ok";
                    }
                    else
                    {
                        message.Status = "failed";
                    }
                }
                catch (KM.JXC.Common.KMException.KMJXCException ex)
                {
                    message.Status = "failed";
                    message.Message = ex.Message;
                }
            }
            return message;
        }
Exemple #14
0
        public ApiMessage AddChildShop()
        {
            ApiMessage message = new ApiMessage() { Status="ok"};
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ShopManager shopManager = new ShopManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission, userMgr);
            string child_shop = request["shop_name"];
            int mtype = 0;
            int.TryParse(request["type"],out mtype);

            try
            {
                if (shopManager.AddChildShop(mtype, child_shop))
                {
                    message.Status = "failed";
                    message.Message = "添加失败";
                }
                else
                {
                    message.Message = "添加子店铺请求已经发出,等待子店铺主账户登录进销存批准请求";
                }
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch
            {
                message.Status = "failed";
                message.Message = "未知错误,请联系管理员";
            }
            finally
            {

            }
            return message;
        }
Exemple #15
0
        public ApiMessage CreateRole()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            List<BAdminRole> roles = new List<BAdminRole>();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            PermissionManagement permissionMgt = new PermissionManagement(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            string role_name = request["role"];
            string desc=request["desc"];
            int shop_id = 0;
            int.TryParse(request["shop_id"],out shop_id);
            try
            {
                int[] actions = this.ConvertToIntArrar(request["actions"]);
                if (string.IsNullOrEmpty(role_name))
                {
                    message.Status = "failed";
                    message.Message = "分组名字不能为空";
                    return message;
                }
                BAdminRole role=permissionMgt.CreateRole(role_name, desc,actions, shop_id);
                message.Item = role;

            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch
            {
            }
            finally
            {

            }
            return message;
        }
Exemple #16
0
        public ApiMessage BatchEditCategory()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            ApiMessage message = new ApiMessage();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            string products=request["products"];
            if (string.IsNullOrEmpty(products))
            {
                message.Status = "failed";
                message.Message = "没有选择产品,不能批量编辑类目";
                return message;
            }

            int[] product_ids = base.ConvertToIntArrar(products);
            int category = 0;
            int.TryParse(request["category"],out category);
            try
            {
                bool ret = pdtManager.BatchUpdateCategory(category, product_ids);
                if (ret)
                {
                    message.Status = "ok";
                }
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }
            return message;
        }
Exemple #17
0
        public ApiMessage CreateStoreHouse()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);

            try
            {
                BStoreHouse house = new BStoreHouse();
                house.Name=request["name"];
                house.Address=request["address"];
                house.Phone=request["phone"];
                house.IsDefault = false;
                if (!string.IsNullOrEmpty(request["isdefault"]))
                {
                    if (request["isdefault"] == "1")
                    {
                        house.IsDefault = true;
                    }
                }
                stockManager.CreateStoreHouse(house);
                message.Status = "ok";
                message.Message = "创建成功";
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }
            return message;
        }
Exemple #18
0
 public ApiMessage CreateLeaveStockForMallTrade()
 {
     ApiMessage message = new ApiMessage() { Status = "ok", Message = "更新成功" };
     HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
     HttpRequestBase request = context.Request;
     string user_id = User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
     string mall_product=request["mall_item_id"];
     string mall_sku=request["mall_sku_id"];
     int product = 0;
     int parent_product = 0;
     string trade_id=request["trade_id"];
     string order_id = request["order_id"];
     int.TryParse(request["product"], out parent_product);
     int.TryParse(request["product_prop"], out product);
     bool map = false;
     try
     {
         if (!string.IsNullOrEmpty(request["connect"]) && request["connect"].Trim() == "1")
         {
             map = true;
         }
         else
         {
             map = false;
         }
         stockManager.CreateLeaveStockForMallTrade(trade_id, order_id, mall_product, mall_sku, parent_product, product, map);
     }
     catch (KMJXCException kex)
     {
         message.Status = "failed";
         message.Message = kex.Message;
     }
     catch
     {
     }
     return message;
 }
Exemple #19
0
        public ApiMessage Add()
        {
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            Shop cShop = userMgr.Shop;
            ShopCategoryManager cateMgr = new ShopCategoryManager(userMgr.CurrentUser, cShop, userMgr.CurrentUserPermission);

            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            ApiMessage message = new ApiMessage();
            try
            {
                BCategory cate = new BCategory();
                cate.Name = request["name"].ToString();
                cate.ID = 0;
                cate.Mall_ID = "";
                cate.Mall_PID = "";
                cate.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                cate.Parent = new BCategory() { ID = int.Parse(request["parent_id"].ToString()) };
                cateMgr.CreateCategory(cate);
                message.Status = "ok";
                message.Message = "分类创建成功";
                message.Item = cate;
            }
            catch (KM.JXC.Common.KMException.KMJXCException ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "分类创建失败";
            }

            return message;
        }
Exemple #20
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            string user_id = filterContext.HttpContext.User.Identity.Name;
            if (string.IsNullOrEmpty(user_id))
            {
                return;
            }
            //Verify if the cookie user is a valid user
            UserManagement userManagement = new UserManagement();
            BUser loginuser = userManagement.GetUserInfo(int.Parse(user_id));
            if (loginuser == null)
            {
                return;
            }

            if (!loginuser.IsSystemUser)
            {
                //normal user login
                UserManager userMgr = new UserManager(int.Parse(user_id), null);
                BUser user = userMgr.CurrentUser;
                ShopManager shopManager = new ShopManager(user, userMgr.Shop, userMgr.CurrentUserPermission, userMgr);
                filterContext.Controller.ViewData["CurrentShop"] = userMgr.Shop;
                filterContext.Controller.ViewData["MainShop"] = userMgr.Main_Shop;
                filterContext.Controller.ViewData["ChildShop"] = userMgr.ChildShops;
                filterContext.Controller.ViewData["CurrentPermission"] = userMgr.CurrentUserPermission;
                filterContext.Controller.ViewData["CurrentUser"] = userMgr.CurrentUser;
                filterContext.Controller.ViewData["SPStatistic"] = shopManager.GetShopStatistic(0, true);
            }
            else
            {
                //system user login
                //filterContext.HttpContext.Response.Redirect("/Admin/Index");
                filterContext.Controller.ViewData["CurrentUser"] = loginuser;
            }
        }
Exemple #21
0
        public JsonResult Upload()
        {
            JsonResult res = new JsonResult();
            ApiMessage message = new ApiMessage() { Status = "ok" };
            int len = Request.Files["Filedata"].ContentLength;
            string name = Request.Files["Filedata"].FileName;
            string uid = Request["authid"];
            int user_id = 0;
            int.TryParse(uid,out user_id);

            //if (user_id <= 0) {
            //    message.Status = "failed";
            //    message.Message = "未登录用户不能上传图片";
            //    res.Data = message;
            //    return res;
            //}

            int size = len / (1024);

            if (size > 2 * 1024)
            {
                message.Status = "failed";
                message.Message = "上传的文件大小不能超过3M";
            }
            else
            {
                string user = HttpContext.User.Identity.Name;
                UserManager userMgr = new UserManager(int.Parse(user), null);
                ImageManager imgMgr = new ImageManager(userMgr.CurrentUser,userMgr.Shop,userMgr.CurrentUserPermission);
                string fileName = Path.GetFileName(name);
                string fileExt = Path.GetExtension(name);
                string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
                string dir1 = DateTime.Now.ToString("yyyy");
                string dir2 = DateTime.Now.ToString("MM");
                string dir3 = DateTime.Now.ToString("dd");
                string dir4 = DateTime.Now.Hour.ToString();
                string rootPath=Request.PhysicalApplicationPath+@"Content\Uploads\Images";
                string absPath=@"/Content/Uploads/Images";
                string location = Path.Combine(rootPath, dir1, dir2, dir3, dir4);
                absPath = absPath + "/" + dir1 + "/" + dir2 + "/" + dir3 + "/" + dir4;
                if (!Directory.Exists(location))
                {
                    Directory.CreateDirectory(location);
                }

                KM.JXC.DBA.Image img = new KM.JXC.DBA.Image();
                img.UserID = user_id;
                img.ProductID = 0;
                img.Path = "";
                img.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                img.FileName = name;
                img.UserID = userMgr.CurrentUser.ID;
                imgMgr.CreateImage(img);

                System.Drawing.Image image = System.Drawing.Image.FromStream(Request.Files["Filedata"].InputStream);
                //if(image.Width>600){
                //    ImageUtil.ThumbPic(Request.Files["Filedata"].InputStream, 600, 0, location, fileName, true);
                //}

                ImageUtil.CutForCustom(Request.Files["Filedata"].InputStream, Path.Combine(location, newFileName), 600, 700, 80);

                if (System.IO.File.Exists(Path.Combine(location, newFileName)))
                {
                    img.Path = absPath + "/" + newFileName;
                }
                message.Status = "ok";
                message.Message = "succeed";
                imgMgr.UpdateImage(img);
                message.Item = img;
            }

            res.Data = message;
            return res;
        }
Exemple #22
0
        public PQGridData GetStockReport()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ReportFactory reportManager = new ReportFactory(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);

            int page = 1;
            int pageSize = 50;
            int totalProducts = 0;
            int[] product_id = null;
            bool paging = false;

            int.TryParse(request["page"], out page);
            int.TryParse(request["pageSize"], out pageSize);

            if (!string.IsNullOrEmpty(request["products"]))
            {
                product_id = base.ConvertToIntArrar(request["products"]);
            }

            if (page <= 0)
            {
                page = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 50;
            }
            if (!string.IsNullOrEmpty(request["paging"]) && request["paging"] == "1")
            {
                paging = true;
            }
            else
            {
                paging = false;
            }
            try
            {
                string json = reportManager.GetStockReport(product_id, page, pageSize, out totalProducts, paging);
                data.totalRecords = totalProducts;
                if (!string.IsNullOrEmpty(json))
                {
                    data.data = JArray.Parse(json);
                }
                data.curPage = page;
            }
            catch (Exception ex)
            {
                data.data = JArray.Parse("[]");
                data.totalRecords = 0;
                data.curPage = 1;
            }
            finally
            {

            }
            return data;
        }
Exemple #23
0
        public ApiMessage GetExcelBuyReport()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ReportFactory reportManager = new ReportFactory(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            long stime = 0;
            long etime = 0;

            int totalProducts = 0;
            int[] product_id = null;

            long.TryParse(request["stime"], out stime);
            long.TryParse(request["etime"], out etime);

            if (!string.IsNullOrEmpty(request["products"]))
            {
                product_id = base.ConvertToIntArrar(request["products"]);
            }

            try
            {
                JToken[] json = reportManager.GetBuyReport(stime, etime, product_id, 0, 0, out totalProducts, false);
                if (json!=null)
                {
                    BuyExcelReport excel = new BuyExcelReport();
                    excel.Export(json);
                    message.Item = "http://" + request.Url.Authority + "/Content/reports/tmp/" + excel.ReportFileName;
                }
                else
                {
                    message.Status = "failed";
                    message.Message = "没有搜索到符合要求的采购数据";
                }
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "没有搜索到符合要求的采购数据";
            }
            finally
            {

            }
            return message;
        }
Exemple #24
0
        public ApiMessage CreateBuyPrice()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                string details = request["price_details"];
                string desc = request["desc"];
                string title = request["title"];
                int shopId = 0;
                int.TryParse(request["shop_id"], out shopId);
                if (!string.IsNullOrEmpty(details))
                {
                    details = HttpUtility.UrlDecode(details);
                }

                JArray jDetails = JArray.Parse(details);
                BBuyPrice buyPrice = new BBuyPrice() { Desc = desc, Title = title, Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) };
                buyPrice.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                if (shopId > 0)
                {
                    buyPrice.Shop = new BShop() { ID = shopId };
                }
                buyPrice.Details = new List<BBuyPriceDetail>();
                for (int i = 0; i < jDetails.Count(); i++)
                {
                    JObject jDetail = (JObject)jDetails[i];
                    BBuyPriceDetail bDetail = new BBuyPriceDetail();
                    bDetail.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    bDetail.Price = (double)jDetail["price"];
                    bDetail.Product = new BProduct() { ID = (int)jDetail["sku_id"], ParentID = (int)jDetail["product_id"] };
                    bDetail.Supplier = new BSupplier() { ID = (int)jDetail["supplier_id"] };
                    buyPrice.Details.Add(bDetail);
                }

                bool result = buyManager.CreateBuyPrice(buyPrice);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                message.Status = "failed";
                message.Message = dbex.Message;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Exemple #25
0
 public PQGridData ExportBuyOrders()
 {
     PQGridData data = new PQGridData();
     HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
     HttpRequestBase request = context.Request;
     string user_id = User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
     int total = 0;
     int page = 1;
     int pageSize = 30;
     int.TryParse(request["page"], out page);
     int.TryParse(request["pageSize"], out pageSize);
     int order_id = 0;
     int supplier_id = 0;
     int.TryParse(request["order_id"], out order_id);
     int.TryParse(request["supplier_id"], out supplier_id);
     string keyword = request["keyword"];
     int[] orders = null;
     if (order_id > 0)
     {
         orders = new int[] { order_id };
     }
     int[] suppliers = null;
     if (supplier_id > 0)
     {
         suppliers = new int[] { supplier_id };
     }
     data.data = buyManager.SearchBuyOrders(orders, null, suppliers, null, keyword, 0, 0, page, pageSize, out total);
     data.totalRecords = total;
     return data;
 }
Exemple #26
0
        public PQGridData GetBuyPrices()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            string keyword = request["keyword"];
            int total = 0;
            int page = 1;
            int pageSize = 30;
            int.TryParse(request["page"], out page);
            int.TryParse(request["pageSize"], out pageSize);
            int price_user_id = 0;
            int supplier_id = 0;
            int.TryParse(request["user_id"], out price_user_id);
            int.TryParse(request["supplier_id"], out supplier_id);
            int buyPriceId = 0;
            int.TryParse(request["price_id"], out buyPriceId);
            string keyWord = request["keyword"];
            if (page <= 0)
            {
                page = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 30;
            }

            data.data = buyManager.SearchBuyPrices(buyPriceId, price_user_id, supplier_id, 0,keyword, page, pageSize, out total);
            data.totalRecords = total;
            data.curPage = page;
            data.pageSize = pageSize;
            return data;
        }
Exemple #27
0
        public ApiMessage GetBuyPriceFullInfo()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BBuyPrice buyPrice = null;
            int priceId = 0;
            try
            {
                int.TryParse(request["buy_price_id"], out priceId);
                if (priceId <= 0)
                {
                    message.Status = "failed";
                    message.Message = "没有输入询价单编号";
                    return message;
                }

                buyPrice = buyManager.GetBuyPriceFullInfo(priceId);

                if (buyPrice == null)
                {
                    message.Status = "failed";
                    message.Message = "询价单编号错误";
                    return message;
                }

                message.Item = buyPrice;
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                message.Status = "failed";
                message.Message = dbex.Message;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Exemple #28
0
        public ApiMessage VerifyOrder()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                int oid = 0;
                long comeDate = 0;
                string odetails = request["order_products"];
                string desc = request["description"];
                int.TryParse(request["oid"], out oid);

                if (!string.IsNullOrEmpty(request["comedate"]))
                {
                    comeDate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["comedate"]));
                }

                BBuy buy = new BBuy();
                buy.ID = 0;
                buy.Order = new BBuyOrder() { ID = oid };
                buy.ComeDate = comeDate;
                buy.Description = desc;
                buy.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                buy.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                buy.User = new BUser() { ID = buyManager.CurrentUser.ID };

                if (!string.IsNullOrEmpty(odetails))
                {
                    odetails = HttpUtility.UrlDecode(odetails);
                    buy.Details = new List<BBuyDetail>();

                    JArray jsons = JArray.Parse(odetails);
                    if (jsons != null && jsons.Count > 0)
                    {

                        for (int i = 0; i < jsons.Count; i++)
                        {
                            JObject jOrder = (JObject)jsons[i];
                            int parent_product_id = (int)jOrder["product_id"];
                            JArray cjorders = (JArray)jOrder["orders"];

                            if (cjorders != null && cjorders.Count > 0)
                            {
                                for (int j = 0; j < cjorders.Count; j++)
                                {
                                    JObject json = (JObject)cjorders[j];
                                    BBuyDetail oDetail = new BBuyDetail();
                                    oDetail.Buy_Order_ID = oid;
                                    double price = 0;
                                    int quantity = 0;
                                    double.TryParse(json["price"].ToString(), out price);
                                    int.TryParse(json["quantity"].ToString(), out quantity);
                                    oDetail.Price = price;
                                    oDetail.Product = new BProduct() { ID = (int)json["child_id"] };
                                    oDetail.Quantity = quantity;

                                    if (quantity <= 0)
                                    {
                                        continue;
                                    }
                                    oDetail.Parent_Product_ID = parent_product_id;
                                    buy.Details.Add(oDetail);
                                }
                            }
                        }
                    }
                }

                bool result = buyManager.VerifyBuyOrder(buy);

                if (result)
                {
                    message.Status = "ok";
                }
                else
                {
                    message.Status = "failed";
                    message.Message = "验货单创建失败";
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Exemple #29
0
        public ApiMessage UpdateProduct()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            ApiMessage message = new ApiMessage();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int product_id = 0;
            int categoryId = 0;
            string description = "";
            string props = "";
            string images = "";
            string title = "";
            int.TryParse(request["cid"], out categoryId);
            int.TryParse(request["product_id"],out product_id);
            description = request["desc"];
            title = request["title"];
            images = request["images"];
            props = request["props"];
            string suppliers = request["sids"];
            try
            {
                BProduct product = new BProduct();
                product.ID = product_id;
                product.Parent = null;
                product.Category = new BCategory() { ID = categoryId };
                product.Title = title;
                product.Description = description;
                product.Properties = null;
                product.FileRootPath = request.PhysicalApplicationPath;
                if (!string.IsNullOrEmpty(images))
                {
                    product.Images = new List<Image>();
                    string[] ims = images.Split(',');
                    foreach (string img in ims)
                    {
                        int image_id = 0;
                        int.TryParse(img,out image_id);
                        if (image_id > 0)
                        {
                            product.Images.Add(new Image() { ID = image_id });
                        }
                    }
                }

                if (!string.IsNullOrEmpty(suppliers))
                {
                    product.Suppliers = new List<Supplier>();
                    string[] sids = suppliers.Split(',');
                    foreach (string sid in sids)
                    {
                        product.Suppliers.Add(new Supplier() { Supplier_ID = int.Parse(sid), Enabled = true });
                    }
                }

                if (!string.IsNullOrEmpty(props))
                {
                    if (product.Children == null)
                    {
                        product.Children = new List<BProduct>();
                    }
                    string[] groups = props.Split(';');
                    foreach (string group in groups)
                    {
                        string groupp = group.Split('|')[1];
                        int pdtId = int.Parse(group.Split('|')[0]);
                        BProduct child = new BProduct();
                        child.ID = pdtId;
                        child.Title = product.Title;
                        child.Description = product.Description;
                        child.Category = product.Category;
                        List<BProductProperty> properties = new List<BProductProperty>();
                        string[] pops = groupp.Split(',');
                        foreach (string pop in pops)
                        {
                            BProductProperty prop = new BProductProperty();
                            prop.PID = int.Parse(pop.Split(':')[0]);
                            prop.PVID = int.Parse(pop.Split(':')[1]);
                            properties.Add(prop);
                        }
                        child.Properties = properties;
                        product.Children.Add(child);
                    }
                }

                pdtManager.UpdateProduct(ref product);
                message.Status = "ok";
                message.Item = product;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            return message;
        }
Exemple #30
0
        public ApiMessage UpdateBuyOrder()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                int oid = 0;
                long writedate = 0;
                long issuedate = 0;
                long enddate = 0;
                int supplier_id = 0;
                int order_user = 0;
                string odetails = request["order_products"];
                string desc = request["description"];
                int.TryParse(request["oid"],out oid);

                if (!string.IsNullOrEmpty(odetails))
                {
                    odetails = HttpUtility.UrlDecode(odetails);
                }

                if (!string.IsNullOrEmpty(request["writedate"]))
                {
                    writedate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["writedate"]));
                }

                if (!string.IsNullOrEmpty(request["issuedate"]))
                {
                    issuedate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["issuedate"]));
                }

                if (!string.IsNullOrEmpty(request["enddate"]))
                {
                    enddate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["enddate"]));
                }

                int.TryParse(request["supplier"], out supplier_id);
                int.TryParse(request["order_user"], out order_user);
                BBuyOrder order = new BBuyOrder();
                order.ID = oid;
                //order.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                //order.Created_By = new BUser() { ID = buyManager.CurrentUser.ID };
                order.Description = desc;
                order.EndTime = enddate;
                order.InsureTime = issuedate;
                order.OrderUser = new BUser() { ID = order_user };
                order.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                order.Status = 0;
                order.Supplier = new Supplier() { Supplier_ID = supplier_id };
                order.WriteTime = writedate;
                if (!string.IsNullOrEmpty(odetails))
                {
                    JArray jOrders = JArray.Parse(odetails);
                    order.Details = new List<BBuyOrderDetail>();
                    if (jOrders != null && jOrders.Count > 0)
                    {
                        for (int i = 0; i < jOrders.Count; i++)
                        {
                            JObject jOrder = (JObject)jOrders[i];
                            int parent_product_id = (int)jOrder["product_id"];
                            JArray cjorders = (JArray)jOrder["orders"];
                            if (cjorders != null && cjorders.Count > 0)
                            {
                                for (int j = 0; j < cjorders.Count; j++)
                                {
                                    BBuyOrderDetail oDetail = new BBuyOrderDetail();
                                    oDetail.Parent_Product_ID = parent_product_id;
                                    double price = 0;
                                    int quantity = 0;
                                    double.TryParse(cjorders[j]["price"].ToString(), out price);
                                    int.TryParse(cjorders[j]["quantity"].ToString(), out quantity);
                                    oDetail.Product = new BProduct() { ID = (int)cjorders[j]["child_id"] };
                                    oDetail.Quantity = quantity;
                                    oDetail.Status = 0;
                                    oDetail.Price = price;
                                    if (quantity <= 0)
                                    {
                                        continue;
                                    }
                                    order.Details.Add(oDetail);
                                }
                            }
                        }
                    }
                }

                bool result = buyManager.UpdateBuyOrder(order);
                if (result)
                {
                    message.Status = "ok";
                }
                else
                {
                    message.Status = "failed";
                    message.Message = "更新失败";
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }