Ejemplo n.º 1
0
        //private void Button_Click(object sender, RoutedEventArgs e)
        //{
        //    DataRowView x = (DataRowView)listGoods.Items[0];
        //    string s = "";
        //    foreach (var item in x.Row.ItemArray)
        //    {
        //        s += item.ToString()+"*";
        //    }
        //    MessageBox.Show(x.Row.ItemArray[0].ToString()+"\n\n"+s);// x.Row.Field<double>("price").ToString());
        //}

        private void AddGoods(object sender, RoutedEventArgs e)
        {
            int x = listGoods.SelectedIndex;

            DataTable table = SQLbase.Select($"select * from Goods");


            if (x == -1)
            {
                ButtonAdd.ToolTip    = "Выберите элемент!";
                ButtonAdd.Foreground = Brushes.Red;
                return;
            }
            else
            {
                ButtonAdd.ToolTip    = "";
                ButtonAdd.Foreground = Brushes.LightGreen;
            }

            DataTable tableOrders = SQLbase.Select($"select login, good, count from Orders where login = N'{LOGIN}' and good = N'{table.Rows[x][0]}'");

            if (tableOrders.Rows.Count > 0)
            {
                SQLbase.Insert($"update Orders set count = {(int)tableOrders.Rows[0][2] + 1} where login = N'{LOGIN}' and good = N'{table.Rows[x][0]}';");
            }
            else
            {
                SQLbase.Insert($"insert into Orders(login, good, count) values (N'{LOGIN}',N'{table.Rows[x][0]}',N'1')");
            }
        }
Ejemplo n.º 2
0
        private void Edit(object sender, RoutedEventArgs e)
        {
            string s = Count.Text;

            if (s.Length > 6)
            {
                Count.ToolTip    = "Ошибка ввода числа поиска!";
                Count.Foreground = Brushes.Red;
                return;
            }

            foreach (Char u in s)
            {
                if (!char.IsDigit(u))
                {
                    Count.ToolTip    = "Требуется числовое значение!";
                    Count.Foreground = Brushes.Red;
                    return;
                }
                else
                {
                    Count.ToolTip    = "";
                    Count.Foreground = Brushes.Black;
                }
            }

            int x = listGoods.SelectedIndex;

            if (x == -1 || s.Length == 0)
            {
                ButtonEdit.ToolTip    = "Выберите элемент!";
                ButtonEdit.Foreground = Brushes.Red;
                return;
            }
            else
            {
                ButtonEdit.ToolTip    = "";
                ButtonEdit.Foreground = Brushes.LightGreen;
            }

            DataTable table = SQLbase.Select($"select * from Orders where login = N'{LOGIN}'");

            SQLbase.Insert($"update Orders set count = {int.Parse(Count.Text)} where login = N'{LOGIN}' and good = N'{table.Rows[x][2]}'");

            ShowList();
        }
