public ActionResult GetEnterpriseLessonReportXlsx(EnterpriseContractViewModel viewModel)
        {
            var contract = models.GetTable <EnterpriseCourseContract>().Where(m => m.ContractID == viewModel.ContractID).FirstOrDefault();

            if (contract == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "未建立學員!!"));
            }

            DataTable table = createEnterpriseLessonSummary(contract);

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Cache-control", "max-age=1");
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=({1:yyyy-MM-dd HH-mm-ss}){0}", HttpUtility.UrlEncode("EnterpriseCourseSummary.xlsx"), DateTime.Now));

            using (DataSet ds = new DataSet())
            {
                ds.Tables.Add(table);

                using (var xls = ds.ConvertToExcel())
                {
                    xls.SaveAs(Response.OutputStream);
                }
            }

            return(new EmptyResult());
        }
        public ActionResult EditEnterpriseContract(EnterpriseContractViewModel viewModel)
        {
            var item = models.GetTable <EnterpriseCourseContract>().Where(c => c.ContractID == viewModel.ContractID).FirstOrDefault();

            if (item != null)
            {
                viewModel.TotalCost                   = item.TotalCost;
                viewModel.CompanyID                   = item.CompanyID;
                viewModel.CompanyName                 = item.Organization.CompanyName;
                viewModel.ReceiptNo                   = item.Organization.ReceiptNo;
                viewModel.EnterprisePriceID           = item.EnterpriseCourseContent.Select(c => (int?)c.TypeID).ToArray();
                viewModel.EnterpriseLessons           = item.EnterpriseCourseContent.Select(c => c.Lessons).ToArray();
                viewModel.EnterpriseDurationInMinutes = item.EnterpriseCourseContent.Select(c => c.DurationInMinutes).ToArray();
                viewModel.EnterpriseListPrice         = item.EnterpriseCourseContent.Select(c => c.ListPrice).ToArray();
                viewModel.Subject    = item.Subject;
                viewModel.Remark     = item.Remark;
                viewModel.UID        = item.EnterpriseCourseMember.Select(m => m.UID).ToArray();
                viewModel.BranchID   = item.BranchID;
                viewModel.ValidFrom  = item.ValidFrom;
                viewModel.Expiration = item.Expiration;
            }

            ViewBag.ViewModel = viewModel;
            return(View("~/Views/EnterpriseProgram/Module/EditEnterpriseContract.ascx", item));
        }
        public ActionResult GetMemberLessonXlsxList(EnterpriseContractViewModel viewModel)
        {
            var contract = models.GetTable <EnterpriseCourseContract>().Where(m => m.ContractID == viewModel.ContractID).FirstOrDefault();

            if (contract == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "未建立學員!!"));
            }

            var group = models.GetTable <EnterpriseCourseContract>().Where(m => m.ContractID == viewModel.ContractID)
                        .SelectMany(d => d.RegisterLessonEnterprise)
                        .Select(r => r.RegisterLesson)
                        .Select(r => r.GroupingLesson)
                        .Select(g => g.GroupID);

            var items = group.Distinct()
                        .Join(models.GetTable <LessonTime>(), g => g, l => l.GroupID, (g, l) => l);

            var details = items.ToArray()
                          .OrderBy(i => i.GroupID)
                          .ThenByDescending(i => i.ClassTime)
                          .Select(i => new
            {
                課學員  = String.Join("、", i.GroupingLesson.RegisterLesson.Select(r => r.UserProfile).ToArray().Select(u => u.FullName())),
                課日期  = String.Format("{0:yyyy/MM/dd HH:mm}", i.ClassTime),
                課程項目 = i.RegisterLesson.RegisterLessonEnterprise.EnterpriseCourseContent.EnterpriseLessonType.Description
            });


            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Cache-control", "max-age=1");
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=({1:yyyy-MM-dd HH-mm-ss}){0}", HttpUtility.UrlEncode("EnterpriseCourse.xlsx"), DateTime.Now));

            using (DataSet ds = new DataSet())
            {
                DataTable table = details.ToDataTable();
                table.TableName = "企業方案(" + contract.ContractNo + ")";
                ds.Tables.Add(table);

                table = createEnterpriseLessonSummary(contract);
                ds.Tables.Add(table);

                using (var xls = ds.ConvertToExcel())
                {
                    xls.SaveAs(Response.OutputStream);
                }
            }

            return(new EmptyResult());
        }
        public ActionResult EnterprisePaymentList(EnterpriseContractViewModel viewModel, bool?itemsOnly)
        {
            var item = models.GetTable <EnterpriseCourseContract>().Where(t => t.ContractID == viewModel.ContractID).FirstOrDefault();

            if (item == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "資料錯誤!!"));
            }
            if (itemsOnly == true)
            {
                return(View("~/Views/EnterpriseProgram/Module/PaymentItemList.ascx", item));
            }
            else
            {
                return(View("~/Views/EnterpriseProgram/Module/EnterpriseContractPaymentList.ascx", item));
            }
        }
