예제 #1
0
        public ActionResult GetCompany()
        {
            var db     = new OrganizationUnitDAL();
            var result = db.GetCompany();

            return(Content(JsonConvert.SerializeObject(new
            {
                result
            })));
        }
예제 #2
0
        public virtual ActionResult DownloadTemplate(string formatFile, int?param)
        {
            if (String.IsNullOrEmpty(formatFile))
            {
                formatFile = ".xlsx";
            }
            //var globalListDal = new GlobalListDal();
            DataTable dt = new DataTable("Grid");

            dt.Columns.AddRange(new DataColumn[16]
            {
                new DataColumn(AppRes.StaffIDD),
                new DataColumn(AppRes.OrganazationId),
                new DataColumn(AppRes.ShareRate),
                new DataColumn(AppRes.StartDate),
                new DataColumn(AppRes.EndDate),
                new DataColumn(AppRes.CompanyId),
                new DataColumn(AppRes.Note),
                new DataColumn(""),
                new DataColumn(""),
                new DataColumn(AppRes.CompanyId + " "),
                new DataColumn(AppRes.Company + " "),
                new DataColumn(""),
                new DataColumn(AppRes.StaffIDD + " "),
                new DataColumn(AppRes.Staff + "  "),
                new DataColumn(AppRes.OrganazationId + " "),
                new DataColumn(AppRes.OrganizationUnit + " ")
            });
            var db                   = new OrganizationUnitDAL();
            var listCompany          = db.GetCompany();
            var dborg                = new OrganizationUnitDAL();
            var listStaff            = dborg.GetEmployeeByStatusAndDept(Global.CurrentLanguage, 0, Constant.numStatusStaff.Activity.GetHashCode(), Global.CurrentUser.UserID, Global.CurrentUser.RoleId);
            var listOrganizationUnit = dborg.OrganizationUnitAll(1, Global.CurrentUser.RoleId, Global.CurrentUser.UserID);
            var rowsNumber           = 0;

            rowsNumber = Math.Max(listCompany.Count, Math.Max(listStaff.Count, listOrganizationUnit.Count));

            dt.Rows.Add(
                1,
                1230,
                50,
                DateTime.Now,
                DateTime.Now,
                1221,
                Global.CurrentLanguage == 4 ? "Note" : "Ghi chú"
                );

            for (int i = 0; i < rowsNumber; i++)
            {
                dt.Rows.Add(
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    listCompany.Count > i ? listCompany[i].OrganizationUnitID.ToString() : "", listCompany.Count > i ? listCompany[i].Name.ToString() : "",
                    "",
                    listStaff.Count > i ? listStaff[i].StaffID.ToString() : "", listStaff.Count > i ? listStaff[i].FullName.ToString() : "",
                    listOrganizationUnit.Count > i ? listOrganizationUnit[i].OrganizationUnitID.ToString() : "", listOrganizationUnit.Count > i ? listOrganizationUnit[i].Name.ToString() : ""

                    );
            }

            if (param == 2)
            {
                dt.Columns.Remove(AppRes.StaffIDD + " ");
                dt.Columns.Remove(AppRes.Staff + "  ");
                dt.Columns.Remove(AppRes.StaffIDD);
            }
            else
            {
                dt.Columns.Remove(AppRes.OrganazationId + " ");
                dt.Columns.Remove(AppRes.OrganizationUnit + " ");
                dt.Columns.Remove(AppRes.OrganazationId);
            }

            var wb = new XLWorkbook();

            wb.Worksheets.Add(dt);
            wb.Worksheet("Grid").Cell(1, 7).Style.Fill.BackgroundColor  = XLColor.White;
            wb.Worksheet("Grid").Cell(1, 8).Style.Fill.BackgroundColor  = XLColor.White;
            wb.Worksheet("Grid").Cell(1, 11).Style.Fill.BackgroundColor = XLColor.White;



            byte[] data = null;
            using (var stream = new MemoryStream())
            {
                wb.SaveAs(stream);
                data = stream.ToArray();
            }
            return(File(data, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ImportFileTemplate" + formatFile));
        }