Exemplo n.º 1
0
        public ActionResult FormKW(MEDICINE_VIEWMODEL model)
        {
            var sdId        = ProjectProvider.Instance.Current.SD_ID;
            var termcatconf = _termcatconfService.GetManay(d =>
                                                           d.TERM_CAT_CODE == model.TERM_CAT_CODE && d.TERM_CAT1_CODE == model.TERM_CAT1_CODE && d.SD_ID == sdId &&
                                                           d.TERM_TYPE == 1);

            if (model.TERM_CAT2_CODE != null && !model.TERM_CAT2_CODE.Equals("null"))
            {
                termcatconf = termcatconf.Where(d => d.TERM_CAT2_CODE == model.TERM_CAT2_CODE).ToList();
            }
            if (model.TERM_CAT3_CODE != null && !model.TERM_CAT3_CODE.Equals("null"))
            {
                termcatconf = termcatconf.Where(d => d.TERM_CAT3_CODE == model.TERM_CAT3_CODE).ToList();
            }
            if (_medicineKWService.Exists(d => d.TERM_KW_MAP_ID == model.TERM_KW_MAP_ID))
            {
                var entity = _medicineKWService.GetWithTrace(r => r.TERM_KW_MAP_ID == model.TERM_KW_MAP_ID);
                entity.TERM_KW_NAME     = model.TERM_KW_NAME;
                entity.TERM_CAT_CONF_ID = termcatconf.FirstOrDefault().TERM_CAT_CONF_ID;
                var row = _medicineKWService.Update(entity);
                return(row > 0 ? Success() : Error());
            }
            else
            {
                var value = new UN_SD_TERM_KW_MAP
                {
                    TERM_CAT_CONF_ID = termcatconf.FirstOrDefault().TERM_CAT_CONF_ID,
                    TERM_KW_NAME     = model.TERM_KW_NAME,
                    ATTR2_NAME       = "",
                    ATTR1_NAME       = "",
                    MEMO             = "",
                    UPD_USER_ID      = "",
                    UPD_DATE         = DateTime.Now,
                    SD_ID            = sdId
                };
                var m =
                    _medicineKWService.GetWithTrace(
                        d => d.TERM_CAT_CONF_ID == value.TERM_CAT_CONF_ID && d.SD_ID == sdId &&
                        d.TERM_KW_NAME.Trim() == value.TERM_KW_NAME.Trim());
                if (m != null)
                {
                    return(Error("该关键字已存在,无法重复添加!"));
                }
                var entity = _medicineKWService.Insert(value);
                return(entity != null?Success() : Error());
            }
        }
Exemplo n.º 2
0
        public ActionResult Form(MEDICINE_VIEWMODEL model)
        {
            var sdId        = ProjectProvider.Instance.Current.SD_ID;
            var termcatconf = _termcatconfService.GetManay(d =>
                                                           d.TERM_CAT_CODE == model.TERM_CAT_CODE && d.TERM_CAT1_CODE == model.TERM_CAT1_CODE && d.SD_ID == sdId &&
                                                           d.TERM_TYPE == 1);

            if (model.TERM_CAT2_CODE != null && !model.TERM_CAT2_CODE.Equals("null"))
            {
                termcatconf = termcatconf.Where(d => d.TERM_CAT2_CODE == model.TERM_CAT2_CODE).ToList();
            }
            if (model.TERM_CAT3_CODE != null && !model.TERM_CAT3_CODE.Equals("null"))
            {
                termcatconf = termcatconf.Where(d => d.TERM_CAT3_CODE == model.TERM_CAT3_CODE).ToList();
            }
            if (_medicineService.Exists(d => d.DRUG_MAP_ID == model.DRUG_MAP_ID))
            {
                var entity = _medicineService.GetWithTrace(r => r.DRUG_MAP_ID == model.DRUG_MAP_ID);
                entity.DRUG_CODE        = model.DRUG_CODE;
                entity.DRUG_NAME        = model.DRUG_NAME;
                entity.DRUG_BRAND_NAME  = model.DRUG_BRAND_NAME;
                entity.DRUG_GEN_NAME    = model.DRUG_GEN_NAME;
                entity.DRUG_OTH_NAME    = model.DRUG_OTH_NAME;
                entity.TERM_CAT_CONF_ID = termcatconf.FirstOrDefault().TERM_CAT_CONF_ID;
                var row = _medicineService.Update(entity);
                return(row > 0 ? Success() : Error());
            }
            else
            {
                var drugcode = "";
                if (string.IsNullOrEmpty(model.DRUG_CODE))
                {
                    var lsDrugCode = _medicineService
                                     .GetManay(d => d.SD_ID == sdId)
                                     .Select(d => new { d.DRUG_CODE }).Distinct().ToList()
                                     .FindAll(d => Regex.IsMatch(d.DRUG_CODE, @"^\d+$"));
                    var lsDrugCodeInt = lsDrugCode.Select(d => new { drugcode = Convert.ToInt32(d.DRUG_CODE) })
                                        .OrderByDescending(d => d.drugcode);
                    var drugCodeInt = lsDrugCodeInt.FirstOrDefault()?.drugcode;
                    if (drugCodeInt > 0)
                    {
                        drugCodeInt++;
                    }
                    drugcode = drugCodeInt.ToString();
                }
                else
                {
                    if (_medicineService.Count(d => d.DRUG_CODE == model.DRUG_CODE && d.SD_ID == sdId) <= 0)
                    {
                        drugcode = model.DRUG_CODE;
                    }
                    else
                    {
                        return(Error("此药品编码已在数据库中存在,请重新输入!"));
                    }
                }
                var value = new UN_SD_DRUG_MAP
                {
                    TERM_CAT_CONF_ID = termcatconf.FirstOrDefault().TERM_CAT_CONF_ID,
                    DRUG_CODE        = drugcode,
                    DRUG_NAME        = model.DRUG_NAME,
                    DRUG_GEN_NAME    = model.DRUG_GEN_NAME,
                    DRUG_BRAND_NAME  = model.DRUG_BRAND_NAME,
                    DRUG_OTH_NAME    = model.DRUG_OTH_NAME,
                    DRG_ATC_CODE     = "",
                    MEMO             = "",
                    UPD_USER_ID      = "",
                    UPD_DATE         = DateTime.Now,
                    SD_ID            = sdId
                };

                var entity = _medicineService.Insert(value);
                return(entity != null?Success() : Error());
            }
        }