Esempio n. 1
0
        /// <summary>
        /// Step 2 Read impoted file into Import Table
        /// </summary>
        /// <returns></returns>
        public ActionResult Import()
        {
            List <ImportModel.rawImport> recordsIn  = new List <ImportModel.rawImport>();
            List <ImportModel.rawImport> newRecords = new List <ImportModel.rawImport>();

            try
            {
                recordsIn = ReadInputFile();
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.InnerException.Message;
                return(View("version"));
            }
            try
            {
                #region import
                ///// empty the import tables
                // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]");
                db.EmptyImport();
                /// insert into raw import and remove any duplicates just in case
                // db.BulkInsert<Pannebakker>(newRecords);
                db.BulkInsertIntoImport(recordsIn);
                db.RemoveDuplicateImport();
                return(View());

                #endregion import
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.InnerException.Message;
                return(View("shit"));
            }
        }
        public ActionResult UpLoad()
        {
            ImportSet importSet = new ImportSet();
            List <ImportModel.rawImport> recordsIn = new List <ImportModel.rawImport>();
            List <ImportModel.Batch>     batchIn   = new List <ImportModel.Batch>();

            //List<ImportModel.Pannebakker> existingRecords = new List<ImportModel.Pannebakker>();
            //List<ImportModel.rawImport> newRecords = new List<ImportModel.rawImport>();

            try
            {
                importSet = ReadInputFile();
                recordsIn = importSet.rawImport;
                batchIn   = importSet.batchImport;
                // existingRecords = db.GetPannebakkers().ToList();
                // newRecords = recordsIn.Union(existingRecords).ToList();
                // newRecords = existingRecords.Union(recordsIn, new DTO.PbComparer()).ToList();
            }
            catch (Exception ex)
            {
                //ViewBag.Error = ex.InnerException.Message;
                return(View("version"));
            }


            try
            {
                // "TRUNCATE TABLE [rawImport]"]");
                RepDb.EmptyImport();

                // db.BulkInsert<Pannebakker>(newRecords);
                RepDb.BulkInsertIntoImport(recordsIn);
                RepDb.BulkInsertGMBatch(batchIn);
                // RepDb.RemoveDuplicateNames();
                //AddBatch(records);
                RepDb.MergeBatchToNames();
                RepDb.RemoveDuplicateNames();
                ViewBag.Title = "done";
                Response.Write("<script>console.log('Data has been saved to db');</script>");
                //return View("Index");
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.InnerException.Message;
                return(View("shit"));
            }
        }
Esempio n. 3
0
        public ActionResult UpLoad()
        {
            List <ImportModel.rawImport>   recordsIn       = new List <ImportModel.rawImport>();
            List <ImportModel.Pannebakker> existingRecords = new List <ImportModel.Pannebakker>();
            List <ImportModel.rawImport>   newRecords      = new List <ImportModel.rawImport>();

            try
            {
                recordsIn = ReadInputFile();
                // existingRecords = db.GetPannebakkers().ToList();
                // newRecords = recordsIn.Union(existingRecords).ToList();
                // newRecords = existingRecords.Union(recordsIn, new DTO.PbComparer()).ToList();
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.InnerException.Message;
                return(View("version"));
            }


            try
            {
                #region import
                ///// empty the import tables
                // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]");
                db.EmptyImport();
                /// insert into raw import and remove any duplicates just in case
                // db.BulkInsert<Pannebakker>(newRecords);
                db.BulkInsertIntoImport(recordsIn);
                db.RemoveDuplicateImport();
                #endregion import

                // merge import into PB and clean form sizes
                //AddBatch(records);
                db.MergeImportToPB();
                db.cleanPBForms();
                db.cleanForms();
                db.RemoveDuplicatePB();
                // so PB table sould now be solid and ready


                // remove any duplicates from PB and Batch
                // may not be needed but just in case

                // db.RemoveDuplicateBatch();

                // clean all old PB's from batch as we are going to provide a new lot.
                // worried about this moving frowards if quotes use batch ids from PB's i am removing
                //db.RemovePBFromBatch();


                var allPB = db.GetPannebakkers().ToList();
                // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]");


                List <ImportModel.Pannebakker> newBatches = new List <ImportModel.Pannebakker>();
                foreach (var b in allPB)
                {
                    ImportModel.Pannebakker newB = new ImportModel.Pannebakker();
                    decimal price = CalCapPrice(b);
                    if (price != 0)
                    {
                        newB.WholesalePrice = Convert.ToInt32(price);
                    }
                    else
                    {
                        newB.WholesalePrice = Convert.ToInt32(b.Price);
                    }
                    newB.Price          = b.Price;
                    newB.FormSize       = b.FormSize;
                    newB.Location       = "PB";
                    newB.Name           = b.Name;
                    newB.Sku            = b.Sku;
                    newB.WholesalePrice = Convert.ToInt32(price);
                    newB.FormSizeCode   = b.FormSizeCode;
                    if (price != b.Price)
                    {
                        newB.Comment = "Price Modified from " + b.Price + " to " + newB.WholesalePrice;
                    }
                    if (price == b.Price)
                    {
                        newB.Comment = "Price Not Modified";
                    }
                    if (price == 0)
                    {
                        newB.Comment = null;
                    }
                    newBatches.Add(newB);
                }


                //IEnumerable<ImportModel.Batch> newBatches = allPB.Select(batch => new ImportModel.Batch
                //{
                //    Active = true,
                //    AllocatedQuantity = 0,
                //    BuyPrice = CalCapPrice(batch),
                //    Comment = "",
                //    FormSize = batch.FormSize,
                //    ImageExists = false,
                //    GrowingQuantity = 0,
                //    Location = "PB",
                //    Name = batch.Name,
                //    Sku = batch.Sku,
                //    Quantity = 5000,
                //    WholesalePrice = 0,
                //    DateStamp = DateTime.Now,

                //});
                db.EmptyPB();
                db.BulkInsertIntoPB(newBatches);
                db.MergePbToBatch();
                ViewBag.Title = "done";
                Response.Write("<script>console.log('Data has been saved to db');</script>");
                return(View("uploadDone"));
                //return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.InnerException.Message;
                return(View("shit"));
            }
        }