Пример #5
0
        public async Task <ActionResult> GetMemberLessonXlsxListAsync(EnterpriseContractViewModel viewModel)
        {
            var contract = models.GetTable <EnterpriseCourseContract>().Where(m => m.ContractID == viewModel.ContractID).FirstOrDefault();

            if (contract == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "未建立學員!!"));
            }

            var group = models.GetTable <EnterpriseCourseContract>().Where(m => m.ContractID == viewModel.ContractID)
                        .SelectMany(d => d.RegisterLessonEnterprise)
                        .Select(r => r.RegisterLesson)
                        .Select(r => r.GroupingLesson)
                        .Select(g => g.GroupID);

            var items = group.Distinct()
                        .Join(models.GetTable <LessonTime>(), g => g, l => l.GroupID, (g, l) => l);

            var details = items.ToArray()
                          .OrderBy(i => i.GroupID)
                          .ThenByDescending(i => i.ClassTime)
                          .Select(i => new
            {
                課學員  = String.Join("、", i.GroupingLesson.RegisterLesson.Select(r => r.UserProfile).ToArray().Select(u => u.FullName())),
                課日期  = String.Format("{0:yyyy/MM/dd HH:mm}", i.ClassTime),
                課程項目 = i.RegisterLesson.RegisterLessonEnterprise.EnterpriseCourseContent.EnterpriseLessonType.Description
            });

            using (DataSet ds = new DataSet())
            {
                DataTable table = details.ToDataTable();
                table.TableName = "企業方案(" + contract.ContractNo + ")";
                ds.Tables.Add(table);

                table = createEnterpriseLessonSummary(contract);
                ds.Tables.Add(table);

                await ds.SaveAsExcelAsync(Response, String.Format("attachment;filename={0}({1:yyyy-MM-dd HH-mm-ss}).xlsx", HttpUtility.UrlEncode("EnterpriseCourse"), DateTime.Now), viewModel.FileDownloadToken);
            }

            return(new EmptyResult());
        }
