Ejemplo n.º 1
0
        // public delegate void ChangeRangeDateHandler(object sender);

        //public event ChangeRangeDateHandler ChangeRangeDate;

        private void MainForm_Load(object sender, EventArgs e)
        {
            #region write ini
            try
            {
                //Создание объекта, для работы с файлом
                INIManager manager = new INIManager(Application.StartupPath + @"\settings\set.ini");
                //Получить значение по ключу name из секции main
                path_db       = manager.GetPrivateString("connection", "db");
                db_puth.Value = path_db;

                path_db   = manager.GetPrivateString("workstation", "Key");
                Key.Value = path_db;
                //MessageBox.Show("бд - " + db_puth.Value, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                File.AppendAllText(Application.StartupPath + @"\new_file.txt", "путь к db:" + path_db + "\n");
                //Записать значение по ключу age в секции main
                // manager.WritePrivateString("main", "age", "21");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ini не прочтен" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion


            var dialog = new LoginFormadd();
            //dialog.UserName = "";
            //dialog.Password = "";

            if ((dialog.ShowDialog() == DialogResult.OK))
            {
                //MessageBox.Show("Не корректный логин или пароль " + dialog.UserName + '/' + dialog.Password, "", MessageBoxButtons.OK, MessageBoxIcon.Error);


                ApplicationContext dbContext = new ApplicationContext();

                try
                {
                    //string s = dbContext.Database.Connection.ConnectionString;
                    //var builder = new FbConnectionStringBuilder(s);
                    //builder.UserID = dialog.UserName;
                    //builder.Password = dialog.Password;

                    //dbContext.Database.Connection.ConnectionString = builder.ConnectionString;

                    //// пробуем подключится
                    // dbContext.Database.Connection.Open();

                    // формируем connection string для последующего соединения с нашей базой данных
                    FbConnectionStringBuilder fb_con = new FbConnectionStringBuilder();
                    fb_con.Charset    = "UTF8";               //используемая кодировка
                    fb_con.UserID     = "SYSDBA";             //логин
                    fb_con.Password   = "******";          //пароль
                    fb_con.Database   = db_puth.Value;        //путь к файлу базы данных
                    fb_con.ServerType = 0;                    //указываем тип сервера (0 - "полноценный Firebird" (classic или super server), 1 - встроенный (embedded))
                    fb = new FbConnection(fb_con.ToString()); //передаем нашу строку подключения объекту класса FbConnection

                    DataSet dataset = new DataSet();

                    fb.Open();

                    FbCommand fbcommand = fb.CreateCommand();
                    fbcommand.CommandType = CommandType.Text;
                    fbcommand.Connection  = fb;

                    fbcommand.CommandText = @"SELECT login, pass FROM sec_users WHERE Login='******' AND Pass='******';";

                    FbDataAdapter adaptor = new FbDataAdapter(fbcommand.CommandText, fbcommand.Connection);
                    adaptor.Fill(dataset, "0");
                    int count = dataset.Tables[0].Rows.Count;

                    FbDatabaseInfo fb_inf = new FbDatabaseInfo(fb); //информация о БД
                    typelabel.Text = "connect Info: " + fb_inf.ServerClass + "; " + fb_inf.ServerVersion + $"; Rows:{count}";
                    statusStrip1.Items.Add(typelabel);

                    if (count <= 0)
                    {
                        MessageBox.Show("Не корректный логин или пароль " + dialog.UserName + '/' + dialog.Password, "", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        MessageBox.Show("Не корректный логин или пароль " + dialog.UserName + '/' + dialog.Password, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        MessageBox.Show(fbcommand.CommandText, "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //Application.Exit();
                    }

                    if (!CheckLic())
                    {
                        MessageBox.Show(Key.Value + ":" + libtaryMy.CalculateMD5Hash(libtaryMy.GetProcessorIdAndGetOSSerialNumberID()), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    // отображаем ошибку
                    MessageBox.Show(ex.Message, "Error");
                    Application.Exit();
                }
            }
            else
            {
                Application.Exit();
            }
        }
Ejemplo n.º 2
0
        private void MainForm_Load_(object sender, EventArgs e)
        {
            var dialog = new LoginFormadd();

            dialog.UserName = "******";
            dialog.Password = "******";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var dbContext = AppVariables.getDbContext();

                try
                {
                    string s       = dbContext.Database.Connection.ConnectionString;
                    var    builder = new FbConnectionStringBuilder(s);
                    builder.UserID   = dialog.UserName;
                    builder.Password = dialog.Password;

                    dbContext.Database.Connection.ConnectionString = builder.ConnectionString;

                    //// пробуем подключится

                    //dbContext.Database.Connection.Open();

                    //MessageBox.Show("DataLayer " + DataLayer.Sec_users. + '/' + dialog.Password, "", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //edtCustomer.Text = customerForm.CurrentCustomer.NAME
                    ////////
                    //fb.Open();

                    //FbCommand fbcommand = fb.CreateCommand();
                    //fbcommand.CommandType = CommandType.Text;
                    //fbcommand.Connection = fb;

                    //fbcommand.CommandText = @"SELECT login, pass FROM sec_users WHERE Login='******' AND Pass='******';";

                    //FbDataAdapter adaptor = new FbDataAdapter(fbcommand.CommandText, fbcommand.Connection);
                    //adaptor.Fill(dataset, "0");
                    //int count = dataset.Tables[0].Rows.Count;

                    //FbDatabaseInfo fb_inf = new FbDatabaseInfo(fb); //информация о БД
                    //typelabel.Text = "connect Info: " + fb_inf.ServerClass + "; " + fb_inf.ServerVersion + $"; Rows:{count}";
                    //statusStrip1.Items.Add(typelabel);

                    //if (count <= 0)
                    //{
                    //    MessageBox.Show("Не корректный логин или пароль " + dialog.UserName + '/' + dialog.Password, "", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //    MessageBox.Show("Не корректный логин или пароль " + dialog.UserName + '/' + dialog.Password, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    MessageBox.Show(fbcommand.CommandText, "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //    //Application.Exit();
                    //}

                    //if (!CheckLic())
                    //{
                    //    MessageBox.Show(Key.Value + ":" + libtaryMy.CalculateMD5Hash(libtaryMy.GetProcessorIdAndGetOSSerialNumberID()), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //}
                    ///////////
                }
                catch (Exception ex)
                {
                    // отображаем ошибку
                    MessageBox.Show(ex.Message, "Error");
                    // Application.Exit();
                }
            }
            else
            {
                Application.Exit();
            }
        }