예제 #1
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ReturnModel Insert(Wjjg model)
        {
            try
            {
                //验证参数
                if (string.IsNullOrWhiteSpace(model.YYBH))
                {
                    return(new ReturnModel {
                        Code = 201, Msg = "请选择医院"
                    });
                }

                //保存
                StringBuilder sbSql = new StringBuilder();
                using (IDbConnection conn = new DapperConnection().DbConnection)
                {
                    //判断重名
                    sbSql.Append("SELECT * FROM WJ_JG WHERE YYBH=@YYBH AND WJZT=@WJZT");
                    Wjjg sameName = conn.QueryFirstOrDefault <Wjjg>(sbSql.ToString(), model);
                    if (sameName != null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "存在相同名称的医院"
                        });
                    }

                    sbSql.Clear();
                    model.WJZT = 1;
                    sbSql.Append("INSERT INTO WJ_JG(YYBH, WJZT, CJR, CJSJ) VALUES (@YYBH, @WJZT, @CJR, @CJSJ)");
                    int result = conn.Execute(sbSql.ToString(), model);
                    if (result.Equals(1))
                    {
                        return(new ReturnModel {
                            Code = 200, Msg = "保存成功"
                        });
                    }
                    return(new ReturnModel {
                        Code = 201, Msg = "保存失败"
                    });
                }
            }
            catch (Exception e)
            {
                Log.WriteLog(e.Message);
                return(new ReturnModel {
                    Code = 201, Msg = "保存失败"
                });
            }
        }
예제 #2
0
        public JsonResult Save(Wjjg model)
        {
            ReturnModel returnModel;

            if (model.ID.Equals(0))
            {
                model.CJR   = GLYadmin.GLYUserAccount;
                model.CJSJ  = DateTime.Now;
                returnModel = wjjgService.Insert(model);
                return(Json(returnModel, JsonRequestBehavior.AllowGet));
            }

            returnModel = wjjgService.Update(model);
            return(Json(returnModel, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        public ReturnModel Delete(int id)
        {
            StringBuilder sbSql = new StringBuilder();

            using (IDbConnection conn = new DapperConnection().DbConnection)
            {
                var transaction = conn.BeginTransaction();
                try
                {
                    sbSql.Append($"SELECT * FROM WJ_JG WHERE ID={id}");
                    Wjjg model = conn.QueryFirstOrDefault <Wjjg>(sbSql.ToString(), null, transaction);
                    if (model == null)
                    {
                        return new ReturnModel {
                                   Code = 201, Msg = "医院不存在"
                        }
                    }
                    ;

                    sbSql.Clear();
                    sbSql.Append($"DELETE FROM WJ_TCBQ WHERE GLID IN (SELECT id FROM WJ_TC WHERE TCID IN (SELECT TCID FROM TC_TJ WHERE YYBH='{model.YYBH}'))");
                    conn.Execute(sbSql.ToString(), null, transaction);

                    sbSql.Clear();
                    sbSql.Append($"DELETE FROM WJ_TC WHERE TCID IN (SELECT tcid FROM TC_TJ WHERE yybh='{model.YYBH}')");
                    conn.Execute(sbSql.ToString(), null, transaction);

                    sbSql.Append($"DELETE FROM WJ_JG WHERE ID={id}");
                    conn.Execute(sbSql.ToString(), null, transaction);

                    transaction.Commit();
                    return(new ReturnModel {
                        Code = 200, Msg = "删除成功"
                    });
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    Log.WriteLog(e.Message);
                    return(new ReturnModel {
                        Code = 201, Msg = "删除失败"
                    });
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        public ReturnModel Update(Wjjg model)
        {
            try
            {
                StringBuilder sbSql = new StringBuilder();
                using (IDbConnection conn = new DapperConnection().DbConnection)
                {
                    //判断医院存在
                    sbSql.Append("SELECT * FROM WJ_JG WHERE Id=@Id");
                    Wjjg existModel = conn.QueryFirstOrDefault <Wjjg>(sbSql.ToString(), new { Id = model.ID });
                    if (existModel == null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "医院不存在"
                        });
                    }

                    //保存更新
                    sbSql.Clear();
                    sbSql.Append("UPDATE WJ_JG SET WJZT = @WJZT WHERE ID = @ID");
                    int result = conn.Execute(sbSql.ToString(), model);

                    if (result.Equals(1))
                    {
                        return(new ReturnModel {
                            Code = 200, Msg = model.WJZT.Equals(0)?"停用成功":"启用成功"
                        });
                    }

                    return(new ReturnModel {
                        Code = 201, Msg = model.WJZT.Equals(0) ? "停用失败" : "启用失败"
                    });
                }
            }
            catch (Exception e)
            {
                Log.WriteLog(e.Message);
                return(new ReturnModel {
                    Code = 201, Msg = "保存失败"
                });
            }
        }
예제 #5
0
 public JsonResult AddOrEdit(int id = 0)
 {
     try
     {
         Wjjg bq = new Wjjg();
         if (id > 0)
         {
             bq = wjjgService.GetEntity(id);
         }
         return(Json(new ReturnModel {
             Code = 200, Msg = "Success", Result = bq
         }));
     }
     catch (Exception e)
     {
         Log.WriteLog(e.Message);
         return(Json(new ReturnModel {
             Code = 201, Msg = "获取标签失败"
         }));
     }
 }