Exemplo n.º 1
0
        public bool AddOrder(OrderType composite)
        {
            var tables = new LinqWorkerDataContext();

            if (tables.Orders.All(x => x.Date != composite.Date ))
            {
                string type = "user", message = string.Empty;

                var order = new Orders
                    {
                        UserId = composite.UserId,
                        Article = composite.Article,
                        Date =  composite.Date,
                        Comment = composite.Comment,
                        ItemCount =  composite.ItemCount,
                        ItemId = composite.ItemId
                    };

                try
                {
                    String command =
                        String.Format(
                            "INSERT INTO dbo.Orders(Article,UserId,Date,Comment,Itemid,ItemCount) VALUES(\'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\')",
                            order.Article,
                            order.UserId,
                            order.Date,
                            order.Comment,
                            order.ItemId,
                             order.ItemCount
                            );

                    tables.ExecuteCommand(command);

                    message = "Добавлена новая заявка : " + order.Article;
                    //tables.Orders.Context.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    message = "Ошибка при добавление заявки : " + order.Article;
                    type = "system";
                    Console.WriteLine(ex.Message);
                    return false;
                }
                finally
                {
                    AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
                }
            }
            return false;
        }
Exemplo n.º 2
0
        public bool UptadeOrder(OrderType composite)
        {
            var tables = new LinqWorkerDataContext();
            string type = "user", message = string.Empty;
            try
            {
                var order = tables.Orders.Single(c => c.Id == composite.Id);

                order.Article = composite.Article;
                order.Date = composite.Date;
                order.UserId = composite.UserId;
                order.Comment = composite.Comment;
                order.ItemId = composite.ItemId;
                order.ItemCount = composite.ItemCount;

                tables.Orders.Context.SubmitChanges();

                message = "Обновление заявки : " + composite.Article;
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                message = "Ошибка при обновлении заявки : " + composite.Article;
                type = "system";
                return false;
            }
            finally
            {
                AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
            }
            /*
                        return false;
            */
        }
Exemplo n.º 3
0
        public bool DeleteOrder(OrderType composite)
        {
            var tables = new LinqWorkerDataContext();
            string type = "user", message = string.Empty;
            try
            {
                var order = tables.Orders.Single(c => c.Id == composite.Id);
                tables.Orders.DeleteOnSubmit(order);
                tables.Orders.Context.SubmitChanges();

                message = "Заявка удалена : " + composite.Article;
                return true;
            }
            catch (Exception ex)
            {
                message = "Ошибка при удалении заявки : " + composite.Article;
                type = "system";
                return false;
            }
            finally
            {
                AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
            }

            /*
                        return false;
            */
        }