Example #1
0
        public static List <EvaluationDisplay> LoadEvaluation(int id)
        {
            FancyStoreEntities db = new FancyStoreEntities();

            var ordernums = db.ProductEvaluations.Where(e => e.ProductID == id);
            List <EvaluationDisplay> evaluations = new List <EvaluationDisplay>();
            EvaluationDisplay        evaluation;

            foreach (var ordernum in ordernums)
            {
                var    user  = db.Users.Find(ordernum.UserID);
                string photo = user.OauthType != "N" ? Encoding.UTF8.GetString(user.Photo.Photo1) : $"data:Image/jpeg;base64,{Convert.ToBase64String(user.Photo.Photo1)}";
                evaluation = new EvaluationDisplay
                {
                    //UserPhoto = Convert.ToBase64String(db.Users.Find(ordernum.UserID).Photo.Photo1),
                    UserPhoto      = photo,
                    Comment        = ordernum.Comment,
                    Grade          = ordernum.Grade,
                    Other          = 5 - ordernum.Grade,
                    OrderNum       = ordernum.OrderNum,
                    EvaluationDate = ordernum.EvaluationDate.ToString("yyyy/MM/dd"),
                    ColorName      = db.ProductColors.Where(c => c.ProductID == ordernum.ProductID).FirstOrDefault().Color.ColorName,
                    SizeName       = db.ProductSizes.Where(s => s.ProductID == ordernum.ProductID).FirstOrDefault().Size.SizeName
                };
                evaluations.Add(evaluation);
            }
            return(evaluations);
        }
Example #2
0
        //動態產生 OrderHeader 資料
        void ResetData()
        {
            dbContext = new FancyStoreEntities(); //為了能刷新資料

            var pm = dbContext.PayMethods;

            PayMethodName.DataSource = pm.ToList();

            var os = dbContext.OrderStatusLists;

            OrderStatusName.DataSource = os.ToList();

            var sp = dbContext.Shippings;

            ShippingName.DataSource = sp.ToList();

            DateTime date_b = DateTime.Parse(dateTimePicker1.Text).Date;
            DateTime date_t = DateTime.Parse(dateTimePicker2.Text).Date;

            var o = from x in dbContext.OrderHeaders.AsEnumerable()
                    where (x.OrderDate >= date_b) && (x.OrderDate <= date_t.AddDays(1)) && x.OrderStatusID == 1
                    select x;

            orderHeaderBindingSource.DataSource = o.ToList();
            orderHeaderDataGridView.DataSource  = orderHeaderBindingSource;
        }
Example #3
0
        public JA_OrdersSearch()
        {
            InitializeComponent();
            FancyStoreEntities db = new FancyStoreEntities();

            Loaddata(db.OrderHeaders.Where(n => n.OrderDate.Year == DateTime.Now.Year &&
                                           n.OrderDate.Month == DateTime.Now.Month
                                           ).OrderByDescending(n => n.OrderDate).ToList());
        }
Example #4
0
        void ResetData()
        {
            dbContext = new FancyStoreEntities();

            var q = dbContext.ProductWashings.Where(x => x.ProductID == cProd.ProductID).Select(x => x);

            productWashingBindingSource.DataSource = q.ToList();
            productWashingDataGridView.DataSource  = productWashingBindingSource;
        }
