Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }