Ejemplo n.º 1
0
        /// <summary>
        /// 导入数据
        /// </summary>
        /// <returns></returns>
        public ActionResult ExcelImport()
        {
            JsonObject         json = new JsonObject();
            HttpPostedFileBase file = Request.Files["fileImport"];

            if (file == null || file.ContentLength <= 0)
            {
                json.Status      = JsonObject.STATUS_FAIL;
                json.ErroMessage = "文件不能为空";
                return(Json(json));
            }
            string[] FileType   = new string[] { ".xls", ".xlsx" };                     //定义上传文件的类型
            string   filename   = Path.GetFileName(file.FileName);
            int      filesize   = file.ContentLength;                                   //获取上传文件的大小单位为字节byte
            string   fileEx     = System.IO.Path.GetExtension(filename);                //获取上传文件的扩展名
            string   NoFileName = System.IO.Path.GetFileNameWithoutExtension(filename); //获取无扩展名的文件名

            if (!fileEx.Contains(fileEx.ToLower()))
            {
                json.Status      = JsonObject.STATUS_FAIL;
                json.ErroMessage = "文件类型不对,只能导入xls和xlsx格式的文件";
                return(Json(json));
            }
            DataTable dt = ExcelHelper.ReadExcelToDataTable(Server.MapPath("~/"), file, fileEx.ToLower());
            //查询和模板页列是否相同
            DataTable dtTemplate = NOPI_ExcelHelp.ImportDataTableFromExcel2007(Server.MapPath("~/") + @"\Excel\Template\销售健康度模板.xlsx");

            json = new Excel.HealthXsExcel().Import(dt, dtTemplate);
            return(Json(json));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        public ActionResult Save(Model.Health_Xs model)
        {
            JsonObject    json   = new JsonObject();
            StringBuilder sbErro = new StringBuilder();

            if (string.IsNullOrEmpty(model.区域))
            {
                sbErro.Append(",区域不能为空");
            }
            else
            {
                Model.Area modelParmExist = new BLL.Area().GetModel(model.区域);
                if (modelParmExist == null)
                {
                    sbErro.Append(",区域不存在");
                }
            }
            if (string.IsNullOrEmpty(model.客户名称))
            {
                sbErro.Append(",客户名称不能为空");
            }
            else
            {
                Model.Customer modelParmExist = new BLL.Customer().GetModel(model.客户名称);
                if (modelParmExist == null)
                {
                    sbErro.Append(",客户名称不存在");
                }
            }
            if (string.IsNullOrEmpty(model.站点编码))
            {
                sbErro.Append(",站点编码不能为空");
            }
            if (string.IsNullOrEmpty(model.站点名称))
            {
                sbErro.Append(",站点名称不能为空");
            }
            if (sbErro.Length > 0)
            {
                json.Status      = JsonObject.STATUS_FAIL;
                json.ErroMessage = sbErro.ToString().Substring(1);
                return(Json(json));
            }
            //初始化自动生成值
            Excel.HealthXsExcel healthXsExcel = new Excel.HealthXsExcel();
            model.伟通收入不含税 = 0;
            model.累计应收金额  = 0;
            healthXsExcel.Get伟通收入不含税(model);
            healthXsExcel.Get累计应收金额(model);
            //如果ID为空,则是添加
            if (string.IsNullOrEmpty(model.id))
            {
                List <Model.Health_Xs> modelExistsList = BLL.GetModelList("站点编码='" + model.站点编码 + "' and IsDeleted!=1");
                if (modelExistsList != null && modelExistsList.Count > 0)
                {
                    json.Status      = JsonObject.STATUS_FAIL;
                    json.ErroMessage = "添加失败,此数据已存在";
                    return(Json(json));
                }
                model.IsDeleted  = 0;
                model.CreateTime = DateTime.Now;
                model.CreateBy   = CurrentUser.User.Userinfo.UserID;
                model.id         = Guid.NewGuid().ToString();
                bool res = BLL.Add(model);
                if (res)
                {
                    json.Status  = JsonObject.STATUS_SUCCESS;
                    json.Message = "添加成功";
                    return(Json(json));
                }
                else
                {
                    json.Status      = JsonObject.STATUS_FAIL;
                    json.ErroMessage = "添加失败";
                    return(Json(json));
                }
            }
            else
            {
                List <Model.Health_Xs> modelExistsList = BLL.GetModelList("站点编码='" + model.站点编码 + "' and id!='" + model.id + "' and IsDeleted!=1");
                if (modelExistsList != null && modelExistsList.Count > 0)
                {
                    json.Status      = JsonObject.STATUS_FAIL;
                    json.ErroMessage = "添加失败,此数据已存在";
                    return(Json(json));
                }
                Model.Health_Xs modelOld = BLL.GetModel(model.id);
                if (modelOld == null)
                {
                    json.Status      = JsonObject.STATUS_FAIL;
                    json.ErroMessage = "数据不存在";
                    return(Json(json));
                }
                if (modelOld.IsDeleted == 1)
                {
                    json.Status      = JsonObject.STATUS_FAIL;
                    json.ErroMessage = "修改失败,数据已删除";
                    return(Json(json));
                }
                model.IsDeleted  = modelOld.IsDeleted;
                model.CreateBy   = modelOld.CreateBy;
                model.CreateTime = modelOld.CreateTime;
                model.UpdateTime = DateTime.Now;
                model.UpdateBy   = CurrentUser.User.Userinfo.UserID;
                bool res = BLL.Update(model);
                if (res)
                {
                    json.Status  = JsonObject.STATUS_SUCCESS;
                    json.Message = "修改成功";
                    return(Json(json));
                }
                else
                {
                    json.Status      = JsonObject.STATUS_FAIL;
                    json.ErroMessage = "修改失败";
                    return(Json(json));
                }
            }
        }