/// <summary> /// Inserts details in database. /// </summary> /// <param name="details">Calendar details.</param> /// <returns>ID of inserted record.</returns> public override int InsertDetails( CalendarDetails details ) { int id = -1; using( SqlConnection connection = new SqlConnection( this.ConnectionString ) ) { connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); SqlCommand command = connection.CreateCommand(); command.Transaction = transaction; command.CommandText = string.Format( "INSERT INTO {0} (Date, WorkTime, Comment) VALUES (@Date, @WorkTime, @Comment) SELECT @@IDENTITY", DBTableName ); command.Parameters.Add( "@Date", SqlDbType.DateTime ).Value = details.Date.Date; command.Parameters.Add( "@WorkTime", SqlDbType.DateTime ).Value = details.WorkTime; command.Parameters.Add( "@Comment", SqlDbType.NVarChar ).Value = details.Comment; try { id = Convert.ToInt32( ExecuteScalar( command ) ); transaction.Commit(); } catch { transaction.Rollback();} } return id; }
public async Task <bool> SaveAppointment(CalendarDetails calendar, DateTime dateTime, string title, string Description, string location = "") { ContentValues eventValues = new ContentValues(); eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, calendar.Id); eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, title); eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, Description); eventValues.Put(CalendarContract.Events.InterfaceConsts.EventLocation, location); eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(dateTime)); eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(dateTime + new TimeSpan(hours: 1, minutes: 0, seconds: 0))); eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "UTC"); eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "UTC"); var uri = Forms.Context.ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues); Console.WriteLine("Uri for new event: {0}", uri); return(true); }
public async Task <bool> SaveAppointment(CalendarDetails calendar, DateTime dateTime, string title, string Description, string location = "") { var appointment = new Windows.ApplicationModel.Appointments.Appointment(); appointment.StartTime = dateTime; appointment.Duration = TimeSpan.FromHours(1); appointment.Location = location; appointment.Subject = title; appointment.Details = Description; Rect rect = new Rect(new Point(10, 10), new Size(100, 200)); try { String appointmentId = await Windows.ApplicationModel.Appointments.AppointmentManager.ShowEditNewAppointmentAsync(appointment); return(!string.IsNullOrEmpty(appointmentId)); } catch (Exception ex) { return(false); } }
/// <summary> /// Returns calendar details from data reader. /// </summary> /// <param name="reader">Data reader.</param> /// <returns>Calendar details from data reader.</returns> protected virtual CalendarDetails GetDetailsFromReader( IDataReader reader ) { CalendarDetails details = new CalendarDetails(); details.ID = (int) reader[ "ID" ]; details.Date = (DateTime) reader[ "Date" ]; details.WorkTime = (DateTime) reader[ "WorkTime" ]; details.Comment = (string) reader[ "Comment" ]; return details; }
/// <summary> /// Updates details in database. /// </summary> /// <param name="details">Calendar details.</param> public override bool UpdateDetails( CalendarDetails details ) { using( SqlConnection connection = new SqlConnection( this.ConnectionString ) ) { SqlCommand command = connection.CreateCommand(); command.CommandText = string.Format( "UPDATE {0} SET Date=@Date, WorkTime=@WorkTime, Comment=@Comment WHERE ID=@ID", DBTableName ); command.Parameters.Add( "@ID", SqlDbType.Int ).Value = details.ID; command.Parameters.Add( "@Date", SqlDbType.DateTime ).Value = details.Date.Date; command.Parameters.Add( "@WorkTime", SqlDbType.DateTime ).Value = details.WorkTime; command.Parameters.Add( "@Comment", SqlDbType.NVarChar ).Value = details.Comment; connection.Open(); ExecuteNonQuery( command ); return true; } }