Exemple #1
0
        private List <DataModel.DMNewInvoice> AddItemInvoice(List <DataModel.DMNewInvoice> data)
        {
            List <DataModel.DMNewInvoice> ChaceInvoice = HttpContext.Cache["ChaceInvoice"] as List <DataModel.DMNewInvoice>;

            try
            {
                if (ChaceInvoice == null || ChaceInvoice.Count == 0)
                {
                    DataModel.DMNewInvoice NV = new DataModel.DMNewInvoice();
                    ChaceInvoice = new List <DataModel.DMNewInvoice>();
                    ChaceInvoice.Add(new DataModel.DMNewInvoice()
                    {
                        NoID = data[0].NoID, ItemID = 0, ItemName = string.Empty, Descriptions = string.Empty, Price = 0, Qty = 1, Total = 0, UOM = string.Empty
                    });

                    HttpContext.Cache.Insert("ChaceInvoice", ChaceInvoice, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0));
                }
                else
                {
                    bool Addrow = false;
                    foreach (DataModel.DMNewInvoice DI in data)
                    {
                        Addrow = false;
                        if (DI.ItemName != null && DI.Qty != 0 && DI.Price != 0)
                        {
                            Addrow = true;
                            var CI = ChaceInvoice.FirstOrDefault(x => x.NoID == DI.NoID);
                            CI.ItemName     = DI.ItemName;
                            CI.ItemID       = DI.ItemID;
                            CI.Descriptions = DI.Descriptions;
                            CI.Qty          = DI.Qty;
                            CI.UOM          = DI.UOM;
                            CI.Price        = DI.Price;
                            CI.Total        = DI.Qty * DI.Price;
                        }
                    }

                    if (Addrow == true)
                    {
                        DataModel.DMNewInvoice NI = new DataModel.DMNewInvoice();
                        NI.NoID = ChaceInvoice.Count() + 1;
                        NI.Qty  = 1;

                        ChaceInvoice.Add(NI);
                    }


                    HttpContext.Cache.Insert("ChaceInvoice", ChaceInvoice, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0));
                }
            }
            catch { }

            return(ChaceInvoice);
        }
Exemple #2
0
        public ActionResult DeleteInvoiceItem(int ID)
        {
            DMCreateNewInvoice DCI = new DMCreateNewInvoice();

            DataModel.DMNewInvoice INV = new DMNewInvoice();
            int i = 1;

            INV.NoID = ID;


            List <DataModel.DMNewInvoice> ChaceInvoice    = HttpContext.Cache["ChaceInvoice"] as List <DataModel.DMNewInvoice>;
            List <DataModel.DMNewInvoice> TmpChaceInvoice = new List <DataModel.DMNewInvoice>();

            foreach (DataModel.DMNewInvoice DI in ChaceInvoice)
            {
                if (DI.NoID != ID)
                {
                    DataModel.DMNewInvoice NI = new DataModel.DMNewInvoice();
                    NI.NoID         = i;
                    NI.ItemID       = DI.ItemID;
                    NI.ItemName     = DI.ItemName;
                    NI.Descriptions = DI.Descriptions;
                    NI.Qty          = DI.Qty;
                    NI.UOM          = DI.UOM;
                    NI.Price        = DI.Price;
                    NI.Total        = DI.Qty * DI.Price;
                    TmpChaceInvoice.Add(NI);
                    i++;
                }
            }
            HttpContext.Cache.Insert("ChaceInvoice", TmpChaceInvoice, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0));

            DCI.ListDI    = TmpChaceInvoice;
            ViewBag.Total = CountTotal(TmpChaceInvoice);
            return(PartialView("_NewInvoice", DCI));
        }