Ejemplo n.º 3
0
        private void ReportGo()
        {
            DataTable table = SQLbase.Select($"select * from Orders");

            var word = new Word.Application();

            word.Visible = false;
            //  word.Document worddoc;

            //ReplaceWordStub("{nazv}", TableString(table), worddoc);
            var worddoc = word.Documents.Open($"{Environment.CurrentDirectory}/report.docx");

            try
            {
                Word.Table t = worddoc.Tables[1];

                for (int i = 0, count = 2; i < table.Rows.Count; i++, count++)
                {
                    t.Cell(count, 1).Range.Text = table.Rows[i][0].ToString();
                    t.Cell(count, 2).Range.Text = table.Rows[i][1].ToString();
                    t.Cell(count, 3).Range.Text = table.Rows[i][2].ToString();
                    t.Cell(count, 4).Range.Text = table.Rows[i][3].ToString();
                    if (count < table.Rows.Count + 1)
                    {
                        t.Rows.Add();
                    }
                }

                worddoc.SaveAs2($"{Environment.CurrentDirectory}/report1.docx");
                //word.ActiveDocument.Close();
                MessageBox.Show("Создан");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //finally
            //{
            //    //worddoc.Close();
            //}
        }
Ejemplo n.º 4
0
        private void ShowList()
        {
            DataTable table = SQLbase.Select($"select login, good, count, price from Orders inner join Goods on Orders.good = Goods.name where login = N'{LOGIN}'");

            listGoods.ItemsSource = table.DefaultView;

            double sum = 0;

            if (table.Rows.Count == 0)
            {
                orderPrice.Content = $"Сумма заказа:";
                return;
            }

            for (int i = 0; i < table.Rows.Count; i++)
            {
                sum += (double)table.Rows[i][3] * (int)table.Rows[i][2];
            }

            orderPrice.Content = $"Сумма заказа: {sum}";
        }
Ejemplo n.º 5
0
        private void Delete(object sender, RoutedEventArgs e)
        {
            int x = listGoods.SelectedIndex;

            if (x == -1)
            {
                ButtonDelete.ToolTip    = "Выберите элемент!";
                ButtonDelete.Foreground = Brushes.Red;
                return;
            }
            else
            {
                ButtonDelete.ToolTip    = "";
                ButtonDelete.Foreground = Brushes.LightGreen;
            }

            DataTable table = SQLbase.Select($"select * from Orders where login = N'{LOGIN}'");

            DataRowView i = (DataRowView)listGoods.Items[x];

            SQLbase.Insert($"delete Orders where good = N'{i.Row.ItemArray[1].ToString()}'");

            ShowList();
        }
Ejemplo n.º 6
0
        private void Button_Reg_Click(object sender, RoutedEventArgs e)
        {
            string login = loginBox.Text.Trim().ToUpper();

            string [] name      = nameBox.Text.Trim().Split(" ");
            string    password1 = firstPassBox.Password.Trim();
            string    password2 = secondPassBox.Password.Trim();

            bool isGood = true;

            //Проверка поля логина
            if (login.Length < 3 && login.Length > 20)
            {
                isGood              = false;
                loginBox.ToolTip    = "Длина логина должна быть от 3 до 20 букв!";
                loginBox.Foreground = Brushes.Red;
            }
            else
            {
                bool stop = false;

                foreach (char x in login)
                {
                    Console.WriteLine("yes");
                    if (Char.IsDigit(x))
                    {
                        stop = true;
                        break;
                    }

                    if (Convert.ToInt16(x) < 0 || Convert.ToInt16(x) > 128)
                    {
                        stop = true;
                        break;
                    }
                }

                if (stop)
                {
                    isGood              = false;
                    loginBox.ToolTip    = "Недопустимый ввод символов!";
                    loginBox.Foreground = Brushes.Red;
                }
                else
                {
                    DataTable table = SQLbase.Select($"select * from Customer where login = '******'");
                    if (table.Rows.Count > 0)
                    {
                        isGood              = false;
                        loginBox.ToolTip    = "Такой пользователь уже существует!";
                        loginBox.Foreground = Brushes.Red;
                    }
                    else
                    {
                        loginBox.ToolTip    = " ";
                        loginBox.Foreground = Brushes.Black;
                    }
                }
            }

            //Поле фио
            if (!(name.Length == 2 || name.Length == 3))
            {
                isGood             = false;
                nameBox.ToolTip    = "Требуется полное написание ФИО!";
                nameBox.Foreground = Brushes.Red;
            }
            else
            {
                nameBox.ToolTip    = "";
                nameBox.Foreground = Brushes.Black;
            }

            //Проверка пароля
            if (password1.Length < 4 && password1.Length > 16)
            {
                isGood = false;
                firstPassBox.ToolTip    = "Длина пароля должна быть от 4 до 16 символов!";
                firstPassBox.Foreground = Brushes.Red;
            }
            else
            {
                firstPassBox.ToolTip    = "";
                firstPassBox.Foreground = Brushes.Black;
            }

            //Подтверждение пароля
            if (password1 != password2)
            {
                isGood = false;
                secondPassBox.ToolTip    = "Пароли не совпадают";
                secondPassBox.Foreground = Brushes.Red;
            }
            else
            {
                secondPassBox.ToolTip    = "";
                secondPassBox.Foreground = Brushes.Black;
            }

            if (isGood == true)
            {
                loginBox.Text          = "";
                nameBox.Text           = "";
                firstPassBox.Password  = "";
                secondPassBox.Password = "";
                SQLbase.Insert($"insert into Customer(login, name, pass) values (N'{login}',N'{name}',N'{password1}')");
                Login log = new Login();

                this.Close();
                log.Show();
            }
        }
Ejemplo n.º 7
0
        private void Button_Login_Click(object sender, RoutedEventArgs e)
        {
            string login     = loginBox.Text.Trim().ToUpper();
            string password1 = firstPassBox.Password.Trim();

            bool isGood = true;

            if (login.Length < 1)
            {
                isGood              = false;
                loginBox.ToolTip    = "Введите логин!";
                loginBox.Foreground = Brushes.Red;
            }
            else
            {
                loginBox.ToolTip    = " ";
                loginBox.Foreground = Brushes.Black;
            }

            if (password1.Length < 1)
            {
                isGood = false;
                firstPassBox.ToolTip    = "Введите пароль!";
                firstPassBox.Foreground = Brushes.Red;
            }
            else
            {
                firstPassBox.ToolTip    = " ";
                firstPassBox.Foreground = Brushes.Black;
            }

            if (isGood == true)
            {
                if (login == "ADMIN" && password1 == "Admin")
                {
                    ListOrders s = new ListOrders();
                    s.Show();
                    this.Close();
                    return;
                }

                DataTable table = SQLbase.Select($"select * from Customer where login = '******'");

                if (table.Rows.Count > 0)
                {
                    loginBox.ToolTip    = " ";
                    loginBox.Foreground = Brushes.Black;
                    table = SQLbase.Select($"select * from Customer where login = '******' and pass = '******'");
                    if (table.Rows.Count > 0)
                    {
                        Goods s = new Goods(login);
                        this.Close();

                        s.Show();
                    }
                    else
                    {
                        firstPassBox.ToolTip    = "Неправильный пароль!";
                        firstPassBox.Foreground = Brushes.Red;
                    }
                }
                else
                {
                    loginBox.ToolTip    = "Такого пользователя не существует!";
                    loginBox.Foreground = Brushes.Red;
                }
            }
        }
Ejemplo n.º 8
0
        private void ShowList()
        {
            DataTable table = SQLbase.Select($"select * from Orders");

            listGoods.ItemsSource = table.DefaultView;
        }
Ejemplo n.º 9
0
        private void ShowList(string str)
        {
            DataTable talbe = SQLbase.Select(str);

            listGoods.ItemsSource = talbe.DefaultView;
        }