Exemplo n.º 1
0
        private void EnterButton_Click(object sender, EventArgs e)
        {
            string password = "";

            if (LoginTextBox.Text == " " || PasswordTextBox.Text == " ")
            {
                MessageBox.Show("Не все поля заполнены");
                LoginTextBox.Focus();
            }
            int          count   = 0;
            string       command = "Select Пароль from Пользователи Where Имя_Пользователя = @login";
            SqlParameter p1      = new SqlParameter("login", LoginTextBox.Text);
            var          reader  = StaticProcesser.GetReader(command, p1);

            while (reader.Read())
            {
                count++;
                try
                {
                    password = reader.GetString(0);
                    password = password.Replace(Environment.NewLine, "");
                }
                catch (Exception ex)
                {
                    StaticHelper.ErrorNotifier(ex);
                }
            }
            if (count == 0)
            {
                MessageBox.Show("Такого пользователя не существует");
                LoginTextBox.Clear();
                LoginTextBox.Focus();
                PasswordTextBox.Clear();
                reader.Close();
                StaticProcesser.CloseConnection();
            }
            else if (count == 1)
            {
                reader.Close();
                StaticProcesser.CloseConnection();
                string inputedPass = StaticProcesser.ComputeHash(PasswordTextBox.Text, new MD5CryptoServiceProvider());
                if (password == inputedPass)
                {
                    User.Login  = LoginTextBox.Text;
                    User.Access = 1;
                    if (User.Login == "admin")
                    {
                        User.Access = 2;
                    }
                    this.Dispose();
                }
                else
                {
                    MessageBox.Show("Пароль введён не верно");
                    PasswordTextBox.Clear();
                    PasswordTextBox.Focus();
                }
            }
        }
Exemplo n.º 2
0
        private void FormDocButton_Click(object sender, EventArgs e)
        {
            try
            {
                string place = "beginning";
                bool   hasCard;
                string Command = "INSERT INTO Продажа (Дата,Сумма_Чека) VALUES (@date,@chequeSum)";
                Data.numberOfCard = 0;
                var result = MessageBox.Show("Спросите есть ли у клиента карта", "Наличие карты", MessageBoxButtons.YesNo);

                SqlParameter cardNumber = new SqlParameter();
                if (result == DialogResult.No)
                {
                    hasCard = false;
                }
                else
                {
                    СправочникКлиенты f = new СправочникКлиенты();
                    f.ShowDialog();

                    if (Data.numberOfCard > 0)
                    {
                        hasCard = true;
                        ApplyDiscount();
                        Command    = "INSERT INTO Продажа (Дата,Номер_Карты,Сумма_Чека) VALUES (@date,@cardNumber,@chequeSum)";
                        cardNumber = new SqlParameter("cardNumber", Data.numberOfCard);
                    }
                    else
                    {
                        hasCard = false;
                    }
                }
                MessageBox.Show("Итоговая стоимость = " + fullcost + " рублей");
                SqlParameter date      = new SqlParameter("date", DateTime.Now.ToShortDateString());
                SqlParameter chequeSum = new SqlParameter("chequeSum", fullcost);
                if (hasCard)
                {
                    StaticProcesser.ExecuteCommand(Command, date, cardNumber, chequeSum);
                }
                else
                {
                    StaticProcesser.ExecuteCommand(Command, date, chequeSum);
                }
                place = "added head";

                Command = "With SRC AS (Select TOP(1) Чек From Продажа ORDER BY Чек DESC) Select Чек FROM SRC";
                SqlDataReader reader = StaticProcesser.GetReader(Command);
                reader.Read();
                int chequeNumber = reader.GetInt32(0);
                StaticProcesser.CloseConnection();
                place = "got chequeNumber";

                double codeOfGood;
                double priceOfSell;
                int    amount;

                string updCommand = "Update Товары SET Остаток=Остаток-@amount Where Код_Товара = @codeOfGood";

                Command = "Insert INTO Состав_Продажи (Чек,Код_Товара,Цена,Количество) VALUES (@chequeNumber,@codeOfGood,@priceOfSell,@amount)";

                SqlParameter PchequeNumber = new SqlParameter("chequeNumber", chequeNumber);
                SqlParameter PcodeOfGood;
                SqlParameter PpriceOfSell;
                SqlParameter Pamount;

                for (int i = 0; i < чекdataGridView.Rows.Count; i++)
                {
                    codeOfGood  = Convert.ToInt32(чекdataGridView.Rows[i].Cells[0].Value);
                    PcodeOfGood = new SqlParameter("codeOfGood", codeOfGood);

                    if (hasCard)
                    {
                        priceOfSell = Convert.ToDouble(чекdataGridView.Rows[i].Cells[2].Value) * Properties.Settings.Default.Discount;
                    }
                    else
                    {
                        priceOfSell = Convert.ToDouble(чекdataGridView.Rows[i].Cells[2].Value);
                    }
                    PpriceOfSell = new SqlParameter("priceOfSell", priceOfSell);

                    amount  = Convert.ToInt32(чекdataGridView.Rows[i].Cells[3].Value);
                    Pamount = new SqlParameter("amount", amount);

                    StaticProcesser.ExecuteCommand(updCommand, Pamount, PcodeOfGood);

                    StaticProcesser.ExecuteCommand(Command, PchequeNumber, PcodeOfGood, PpriceOfSell, Pamount);
                    place = "Command executed " + i + " times";
                }
                MessageBox.Show("Документ успешно сформирован");
                StaticProcesser.FillDataGrid(comForListOfGoods, товарыdataGridView);
                cheque.Clear();
                чекdataGridView.DataSource = cheque;
                GetFullCost();
                Data.numberOfCard = 0;
            }
            catch (Exception ex)
            {
                StaticHelper.ErrorNotifier(ex);
            }
        }
