예제 #1
0
        private void searchToolStripButton_Click(object sender, EventArgs e)
        {
            IList result = searchToolStripTextBox.Text == string.Empty ? new ArrayList() : r_po.Search(searchToolStripTextBox.Text);

            if (result.Count == 1)
            {
                m_po          = (PurchaseOrder)result[0];
                m_po          = (PurchaseOrder)r_po.Get(m_po.ID);
                m_po.EMPLOYEE = (Employee)r_employee.GetById(m_po.EMPLOYEE);
                m_po.CURRENCY = (Currency)r_ccy.GetById(m_po.CURRENCY);
                m_po.DIVISION = (Division)r_division.GetById(m_po.DIVISION);
                m_po.TOP      = (TermOfPayment)r_top.GetById(m_po.TOP);
                m_po.TAX      = m_po.TAX == null ? null : (Tax)r_tax.GetById(m_po.TAX);
                m_po.SUPPLIER = (Supplier)r_sup.GetById(m_po.SUPPLIER);
                setEditMode(EditMode.View);
                loadData();
                setEnableForm(false);
            }
            else
            {
                using (SearchPurchaseOrderForm frm = new SearchPurchaseOrderForm(searchToolStripTextBox.Text, result))
                {
                    frm.ShowDialog();
                    if (frm.PURCHASE_ORDER == null)
                    {
                        return;
                    }
                    else
                    {
                        m_po          = frm.PURCHASE_ORDER;
                        m_po          = (PurchaseOrder)r_po.Get(m_po.ID);
                        m_po.EMPLOYEE = (Employee)r_employee.GetById(m_po.EMPLOYEE);
                        m_po.CURRENCY = (Currency)r_ccy.GetById(m_po.CURRENCY);
                        m_po.DIVISION = (Division)r_division.GetById(m_po.DIVISION);
                        m_po.TOP      = (TermOfPayment)r_top.GetById(m_po.TOP);
                        m_po.TAX      = m_po.TAX == null ? null : (Tax)r_tax.GetById(m_po.TAX);
                        m_po.SUPPLIER = (Supplier)r_sup.GetById(m_po.SUPPLIER);
                        setEditMode(EditMode.View);
                        loadData();
                        setEnableForm(false);
                        //setEditMode(EditMode.View);
                    }
                }
            }
        }
