Пример #1
0
        public IHttpActionResult Delete(string ID)
        {
            CnDrug model = service.Get(ID);

            if (model != null)
            {
                model.IsDeleted = true;
                service.Edit(model);
            }

            return(Ok("ok"));
        }
Пример #2
0
        public bool Edit(CnDrug model)
        {
            using (CnDrugDAL dal = new CnDrugDAL())
            {
                if (model == null)
                {
                    return(false);
                }

                DUG_CNDRUG entitys = ModelToEntity(model);
                entitys.CREATEDATETIME = DateTime.Now;

                return(dal.Edit(entitys));
            }
        }
Пример #3
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Add(CnDrug model)
        {
            if (model == null)
            {
                return(string.Empty);
            }
            using (CnDrugDAL dal = new CnDrugDAL())
            {
                DUG_CNDRUG entity = ModelToEntity(model);
                entity.ID             = string.IsNullOrEmpty(model.ID) ? Guid.NewGuid().ToString("N") : model.ID;
                entity.CREATEDATETIME = (model.CreateDateTime != null && model.CreateDateTime.HasValue) ? model.CreateDateTime.Value : DateTime.Now;

                return(dal.Add(entity));
            }
        }
Пример #4
0
        public IHttpActionResult Post([FromBody] Request <CnDrug> request)
        {
            CnDrug model = request.Data as CnDrug;

            if (string.IsNullOrEmpty(model.ID))
            {
                service.Add(model);
            }
            else
            {
                service.Edit(model);
            }

            return(Ok("ok"));
        }
Пример #5
0
        /// <summary>
        /// Entity转Model
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private CnDrug EntityToModel(DUG_CNDRUG entity)
        {
            if (entity != null)
            {
                CnDrug model = new CnDrug()
                {
                    ID                 = entity.ID,
                    DrugBankID         = entity.DRUGBANKID,
                    Name               = entity.NAME,
                    PinyinCode         = entity.PINYINCODE,
                    EnName             = entity.ENNAME,
                    CommonName         = entity.COMMONNAME,
                    TypeName           = entity.TYPENAME,
                    KindName           = entity.KINDNAME,
                    IsPrescription     = entity.ISPRESCRIPTION,
                    IsMedicalInsurance = entity.ISMEDICALINSURANCE,
                    Company            = entity.COMPANY,
                    Pack               = entity.PACK,
                    DosageForms        = entity.DOSAGEFORMS,
                    Dosage             = entity.DOSAGE,
                    Description        = entity.DESCRIPTION,
                    Indication         = entity.INDICATION,
                    Content            = entity.CONTENT,
                    Price              = entity.PRICE,
                    Contraindication   = entity.CONTRAINDICATION,
                    Notice             = entity.NOTICE,
                    Adverse            = entity.ADVERSE,
                    CreateUserID       = entity.CREATEUSERID,
                    CreateUserName     = entity.CREATEUSERNAME,
                    CreateDateTime     = entity.CREATEDATETIME,
                    EditUserID         = entity.EDITUSERID,
                    EditUserName       = entity.EDITUSERNAME,
                    EditTime           = entity.EDITDATETIME,
                    OwnerID            = entity.OWNERID,
                    OwnerName          = entity.OWNERNAME,
                    IsDeleted          = entity.ISDELETED
                };

                return(model);
            }

            return(null);
        }
