Пример #1
0
        //
        // GET: /DataLoader/
        public ActionResult Index(string container, string entitySetName)
        {
            model            = new DataLoaderModel();
            model.OtherModel = new DatasetListModel(0, 0, new OrderByInfo(), null, null);

            if (container == string.Empty || entitySetName == string.Empty)
            {
                model.NewRecord = true;
            }
            else
            {
                //Set the ViewData for controls according to queryString
                LoadControls(container, entitySetName);

                model.Container     = container;
                model.EntitySetName = entitySetName;
                model.Name          = model.ViewDataModel.EntitySetWrapper.EntitySet.Name;
                model.Category      = model.ViewDataModel.EntitySetWrapper.EntitySet.CategoryValue;
                model.DataSource    = model.ViewDataModel.EntitySetWrapper.EntitySet.ContainerAlias;
                model.Description   = model.ViewDataModel.EntitySetWrapper.EntitySet.Description;
                model.Table         = model.ViewDataModel.EntitySetWrapper.EntitySet.EntitySetName;
            }

            return(View("Index", System.Configuration.ConfigurationManager.AppSettings["MasterPageName"], model));
        }
Пример #2
0
        public ActionResult Index(DataLoaderModel model)
        {
            var    sql   = Odp.Data.Sql.sqlServerConnection.GetDataServiceInstance();
            string error = string.Empty;

            this.model       = model;
            model.OtherModel = new DatasetListModel(0, 0, new OrderByInfo(), null, null);

            // ***
            // Error Checking Tree
            model.ErrorMessage = string.Empty;
            if (model.Name == string.Empty || model.Name == null)
            {
                model.ErrorMessage += "Name,";
            }
            if (model.DataSource == string.Empty || model.DataSource == null)
            {
                model.ErrorMessage += "Data Source,";
            }
            if (model.Category == string.Empty || model.Category == null)
            {
                model.ErrorMessage += "Category,";
            }

            if (model.NewRecord)
            {
            }

            // ***
            // If everything is ok, begin saving the record
            if (model.ErrorMessage == string.Empty)
            {
                // ***
                // Save File to Webserver
                if (model.File.HasFile())
                {
                    model.FileLocation = Server.MapPath("//DataFiles") + model.File.FileName;
                    model.File.SaveAs(model.FileLocation);
                    model.FileExtention = System.IO.Path.GetExtension(model.FileLocation).Replace(".", "").ToLower();
                }

                // ***
                // Save file processing
                if (model.Save == "Save")
                {
                    if (sql.UpdateMetaData(model.Name, model.Table, model.DataSource, model.Category, model.Description, model.Icon))
                    {
                        return(RedirectToAction("DataSetList", "DataCatalog"));
                    }
                    else
                    {
                        return(View("Index", System.Configuration.ConfigurationManager.AppSettings["MasterPageName"], model));
                    }
                }
                else if (model.Save == "Upload")
                {
                    if (model.FileExtention == "kml" || model.FileExtention == "kmz" || model.FileExtention == "shp" || model.FileExtention == "rss" || model.FileExtention == "rss")
                    {
                        model.UploadOnly    = true;
                        model.Table         = "DownloadedFile";
                        model.EntitySetName = "DownloadedFile";

                        if (sql.InsertMetaData(model.Name, model.Table, model.DataSource, model.Category, model.Icon, model.Description, "/DataFiles/" + model.File.FileName, model.FileExtention.ToUpper()))
                        {
                            return(RedirectToAction("DataSetList", "DataCatalog"));
                        }
                        else
                        {
                            return(View("Index", System.Configuration.ConfigurationManager.AppSettings["MasterPageName"], model));
                        }
                    }
                    else
                    {
                        model.ErrorMessage = "You can only upload KML, KMZ, SHP, RSS or XLS files.";
                        return(View("Index", System.Configuration.ConfigurationManager.AppSettings["MasterPageName"], model));
                    }
                }
                else if (model.Save == "Import")
                {
                    if (model.FileExtention == "csv" || model.FileExtention == "txt")
                    {
                        model.UploadOnly = false;
                        model.DataSet    = UploadFile(model.FileLocation, model.HasHeaders, model.Delimiter);
                    }
                    else
                    {
                        model.ErrorMessage = "You can only import CSV or TXT delimted files.";
                        return(View("Index", System.Configuration.ConfigurationManager.AppSettings["MasterPageName"], model));
                    }

                    if (model.FileLocation != string.Empty && model.FileLocation != null)
                    {
                        model.DataSet = UploadFile(model.FileLocation, model.HasHeaders, model.Delimiter);
                    }
                }
            }

            return(View("Index", System.Configuration.ConfigurationManager.AppSettings["MasterPageName"], model));
        }