Exemple #1
0
 //
 // GET: /TelesalePluginCode/
 public ActionResult Index()
 {
     //using (IDbConnection dbConn = Helpers.OrmliteConnection.openConn())
     //{
     //    OrmLiteConfig.DialectProvider.UseUnicode = true;
     //    dbConn.DropTables(typeof(DC_Org_AvoidCallingTime));
     //    const bool overwrite = false;
     //    dbConn.CreateTables(overwrite, typeof(DC_Org_AvoidCallingTime));
     //}
     using (IDbConnection dbConn = Helpers.OrmliteConnection.openConn())
     {
         ViewBag.AVoidCallTime = dbConn.Select <DC_AvoidCallingTimeFrame>("SELECT * FROM DC_AvoidCallingTimeFrame");
     }
     if (asset.View)
     {
         ViewData["AllowCreate"] = asset.Create;
         ViewData["AllowUpdate"] = asset.Update;
         ViewData["AllowDelete"] = asset.Delete;
         ViewData["AllowExport"] = asset.Export;
         ViewData["Asset"]       = asset;
         using (var dbConn = Helpers.OrmliteConnection.openConn())
         {
             ViewData["UserGroups"] = dbConn.Select <Groups>();
         }
         ViewBag.listAvoidCallTime   = Deca_Code_Master.GetDeca_Code_Masters("[CodeType]='AvoidCallTime'", "").OrderBy(s => s.CodeID);
         ViewBag.listAllowedServices = Deca_Code_Master.GetDeca_Code_Masters("[CodeType]='AllowedServices'", "").OrderBy(s => s.CodeID);
         ViewBag.listCollectionType  = Deca_Code_Master.GetDeca_Code_Masters("[CodeType]='CollectionType'", "").OrderBy(s => s.CodeID);
         ViewBag.listRegion          = DC_Location_Region.GetList_Regions();
         return(View());
     }
     else
     {
         return(RedirectToAction("NoAccessRights", "Error"));
     }
 }
Exemple #2
0
        public ActionResult Export([DataSourceRequest] DataSourceRequest request)
        {
            if (asset.Export)
            {
                var         data  = DW_DC_Organization.GetListOrganizationForTeleSale().ToList();
                IEnumerable datas = data.ToDataSourceResult(request).Data;

                //using (ExcelPackage excelPkg = new ExcelPackage())
                FileInfo       fileInfo  = new FileInfo(Server.MapPath(@"~\ExportExcelFile\DC_OrganizationForTeleSale.xlsx"));
                var            excelPkg  = new ExcelPackage(fileInfo);
                ExcelWorksheet dataSheet = excelPkg.Workbook.Worksheets["DC_OrganizationForTeleSale"];
                int            rowData   = 1;
                foreach (DW_DC_Organization item in datas)
                {
                    int i = 1;
                    rowData++;
                    dataSheet.Cells[rowData, i++].Value = item.OrganizationID;
                    dataSheet.Cells[rowData, i++].Value = item.LongName;
                    dataSheet.Cells[rowData, i++].Value = item.Address;

                    if (string.IsNullOrEmpty(item.CheckAllowServices))
                    {
                        dataSheet.Cells[rowData, i++].Value = "";
                    }
                    else
                    {
                        if (item.CheckAllowServices == "1")
                        {
                            dataSheet.Cells[rowData, i++].Value = "Airtime";
                        }
                        else if (item.CheckAllowServices == "2")
                        {
                            dataSheet.Cells[rowData, i++].Value = "Airtime, Cashdvance, Physical goods, Services";
                        }
                        else
                        {
                            dataSheet.Cells[rowData, i++].Value = "Airtime, Physical goods, Services";
                        }
                    }



                    dataSheet.Cells[rowData, i++].Value = item.SalesPriority;
                    if (!string.IsNullOrEmpty(item.CollectionType))
                    {
                        var data1 = Deca_Code_Master.GetDeca_Code_Masters("[CodeID] = '" + item.CollectionType + "'", "").FirstOrDefault();
                        dataSheet.Cells[rowData, i++].Value = data1.Description;
                    }
                    else
                    {
                        dataSheet.Cells[rowData, i++].Value = "";
                    }
                    dataSheet.Cells[rowData, i++].Value = item.TeleSaleNote;
                    dataSheet.Cells[rowData, i++].Value = item.KeyPerson;
                    dataSheet.Cells[rowData, i++].Value = item.OnsiteInfo;
                    dataSheet.Cells[rowData, i++].Value = item.DeliveryNote;
                    dataSheet.Cells[rowData, i++].Value = item.CreditLimitRules;
                    dataSheet.Cells[rowData, i++].Value = item.SettlementDate;
                    dataSheet.Cells[rowData, i++].Value = item.DeliveryNote;
                    dataSheet.Cells[rowData, i++].Value = item.Note;
                    dataSheet.Cells[rowData, i++].Value = item.RegionalBD;
                    dataSheet.Cells[rowData, i++].Value = item.DueDate;
                }

                MemoryStream output = new MemoryStream();
                excelPkg.SaveAs(output);
                string fileName    = "DC_OrganizationForTeleSale_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx";
                string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                output.Position = 0;
                return(File(output.ToArray(), contentType, fileName));
            }
            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
            }
        }