示例#1
0
        // кнопка удалить запись
        private void Button_delRow_click(object sender, RoutedEventArgs e)
        {
            // получаем запись, которую собираемся удалить
            Order_entity order = ((FrameworkElement)sender).DataContext as Order_entity;
            // поулчаем подтверждение на удаление
            MessageBoxResult messageBoxResult =
                System.Windows.MessageBox.Show(
                    "Вы действительно хотите удалить заказ №" + order.Id,
                    "Delete Confirmation",
                    System.Windows.MessageBoxButton.YesNo
                    );

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                Console.WriteLine("clicked delete row id = " + order.Id);

                // Проверяем, нет ли зависимых от это строки записей
                using (var context = new ApplicationContext())
                {
                    // получаем запись по первичному ключу, которую собираемся удалить
                    var deletedRoom = context.Orders.Where(c => c.Id == order.Id).FirstOrDefault();
                    // удаляем запись
                    context.Orders.Remove(deletedRoom);
                    // применяем изменения в базе
                    context.SaveChanges();
                }
                // применяем изменения в бд
                db.SaveChanges();
                // обновляем таблицу с заказами
                this.updateDataGrid();
            }
        }
示例#2
0
        // Обновляем значение таблицы
        public void updateDataGrid()
        {
            // создаем контакст базы
            db = new ApplicationContext();
            // получаем с базы запии таблиц
            roomTypesList = RoomTypes.init_RoomTypes(db);
            roomsList     = Entity.Rooms.init_Rooms(db);
            clientsList   = Clients.init_Clients(db);
            ordersList    = Order_entity.init_Orders(db);

            // создаем список записей, отображаемых в таблице
            ordersList_table = new List <Order_entity>();
            foreach (var order in ordersList)
            {
                ordersList_table.Add(order);
            }

            DateTime now = DateTime.Now;

            ObservableCollection <Order_entity> items = new ObservableCollection <Order_entity>(ordersList)
            {
            };

            DataGrid_orders.ItemsSource = ordersList_table;

            findRowsByFilter();
        }
示例#3
0
        public List <Order_entity> load_ordenow(int limit)
        {
            List <Order_entity> l = new List <Order_entity>();
            var list = (from a in db.ESHOP_ORDERs
                        join b in db.ESHOP_ORDER_ITEMs on a.ORDER_ID equals b.ORDER_ID
                        join c in db.ESHOP_NEWs on b.NEWS_ID equals c.NEWS_ID
                        join d in db.ESHOP_NEWS_CATs on c.NEWS_ID equals d.NEWS_ID
                        select new
            {
                c.NEWS_TITLE,
                a.ORDER_NAME,
                a.ORDER_ID,
                c.NEWS_SEO_URL,
                c.NEWS_URL,
                d.ESHOP_CATEGORy.CAT_SEO_URL
            }).OrderByDescending(n => n.ORDER_ID).Take(limit);

            foreach (var i in list)
            {
                Order_entity order = new Order_entity();
                order.CAT_SEO_URL  = i.CAT_SEO_URL;
                order.NEWS_SEO_URL = i.NEWS_SEO_URL;
                order.NEWS_URL     = i.NEWS_URL;
                order.ORDER_NAME   = i.ORDER_NAME;
                order.NEWS_TITLE   = i.NEWS_TITLE;
                l.Add(order);
            }
            return(l);
        }
示例#4
0
        public IQueryable <Order_entity> load_ordePaymentFinalobj(object id)
        {
            int _id = Utils.CIntDef(id);
            List <Order_entity> l = new List <Order_entity>();
            var list = (from a in db.ESHOP_ORDERs
                        join b in db.ESHOP_ORDER_ITEMs on a.ORDER_ID equals b.ORDER_ID
                        join c in db.ESHOP_NEWs on b.NEWS_ID equals c.NEWS_ID
                        where a.ORDER_ID == _id
                        select new
            {
                c.NEWS_TITLE,
                a.ORDER_NAME,
                a.ORDER_PHONE,
                a.ORDER_ID,
                c.NEWS_SEO_URL,
                c.NEWS_URL,
                c.NEWS_IMAGE3,
                a.ORDER_ADDRESS,
                c.NEWS_ID,
                c.NEWS_PRICE1,
                c.NEWS_PRICE2,
                a.ORDER_CODE,
                a.ORDER_SHIPPING_FEE,
                a.ORDER_TOTAL_AMOUNT,
                a.ORDER_TOTAL_ALL,
                b.ITEM_QUANTITY,
                b.ITEM_SUBTOTAL,
                b.ITEM_PRICE
            }).OrderByDescending(n => n.ORDER_ID);

            foreach (var i in list)
            {
                Order_entity order = new Order_entity();
                order.NEWS_SEO_URL       = i.NEWS_SEO_URL;
                order.NEWS_URL           = i.NEWS_URL;
                order.ORDER_NAME         = i.ORDER_NAME;
                order.ORDER_PHONE        = i.ORDER_PHONE;
                order.NEWS_TITLE         = i.NEWS_TITLE;
                order.NEWS_IMAGE3        = i.NEWS_IMAGE3;
                order.NEWS_ID            = Utils.CIntDef(i.NEWS_ID);
                order.ORDER_ADDRESS      = i.ORDER_ADDRESS;
                order.NEWS_PRICE1        = Utils.CDecDef(i.NEWS_PRICE1);
                order.NEWS_PRICE2        = Utils.CDecDef(i.NEWS_PRICE2);
                order.ORDER_CODE         = i.ORDER_CODE;
                order.ORDER_SHIPPING_FEE = Utils.CDecDef(i.ORDER_SHIPPING_FEE);
                order.ITEM_PRICE         = Utils.CDecDef(i.ITEM_PRICE);
                order.ITEM_SUBTOTAL      = Utils.CDecDef(i.ITEM_SUBTOTAL);
                order.ITEM_QUANTITY      = Utils.CIntDef(i.ITEM_QUANTITY);
                order.ORDER_TOTAL_AMOUNT = Utils.CDecDef(i.ORDER_TOTAL_AMOUNT);
                order.ORDER_TOTAL_ALL    = Utils.CDecDef(i.ORDER_TOTAL_ALL);
                l.Add(order);
            }
            return(l.AsQueryable());
        }
