コード例 #1
0
ファイル: Designer.cs プロジェクト: jkwchunjae/ProjectSIA
 public static void Caching(ProjectSIAEntities db)
 {
     using (var wl = new WriteLock())
     {
         _designerList = db.Designer.ToList().Select(x => new Designer(x)).ToList();
     }
 }
コード例 #2
0
ファイル: Order.cs プロジェクト: jkwchunjae/ProjectSIA
        public static Order AddNewOrder(ProjectSIAEntities db, int memberId, DateTime orderDate, string orgName, string phone, string address, IEnumerable<ProductCount> receipts, int storeId)
        {
            using (var wl = new WriteLock())
            {
                if (receipts == null || receipts.Count() == 0) throw new AutistarException("주문물품이 없습니다.");
                if (receipts.Where(x => x.Count <= 0).Any()) throw new AutistarException("주문내역에 0 이하의 수량이 있습니다.");

                var newOrder = db.OrderInfo.Add(new OrderInfo
                {
                    memberId = memberId,
                    status = OrderStatus.Prepare.ToString(),
                    orderDate = orderDate,
                    isPay = false,
                    isOrg = !string.IsNullOrEmpty(orgName),
                    orgName = orgName,
                    phone = phone,
                    address = address,
                    storeId = storeId,
                });
                var rows = db.SaveChanges();

                if (rows != 1)
                    throw new AutistarException("주문 추가 DB 작업이 실패했습니다.");

                foreach (var receipt in receipts)
                {
                    ProductManager.Ordering(db, receipt.ProductInfoId, receipt.Count, receipt.Price, newOrder.id, storeId);
                }
                return new Order(newOrder);
            }
        }
コード例 #3
0
ファイル: Designer.cs プロジェクト: jkwchunjae/ProjectSIA
 public static Designer AddNewDesigner(ProjectSIAEntities db, string name, string phone, string picture)
 {
     using (var wl = new WriteLock())
     {
         var newDesigner = db.Designer.Add(new ProjectSIA.Designer { name = name, phone = phone, picture = picture });
         var rows = db.SaveChanges();
         if (rows != 1)
             throw new AutistarException("디자이너 추가 DB 작업이 실패했습니다.");
         return new Designer(newDesigner);
     }
 }
コード例 #4
0
ファイル: Designer.cs プロジェクト: jkwchunjae/ProjectSIA
        public static void Caching(Designer designer)
        {
            using (var wl = new WriteLock())
            {
                #region Remove
                var d = _designerList.Where(x => x.Id == designer.Id).FirstOrDefault();
                if (d != null)
                    _designerList.Remove(d);
                #endregion

                #region Add
                _designerList.Add(designer);
                #endregion
            }
        }
コード例 #5
0
ファイル: Store.cs プロジェクト: jkwchunjae/ProjectSIA
        public static void BringProduct(ProjectSIAEntities db, int storeId, IEnumerable<ProductCount> productCountList)
        {
            using (var wl = new WriteLock())
            {
                if (productCountList.Count() == 0)
                    throw new AutistarException("행사장(거래처) 가져갈 물품을 입력하지 않았습니다.");
                if (productCountList.Where(x => x.Count <= 0).Any())
                    throw new AutistarException("행사장(거래처) 가져갈 물품 중 수량이 0보다 작은 항목이 있습니다.");

                // Id 검사. Invalid 한 Id이면 exception 나겠지
                productCountList.Select(x => ProductInfoManager.GetByProductInfoId(db, x.ProductInfoId)).ToList();
                GetStore(db, storeId);

                foreach (var productCount in productCountList)
                {
                    ProductManager.BringStore(db, storeId, productCount.ProductInfoId, productCount.Count);
                }
            }
        }
