示例#1
0
        public void SaveScannedBarcodeToTextFile(string barcode, long salesReturnId)
        {
            SuccessErrorModel model = new SuccessErrorModel();
            ViewWriteLogModel log   = new ViewWriteLogModel();

            try
            {
                var filePath = GetSalesReturnProductFilePath(salesReturnId);

                var scannedBarCode      = barcode.ToUpper();
                int productId           = Convert.ToInt32(scannedBarCode.Substring(2, 3));
                var receivesProductList = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList();

                //------------read Scanned barcode form text file---------
                var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList();

                //------------Load receiveable product---------
                var isvalid = Validator.ValidateProductBarCode(scannedBarCode);

                int requistionQtyByProductId = receivesProductList.ToList().FindAll(n => n.ProductId == productId).Sum(n => n.Quantity);

                int scannedQtyByProductId = barcodeList
                                            .FindAll(n => Convert.ToInt32(n.ProductCode.Substring(2, 3)) == productId).Count;

                bool isScannComplete = requistionQtyByProductId.Equals(scannedQtyByProductId);

                if (isScannComplete)
                {
                    model.Message = "<p style='color:green'> Scanned Complete</p>";
                    // return Json(model, JsonRequestBehavior.AllowGet);
                }
                else if (!isvalid)
                {
                    model.Message = "<p style='color:red'> Invalid Barcode</p>";
                    //return Json(model, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    _iProductManager.AddProductToTextFile(scannedBarCode, filePath);
                }
            }
            catch (FormatException exception)
            {
                log.Heading    = exception.GetType().ToString();
                log.LogMessage = exception.StackTrace;
                Log.WriteErrorLog(log);
                model.Message = "<p style='color:red'>" + exception.GetType() + "</p>";
                //return Json(model, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                log.Heading    = exception.GetType().ToString();
                log.LogMessage = exception.StackTrace;
                Log.WriteErrorLog(log);
                model.Message = "<p style='color:red'>" + exception.Message + "</p>";
                // return Json(model, JsonRequestBehavior.AllowGet);
            }
            // return Json(model, JsonRequestBehavior.AllowGet);
        }
        public void SaveScannedBarcodeToTextFile(string barcode, long dispatchId)
        {
            SuccessErrorModel model = new SuccessErrorModel();
            ViewWriteLogModel log   = new ViewWriteLogModel();

            try
            {
                int branchId       = Convert.ToInt32(Session["BranchId"]);
                var scannedBarCode = barcode.ToUpper();
                int productId      = Convert.ToInt32(scannedBarCode.Substring(2, 3));

                var filePath = GetReceiveProductFilePath(dispatchId, branchId);

                //------------read Scanned barcode form text file---------
                var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList();
                //------------Load receiveable product---------
                var receivesProductList     = _iInventoryManager.GetAllReceiveableProductToBranchByDispatchId(dispatchId, branchId);
                var receivesProductCodeList = _iInventoryManager.GetAllReceiveableItemsByDispatchAndBranchId(dispatchId, branchId).Select(n => n.ProductBarcode).ToList();
                var isvalid = Validator.ValidateProductBarCode(scannedBarCode);

                int requistionQtyByProductId = receivesProductList.ToList().FindAll(n => n.ProductId == productId).Sum(n => n.Quantity);

                int scannedQtyByProductId = barcodeList
                                            .FindAll(n => Convert.ToInt32(n.ProductCode.Substring(2, 3)) == productId).Count;

                bool isScannComplete = requistionQtyByProductId.Equals(scannedQtyByProductId);

                if (isScannComplete)
                {
                    model.Message = "<p style='color:green'> Scanned Complete</p>";
                    // return Json(model, JsonRequestBehavior.AllowGet);
                }
                else if (!isvalid)
                {
                    model.Message = "<p style='color:red'> Invalid Barcode</p>";
                    //return Json(model, JsonRequestBehavior.AllowGet);
                }

                else if (receivesProductCodeList.Contains(scannedBarCode))
                {
                    _iProductManager.AddProductToTextFile(scannedBarCode, filePath);
                }
            }
            catch (FormatException exception)
            {
                Log.WriteErrorLog(exception);
                model.Message = "<p style='color:red'>" + exception.GetType() + "</p>";
                //return Json(model, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                model.Message = "<p style='color:red'>" + exception.Message + "</p>";
                // return Json(model, JsonRequestBehavior.AllowGet);
            }
            // return Json(model, JsonRequestBehavior.AllowGet);
        }
