public int GetRecordCount() { string sql = "select count(*) from users"; return(Convert.ToInt32(DbHelperSql.ExecuteScalar(sql, CommandType.Text))); }
public int DeleteUser(int id) { string sql = "delete from users where id=@id"; return(DbHelperSql.ExecuteNonQuery(sql, CommandType.Text, new SqlParameter("@id", id))); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.gsjs GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,year,month,depart,departid,empid,name,gzjb,yfje,kk,gjj,bxkk,zxkk,jckk,ysgzlj,gslj,bygs from r_jshz "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.gsjs model = new Model.gsjs(); DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["year"] != null && ds.Tables[0].Rows[0]["year"].ToString() != "") { model.year = ds.Tables[0].Rows[0]["year"].ToString(); } if (ds.Tables[0].Rows[0]["month"] != null && ds.Tables[0].Rows[0]["month"].ToString() != "") { model.month = ds.Tables[0].Rows[0]["month"].ToString(); } if (ds.Tables[0].Rows[0]["depart"] != null && ds.Tables[0].Rows[0]["depart"].ToString() != "") { model.depart = ds.Tables[0].Rows[0]["depart"].ToString(); } if (ds.Tables[0].Rows[0]["departid"] != null && ds.Tables[0].Rows[0]["departid"].ToString() != "") { model.departid = ds.Tables[0].Rows[0]["departid"].ToString(); } if (ds.Tables[0].Rows[0]["empid"] != null && ds.Tables[0].Rows[0]["empid"].ToString() != "") { model.empid = ds.Tables[0].Rows[0]["empid"].ToString(); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["gzjb"] != null && ds.Tables[0].Rows[0]["gzjb"].ToString() != "") { model.gzjb = ds.Tables[0].Rows[0]["gzjb"].ToString(); } if (ds.Tables[0].Rows[0]["yfje"] != null && ds.Tables[0].Rows[0]["yfje"].ToString() != "") { model.yfje = double.Parse(ds.Tables[0].Rows[0]["yfje"].ToString()); } if (ds.Tables[0].Rows[0]["kk"] != null && ds.Tables[0].Rows[0]["kk"].ToString() != "") { model.kk = double.Parse(ds.Tables[0].Rows[0]["kk"].ToString()); } if (ds.Tables[0].Rows[0]["gjj"] != null && ds.Tables[0].Rows[0]["gjj"].ToString() != "") { model.gjj = double.Parse(ds.Tables[0].Rows[0]["gjj"].ToString()); } if (ds.Tables[0].Rows[0]["bxkk"] != null && ds.Tables[0].Rows[0]["bxkk"].ToString() != "") { model.bxkk = double.Parse(ds.Tables[0].Rows[0]["bxkk"].ToString()); } if (ds.Tables[0].Rows[0]["zxkk"] != null && ds.Tables[0].Rows[0]["zxkk"].ToString() != "") { model.zxkk = double.Parse(ds.Tables[0].Rows[0]["zxkk"].ToString()); } if (ds.Tables[0].Rows[0]["jckk"] != null && ds.Tables[0].Rows[0]["jckk"].ToString() != "") { model.jckk = double.Parse(ds.Tables[0].Rows[0]["jckk"].ToString()); } if (ds.Tables[0].Rows[0]["ysgzlj"] != null && ds.Tables[0].Rows[0]["ysgzlj"].ToString() != "") { model.ysgzlj = double.Parse(ds.Tables[0].Rows[0]["ysgzlj"].ToString()); } if (ds.Tables[0].Rows[0]["gslj"] != null && ds.Tables[0].Rows[0]["gslj"].ToString() != "") { model.gslj = double.Parse(ds.Tables[0].Rows[0]["gslj"].ToString()); } if (ds.Tables[0].Rows[0]["bygs"] != null && ds.Tables[0].Rows[0]["bygs"].ToString() != "") { model.bygs = double.Parse(ds.Tables[0].Rows[0]["bygs"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.gsjs model) { int newId; using (SqlConnection conn = new SqlConnection(DbHelperSql.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into r_jshz("); strSql.Append("year,month,depart,departid,empid,name,gzjb,yfje,kk,gjj,bxkk,zxkk,jckk,ysgzlj,gslj,bygs)"); strSql.Append(" values ("); strSql.Append("@year,@month,@depart,@departid,@empid,@name,@gzjb,@yfje,@kk,@gjj,@bxkk,@zxkk,@jckk,@ysgzlj,@gslj,@bygs)"); SqlParameter[] parameters = { new SqlParameter("@year", SqlDbType.VarChar, 50), new SqlParameter("@month", SqlDbType.VarChar, 50), new SqlParameter("@depart", SqlDbType.VarChar, 50), new SqlParameter("@departid", SqlDbType.VarChar, 50), new SqlParameter("@empid", SqlDbType.VarChar, 50), new SqlParameter("@name", SqlDbType.VarChar, 50), new SqlParameter("@gzjb", SqlDbType.VarChar, 50), new SqlParameter("@yfje", SqlDbType.Decimal), new SqlParameter("@kk", SqlDbType.Decimal), new SqlParameter("@gjj", SqlDbType.Decimal), new SqlParameter("@bxkk", SqlDbType.Decimal), new SqlParameter("@zxkk", SqlDbType.Decimal), new SqlParameter("@jckk", SqlDbType.Decimal), new SqlParameter("@ysgzlj", SqlDbType.Decimal), new SqlParameter("@gslj", SqlDbType.Decimal), new SqlParameter("@bygs", SqlDbType.Decimal) }; parameters[0].Value = model.year; parameters[1].Value = model.month; parameters[2].Value = model.depart; parameters[3].Value = model.departid; parameters[4].Value = model.empid; parameters[5].Value = model.name; parameters[6].Value = model.gzjb; parameters[7].Value = model.yfje; parameters[8].Value = model.kk; parameters[9].Value = model.gjj; parameters[10].Value = model.bxkk; parameters[11].Value = model.zxkk; parameters[12].Value = model.jckk; parameters[13].Value = model.ysgzlj; parameters[14].Value = model.gslj; parameters[15].Value = model.bygs; DbHelperSql.ExecuteSql(conn, trans, strSql.ToString(), parameters); //取得新插入的ID newId = GetMaxId(conn, trans); trans.Commit(); } catch { trans.Rollback(); return(-1); } } } return(newId); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.gsjs model) { using (SqlConnection conn = new SqlConnection(DbHelperSql.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("update r_jshz set "); strSql.Append("year=@year,"); strSql.Append("month=@month,"); strSql.Append("depart=@depart,"); strSql.Append("departid=@departid,"); strSql.Append("empid=@empid,"); strSql.Append("name=@name,"); strSql.Append("yfje=@yfje,"); strSql.Append("kk=@kk,"); strSql.Append("gjj=@gjj,"); strSql.Append("bxkk=@bxkk,"); strSql.Append("zxkk=@zxkk,"); strSql.Append("jckk=@jckk,"); strSql.Append("ysgzlj=@ysgzlj,"); strSql.Append("gslj=@gslj,"); strSql.Append("bygs=@bygs"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@year", SqlDbType.VarChar, 50), new SqlParameter("@month", SqlDbType.VarChar, 50), new SqlParameter("@depart", SqlDbType.VarChar, 50), new SqlParameter("@departid", SqlDbType.VarChar, 50), new SqlParameter("@empid", SqlDbType.VarChar, 50), new SqlParameter("@name", SqlDbType.VarChar, 50), new SqlParameter("@gzjb", SqlDbType.VarChar, 50), new SqlParameter("@yfje", SqlDbType.Decimal), new SqlParameter("@kk", SqlDbType.Decimal), new SqlParameter("@gjj", SqlDbType.Decimal), new SqlParameter("@bxkk", SqlDbType.Decimal), new SqlParameter("@zxkk", SqlDbType.Decimal), new SqlParameter("@jckk", SqlDbType.Decimal), new SqlParameter("@ysgzlj", SqlDbType.Decimal), new SqlParameter("@gslj", SqlDbType.Decimal), new SqlParameter("@bygs", SqlDbType.Decimal), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.year; parameters[1].Value = model.month; parameters[2].Value = model.depart; parameters[3].Value = model.departid; parameters[4].Value = model.empid; parameters[5].Value = model.name; parameters[6].Value = model.gzjb; parameters[7].Value = model.yfje; parameters[9].Value = model.kk; parameters[10].Value = model.gjj; parameters[11].Value = model.bxkk; parameters[12].Value = model.zxkk; parameters[13].Value = model.jckk; parameters[14].Value = model.ysgzlj; parameters[15].Value = model.gslj; parameters[16].Value = model.bygs; parameters[17].Value = model.id; DbHelperSql.ExecuteSql(conn, trans, strSql.ToString(), parameters); trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.zxkc GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,year,month,empid,name,znjy,jxjy,dbyl,zfdk,zfzj,sylr from t_zxkc "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.zxkc model = new Model.zxkc(); DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["year"] != null && ds.Tables[0].Rows[0]["year"].ToString() != "") { model.year = ds.Tables[0].Rows[0]["year"].ToString(); } if (ds.Tables[0].Rows[0]["month"] != null && ds.Tables[0].Rows[0]["month"].ToString() != "") { model.month = ds.Tables[0].Rows[0]["month"].ToString(); } if (ds.Tables[0].Rows[0]["empid"] != null && ds.Tables[0].Rows[0]["empid"].ToString() != "") { model.empid = ds.Tables[0].Rows[0]["empid"].ToString(); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["znjy"] != null && ds.Tables[0].Rows[0]["znjy"].ToString() != "") { model.znjy = double.Parse(ds.Tables[0].Rows[0]["znjy"].ToString()); } if (ds.Tables[0].Rows[0]["jxjy"] != null && ds.Tables[0].Rows[0]["jxjy"].ToString() != "") { model.jxjy = double.Parse(ds.Tables[0].Rows[0]["jxjy"].ToString()); } if (ds.Tables[0].Rows[0]["dbyl"] != null && ds.Tables[0].Rows[0]["dbyl"].ToString() != "") { model.dbyl = double.Parse(ds.Tables[0].Rows[0]["dbyl"].ToString()); } if (ds.Tables[0].Rows[0]["zfdk"] != null && ds.Tables[0].Rows[0]["zfdk"].ToString() != "") { model.zfdk = double.Parse(ds.Tables[0].Rows[0]["zfdk"].ToString()); } if (ds.Tables[0].Rows[0]["zfzj"] != null && ds.Tables[0].Rows[0]["zfzj"].ToString() != "") { model.zfzj = double.Parse(ds.Tables[0].Rows[0]["zfzj"].ToString()); } if (ds.Tables[0].Rows[0]["sylr"] != null && ds.Tables[0].Rows[0]["sylr"].ToString() != "") { model.sylr = double.Parse(ds.Tables[0].Rows[0]["sylr"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.gzmx GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,year,month,empid,name,yfje,kqtk,kk,gsk,gjj2,gjj,bxkk,sfje from t_gzmx "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.gzmx model = new Model.gzmx(); DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["year"] != null && ds.Tables[0].Rows[0]["year"].ToString() != "") { model.year = ds.Tables[0].Rows[0]["year"].ToString(); } if (ds.Tables[0].Rows[0]["month"] != null && ds.Tables[0].Rows[0]["month"].ToString() != "") { model.month = ds.Tables[0].Rows[0]["month"].ToString(); } if (ds.Tables[0].Rows[0]["empid"] != null && ds.Tables[0].Rows[0]["empid"].ToString() != "") { model.empid = ds.Tables[0].Rows[0]["empid"].ToString(); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["yfje"] != null && ds.Tables[0].Rows[0]["yfje"].ToString() != "") { model.yfje = double.Parse(ds.Tables[0].Rows[0]["yfje"].ToString()); } if (ds.Tables[0].Rows[0]["kqtk"] != null && ds.Tables[0].Rows[0]["kqtk"].ToString() != "") { model.kqtk = double.Parse(ds.Tables[0].Rows[0]["kqtk"].ToString()); } if (ds.Tables[0].Rows[0]["kk"] != null && ds.Tables[0].Rows[0]["kk"].ToString() != "") { model.kk = double.Parse(ds.Tables[0].Rows[0]["kk"].ToString()); } if (ds.Tables[0].Rows[0]["gsk"] != null && ds.Tables[0].Rows[0]["gsk"].ToString() != "") { model.gsk = double.Parse(ds.Tables[0].Rows[0]["gsk"].ToString()); } if (ds.Tables[0].Rows[0]["gjj2"] != null && ds.Tables[0].Rows[0]["gjj2"].ToString() != "") { model.gjj2 = double.Parse(ds.Tables[0].Rows[0]["gjj2"].ToString()); } if (ds.Tables[0].Rows[0]["gjj"] != null && ds.Tables[0].Rows[0]["gjj"].ToString() != "") { model.gjj = double.Parse(ds.Tables[0].Rows[0]["gjj"].ToString()); } if (ds.Tables[0].Rows[0]["bxkk"] != null && ds.Tables[0].Rows[0]["bxkk"].ToString() != "") { model.bxkk = double.Parse(ds.Tables[0].Rows[0]["bxkk"].ToString()); } if (ds.Tables[0].Rows[0]["sfje"] != null && ds.Tables[0].Rows[0]["sfje"].ToString() != "") { model.sfje = double.Parse(ds.Tables[0].Rows[0]["sfje"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.gzmx model) { using (SqlConnection conn = new SqlConnection(DbHelperSql.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_gzmx set "); strSql.Append("year=@year,"); strSql.Append("month=@month,"); strSql.Append("name=@name,"); strSql.Append("yfje=@yfje,"); strSql.Append("kqtk=@kqtk,"); strSql.Append("kk=@kk,"); strSql.Append("gsk=@gsk,"); strSql.Append("gjj2=@gjj2,"); strSql.Append("gjj=@gjj,"); strSql.Append("bxkk=@bxkk,"); strSql.Append("sfje=@sfje"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@year", SqlDbType.VarChar, 50), new SqlParameter("@month", SqlDbType.VarChar, 50), new SqlParameter("@empid", SqlDbType.VarChar, 50), new SqlParameter("@name", SqlDbType.VarChar, 50), new SqlParameter("@yfje", SqlDbType.Decimal), new SqlParameter("@kqtk", SqlDbType.Decimal), new SqlParameter("@kk", SqlDbType.Decimal), new SqlParameter("@gsk", SqlDbType.Decimal), new SqlParameter("@gjj2", SqlDbType.Decimal), new SqlParameter("@gjj", SqlDbType.Decimal), new SqlParameter("@bxkk", SqlDbType.Decimal), new SqlParameter("@sfje", SqlDbType.Decimal), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.year; parameters[1].Value = model.month; parameters[2].Value = model.empid; parameters[3].Value = model.name; parameters[4].Value = model.yfje; parameters[5].Value = model.kqtk; parameters[6].Value = model.kk; parameters[7].Value = model.gsk; parameters[8].Value = model.gjj2; parameters[9].Value = model.gjj; parameters[10].Value = model.bxkk; parameters[11].Value = model.sfje; parameters[12].Value = model.id; DbHelperSql.ExecuteSql(conn, trans, strSql.ToString(), parameters); trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
/// <summary> /// 添加 /// </summary> /// <param name="NMYCtable"></param> /// <returns></returns> public static bool addjhtable(jkModel jhModel) { StringBuilder str = new StringBuilder(); StringBuilder str1 = new StringBuilder(); StringBuilder str2 = new StringBuilder(); if (jhModel.OfficeName1.ToString() != null) { str1.Append("OfficeName,"); str2.Append("'" + jhModel.OfficeName1 + "',"); } if (jhModel.BedId1.ToString() != null) { str1.Append("BedId,"); str2.Append("" + jhModel.BedId1 + ","); } if (jhModel.PatientMonitor_IP1.ToString() != null) { str1.Append("PatientMonitor_IP,"); str2.Append("'" + jhModel.PatientMonitor_IP1 + "',"); } if (jhModel.IPSeq1.ToString() != null) { str1.Append("IPSeq,"); str2.Append("'" + jhModel.IPSeq1 + "',"); } if (jhModel.MeasureTime1.ToString() != null) { str1.Append("MeasureTime,"); str2.Append("'" + jhModel.MeasureTime1 + "',"); } if (jhModel.HR1.ToString() != null) { str1.Append("HR,"); str2.Append("'" + jhModel.HR1 + "',"); } if (jhModel.SpO21.ToString() != null) { str1.Append("SpO2,"); str2.Append("'" + jhModel.SpO21 + "',"); } if (jhModel.PVCs1.ToString() != null) { str1.Append("PVCs,"); str2.Append("'" + jhModel.PVCs1 + "',"); } if (jhModel.ST_II1.ToString() != null) { str1.Append("ST_II,"); str2.Append("'" + jhModel.ST_II1 + "',"); } if (jhModel.RR1.ToString() != null) { str1.Append("RR,"); str2.Append("'" + jhModel.RR1 + "',"); } if (jhModel.PR1.ToString() != null) { str1.Append("PR,"); str2.Append("'" + jhModel.PR1 + "',"); } if (jhModel.Dia1.ToString() != null) { str1.Append("Dia,"); str2.Append("'" + jhModel.Dia1 + "',"); } if (jhModel.Mean1.ToString() != null) { str1.Append("Mean,"); str2.Append("'" + jhModel.Mean1 + "',"); } if (jhModel.Sys1.ToString() != null) { str1.Append("Sys,"); str2.Append("'" + jhModel.Sys1 + "',"); } str.Append("insert into dbo." + jhModel.TableNumber1 + " ("); str.Append(str1.ToString().Remove(str1.Length - 1)); str.Append(")"); str.Append(" values ("); str.Append(str2.ToString().Remove(str2.Length - 1)); str.Append(")"); return(DbHelperSql.EditData(str.ToString())); }