コード例 #6
0
ファイル: LogWarehouse.cs プロジェクト: jkwchunjae/ProjectSIA
        public static LogWarehouse AddNewLogWarehouse(ProjectSIAEntities db, int productInfoId, int warehouseCount, DateTime warehouseDate, string others)
        {
            using (var wl = new WriteLock())
            {
                var newLogWarehouse = db.LogWarehouse.Add(new ProjectSIA.LogWarehouse
                {
                    productInfoId = productInfoId,
                    warehouseCount = warehouseCount,
                    warehouseDate = warehouseDate,
                    badCount = 0,
                    others = ""
                });
                var rows = db.SaveChanges();

                if (rows != 1)
                    throw new Exception("상품 입고 처리 중 DB 작업이 실패하였습니다.");

                return new LogWarehouse(newLogWarehouse);
            }
        }
コード例 #7
0
ファイル: Member.cs プロジェクト: jkwchunjae/ProjectSIA
 public static Member AddNewMember(ProjectSIAEntities db, string name, string phone, string address, string orgName)
 {
     using (var wl = new WriteLock())
     {
         if (name == "dummy")
         {
             // thread-safe 하게 하기 위해서 WriteLock 걸고 한번 더 체크해 줘야 함.
             var dummy = db.Member.Where(x => x.name == "dummy").FirstOrDefault();
             if (dummy != null)
                 return GetDummyMember(db);
         }
         var isOrg = string.IsNullOrEmpty(orgName) ? false : true;
         var newMember = db.Member.Add(new ProjectSIA.Member { name = name, phone = phone, address = address, isOrg = isOrg, orgName = orgName, isVip = false });
         var rows = db.SaveChanges();
         if (rows != 1)
             throw new AutistarException("사용자 추가 DB 작업이 실패했습니다.");
         var member = new Member(newMember);
         _memberList.Add(member);
         return member;
     }
 }
コード例 #8
0
ファイル: Product.cs プロジェクト: jkwchunjae/ProjectSIA
        public static void Ordering(ProjectSIAEntities db, int productInfoId, int orderCount, long eachPrice, int orderId, int storeId)
        {
            using (var wl = new WriteLock())
            {
                var localStore = StoreManager.GetLocalStore(db);
                var checkProductStatus = localStore.Id == storeId ? ProductStatus.Warehoused : ProductStatus.Store;
                var productList = GetByProductInfoIdAndStoreIdAndStatus(db, productInfoId, storeId, checkProductStatus).Take(orderCount);
                if (productList.Count() < orderCount)
                    throw new AutistarException("재고가 부족합니다. (상품명: {0})".With(ProductInfoManager.GetByProductInfoId(db, productInfoId).Info));

                foreach (var product in productList)
                {
                    var dbProduct = db.Product.Where(x => x.id == product.Id).First();
                    dbProduct.status = ProductStatus.OrderPrepare.ToString();
                    dbProduct.orderId = orderId;
                    dbProduct.price = eachPrice;
                }
                var rows = db.SaveChanges();
                if (rows != orderCount)
                    throw new AutistarException("상품 주문 처리 중 DB 작업이 실패했습니다.");
            }
        }
コード例 #9
0
ファイル: Store.cs プロジェクト: jkwchunjae/ProjectSIA
        public static Store CreateStore(ProjectSIAEntities db, string name, DateTime beginDate, DateTime endDate, StoreType type, StoreRule rule, double value)
        {
            using (var wl = new WriteLock())
            {
                if (endDate <= beginDate)
                    throw new AutistarException("종료일이 시작일보다 빠릅니다.");

                var newStore = db.Store.Add(new ProjectSIA.Store { name = name, beginDate = beginDate, endDate = endDate, type = type.ToString(), rule = rule.ToString(), value = value });
                var rows = db.SaveChanges();
                if (rows != 1)
                    throw new AutistarException("행사장(거래처) 추가 중 DB 작업이 실패했습니다.");
                var store = new Store(newStore);
                _storeList.Add(store);
                return store;
            }
        }