Example #5
0
        public static IEnumerable <ProductCell> ClassifyResult(SearchFilters searchFilters)
        {
            FancyStoreEntities db = new FancyStoreEntities();

            IQueryable <ProductColor> preproducts = db.ProductColors.AsQueryable();

            var products = ProductMethod.CreateProductCells(preproducts).OrderBy(c => c.ProductID);

            IEnumerable <ProductCell> result;

            result = products.Where(p => p.ProductName.Contains(searchFilters.Keyword));

            if (result.Count() > 0)
            {
                if (searchFilters.CategorySID != null)
                {
                    result = result.Where(p => searchFilters.CategorySID.Contains(p.CategorySID));
                }
                if (searchFilters.ColorID != null)
                {
                    result = result.Where(p => searchFilters.ColorID.Contains(p.ColorID));
                }
                if (searchFilters.SizeID != null)
                {
                    switch (searchFilters.SizeID.Count)
                    {
                    case 1:
                        result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]));
                        break;

                    case 2:
                        result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]) || p.SizeID.Contains(searchFilters.SizeID[1]));
                        break;

                    case 3:
                        result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]) || p.SizeID.Contains(searchFilters.SizeID[1]) || p.SizeID.Contains(searchFilters.SizeID[2]));
                        break;

                    case 4:
                        result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]) || p.SizeID.Contains(searchFilters.SizeID[1]) || p.SizeID.Contains(searchFilters.SizeID[2]) || p.SizeID.Contains(p.SizeID[3]));
                        break;
                    }
                }
                if (searchFilters.MaxSunitPrice != 0)
                {
                    result = result.Where(p => p.SUnitPrice >= searchFilters.MinSunitPrice && p.SUnitPrice <= searchFilters.MaxSunitPrice);
                }
                if (searchFilters.ActivityID != 0)
                {
                    var activityname = db.Activities.Where(a => a.ActivityID == searchFilters.ActivityID && a.EndDate >= DateTime.Now).FirstOrDefault().ActivityName;
                    result = result.Where(p => p.ActivityName == activityname);
                }
            }
            return(result);
        }
        public ActionResult ProductSeOmise(int?id = 1)
        {
            using (db = new FancyStoreEntities())
            {
                var _productseomise = db.ProductColors.Where(P => P.Product.CategorySID == id).Select
                                          (p => new {
                    p.Product.ProductID,
                    p.Product.ProductName,
                    p.ColorID,
                    p.Product.UnitPrice,
                    p.Color.ColorName,
                });

                return(Json(_productseomise.ToList(), JsonRequestBehavior.AllowGet));
            }
        }
Example #7
0
        void ResetData()
        {
            dbContext = new FancyStoreEntities();

            var s = dbContext.VW_EW_ProductSize;

            ProductSizeName.DataSource = s.ToList();

            var c = dbContext.VW_EW_ProductColor;

            ProductColorName.DataSource = c.ToList();

            var q = dbContext.ProductStocks.Where(x => x.ProductID == cProd.ProductID).Select(x => x);

            productStockBindingSource.DataSource = q.ToList();
            productStockDataGridView.DataSource  = productStockBindingSource;
        }
Example #8
0
        //動態產生products資料
        void ResetData()
        {
            dbContext = new FancyStoreEntities(); //為了能刷新資料

            var c = dbContext.VW_EW_CategorySML;

            vWEWCategorySMLBindingSource1.DataSource = c.ToList();  //DataGridView中的Category

            var s = dbContext.Suppliers;

            SupplierName.DataSource = s.ToList();

            DateTime date_b = DateTime.Parse(dateTimePicker1.Text).Date;
            DateTime date_t = DateTime.Parse(dateTimePicker2.Text).Date;

            var q = from x in dbContext.Products.AsEnumerable()
                    where ((x.ProductInDate >= date_b) && (x.ProductInDate <= date_t.AddDays(1))) ||
                    ((x.ProductOutDate >= date_b) && (x.ProductOutDate <= date_t.AddDays(1)))
                    select x;

            ;

            if (txtProductName.Text != "")
            {
                q = from x in q
                    where x.ProductName.Contains(txtProductName.Text)
                    select x;
            }

            int cID;

            try
            {
                cID = (int)cbCategory.SelectedValue;
                q   = q.Where(x => x.CategorySID == cID).Select(x => x);
            }
            catch (NullReferenceException ex)
            {
                Debug.WriteLine(ex);
            }

            productBindingSource.DataSource = q.ToList();
            productDataGridView.DataSource  = productBindingSource;
        }
Example #9
0
        public static List <CartItem> Cart(int id)
        {
            FancyStoreEntities db = new FancyStoreEntities();
            //回傳要顯示的購物車資料
            List <CartItem> cart;
            var             usercart = db.Carts.Where(c => c.UserID == id).ToList();

            cart = new List <CartItem>();
            CartItem cartItem;

            foreach (var uitem in usercart)
            {
                cartItem = new CartItem()
                {
                    ProductID      = uitem.ProductID,
                    ProductName    = db.Products.Find(uitem.ProductID).ProductName,
                    ProductColorID = uitem.ProductColorID,
                    ColorID        = db.ProductColors.Find(uitem.ProductColorID).Color.ColorID,
                    ColorName      = db.ProductColors.Find(uitem.ProductColorID).Color.ColorName,
                    ProductSizeID  = uitem.ProductSizeID,
                    SizeID         = db.ProductSizes.Find(uitem.ProductSizeID).Size.SizeID,
                    SizeName       = db.ProductSizes.Find(uitem.ProductSizeID).Size.SizeName,
                    OrderQTY       = uitem.Quantity,
                    UnitPrice      = uitem.UnitPrice,
                };

                var stock = db.ProductStocks.Where(s => s.ProductID == cartItem.ProductID && s.ProductSizeID == cartItem.ProductSizeID && s.ProductColorID == cartItem.ProductColorID).FirstOrDefault().StockQTY;

                cartItem.Enough = (stock < cartItem.OrderQTY) ? false : true;

                var inactivity = db.ActivityProducts.Where(a => a.ProductID == uitem.ProductID).ToList();
                if (inactivity.Count() > 0)
                {
                    cartItem.SUnitPrice   = Convert.ToInt32(Math.Floor(inactivity.First().Activity.DiscountMethod.Discount *uitem.UnitPrice));
                    cartItem.DiscountID   = inactivity.First().Activity.DiscountID;
                    cartItem.ActivityName = inactivity.First().Activity.ActivityName;
                }
                cart.Add(cartItem);
            }
            return(cart);
        }
