Ejemplo n.º 1
0
        public static IOBalanceEntity.BatchSummary DtoToEntity(this BatchSummariesDto dto)
        {
            IOBalanceEntity.BatchSummary entity = null;

            if (!dto.IsNull())
            {
                entity = new IOBalanceEntity.BatchSummary
                {
                    BatchNo        = dto.BatchNo == null ? 0 : (long)dto.BatchNo,
                    FileName       = dto.FileName,
                    FilePath       = dto.FilePath,
                    TotalRecords   = dto.TotalRecords,
                    Successful     = dto.Successful,
                    Failed         = dto.Failed,
                    UploadStatus   = dto.UploadStatus,
                    IsDownload     = false,
                    ResultFileName = null,
                    ResultFilePath = null,
                    UploadedBy     = dto.UploadedBy,
                    StartUpload    = dto.StartUpload,
                    EndUpload      = dto.EndUpload
                };
            }

            return(entity);
        }
Ejemplo n.º 2
0
        //return results:
        //result = 0 -> no error
        //result = 1 -> system error
        //result = 2 -> batch no error
        //result = 3 -> bulk insert batchproductlog error
        //result = 4 -> BATCH UPLOAD data message return <= 0
        //result = 5 -> Successfully inserted ALL records
        //result = 6 -> Successfully inserted but with errors
        //result = 7 -> All records error
        public int SaveBulkProducts(BatchSummariesDto dto, List <BatchProductLogDto> dtoList)
        {
            int result = 0;

            if (!dto.IsNull())
            {
                this.batchSummary = dto.DtoToEntity();
                var batchNoIdentity = _batchSummary.Insert(this.batchSummary).BatchNo;

                if (!batchNoIdentity.IsNull() && batchNoIdentity <= 0)
                {
                    result = 2;
                }
                else
                {
                    if (!SaveProductBulk(dtoList, batchNoIdentity))
                    {
                        result = 3;
                    }
                    else
                    {
                        DataTable      dtResultSet   = new DataTable();
                        SqlParameter[] sqlParameters = new SqlParameter[]
                        {
                            new SqlParameter()
                            {
                                ParameterName = "BatchNo", SqlValue = batchNoIdentity, SqlDbType = SqlDbType.BigInt
                            }
                        };
                        dtResultSet = _product.ExecuteSPReturnTable("uspBatchProductCreation", true, sqlParameters);

                        if (dtResultSet.Rows.Count <= 0)
                        {
                            result = 4;
                        }
                        else
                        {
                            if (dtResultSet.Rows[0][Globals.Result].ToString() == "5")
                            {
                                result = 0;
                            }
                            else if (dtResultSet.Rows[0][Globals.Result].ToString() == "6")
                            {
                                result = 6;
                            }
                            else if (dtResultSet.Rows[0][Globals.Result].ToString() == "7")
                            {
                                result = 7;
                            }
                        }
                    }
                }
            }
            else
            {
                result = 1;
            }


            return(result);
        }
