Example #1
0
        public static bool fnSaveBulk(BulkContainerViewModel incoming)
        {
            bool retval = true;
            try
            {
                using (var db = new EF.CMCSQL03Entities())
                {
                    int pk = incoming.bulkid;
                    if (incoming.bulkid == -1)
                    {
                        var newrec = new EF.tblBulk { ProductMasterID = incoming.productmasterid };
                        db.tblBulk.Add(newrec);
                        newrec.CreateDate = System.DateTime.Now;
                        newrec.CreateUser = HttpContext.Current.User.Identity.Name;
                        db.SaveChanges();
                        pk = newrec.BulkID;
                    }

                    var qry = (from t in db.tblBulk where t.BulkID == pk select t).FirstOrDefault();
                    qry.Warehouse = incoming.warehouse;
                    qry.ReceiveDate = incoming.receivedate;
                    qry.Carrier = incoming.carrier;
                    qry.ReceivedBy = incoming.receivedby;
                    qry.EnteredBy = incoming.enteredby;
                    qry.ProductMasterID = incoming.productmasterid;
                    qry.ReceiveWeight = incoming.receiveweight;
                    qry.LotNumber = incoming.lotnumber;
                    qry.MfgDate = incoming.mfgdate;
                    qry.ExpirationDate = incoming.expirationdate;
                    qry.CeaseShipDate = incoming.ceaseshipdate;
                    qry.BulkStatus = incoming.bulkstatus;
                    qry.UM = incoming.um;
                    qry.ContainerColor = incoming.containercolor;
                    qry.Bin = incoming.bin;
                    qry.ContainerType = incoming.containertype;
                    qry.COAIncluded = incoming.coaincluded;
                    qry.MSDSIncluded = incoming.msdsincluded;
                    qry.ContainerNotes = incoming.containernotes;
                    qry.CurrentWeight = incoming.currentweight;
                    qry.QCDate = incoming.qcdate;
                    qry.ReturnLocation = incoming.returnlocation;
                    qry.NoticeDate = incoming.noticedate;
                    qry.BulkLabelNote = incoming.bulklabelnote;
                    qry.ReceivedAsCode = incoming.receivedascode;
                    qry.ReceivedAsName = incoming.receivedasname;
                    qry.OtherStorage = incoming.otherstorage;
                    qry.UpdateDate = System.DateTime.Now;
                    qry.UpdateUser = HttpContext.Current.User.Identity.Name;
                    db.SaveChanges();
                    retval = true;
                }
            }
            catch
            {
                retval = false;
                throw new Exception("Error occurred saving Bulk Container");
                //System.Diagnostics.Debug.WriteLine(ex.Message);
                //retval = false;
            }
            return retval;
        }
        public static int fnNewBulkID()
        {
            using (var db = new EF.CMCSQL03Entities())
            {
                EF.tblBulk newrec = new EF.tblBulk();
                db.tblBulk.Add(newrec);
                db.SaveChanges();

                return newrec.BulkID;
            }
        }
        public static bool fnSavePrePack(PrePackViewModel vm, FormCollection fc)
        {
            bool retval = true;
            try
            {
                using (var db = new EF.CMCSQL03Entities())
                {
                    var newbulk = new EF.tblBulk();
                    newbulk.ProductMasterID = vm.productmasterid; newbulk.ReceiveDate = vm.receivedate; newbulk.LotNumber = vm.lotnumber;
                    newbulk.CeaseShipDate = vm.ceaseshipdate; newbulk.Carrier = vm.carrier; newbulk.ReceivedBy = vm.receivedby;
                    newbulk.QCDate = vm.qcdate; newbulk.Warehouse = vm.warehouse; newbulk.MfgDate = vm.mfgdate;
                    newbulk.COAIncluded = vm.coaincluded; newbulk.EnteredBy = vm.enteredby; newbulk.ExpirationDate = vm.expirationdate;
                    newbulk.MSDSIncluded = vm.msdsincluded; newbulk.BulkStatus = "PP";
                    db.tblBulk.Add(newbulk);
                    db.SaveChanges();
                    int newBulkID = newbulk.BulkID;

                    for (int i = 1; i <= vm.ItemsCount; i++)
                    {
                        string sThisShelfID = fc["Key" + i.ToString()];
                        int ThisShelfID = Convert.ToInt32(sThisShelfID);

                        string sThisQty = fc["Value" + i.ToString()];
                        int ThisQty = Convert.ToInt32(sThisQty);

                        //System.Diagnostics.Debug.WriteLine("Shelfid=" + ThisShelfID + " | Qty=" + ThisQty);
                        var newstock = new EF.tblStock();
                        newstock.BulkID = newBulkID; newstock.ShelfID = ThisShelfID; newstock.CreateDate = DateTime.Now;
                        newstock.Warehouse = vm.warehouse; newstock.QtyOnHand = ThisQty; //newStock.Bin = null; // ???
                        newstock.ShelfStatus = "PP";
                        db.tblStock.Add(newstock);
                        db.SaveChanges();
                    }
                }
            }
            catch
            {
                retval = false;
                throw new Exception("Error occurred saving Pre Packs");
            }

            return retval;
        }