示例#5
0
        // кнопка редактирование записи
        private void Button_editRow_click(object sender, RoutedEventArgs e)
        {
            // получаем запись которую собираемся редактировать
            Order_entity order = ((FrameworkElement)sender).DataContext as Order_entity;

            Console.WriteLine("clicked edit row  id = " + order.Id);

            // открываем окно по редактированию записи
            Form_createOrder form = new Form_createOrder(order);

            form.Owner   = this;
            form.Closed += new EventHandler((o, args) => updateDataGrid());
            form.ShowDialog();
        }
示例#6
0
        private void UpdateCalendar()
        {
            Entity.Rooms        selectedRoom = (Entity.Rooms)DataGrid_rooms.SelectedItem;
            List <Order_entity> ordersList   = Order_entity.init_Orders(db);

            // достаем заказы с выбранной комнатой
            OrderRepos          orderRepos            = new OrderRepos(db);
            List <Order_entity> selectedRoomOrderList = orderRepos.GetByRoomId(selectedRoom.Id);

            Calendar_.BlackoutDates.Clear();
            foreach (Order_entity order in selectedRoomOrderList)
            {
                Calendar_.BlackoutDates.Add(
                    new CalendarDateRange(order.DateStart, order.DateEnd)
                    );
            }

            int a = 2;
        }
示例#7
0
        public List <Order_entity> load_ordePaymentFinal(int id)
        {
            List <Order_entity> l = new List <Order_entity>();
            var list = (from a in db.ESHOP_ORDERs
                        join b in db.ESHOP_ORDER_ITEMs on a.ORDER_ID equals b.ORDER_ID
                        join c in db.ESHOP_NEWs on b.NEWS_ID equals c.NEWS_ID
                        join d in db.ESHOP_NEWS_CATs on c.NEWS_ID equals d.NEWS_ID
                        where a.ORDER_ID == id
                        select new
            {
                c.NEWS_TITLE,
                a.ORDER_NAME,
                a.ORDER_ID,
                c.NEWS_SEO_URL,
                c.NEWS_URL,
                d.ESHOP_CATEGORy.CAT_SEO_URL,
                c.NEWS_IMAGE3,
                a.ORDER_ADDRESS,
                c.NEWS_ID,
                c.NEWS_PRICE1,
                c.NEWS_PRICE2,
                a.ORDER_CODE
            }).OrderByDescending(n => n.ORDER_ID).Take(1);

            foreach (var i in list)
            {
                Order_entity order = new Order_entity();
                order.CAT_SEO_URL   = i.CAT_SEO_URL;
                order.NEWS_SEO_URL  = i.NEWS_SEO_URL;
                order.NEWS_URL      = i.NEWS_URL;
                order.ORDER_NAME    = i.ORDER_NAME;
                order.NEWS_TITLE    = i.NEWS_TITLE;
                order.NEWS_IMAGE3   = i.NEWS_IMAGE3;
                order.NEWS_ID       = Utils.CIntDef(i.NEWS_ID);
                order.ORDER_ADDRESS = i.ORDER_ADDRESS;
                order.NEWS_PRICE1   = Utils.CDecDef(i.NEWS_PRICE1);
                order.NEWS_PRICE2   = Utils.CDecDef(i.NEWS_PRICE2);
                order.ORDER_CODE    = i.ORDER_CODE;
                l.Add(order);
            }
            return(l);
        }
