/// <summary>
 /// 获取单个角色
 /// </summary>
 /// <param name="id">角色Id</param>
 /// <returns></returns>
 public JsModel GetJs(int id)
 {
     using (IDbConnection conn = new DapperConnection().DbConnection)
     {
         string  sql   = "SELECT * FROM xt_jsglb WHERE Id=@Id";
         JsModel model = conn.Query <JsModel>(sql, new { Id = id }).FirstOrDefault();
         return(model);
     }
 }
Example #2
0
        public JsonResult Save(JsModel model)
        {
            ReturnModel returnModel;

            model.Gxrq = DateTime.Now;
            model.Gxr  = GLYadmin.GLYUserAccount;
            model.Yybh = GLYadmin.YYID;
            if (model.Id.Equals(0))
            {
                model.Cjrq  = DateTime.Now;
                model.Cjr   = GLYadmin.GLYUserAccount;
                returnModel = jsglbService.AddJs(model);
                return(Json(returnModel, JsonRequestBehavior.AllowGet));
            }

            returnModel = jsglbService.UpdateJs(model);
            return(Json(returnModel, JsonRequestBehavior.AllowGet));
        }
Example #3
0
 public JsonResult AddOrEdit(int id = 0)
 {
     try
     {
         JsModel js = new JsModel();
         if (id > 0)
         {
             js = jsglbService.GetJs(id);
         }
         return(Json(new ReturnModel {
             Code = 200, Msg = "Success", Result = js
         }));
     }
     catch (Exception e)
     {
         return(Json(new ReturnModel {
             Code = 201, Msg = "获取角色失败"
         }));
     }
 }
