예제 #1
0
        public ActionResult Index(FormCollection collection, string submitbutton)
        {
            //Title'
            string testhtml = Request.Form["table"];
            ViewData["Title"] = "User Report";
            ViewData["Users"] = new SelectList(userdb.GetUserItems(), "cai", "detail", collection["ddlusers"]);

            ViewData["startdate"] = collection["txtStartDate"];
            ViewData["enddate"] = collection["txtEndDate"];
            string userid = collection["ddlUsers"];
            tbl_User myUser = userdb.GetUserByID(userid);
            ViewData["User"] = myUser;
            var test = projectdb.GetProjectHours(collection["ddlUsers"], DateTime.Parse(collection["txtStartDate"]), DateTime.Parse(collection["txtEndDate"]));
            ViewData["ProjectHours"] = test;
            switch (submitbutton)
            {
                case "Print":
                    if (test.Count() > 0)
                    {
                        List<string> ColList = new List<string>();
                        ColList.Add("Number");
                        ColList.Add("Name");
                        ColList.Add("Staus");
                        ColList.Add("Hours");

                        List<ReportRow> rows = new List<ReportRow>();
                        decimal totalhours = 0M;
                        int i = 0;

                        foreach (var item in test)
                        {
                            List<ReportCell> cells = new List<ReportCell>();
                            cells.Add(new ReportCell() { colnum = 0, colspan = 1, rownum = i, value = item.ProjectNumber.ToString(), type = CellType.String });
                            cells.Add(new ReportCell() { colnum = 1, colspan = 1, rownum = i, value = item.ProjectName, type = CellType.String });
                            cells.Add(new ReportCell() { colnum = 2, colspan = 1, rownum = i, value = item.ProjectStatus, type = CellType.String });
                            cells.Add(new ReportCell() { colnum = 3, colspan = 1, rownum = i, value = item.Hours.ToString(), type = CellType.Number });
                            i++;
                            totalhours += (decimal)item.Hours;
                            rows.Add(new ReportRow() { row = cells });

                        }

                        IPDFReport myReport = new Report(false);
                        float[] HeaderWidths = { 10, 70, 10, 10 };
                        myReport.ColList = ColList;
                        myReport.ReportRows = rows;
                        myReport.total = totalhours.ToString("#,##0.00");
                        myReport.Start = DateTime.Parse(collection["txtStartDate"]);
                        myReport.End = DateTime.Parse(collection["txtEndDate"]);
                        myReport.User = myUser;
                        myReport.Headerwidths = HeaderWidths;
                        myReport.filename = "TSD_User_Report_" + myUser.User_FirstName + "_" + myUser.User_LastName + "_[" + myUser.User_CAI + "]";
                        myReport.PageHeight = 595;
                        myReport.LogoImagePath = "~/images/img_hallmark.gif";
                        myReport.myXML = testhtml;
                        myReport.query = "User Report: " + myUser.User_FirstName + " " + myUser.User_LastName + " [" + myUser.User_CAI + "]"; ;
                        myReport.ReportDescription = "User Report";
                        myReport.GenerateXMLReport();
                        myReport.OpenPDF();
                    }

                    break;
                case "Get User Report":
                    break;
            }

            return View();
        }
예제 #2
0
        public ActionResult Print(FormCollection collection)
        {
            StringBuilder sb = new StringBuilder();

            //string userid = collection["ddlUsers"];
            //tbl_User myUser = db.GetUserByID(userid);

            foreach (var item in collection)
            {
                try
                {
                    if (item.ToString().Contains("chk"))    //Only check the checkboxes
                    {
                        ViewData[item.ToString()] = collection[item.ToString()].Replace(",false", "");
                        if (collection[item.ToString()] == "false")
                        { }//do nothing
                        else
                            sb.Append(item.ToString().Replace("chk", "") + ",");
                    }
                }
                catch
                {
                    //Do nothing
                }

            }

            string[] myIds = sb.ToString().Trim(',').Split(',');

            try
            {
                int test = int.Parse(myIds[0]);
            }
            catch
            {
                ViewData["Message"] = "Please select at least one project item";
                return View("Index");
            }

            try
            {
                var userdatacollection = userdb.GetUsersHoursForProject(myIds, DateTime.Parse(collection["txtStartDate"]), DateTime.Parse(collection["txtEndDate"]));
                ViewData["UserDataCollection"] = userdatacollection;
                if (userdatacollection.Count() > 0)
                {
                    List<string> ColList = new List<string>();
                    ColList.Add("Last Name");
                    ColList.Add("First Name");
                    ColList.Add("CAI");
                    ColList.Add("Hours");

                    decimal totalhours = 0M;
                    List<ReportRow> rows = new List<ReportRow>();
                    int i = 0;
                    foreach (var item in userdatacollection)
                    {
                        List<ReportCell> cells = new List<ReportCell>();
                        cells.Add(new ReportCell() { colnum = 0, colspan=1 , rownum = i, value = item.LastName, type  = CellType.String});
                        cells.Add(new ReportCell() { colnum = 1, colspan=1 , rownum = i, value = item.FirstName, type = CellType.String});
                        cells.Add(new ReportCell() { colnum = 2, colspan=1 , rownum = i, value = item.CAI, type= CellType.String });
                        cells.Add(new ReportCell() { colnum = 3, colspan=1 , rownum = i, value = item.hours.ToString(), type= CellType.Number});
                        i++;
                        totalhours += (decimal)item.hours;
                        rows.Add(new ReportRow() { row = cells });

                    }

                    IPDFReport myReport = new Report(false);
                    float[] HeaderWidths = { 40, 40, 10, 10 };
                    myReport.ColList = ColList;
                    myReport.ReportRows = rows;
                    myReport.total = totalhours.ToString("#,##0.00");
                    myReport.Start = DateTime.Parse(collection["txtStartDate"]);
                    myReport.End = DateTime.Parse(collection["txtEndDate"]);
                    myReport.Name = "Project Report";
                    myReport.ProjectList = projectdb.GetProjectsByIds(myIds);
                    myReport.Headerwidths = HeaderWidths;
                    myReport.filename = "TSD_Project_Report";// +myUser.User_FirstName + "_" + myUser.User_LastName + "_[" + myUser.User_CAI + "]";
                    myReport.PageHeight = 595;
                    myReport.LogoImagePath = "~/images/img_hallmark.gif";
                    //myReport.myXML = testhtml;
                    myReport.query = "Project Report: ";// +myUser.User_FirstName + " " + myUser.User_LastName + " [" + myUser.User_CAI + "]"; ;
                    myReport.ReportDescription = "User Report";
                    myReport.GenerateXMLReport();
                    myReport.OpenPDF();
                }
                return View("Index");
            }
            catch (Exception ex)
            {
                string error = "";
                if (ex.Message.Contains("DateTime"))
                    error = "Invalid Date Value";
                else
                    error = ex.Message;
                ViewData["Message"] = error;
            }
            return View("Index");
        }