Example #10
0
        void ResetData()
        {
            dbContext = new FancyStoreEntities();

            var p = dbContext.Products;

            productBindingSource.DataSource = p.ToList();

            var c = dbContext.VW_EW_ProductColor;

            vWEWProductColorBindingSource.DataSource = c.ToList();

            var s = dbContext.VW_EW_ProductSize;

            vWEWProductSizeBindingSource.DataSource = s.ToList();

            var q = dbContext.ProductStocks.Where(x => x.StockQTY < x.MinStock).OrderBy(x => x.StockQTY);

            productStockBindingSource.DataSource = q.ToList();
            productStockDataGridView.DataSource  = productStockBindingSource;
        }
Example #11
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            db = new FancyStoreEntities();
            var 年月銷售比 = db.OrderDetails.AsEnumerable().Where(n => n.CreateDate.Value.Year == ((Int32)((ComboBox)sender).SelectedItem) &&
                                                             n.OrderHeader.OrderStatusID != 3)
                        .GroupBy(n => n.CreateDate.Value.Month).Select
                            (n => new { 月 = $"{n.Key}月", 月銷售額 = n.Sum(nn => nn.UnitPrice * nn.OrderQTY).ToString("C2") }).OrderByDescending(n => n.月銷售額);

            this.chart4.DataSource              = 年月銷售比;
            this.chart4.Series[0].XValueMember  = "月";
            this.chart4.Series[0].YValueMembers = "月銷售額";
            this.chart4.Series[0].Name          = "月銷售額";
            this.chart4.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;

            this.chart5.DataSource              = 年月銷售比;
            this.chart5.Series[0].XValueMember  = "月";
            this.chart5.Series[0].YValueMembers = "月銷售額";
            this.chart5.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;

            label1.Text = $"{年月銷售比.First().月}銷售額在今年銷售最高:{年月銷售比.First().月銷售額}";
            label2.Text = $"{年月銷售比.Last().月}銷售額在今年銷售最低:{年月銷售比.Last().月銷售額}";
        }
Example #12
0
        public static IQueryable <ProductCell> CreateProductCells(IQueryable <ProductColor> preproducts)
        {
            FancyStoreEntities db = new FancyStoreEntities();

            var products = preproducts.Where(p => p.Product.ProductInDate <= DateTime.Now && p.Product.ProductOutDate >= DateTime.Now).Select(p => new ProductCell
            {
                ProductID     = p.Product.ProductID,
                ProductName   = p.Product.ProductName,
                CategorySID   = p.Product.CategorySID,
                ColorID       = p.ColorID,
                SizeID        = p.Product.ProductSizes.Select(s => s.SizeID).ToList(),
                R             = p.Color.R,
                G             = p.Color.G,
                B             = p.Color.B,
                UnitPrice     = p.Product.UnitPrice,
                SUnitPrice    = p.Product.ActivityProducts.Where(a => a.ProductID == p.ProductID && a.Activity.EndDate >= DateTime.Now).Count() > 0 ? Math.Floor(p.Product.ActivityProducts.Where(a => a.ProductID == p.ProductID && a.Activity.EndDate >= DateTime.Now).FirstOrDefault().Activity.DiscountMethod.Discount *p.Product.UnitPrice) : p.Product.UnitPrice,
                ProductInDate = p.Product.ProductInDate,
                ActivityName  = p.Product.ActivityProducts.Where(a => a.Activity.EndDate >= DateTime.Now).FirstOrDefault().Activity.ActivityName
            });

            return(products);
        }
