public static void createDatabase(string databasePath)
        {
            SQLiteConnection.CreateFile(databasePath);

            try
            {
                SQLiteConnection connection = new SQLiteConnection("Data Source = " + databasePath + "; Version = 3;");
                connection.Open();

                SQLiteCommand command = new SQLiteCommand(DatabaseTables.CalendarItemTableCreation, connection);
                command.ExecuteNonQuery();

                command = new SQLiteCommand(DatabaseTables.CatagoryTableCreation, connection);
                command.ExecuteNonQuery();

                CatagoryDto dto = new CatagoryDto();
                dto.Name = "Misc";
                dto.Color = Colors.Gray;

                CatagoryDao.AddItem(dto, connection);

                connection.Close();
            }
            catch (Exception ex)
            {
                File.Delete(databasePath);
            }
        }
        public CatagoryDto GuiToDto()
        {
            CatagoryDto dto = new CatagoryDto();
            dto.Name = name.Text;
            dto.Color = ColorPicker.SelectedColor.Value;

            return dto;
        }
 public void AddItem(CatagoryDto item)
 {
     if (item.id == -1)
     {
         item.id = currentId--;
         CatagoryDao.AddItem(item);
     }
     else if (item.id <= currentId) currentId = item.id - 1;
     CalendarItems[item.id] = item;
     if (ItemAddedEvt != null)  ItemAddedEvt(item);
 }
Example #4
0
        public static bool DeleteCalenderItem(CatagoryDto dto, SQLiteConnection conn = null)
        {
            bool closeCon = false;
            if (conn == null)
            {
                conn = DatabaseHelper.GetDatabaseConnection();
                closeCon = true;
            }

            if (closeCon) conn.Close();
            return false;
        }
Example #5
0
        public static bool AddItem(CatagoryDto dto, SQLiteConnection conn = null)
        {
            bool closeCon = false;
            if (conn == null)
            {
                conn = DatabaseHelper.GetDatabaseConnection();
                closeCon = true;
            }

            using (SQLiteCommand command = new SQLiteCommand(conn))
            {
                command.CommandText = ADD_ITEM_SQL;
                command.Prepare();
                command.Parameters.AddWithValue("@Name", dto.Name);
                command.Parameters.AddWithValue("@Color", dto.Color.ToString());
                dto.id = command.ExecuteNonQuery();
            }

            if (closeCon) conn.Close();
            return false;
        }
 public void UpdateItem(CatagoryDto item)
 {
     if (item.id < 0) return;
     modifiedItems[item.id] = item;
 }
 public void DtoToGui(CatagoryDto dto)
 {
     name.Text = dto.Name;
     //ColorPicker.SelectedColor = dto.Color
 }
Example #8
0
        static CatagoryDto DtoFromReader(SQLiteDataReader read)
        {
            CatagoryDto dto = new CatagoryDto();

            dto.Name = read["Name"] as string;
            dto.id = Convert.ToInt32(read["id"]);
            dto.Color = (Color)ColorConverter.ConvertFromString(read["Color"] as string);

            return dto;
        }