public static void Caching(ProjectSIAEntities db) { using (var wl = new WriteLock()) { _designerList = db.Designer.ToList().Select(x => new Designer(x)).ToList(); } }
public static List<ProductInfo> GetByType1(ProjectSIAEntities db, string type1) { using (var rl = new ReadLock()) { return GetAllProductInfoList(db).Where(x => x.Type1 == type1).ToList(); } }
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); } }
public static List<string> GetType2ListByType1(ProjectSIAEntities db, string type1) { using (var rl = new ReadLock()) { return GetAllProductInfoList(db).Where(x => x.Type1 == type1).Select(x => x.Type2) .Distinct().OrderBy(x => x).ToList(); } }
public static List<ProductInfo> GetAllProductInfoList(ProjectSIAEntities db, bool reload = false) { using (var rl = new ReadLock()) { if (_productInfoList == null || reload) Caching(db); return _productInfoList; } }
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); } }
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); } } }
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); } }
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; } }
public static Order GetOrder(ProjectSIAEntities db, int orderId) { using (var rl = new ReadLock()) { var dbOrder = db.OrderInfo.Where(x => x.id == orderId).FirstOrDefault(); if (dbOrder == null) throw new AutistarException("등록되지 않은 주문번호입니다. (id: {0})".With(orderId)); return new Order(dbOrder); } }
public static List<Designer> GetAllDesingerList(ProjectSIAEntities db, bool reload = false) { using (var rl = new ReadLock()) { if (_designerList == null || reload) { Caching(db); } return _designerList; } }
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); } }
public static List<Order> GetOrderList(ProjectSIAEntities db, DateTime beginDate, DateTime endDate) { using (var rl = new ReadLock()) { return db.OrderInfo.Where(x => x.payDate >= beginDate && x.payDate <= endDate) .ToList() .Select(x => new Order(x)) .ToList(); //return GetAllOrderList(db).Where(x => (x.PayDate >= beginDate && x.PayDate <= endDate)).ToList(); } }
/// <summary> 매핑된 디자이너 이름 포함 검색 </summary> public static List<ProductInfo> SearchWithDesignerName(ProjectSIAEntities db, string[] keywords) { using (var rl = new ReadLock()) { var result = new List<ProductInfo>(); #region 디자이너 이름 전처리 var DesignerNameDic = DesignerMappingManager.GetAllMappingList(db) .Join(DesignerManager.GetAllDesingerList(db), x => x.DesignerId, y => y.Id, (x, y) => new { x.ProductInfoId, y.Name }) .GroupBy(x => new { x.ProductInfoId }) .Select(x => new { x.Key.ProductInfoId, DesignerNames = x.Select(e => e.Name).StringJoin(" ") }) .ToDictionary(x => x.ProductInfoId, y => y.DesignerNames); #endregion var productList = GetAllProductInfoList(db); foreach (var product in productList) { var str = product.Type1 + product.Type2 + product.Type3 + product.Name; if (DesignerNameDic.ContainsKey(product.Id)) str += DesignerNameDic[product.Id]; var allChecked = true; foreach (var keyword in keywords) { if (!str.Contains(keyword)) { allChecked = false; break; } } if (allChecked) result.Add(product); } return result; } }
public static List<string> SearchType2ByType1(ProjectSIAEntities db, string type1, string[] keywords) { using (var rl = new ReadLock()) { var type2List = GetType2ListByType1(db, type1); if (keywords.Contains(".")) return type2List; var result = new List<string>(); foreach (var type2 in type2List) { var allChecked = true; foreach (var keyword in keywords) { if (!type2.Contains(keyword)) { allChecked = false; break; } } if (allChecked) result.Add(type2); } return result; } }
/// <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 작업이 실패했습니다."); } }
public static List<Order> GetAllOrderList(ProjectSIAEntities db) { using (var rl = new ReadLock()) { return db.OrderInfo.ToList().Select(x => new Order(x)).ToList(); } }
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; } }
public static List<Store> GetAllStoreList(ProjectSIAEntities db, bool reload = false) { using (var rl = new ReadLock()) { if (_storeList == null || reload) { _storeList = db.Store.ToList().Select(x => new Store(x)).ToList(); } return _storeList; } }
/// <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); } }
public static Designer GetDesigner(ProjectSIAEntities db, int designerId) { using (var rl = new ReadLock()) { var designer = GetAllDesingerList(db).Where(x => x.Id == designerId).FirstOrDefault(); if (designer == null) throw new AutistarException("등록되지 않은 디자이너입니다. (id: {0})".With(designerId)); return designer; } }
public static List<Designer> Search(ProjectSIAEntities db, string keyword) { using (var rl = new ReadLock()) { return GetAllDesingerList(db) .Where(x => x.Name.Contains(keyword)) .ToList(); } }
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; } }
public static ProductInfo GetByProductInfoId(ProjectSIAEntities db, int productInfoId) { using (var rl = new ReadLock()) { if (_productInfoDic == null) GetAllProductInfoList(db, true); if (!_productInfoDic.ContainsKey(productInfoId)) throw new AutistarException("등록되지 않은 상품 기본정보 일련번호입니다. (id: {0})".With(productInfoId)); return _productInfoDic[productInfoId]; } }
public static List<Store> GetCurrentOpenedStore(ProjectSIAEntities db) { using (var rl = new ReadLock()) { return GetAllStoreList(db).Where(x => x.BeginDate < DateTime.Now && x.EndDate > DateTime.Now).ToList(); } }
public static List<ProductInfo> GetListByProductInfoId(ProjectSIAEntities db, IEnumerable<int> productInfoIdList) { using (var rl = new ReadLock()) { if (_productInfoDic == null) GetAllProductInfoList(db, true); if (productInfoIdList.Where(x => !_productInfoDic.ContainsKey(x)).Any()) throw new AutistarException("등록되지 않은 ProductInfo Id가 있습니다."); return productInfoIdList.Select(x => _productInfoDic[x]).ToList(); } }
public static Store GetStore(ProjectSIAEntities db, int storeId) { using (var rl = new ReadLock()) { var store = GetAllStoreList(db).Where(x => x.Id == storeId).FirstOrDefault(); if (store == null) throw new AutistarException("등록되지 않은 행사장(거래처) 번호입니다. (id: {0})".With(storeId)); return store; } }
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가 존재합니다."); } } }
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; } }
/// <summary> 분류1,2,3 + 이름 검색 </summary> public static List<ProductInfo> Search(ProjectSIAEntities db, string[] keywords) { using (var rl = new ReadLock()) { var result = new List<ProductInfo>(); var productList = GetAllProductInfoList(db); foreach (var product in productList) { var str = product.Type1 + product.Type2 + product.Type3 + product.Name; var allChecked = true; foreach (var keyword in keywords) { if (!str.Contains(keyword)) { allChecked = false; break; } } if (allChecked) result.Add(product); } return result; } }