Example #13
0
        int currentIndex; //目前位置

        //動態產生products資料
        void ResetData()
        {
            dbContext = new FancyStoreEntities(); //為了能刷新資料

            var s = dbContext.Suppliers.OrderBy(x => x.SupplierID).ToList();

            cbSupplierName.DataSource = s;

            var q = dbContext.Products.Select(x => x);

            int pID;

            if (int.TryParse(txtProductID.Text, out pID))
            {
                q = q.Where(x => x.ProductID == pID).Select(x => x);
            }
            else
            {
                txtProductID.Text = "";
            }
            if (txtProductName.Text != "")
            {
                q = from x in q
                    where x.ProductName.Contains(txtProductName.Text)
                    select x;
            }
            try
            {
                pID = (int)cbCategory.SelectedValue;
                q   = q.Where(x => x.CategorySID == pID).Select(x => x);
            }
            catch (NullReferenceException ex)
            {
                Debug.WriteLine(ex);
            }
            productBindingSource.DataSource = q.ToList();
            productDataGridView.DataSource  = productBindingSource;
        }
Example #14
0
        public static List <CartItem> Cart(int id)
        {
            using (FancyStoreEntities db = new FancyStoreEntities())
            {
                //回傳要顯示的購物車資料
                List <CartItem> cart;
                var             usercart = db.Carts.Where(c => c.UserID == id).ToList();
                cart = new List <CartItem>();
                CartItem cartItem;

                foreach (var uitem in usercart)
                {
                    cartItem = new CartItem()
                    {
                        ProductID      = uitem.ProductID,
                        ProductName    = db.Products.Find(uitem.ProductID).ProductName,
                        ProductColorID = uitem.ProductColorID,
                        ColorID        = db.ProductColors.Find(uitem.ProductColorID).Color.ColorID,
                        ColorName      = db.ProductColors.Find(uitem.ProductColorID).Color.ColorName,
                        ProductSizeID  = uitem.ProductSizeID,
                        SizeID         = db.ProductSizes.Find(uitem.ProductSizeID).Size.SizeID,
                        SizeName       = db.ProductSizes.Find(uitem.ProductSizeID).Size.SizeName,
                        OrderQTY       = uitem.Quantity,
                        UnitPrice      = uitem.UnitPrice,
                    };
                    var inactivity = db.ActivityProducts.Where(a => a.ProductID == uitem.ProductID).ToList();
                    if (inactivity.Count() > 0)
                    {
                        cartItem.SUnitPrice   = Convert.ToInt32(inactivity.First().Activity.DiscountMethod.Discount *uitem.UnitPrice);
                        cartItem.DiscountID   = inactivity.First().Activity.DiscountID;
                        cartItem.ActivityName = inactivity.First().Activity.ActivityName;
                    }
                    cart.Add(cartItem);
                }
                return(cart);
            }
        }
Example #15
0
        public static User UserDetail()
        {
            FancyStoreEntities dbb = new FancyStoreEntities();

            return(dbb.Users.Where(n => n.UserID == UserID).First());
        }