コード例 #10
0
ファイル: Store.cs プロジェクト: jkwchunjae/ProjectSIA
 public static bool DeleteStore(ProjectSIAEntities db, int storeId)
 {
     using (var wl = new WriteLock())
     {
         var dbStore = db.Store.Where(x => x.id == storeId).FirstOrDefault();
         if (dbStore == null)
             throw new AutistarException("등록되지 않은 행사장(거래처) Id 입니다. (id: {0})".With(storeId));
         db.Store.Remove(dbStore);
         var rows = db.SaveChanges();
         if (rows == 1)
         {
             var store = _storeList.Where(x => x.Id == storeId).FirstOrDefault();
             if (store != null)
                 _storeList.Remove(store);
         }
         return rows == 1;
     }
 }
コード例 #11
0
ファイル: Store.cs プロジェクト: jkwchunjae/ProjectSIA
 public static Store GetLocalStore(ProjectSIAEntities db)
 {
     using (var rl = new ReadLock())
     {
         var localStore = GetAllStoreList(db).Where(x => x.Type == StoreType.Local).FirstOrDefault();
         if (localStore == null)
         {
             using (var wl = new WriteLock())
             {
                 var dbLocalStore = db.Store.Add(new ProjectSIA.Store() { name = "사무실", beginDate = new DateTime(2012, 1, 1), endDate = DateTime.MaxValue, type = StoreType.Local.ToString(), rule = StoreRule.None.ToString(), value = 0 });
                 var rows = db.SaveChanges();
                 if (rows != 1)
                     throw new AutistarException("사무실 Store를 만드는 과정 중 DB 작업을 실패했습니다.");
                 localStore = new Store(dbLocalStore);
             }
         }
         return localStore;
     }
 }
コード例 #12
0
ファイル: ProductInfo.cs プロジェクト: jkwchunjae/ProjectSIA
		public static ProductInfo AddNewProductInfo(ProjectSIAEntities db, string type1, string type2, string type3, string name, long price, DateTime regDate)
		{
			using (var wl = new WriteLock())
			{
				var newProductInfo = db.ProductInfo.Add(new ProjectSIA.ProductInfo { type1 = type1, type2 = type2, type3 = type3, name = name, price = price, regDate = regDate });
				var rows = db.SaveChanges();
				if (rows != 1)
					throw new AutistarException("신규 상품 등록 중 DB 작업이 실패하였습니다.");
				return new ProductInfo(newProductInfo);
			}
		}
コード例 #13
0
ファイル: Product.cs プロジェクト: jkwchunjae/ProjectSIA
 /// <summary> 주문된 상품을 배송(판매) </summary>
 public static void ReleaseProduct(ProjectSIAEntities db, int orderId)
 {
     using (var wl = new WriteLock())
     {
         var productList = GetAllProductList(db).Where(x => x.OrderId == orderId);
         foreach (var product in productList)
         {
             var dbProduct = db.Product.Where(x => x.id == product.Id).First();
             dbProduct.status = ProductStatus.Release.ToString();
         }
         var rows = db.SaveChanges();
         if (rows != productList.Count())
             throw new AutistarException("상품 발송처리 중 DB 작업이 실패했습니다.");
     }
 }
コード例 #14
0
ファイル: ProductInfo.cs プロジェクト: jkwchunjae/ProjectSIA
		public static void Caching(ProductInfo productInfo)
		{
			if (_productInfoList == null || _productInfoDic == null)
				return;
			using (var wl = new WriteLock())
			{
				#region Remove
				var p = _productInfoList.Where(x => x.Id == productInfo.Id).FirstOrDefault();
				if (p != null)
					_productInfoList.Remove(p);
				_productInfoDic.Remove(productInfo.Id);
				#endregion

				#region Add
				_productInfoList.Add(productInfo);
				_productInfoDic.Add(productInfo.Id, productInfo);
				#endregion
			}
		}
コード例 #15
0
ファイル: ProductInfo.cs プロジェクト: jkwchunjae/ProjectSIA
		public static void Caching(IEnumerable<ProductInfo> productInfoList)
		{
			if (_productInfoList == null || _productInfoDic == null)
				return;
			using (var wl = new WriteLock())
			{
				foreach (var productInfo in productInfoList)
					Caching(productInfo);
			}
		}
