예제 #1
0
        /// <summary>
        /// Создать новый аккаунт
        /// </summary>
        /// <returns>возвращает TRUE, если аккаунт успешно создан</returns>
        public bool CreateAccount()
        {
            bool result = false;

            try
            {
                using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString)))
                {
                    connection.Open();

                    string newPass = Criptex.Cript("12345");

                    string sql = String.Format(@"INSERT INTO `ACCOUNT` (`LOGIN`, `PASSWORD`, `SURNAME`, `NAME`, `PATRONYMIC`, `ADRESS`, `PHONE`, `SEX`, `PURCHASE_INVOICE`, `SALES_INVOICE`, `REPORTS`, `REPORT_PURCHASE_INVOICE`, `REPORT_SALES_INVOICE`, `REPORT_INCOME_EXPENSE`, `COUNTERPARTY`, `COUNTERPARTY_PROVIDER`, `COUNTERPARTY_PROVIDER_ADD`, `COUNTERPARTY_PROVIDER_EDIT`, `COUNTERPARTY_PROVIDER_DELETE`, `COUNTERPARTY_CUSTOMER`, `COUNTERPARTY_CUSTOMER_ADD`, `COUNTERPARTY_CUSTOMER_EDIT`, `COUNTERPARTY_CUSTOMER_DELETE`, `WAREHOUSE`, `WAREHOUSE_ADD_PRODUCT`, `WAREHOUSE_EDIT_PRODUCT`, `WAREHOUSE_ANNULATE_PRODUCT`, `WAREHOUSE_EDIT_COUNT`, `ADMIN_PANEL`, `ADMIN_PANEL_ADD_ACCOUNT`, `ADMIN_PANEL_EDIT_ACCOUNT`, `ADMIN_PANEL_DELETE_ACCOUNT`, `ADMIN_PANEL_SET_NUMERATOR`, `ADMIN_PANEL_JOURNAL`, `IS_ANNULATED`, `REPORT_UN_ISSUE_PURCHASE_INVOICE`, `REPORT_UN_ISSUE_SALES_INVOICE`, `CODE`)  VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', '{22}', '{23}', '{24}', '{25}', '{26}', '{27}', '{28}', '{29}', '{30}', '{31}', '{32}', '{33}', '{34}', '{35}', '{36}', '{37}')", Login, newPass, PersonalData.Surname, PersonalData.Name, PersonalData.Patronymic, Criptex.Cript(PersonalData.Adress), Criptex.Cript(PersonalData.Phone), Conversion.ToString(PersonalData.Sex), Conversion.ToString(InvoiceData.PurchaseInvoice), Conversion.ToString(InvoiceData.SalesInvoice), Conversion.ToString(ReportsData.Reports), Conversion.ToString(ReportsData.ReportPurchaseInvoice), Conversion.ToString(ReportsData.ReportSalesInvoice), Conversion.ToString(ReportsData.ReportIncomeExpense), Conversion.ToString(CounterpartyData.Counterparty), Conversion.ToString(CounterpartyData.CounterpartyProvider), Conversion.ToString(CounterpartyData.CounterpartyProviderAdd), Conversion.ToString(CounterpartyData.CounterpartyProviderEdit), Conversion.ToString(CounterpartyData.CounterpartyProviderDelete), Conversion.ToString(CounterpartyData.CounterpartyCustomer), Conversion.ToString(CounterpartyData.CounterpartyCustomerAdd), Conversion.ToString(CounterpartyData.CounterpartyCustomerEdit), Conversion.ToString(CounterpartyData.CounterpartyCustomerDelete), Conversion.ToString(WarehouseData.Warehouse), Conversion.ToString(WarehouseData.WarehouseAddProduct), Conversion.ToString(WarehouseData.WarehouseEditProduct), Conversion.ToString(WarehouseData.WarehouseAnnulateProduct), Conversion.ToString(WarehouseData.WarehouseEditCount), Conversion.ToString(AdminPanelData.AdminPanel), Conversion.ToString(AdminPanelData.AdminPanelAddAccount), Conversion.ToString(AdminPanelData.AdminPanelEditAccount), Conversion.ToString(AdminPanelData.AdminPanelDeleteAccount), Conversion.ToString(AdminPanelData.AdminPanelSetNumerator), Conversion.ToString(AdminPanelData.AdminPanelJournal), 0, Conversion.ToString(ReportsData.ReportUnIssuePurchaseInvoice), Conversion.ToString(ReportsData.ReportUnIssueSalesInvoice), PersonalData.Code);

                    using (MySqlCommand command = new MySqlCommand(sql, connection))
                    {
                        command.ExecuteNonQuery();

                        ID = (int)command.LastInsertedId;
                    }

                    Journal.CreateJournal("создал", "пользователя " + _login, connection);

                    connection.Close();
                }

                result = true;
            }
            catch (Exception ex)
            {
                Dialog.ErrorMessage(null, "Ошибка создания пользователя", ex.Message);
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Сменить пароль
        /// </summary>
        /// <param name="newPassword">новый пароль</param>
        /// <returns>возвращает TRUE, если пароль успешно сменен</returns>
        public bool ChangePassword(string newPassword)
        {
            bool result = false;

            if (_id != 0)
            {
                try
                {
                    using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString)))
                    {
                        connection.Open();

                        string newPass = Criptex.Cript(newPassword);

                        string sql = String.Format(@"UPDATE `ACCOUNT` SET `PASSWORD` = '{0}' WHERE `ACCOUNT`.`ID` = {1}", newPass, ID);

                        using (MySqlCommand command = new MySqlCommand(sql, connection))
                        {
                            command.ExecuteNonQuery();
                        }

                        Password = newPass;

                        connection.Close();
                    }

                    result = true;
                }
                catch (Exception ex)
                {
                    Dialog.ErrorMessage(null, "Ошибка редактирования пароля пользователя", ex.Message);
                }
            }
            else
            {
                Dialog.ErrorMessage(null, "Не указан ID пользователя");
            }

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Реадктировать аккаунт
        /// </summary>
        /// <returns>возвращает TRUE, если аккаунт успешно отредактирован</returns>
        public bool EditAccount()
        {
            bool result = false;

            if (_id != 0)
            {
                try
                {
                    using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString)))
                    {
                        connection.Open();

                        string sql = String.Format(@"UPDATE `ACCOUNT` SET `LOGIN` = '{0}', `SURNAME` = '{1}', `NAME` = '{2}', `PATRONYMIC` = '{3}', `ADRESS` = '{4}', `PHONE` = '{5}', `SEX` = '{6}', `PURCHASE_INVOICE` = '{7}', `SALES_INVOICE` = '{8}', `REPORTS` = '{9}', `REPORT_PURCHASE_INVOICE` = '{10}', `REPORT_SALES_INVOICE` = '{11}', `REPORT_INCOME_EXPENSE` = '{12}', `COUNTERPARTY` = '{13}', `COUNTERPARTY_PROVIDER` = '{14}', `COUNTERPARTY_PROVIDER_ADD` = '{15}', `COUNTERPARTY_PROVIDER_EDIT` = '{16}', `COUNTERPARTY_PROVIDER_DELETE` = '{17}', `COUNTERPARTY_CUSTOMER` = '{18}', `COUNTERPARTY_CUSTOMER_ADD` = '{19}', `COUNTERPARTY_CUSTOMER_EDIT` = '{20}', `COUNTERPARTY_CUSTOMER_DELETE` = '{21}', `WAREHOUSE` = '{22}', `WAREHOUSE_ADD_PRODUCT` = '{23}', `WAREHOUSE_EDIT_PRODUCT` = '{24}', `WAREHOUSE_ANNULATE_PRODUCT` = '{25}', `WAREHOUSE_EDIT_COUNT` = '{26}', `ADMIN_PANEL` = '{27}', `ADMIN_PANEL_ADD_ACCOUNT` = '{28}', `ADMIN_PANEL_EDIT_ACCOUNT` = '{29}', `ADMIN_PANEL_DELETE_ACCOUNT` = '{30}', `ADMIN_PANEL_SET_NUMERATOR` = '{31}', `ADMIN_PANEL_JOURNAL` = '{32}', `REPORT_UN_ISSUE_PURCHASE_INVOICE` = '{33}', `REPORT_UN_ISSUE_SALES_INVOICE` = '{34}', `CODE` = '{35}' WHERE `ACCOUNT`.`ID` = {36}", Login, PersonalData.Surname, PersonalData.Name, PersonalData.Patronymic, Criptex.Cript(PersonalData.Adress), Criptex.Cript(PersonalData.Phone), Conversion.ToString(PersonalData.Sex), Conversion.ToString(InvoiceData.PurchaseInvoice), Conversion.ToString(InvoiceData.SalesInvoice), Conversion.ToString(ReportsData.Reports), Conversion.ToString(ReportsData.ReportPurchaseInvoice), Conversion.ToString(ReportsData.ReportSalesInvoice), Conversion.ToString(ReportsData.ReportIncomeExpense), Conversion.ToString(CounterpartyData.Counterparty), Conversion.ToString(CounterpartyData.CounterpartyProvider), Conversion.ToString(CounterpartyData.CounterpartyProviderAdd), Conversion.ToString(CounterpartyData.CounterpartyProviderEdit), Conversion.ToString(CounterpartyData.CounterpartyProviderDelete), Conversion.ToString(CounterpartyData.CounterpartyCustomer), Conversion.ToString(CounterpartyData.CounterpartyCustomerAdd), Conversion.ToString(CounterpartyData.CounterpartyCustomerEdit), Conversion.ToString(CounterpartyData.CounterpartyCustomerDelete), Conversion.ToString(WarehouseData.Warehouse), Conversion.ToString(WarehouseData.WarehouseAddProduct), Conversion.ToString(WarehouseData.WarehouseEditProduct), Conversion.ToString(WarehouseData.WarehouseAnnulateProduct), Conversion.ToString(WarehouseData.WarehouseEditCount), Conversion.ToString(AdminPanelData.AdminPanel), Conversion.ToString(AdminPanelData.AdminPanelAddAccount), Conversion.ToString(AdminPanelData.AdminPanelEditAccount), Conversion.ToString(AdminPanelData.AdminPanelDeleteAccount), Conversion.ToString(AdminPanelData.AdminPanelSetNumerator), Conversion.ToString(AdminPanelData.AdminPanelJournal), Conversion.ToString(ReportsData.ReportUnIssuePurchaseInvoice), Conversion.ToString(ReportsData.ReportUnIssueSalesInvoice), PersonalData.Code, ID);

                        using (MySqlCommand command = new MySqlCommand(sql, connection))
                        {
                            command.ExecuteNonQuery();
                        }

                        if (ProgramSettings.CurrentUser.ID != _id)
                        {
                            Journal.CreateJournal("изменил", "данные пользователя " + _login, connection);
                        }

                        connection.Close();
                    }

                    result = true;
                }
                catch (Exception ex)
                {
                    Dialog.ErrorMessage(null, "Ошибка редактирования данных пользователя", ex.Message);
                }
            }
            else
            {
                Dialog.ErrorMessage(null, "Не указан ID пользователя");
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Кнопка Применить
        /// </summary>
        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            if (tbLogin.Text.Trim() == "")
            {
                Dialog.WarningMessage(this, "Не указано имя пользователя");
                return;
            }

            try
            {
                bool accept = false;

                using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString)))
                {
                    connection.Open();

                    string       sql     = "SELECT * FROM ACCOUNT WHERE LOGIN = \'" + tbLogin.Text.Trim() + "\'";
                    MySqlCommand command = new MySqlCommand(sql, connection);

                    MySqlDataReader reader = command.ExecuteReader();
                    if (reader == null)
                    {
                        Dialog.WarningMessage(this, "Учетная запись пользователя не зарегистрирована");
                        return;
                    }

                    while (reader.Read())
                    {
                        if (Criptex.UnCript(reader["PASSWORD"].ToString()) == pbPassword.Password.Trim())
                        {
                            accept = true;
                            break;
                        }
                    }

                    connection.Close();
                }

                if (!accept)
                {
                    Dialog.WarningMessage(this, "Не верно указано имя пользователя или пароль");
                    return;
                }

                UserName = tbLogin.Text.Trim();

                // Сохранение настроек аутентификации
                try
                {
                    AuthentificateSettings auth = new AuthentificateSettings();
                    auth.UserName = Criptex.Cript(tbLogin.Text.Trim());

                    using (FileStream fs = new FileStream(ProgramSettings.WorkFolder + "settings.plg", FileMode.Create))
                    {
                        BinaryFormatter serializer = new BinaryFormatter();
                        serializer.Serialize(fs, auth);
                    }
                }
                catch { }

                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                Dialog.ErrorMessage(this, "Ошибка аутентификации", ex.Message);
                return;
            }
        }