public bool Update(SystemTimeBase mClass) { bool mResult = false; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString); string sql = "UPDATE SystemTime SET TimeId = @TimeId, TimeLabel = @TimeLabel, StartTime = @StartTime, EndTime = @EndTime " + "WHERE ClassTimeId = @ClassTimeId;"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.Add("@ClassTimeId", SqlDbType.Int).Value = mClass.ClassTimeId; cmd.Parameters.Add("@TimeId", SqlDbType.Int).Value = mClass.TimeId; cmd.Parameters.Add("@TimeLabel", SqlDbType.VarChar).Value = mClass.TimeLabel; cmd.Parameters.Add("@StartTime", SqlDbType.Bit).Value = mClass.StartTime; cmd.Parameters.Add("@EndTime", SqlDbType.Bit).Value = mClass.EndTime; try { con.Open(); cmd.ExecuteNonQuery(); mResult = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { con.Close(); con.Dispose(); cmd.Dispose(); } return(mResult); }
public int Add(SystemTimeBase mClass) { int ClassTimeId = 0; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString); string sql = "INSERT INTO SystemTime (TimeId, TimeLabel, StartTime, EndTime)" + " VALUES (@TimeId, @TimeLabel, @StartTime, @EndTime)" + " SELECT SCOPE_IDENTITY()"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.Add("@TimeId", SqlDbType.Int).Value = mClass.TimeId; cmd.Parameters.Add("@TimeLabel", SqlDbType.VarChar).Value = mClass.TimeLabel; cmd.Parameters.Add("@StartTime", SqlDbType.Bit).Value = mClass.StartTime; cmd.Parameters.Add("@EndTime", SqlDbType.Bit).Value = mClass.EndTime; try { con.Open(); ClassTimeId = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { ClassTimeId = -1; Console.WriteLine(ex.ToString()); } finally { con.Close(); con.Dispose(); cmd.Dispose(); } return(ClassTimeId); }
private SystemTimeBase Get(string WhereClause, params SqlParameter[] commandparameters) { SystemTimeBase mClass = null; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString); string sql = "SELECT db.ClassTimeId, db.TimeId, db.TimeLabel, db.StartTime, db.EndTime " + "FROM SystemTime db " + WhereClause; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader rdr = null; foreach (var parameter in commandparameters) { cmd.Parameters.Add(parameter); } try { con.Open(); rdr = cmd.ExecuteReader(); if (rdr.Read()) { mClass = LoadRow(rdr); } } catch (Exception ex) { mClass = null; Console.WriteLine(ex.ToString()); } finally { con.Close(); con.Dispose(); cmd.Dispose(); } return(mClass); }
private void Populate(SystemTimeBase mClass) { this.ClassTimeId = mClass.ClassTimeId; this.TimeId = mClass.TimeId; this.TimeLabel = mClass.TimeLabel; this.StartTime = mClass.StartTime; this.EndTime = mClass.EndTime; }