public int GetLastId() { //Events eventData = new Events(); returnEvent returnEventData = new returnEvent(); string connStr = CommonVariables.ConnectionString; using (SqlConnection conn = new SqlConnection(connStr)) { string query = "SELECT IDENT_CURRENT('Events') as event_id"; using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); event_id = Convert.ToInt16(reader["event_id"]); } } return(event_id); }
public returnEvent EditEvent(int event_id) { //Events eventData = new Events(); returnEvent returnEventData = new returnEvent(); string connStr = CommonVariables.ConnectionString; using (SqlConnection conn = new SqlConnection(connStr)) { string query = "SELECT * FROM Events WHERE event_id = @eventId"; using (SqlCommand cmd = new SqlCommand(query, conn)){ conn.Open(); cmd.Parameters.AddWithValue("@eventId", event_id); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); if (reader.HasRows) { returnEventData.event_id = Convert.ToInt16(reader["event_id"]); returnEventData.user_id = Convert.ToInt16(reader["user_id"]); returnEventData.title = Convert.ToString(reader["title"]); //returnEventData.location = Convert.ToString(reader["location"]); returnEventData.description = Convert.ToString(reader["description"]); returnEventData.status = Convert.ToString(reader["status"]); // eventData.start_time = Convert.ToString(reader.GetOrdinal("start_time")); // eventData.end_time = Convert.ToString(reader.GetOrdinal("end_time")); TimeSpan start_time = (TimeSpan)reader["start_time"]; TimeSpan end_time = (TimeSpan)reader["end_time"]; DateTime time = DateTime.Today.Add(start_time); string displayTime = time.ToString("hh:mm tt"); DateTime time1 = DateTime.Today.Add(end_time); string displayTime1 = time1.ToString("hh:mm tt"); returnEventData.returnStartTime = displayTime; // (DateTime.Today + start_time).ToString("HH 'hrs' mm 'mins' ss 'secs'"); returnEventData.returnEndTime = displayTime1; // (DateTime.Today + end_time).ToString("HH 'hrs' mm 'mins' ss 'secs'"); //returnEventData.start_date = Convert.ToString(reader["start_date"]); //returnEventData.end_date = Convert.ToString(reader["end_date"]); DateTime date = DateTime.Parse(Convert.ToString(reader["start_date"])); DateTime date1 = DateTime.Parse(Convert.ToString(reader["end_date"])); returnEventData.start_date = date.ToString("yyyy-MM-dd"); // Convert.ToString(reader["start_date"]); returnEventData.end_date = date1.ToString("yyyy-MM-dd"); // Convert.ToString(reader["end_date"]); returnEventData.priority = Convert.ToString(reader["priority"]); returnEventData.isTimeSet = Convert.ToByte(reader["isTimeSet"]); returnEventData.returnMsg = "true"; } else { returnEventData.returnMsg = "false"; } } } return(returnEventData); }