Exemplo n.º 1
0
        /// <summary>
        /// Lazy Loads the text for each Control in form
        /// </summary>
        /// <param name="ControlDefaultValues">A dictionary with ControlName-Text pairs</param>
        public static Thread LazyLoadTranslations(FinOrgForm f)
        {
            try
            {
                Thread t = new Thread(() =>
                {
                    // Get a list of items to fetch
                    IEnumerable <string> items = f.ControlDefaultValues.Values;
                    if (Translations != null)
                    {
                        items = items.Except(Translations.Keys).ToArray();
                    }
                    SqlConnection con = FinOrgForm.getSqlConnection();
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand(string.Format("SELECT text, {0} FROM TRANSLATIONS WHERE text IN ({{keys}});", currentLanguage), con);
                        cmd.AddArrayParameters(items, "keys");
                        if (cmd.Parameters.Count > 0)
                        {
                            using (SqlDataReader reader = cmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    // Only Keys NOT Present in Translations Dictionary is fetched from Database
                                    if (!Translations.ContainsKey(reader["text"].ToString()))
                                    {
                                        Translations.Add(reader["text"].ToString(), reader[currentLanguage].ToString());
                                    }
                                }
                            }
                        }
                        con.Close();
                    }
                    catch (Exception e)
                    {
                        con.Close();
                        MessageBox.Show(e.Message, "FinOrg Languages LazyLoadTranslations");
                    }
                    if (LANG_DEBUG_MODE) // Copies the value from form to database currentLanguage field
                    {
                        InsertFormTranslations(f.ControlDefaultValues);
                    }

                    // Apply Translation
                    f.BeginInvoke(new Action(() =>
                    {
                        ApplyTranslation(f);
                    }));
                });
                // finish  this fast
                t.Priority = ThreadPriority.Highest;
                t.Start();
                return(t);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        //
        public static Thread Init()
        {
            Thread t = new Thread(() =>
            {
                SqlConnection con = FinOrgForm.getSqlConnection();
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'TRANSLATIONS';", con);
                    if ((int)cmd.ExecuteScalar() == 0)
                    {
                        // create translations table
                        cmd.CommandText = TRANSLATIONS_TABLE_SQL;
                        cmd.ExecuteNonQuery();
                    }
                    if (LANG_DEBUG_MODE)
                    {
                        LoadAllTranslations();
                    }
                    else
                    {
                        Translations = new Dictionary <string, string>();
                    }
                    con.Close();
                }
                catch (Exception e)
                {
                    con.Close();
                    MessageBox.Show(e.Message, "FinOrg Languages Init");
                }
            });

            t.Start();
            return(t);
        }
Exemplo n.º 3
0
        public static void CheckLicense()
        {
https:      //stackoverflow.com/questions/17292366/hashing-with-sha1-algorithm-in-c-sharp
            using (SqlConnection con = FinOrgForm.getSqlConnection())
            {
                con.Open();
                SqlDataAdapter adapter = new SqlDataAdapter(@"
				SELECT * FROM LicenseAuth;

				EXEC xp_instance_regread
				'HKEY_LOCAL_MACHINE',
				'HARDWARE\DESCRIPTION\System\CentralProcessor\0',
				'ProcessorNameString';

				EXEC xp_instance_regread
				'HKEY_LOCAL_MACHINE',
				'HARDWARE\DESCRIPTION\System\BIOS',
				'BaseBoardManufacturer';

				EXEC xp_instance_regread
				'HKEY_LOCAL_MACHINE',
				'HARDWARE\DESCRIPTION\System\BIOS',
				'BaseBoardProduct';

				EXEC xp_instance_regread
				'HKEY_LOCAL_MACHINE',
				'HARDWARE\DESCRIPTION\System\BIOS',
				'BaseBoardVersion';

				EXEC xp_instance_regread
				'HKEY_LOCAL_MACHINE',
				'HARDWARE\DESCRIPTION\System\BIOS',
				'SystemProductName';
				"                , con);

                DataSet _data = new DataSet();
                adapter.Fill(_data);

                string str = _data.Tables[0].Rows[0]["name"].ToString();
                for (int i = 1; i < _data.Tables.Count; i++)
                {
                    foreach (DataRow r in _data.Tables[i].Rows)
                    {
                        str += r["Value"].ToString() + r["Data"].ToString();
                    }
                }
                string hashed = Hash(str);
                if (_data.Tables[0].Rows[0]["license_key"].ToString() != hashed)
                {
                    MessageBox.Show("Not licensed");
                }
                else
                {
                    MessageBox.Show("Licensed");
                }
            }
        }
Exemplo n.º 4
0
        private static void LoadAllTranslations()
        {
            SqlConnection con = FinOrgForm.getSqlConnection();

            con.Open();
            SqlCommand cmd = new SqlCommand(string.Format("SELECT text, {0} FROM TRANSLATIONS", currentLanguage), con);

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                Translations = new Dictionary <string, string>();
                while (reader.Read())
                {
                    Translations.Add(reader["text"].ToString(), reader[currentLanguage].ToString());
                }
            }
            con.Close();
        }
