Exemple #1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Order order = orderService.FindById(Convert.ToInt32(id));

            if (order == null)
            {
                return(HttpNotFound());
                //throw new HttpException(404, "Some description");
            }
            else
            {
                _Distributor distributor = distributorService.GetOne(order.DistributorId);
                Employee     employee    = employeeService.GetOne(order.EmployeeId);
                ViewBag.EmpInfoName = employee.EmpName;
                ViewBag.EmpInfoId   = employee.EmployeeId;
                List <OrderDetail> detail  = detailService.FindByOrderId(order.OrderId);
                Invoice            invoice = invoiceService.FindByOrderId(order.OrderId);

                return(View(Tuple.Create(distributor, order, detail)));
            }
        }
Exemple #2
0
        public ActionResult AddOrEdit(int id = 0)
        {
            List <Region> regions = regionService.GetAll();

            ViewBag.RegionId = new SelectList(regions, "RegionId", "RegionName");

            if (id == 0)
            {
                return(View(new _Distributor()));
            }
            else
            {
                _Distributor distributor = distributorService.GetOne(id);
                return(View(distributor));
            }
        }
        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);
            }
        }