Example #4
0
        /// <summary>
        /// Generates the models in JavaScript.
        /// </summary>
        /// <param name="assemblyName">The fully qualitified assembly name.</param>
        /// <returns></returns>
        public static string GenerateModelScript(string assemblyName)
        {
            try
            {
                var assembly    = Assembly.Load(assemblyName);
                var allTypes    = assembly.GetTypes();
                var targetTypes = new List <Type>();

                foreach (var type in allTypes)
                {
                    var attributes = type.GetCustomAttributes(false);
                    for (var i = 0; i < attributes.Length; i++)
                    {
                        var modelAttribute = attributes[i] as ModelAttribute;
                        //TODO: Read more info from attribute in the future
                        if (modelAttribute != null)
                        {
                            targetTypes.Add(type);
                        }
                    }
                }

                var modelInfos = GetModelInfos(targetTypes);

                var codeBuilder = new StringBuilder();
                foreach (var modelInfo in modelInfos)
                {
                    var modelTemplate = new JsModel(modelInfo);
                    codeBuilder.Append(modelTemplate.TransformText());
                }

                return(codeBuilder.ToString());
            }
            catch (System.IO.FileNotFoundException)
            {
                return(String.Empty);
            }
        }
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <returns></returns>
        public ReturnModel UpdateJs(JsModel model)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.Jsmc))
                {
                    return(new ReturnModel {
                        Code = 201, Msg = "角色名称不能为空"
                    });
                }
                if (model.Lx == 1 || model.Lx == 3)
                {
                    if (string.IsNullOrWhiteSpace(model.Yybh))
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "医院编号不能为空"
                        });
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(model.QdId.ToString()))
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "渠道不能为空"
                        });
                    }
                }
                StringBuilder sbSql = new StringBuilder();
                using (IDbConnection conn = new DapperConnection().DbConnection)
                {
                    //判断角色存在
                    sbSql.Append("SELECT * FROM xt_jsglb WHERE Id=@Id");
                    JsModel existModel = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), new { Id = model.Id });
                    if (existModel == null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "角色不存在"
                        });
                    }

                    //判断重名
                    sbSql.Clear();
                    sbSql.Append("SELECT * FROM xt_jsglb WHERE Id<>@Id AND Jsmc=@Jsmc and lx=" + model.Lx.ToString());
                    JsModel sameName = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), model);
                    if (sameName != null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "存在相同名称的角色"
                        });
                    }

                    //保存更新
                    sbSql.Clear();
                    sbSql.Append("UPDATE xt_jsglb SET Jsmc=@Jsmc, Bz=@Bz, Yybh=@Yybh, Gxrq=@Gxrq, Gxr=@Gxr WHERE Id=@Id");
                    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 = "保存失败"
                });
            }
        }
        /// <summary>
        /// 新增角色
        /// </summary>
        /// <returns></returns>
        public ReturnModel AddJs(JsModel model)
        {
            try
            {
                //验证参数
                if (string.IsNullOrWhiteSpace(model.Jsmc))
                {
                    return(new ReturnModel {
                        Code = 201, Msg = "角色名称不能为空"
                    });
                }
                if (model.Lx == 1 || model.Lx == 3)
                {
                    if (string.IsNullOrWhiteSpace(model.Yybh))
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "医院编号不能为空"
                        });
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(model.QdId.ToString()))
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "渠道不能为空"
                        });
                    }
                }
                //保存
                StringBuilder sbSql = new StringBuilder();
                using (IDbConnection conn = new DapperConnection().DbConnection)
                {
                    //判断重名
                    sbSql.Append("SELECT * FROM xt_jsglb WHERE Jsmc=@Jsmc and Lx=" + model.Lx.ToString());
                    JsModel sameName = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), model);
                    if (sameName != null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "存在相同名称的角色"
                        });
                    }

                    sbSql.Clear();
                    sbSql.Append("INSERT INTO xt_jsglb (Jsmc, Bz, Yybh, Cjrq, Cjr, Gxrq, Gxr,Lx,QdId) VALUES (@Jsmc, @Bz, @Yybh, @Cjrq, @Cjr, @Gxrq, @Gxr,@Lx,@QdId)");
                    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 = "保存失败"
                });
            }
        }
        public ReturnModel Add(XtZhbModel model)
        {
            try
            {
                //验证参数
                if (string.IsNullOrWhiteSpace(model.zh))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "账号不能为空"
                    }
                }
                ;
                if (string.IsNullOrWhiteSpace(model.mm))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "医院编号不能为空"
                    }
                }
                ;
                if (string.IsNullOrWhiteSpace(model.dh))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "手机号不能为空"
                    }
                }
                ;
                if (model.jsid.Equals(0))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "请选择角色"
                    }
                }
                ;
                if (string.IsNullOrWhiteSpace(model.lxr))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "姓名不能为空"
                    }
                }
                ;
                StringBuilder     sbSql     = new StringBuilder();
                DynamicParameters paramList = new DynamicParameters();
                paramList.Add("Zh", model.zh);
                paramList.Add("Mm", model.mm);
                paramList.Add("CreateTime", model.createtime);
                paramList.Add("Dh", model.dh);
                paramList.Add("Lxr", model.lxr);
                paramList.Add("Ys", model.ys);
                paramList.Add("Yybh", model.yybh);
                paramList.Add("Jsid", model.jsid);
                paramList.Add("Zt", model.zt);
                paramList.Add("Bz", model.bz);
                paramList.Add("QdId", model.QdId);
                paramList.Add("Lx", model.Lx);
                paramList.Add("Txlj", model.txlj);
                using (IDbConnection conn = new DapperConnection().DbConnection)
                {
                    //判断重名
                    sbSql.Clear();

                    sbSql.Append("SELECT * FROM xt_zhb WHERE zh=@Zh");
                    JsModel sameName = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), paramList);
                    if (sameName != null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "存在相同的账号名"
                        });
                    }

                    sbSql.Clear();
                    sbSql.Append("INSERT INTO xt_zhb (zh, mm, createtime, dh, lxr, ys, yybh, jsid, zt, bz,Lx,QdId,txlj) VALUES (@Zh, @Mm, @CreateTime, @Dh, @Lxr, @Ys, @Yybh, @Jsid, @Zt, @Bz,@Lx,@QdId,@Txlj)");
                    int result = conn.Execute(sbSql.ToString(), paramList);
                    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 = "保存失败"
                });
            }
        }
        /// <summary>
        /// 修改账号
        /// </summary>
        /// <returns></returns>
        public ReturnModel Update(XtZhbModel model)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.zh))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "账号不能为空"
                    }
                }
                ;
                if (string.IsNullOrWhiteSpace(model.mm))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "医院编号不能为空"
                    }
                }
                ;
                if (model.jsid.Equals(0))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "请选择角色"
                    }
                }
                ;
                if (string.IsNullOrWhiteSpace(model.lxr))
                {
                    return new ReturnModel {
                               Code = 201, Msg = "姓名不能为空"
                    }
                }
                ;
                StringBuilder sbSql = new StringBuilder();
                using (IDbConnection conn = new DapperConnection().DbConnection)
                {
                    DynamicParameters paramList = new DynamicParameters();

                    paramList.Add("Id", model.id);
                    paramList.Add("Zh", model.zh);
                    paramList.Add("Mm", model.mm);
                    paramList.Add("Dh", model.dh);
                    paramList.Add("Lxr", model.lxr);
                    paramList.Add("Ys", model.ys);
                    paramList.Add("Yybh", model.yybh);
                    paramList.Add("Jsid", model.jsid);
                    paramList.Add("Zt", model.zt);
                    paramList.Add("Bz", model.bz);
                    //判断账号存在
                    sbSql.Append("SELECT * FROM xt_zhb WHERE Id=@Id");
                    XtZhbModel existModel = conn.QueryFirstOrDefault <XtZhbModel>(sbSql.ToString(), paramList);
                    if (existModel == null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "账号不存在"
                        });
                    }

                    //判断重名
                    sbSql.Clear();
                    sbSql.Append("SELECT * FROM xt_zhb WHERE id<>@Id AND zh=@Zh");
                    JsModel sameName = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), paramList);
                    if (sameName != null)
                    {
                        return(new ReturnModel {
                            Code = 201, Msg = "存在相同的账号名"
                        });
                    }

                    //保存更新
                    sbSql.Clear();
                    sbSql.Append("UPDATE xt_zhb SET zh=@Zh, mm=@Mm, dh=@Dh, lxr=@Lxr, ys=@Ys, jsid=@Jsid, zt=@Zt, bz=@Bz WHERE Id=@Id");
                    int result = conn.Execute(sbSql.ToString(), paramList);
                    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 = "保存失败"
                });
            }
        }