예제 #2
0
        private void TestCreate()
        {
            PurchaseOrder   po  = (PurchaseOrder)m_poRep.Get(5);
            GoodReceiveNote grn = new GoodReceiveNote();

            grn.CODE                  = "GRN001";
            grn.EMPLOYEE              = new Employee(1);
            grn.EVENT_STATUS          = EventStatus.Entry;
            grn.NOTES                 = "TEST IN GRN";
            grn.NOTICE_DATE           = DateTime.Today;
            grn.STOCK_CARD_ENTRY_TYPE = StockCardEntryType.GoodReceiveNote;
            grn.TRANSACTION_DATE      = DateTime.Today;

            GoodReceiveNoteItem grni1 = new GoodReceiveNoteItem();

            grni1.EVENT                 = grn;
            grni1.NOTES                 = "TEST GRN ITEM 1";
            grni1.PART                  = new Part(9070);
            grni1.PO_ITEM               = (PurchaseOrderItem)po.EVENT_ITEMS[0];
            grni1.QYTAMOUNT             = 13000;
            grni1.RETURNED_AMOUNT       = 0;
            grni1.STOCK_CARD_ENTRY_TYPE = StockCardEntryType.GoodReceiveNote;
            grni1.UNIT                  = new Unit(1);
            grni1.WAREHOUSE             = new Warehouse(1);

            GoodReceiveNoteItem grni2 = new GoodReceiveNoteItem();

            grni2.EVENT                 = grn;
            grni2.NOTES                 = "TEST GRN ITEM 1";
            grni2.PART                  = new Part(9071);
            grni2.PO_ITEM               = (PurchaseOrderItem)po.EVENT_ITEMS[1];
            grni2.QYTAMOUNT             = 1254;
            grni2.RETURNED_AMOUNT       = 0;
            grni2.STOCK_CARD_ENTRY_TYPE = StockCardEntryType.GoodReceiveNote;
            grni2.UNIT                  = new Unit(1);
            grni2.WAREHOUSE             = new Warehouse(1);

            grn.EVENT_ITEMS.Add(grni1);
            grn.EVENT_ITEMS.Add(grni2);

            m_grnRep.Save(grn);
        }
        public void CreateOrUpdate(PurchaseOrderContract purchaseOrderContract)
        {
            var purchaseorder = PurchaseOrderRepository.Get(purchaseOrderContract.Id);

            if (purchaseorder != null)
            {
                purchaseorder.Code = purchaseOrderContract.Code;
                //purchaseorder.CreationDate = purchaseOrderContract.CreationDate;
                purchaseorder.Title = purchaseOrderContract.Title;
                for (int i = 0; i < purchaseOrderContract.PurchaseOrderItems.Count; i++)
                {
                    var temp = purchaseOrderContract.PurchaseOrderItems[i];
                    if (purchaseorder.PurcahseOrderItems.Any(p => p.Id == temp.Id))
                    {
                        var indatabasepurchaseorder = purchaseorder.PurcahseOrderItems.FirstOrDefault(p => p.Id == temp.Id);
                        indatabasepurchaseorder.NetPrice   = temp.NetPrice;
                        indatabasepurchaseorder.Quantity   = temp.Quantity;
                        indatabasepurchaseorder.TotalPrice = temp.TotalPrice;
                        indatabasepurchaseorder.UnitPrice  = temp.UnitPrice;
                        indatabasepurchaseorder.Item       = ItemRepository.Get(temp.ItemId);
                        indatabasepurchaseorder.Rack       = RackRepository.Get(temp.RackId);
                    }
                    else
                    {
                        var purchaseorderitem = new PurchaseOrderItem();
                        purchaseorderitem.NetPrice   = temp.NetPrice;
                        purchaseorderitem.Quantity   = temp.Quantity;
                        purchaseorderitem.TotalPrice = temp.TotalPrice;
                        purchaseorderitem.UnitPrice  = temp.UnitPrice;
                        purchaseorderitem.Item       = ItemRepository.Get(temp.ItemId);
                        purchaseorderitem.Rack       = RackRepository.Get(temp.RackId);


                        purchaseorder.PurcahseOrderItems.Add(purchaseorderitem);
                    }
                }
                for (int i = 0; i < purchaseorder.PurcahseOrderItems.Count; i++)
                {
                    var temp = purchaseorder.PurcahseOrderItems.ToArray()[i];
                    if (!purchaseOrderContract.PurchaseOrderItems.Any(p => p.Id == temp.Id))
                    {
                        purchaseorder.PurcahseOrderItems.Remove(temp);
                    }
                }

                PurchaseOrderRepository.Update(purchaseorder);
            }
            else
            {
                purchaseorder              = new PurchaseOrder();
                purchaseorder.Code         = purchaseOrderContract.Code;
                purchaseorder.CreationDate = purchaseOrderContract.CreationDate;
                purchaseorder.Title        = purchaseOrderContract.Title;
                for (int i = 0; i < purchaseOrderContract.PurchaseOrderItems.Count; i++)
                {
                    var temp = purchaseOrderContract.PurchaseOrderItems[i];

                    var indatabaepurchaseorder = purchaseorder.PurcahseOrderItems.FirstOrDefault(p => p.Id == temp.Id);
                    indatabaepurchaseorder.NetPrice   = temp.NetPrice;
                    indatabaepurchaseorder.Quantity   = temp.Quantity;
                    indatabaepurchaseorder.TotalPrice = temp.TotalPrice;
                    indatabaepurchaseorder.UnitPrice  = temp.UnitPrice;
                    indatabaepurchaseorder.Item       = ItemRepository.Get(temp.ItemId);
                    indatabaepurchaseorder.Rack       = RackRepository.Get(temp.RackId);
                }

                PurchaseOrderRepository.Insert(purchaseorder);
            }
        }
        public void Delete(PurchaseOrderContract purchaseOrderContract)
        {
            var purchaseorder = PurchaseOrderRepository.Get(purchaseOrderContract.Id);

            PurchaseOrderRepository.Delete(purchaseorder);
        }
        public void CreateAndUpdatePurchaseOrder(PurchaseOrderContract purchaseOrderContract)
        {
            //db
            var purchaseOrder = PurchaseOrderRepository.Get(purchaseOrderContract.Id);

            if (purchaseOrder != null)
            {
                // Update Order
                purchaseOrder.Title = purchaseOrderContract.Title;

                for (int i = 0; i < purchaseOrderContract.PurchaseOrderItemContracts.Count; i++)
                {
                    var temp = purchaseOrderContract.PurchaseOrderItemContracts[i];
                    if (purchaseOrder.PurchaseOrderItems.Any(x => x.Id == temp.Id))
                    {
                        //Update OrderItem
                        var InDatabaseOrderItem = purchaseOrder.PurchaseOrderItems.FirstOrDefault(x => x.Id == temp.Id);
                        InDatabaseOrderItem.NetPrice   = temp.NetPrice;
                        InDatabaseOrderItem.Quantity   = temp.Quantity;
                        InDatabaseOrderItem.UnitPrice  = temp.UnitPrice;
                        InDatabaseOrderItem.TotalPrice = temp.TotalPrice;
                        InDatabaseOrderItem.Item       = IitemRepository.Get(temp.ItemId);
                        InDatabaseOrderItem.Rack       = IRackRepository.Get(temp.RackId);
                    }
                    else
                    {
                        //Create OrderItem
                        var InDatabaseOrderItem = new PurchaseOrderItem();

                        InDatabaseOrderItem.NetPrice   = temp.NetPrice;
                        InDatabaseOrderItem.Quantity   = temp.Quantity;
                        InDatabaseOrderItem.UnitPrice  = temp.UnitPrice;
                        InDatabaseOrderItem.TotalPrice = temp.TotalPrice;
                        InDatabaseOrderItem.Item       = IitemRepository.Get(temp.ItemId);
                        InDatabaseOrderItem.Rack       = IRackRepository.Get(temp.RackId);

                        purchaseOrder.PurchaseOrderItems.Add(InDatabaseOrderItem);
                    }
                }

                for (int i = 0; i < purchaseOrder.PurchaseOrderItems.Count; i++) //db
                {
                    var temp = purchaseOrder.PurchaseOrderItems[i];
                    //Delete extra orderItems in order(DB)
                    if (!purchaseOrderContract.PurchaseOrderItemContracts.Any(x => x.Id == temp.Id))
                    {
                        ;
                    }
                    {
                        //if (purchaseOrderContract.PurchaseOrderItemContracts.Exists(d => d.Id != temp.Id))
                        purchaseOrder.PurchaseOrderItems.Remove(temp);
                    }
                }

                PurchaseOrderRepository.Update(purchaseOrder);
            }
            else
            {
                // Create Order
                purchaseOrder              = new PurchaseOrder();
                purchaseOrder.Code         = purchaseOrderContract.Code;
                purchaseOrder.CreationDate = purchaseOrderContract.CreationDate;
                purchaseOrder.Title        = purchaseOrderContract.Title;

                for (int i = 0; i < purchaseOrderContract.PurchaseOrderItemContracts.Count; i++)
                {
                    var temp = purchaseOrderContract.PurchaseOrderItemContracts[i];

                    var InDatabaseOrderItem = new PurchaseOrderItem();

                    InDatabaseOrderItem.NetPrice   = temp.NetPrice;
                    InDatabaseOrderItem.Quantity   = temp.Quantity;
                    InDatabaseOrderItem.UnitPrice  = temp.UnitPrice;
                    InDatabaseOrderItem.TotalPrice = temp.TotalPrice;
                    InDatabaseOrderItem.Item       = IitemRepository.Get(temp.ItemId);
                    InDatabaseOrderItem.Rack       = IRackRepository.Get(temp.RackId);

                    purchaseOrder.PurchaseOrderItems.Add(InDatabaseOrderItem);
                }

                PurchaseOrderRepository.Insert(purchaseOrder);
            }
        }