Exemplo n.º 5
0
        public static string GetStringTranslation(string s)
        {
            // lower
            string key = s.Simplified(true);

            if (!Translations.ContainsKey(key))
            {
                SqlConnection con = FinOrgForm.getSqlConnection();
                SqlCommand    cmd = new SqlCommand("", con);
                try
                {
                    con.Open();
                    // Insert to DB
                    if (LANG_DEBUG_MODE)
                    {
                        cmd.CommandText = "INSERT INTO TRANSLATIONS (text, english) VALUES (@key, @v);";
                        cmd.Parameters.Add(new SqlParameter("key", key));
                        cmd.Parameters.Add(new SqlParameter("v", s));
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                    }
                    // fetch from DB
                    cmd.CommandText = string.Format("SELECT {0} FROM TRANSLATIONS WHERE text = @v", currentLanguage);
                    cmd.Parameters.Add(new SqlParameter("v", key));
                    object data = cmd.ExecuteScalar();
                    con.Close();
                    if (data != null)
                    {
                        Translations.Add(key, data.ToString());
                        return(data.ToString());
                    }
                    else
                    {
                        return(s);
                    }
                } catch (Exception ef)
                {
                    MessageBox.Show(ef.Message + "\nSQL: " + cmd.CommandText, "FinOrg Languages GetTranslation");
                    return("");
                }
            }
            else
            {
                return(Translations[key]);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Copies values
        /// Call from a thread, not from UI
        /// </summary>
        /// <param name="ControlDefaultValues"></param>
        public static void InsertFormTranslations(Dictionary <string, string> ControlDefaultValues)
        {
            if (ControlDefaultValues.Count == 0)
            {
                return;
            }
            SqlConnection con = FinOrgForm.getSqlConnection();
            SqlCommand    cmd = new SqlCommand(string.Format("INSERT INTO TRANSLATIONS (text, {0}) VALUES ", currentLanguage), con);

            try
            {
                con.Open();
                int i = 0;                 // dictionary doesnt have proper index to loop with forloop
                foreach (KeyValuePair <string, string> e in ControlDefaultValues)
                {
                    // check for duplications
                    if (Translations.ContainsKey(e.Value.Simplified()))
                    {
                        continue;
                    }
                    if (i > 0)
                    {
                        cmd.CommandText += ", ";
                    }
                    cmd.CommandText += string.Format("(@text{0}, @value{0})", i);
                    cmd.Parameters.Add(new SqlParameter("@text" + i, e.Value.Simplified()));
                    cmd.Parameters.Add(new SqlParameter("@value" + i, e.Value.Simplified()));
                    Translations.Add(e.Value.Simplified(), e.Value.Simplified());
                    i++;
                }
                if (cmd.Parameters.Count > 0)
                {
                    cmd.ExecuteNonQuery();
                }
                con.Close();
            } catch (Exception e)
            {
                con.Close();
                MessageBox.Show(e.Message + "\n" + cmd.CommandText, "FinOrg: Languages InsertFormTranslations");
            }
        }