Example #16
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            db = new FancyStoreEntities();
            var 每日會員成長 = db.Users.AsEnumerable().GroupBy(n => n.RegistrationDate.ToShortDateString())
                         .Select(n => new { 天 = n.Key, 人數 = n.Count() }).ToList();

            this.chart1.DataSource              = 每日會員成長;
            this.chart1.Series[0].XValueMember  = "天";
            this.chart1.Series[0].YValueMembers = "人數";
            this.chart1.Series[0].Name          = "人數";
            this.chart1.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            var 性別占比 = Cls_JA_Member.db.Users.GroupBy(n => n.Gender == true ? "男性" : "女性").
                       Select(n => new { 性別 = n.Key, 人數 = n.Count() }).ToList();

            this.chart2.DataSource              = 性別占比;
            this.chart2.Series[0].XValueMember  = "性別";
            this.chart2.Series[0].YValueMembers = "人數";
            this.chart2.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;

            var 地區人數 = db.Users.GroupBy(n => n.Region.City.CityName)
                       .Select(n => new { 地區 = n.Key, 人數 = n.Count() }).ToList();

            this.chart3.DataSource              = 地區人數;
            this.chart3.Series[0].XValueMember  = "地區";
            this.chart3.Series[0].YValueMembers = "人數";
            this.chart3.Series[0].Name          = "人數";
            this.chart3.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;

            var year = db.OrderDetails
                       .OrderBy(n => n.CreateDate.Value.Year).Select(n => n.CreateDate.Value.Year)
                       .Distinct().ToList();

            this.comboBox1.DataSource = year;

            var 中分類銷售比 = db.OrderDetails.AsEnumerable().Where(n => n.OrderHeader.OrderStatusID != 3)
                         .GroupBy(n => n.Product.CategorySmall.CategoryMiddle.CategoryMName).Select
                             (n => new { 中分類 = n.Key, 銷售額 = n.Sum(nn => nn.UnitPrice * nn.OrderQTY).ToString("C2") }).OrderByDescending(n => n.銷售額);

            this.chart6.DataSource              = 中分類銷售比;
            this.chart6.Series[0].XValueMember  = "中分類";
            this.chart6.Series[0].YValueMembers = "銷售額";
            this.chart6.Series[0].Name          = "銷售額";
            this.chart6.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;


            var 小分類銷售比 = db.OrderDetails.AsEnumerable().Where(n => n.OrderHeader.OrderStatusID != 3)
                         .GroupBy(n => n.Product.CategorySmall.CategorySName).Select
                             (n => new { 小分類 = n.Key, 銷售額 = n.Sum(nn => nn.UnitPrice * nn.OrderQTY).ToString("C2") }).OrderByDescending(n => n.銷售額);

            this.chart7.DataSource              = 小分類銷售比;
            this.chart7.Series[0].XValueMember  = "小分類";
            this.chart7.Series[0].YValueMembers = "銷售額";
            this.chart7.Series[0].Name          = "銷售額";
            this.chart7.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;



            var 供應商 = db.OrderDetails.AsEnumerable().Where(n => n.OrderHeader.OrderStatusID != 3)
                      .GroupBy(n => n.Product.Supplier.SupplierName).Select
                          (n => new { 供應商 = n.Key, 銷售額 = n.Sum(nn => nn.UnitPrice * nn.OrderQTY).ToString("C2") }).OrderByDescending(n => n.銷售額);

            this.chart8.DataSource              = 供應商;
            this.chart8.Series[0].XValueMember  = "供應商";
            this.chart8.Series[0].YValueMembers = "銷售額";
            this.chart8.Series[0].Name          = "銷售額";
            this.chart8.Series[0].ChartType     = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
        }
