Example #1
0
        public int DecreaseAvailableQty(int ProductId, int DescreaseAmt)
        {
            // product not existed
            int     success = -1;
            Product p       = FindById(ProductId);

            if (p != null)
            {
                // Turn flag to existed
                success = 0;
                if (p.AvailableQty >= DescreaseAmt)
                {
                    try
                    {
                        p.AvailableQty -= DescreaseAmt;
                        _uow.SaveChange();
                        // sucessfully updated
                        success = 1;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex, "Error");
                        string Path = @"C:/DescreaseAvailableQty.Exception.txt";
                        ExceptionProofer.LogToFile(Path, ex);
                    }
                }
            }

            return(success);
        }
Example #2
0
        public int AddListDetail(int OrderId, string[] productId, string[] price, string[] DemandQty, string[] ActualQty)
        {
            {
                int SuccessNumb = 0;

                int count = productId.Count();
                for (int i = 0; i < count; i++)
                {
                    OrderDetail detail = new OrderDetail()
                    {
                        OrderId        = OrderId,
                        ProductId      = Convert.ToInt32(productId[i]),
                        Price          = Convert.ToDecimal(price[i]),
                        DemandQuantity = Convert.ToInt32(DemandQty[i]),
                        ActualQuantity = Convert.ToInt32(ActualQty[i])
                    };
                    try
                    {
                        Add(detail);
                        productService.DecreaseAvailableQty(Convert.ToInt32(productId[i]), Convert.ToInt32(ActualQty[i]));
                        SuccessNumb++;
                    }
                    catch (Exception ex)
                    {
                        string strPath = @"C:\OrderDetails.Error.Logger.txt";
                        ExceptionProofer.LogToFile(strPath, ex);
                        break;
                    }
                }
                return(SuccessNumb);
            }
        }
Example #3
0
        public int Add(Order order)
        {
            int success;

            _logger.Info("Start add new Order");
            try
            {
                repoOrder.Add(order);
                int Nrow = (_uow.SaveChange() > 0) ? 1 : 0;
                if (Nrow > 0)
                {
                    success = order.OrderId;
                }
                else
                {
                    success = 0;
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine(e.ToString());
                //HttpContext.Current.Response.Write(e);

                //string filePath = @"C:\Error.txt";

                //using (StreamWriter writer = new StreamWriter(filePath, true))
                //{
                //    writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                //       "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                //    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                //}

                _logger.Error(ex, "Catch Exception in Order controller");;
                string strPath = @"C:\Order.Error.Logger.txt";
                ExceptionProofer.LogToFile(strPath, ex);

                success = -1;
            }

            _logger.Info("End add new Order");
            ;
            if (success > 0)
            {
                _logger.Info("successfull added Order");
            }
            else
            {
                _logger.Info("failed to add");
            }
            _logger.Info("End add a Order");
            return(success);
        }
        public ActionResult PrintInvoice(int?orderId)
        {
            if (orderId == null)
            {
                return(null);
            }
            int   _orderId = Convert.ToInt32(orderId);
            Order order    = orderService.FindById(_orderId);

            if (order == null)
            {
                return(null);
            }

            // get distributor info
            _Distributor distributor = distributorService.GetOne(order.DistributorId);

            // get cashier info
            Employee employee = employeeService.FindById(order.EmployeeId);

            // get order detail info
            //List<OrderDetail> detail = detailService.FindByOrderId(order.OrderId);


            ReportDocument rd = new ReportDocument();

            rd.Load(Path.Combine(Server.MapPath("~/Reports/InvoiceCrystal.rpt")));


            //CrystalReportViewer crysReportViewer = new CrystalReportViewer();

            //InvoiceCrystal report = new InvoiceCrystal();

            // set list order detail  info


            using (ManagementDistributorDbContext dbContext = new ManagementDistributorDbContext())
            {
                rd.SetDataSource(dbContext.OrderDetails.Select(od => new
                {
                    od.OrderId,
                    od.OrderDetailId,
                    od.ActualQuantity,
                    od.Price,
                    od.ProductId,
                    od.Product.ProductName,
                }
                                                               ).ToList());
            }
            //rd.SetDataSource(detail);

            // set order generic info
            //rd.SetParameterValue("OrderDate", order.OrderDate);
            rd.SetParameterValue("OrderId", order.OrderId);

            rd.SetParameterValue("OrderToTalAmount", order.ToTalAmount);

            rd.SetParameterValue("InvoiceDate", DateTime.Now);
            rd.SetParameterValue("InvoiceId", 1);
            //rd.SetParameterValue("DueDate", DateTime.Now); //

            // Set Distributor Info
            rd.SetParameterValue("DistributorName", distributor.DistributorName);
            rd.SetParameterValue("DistributorAddress", distributor.DistributorAddress);

            // set Cashier info
            rd.SetParameterValue("EmployeeName", employee.EmpName);


            //crysReportViewer.ReporSource = report;

            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            try
            {
                Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);


                return(File(stream, "application/pdf", "Invoice.pdf"));
            }
            catch (Exception ex)
            {
                string path = @"C:/PrintInvoice.Exception.txt";
                ExceptionProofer.LogToFile(path, ex);
                return(null);
            }
        }