Esempio n. 1
0
        public async Task LoadLangs()
        {
            try
            {
                Status       = "";
                SelectedLang = new CodeLangs();

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

                        using (var comm = new SQLiteCommand(conn))
                        {
                            comm.CommandText = "SELECT rowid,* FROM code_lib_langs WHERE userid=(SELECT userid FROM users WHERE active)";

                            using (var reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    while (reader.Read())
                                    {
                                        var lang = new CodeLangs()
                                        {
                                            RowId    = Convert.ToInt64(reader["rowid"]),
                                            Title    = reader["title"].ToString(),
                                            Desc     = reader["desc"].ToString(),
                                            DescPrev = reader["desc_prev"].ToString()
                                        };

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

                        if (CodeLangs != null)
                        {
                            using (var commgetactivelang = new SQLiteCommand(conn))
                            {
                                commgetactivelang.CommandText = "SELECT active_langid FROM code_lib_settings";

                                using (var reader = commgetactivelang.ExecuteReader())
                                {
                                    if (reader.HasRows)
                                    {
                                        reader.Read();

                                        foreach (var lang in CodeLangs)
                                        {
                                            if (lang.RowId == Convert.ToInt64(reader["active_langid"] ?? "0"))
                                            {
                                                SelectedLang = lang;
                                            }
                                        }

                                        if (SelectedLang == null)
                                        {
                                            SelectedLang = CodeLangs[0];
                                        }
                                    }
                                    else
                                    {
                                        SelectedLang = CodeLangs[0];
                                    }
                                }
                            }
                        }

                        AddGroupIsEnabled = true;
                        conn.Close();
                    }
                });
            }
            catch (Exception exp)
            {
                AddGroupIsEnabled = true;

                Debug.WriteLine(exp.ToString());
            }
        }
Esempio n. 2
0
        public async Task AddLang(object parameter)
        {
            try
            {
                Status = "";

                await Task.Factory.StartNew(async() =>
                {
                    AddLangIsEnabled = false;

                    using (var conn = new SQLiteConnection(Connection.ConnString))
                    {
                        conn.Open();

                        using (var trns = conn.BeginTransaction())
                        {
                            AddLangIsEnabled = false;

                            using (var comm = new SQLiteCommand(conn))
                            {
                                comm.CommandText = "INSERT INTO code_lib_langs (userid, title, desc, desc_prev) values(?,?,?,?)";

                                comm.Parameters.AddWithValue("@0", User.GetUserId());
                                comm.Parameters.AddWithValue("@1", (string)parameter);
                                comm.Parameters.AddWithValue("@2",
                                                             !string.IsNullOrEmpty(AddLangDesc) && AddLangDesc.Trim() !=
                                                             "Bu kısma kod bloğu hakkında küçük bir not veya URL adersi eklenebilir."
                                        ? AddLangDesc
                                        : string.Empty);

                                comm.Parameters.AddWithValue("@3",
                                                             !string.IsNullOrEmpty(AddLangDesc) && AddLangDesc.Trim() !=
                                                             "Bu kısma kod bloğu hakkında küçük bir not veya URL adersi eklenebilir."
                                        ? (AddLangDesc.Length >= 200 ? AddLangDesc.Substring(0, 200) : AddLangDesc)
                                        : string.Empty);

                                var rows = comm.ExecuteNonQuery();
                                if (rows > 0)
                                {
                                    var rowid = conn.LastInsertRowId;
                                    if (CodeLangs.Any(Lang => Lang.RowId != rowid))
                                    {
                                        //if (CodeLangs.Any(Lang => Lang.RowId != rowid))
                                        //{
                                        //    CodeLangs.Add(new CodeLangs()
                                        //    {
                                        //        RowId = conn.LastInsertRowId,
                                        //        Title = (string)parameter,
                                        //        Desc = !string.IsNullOrEmpty(AddLangDesc) && AddLangDesc !=
                                        //               "Bu kısma kod bloğu hakkında küçük bir not veya URL adersi eklenebilir."
                                        //            ? AddLangDesc
                                        //            : string.Empty,
                                        //        DescPrev =
                                        //            !string.IsNullOrEmpty(AddLangDesc) && AddLangDesc !=
                                        //            "Bu kısma kod bloğu hakkında küçük bir not veya URL adersi eklenebilir."
                                        //                ? (AddLangDesc.Length >= 200
                                        //                    ? AddLangDesc.Substring(0, 200)
                                        //                    : AddLangDesc)
                                        //                : string.Empty
                                        //    });
                                        //}

                                        var newitem = new CodeLangs()
                                        {
                                            RowId    = conn.LastInsertRowId,
                                            Title    = (string)parameter,
                                            DescPrev =
                                                !string.IsNullOrEmpty(AddLangDesc) && AddLangDesc !=
                                                "Bu kısma kod bloğu hakkında küçük bir not veya URL adersi eklenebilir."
                                                    ? (AddLangDesc.Length >= 200
                                                        ? AddLangDesc.Substring(0, 200)
                                                        : AddLangDesc)
                                                    : string.Empty
                                        };

                                        await Task.Delay(1000);

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

                                        SelectedLang = newitem;
                                    }
                                }
                            }

                            trns.Commit();
                        }

                        conn.Close();
                    }

                    await Task.Delay(1000);
                    AddLangIsEnabled = true;
                });
            }
            catch (Exception exp)
            {
                AddLangIsEnabled = true;

                Debug.WriteLine(exp.ToString());
            }
        }