Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(PurchaseComplex model)
        {
            ResultModel result = new ResultModel();

            try
            {
                #region Service資料庫
                if (this._PurchaseComplexService.IsUsed(model))
                {
                    result.Message          = "MessageChaneDelete2UpdateComplete".ToLocalized();
                    model.Purchase.Activate = YesNo.No.Value;
                    this._PurchaseComplexService.Update(model);
                }
                else
                {
                    this._PurchaseComplexService.Delete(model);
                }
                #endregion
            }
            catch (Exception ex)
            {
                #region  錯誤時錯誤訊息
                result.Status  = false;
                result.Message = ex.Message.ToString();
                #endregion
            }
            return(Json(result));
        }
Exemplo n.º 2
0
        public PurchaseComplex Create(PurchaseComplex source)
        {
            #region 取資料


            #endregion

            #region 邏輯驗證


            #endregion

            #region 變為Models需要之型別及邏輯資料
            Purchase main = GetPurchaseOnCreate(source);

            List <PurchaseDetail> children = GetChildOnCreate(main, source);
            #endregion

            #region Models資料庫

            this._Repository.Create(main);

            foreach (PurchaseDetail item in children)
            {
                this._DetailRepository.Create(item);
            }

            this._UnitOfWork.SaveChange();
            #endregion

            return(this.Get(main.PurchaseID));
        }
Exemplo n.º 3
0
        public void Delete(PurchaseComplex model)
        {
            #region 邏輯驗證
            if (model == null)//沒有資料
            {
                throw new Exception("MessageNoData".ToLocalized());
            }
            #endregion

            #region 變為Models需要之型別及邏輯資料
            var info = Mapper.Map <Purchase>(model.Purchase);
            #endregion

            #region Models資料庫

            foreach (PurchaseDetailViewModel t in model.ChildList)
            {
                var d = Mapper.Map <PurchaseDetail>(t);
                _DetailRepository.Delete(d);
            }

            this._Repository.Delete(info);
            this._UnitOfWork.SaveChange();
            #endregion
        }
Exemplo n.º 4
0
        private Purchase GetPurchaseOnUpdate(PurchaseComplex source)
        {
            Purchase info = Mapper.Map <Purchase>(source.Purchase);

            info.LastPerson = IdentityService.GetUserData().UserID;
            info.LastUpdate = DateTime.Now;
            return(info);
        }
Exemplo n.º 5
0
 public bool IsUsed(PurchaseComplex info)
 {
     //var query = this._Repository.Get(x => x.InquiryID == model.Inquiry.InquiryID);
     //var result = query.Product.Any();
     //this._Repository.HandleDetached(query); //
     //return result;
     return(true); // 目前不知關聯到哪些資料表
 }
Exemplo n.º 6
0
        public PurchaseComplex Get(string id)
        {
            PurchaseComplex info = new PurchaseComplex();

            //var query =
            //    from u in this._Repository.GetAll()
            //    join p in this._Company.GetAll() on u.SupplierID equals p.CompanySupplier into g
            //    from p in g.DefaultIfEmpty()
            //    where (u.PurchaseID == id)
            //    select new PurchaseViewModel()
            //    {
            //        PurchaseID = u.PurchaseID,
            //        PurchaseDate = u.PurchaseDate,
            //        SupplierID = u.SupplierID,
            //        ContactPerson = u.ContactPerson,
            //        ContactPhone = u.ContactPhone,
            //        InvoiceAmount = u.InvoiceAmount,
            //        InvoiceID = u.InvoiceID,
            //        CurrencyID = u.CurrencyID,
            //        ExchangeRate = u.ExchangeRate,
            //        AccountMonth = u.AccountMonth,
            //        WarehouseID = u.WarehouseID,
            //        Remarks = u.Remarks,
            //        PostingTime = u.PostingTime,
            //        CompanyName = (p == null) ? "" : p.CompanyName
            //    };

            //info.Purchase = query.SingleOrDefault();

            //var query2 =
            //   from u in this._DetailRepository.GetAll()
            //   join p in this._Company.GetAll() on u.ProductID equals p.ProductID into g
            //   from p in g.DefaultIfEmpty()
            //   where (u.PurchaseID == id)
            //   select new PurchaseDetailViewModel()
            //   {
            //       SeqNo = u.SeqNo,
            //       PurchaseID = u.PurchaseID,
            //       ProductID = u.ProductID,
            //       PriceKindID = u.PriceKindID,
            //       ConditionID = u.ConditionID,
            //       Discount = u.Discount,
            //       ForeignPrice = u.ForeignPrice,
            //       Price = u.Price,
            //       Qty = u.Qty,
            //       Amount = u.Amount,
            //       Remarks = u.Remarks,
            //       ProductName = (p == null) ? "" : p.ProductName
            //   };

            //info.ChildList = query2.ToList();

            info = this.GetAll().Where(x => x.Purchase.PurchaseID == id).Single();

            return(info);
        }
Exemplo n.º 7
0
        private Purchase GetPurchaseOnCreate(PurchaseComplex source)
        {
            Purchase info = Mapper.Map <Purchase>(source.Purchase);

            // 取得詢價單號;目前由使用者自型輸入
            info.PurchaseID = GeneratePurchaseID(info);
            //info.PostingTime = DateTime.Today;
            info.LastPerson = IdentityService.GetUserData().UserID;
            info.LastUpdate = DateTime.Now;
            return(info);
        }
Exemplo n.º 8
0
        private List <PurchaseDetail> GetChildOnCreate(Purchase master, PurchaseComplex source)
        {
            List <PurchaseDetail> infos = new List <PurchaseDetail>();
            var wanted = source.ChildList.Where(x => x.IsDirty == true);

            foreach (var item in wanted)
            {
                PurchaseDetail temp = Mapper.Map <PurchaseDetail>(item);
                temp.PurchaseID = master.PurchaseID;
                temp.LastPerson = IdentityService.GetUserData().UserID;
                temp.LastUpdate = DateTime.Now;
                infos.Add(temp);
            }
            return(infos);
        }
Exemplo n.º 9
0
        private void InitViewBag(PurchaseComplex info)
        {
            // 倉庫
            ViewBag.CurrencyKindList =
                new SelectList(this._GlobalService.GetCurrencyKindList(), "Key", "Value", info?.Purchase.CurrencyID);

            // 倉庫
            ViewBag.WareHouseList =
                new SelectList(this._GlobalService.GetWarehouseList(), "Key", "Value", info?.Purchase.WarehouseID);

            // 公司供應商廠商名稱
            ViewBag.CompanyList =
                new SelectList(this._GlobalService.GetSupplierList(), "Value", "Display", info?.Purchase?.SupplierID);


            ViewBag.YseNoList =
                new SelectList(YesNo.GetAll(), "value", "Text", info?.Purchase.Activate);
        }
Exemplo n.º 10
0
        public void Update(PurchaseComplex source)
        {
            #region 取資料


            #endregion

            #region 邏輯驗證


            #endregion

            #region 變為Models需要之型別及邏輯資料
            Purchase main = GetPurchaseOnUpdate(source);

            List <PurchaseDetail> children = GetChildOnCreate(main, source);
            #endregion

            #region Models資料庫

            this._Repository.Update(main);

            foreach (PurchaseDetail item in children)
            {
                if (item.SeqNo == 0)
                {
                    this._DetailRepository.Create(item);
                }
                else
                {
                    this._DetailRepository.Update(item);
                }
            }

            this._UnitOfWork.SaveChange();
            #endregion
        }
Exemplo n.º 11
0
        public ActionResult Edit(PurchaseComplex info)
        {
            ResultModel result = new ResultModel();

            try
            {
                #region 驗證Model
                if (!ModelState.IsValid)
                {
                    throw new Exception(ModelStateErrorClass.FormatToString(ModelState));
                }

                // 至少需有一筆明細資料
                if (info.ChildList == null || info.ChildList.Count == 0)
                {
                    ModelState.AddModelError("ChildList", "至少需有一筆明細資料。");
                }
                else
                {
                    var query =
                        info.ChildList
                        .GroupBy(x => x.ProductID)
                        .ToDictionary(x => x.Key, x => x.Count())
                        .Where(x => x.Value > 1)
                        .ToList();

                    CDMS.Web.Common.DuplicateValidator validator =
                        new CDMS.Web.Common.DuplicateValidator(query);

                    if (validator.Message.Count > 0)
                    {
                        foreach (var s in validator.Message)
                        {
                            ModelState.AddModelError("ChildList", s);
                        }
                    }
                }

                if (!ModelState.IsValid)
                {
                    string message = ModelStateErrorClass.FormatToString(ModelState);

                    result.Status  = false;
                    result.Message = message;

                    return(Json(result));
                }
                #endregion

                #region 前端資料變後端用資料ViewModel時用

                #endregion

                #region Service資料庫
                this._PurchaseComplexService.Update(info);
                #endregion

                #region  息頁面設定
                result.Status      = true;
                result.CloseWindow = false;
                result.Url         = Url.Action("Edit", new { id = info.Purchase.PurchaseID });
                result.Message     = "MessageComplete".ToLocalized();
                #endregion
            }
            catch (Exception ex)
            {
                #region  錯誤時錯誤訊息
                result.Status  = false;
                result.Message = ex.Message.ToString();
                #endregion
            }
            return(Json(result));
        }
Exemplo n.º 12
0
        public ActionResult Create()
        {
            var info = new PurchaseComplex()
            {
#if DEBUG
                Purchase = new PurchaseViewModel()
                {
                    PurchaseID    = "0".PadLeft(10, '0'),
                    PurchaseDate  = DateTime.Today,
                    InvoiceAmount = 10000,
                    InvoiceID     = "0".PadLeft(10, '0'),
                    //SupplierID = "000000",
                    //ContactPerson = "聯絡人",
                    //ContactPhone = "聯絡電話",
                    CurrencyID   = "1",
                    ExchangeRate = 1,
                    AccountMonth = "1702",
                    WarehouseID  = "1",
                    Remarks      = "Remarks",
                    PostingTime  = DateTime.Today.AddMonths(1)
                },
                ChildList = new List <PurchaseDetailViewModel>()
                            //ChildList = new List<PurchaseDetailViewModel>() {
                            //    new PurchaseDetailViewModel() {
                            //        SeqNo           = 0 ,
                            //        PurchaseID       = "0000000000",
                            //        ProductID       = "88888888888888888888",
                            //        ProductName     = "產品1",
                            //        PriceKindID     = "1",
                            //        ConditionID     = "1",
                            //        Discount        = 100,
                            //        ForeignPrice    = 30000,
                            //        Price           = 40000,
                            //        Qty             = 1,
                            //        Amount          = 40000,
                            //        Remarks         ="Remarks",
                            //        IsDirty         = true
                            //    },
                            //    new PurchaseDetailViewModel() {
                            //        SeqNo           = 0 ,
                            //        PurchaseID       = "0000000000",
                            //        ProductID       = "99999999999999999999",
                            //        ProductName     = "產品2",
                            //        PriceKindID     = "2",
                            //        ConditionID     = "2",
                            //        Discount        = 100,
                            //        ForeignPrice    = 60000,
                            //        Price           = 80000,
                            //        Qty             = 2,
                            //        Amount          = 160000,
                            //        Remarks         ="Remarks",
                            //        IsDirty         = true
                            //    },
                            //}
#endif
            };

            InitViewBag(info);
            InitChildViewBag(null);
            return(View(info));
        }