示例#3
0
        public ActionResult Error()
        {
            var eLogModel = new ViewWriteLogModel
            {
                Heading    = "TEst Error",
                LogMessage = "Test"
            };

            Log.WriteErrorLog(eLogModel);
            return(View("_ErrorPartial", new Exception()));
        }
示例#4
0
        public static void WriteErrorLog(ViewWriteLogModel model)
        {
            var filePath    = HttpContext.Current.Server.MapPath("~/Logs/" + "Error_log_Xml_file.xml");
            var xmlDocument = XDocument.Load(filePath);

            xmlDocument.Element("Errors")?.Add(
                new XElement("Error", new XAttribute("LogId", DateTime.Now.ToString("yy-MMM-dd") + Guid.NewGuid()),
                             new XElement("Heading", model.Heading),
                             new XElement("LogMessage", model.LogMessage),
                             new XElement("LogDateTime", DateTime.Now)
                             ));
            xmlDocument.Save(filePath);
        }
示例#5
0
 private static void AppendLog(ViewWriteLogModel model, TextWriter txtWriter)
 {
     try
     {
         txtWriter.Write(Environment.NewLine + "Log Entry : ");
         txtWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
         txtWriter.WriteLine(":" + model.Heading);
         txtWriter.WriteLine("  :{0}", model.LogMessage);
         txtWriter.WriteLine("-------------------------------");
     }
     catch (Exception ex)
     {
         throw new Exception();
     }
 }
示例#6
0
 // GET: Demo
 public ActionResult Index()
 {
     try
     {
         Convert.ToInt32("addfd");
     }
     catch (Exception exception)
     {
         ViewWriteLogModel model = new ViewWriteLogModel
         {
             Heading    = exception.GetType().ToString(),
             LogMessage = exception.StackTrace
         };
         Log.WriteErrorLog(model);
     }
     return(View());
 }
