private void bActivation_Click(object sender, EventArgs e) { byte[] key = ASCIIEncoding.ASCII.GetBytes("DIAR"); /*RC4 encoder = new RC4(key); * byte[] testBytes = ASCIIEncoding.ASCII.GetBytes(m_strCode); * byte[] result2 = encoder.Encode(testBytes, testBytes.Length); * string encryptedString = encoder.GetByteString(result2);// ASCIIEncoding.ASCII.GetString(result);*/ RC4 decoder = new RC4(key); byte[] result = decoder.SetByteString(teActivationKey.Text); byte[] decryptedBytes = decoder.Decode(result, result.Length); string decryptedString = ASCIIEncoding.ASCII.GetString(decryptedBytes); if (decryptedString == m_strCode) { SQLiteConnection con = new SQLiteConnection(global::Condenser.Properties.Settings.Default.condenserConnectionString); try { con.Open(); SQLiteCommand com = new SQLiteCommand(con); com.CommandType = CommandType.Text; com.CommandText = "INSERT INTO Licenses (Code) VALUES ('" + teActivationKey.Text + "')"; com.ExecuteNonQuery(); con.Close(); } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow("Ошибка при работе с базой данных. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MyLocalizer.XtraMessageBoxShow("Активация успешно произведена.\nНеобходимо перезапустить программу.", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { MyLocalizer.XtraMessageBoxShow("Неверный ключ активации.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static bool LoadParamData(string strFileName) { StreamReader sr = StreamReader.Null; try { sr = new StreamReader(strFileName); bool bReadKoef = false; bool bReadKIn = false; string strVal = ""; string strSeparator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; string strCondenserType = ""; long KoefID = 0; Decimal?fVal = null; if (sr != StreamReader.Null) { SQLiteConnection connection = new SQLiteConnection(global::Condenser.Properties.Settings.Default.condenserConnectionString); connection.Open(); byte[] key = Encoding.Unicode.GetBytes("ELCHROM"); RC4 decoder = new RC4(key); while (!sr.EndOfStream) { string strData = sr.ReadLine(); // расшифровка byte[] result = decoder.SetByteString(strData); byte[] decryptedBytes = decoder.Decode(result, result.Length); strData = Encoding.Unicode.GetString(decryptedBytes); if (strData == "Data") { bReadKoef = true; bReadKIn = false; continue; } else { if (bReadKoef && strData == "KIn") { bReadKIn = true; continue; } string[] vecData = strData.Split('\t'); if (bReadKoef) { try { SQLiteCommand com = new SQLiteCommand(connection); com.CommandType = CommandType.Text; if (!bReadKIn) { Decimal?fKI1 = null, fkoefA = null, fkoefB = null, fkoefR2 = null; long iFunctionType = 0; fKI1 = null; fkoefA = null; fkoefB = null; fkoefR2 = null; iFunctionType = 0; //if (vecData.GetLength(0) != 16) throw new Exception("некорректный формат файла."); for (int j = 0; j < vecData.GetLength(0); j += 2) { strVal = vecData[j + 1]; if (vecData[j] == "CondenserType") { strCondenserType = vecData[j + 1]; } if (vecData[j] == "KI1" && strVal != "") { strVal = strVal.Replace(".", strSeparator); strVal = strVal.Replace(",", strSeparator); fKI1 = Convert.ToDecimal(strVal); } if (vecData[j] == "KoefA" && strVal != "") { strVal = strVal.Replace(".", strSeparator); strVal = strVal.Replace(",", strSeparator); fkoefA = Convert.ToDecimal(strVal); } if (vecData[j] == "KoefB" && strVal != "") { strVal = strVal.Replace(".", strSeparator); strVal = strVal.Replace(",", strSeparator); fkoefB = Convert.ToDecimal(strVal); } if (vecData[j] == "KoefR2" && strVal != "") { strVal = strVal.Replace(".", strSeparator); strVal = strVal.Replace(",", strSeparator); fkoefR2 = Convert.ToDecimal(strVal); } if (vecData[j] == "FunctionType" && strVal != "") { iFunctionType = Convert.ToInt64(strVal); } } if (fKI1 == null) { throw new Exception("отсутствует значение в поле КЦ1."); } com.CommandText = "SELECT (SELECT CondenserTypeID FROM CondenserTypes WHERE CondenserTypeName = @tname) AS CondenserTypeID, " + "(SELECT KoefID FROM CondenserTypeParameters WHERE CondenserTypeID = (SELECT CondenserTypeID FROM CondenserTypes WHERE CondenserTypeName = @tname)) AS KoefID"; AddParam(com, "@tname", DbType.String, strCondenserType); SQLiteDataReader dr = com.ExecuteReader(); long CondenserTypeID = 0; KoefID = 0; while (dr.Read()) { if (dr["CondenserTypeID"] != DBNull.Value) { CondenserTypeID = Convert.ToInt64(dr["CondenserTypeID"]); } if (dr["KoefID"] != DBNull.Value) { KoefID = Convert.ToInt64(dr["KoefID"]); } } dr.Close(); if (CondenserTypeID == 0) { continue; } com.Parameters.Clear(); if (KoefID > 0) { com.CommandText = "UPDATE CondenserTypeParameters SET KI1 = @ki1, KoefA = @koefA, KoefB = @koefB, KoefR2 = @koefR2, FunctionType = @ftype WHERE CondenserTypeID = @ctypeid"; } else { com.CommandText = "INSERT INTO CondenserTypeParameters (CondenserTypeID, KI1, KoefA, KoefB, KoefR2, FunctionType) VALUES (@ctypeid, @ki1, @koefA, @koefB, @koefR2, @ftype)"; } AddParam(com, "@ctypeid", DbType.Int64, CondenserTypeID); AddParam(com, "@ki1", DbType.Decimal, fKI1); AddParam(com, "@koefA", DbType.Decimal, fkoefA); AddParam(com, "@koefB", DbType.Decimal, fkoefB); AddParam(com, "@koefR2", DbType.Decimal, fkoefR2); AddParam(com, "@ftype", DbType.Int64, iFunctionType); com.ExecuteNonQuery(); if (KoefID == 0) { com.CommandText = "select seq from sqlite_sequence where name = 'CondenserTypeParameters'"; com.Parameters.Clear(); SQLiteDataReader dr_ = com.ExecuteReader(); while (dr_.Read()) { KoefID = Convert.ToInt64(dr_["seq"]); } dr_.Close(); } else { com.CommandText = "DELETE FROM ParameterRecommendations where KoefID = @koefID"; com.Parameters.Clear(); AddParam(com, "@koefID", DbType.Int64, KoefID); com.ExecuteNonQuery(); } } else { long iPosition = 0; Decimal?fValue = null; string strRecommendation = ""; string strConclusion = ""; com.CommandText = "INSERT INTO ParameterRecommendations (KoefID, Position, Value, Recommendation, Conclusion) VALUES (@koefID, @pos, @val, @recom, @concl)"; for (int j = 0; j < vecData.GetLength(0); j += 2) { strVal = vecData[j + 1]; if (vecData[j] == "Pos") { iPosition = Convert.ToInt64(vecData[j + 1]); } if (vecData[j] == "Val" && strVal != "") { strVal = strVal.Replace(".", strSeparator); strVal = strVal.Replace(",", strSeparator); fValue = Convert.ToDecimal(strVal); } if (vecData[j] == "Recommendation") { strRecommendation = strVal; } if (vecData[j] == "Conclusion") { strConclusion = strVal; } } com.Parameters.Clear(); AddParam(com, "@koefID", DbType.Int64, KoefID); AddParam(com, "@pos", DbType.Int64, iPosition); AddParam(com, "@val", DbType.Decimal, fValue); AddParam(com, "@recom", DbType.String, strRecommendation); AddParam(com, "@concl", DbType.String, strConclusion); com.ExecuteNonQuery(); } } catch (SQLiteException ex) { throw ex; } } else { fVal = null; if (vecData.GetLength(0) != 2) { throw new Exception("некорректный формат файла."); } if (vecData[0] == "ПЧХ" && vecData[1] != "") { strVal = vecData[1]; strVal = strVal.Replace(".", strSeparator); strVal = strVal.Replace(",", strSeparator); fVal = Convert.ToDecimal(strVal); if (fVal == null) { throw new Exception("отсутствует значение в поле ПЧХ."); } } try { SQLiteCommand com = new SQLiteCommand(connection); com.CommandText = "UPDATE CommonParameters SET ParameterValue = @pval WHERE ParameterName = @pname"; com.CommandType = CommandType.Text; AddParam(com, "@pval", DbType.String, fVal.ToString()); AddParam(com, "@pname", DbType.String, vecData[0]); com.ExecuteNonQuery(); } catch (SQLiteException ex) { throw ex; } } } } connection.Close(); } } catch (Exception ex) { if (sr != StreamReader.Null) { sr.Close(); } MyLocalizer.XtraMessageBoxShow("Ошибка при загрузке коэффициентов аппроксимации: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (sr != StreamReader.Null) { sr.Close(); } return(true); }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //AppDomain.CurrentDomain.SetData("DataDirectory", Environment.CurrentDirectory); /*AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => * { * // В вашем случае в args.Name будет лежать строка * // Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342 * // Также сюда вам необходимо каким-то образом передать каталог, где лежит COM-компонент * // и зависимая сборка (например, считать через реестр: HKEY_CLASSES_ROOT\CLSID\{guid_вашего_компонента}\InprocServer32) * // Пусть comPath - каталог, где лежит ваша зависимая сборка * * string depAssemblyFileName = new AssemblyName(args.Name).Name + ".dll"; * string depAssemblyPath = Path.Combine("", depAssemblyFileName); * return Assembly.Load(depAssemblyPath); * };*/ //DevExpress.UserSkins.SkinFHA fha = new DevExpress.UserSkins.SkinFHA(); //string str = fha.SkinInfo1[0]; listSkin.Add("SkinMyButton.dll"); /*listSkin.Add("SkinPassport.dll"); * listSkin.Add("SkinReport.dll"); * listSkin.Add("SkinAdd2.dll");*/ listDLL.Add("DevExpress.BonusSkins.v11.1.dll"); listDLL.Add("DevExpress.Data.v11.1.dll"); listDLL.Add("DevExpress.OfficeSkins.v11.1.dll"); listDLL.Add("DevExpress.Printing.v11.1.Core.dll"); listDLL.Add("DevExpress.Utils.v11.1.dll"); listDLL.Add("DevExpress.XtraBars.v11.1.dll"); listDLL.Add("DevExpress.XtraEditors.v11.1.dll"); listDLL.Add("DevExpress.XtraGrid.v11.1.dll"); listDLL.Add("DevExpress.XtraLayout.v11.1.dll"); listDLL.Add("DevExpress.XtraVerticalGrid.v11.1.dll"); listDLL.Add("DevExpress.RichEdit.v11.1.Core.dll"); listDLL.Add("DevExpress.XtraRichEdit.v11.1.dll"); //string str = typeof(DevExpress.UserSkins.SkinFHA).ToString(); RegisterAssembly(); /*DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinHARG).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinVibro).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinVisual).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinParameter).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinWarm).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinPassport).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinReport).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinAdd).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinAdd2).Assembly); //Register! * DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.SkinElectrical).Assembly); //Register!*/ DevExpress.UserSkins.BonusSkins.Register(); DevExpress.UserSkins.OfficeSkins.Register(); if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "DB\\Condenser.sqlite")) { Properties.Settings.Default["condenserConnectionString"] = "data source=" + AppDomain.CurrentDomain.BaseDirectory + "DB\\Condenser.sqlite"; } else { if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Condenser.sqlite")) { Properties.Settings.Default["condenserConnectionString"] = "data source=" + AppDomain.CurrentDomain.BaseDirectory + "Condenser.sqlite"; } else { MyLocalizer.XtraMessageBoxShow("Ошибка при работе с базой данных. Описание: отсутствует файл Condenser.sqlite.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } AppearanceObject.DefaultFont = new Font("Segoe UI", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); // ----------------- // проверка лицензии // ----------------- string testString = GetUniqueHardwaeId(); byte[] key = ASCIIEncoding.ASCII.GetBytes("DIAR"); RC4 encoder = new RC4(key); byte[] testBytes = ASCIIEncoding.ASCII.GetBytes(testString); byte[] result = encoder.Encode(testBytes, testBytes.Length); string encryptedString = encoder.GetByteString(result);// ASCIIEncoding.ASCII.GetString(result); SQLiteConnection con = new SQLiteConnection(global::Condenser.Properties.Settings.Default.condenserConnectionString); bool bNoLicense = true; string strLicenseCode = ""; try { con.Open(); SQLiteCommand com = new SQLiteCommand(con); com.CommandType = CommandType.Text; com.CommandText = "Select Code FROM Licenses WHERE Code = '" + encryptedString + "'"; SQLiteDataReader dr = com.ExecuteReader(); if (dr.HasRows) { bNoLicense = false; strLicenseCode = dr["Code"].ToString(); } dr.Close(); con.Close(); } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow("Ошибка при работе с базой данных. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception ex) { MyLocalizer.XtraMessageBoxShow("Ошибка при работе с базой данных. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (bNoLicense) { LicenseForm f = new LicenseForm(); f.m_strCode = testString; Application.Run(f); } else { try { con.Open(); SQLiteCommand com = new SQLiteCommand(con); com.CommandText = "Select CurVersion from Version"; com.CommandType = CommandType.Text; SQLiteDataReader dr = com.ExecuteReader(); //Decimal curVersion = new decimal(0); while (dr.Read()) { m_fVersion = Convert.ToDecimal(dr.GetValue(0)); } dr.Close(); con.Close(); ServicePackForm sp = new ServicePackForm(); if (m_fVersion < Program.m_CurVersionDB) { sp.m_DBVersion = m_fVersion; if (sp.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } ; } con.Close(); } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow("Ошибка при работе с базой данных. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } LoadParameters(); Application.Run(new MainForm()); } } catch (Exception ex) { MessageBox.Show(ex.Message + "(" + ex.StackTrace + ")", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void simpleButton1_Click(object sender, EventArgs e) { if (dlgSave.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SQLiteConnection connection = new SQLiteConnection(global::Condenser.Properties.Settings.Default.condenserConnectionString); connection.Open(); string strPath = dlgSave.FileName; //StreamWriter sw = new StreamWriter(strPath, false); char chTab = (char)9; List <string> vecData = new List <string>(); string strData = "ПЧХ" + chTab + teHLS.EditValue.ToString(); //sw.WriteLine(strData); vecData.Add(strData); for (int i = 0; i < qCondenserTypeParametersBindingSource.Count; i++) { DataRowView drv = (DataRowView)(qCondenserTypeParametersBindingSource[i]); long CondenserTypeID = -1; string strCondenserTypeName = ""; if (drv["CondenserTypeID"] != DBNull.Value) { CondenserTypeID = Convert.ToInt64(drv["CondenserTypeID"]); int itemFound = qCondenserTypesBindingSource.Find("CondenserTypeID", CondenserTypeID); strCondenserTypeName = ((DataRowView)(qCondenserTypesBindingSource[itemFound]))["CondenserTypeName"].ToString(); } if (drv["KoefID"] != DBNull.Value) { strData = "Data"; //sw.WriteLine(strData); vecData.Add(strData); strData = "CondenserType" + chTab + strCondenserTypeName + chTab + "KI1" + chTab + drv["KI1"].ToString() + chTab //+ "КИn80" + chTab + drv["KIn80"].ToString() + chTab //+ "КИn90" + chTab + drv["KIn90"].ToString() + chTab //+ "КИn100" + chTab + drv["KIn100"].ToString() + chTab + "KoefA" + chTab + drv["KoefA"].ToString() + chTab + "KoefB" + chTab + drv["KoefB"].ToString() + chTab + "KoefR2" + chTab + drv["KoefR2"].ToString() + chTab + "FunctionType" + chTab + drv["FunctionType"].ToString(); //sw.WriteLine(strData); vecData.Add(strData); strData = "KIn"; //sw.WriteLine(strData); vecData.Add(strData); long iKoefID = Convert.ToInt64(drv["KoefID"]); try { SQLiteCommand com = new SQLiteCommand(connection); com.CommandText = "select ID, Position, Value, Conclusion, Recommendation FROM ParameterRecommendations WHERE KoefID = @KoefID ORDER BY Position"; com.CommandType = CommandType.Text; SQLiteParameter param1 = new SQLiteParameter("@koefID", DbType.Int64); param1.Value = (long)iKoefID; com.Parameters.Add(param1); SQLiteDataReader drRecomm = com.ExecuteReader(); // заносим данные по рекомендациям и КЦn while (drRecomm.Read()) { Decimal?fValue = null; if (drRecomm["Value"] != DBNull.Value) { fValue = Convert.ToDecimal(drRecomm["Value"]); } strData = "Pos" + chTab + Convert.ToInt64(drRecomm["Position"]) + chTab + "Val" + chTab + fValue.ToString() + chTab + "Recommendation" + chTab + Convert.ToString(drRecomm["Recommendation"]) + chTab + "Conclusion" + chTab + Convert.ToString(drRecomm["Conclusion"]); //sw.WriteLine(strData); vecData.Add(strData); } drRecomm.Close(); } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow("Ошибка при работе с базой данных. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } //sw.Close(); connection.Close(); try { byte[] key = Encoding.Unicode.GetBytes("ELCHROM"); RC4 encoder = new RC4(key); System.IO.StreamWriter fsWrite = new System.IO.StreamWriter(strPath); for (int i = 0; i < vecData.Count; i++) { byte[] testBytes = Encoding.Unicode.GetBytes(vecData[i]); byte[] result = encoder.Encode(testBytes, testBytes.Length); string encryptedString = encoder.GetByteString(result); fsWrite.WriteLine(encryptedString); } fsWrite.Close(); } catch (Exception ex) { MyLocalizer.XtraMessageBoxShow("В программе произошла ошибка. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MyLocalizer.XtraMessageBoxShow("Экспорт настроек успешно выполнен.", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } }