Exemplo n.º 1
0
        public ActionResult SubmitImprot(string cityId, string countyId, string ProjectId, int isReName = 1)
        {
            var file = Request.Files[0];

            string path     = TemporaryFilesDiskPath;
            string fileName = Guid.NewGuid().ToString() + FileHelper.GetExtension(file.FileName);

            string filePah = Path.Combine(path, fileName);

            if (!FileHelper.IsExistDirectory(path))
            {
                FileHelper.CreateDirectory(path);
            }

            try
            {
                //将上传文件保存
                file.SaveAs(filePah);

                if (FileHelper.IsExistFile(filePah))
                {
                    using (ExcelHelper exHelp = new ExcelHelper(filePah))
                    {
                        var datatable = exHelp.ExcelToDataTable(fileName, true);

                        ProfileSanitationWayEntity wayEntity = null;

                        string streetName     = string.Empty;
                        string wayName        = string.Empty;
                        string mainWayName    = string.Empty;
                        string wayOrigin      = string.Empty;
                        string wayDestination = string.Empty;
                        string wayGrade       = string.Empty;

                        #region 每行填充数据

                        for (int i = 0; i < datatable.Rows.Count; i++)
                        {
                            wayEntity = new ProfileSanitationWayEntity();


                            try
                            {
                                streetName = datatable.Rows[i]["街道"].ToString();
                                //"大连西路(四平路-密云路)" 格式
                                wayName = datatable.Rows[i]["路名"].ToString();

                                mainWayName    = wayName.Split('(')[0];
                                wayOrigin      = wayName.Split('(')[1].Split(')')[0].Split('-')[0];
                                wayDestination = wayName.Split('(')[1].Split(')')[0].Split('-')[1];

                                wayGrade = datatable.Rows[i]["类型"].ToString();

                                wayEntity.CityId         = cityId;
                                wayEntity.CountyId       = countyId;
                                wayEntity.ProjectId      = ProjectId;
                                wayEntity.F_EnCode       = int.Parse(datatable.Rows[i]["序号"].ToString());
                                wayEntity.StreetId       = StreetApp.GetDictionary(d => d.StreetName == streetName)[0].Key;
                                wayEntity.MainWayId      = MainWayApp.GetDictionary(d => d.MainWayName == mainWayName)[0].Key;
                                wayEntity.WayName        = wayName;
                                wayEntity.Origin         = wayOrigin;
                                wayEntity.Destination    = wayDestination;
                                wayEntity.IsJointPartWay = false;
                            }
                            catch
                            {
                                continue;
                            }

                            switch (wayGrade)
                            {
                            case "一级":
                                wayEntity.WayGrade = (int)ProfileWayGradeEnum.一级道路;
                                break;

                            case "二级":
                                wayEntity.WayGrade = (int)ProfileWayGradeEnum.二级道路;
                                break;

                            case "三级及其它":
                                wayEntity.WayGrade = (int)ProfileWayGradeEnum.级及其它;
                                break;

                            default:
                                break;
                            }

                            wayApp.BatchSubmitFrom(wayEntity, null, (db, c) => { return(db.F_EnCode == c.F_EnCode); });
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (FileHelper.IsExistFile(filePah))
                {
                    FileHelper.DeleteFile(filePah);
                }
            }

            return(Success("操作成功。"));
        }
        public ActionResult SummitImport(string CityId, string CountyId, string ProjectId, int isRename = 1)
        {
            var file = Request.Files[0];

            string path     = @"D:\项目\聚力环境测评系统\NFine.Web\bin\TemporaryFilesDiskPath\";
            string fileName = file.FileName;
            string filePath = Path.Combine(path, fileName);

            ImportResultModel result = new ImportResultModel();
            int failureQuantity, successfulQuantity;

            try
            {
                if (NFine.Code.FileHelper.IsExistFile(path))
                {
                    NFine.Code.FileHelper.DeleteFile(path);
                }

                file.SaveAs(filePath);

                using (ExcelHelper exHelp = new ExcelHelper(filePath))
                {
                    var datatable = exHelp.ExcelToDataTable(filePath, true);

                    ProfileSanitationGarbageBoxEntity[] models = new ProfileSanitationGarbageBoxEntity[datatable.Rows.Count];

                    ProfileSanitationGarbageBoxEntity model;
                    for (int i = 0; i < datatable.Rows.Count; i++)
                    {
                        model = new ProfileSanitationGarbageBoxEntity();

                        var code               = datatable.Rows[i]["序"].ToString();
                        var streetName         = datatable.Rows[i]["街道"].ToString();
                        var garbageBoxTypeName = datatable.Rows[i]["类型"].ToString();
                        var address            = datatable.Rows[i]["地址"].ToString();

                        string streetKey = "";

                        var streetList = StreetApp.GetDictionary(d => d.StreetName == streetName);
                        if (streetList.Count > 0)
                        {
                            streetKey = streetList[0].Key;
                        }
                        else
                        {
                            continue;
                        }

                        model.F_EnCode  = int.Parse(code);
                        model.CityId    = CityId;
                        model.CountyId  = CountyId;
                        model.ProjectId = ProjectId;
                        model.StreetId  = streetKey;
                        model.Address   = address;

                        models[i] = model;
                    }

                    App.ImportData(models, out successfulQuantity, out failureQuantity);
                    result.IsSucceed          = true;
                    result.FailureQuantity    = failureQuantity;
                    result.SuccessfulQuantity = successfulQuantity;
                    result.TotalQuantity      = models.Length;
                }
            }
            catch (Exception ex)
            {
                result.IsSucceed    = false;
                result.ErrorMessage = ex.ToString();
            }
            finally
            {
                if (NFine.Code.FileHelper.IsExistFile(path))
                {
                    NFine.Code.FileHelper.DeleteFile(path);
                }
            }


            return(Success(string.Format("总条数:{0},成功条数:{1},失败条数:{2}", result.TotalQuantity, result.FailureQuantity, result.ErrorMessage)));
        }
        public ActionResult SummitImport(string CityId, string CountyId, int isRename = 1)
        {
            var file = Request.Files[0];

            string path     = @"D:\项目\卫星设备台账流程管理\NFine.Web\bin\TemporaryFilesDiskPath\";
            string fileName = file.FileName;

            ImportResultModel result = new ImportResultModel();
            int failureQuantity, successfulQuantity;

            try
            {
                file.SaveAs(Path.Combine(path, fileName));

                #region 导出

                if (FileHelper.IsExistFile(Path.Combine(path, fileName)))
                {
                    FileHelper.DeleteFile(Path.Combine(path, fileName));

                    using (ExcelHelper exHelp = new ExcelHelper(Path.Combine(path, fileName)))
                    {
                        var datatable = exHelp.ExcelToDataTable(fileName, true);
                        ProfileMainWayEntity[] models = new ProfileMainWayEntity[datatable.Rows.Count];
                        ProfileMainWayEntity   model;

                        for (int i = 0; i < datatable.Rows.Count; i++)
                        {
                            var mainWayName = datatable.Rows[i]["主路名"].ToString();
                            var jdName      = datatable.Rows[i]["街道"].ToString();
                            var fCode       = datatable.Rows[i]["序号"].ToString();

                            var StreetNamekey = StreetApp.GetDictionary(d => d.StreetName == jdName)[0].Key;

                            var streetModel = StreetApp.GetForm(StreetNamekey);

                            model = new ProfileMainWayEntity()
                            {
                                CityId      = streetModel.CityId,
                                CountyId    = streetModel.CountyId,
                                StreetId    = streetModel.F_Id,
                                MainWayName = mainWayName,
                                F_EnCode    = fCode
                            };

                            models[i] = model;
                        }
                        mainWayApp.ImportData(models, out successfulQuantity, out failureQuantity);
                        result.IsSucceed          = true;
                        result.FailureQuantity    = failureQuantity;
                        result.SuccessfulQuantity = successfulQuantity;
                        result.TotalQuantity      = models.Length;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                result.IsSucceed    = false;
                result.ErrorMessage = ex.ToString();
            }
            finally
            {
            }
            return(Success(string.Format("总条数:{0},成功条数:{1},失败条数:{2}", result.TotalQuantity, result.FailureQuantity, result.ErrorMessage)));
        }
        public ActionResult SummitImport(string CityId, string CountyId, string projectId, int isRename = 1)
        {
            projectId = "dd1bbf6b-bcea-4cad-851b-1be4adf71860";

            string path     = @"C:\Users\zps\Desktop\聚力环境测评系统样版\聚力环境测评系统样版\附件6、虹口市容点位\";
            string fileName = "Book1.xlsx";

            #region 导出

            if (FileHelper.IsExistFile(Path.Combine(path, fileName)))
            {
                using (ExcelHelper exHelp = new ExcelHelper(Path.Combine(path, fileName)))
                {
                    var datatable = exHelp.ExcelToDataTable(fileName, true);


                    //ProfileAmenitiesConstructionSiteEntiy

                    ProfileAmenitiesConstructionSiteEntity[] models = new ProfileAmenitiesConstructionSiteEntity[datatable.Rows.Count];
                    ProfileAmenitiesConstructionSiteEntity   model;

                    for (int i = 0; i < datatable.Rows.Count; i++)
                    {
                        try
                        {
                            var jdName  = datatable.Rows[i]["街道"].ToString();
                            var fCode   = datatable.Rows[i]["序号"].ToString();
                            var address = datatable.Rows[i]["地址"].ToString();
                            var name    = datatable.Rows[i]["工地名称"].ToString();



                            var StreetNamekey = StreetApp.GetDictionary(d => d.StreetName == jdName)[0].Key;

                            var streetModel = StreetApp.GetForm(StreetNamekey);

                            model = new ProfileAmenitiesConstructionSiteEntity()
                            {
                                CityId    = streetModel.CityId,
                                CountyId  = streetModel.CountyId,
                                StreetId  = streetModel.F_Id,
                                Address   = address,
                                F_EnCode  = fCode,
                                SiteName  = name,
                                ProjectId = projectId
                            };

                            models[i] = model;
                        }
                        catch
                        {
                        }
                    }
                    var thapp = new ProfileAmenitiesConstructionSiteApp();
                    foreach (var item in models)
                    {
                        try
                        {
                            if (item == null)
                            {
                                continue;
                            }
                            thapp.SubmitForm(item, string.Empty);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            #endregion


            return(Success("ss"));
        }
Exemplo n.º 5
0
        public ActionResult GetEnableGridJsonByCountyId(string CountyId)
        {
            var data = StreetApp.GetDictionary(d => d.CountyId == CountyId);

            return(Content(data.ToJson()));
        }