Ejemplo n.º 3
0
        public virtual ActionResult UploadInventory(HttpPostedFileBase file)
        {
            string content = string.Empty, messageResult = string.Empty;
            bool   isSuccess = true;
            int    rowId     = 2;

            var branchId  = Session[SessionVariables.UserDetails].GetBranchIdFromSession();
            var createdBy = Session[SessionVariables.UserDetails].GetUserIdFromSession();
            var dateNow   = System.DateTime.Now;

            List <BatchProductLogDto> listDto = new List <BatchProductLogDto>();

            if (!file.IsNull())
            {
                if (!file.IsValidExcelFile())
                {
                    isSuccess     = false;
                    messageResult = Messages.InvalidFileType;
                }
                else
                {
                    var package      = new ExcelPackage(file.InputStream);
                    var currentSheet = package.Workbook.Worksheets;
                    var workSheet    = currentSheet.First();
                    var noOfCol      = workSheet.Dimension.End.Column;
                    var noOfRow      = workSheet.Dimension.End.Row;

                    if (noOfRow < 2)
                    {
                        isSuccess     = false;
                        messageResult = Messages.ExcelUploadedEmpty;
                    }
                    else if (noOfCol != 15)
                    {
                        isSuccess     = false;
                        messageResult = Messages.ExcelUploadNumberOfColumns;
                    }
                    else
                    {
                        var dto = new BatchSummariesDto()
                        {
                            FileName     = file.FileName,
                            FilePath     = Constants.ProductBatchExcelUploads,
                            TotalRecords = (noOfRow - 1),
                            Successful   = 0,
                            Failed       = 0,
                            UploadStatus = Globals.Uploading.ToUpper(),
                            UploadedBy   = createdBy,
                            StartUpload  = dateNow
                        };

                        if (dto.IsNull())
                        {
                            isSuccess     = false;
                            messageResult = Messages.ErrorOccuredDuringProcessing;
                        }
                        else
                        {
                            for (int i = 0; i < (noOfRow - 1); i++)
                            {
                                var branchName    = workSheet.Cells["A" + rowId.ToString()].Value;
                                var categoryCode  = workSheet.Cells["B" + rowId.ToString()].Value;
                                var categoryName  = workSheet.Cells["C" + rowId.ToString()].Value;
                                var productCode   = workSheet.Cells["D" + rowId.ToString()].Value;
                                var productName   = workSheet.Cells["E" + rowId.ToString()].Value;
                                var extension     = workSheet.Cells["F" + rowId.ToString()].Value;
                                var quantity      = workSheet.Cells["G" + rowId.ToString()].Value;
                                var originalPrice = workSheet.Cells["H" + rowId.ToString()].Value;
                                var price         = workSheet.Cells["I" + rowId.ToString()].Value;
                                var size          = workSheet.Cells["J" + rowId.ToString()].Value;
                                var supplierCode  = workSheet.Cells["K" + rowId.ToString()].Value;
                                var supplierName  = workSheet.Cells["L" + rowId.ToString()].Value;
                                var description   = workSheet.Cells["M" + rowId.ToString()].Value;
                                var barCode       = workSheet.Cells["N" + rowId.ToString()].Value;
                                var remarks       = workSheet.Cells["O" + rowId.ToString()].Value;

                                listDto.Add(new BatchProductLogDto()
                                {
                                    BranchName    = branchName == null ? string.Empty : branchName.ToString(),
                                    CategoryCode  = categoryCode == null ? string.Empty : categoryCode.ToString(),
                                    CategoryName  = categoryName == null ? string.Empty : categoryName.ToString(),
                                    ProductCode   = productCode == null ? string.Empty : productCode.ToString(),
                                    ProductName   = productName == null ? string.Empty : productName.ToString(),
                                    Extension     = extension == null ? string.Empty : extension.ToString(),
                                    Quantity      = quantity == null ? string.Empty : quantity.ToString(),
                                    OriginalPrice = originalPrice == null ? string.Empty : originalPrice.ToString(),
                                    Price         = price == null ? string.Empty : price.ToString(),
                                    Size          = size == null ? string.Empty : size.ToString(),
                                    SupplierCode  = supplierCode == null ? string.Empty : supplierCode.ToString(),
                                    SupplierName  = supplierName == null ? string.Empty : supplierName.ToString(),
                                    Description   = description == null ? string.Empty : description.ToString(),
                                    BarCode       = barCode == null ? string.Empty : barCode.ToString(),
                                    Remarks       = remarks == null ? string.Empty : remarks.ToString()
                                });

                                rowId++;
                            }


                            var resultSave = _inventoryService.SaveBulkProducts(dto, listDto);

                            if (resultSave == 1)
                            {
                                isSuccess     = false;
                                messageResult = Messages.ErrorOccuredDuringProcessing;
                            }
                            else if (resultSave == 2)
                            {
                                isSuccess     = false;
                                messageResult = Messages.BatchNoEmpty;
                            }
                            else if (resultSave == 3)
                            {
                                isSuccess     = false;
                                messageResult = Messages.BulkInsertError;
                            }
                            else if (resultSave == 4)
                            {
                                isSuccess     = false;
                                messageResult = Messages.ErrorOccuredDuringBatchProcessing;
                            }
                            else if (resultSave == 6)
                            {
                                isSuccess     = false;
                                messageResult = Messages.InsertSuccessButWithError;
                            }
                            else if (resultSave == 7)
                            {
                                isSuccess     = false;
                                messageResult = Messages.BatchUploadErrorAllRecords;
                            }
                        }
                    }
                }
            }
            else
            {
                isSuccess = false;
            }

            var json = new
            {
                result        = isSuccess,
                messageResult = messageResult
            };

            return(Json(json, Globals.ContentTypeTextPlain, JsonRequestBehavior.AllowGet));
        }