コード例 #16
0
ファイル: Designer.cs プロジェクト: jkwchunjae/ProjectSIA
 public static void Caching(IEnumerable<Designer> designerList)
 {
     using (var wl = new WriteLock())
     {
         foreach (var designer in designerList)
             Caching(designer);
     }
 }
コード例 #17
0
ファイル: ProductInfo.cs プロジェクト: jkwchunjae/ProjectSIA
		public static void Caching(ProjectSIAEntities db)
		{
			using (var wl = new WriteLock())
			{
				_productInfoList = db.ProductInfo.ToList().Select(x => new ProductInfo(x)).ToList();
				try
				{
					_productInfoDic = _productInfoList.ToDictionary(x => x.Id, x => x);
				}
				catch (ArgumentException)
				{
					_productInfoDic = null;
					throw new AutistarException("중복된 ProductInfo Id가 존재합니다.");
				}
			}
		}
コード例 #18
0
ファイル: Product.cs プロジェクト: jkwchunjae/ProjectSIA
        public static void BringStore(ProjectSIAEntities db, int storeId, int productInfoId, int bringCount)
        {
            using (var wl = new WriteLock())
            {
                var productList = GetByProductInfoIdAndStatus(db, productInfoId, ProductStatus.Warehoused).Take(bringCount);
                if (productList.Count() < bringCount)
                    throw new AutistarException("행사장 또는 거래처에 가져갈 제품의 재고가 부족합니다.");

                foreach (var product in productList)
                {
                    var dbProduct = db.Product.Where(x => x.id == product.Id).First();
                    dbProduct.status = ProductStatus.Store.ToString();
                    dbProduct.storeId = storeId;
                }
                var rows = db.SaveChanges();
                if (rows != bringCount)
                    throw new AutistarException("행사장 또는 거래처에 제품 가져가는 작업 중 DB 작업이 실패했습니다.");
            }
        }
コード例 #19
0
ファイル: Product.cs プロジェクト: jkwchunjae/ProjectSIA
 /// <summary> 상품 입고처리 </summary>
 public static void WarehouseProduct(ProjectSIAEntities db, int productInfoId, int warehouseCount, DateTime warehouseDate, int logWarehouseId)
 {
     using (var wl = new WriteLock())
     {
         var localStore = StoreManager.GetLocalStore(db);
         for (int i = 0; i < warehouseCount; i++)
         {
             var newProduct = db.Product.Add(new ProjectSIA.Product
             {
                 productInfoId = productInfoId,
                 warehouseDate = warehouseDate,
                 status = ProductStatus.Warehoused.ToString(),
                 logWarehouseId = logWarehouseId,
                 storeId = localStore.Id,
             });
         }
         var rows = db.SaveChanges();
         if (rows != warehouseCount)
             throw new AutistarException("상품 입고 중 DB 작업이 실패했습니다.");
     }
 }
