コード例 #1
0
 public ActionResult TelesalesAgent_Read([DataSourceRequest] DataSourceRequest request)
 {
     if (asset.View)
     {
         List <DC_Telesales_Agent> data = new List <DC_Telesales_Agent>();
         data = DC_Telesales_Agent.GetDC_Telesales_Agent();
         return(Json(data.ToDataSourceResult(request)));
     }
     else
     {
         return(RedirectToAction("NoAccessRights", "Error"));
     }
 }
コード例 #2
0
        public FileResult TelesalesAgent_Export([DataSourceRequest]
                                                DataSourceRequest request)
        {
            if (asset.Export)
            {
                using (var dbConn = Helpers.OrmliteConnection.openConn())
                {
                    var UserName = currentUser.UserName;
                    List <DC_Telesales_Agent> d = DC_Telesales_Agent.GetDC_Telesales_Agent();

                    var listRequest = d;
                    //Get the data representing the current grid state - page, sort and filter
                    IEnumerable datas = listRequest.ToDataSourceResult(request).Data;
                    //Create new Excel workbook
                    FileStream fs       = new FileStream(Server.MapPath(@"~\ExportExcelFile\DC_TelesaleAgent.xls"), FileMode.Open, FileAccess.Read);
                    var        workbook = new HSSFWorkbook(fs, true);

                    //Create new Excel sheet
                    var sheetTeam = workbook.GetSheet("List");

                    int rowNumber1 = 1;

                    //Populate the sheet with values from the grid data
                    var list = dbConn.Select <DC_Telesales_Agent>().Select(s => s.Team.Distinct());

                    foreach (string data in list)
                    {
                        //Create a new row
                        var row = sheetTeam.CreateRow(rowNumber1++);
                        //Set values for the cells
                        row.CreateCell(0).SetCellValue(data);
                    }


                    //Create new Excel sheet
                    var sheetRegion = workbook.GetSheet("ListRegion");

                    int rowNumberRegion = 1;

                    //Populate the sheet with values from the grid data
                    var listRegion = DC_Location_Region.GetAllDC_Location_Regions().ToList();

                    foreach (var data in listRegion)
                    {
                        //Create a new row
                        var row = sheetRegion.CreateRow(rowNumberRegion++);
                        //Set values for the cells
                        row.CreateCell(0).SetCellValue(data.RegionName);
                    }

                    //Create new Excel sheet
                    var sheet = workbook.GetSheet("TelesaleAgent");

                    int rowNumber = 1;

                    //Populate the sheet with values from the grid data
                    foreach (DC_Telesales_Agent data in datas)
                    {
                        //Create a new row
                        var row = sheet.CreateRow(rowNumber++);
                        //Set values for the cells
                        row.CreateCell(0).SetCellValue(data.UserName);
                        row.CreateCell(1).SetCellValue(data.Team);
                        row.CreateCell(2).SetCellValue(data.Region);
                        row.CreateCell(3).SetCellValue(data.XLiteID);
                    }

                    //Write the workbook to a memory stream
                    MemoryStream output = new MemoryStream();
                    workbook.Write(output);

                    //Return the result to the end user
                    return(File(output.ToArray(),                                                         //The binary data of the XLS file
                                "application/vnd.ms-excel",                                               //MIME type of Excel files
                                "DC_TelesaleAgent" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls")); //Suggested file name in the "Save as" dialog which will be displayed to the end user
                }
            }
            else
            {
                ModelState.AddModelError("", "You don't have permission to export data");
                return(File("",                                                                       //The binary data of the XLS file
                            "application/vnd.ms-excel",                                               //MIME type of Excel files
                            "DC_TelesaleAgent" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls")); //Suggested file name in the "Save as" dialog which will be displayed to the end user
            }
        }