コード例 #1
0
        public int Update(PRQChemicalPI model, int userId)
        {
            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        #region PI_Informaiton_Update
                        var currentPI = (from p in _context.PRQ_ChemicalPI.AsEnumerable()
                                         where p.PIID == model.PIID
                                         select p).FirstOrDefault();
                        currentPI.PINo       = model.PINo;
                        currentPI.PIDate     = DalCommon.SetDate(model.PIDate);
                        currentPI.PICategory = model.PICategory;
                        currentPI.OrderID    = model.OrderID;
                        currentPI.OrderNo    = model.OrderNo;

                        currentPI.PIReceiveDate = DateTime.Now;

                        if (model.SupplierID == 0)
                        {
                            currentPI.SupplierID = null;
                        }
                        else
                        {
                            currentPI.SupplierID = model.SupplierID;
                        }

                        if (model.LocalAgent == 0)
                        {
                            currentPI.LocalAgent = null;
                        }
                        else
                        {
                            currentPI.LocalAgent = model.LocalAgent;
                        }

                        if (model.ForeignAgent == 0)
                        {
                            currentPI.ForeignAgent = null;
                        }
                        else
                        {
                            currentPI.ForeignAgent = model.ForeignAgent;
                        }

                        if (model.BuyerID == 0)
                        {
                            currentPI.PIBeneficiary = null;
                        }
                        else
                        {
                            currentPI.PIBeneficiary = model.BuyerID;
                        }

                        if (model.BuyerAddressID == 0)
                        {
                            currentPI.BeneficiaryAddressID = null;
                        }
                        else
                        {
                            currentPI.BeneficiaryAddressID = model.BuyerAddressID;
                        }

                        if (model.PICurrency == 0)
                        {
                            currentPI.PICurrency = null;
                        }
                        else
                        {
                            currentPI.PICurrency = model.PICurrency;
                        }

                        if (model.ExchangeCurrency == 0)
                        {
                            currentPI.ExchangeCurrency = null;
                        }
                        else
                        {
                            currentPI.ExchangeCurrency = model.ExchangeCurrency;
                        }

                        if (model.ExchangeRate == 0)
                        {
                            currentPI.ExchangeRate = null;
                        }
                        else
                        {
                            currentPI.ExchangeRate = model.ExchangeRate;
                        }

                        if (model.ExchangeValue == 0)
                        {
                            currentPI.ExchangeValue = null;
                        }
                        else
                        {
                            currentPI.ExchangeValue = model.ExchangeValue;
                        }


                        currentPI.PaymentTerm  = model.PaymentTerm;
                        currentPI.PaymentMode  = model.PaymentMode;
                        currentPI.DeferredDays = model.DeferredDays;


                        if (model.CountryOforigin == 0)
                        {
                            currentPI.CountryOforigin = null;
                        }
                        else
                        {
                            currentPI.CountryOforigin = model.CountryOforigin;
                        }


                        if (model.BeneficiaryBank == 0)
                        {
                            currentPI.BeneficiaryBank = null;
                        }
                        else
                        {
                            currentPI.BeneficiaryBank = model.BeneficiaryBank;
                        }

                        currentPI.FreightCharge      = model.FreightCharge;
                        currentPI.FreightChargeExtra = model.FreightChargeExtra;

                        //if (model.AdvisingBank == 0)
                        //    currentPI.AdvisingBank = null;
                        //else
                        //    currentPI.AdvisingBank = model.AdvisingBank;


                        currentPI.DeliveryTerm = model.DeliveryTerm;
                        currentPI.DeliveryMode = model.DeliveryMode;


                        if (model.PortofLoading == 0)
                        {
                            currentPI.PortofLoading = null;
                        }
                        else
                        {
                            currentPI.PortofLoading = model.PortofLoading;
                        }

                        if (model.PortofDischarge == 0)
                        {
                            currentPI.PortofDischarge = null;
                        }
                        else
                        {
                            currentPI.PortofDischarge = model.PortofDischarge;
                        }


                        currentPI.Transshipment   = model.Transshipment;
                        currentPI.PartialShipment = model.PartialShipment;
                        currentPI.GoodDelivery    = model.GoodDelivery;
                        currentPI.ShippingMark    = model.ShippingMark;

                        if (model.ExpectedShipmentTime == 0)
                        {
                            currentPI.ExpectedShipmentTime = null;
                        }
                        else
                        {
                            currentPI.ExpectedShipmentTime = model.ExpectedShipmentTime;
                        }


                        currentPI.Packing        = model.Packing;
                        currentPI.PreShipmentIns = model.PreShipmentIns;

                        if (model.OfferValidityDays == 0)
                        {
                            currentPI.OfferValidityDays = null;
                        }
                        else
                        {
                            currentPI.OfferValidityDays = model.OfferValidityDays;
                        }


                        currentPI.OfferValidityNote = model.OfferValidityNote;
                        currentPI.RecordStatus      = "NCF";
                        currentPI.ModifiedBy        = userId;
                        currentPI.ModifiedOn        = DateTime.Now;

                        _context.SaveChanges();
                        #endregion

                        #region Update_PIItemList
                        if (model.PIItemList != null)
                        {
                            foreach (var PIItem in model.PIItemList)
                            {
                                var checkPIItem = (from i in _context.PRQ_ChemicalPIItem.AsEnumerable()
                                                   where i.PIItemID == PIItem.PIItemID
                                                   select i).Any();

                                #region New_Requisition_Insertion
                                if (!checkPIItem)
                                {
                                    PRQ_ChemicalPIItem objItem = new PRQ_ChemicalPIItem();
                                    objItem.PIID         = model.PIID;
                                    objItem.ItemID       = PIItem.ItemID;
                                    objItem.OrderQty     = PIItem.OrderQty;
                                    objItem.OrderUnit    = DalCommon.GetUnitCode(PIItem.OrderUnitName);
                                    objItem.PackSize     = DalCommon.GetSizeCode(PIItem.PackSizeName);
                                    objItem.SizeUnit     = DalCommon.GetUnitCode(PIItem.SizeUnitName);
                                    objItem.PackQty      = PIItem.PackQty;
                                    objItem.PIQty        = Convert.ToDecimal(PIItem.PackSizeName) * PIItem.PackQty;
                                    objItem.PIUnit       = DalCommon.GetUnitCode(PIItem.PIUnitName);
                                    objItem.PIUnitPrice  = PIItem.PIUnitPrice;
                                    objItem.PITotalPrice = Convert.ToDecimal(PIItem.PackSizeName) * PIItem.PackQty * PIItem.PIUnitPrice;
                                    objItem.SupplierID   = PIItem.SupplierID;
                                    //objItem.ManufacturerID = item.ManufacturerID;
                                    objItem.ItemSource = PIItem.ItemSource;
                                    objItem.SetOn      = DateTime.Now;
                                    objItem.SetBy      = userId;

                                    _context.PRQ_ChemicalPIItem.Add(objItem);
                                    _context.SaveChanges();
                                }
                                #endregion

                                #region Existing_Requisition_Update
                                else
                                {
                                    var FoundPI = (from i in _context.PRQ_ChemicalPIItem.AsEnumerable()
                                                   where i.PIItemID == PIItem.PIItemID
                                                   select i).FirstOrDefault();

                                    FoundPI.PIID      = model.PIID;
                                    FoundPI.ItemID    = PIItem.ItemID;
                                    FoundPI.OrderQty  = PIItem.OrderQty;
                                    FoundPI.OrderUnit = DalCommon.GetUnitCode(PIItem.OrderUnitName);
                                    FoundPI.PackSize  = DalCommon.GetSizeCode(PIItem.PackSizeName);
                                    FoundPI.SizeUnit  = DalCommon.GetUnitCode(PIItem.SizeUnitName);
                                    FoundPI.PackQty   = PIItem.PackQty;

                                    FoundPI.PIQty        = Convert.ToDecimal(PIItem.PackSizeName) * PIItem.PackQty;
                                    FoundPI.PIUnit       = DalCommon.GetUnitCode(PIItem.PIUnitName);
                                    FoundPI.PIUnitPrice  = PIItem.PIUnitPrice;
                                    FoundPI.PITotalPrice = Convert.ToDecimal(PIItem.PackSizeName) * PIItem.PackQty * PIItem.PIUnitPrice;

                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }

                        #endregion
                    }

                    transaction.Complete();
                }
                return(1);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
コード例 #2
0
        public int Save(PRQChemicalPI model, int userId, string pageUrl)
        {
            int CurrentPIID = 0;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        #region New_PI_Insert

                        PRQ_ChemicalPI objPI = new PRQ_ChemicalPI();

                        objPI.PINo       = model.PINo;
                        objPI.PIDate     = DalCommon.SetDate(model.PIDate);
                        objPI.PICategory = model.PICategory;
                        objPI.OrderID    = model.OrderID;
                        objPI.OrderNo    = model.OrderNo;

                        objPI.PIReceiveDate = DateTime.Now;

                        if (model.SupplierID == 0)
                        {
                            objPI.SupplierID = null;
                        }
                        else
                        {
                            objPI.SupplierID = model.SupplierID;
                        }

                        if (model.LocalAgent == 0)
                        {
                            objPI.LocalAgent = null;
                        }
                        else
                        {
                            objPI.LocalAgent = model.LocalAgent;
                        }

                        if (model.ForeignAgent == 0)
                        {
                            objPI.ForeignAgent = null;
                        }
                        else
                        {
                            objPI.ForeignAgent = model.ForeignAgent;
                        }

                        if (model.BuyerID == 0)
                        {
                            objPI.PIBeneficiary = null;
                        }
                        else
                        {
                            objPI.PIBeneficiary = model.BuyerID;
                        }

                        if (model.BuyerAddressID == 0)
                        {
                            objPI.BeneficiaryAddressID = null;
                        }
                        else
                        {
                            objPI.BeneficiaryAddressID = model.BuyerAddressID;
                        }

                        if (model.PICurrency == 0)
                        {
                            objPI.PICurrency = null;
                        }
                        else
                        {
                            objPI.PICurrency = model.PICurrency;
                        }

                        if (model.ExchangeCurrency == 0)
                        {
                            objPI.ExchangeCurrency = null;
                        }
                        else
                        {
                            objPI.ExchangeCurrency = model.ExchangeCurrency;
                        }

                        if (model.ExchangeRate == 0)
                        {
                            objPI.ExchangeRate = null;
                        }
                        else
                        {
                            objPI.ExchangeRate = model.ExchangeRate;
                        }

                        if (model.ExchangeValue == 0)
                        {
                            objPI.ExchangeValue = null;
                        }
                        else
                        {
                            objPI.ExchangeValue = model.ExchangeValue;
                        }


                        objPI.PaymentTerm  = model.PaymentTerm;
                        objPI.PaymentMode  = model.PaymentMode;
                        objPI.DeferredDays = model.DeferredDays;


                        if (model.CountryOforigin == 0)
                        {
                            objPI.CountryOforigin = null;
                        }
                        else
                        {
                            objPI.CountryOforigin = model.CountryOforigin;
                        }


                        if (model.BeneficiaryBank == 0)
                        {
                            objPI.BeneficiaryBank = null;
                        }
                        else
                        {
                            objPI.BeneficiaryBank = model.BeneficiaryBank;
                        }

                        //if (model.AdvisingBank == 0)
                        //    objPI.AdvisingBank = null;
                        //else
                        //    objPI.AdvisingBank = model.AdvisingBank;

                        objPI.FreightCharge      = model.FreightCharge;
                        objPI.FreightChargeExtra = model.FreightChargeExtra;

                        objPI.DeliveryTerm = model.DeliveryTerm;
                        objPI.DeliveryMode = model.DeliveryMode;


                        if (model.PortofLoading == 0)
                        {
                            objPI.PortofLoading = null;
                        }
                        else
                        {
                            objPI.PortofLoading = model.PortofLoading;
                        }

                        if (model.PortofDischarge == 0)
                        {
                            objPI.PortofDischarge = null;
                        }
                        else
                        {
                            objPI.PortofDischarge = model.PortofDischarge;
                        }


                        objPI.Transshipment   = model.Transshipment;
                        objPI.PartialShipment = model.PartialShipment;
                        objPI.GoodDelivery    = model.GoodDelivery;
                        objPI.ShippingMark    = model.ShippingMark;

                        if (model.ExpectedShipmentTime == 0)
                        {
                            objPI.ExpectedShipmentTime = null;
                        }
                        else
                        {
                            objPI.ExpectedShipmentTime = model.ExpectedShipmentTime;
                        }


                        objPI.Packing        = model.Packing;
                        objPI.PreShipmentIns = model.PreShipmentIns;

                        if (model.OfferValidityDays == 0)
                        {
                            objPI.OfferValidityDays = null;
                        }
                        else
                        {
                            objPI.OfferValidityDays = model.OfferValidityDays;
                        }


                        objPI.OfferValidityNote = model.OfferValidityNote;
                        objPI.RecordStatus      = "NCF";
                        objPI.SetBy             = userId;
                        objPI.SetOn             = DateTime.Now;

                        objPI.PIStatus = "ODDN";
                        objPI.PIState  = "RNG";
                        //objPI.PIReceiveDate=??
                        //objPI.PINote=??
                        //objPI.RunningStatus= ??
                        //objPI.CostIndicator= ??

                        _context.PRQ_ChemicalPI.Add(objPI);
                        _context.SaveChanges();
                        CurrentPIID = objPI.PIID;
                        #endregion

                        #region Item Insert
                        if (model.PIItemList != null)
                        {
                            foreach (var item in model.PIItemList)
                            {
                                PRQ_ChemicalPIItem objItem = new PRQ_ChemicalPIItem();
                                objItem.PIID         = CurrentPIID;
                                objItem.ItemID       = item.ItemID;
                                objItem.OrderQty     = item.OrderQty;
                                objItem.OrderUnit    = DalCommon.GetUnitCode(item.OrderUnitName);
                                objItem.PackSize     = DalCommon.GetSizeCode(item.PackSizeName);
                                objItem.SizeUnit     = DalCommon.GetUnitCode(item.SizeUnitName);
                                objItem.PackQty      = item.PackQty;
                                objItem.PIQty        = Convert.ToDecimal(item.PackSizeName) * item.PackQty;
                                objItem.PIUnit       = DalCommon.GetUnitCode(item.PIUnitName);
                                objItem.PIUnitPrice  = item.PIUnitPrice;
                                objItem.PITotalPrice = Convert.ToDecimal(item.PackSizeName) * item.PackQty * item.PIUnitPrice;
                                objItem.SupplierID   = item.SupplierID;
                                //objItem.ManufacturerID = item.ManufacturerID;
                                objItem.ItemSource = item.ItemSource;
                                objItem.SetOn      = DateTime.Now;
                                objItem.SetBy      = userId;

                                _context.PRQ_ChemicalPIItem.Add(objItem);
                                _context.SaveChanges();
                            }
                        }
                        #endregion
                    }
                    transaction.Complete();
                }
                return(CurrentPIID);
            }
            catch (Exception e)
            {
                return(CurrentPIID);
            }
        }