コード例 #20
0
ファイル: Product.cs プロジェクト: jkwchunjae/ProjectSIA
        public static void BadProducts(ProjectSIAEntities db, int productInfoId, int requestBadCount, int logWarehouseId = 0)
        {
            using (var wl = new WriteLock())
            {
                #region 언제 입고된 불량인지 아는 경우
                if (logWarehouseId > 0)
                {
                    #region Log 테이블 체크
                    var logWarehouse = db.LogWarehouse
                        .Where(x => x.id == logWarehouseId)
                        .FirstOrDefault();
                    if (logWarehouse == null)
                        throw new AutistarException("입고일련번호를 찾을 수 없습니다. (id: {0})".With(logWarehouseId));
                    #endregion

                    #region 상품 테이블 체크
                    var warehousedList = db.Product
                        .Where(x => x.productInfoId == productInfoId)
                        .Where(x => x.logWarehouseId == logWarehouseId)
                        .Where(x => x.status == "Warehoused")
                        .ToList();
                    if (warehousedList.Count() < requestBadCount)
                        throw new AutistarException("불량 처리 수량이 남아있는 재고보다 많습니다.");
                    #endregion

                    #region DB 처리
                    logWarehouse.badCount += requestBadCount;
                    var rows = db.SaveChanges();
                    if (rows != 1)
                        throw new AutistarException("불량 처리 작업 중 DB 작업이 실패했습니다. (table: LogWarehouseProduct)");

                    foreach (var product in warehousedList.Take(requestBadCount))
                        product.status = ProductStatus.Bad.ToString();
                    rows = db.SaveChanges();
                    if (rows != requestBadCount)
                        throw new AutistarException("불량 처리 작업 중 DB 작업이 실패했습니다. (table: Product)");
                    #endregion
                }
                #endregion
                #region 언제 입고된 불량인지 모르는 경우
                else
                {
                    var logWarehouseList = db.LogWarehouse
                        .Where(x => x.productInfoId == productInfoId)
                        .Where(x => x.warehouseCount > x.badCount)
                        .ToList()
                        .OrderBy(x => x.warehouseDate)
                        .ThenBy(x => x.id)
                        .ToList();

                    var warehousedList = db.Product
                        .Where(x => x.productInfoId == productInfoId)
                        .Where(x => x.status == "Warehoused")
                        .ToList()
                        .OrderBy(x => x.warehouseDate)
                        .ToList();
                    if (warehousedList.Count() < requestBadCount)
                        throw new AutistarException("불량 처리 수량이 남아있는 재고보다 많습니다.");

                    foreach (var product in warehousedList.Take(requestBadCount))
                    {
                        product.status = ProductStatus.Bad.ToString();
                        var logWarehouse = logWarehouseList.Where(x => x.id == product.logWarehouseId).FirstOrDefault();
                        if (logWarehouse == null)
                            throw new AutistarException("불량처리: 등록되지 않은 입고일련번호입니다. (id: {0})".With(product.logWarehouseId));
                        logWarehouse.badCount += 1;
                    }
                    db.SaveChanges();
                }
                #endregion
            }
        }
コード例 #21
0
ファイル: Order.cs プロジェクト: jkwchunjae/ProjectSIA
        /// <summary> 주문 결재 </summary>
        public static void PayingOrder(ProjectSIAEntities db, int orderId, DateTime payDate)
        {
            using (var wl = new WriteLock())
            {
                var dbOrder = db.OrderInfo.Where(x => x.id == orderId).FirstOrDefault();

                if (dbOrder == null)
                    throw new AutistarException("결재: 등록되지 않은 주문번호입니다. (id: {0})".With(orderId));

                dbOrder.payDate = payDate;
                dbOrder.isPay = true;
                var rows = db.SaveChanges();
                if (rows != 1)
                    throw new AutistarException("주문 결재 처리 DB 작업이 실패했습니다.");
            }
        }
コード例 #22
0
ファイル: Order.cs プロジェクト: jkwchunjae/ProjectSIA
        /// <summary> 주문된 상품 출고하기 </summary>
        public static void ReleaseOrder(ProjectSIAEntities db, int orderId, DateTime releaseDate)
        {
            using (var wl = new WriteLock())
            {
                var dbOrder = db.OrderInfo.Where(x => x.id == orderId).FirstOrDefault();

                if (dbOrder == null)
                    throw new AutistarException("출고: 등록되지 않은 주문번호입니다. (id: {0})".With(orderId));

                if (dbOrder.status != OrderStatus.Prepare.ToString())
                    throw new AutistarException("출고: 상태가 주문 준비중이지 않습니다. (id: {0})".With(orderId));

                dbOrder.status = OrderStatus.Release.ToString();
                dbOrder.releaseDate = releaseDate;
                db.SaveChanges();

                ProductManager.ReleaseProduct(db, orderId);
            }
        }