Exemple #1
0
        private void InintUsers(BindingList <dataGridItem> items)
        {
            var list = new List <dataGridItem>();

            using (var context = new Entity.EntityCodeFirst())
            {
                foreach (var client in context.Client)
                {
                    foreach (var _userData in context.UserData)
                    {
                        var userDate = context.UserData.FirstOrDefault(_client => (_client.id == client.ud_id));
                        var order    = context.Orders.FirstOrDefault(_order => (_order.client_id == client.id));

                        var products = new List <Product>();
                        foreach (var productId in context.OrdersHasProduct)
                        {
                            if (productId.id_orders == order.id)
                            {
                                var _product = context.Product.FirstOrDefault(_item => (_item.id == productId.id_product));
                                items.Add(new dataGridItem()
                                {
                                    orderName = order.name,
                                    firstName = userDate.firstname,
                                    surName   = userDate.middlename,
                                    lastName  = userDate.lastname,
                                    product   = _product.name,
                                    price     = _product.price
                                });
                            }
                        }
                    }
                }
            }
        }
        private void buttonArrange_Click(object sender, EventArgs e)
        {
            try
            {
                if ((string.IsNullOrEmpty(textBoxClientName.Text) || (string.IsNullOrWhiteSpace(textBoxClientName.Text)) ||
                     (string.IsNullOrEmpty(textBoxClientLName.Text) || (string.IsNullOrWhiteSpace(textBoxClientLName.Text)) ||
                      (string.IsNullOrEmpty(textBoxMClientName.Text) || (string.IsNullOrWhiteSpace(textBoxMClientName.Text)) ||
                       (string.IsNullOrEmpty(textBoxPrice.Text) || (string.IsNullOrWhiteSpace(textBoxPrice.Text)) ||
                        (string.IsNullOrEmpty(textBoxName.Text) || (string.IsNullOrWhiteSpace(textBoxName.Text)) ||
                         (string.IsNullOrEmpty(textBoxProduct.Text) || (string.IsNullOrWhiteSpace(textBoxProduct.Text)))))))))
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Пожалуйста заполните все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                using (var context = new Entity.EntityCodeFirst())
                {
                    context.UserData.Add(
                        new Entity.UserData()
                    {
                        id         = 0,
                        firstname  = textBoxClientName.Text,
                        lastname   = textBoxClientLName.Text,
                        middlename = textBoxMClientName.Text,
                    });
                    context.SaveChanges();
                    context.Orders.Add(
                        new Entity.Orders()
                    {
                        id   = 0,
                        name = textBoxName.Text,
                    });
                    context.SaveChanges();
                    context.Product.Add(
                        new Entity.Product()
                    {
                        id    = 0,
                        name  = textBoxProduct.Text,
                        price = Convert.ToDecimal(textBoxPrice.Text)
                    });
                    context.SaveChanges();
                }
                MessageBox.Show("Заказ успешно добавлен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch
            {
                MessageBox.Show("Произошла ошибка добавления информации в базу данных проверьте вводимые данные", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
        public FormManager(string login)
        {
            InitializeComponent();
            dataGridView.DataSource = null;
            db = new BindingList <dataGridItem>();

            InitDataGrid();

            this.login = login;

            pictureBoxavatar.Image = Properties.Resources.profile_icon_183860;
            label_Login.Text       = "@" + login;

            using (Entity.EntityCodeFirst context = new Entity.EntityCodeFirst())
            {
                var user = Class.UserSingleton.GetUser();


                var selecteduser = context.User.FirstOrDefault(_user => (_user.id == _user.id));
                labelName.Text = user.GetFirstName() + " " + user.GetLastName() + " " + user.GetMiddleName();
            }
        }