Ejemplo n.º 1
0
        public long SaveBatchInvetoryLogs(BatchInventoryLogDto newDetails)
        {
            this.batchInventoryLog = newDetails.DtoToEntity();
            var insertedBatchInventoryLog = this._batchInventoryLog.Insert(this.batchInventoryLog);

            if (insertedBatchInventoryLog.IsNull())
            {
                return(0);
            }

            return(insertedBatchInventoryLog.BatchInventoryId);
        }
Ejemplo n.º 2
0
        public static IOBalanceDBV2Entity.BatchInventoryLog DtoToEntity(this BatchInventoryLogDto dto)
        {
            IOBalanceDBV2Entity.BatchInventoryLog entity = null;

            if (!dto.IsNull())
            {
                entity = new IOBalanceDBV2Entity.BatchInventoryLog
                {
                    BatchInventoryId = dto.BatchInventoryId,
                    CreatedBy        = dto.CreatedBy,
                    DateCreated      = dto.DateCreated,
                    FileName         = dto.FileName,
                    ResultMessage    = dto.ResultMessage
                };
            }

            return(entity);
        }
        public virtual ActionResult UploadInventory(HttpPostedFileBase file)
        {
            string content = string.Empty, messageResult = string.Empty, xmlResult = string.Empty;
            bool   isSuccess = true;
            int    rowId     = 2;
            int?   createdBy = 1;
            long   insertedBatchInventoryLogs = 0;


            var dateNow    = System.DateTime.Now;
            var dataResult = string.Empty;

            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 != 13)
                    {
                        isSuccess     = false;
                        messageResult = Messages.ExcelUploadNumberOfColumns;
                    }
                    else
                    {
                        var dtValues = new DataTable("Items");
                        dtValues.Columns.Add("PRODUCT_CODE");
                        dtValues.Columns.Add("PLUS_MINUS");
                        dtValues.Columns.Add("QUANTITY");
                        dtValues.Columns.Add("IS_NEW");
                        dtValues.Columns.Add("CATEGORY_NAME");
                        dtValues.Columns.Add("SUPPLIER_CODE");
                        dtValues.Columns.Add("UNIT_NAME");
                        dtValues.Columns.Add("PRODUCT_NAME");
                        dtValues.Columns.Add("PRODUCT_DESC");
                        dtValues.Columns.Add("PRODUCT_SIZE");
                        dtValues.Columns.Add("CURRENT_NUM");
                        dtValues.Columns.Add("DRNUM");
                        dtValues.Columns.Add("CARTON_NUM");

                        for (int i = 0; i < (noOfRow - 1); i++)
                        {
                            var productCode  = workSheet.Cells["A" + rowId.ToString()].Value;
                            var plusMinus    = workSheet.Cells["B" + rowId.ToString()].Value;
                            var quantity     = workSheet.Cells["C" + rowId.ToString()].Value;
                            var isNew        = workSheet.Cells["D" + rowId.ToString()].Value;
                            var categoryName = workSheet.Cells["E" + rowId.ToString()].Value;
                            var supplierCode = workSheet.Cells["F" + rowId.ToString()].Value;
                            var unitName     = workSheet.Cells["G" + rowId.ToString()].Value;
                            var productName  = workSheet.Cells["H" + rowId.ToString()].Value;
                            var productDesc  = workSheet.Cells["I" + rowId.ToString()].Value;
                            var productSize  = workSheet.Cells["J" + rowId.ToString()].Value;
                            var currentNum   = workSheet.Cells["K" + rowId.ToString()].Value;
                            var drNum        = workSheet.Cells["L" + rowId.ToString()].Value;
                            var cartonNum    = workSheet.Cells["M" + rowId.ToString()].Value;

                            dtValues.Rows.Add(
                                productCode == null ? string.Empty : productCode.ToString(),
                                plusMinus == null ? string.Empty : plusMinus.ToString(),
                                quantity == null ? string.Empty : quantity.ToString(),
                                isNew == null ? string.Empty : isNew.ToString(),
                                categoryName == null ? string.Empty : categoryName.ToString(),
                                supplierCode == null ? string.Empty : supplierCode.ToString(),
                                unitName == null ? string.Empty : unitName.ToString(),
                                productName == null ? string.Empty : productName.ToString(),
                                productDesc == null ? string.Empty : productDesc.ToString(),
                                productSize == null ? string.Empty : productSize.ToString(),
                                currentNum == null ? string.Empty : currentNum.ToString(),
                                drNum == null ? string.Empty : drNum.ToString(),
                                cartonNum == null ? string.Empty : cartonNum.ToString()
                                );

                            rowId++;
                        }


                        using (StringWriter sw = new StringWriter())
                        {
                            dtValues.WriteXml(sw);
                            xmlResult = sw.ToString();
                            xmlResult = xmlResult.Replace("<DocumentElement>", "<NewDataSet>");
                            xmlResult = xmlResult.Replace("</DocumentElement>", "</NewDataSet>");
                        }


                        if (xmlResult.IsEmptyString())
                        {
                            isSuccess     = false;
                            messageResult = string.Format(Messages.ErrorOccuredDuringProcessingThis, "XML Empty");
                        }
                        else
                        {
                            BatchInventoryLogDto batchInventoryDto = new BatchInventoryLogDto()
                            {
                                BatchInventoryId = 0,
                                CreatedBy        = createdBy,
                                DateCreated      = dateNow,
                                FileName         = file.FileName,
                                ResultMessage    = null
                            };
                            insertedBatchInventoryLogs = _inventoryService.SaveBatchInvetoryLogs(batchInventoryDto);
                            if (insertedBatchInventoryLogs <= 0)
                            {
                                isSuccess     = false;
                                messageResult = string.Format(Messages.ErrorOccuredDuringProcessingThis, "Batch Inventory Log");
                            }
                            else
                            {
                                var result = _inventoryService.SaveBatchInventory(xmlResult, createdBy);

                                JavaScriptSerializer jsSerializer             = new JavaScriptSerializer();
                                List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >();
                                Dictionary <string, object>         childRow;
                                foreach (DataRow row in result.Rows)
                                {
                                    childRow = new Dictionary <string, object>();
                                    foreach (DataColumn col in result.Columns)
                                    {
                                        childRow.Add(col.ColumnName, row[col]);
                                    }
                                    parentRow.Add(childRow);
                                }

                                dataResult = jsSerializer.Serialize(parentRow);

                                if (dataResult.IsNull())
                                {
                                    isSuccess     = false;
                                    messageResult = string.Format(Messages.ErrorOccuredDuringProcessingThis, "of serializing the data");
                                }
                                else
                                {
                                    if (!_inventoryService.UpdateBatchInventoryLogs(insertedBatchInventoryLogs, dataResult))
                                    {
                                        isSuccess     = false;
                                        messageResult = string.Format(Messages.ErrorOccuredDuringProcessingThis, "of updating the batch inventory logs");
                                    }
                                    else
                                    {
                                        isSuccess     = true;
                                        messageResult = Messages.UploadSuccess;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                isSuccess = false;
            }

            var json = new
            {
                result           = isSuccess,
                messageResult    = messageResult,
                dataResult       = dataResult,
                batchInventoryId = insertedBatchInventoryLogs
            };

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