示例#8
0
        private void Button_confirmOrder_Click(object sender, RoutedEventArgs e)
        {
            Label_statusMain.Content = "";
            if (!verificateClient())
            {
                return;
            }

            if (!verificateRoom())
            {
                return;
            }

            Label_statusMain.Content = "Вроде все ок, можно заказывать";

            // Разбираемся с выбранным клиентом
            Clients client = null;

            if (isOldClient)
            {
                client = this.oldClient;
            }
            else
            {
                string findPassport   = TextBox_passport.Text;
                string findFirstName  = TextBox_firstName.Text;
                string findSecondName = TextBox_secondName.Text;
                string findPatronymic = TextBox_patronymic.Text;
                string findPhone      = TextBox_phone.Text;

                client            = new Clients();
                client.Passport   = findPassport;
                client.FirstName  = findFirstName;
                client.SecondName = findSecondName;
                client.Patronymic = findPatronymic;
                client.Phone      = findPhone;
                client            = db.Clients.Add(client);
                db.SaveChanges();
            }

            if (this.order_editing == null)
            {
                // create mod
                Order_entity order = new Order_entity();
                order.ClientsId = client.Id;
                order.Clients   = client;

                order.RoomsId = selectedRoom.Id;
                order.Rooms   = selectedRoom;

                SelectedDatesCollection calendarSelectedDates = Calendar_.SelectedDates;
                order.DateStart = calendarSelectedDates[0];
                order.DateEnd   = calendarSelectedDates[calendarSelectedDates.Count - 1];

                order = db.Orders.Add(order);
            }
            else
            {
                // edit mod
                order_editing.ClientsId = client.Id;
                order_editing.Clients   = client;

                order_editing.RoomsId = selectedRoom.Id;
                order_editing.Rooms   = selectedRoom;

                SelectedDatesCollection calendarSelectedDates = Calendar_.SelectedDates;
                order_editing.DateStart = calendarSelectedDates[0];
                order_editing.DateEnd   = calendarSelectedDates[calendarSelectedDates.Count - 1];

                // обновление записи в бд
                using (var db = new ApplicationContext())
                {
                    db.Orders.Attach(order_editing);

                    db.Entry(order_editing).Property(x => x.ClientsId).IsModified = true;
                    db.Entry(order_editing).Property(x => x.RoomsId).IsModified   = true;
                    db.Entry(order_editing).Property(x => x.DateStart).IsModified = true;
                    db.Entry(order_editing).Property(x => x.DateEnd).IsModified   = true;

                    db.SaveChanges();
                }
                // обновляем таблицу на родительской форме
                ((MainWindow)this.Owner).updateDataGrid();
            }

            db.SaveChanges();
            // закрываем текущую форму
            this.Close();
        }
示例#9
0
        public Form_createOrder(Order_entity o)
        {
            this.order_editing = o;

            InitializeComponent();

            db = new ApplicationContext();


            roomTypesList = RoomTypes.init_RoomTypes(db);
            roomsList     = Entity.Rooms.init_Rooms(db);
            clientsList   = Clients.init_Clients(db);
            ordersList    = Order_entity.init_Orders(db);

            // инициализируем комбобокс с выбором типа комнаты
            ComboBox_roomType.Items.Add(emptyComboBoxItem);
            foreach (RoomTypes type in roomTypesList)
            {
                ComboBox_roomType.Items.Add(type);
            }

            // Инициализируем комбобокс выбора размера комнаты значениями
            Combobox_size.Items.Add(emptyComboBoxItem);
            Entity.Rooms.initComboboxSize(Combobox_size);

            updateDataGridRooms();

            try
            {
                updateDataGridClients();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                using (StreamWriter writetext = new StreamWriter("_logs.txt"))
                {
                    writetext.WriteLine(ex.Message);
                    writetext.WriteLine("\n");
                    writetext.WriteLine(ex.ToString());
                }
            }

            DateTime now = DateTime.Now;

            Calendar_.SelectionMode    = CalendarSelectionMode.MultipleRange;
            Calendar_.DisplayDateStart = new DateTime(
                now.Year,
                now.Month - 1 < 1 ? 1 : now.Month - 1,
                1);

            if (order_editing != null)
            {
                // edit mod
                this.Title = "Редактирование информации о заказе";
                this.Button_confirmOrder.Content = "Обновить";
                this.selectedRoom = order_editing.Rooms;

                // инфа о выбранном пользователе
                TextBox_passport.Text   = order_editing.Clients.Passport;
                TextBox_firstName.Text  = order_editing.Clients.FirstName;
                TextBox_secondName.Text = order_editing.Clients.SecondName;
                TextBox_patronymic.Text = order_editing.Clients.Patronymic;
                TextBox_phone.Text      = order_editing.Clients.Phone;

                // достаем заказы с выбранной комнатой
                OrderRepos          orderRepos            = new OrderRepos(db);
                List <Order_entity> selectedRoomOrderList = orderRepos.GetByRoomId(order_editing.RoomsId);

                // помечаем календарь крестиками
                Calendar_.BlackoutDates.Clear();
                Calendar_.SelectedDates.Clear();
                foreach (Order_entity order in selectedRoomOrderList)
                {
                    if (order.Id != order_editing.Id)
                    {
                        Calendar_.BlackoutDates.Add(
                            new CalendarDateRange(order.DateStart, order.DateEnd)
                            );
                    }
                }
                // помечаем на календаре выбранные дни для текущего заказа
                Calendar_.SelectedDates.Clear();
                for (DateTime date = order_editing.DateStart;
                     order_editing.DateEnd.AddDays(1).CompareTo(date) > 0;
                     date = date.AddDays(1.0))
                {
                    Calendar_.SelectedDates.Add(date);
                }
            }
        }