Esempio n. 1
0
        private void InsertData(IList<Cji5DataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

            Cee.DeleteWhere<FinancialOpenPurchaseOrder>(Cee, x => true);

            var existingPurchaseOrders = (from x in Cee.FinancialOpenPurchaseOrders select x).ToList();

            var existingVendors = Cee.Vendors.ToList();

            Int32 rowNumber = 2;
            //import all financial data
            foreach (var purchaseOrder  in importData)
            {
                if (existingPurchaseOrders.Any(x => x.PoNumber == purchaseOrder.PoNumber
                    && x.ProjectDefinition == purchaseOrder.ProjectDefinition
                    && x.ReferenceItem == purchaseOrder.ReferenceItem
                    && x.ReferenceDocType == purchaseOrder.ReferenceDocType
                    && x.Date == purchaseOrder.Date))
                {
                    RaiseMessage(CommonUtils.MessageType.Error,
                        string.Format("Purchase Order for Po Number '{0}',  Project Definition '{1}', Reference item '{2}', Ref.Doc.Type = '{3}' and Date ='{4}' already exist. Skipping",
                        purchaseOrder.PoNumber, purchaseOrder.ProjectDefinition, purchaseOrder.ReferenceItem, purchaseOrder.ReferenceDocType, purchaseOrder.Date));
                    continue;
                }

                var vendor = existingVendors.FirstOrDefault(x => x.Number.ToString() == purchaseOrder.VendorNumber.ToLower().Trim());

                if (vendor == null)
                {
                    //Set default vendor to --
                    vendor = existingVendors.FirstOrDefault(x => x.Description.ToLower().Trim() == "--");
                    RaiseMessage(CommonUtils.MessageType.Warning,
                      string.Format("Row Number: {0} - Could not load Vendor '{1}' from Vendor table. Will use default Vendor'--'.",
                      rowNumber, purchaseOrder.VendorNumber));
                    if (vendor == null)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error,
                       string.Format("Could not load Vendor '--' from Vendor table. Please check that ''--'' entry exist in the Vendor table"));
                        return;
                    }
                }

                FinancialOpenPurchaseOrder newPurchaseOrder = new FinancialOpenPurchaseOrder
                {
                    PoNumber = purchaseOrder.PoNumber,
                    ProjectDefinition = purchaseOrder.ProjectDefinition,
                    VendorId = vendor.Id,
                    Description = purchaseOrder.Description,
                    TotalAmount = purchaseOrder.TotalAmount,
                    UndeliveredPortion = purchaseOrder.ValueInObjCrcy,
                    WbsElement = purchaseOrder.WbsElement,
                    CostElement = purchaseOrder.CostElement,
                    ReferenceItem = purchaseOrder.ReferenceItem,
                    ReferenceDocType = purchaseOrder.ReferenceDocType,
                    Date = purchaseOrder.Date,
                    LastImportedById = MetaData.UserId,
                    LastImportedDate = DateTime.Now
                };

                Cee.FinancialOpenPurchaseOrders.Add(newPurchaseOrder);
                Cee.SaveChanges();
                mSavedResults.Add(newPurchaseOrder);
                rowNumber++;

            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Financials were added from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //SAVE
                Cee.SaveChanges();

                foreach (var purchaseOrder in mSavedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added,
                        string.Format("Processed Purchase Order  PO Number = '{0}' Project Definition = '{1}' Reference Item = '{2}' Date = '{3}'",
                        purchaseOrder.PoNumber, purchaseOrder.ProjectDefinition, purchaseOrder.ReferenceItem, purchaseOrder.Date));
                }
            }
        }
 public PurchaseOrderAccureModel(FinancialOpenPurchaseOrder openPurchaseOrder, FinancialAccrual accrual, AddEditPurchaseOrderDialog view)
 {
     mOpenPurchaseOrder = openPurchaseOrder;
     mAccrual = accrual;
     mView = view;
 }