Exemple #1
0
        public void DeleteGroup(object parameter)
        {
            try
            {
                if (SelectedCodeGroup != null)
                {
                    using (var conn = new SQLiteConnection(Connection.ConnString))
                    {
                        conn.Open();

                        // delete code group of codes
                        using (var comm = new SQLiteCommand(conn))
                        {
                            comm.CommandText = "SELECT rowid FROM code_lib_codes WHERE groupid='" + SelectedCodeGroup.RowId + "'";
                            using (var reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    using (var commdelcodes = new SQLiteCommand(conn))
                                    {
                                        commdelcodes.CommandText = "DELETE FROM code_lib_codes WHERE groupid='" + SelectedCodeGroup.RowId + "'";
                                        commdelcodes.ExecuteNonQuery();
                                    }
                                }
                            }

                            // delete code group and remove from list
                            using (var commdelgroups = new SQLiteCommand(conn))
                            {
                                commdelgroups.CommandText = "DELETE FROM code_lib_groups WHERE rowid='" + SelectedCodeGroup.RowId + "'";

                                foreach (var group in CodeGroups)
                                {
                                    if (group.RowId == SelectedCodeGroup.RowId)
                                    {
                                        commdelgroups.ExecuteNonQuery();
                                        CodeGroups.Remove(group);
                                    }
                                }
                            }
                        }

                        conn.Close();
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp);
            }
        }
Exemple #2
0
        public async Task AddGroup(object parameter)
        {
            try
            {
                Status = "";

                if (SelectedLang == null)
                {
                    Status = "Kod ve kod gruplarının kaydedilebilmesi için bir sil seçiniz.";
                    return;
                }

                await Task.Factory.StartNew(async() =>
                {
                    using (var conn = new SQLiteConnection(Connection.ConnString))
                    {
                        conn.Open();

                        using (var comm = new SQLiteCommand(conn))
                        {
                            AddGroupIsEnabled = false;

                            comm.CommandText = "INSERT INTO code_lib_groups (userid, title, desc, desc_prev, langid, star) values(?,?,?,?,?,?)";

                            comm.Parameters.AddWithValue("@0", User.GetUserId());
                            comm.Parameters.AddWithValue("@1", (string)parameter);
                            comm.Parameters.AddWithValue("@2",
                                                         !string.IsNullOrEmpty(AddGroupDesc)
                                    ? AddGroupDesc
                                    : string.Empty);
                            comm.Parameters.AddWithValue("@3", !string.IsNullOrEmpty(AddGroupDesc)
                                    ? (AddGroupDesc.Length >= 200 ? AddGroupDesc.Substring(0, 200) : AddGroupDesc)
                                    : string.Empty);
                            comm.Parameters.AddWithValue("@4", SelectedLang.RowId);
                            comm.Parameters.AddWithValue("@5", "0");

                            var rows = comm.ExecuteNonQuery();
                            if (rows > 0)
                            {
                                var rowid    = conn.LastInsertRowId;
                                var newgroup = new CodeGroups()
                                {
                                    RowId    = conn.LastInsertRowId,
                                    Title    = (string)parameter,
                                    Desc     = AddGroupDesc,
                                    DescPrev = !string.IsNullOrEmpty(AddGroupDesc)
                                                                        ? (AddGroupDesc.Length >= 200
                                                                                ? AddGroupDesc.Substring(0, 200)
                                                                                : AddGroupDesc)
                                                                        : string.Empty,
                                    Star  = false,
                                    Codes = new ObservableCollection <Codes>()
                                };

                                await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                                     () =>
                                {
                                    CodeGroups.Add(newgroup);
                                    SelectedCodeGroup = newgroup;
                                }));
                            }
                        }

                        conn.Close();
                    }

                    AddGroupIsEnabled = true;
                });
            }
            catch (Exception exp)
            {
                AddGroupIsEnabled = true;

                Debug.WriteLine(exp.ToString());
            }
        }
Exemple #3
0
        public async Task LoadCodes()
        {
            try
            {
                Status = "";

                if (CodeGroups != null)
                {
                    await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                         () =>
                    {
                        CodeGroups.Clear();
                    }));
                }


                await Task.Factory.StartNew(async() =>
                {
                    using (var conn = new SQLiteConnection(Connection.ConnString))
                    {
                        conn.Open();

                        using (var trns = conn.BeginTransaction())
                        {
                            using (var comm = new SQLiteCommand(conn))
                            {
                                comm.CommandText =
                                    "SELECT code_lib_groups.rowid, code_lib_groups.title, code_lib_groups.desc, code_lib_groups.desc_prev, code_lib_groups.star " +
                                    "FROM code_lib_groups " +
                                    "JOIN code_lib_langs ON code_lib_groups.langid = code_lib_langs.rowid " +
                                    "WHERE code_lib_groups.userid = (SELECT userid FROM users WHERE active) " +
                                    "AND code_lib_groups.langid = (SELECT active_langid FROM code_lib_settings WHERE active_langid)";

                                using (var reader = comm.ExecuteReader())
                                {
                                    if (reader.HasRows)
                                    {
                                        var i = 0;
                                        while (reader.Read())
                                        {
                                            var groupadd = new CodeGroups()
                                            {
                                                RowId    = Convert.ToInt64(reader["rowid"]),
                                                Title    = reader["title"].ToString(),
                                                Desc     = reader["desc"].ToString(),
                                                DescPrev = reader["desc_prev"].ToString(),
                                                Star     = Convert.ToBoolean(Convert.ToInt32(reader["star"] != null ? reader["star"].ToString() : "0")),
                                                Codes    = new ObservableCollection <Codes>()
                                            };

                                            await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                                                 () =>
                                            {
                                                CodeGroups.Add(groupadd);
                                            }));

                                            using (var commforcodes = new SQLiteCommand(conn))
                                            {
                                                commforcodes.CommandText =
                                                    "SELECT rowid,* FROM code_lib_codes " +
                                                    "WHERE code_lib_codes.userid = (SELECT userid FROM users WHERE active) " +
                                                    "AND code_lib_codes.groupid = '" + reader["rowid"] + "' " +
                                                    "ORDER BY code_lib_codes.date";

                                                using (var readerforcodes = commforcodes.ExecuteReader())
                                                {
                                                    if (readerforcodes.HasRows)
                                                    {
                                                        var icodecount = 0;
                                                        while (readerforcodes.Read())
                                                        {
                                                            icodecount++;

                                                            var codeadd = new Codes()
                                                            {
                                                                RowId       = Convert.ToInt64(readerforcodes["rowid"]),
                                                                OrderNum    = icodecount,
                                                                Title       = readerforcodes["title"].ToString(),
                                                                Desc        = readerforcodes["desc"].ToString(),
                                                                DescPrev    = readerforcodes["desc_prev"].ToString(),
                                                                GroupId     = Convert.ToInt64(readerforcodes["groupid"].ToString()),
                                                                Color       = readerforcodes["color"].ToString(),
                                                                InvertColor = readerforcodes["invert_color"].ToString(),
                                                            };

                                                            var ii = i;
                                                            await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                                                                 () =>
                                                            {
                                                                CodeGroups[ii].Codes.Add(codeadd);
                                                            }));
                                                        }
                                                    }
                                                }
                                            }

                                            i++;
                                        }
                                    }
                                }
                            }

                            trns.Commit();
                        }

                        SelectedCodeGroup = CodeGroups[0];

                        conn.Close();
                    }
                }).ContinueWith(async(T) =>
                {
                    await LoadColors();
                });
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.ToString());
            }
        }