public ActionResult GroupInsert(GroupAddViewModel model) { GroupDto groupDto = new GroupDto(); groupDto.GroupName = model.GroupName; groupDto.GroupInfo = model.GroupInfo; GroupBll.AddGroup(groupDto); return RedirectTo("/Group/GroupIndex", "医生添加成功了"); //return RedirectToAction("GroupIndex"); }
public static void AddGroup(GroupDto groupDto) { SqlParameter[] arParames = GroupDal.getParameters(groupDto); SqlConnection myconn = new SqlConnection(CommonDal.ConnectionString); try { SqlHelper.ExecuteNonQuery(myconn, CommandType.StoredProcedure, "CreateGroup", arParames); } catch (SqlException ex) { throw ex; } finally { myconn.Close(); myconn.Dispose(); } }
public static List<GroupDto> GetGroupList(string tabel,string strwhere) { List<GroupDto> grouplist = new List<GroupDto>(); SqlParameter[] arParames = new SqlParameter[2]; arParames[0] = new SqlParameter("@table ", SqlDbType.VarChar, 200); arParames[0].Value = tabel; arParames[1] = new SqlParameter("@Where ", SqlDbType.VarChar, 8000); arParames[1].Value = strwhere; SqlConnection myconn = new SqlConnection(CommonDal.ConnectionString); try { DataTable dt = null; DataSet ds = SqlHelper.ExecuteDataset(myconn, CommandType.StoredProcedure, "getModelByWhere", arParames); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { GroupDto groupDto = new GroupDto(); groupDto = GroupDal.getDataRowToGroupDto(dr); grouplist.Add(groupDto); } return grouplist; } catch (SqlException ex) { throw ex; } finally { myconn.Close(); myconn.Dispose(); } }
private static SqlParameter[] getParameters(GroupDto groupDto) { SqlParameter[] arParames = new SqlParameter[3]; arParames[0] = new SqlParameter("@GroupId", SqlDbType.Int); arParames[0].Value = groupDto.GroupId; arParames[1] = new SqlParameter("@GroupName", SqlDbType.VarChar, 50); arParames[1].Value = groupDto.GroupName; arParames[2] = new SqlParameter("@GroupInfo", SqlDbType.Text); arParames[2].Value = groupDto.GroupInfo; return arParames; }
private static GroupDto getDataRowToGroupDto(DataRow dr) { GroupDto groupDto = new GroupDto(); groupDto.GroupId = int.Parse(dr["GroupId"].ToString()); groupDto.GroupName = dr["GroupName"].ToString(); groupDto.GroupInfo = dr["GroupInfo"].ToString(); return groupDto; }