Пример #6
0
        public async Task <ActionResult> GetEnterpriseLessonReportXlsxAsync(EnterpriseContractViewModel viewModel)
        {
            var contract = models.GetTable <EnterpriseCourseContract>().Where(m => m.ContractID == viewModel.ContractID).FirstOrDefault();

            if (contract == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "未建立學員!!"));
            }

            DataTable table = createEnterpriseLessonSummary(contract);

            using (DataSet ds = new DataSet())
            {
                ds.Tables.Add(table);

                await ds.SaveAsExcelAsync(Response, String.Format("attachment;filename={0}({1:yyyy-MM-dd HH-mm-ss}).xlsx", HttpUtility.UrlEncode("EnterpriseCourseSummary"), DateTime.Now), viewModel.FileDownloadToken);
            }

            return(new EmptyResult());
        }
        public ActionResult CommitEnterpriseContract(EnterpriseContractViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            var profile = HttpContext.GetUser();

            EnterpriseCourseContract item = models.GetTable <EnterpriseCourseContract>()
                                            .Where(p => p.ContractID == viewModel.ContractID).FirstOrDefault();

            if (!viewModel.ValidFrom.HasValue)
            {
                ModelState.AddModelError("ValidFrom", "請選擇合約起日!!");
            }

            if (!viewModel.Expiration.HasValue)
            {
                ModelState.AddModelError("Expiration", "請選擇合約迄日!!");
            }

            viewModel.CompanyName = viewModel.CompanyName.GetEfficientString();
            if (viewModel.CompanyName == null)
            {
                ModelState.AddModelError("CompanyName", "請輸入企業名稱!!");
            }

            viewModel.ReceiptNo = viewModel.ReceiptNo.GetEfficientString();
            if (viewModel.ReceiptNo == null)
            {
                ModelState.AddModelError("ReceiptNo", "請輸入統一編號!!");
            }


            viewModel.Subject = viewModel.Subject.GetEfficientString();
            if (viewModel.Subject == null)
            {
                ModelState.AddModelError("Subject", "請輸入合作方案說明!!");
            }

            if (!viewModel.TotalCost.HasValue || viewModel.TotalCost <= 0)
            {
                ModelState.AddModelError("TotalCost", "請輸入價格!!");
            }


            if (viewModel.EnterprisePriceID == null || viewModel.EnterprisePriceID.Length == 0)
            {
                ModelState.AddModelError("Subject", "請設定課程項目!!");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = ModelState;
                return(View("~/Views/Shared/ReportInputError.ascx"));
            }

            try
            {
                var orgItem = models.GetTable <Organization>().Where(o => o.ReceiptNo == viewModel.ReceiptNo).FirstOrDefault();
                if (orgItem == null)
                {
                    orgItem = new Organization
                    {
                        ReceiptNo = viewModel.ReceiptNo
                    };
                    models.GetTable <Organization>().InsertOnSubmit(orgItem);
                }
                orgItem.CompanyName = viewModel.CompanyName;
                models.SubmitChanges();

                if (item == null)
                {
                    item = new EnterpriseCourseContract
                    {
                        ContractNo = "CEA" + String.Format("{0:yyyyMMdd}", DateTime.Today) + String.Format("{0:0000}", DailySequence.NextSequenceNo) + "-00",
                    };
                    models.GetTable <EnterpriseCourseContract>().InsertOnSubmit(item);
                }

                item.BranchID   = viewModel.BranchID;
                item.CompanyID  = orgItem.CompanyID;
                item.Expiration = viewModel.Expiration;
                item.ValidFrom  = viewModel.ValidFrom;
                item.Remark     = viewModel.Remark;
                item.Subject    = viewModel.Subject;
                item.TotalCost  = viewModel.TotalCost;

                models.SubmitChanges();

                try
                {
                    models.ExecuteCommand("delete EnterpriseCourseContent where ContractID={0}", item.ContractID);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }

                if (viewModel.EnterprisePriceID != null && viewModel.EnterprisePriceID.Length > 0)
                {
                    for (int i = 0; i < viewModel.EnterprisePriceID.Length; i++)
                    {
                        var content = item.EnterpriseCourseContent.Where(c => c.TypeID == viewModel.EnterprisePriceID[i]).FirstOrDefault();
                        if (content == null)
                        {
                            content = new EnterpriseCourseContent
                            {
                                ContractID = item.ContractID,
                                TypeID     = viewModel.EnterprisePriceID[i].Value
                            };
                            models.GetTable <EnterpriseCourseContent>().InsertOnSubmit(content);
                        }
                        content.DurationInMinutes = viewModel.EnterpriseDurationInMinutes[i];
                        content.Lessons           = viewModel.EnterpriseLessons[i];
                        content.ListPrice         = viewModel.EnterpriseListPrice[i];
                    }
                    models.SubmitChanges();
                }

                return(Json(new { result = true }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Json(new { result = false, message = ex.Message }));
            }
        }