Пример #6
0
        /// <summary>
        /// Model转Entity
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private DUG_CNDRUG ModelToEntity(CnDrug model)
        {
            if (model != null)
            {
                DUG_CNDRUG entity = new DUG_CNDRUG()
                {
                    ID                 = model.ID,
                    DRUGBANKID         = model.DrugBankID,
                    NAME               = model.Name,
                    PINYINCODE         = model.PinyinCode,
                    ENNAME             = model.EnName,
                    COMMONNAME         = model.CommonName,
                    TYPENAME           = model.TypeName,
                    KINDNAME           = model.KindName,
                    ISPRESCRIPTION     = model.IsPrescription,
                    ISMEDICALINSURANCE = model.IsMedicalInsurance,
                    COMPANY            = model.Company,
                    PACK               = model.Pack,
                    DOSAGEFORMS        = model.DosageForms,
                    DOSAGE             = model.Dosage,
                    DESCRIPTION        = model.Description,
                    INDICATION         = model.Indication,
                    CONTENT            = model.Content,
                    PRICE              = model.Price,
                    CONTRAINDICATION   = model.Contraindication,
                    NOTICE             = model.Notice,
                    ADVERSE            = model.Adverse,
                    CREATEUSERID       = model.CreateUserID,
                    CREATEUSERNAME     = model.CreateUserName,
                    CREATEDATETIME     = model.CreateDateTime,
                    EDITUSERID         = model.EditUserID,
                    EDITUSERNAME       = model.EditUserName,
                    EDITDATETIME       = model.EditTime,
                    OWNERID            = model.OwnerID,
                    OWNERNAME          = model.OwnerName,
                    ISDELETED          = model.IsDeleted
                };

                return(entity);
            }
            return(null);
        }
Пример #7
0
        public IHttpActionResult Get(string ID)
        {
            CnDrug model = service.Get(ID);

            return(Ok(model));
        }
Пример #8
0
        public IHttpActionResult Post()
        {
            //接受文件
            if (HttpContext.Current.Request.Files.Count <= 0)
            {
                return(BadRequest("异常"));
            }
            HttpPostedFile file = HttpContext.Current.Request.Files[0];

            try
            {
                //文件保存路径
                string filePath = HttpContext.Current.Server.MapPath("~/Upload/XLS/");
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }

                //文件格式判断
                string[] exts     = new string[] { ".xls", ".xlsx", ".doc", ".docx", ".jpg", ".gif", ".png", ".jpeg" };
                string   fileName = file.FileName;
                string   fileExt  = file.FileName.Substring(file.FileName.LastIndexOf("."));
                if (!exts.Contains(fileExt))
                {
                    return(BadRequest("非法文件!"));
                }

                //文件保存
                string newName = System.Guid.NewGuid().ToString("N") + fileExt;
                string strPath = filePath + newName;
                file.SaveAs(strPath);

                FileStream fs = File.OpenRead(strPath);
                IWorkbook  wk = null;
                try
                {
                    wk = new HSSFWorkbook(fs);   //把xls文件中的数据写入wk中
                }
                catch
                {
                    fs = File.OpenRead(strPath);
                    wk = new XSSFWorkbook(fs);
                }
                fs.Dispose();


                for (int i = 0; i < wk.NumberOfSheets; i++)     //NumberOfSheets是myxls.xls中总共的表数
                {
                    ISheet sheet = wk.GetSheetAt(i);            //读取当前表数据
                    for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数
                    {
                        IRow row = sheet.GetRow(j);             //读取当前行数据
                        if (row != null)
                        {
                            CnDrug model;
                            string name = GetCellValue(row.GetCell(0));
                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }

                            model = service.Get(p => p.NAME == name).FirstOrDefault();
                            if (model != null)
                            {
                                continue;
                            }

                            model                    = new CnDrug();
                            model.Name               = name;
                            model.CommonName         = GetCellValue(row.GetCell(1));
                            model.EnName             = GetCellValue(row.GetCell(2), 100);
                            model.IsDeleted          = false;
                            model.TypeName           = GetCellValue(row.GetCell(3));
                            model.KindName           = GetCellValue(row.GetCell(4));
                            model.IsMedicalInsurance = false;
                            model.IsPrescription     = false;
                            model.Pack               = GetCellValue(row.GetCell(5), 200);
                            model.Dosage             = GetCellValue(row.GetCell(6), 300);
                            model.DosageForms        = GetCellValue(row.GetCell(7));
                            model.Indication         = GetCellValue(row.GetCell(8), 300);
                            model.Description        = GetCellValue(row.GetCell(9), 300);
                            model.Content            = GetCellValue(row.GetCell(10), 300);
                            model.DrugBankID         = GetCellValue(row.GetCell(11));

                            service.Add(model);
                        }
                    }
                }
            }
            catch
            {
                return(BadRequest("异常"));
            }

            return(Ok());
        }