Ejemplo n.º 1
0
        private void context_SavingChanges(Object sender, EventArgs e)
        {
            string NewProductID, OldProductID;
            int    NewQuantity, OldQuantity;

            //取得所有新增的存貨異動單明細
            foreach (var AddedEntry in context.ObjectStateManager
                     .GetObjectStateEntries(EntityState.Added))
            {
                if (!AddedEntry.IsRelationship)
                {
                    if (AddedEntry.Entity is TransferDetails)
                    {
                        NewProductID = ((TransferDetails)(AddedEntry.Entity)).ProductID;
                        //判斷異動別
                        if (transferTypeTextBox.Text == "1")
                        {
                            //異動別=入庫,要更新庫存量
                            XIN.IncStock(context, NewProductID,
                                         ((TransferDetails)(AddedEntry.Entity)).Quantity);
                        }
                        else
                        {
                            //異動別=出庫,要更新庫存量
                            XIN.DecStock(context, NewProductID,
                                         ((TransferDetails)(AddedEntry.Entity)).Quantity);
                        }
                    }
                }
            }
            //取得所有修改的存貨異動單明細
            foreach (var ModifiedEntry in context.ObjectStateManager
                     .GetObjectStateEntries(EntityState.Modified))
            {
                if (!ModifiedEntry.IsRelationship)
                {
                    if (ModifiedEntry.Entity is TransferDetails)
                    {
                        //取得目前的商品編號與數量
                        CurrentValueRecord curr = ModifiedEntry.CurrentValues;
                        NewProductID = (string)(curr.GetValue(
                                                    curr.GetOrdinal("ProductID")));
                        NewQuantity = (int)
                                      (curr.GetValue(curr.GetOrdinal("Quantity")));
                        //取得原來的商品編號與數量
                        OriginalValueRecord org =
                            ModifiedEntry.GetUpdatableOriginalValues();
                        OldProductID = (string)
                                       (org.GetValue(curr.GetOrdinal("ProductID")));
                        OldQuantity = (int)(org.GetValue(curr.GetOrdinal("Quantity")));
                        //判斷異動別
                        if (transferTypeTextBox.Text == "1")
                        {
                            //異動別=入庫
                            //增加目前的商品編號的庫存量
                            XIN.IncStock(context, NewProductID, NewQuantity);
                            //減少原來的商品編號的庫存量
                            XIN.DecStock(context, OldProductID, OldQuantity);
                        }
                        else
                        {
                            //異動別=出庫
                            //增加原來的商品編號的庫存量
                            XIN.IncStock(context, OldProductID, OldQuantity);
                            //減少目前的商品編號的庫存量
                            XIN.DecStock(context, NewProductID, NewQuantity);
                        }
                    }
                }
            }
            //取得所有刪除的存貨異動單明細
            foreach (var DeletedEntry in context.ObjectStateManager
                     .GetObjectStateEntries(EntityState.Deleted))
            {
                if (!DeletedEntry.IsRelationship)
                {
                    if (DeletedEntry.Entity is TransferDetails)
                    {
                        OldProductID = ((TransferDetails)
                                        (DeletedEntry.Entity)).ProductID;
                        //判斷異動別
                        if (DeleteTransferType == "1")
                        {
                            //異動別=入庫,更新庫存量
                            XIN.DecStock(context, OldProductID,
                                         ((TransferDetails)(DeletedEntry.Entity)).Quantity);
                        }
                        else
                        {
                            //異動別=出庫,更新庫存量
                            XIN.IncStock(context, OldProductID,
                                         ((TransferDetails)(DeletedEntry.Entity)).Quantity);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void context_SavingChanges(Object sender, EventArgs e)
        {
            string NewProductID, OldProductID;
            int    NewQuantity, OldQuantity;

            //取得所有新增的出貨單明細
            foreach (var AddedEntry in context.ObjectStateManager
                     .GetObjectStateEntries(EntityState.Added))
            {
                if (!AddedEntry.IsRelationship)
                {
                    if (AddedEntry.Entity is DeliveryDetails)
                    {
                        NewProductID = ((DeliveryDetails)(AddedEntry.Entity)).ProductID;
                        //判斷出貨別
                        if (deliveryTypeTextBox.Text == "1")
                        {
                            //出貨別=出貨,要更新庫存量與更新商品的最近出貨日
                            //更新庫存量
                            XIN.DecStock(context, NewProductID,
                                         ((DeliveryDetails)(AddedEntry.Entity)).Quantity);
                            //更新商品的最近出貨日
                            var qry = (from P in context.Product
                                       where P.ProductID == NewProductID
                                       select P).FirstOrDefault();
                            qry.LastDeliveryDate = Convert.ToDateTime(
                                deliveryDateTextBox.Text);
                        }
                        else
                        {
                            //出貨別=出貨退回,只要更新庫存量
                            XIN.IncStock(context, NewProductID,
                                         ((DeliveryDetails)(AddedEntry.Entity)).Quantity);
                        }
                    }
                }
            }
            //取得所有修改的出貨單明細
            foreach (var ModifiedEntry in context.ObjectStateManager
                     .GetObjectStateEntries(EntityState.Modified))
            {
                if (!ModifiedEntry.IsRelationship)
                {
                    if (ModifiedEntry.Entity is DeliveryDetails)
                    {
                        //取得目前的商品編號與數量
                        CurrentValueRecord curr = ModifiedEntry.CurrentValues;
                        NewProductID = (string)(curr.GetValue(
                                                    curr.GetOrdinal("ProductID")));
                        NewQuantity = (int)
                                      (curr.GetValue(curr.GetOrdinal("Quantity")));
                        //取得原來的商品編號與數量
                        OriginalValueRecord org =
                            ModifiedEntry.GetUpdatableOriginalValues();
                        OldProductID = (string)
                                       (org.GetValue(curr.GetOrdinal("ProductID")));
                        OldQuantity = (int)(org.GetValue(curr.GetOrdinal("Quantity")));
                        //判斷出貨別
                        if (deliveryTypeTextBox.Text == "1")
                        {
                            //出貨別=出貨,要更新庫存量與更新商品的最近出貨日
                            //增加原來的商品編號的庫存量
                            XIN.IncStock(context, OldProductID, OldQuantity);
                            //減少目前的商品編號的庫存量
                            XIN.DecStock(context, NewProductID, NewQuantity);
                            //更新商品的最近出貨日
                            var qry = (from P in context.Product
                                       where P.ProductID == NewProductID
                                       select P).FirstOrDefault();
                            qry.LastDeliveryDate = Convert.ToDateTime(
                                deliveryDateTextBox.Text);
                        }
                        else
                        {
                            //出貨別=出貨退回,只要更新庫存量
                            //增加目前的商品編號的庫存量
                            XIN.IncStock(context, NewProductID, NewQuantity);
                            //減少原來的商品編號的庫存量
                            XIN.DecStock(context, OldProductID, OldQuantity);
                        }
                    }
                }
            }
            //取得所有刪除的出貨單明細
            foreach (var DeletedEntry in context.ObjectStateManager
                     .GetObjectStateEntries(EntityState.Deleted))
            {
                if (!DeletedEntry.IsRelationship)
                {
                    if (DeletedEntry.Entity is DeliveryDetails)
                    {
                        OldProductID = ((DeliveryDetails)
                                        (DeletedEntry.Entity)).ProductID;
                        //判斷出貨別
                        if (DeleteDeliveryType == "1")
                        {
                            //出貨別=出貨,要更新庫存量
                            //更新庫存量
                            XIN.IncStock(context, OldProductID,
                                         ((DeliveryDetails)(DeletedEntry.Entity)).Quantity);
                        }
                        else
                        {
                            //出貨別=出貨退回,只要更新庫存量
                            XIN.DecStock(context, OldProductID,
                                         ((DeliveryDetails)(DeletedEntry.Entity)).Quantity);
                        }
                    }
                }
            }
        }