示例#7
0
        public static void LogWrite(ViewWriteLogModel model)
        {
            string filePath = HttpContext.Current.Server.MapPath("/Logs") + "/Log_" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Close();
            }

            try
            {
                using (StreamWriter w = File.AppendText(filePath))
                    AppendLog(model, w);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private IEnumerable <ViewWriteLogModel> GetErrorListFromXmalFile(string filePath)
        {
            List <ViewWriteLogModel> list = new List <ViewWriteLogModel>();
            var xmlData = XDocument.Load(filePath).Element("Errors")?.Elements();

            foreach (XElement element in xmlData)
            {
                ViewWriteLogModel aLogModel = new ViewWriteLogModel();
                var elementFirstAttribute   = element.FirstAttribute.Value;
                aLogModel.LogId = elementFirstAttribute;
                var elementValue = element.Elements();
                var xElements    = elementValue as XElement[] ?? elementValue.ToArray();
                aLogModel.Heading        = xElements[0].Value;
                aLogModel.LogMessage     = xElements[1].Value;
                aLogModel.LogDateTime    = Convert.ToDateTime(xElements[2].Value);
                aLogModel.CustomeMessage = xElements[3].Value;
                list.Add(aLogModel);
            }

            return(list);
        }
示例#9
0
        public void SaveScannedBarcodeToTextFile(string barcode, long tripId)
        {
            SuccessErrorModel model = new SuccessErrorModel();
            ViewWriteLogModel log   = new ViewWriteLogModel();

            try
            {
                var    products       = (List <ViewFactoryStockModel>)Session["Factory_Stock"];
                string scannedBarCode = barcode.ToUpper();
                int    productId      = Convert.ToInt32(scannedBarCode.Substring(0, 3));
                string fileName       = "Deliverable_Product_For_" + tripId;
                var    filePath       = Server.MapPath("~/Files/" + fileName);
                var    barcodeList    = _iProductManager.ScannedProducts(filePath);
                if (barcodeList.Count != 0)
                {
                    foreach (ScannedProduct scannedProduct in barcodeList)
                    {
                        var p = products.Find(n => n.ProductBarCode.Equals(scannedProduct.ProductCode));
                        products.Remove(p);
                        Session["Factory_Stock"] = products;
                    }
                }
                bool exists            = barcodeList.Select(n => n.ProductCode).Contains(scannedBarCode);
                bool isDeliveredBefore = _iInventoryManager.IsThisProductDispachedFromFactory(scannedBarCode);
                bool isInfactory       = products.ToList().Select(n => n.ProductBarCode).Contains(scannedBarCode);
                // DateTime date = _iCommonManager.GenerateDateFromBarCode(scannedBarCode);
                // var oldestProducts = products.ToList().FindAll(n=>n.ProductionDate<date && n.ProductId==productId).ToList();
                var issuedProducts = _iProductManager.GetDeliverableProductListByTripId(tripId);

                var isValied = Validator.ValidateProductBarCode(scannedBarCode);

                bool isContains      = issuedProducts.Select(n => n.ProductId).Contains(productId);
                int  reqQty          = issuedProducts.ToList().FindAll(n => n.ProductId == productId).Sum(n => n.Quantity);
                int  scannedQty      = barcodeList.FindAll(n => Convert.ToInt32(n.ProductCode.Substring(0, 3)) == productId).Count;
                bool isScannComplete = reqQty.Equals(scannedQty);
                bool isComplete      = issuedProducts.Sum(n => n.Quantity).Equals(barcodeList.Count);

                if (!isContains)
                {
                    model.Message = "<p style='color:red'> Invalid Product Scanned.....</p>";
                    //return Json(model, JsonRequestBehavior.AllowGet);
                }

                else if (exists)
                {
                    model.Message = "<p style='color:red'> Already Scanned.</p>";
                    // return Json(model, JsonRequestBehavior.AllowGet);
                }
                else if (isScannComplete)
                {
                    model.Message = "<p style='color:green'> Scan Completed.</p>";
                    //return Json(model, JsonRequestBehavior.AllowGet);
                }

                //if (oldestProducts.Count > 0)
                //{
                //    model.Message = "<p style='color:red'>There are total "+oldestProducts.Count+" Old product of this type .Please deliver those first .. </p>";
                //    return Json(model, JsonRequestBehavior.AllowGet);
                //}
                else if (isValied && !isDeliveredBefore && isInfactory && !isComplete)
                {
                    var result = _iProductManager.AddProductToTextFile(scannedBarCode, filePath);
                    if (result.Contains("Added"))
                    {
                        var p = products.Find(n => n.ProductBarCode.Equals(scannedBarCode));
                        products.Remove(p);
                        Session["Factory_Stock"] = products;
                    }
                }
            }
            catch (FormatException exception)
            {
                log.Heading    = exception.GetType().ToString();
                log.LogMessage = exception.StackTrace;
                Log.WriteErrorLog(log);
                model.Message = "<p style='color:red'>Invalid Barcode</p>";
                // return  Json(model, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                log.Heading    = exception.GetType().ToString();
                log.LogMessage = exception.StackTrace;
                Log.WriteErrorLog(log);
                model.Message = "<p style='color:red'>" + exception.Message + "</p>";
                //return  Json(model, JsonRequestBehavior.AllowGet);
            }
            //return Json(model, JsonRequestBehavior.AllowGet);
        }