Exemplo n.º 3
0
        private void FormDocButton_Click(object sender, EventArgs e)
        {
            string place = "beginning";

            try
            {
                string       Command = "Insert Into Приход (Дата,Комментарий) VALUES (@date,@comment)";
                SqlParameter p1      = new SqlParameter("date", DateTime.Now.ToShortDateString());
                SqlParameter p2      = new SqlParameter("comment", CommentRichTextBox.Text);
                StaticProcesser.ExecuteCommand(Command, p1, p2);
                place = "added head";

                Command = "With SRC AS (Select TOP(1) Номер_Прихода From Приход ORDER BY Номер_Прихода DESC) Select Номер_Прихода FROM SRC";
                SqlDataReader reader = StaticProcesser.GetReader(Command);
                reader.Read();
                int incID = reader.GetInt32(0);
                StaticProcesser.CloseConnection();
                place = "got ID";

                int    codeOfGood;
                double priceOfBuy;
                double priceOfSell;
                int    amount;

                string updCommand = "Update Товары SET Остаток=Остаток + @amount Where Код_Товара = @codeOfGood";

                Command = "Insert Into Состав_Прихода (Номер_Прихода,Код_Товара,Количество,Цена_Закупки,Цена_Продажи) VALUES (@id,@codeOfGood,@amount,@priceOfBuy,@priceOfSell)";
                SqlParameter id = new SqlParameter("id", incID);
                SqlParameter PcodeOfGood;
                SqlParameter PpriceOfBuy;
                SqlParameter PpriceOfSell;
                SqlParameter Pamount;
                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    codeOfGood  = Convert.ToInt32(dataGridView2.Rows[i].Cells[0].Value);
                    PcodeOfGood = new SqlParameter("codeOfGood", codeOfGood);

                    priceOfBuy  = Convert.ToDouble(dataGridView2.Rows[i].Cells[2].Value);
                    PpriceOfBuy = new SqlParameter("priceOfBuy", priceOfBuy);

                    priceOfSell  = Convert.ToDouble(dataGridView2.Rows[i].Cells[3].Value);
                    PpriceOfSell = new SqlParameter("priceOfSell", priceOfSell);

                    amount  = Convert.ToInt32(dataGridView2.Rows[i].Cells[4].Value);
                    Pamount = new SqlParameter("amount", amount);

                    StaticProcesser.ExecuteCommand(updCommand, Pamount, PcodeOfGood);

                    StaticProcesser.ExecuteCommand(Command, id, PcodeOfGood, Pamount, PpriceOfBuy, PpriceOfSell);
                    place = "Command executed " + i + " times";
                }

                MessageBox.Show("Документ успешно сформирован");
                StaticProcesser.FillDataGrid(GoodsSelectCommand, dataGridView1);
                IncomingGoodsDataTable.Clear();
                dataGridView2.DataSource = IncomingGoodsDataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show(place);
                StaticHelper.ErrorNotifier(ex);
            }
        }