Example #17
0
        private void UI_SK_RW_BornOrder_Click(object sender, EventArgs e)
        {
            bool UI_SK_MC_OrderQTY_Checker = true;

            for (int i = 0; i <= Cls_Utility.Class1.CartList.Count - 1; i++)
            {
                j = Cls_Utility.Class1.CartList[i].ProductID;
                var q = dbContext_FSE.ProductStocks.AsEnumerable()
                        .Where(ps => ps.ProductID == Cls_Utility.Class1.CartList[i].ProductID &&
                               ps.ProductColorID == Cls_Utility.Class1.CartList[i].ProductColorID &&
                               ps.ProductSizeID == Cls_Utility.Class1.CartList[i].ProductSizeID)
                        .FirstOrDefault();
                tempQTY_SearchStockQTY = q.StockQTY;

                if (Cls_Utility.Class1.CartList[i].Qty > q.StockQTY)
                {
                    MessageBox.Show("庫存不足,請降低數量", "System Alarm");
                    UI_SK_MC_OrderQTY_Checker = false;
                    return;
                }
                else
                {
                }
                //using (var dbContext_FSE = new FancyStoreEntities())
                //{
                //    var q2 = (from ps in dbContext_FSE.ProductStocks.AsEnumerable()
                //             where ps.ProductID == Cls_Utility.Class1.CartList[i].ProductID &&
                //             ps.ProductColorID == Cls_Utility.Class1.CartList[i].ProductColorID &&
                //             ps.ProductSizeID == Cls_Utility.Class1.CartList[i].ProductSizeID
                //             select ps).FirstOrDefault();

                //    q2.StockQTY = tempQTY_SearchStockQTY - Cls_Utility.Class1.CartList[i].Qty;

                //    dbContext_FSE.SaveChanges();
                //}
            }

            //for (int i = 0; i <= Cls_Utility.Class1.CartList.Count - 1; i++)
            //{


            //}

            int id;

            using (var dbContext_FSE = new FancyStoreEntities())
            {
                OrderHeader OH = new OrderHeader();

                OH.OrderNum      = $"GD{DateTime.Now:yyyyMMddHHmmss}{Cls_JA_Member.UserID}";
                OH.OrderDate     = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                OH.ShipDate      = Convert.ToDateTime(DateTime.Now.AddDays(15).ToShortDateString());
                OH.UserID        = Cls_JA_Member.UserID;
                OH.PayMethodID   = Cls_SK_NormalClass.UI_SK_CP_PM_SQL;
                OH.ShippingID    = 1;  /*Cls_SK_NormalClass.UI_SK_CP_SP_SQL*/
                OH.DiscountID    = 3;
                OH.OrderStatusID = 1;
                OH.OrderAmount   = Cls_SK_NormalClass.UI_SK_CP_FinalPay_int;
                OH.CreateDate    = DateTime.Now;

                dbContext_FSE.OrderHeaders.Add(OH);
                dbContext_FSE.SaveChanges();
                id = OH.OrderID;
                MessageBox.Show($"OrderID={id}");
            }


            for (int i = 0; i <= Cls_Utility.Class1.CartList.Count - 1; i++)
            {
                using (var dbContext_FSE = new FancyStoreEntities())
                {
                    OrderDetail OD = new OrderDetail
                    { /*OrderDetailID = 1,*/
                        OrderID        = id,
                        ProductID      = Cls_Utility.Class1.CartList[i].ProductID,
                        ProductColorID = Cls_Utility.Class1.CartList[i].ProductColorID,
                        ProductSizeID  = Cls_Utility.Class1.CartList[i].ProductSizeID,
                        UnitPrice      = Convert.ToInt32(Cls_Utility.Class1.CartList[i].UnitPrice),
                        OrderQTY       = Cls_Utility.Class1.CartList[i].Qty,
                        CreateDate     = DateTime.Now
                    };

                    dbContext_FSE.OrderDetails.Add(OD);
                    dbContext_FSE.SaveChanges();
                }
            }
            #endregion 參數寫入 OrderDetail, OrderHeader, 庫存檢查

            #region 寫入shipping
            //using (var dbContext_FSE = new FancyStoreEntities())
            //{
            //    Shipping SH = new Shipping
            //    {
            //        ShippingName=UI_SK_CP_SP_SentWay_Str,
            //        Phone=UI_SK_CP_SP_Phone_Str,
            //        Fax=UI_SK_CP_SP_Fax_Str,
            //        Email= UI_SK_CP_SP_Email_Str,
            //        Address= UI_SK_CP_SP_Address_Str,
            //        CreateDate= DateTime.Now
            //    };

            //    dbContext_FSE.Shippings.Add(SH);
            //    dbContext_FSE.SaveChanges();
            //}
            #endregion 寫入shipping
            Cls_Utility.Class1.CartList.Clear();
            this.Close();
        }
Example #18
0
        private void orderHeaderDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            switch (e.ColumnIndex)
            {
            case 5:          //Click 出貨
                int orderID = ((OrderHeader)orderHeaderBindingSource.Current).OrderID;

                //判斷庫存是否足夠
                if (dbContext.VW_EW_OrderDetail.Where(x => x.OrderID == orderID).Any(x => x.Balance < 0))
                {
                    MessageBox.Show($"本張訂單有部份產品庫存不足, 請補貨後再出貨 !");
                    return;
                }

                var od = dbContext.VW_EW_OrderDetail.Where(x => x.OrderID == orderID);

                FancyStoreEntities dbContext1 = new FancyStoreEntities();     //為了能 Update 資料

                foreach (var x in od)
                {
                    try
                    {
                        var q = dbContext1.ProductStocks
                                .Where(p => p.ProductID == x.ProductID && p.ProductColorID == x.ProductColorID && p.ProductSizeID == x.ProductSizeID)
                                .FirstOrDefault();

                        q.StockQTY = (int)x.Balance;

                        dbContext1.SaveChanges();

                        ResetData();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                        MessageBox.Show($"更新 [庫存] 失敗, 請找系統管理員幫忙處理 !");
                        return;
                    }
                }

                try
                {
                    var oh = dbContext.OrderHeaders.Find(orderID);
                    oh.OrderStatusID = 2;

                    if (shippingID > 0)
                    {
                        oh.ShippingID = shippingID;
                    }
                    shippingID = 0;      //必須歸0, 否則下一筆會自動承繼上筆的資料
                    dbContext.SaveChanges();
                    MessageBox.Show($"[出貨] 完成 !");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    MessageBox.Show($"更新 [訂單] 失敗, 請找系統管理員幫忙處理 !");
                    return;
                }

                ResetData();
                break;
            }
        }