public ViewOrders()
        {
            InitializeComponent();

            this.scheduler = TaskScheduler.FromCurrentSynchronizationContext();
            te = new ThirtyOneEntities();
        }
示例#2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (orderControl.CustomerID == Guid.Empty)
                return;

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                Order order = new Order();
                order.CustomerID = orderControl.CustomerID;
                order.IsPaid = orderControl.IsPaid;
                order.OrderDate = Convert.ToDateTime(PartyDatePicker.Text);
                order.OrderID = Guid.NewGuid();
                order.OrderShipping = orderControl.ShippingTotal;
                order.OrderSubTotal = orderControl.ProductSubTotal;
                order.OrderTax = orderControl.TaxTotal;
                order.OrderTotal = orderControl.TotalPrice;

                if (order.IsPaid && orderControl.PaymentTypeID != null)
                    order.PaymentTypeID = orderControl.PaymentTypeID;
                else
                    order.PaymentTypeID = GetNonePaymentTypeID();

                te.AddToOrders(order);
                te.SaveChanges();
            }

            orderControl.BeginRemoveStoryboard();

            Storyboard saveCompleteSB = (Storyboard)FindResource("SaveCompleteStoryboard");
            saveCompleteSB.Begin();
        }
示例#3
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (OrdersDataGrid.SelectedItems.Count == 0)
            {
                return;
            }

            using (ThirtyOneEntities toe = new ThirtyOneEntities())
            {
                Guid  orderID = (OrdersDataGrid.SelectedItem as Order).OrderID;
                Order order   = toe.Orders.Single(t => t.OrderID == orderID);

                toe.DeleteObject(order);

                toe.SaveChanges();
            }

            OrdersDataGrid.SelectedIndex      = -1;
            CustomerNameTextBlock.Text        = string.Empty;
            OrderTotalTextBlock.Text          = string.Empty;
            IsPaidCheckBox.IsChecked          = false;
            PaymentTypeComboBox.SelectedIndex = -1;

            te.Dispose();
            te = new ThirtyOneEntities();

            DateTime orderDate = Convert.ToDateTime(OrdersDateComboBox.SelectedValue.ToString());

            var orders = from t in te.Orders
                         where t.OrderDate == orderDate &&
                         t.PartyID == null
                         select t;

            OrdersDataGrid.ItemsSource = orders;
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (OrdersDataGrid.SelectedItems.Count == 0)
                return;

            using (ThirtyOneEntities toe = new ThirtyOneEntities())
            {
                Guid orderID = (OrdersDataGrid.SelectedItem as Order).OrderID;
                Order order = toe.Orders.Single(t => t.OrderID == orderID);

                toe.DeleteObject(order);

                toe.SaveChanges();
            }

            OrdersDataGrid.SelectedIndex = -1;
            CustomerNameTextBlock.Text = string.Empty;
            OrderTotalTextBlock.Text = string.Empty;
            IsPaidCheckBox.IsChecked = false;
            PaymentTypeComboBox.SelectedIndex = -1;

            te.Dispose();
            te = new ThirtyOneEntities();

            DateTime orderDate = Convert.ToDateTime(OrdersDateComboBox.SelectedValue.ToString());

            var orders = from t in te.Orders
                         where t.OrderDate == orderDate
                         && t.PartyID == null
                         select t;

            OrdersDataGrid.ItemsSource = orders;
        }
 private void CreateTableContraints()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "ALTER TABLE [Customers] ADD CONSTRAINT [PK_Customers] PRIMARY KEY ([CustomerID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Orders] ADD CONSTRAINT [PK__Orders__00000000000000BB] PRIMARY KEY ([OrderID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Parties] ADD CONSTRAINT [PK_Parties] PRIMARY KEY ([PartyID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [PaymentTypes] ADD CONSTRAINT [PK__PaymentTypes__00000000000000DE] PRIMARY KEY ([PaymentTypeID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__Customers__0000000000000115] ON [Customers] ([CustomerID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__Orders__00000000000000A9] ON [Orders] ([OrderID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__Parties__000000000000012B] ON [Parties] ([PartyID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__PaymentTypes__00000000000000D6] ON [PaymentTypes] ([PaymentTypeID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Orders] ADD CONSTRAINT [CustomerOrders] FOREIGN KEY ([CustomerID]) REFERENCES [Customers]([CustomerID]) ON DELETE NO ACTION ON UPDATE NO ACTION;";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Orders] ADD CONSTRAINT [PaymentTypeOrders] FOREIGN KEY ([PaymentTypeID]) REFERENCES [PaymentTypes]([PaymentTypeID]) ON DELETE NO ACTION ON UPDATE NO ACTION;";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#6
0
 private Guid GetNonePaymentTypeID()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         return te.PaymentTypes.SingleOrDefault(t => t.PaymentTypeName == "None").PaymentTypeID;
     }
 }
示例#7
0
 private Guid GetNonePaymentTypeID()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         return(te.PaymentTypes.SingleOrDefault(t => t.PaymentTypeName == "None").PaymentTypeID);
     }
 }
        public ViewParty()
        {
            InitializeComponent();

            this.scheduler = TaskScheduler.FromCurrentSynchronizationContext();
            te             = new ThirtyOneEntities();
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CustomerNameTextBox.Text))
            {
                return;
            }

            this.Cursor = Cursors.Wait;

            try
            {
                using (ThirtyOneEntities toe = new ThirtyOneEntities())
                {
                    Customer cust = toe.Customers.SingleOrDefault(t => t.CustomerName == CustomerNameTextBox.Text.Trim());

                    if (cust != null)
                    {
                        this.Cursor = Cursors.Arrow;
                        MessageBox.Show("Customer already exists.");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                string error = string.Format("{0}{1}{2}{3}", ex.Message, Environment.NewLine, (ex.InnerException != null) ? ex.InnerException.Message : "", ex.StackTrace);
                MessageBox.Show(error);
                return;
            }

            try
            {
                using (ThirtyOneEntities te = new ThirtyOneEntities())
                {
                    Customer c = te.CreateObject <Customer>();
                    c.CustomerID   = Guid.NewGuid();
                    c.CustomerName = CustomerNameTextBox.Text.Trim();

                    te.Customers.AddObject(c);
                    te.SaveChanges();
                }

                CustomerNameTextBox.Text = string.Empty;
                OnCustomerAddCompleted();

                Storyboard saveCompleteSB = (Storyboard)FindResource("SaveCompleteStoryboard");
                saveCompleteSB.Begin();

                CustomerNameTextBox.Focus();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                MessageBox.Show(ex.Message);
                return;
            }

            this.Cursor = Cursors.Arrow;
        }
示例#10
0
 private void CreatePartiesTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [Parties] ([PartyID] uniqueidentifier NOT NULL  ROWGUIDCOL, [PartyDate] datetime NOT NULL, [PartyTotal] float NOT NULL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#11
0
 private void CreateOrdersTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [Orders] ([OrderSubTotal] float NULL, [OrderTax] float NULL, [OrderTotal] float NULL, [IsPaid] bit NOT NULL, [OrderID] uniqueidentifier NOT NULL  ROWGUIDCOL, [CustomerID] uniqueidentifier NOT NULL, [PaymentTypeID] uniqueidentifier NOT NULL, [OrderDate] datetime NOT NULL, [PartyID] uniqueidentifier NULL, [OrderShipping] float NULL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#12
0
 private void CreateCustomersTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [Customers] ([CustomerID] uniqueidentifier NOT NULL  ROWGUIDCOL, [CustomerName] nvarchar(150) NOT NULL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
 private void CreatePaymentTypesTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [PaymentTypes] ([PaymentType] nvarchar(100) NULL, [PaymentTypeID] uniqueidentifier NOT NULL  ROWGUIDCOL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
 private void CreateTestTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [Test] ([CustomerID] uniqueidentifier NOT NULL  ROWGUIDCOL, [CustomerName] nvarchar(150) NOT NULL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
 private void CreatePartiesTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [Parties] ([PartyID] uniqueidentifier NOT NULL  ROWGUIDCOL, [PartyDate] datetime NOT NULL, [PartyTotal] float NOT NULL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
 private void CreateOrdersTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [Orders] ([OrderSubTotal] float NULL, [OrderTax] float NULL, [OrderTotal] float NULL, [IsPaid] bit NOT NULL, [OrderID] uniqueidentifier NOT NULL  ROWGUIDCOL, [CustomerID] uniqueidentifier NOT NULL, [PaymentTypeID] uniqueidentifier NOT NULL, [OrderDate] datetime NOT NULL, [PartyID] uniqueidentifier NULL, [OrderShipping] float NULL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#17
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CustomerNameTextBox.Text))
                return;

            this.Cursor = Cursors.Wait;

            try
            {
                using (ThirtyOneEntities toe = new ThirtyOneEntities())
                {
                    Customer cust = toe.Customers.SingleOrDefault(t => t.CustomerName == CustomerNameTextBox.Text.Trim());

                    if (cust != null)
                    {
                        this.Cursor = Cursors.Arrow;
                        MessageBox.Show("Customer already exists.");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                string error = string.Format("{0}{1}{2}{3}", ex.Message, Environment.NewLine, (ex.InnerException != null) ? ex.InnerException.Message : "", ex.StackTrace);
                MessageBox.Show(error);
                return;
            }

            try
            {
                using (ThirtyOneEntities te = new ThirtyOneEntities())
                {
                    Customer c = te.CreateObject<Customer>();
                    c.CustomerID = Guid.NewGuid();
                    c.CustomerName = CustomerNameTextBox.Text.Trim();

                    te.Customers.AddObject(c);
                    te.SaveChanges();
                }

                CustomerNameTextBox.Text = string.Empty;
                OnCustomerAddCompleted();

                Storyboard saveCompleteSB = (Storyboard)FindResource("SaveCompleteStoryboard");
                saveCompleteSB.Begin();

                CustomerNameTextBox.Focus();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                MessageBox.Show(ex.Message);
                return;
            }

            this.Cursor = Cursors.Arrow;
        }
        public void UpdateData()
        {
            DateTime now = DateTime.Now;
            DateTime startOfMonth = new DateTime(now.Year, now.Month, 1);
            DateTime endOfMonth = new DateTime(now.Year, now.Month, 1).AddMonths(1);
            DateTime startOfYear = new DateTime(now.Year, 1, 1);
            DateTime endOfYear = new DateTime(now.Year, 1, 1).AddYears(1);

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var thisMonth = from c in te.Orders
                                where c.OrderDate >= startOfMonth
                                && c.OrderDate < endOfMonth
                                && c.IsPaid == true
                                group c by c.IsPaid into g
                                select new
                                {
                                    MonthlyTotal = g.Sum(t => t.OrderSubTotal)
                                };

                if (thisMonth.Count() != 0)
                    ThisMonthTotal.Text = string.Format("{0:c}", thisMonth.First().MonthlyTotal);
                else
                    ThisMonthTotal.Text = string.Format("{0:c}", 0);

                var thisYear = from c in te.Orders
                               where c.OrderDate >= startOfYear
                               && c.OrderDate < endOfYear
                               && c.IsPaid == true
                               group c by c.IsPaid into g
                               select new
                               {
                                   YearlyTotal = g.Sum(t => t.OrderSubTotal)
                               };

                if (thisYear.Count() != 0)
                    ThisYearTotal.Text = string.Format("{0:c}", thisYear.First().YearlyTotal);
                else
                    ThisYearTotal.Text = string.Format("{0:c}", 0);

                var total = from c in te.Orders
                            where c.IsPaid == true
                            group c by c.IsPaid into g
                            select new
                            {
                                TotalTotal = g.Sum(t => t.OrderSubTotal)
                            };
                if(total.Count() != 0)
                    Total.Text = string.Format("{0:c}", total.First().TotalTotal);
                else
                    Total.Text = string.Format("{0:c}", 0);
            }
        }
        private List <Customer> GetCustomers()
        {
            List <Customer> list = new List <Customer>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = te.Customers;

                list = custs.ToList();
            }

            return(list);
        }
        private List<Customer> GetCustomers()
        {
            List<Customer> list = new List<Customer>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = from c in te.Orders
                            select c.Customer;

                list = custs.Distinct().ToList();
            }

            return list;
        }
        private List <Customer> GetCustomers()
        {
            List <Customer> list = new List <Customer>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = from c in te.Orders
                            select c.Customer;

                list = custs.Distinct().ToList();
            }

            return(list);
        }
 private void CreatePaymentTypeData()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'None','c0a5d459-00b2-4ca1-a436-3a57744551e4');";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'Cash','8c2229c7-46d6-4dd7-b70f-fd53ae5bfbcc');";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'Check','4598225c-1175-46d1-8f62-dbdb2a859c3d');";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'Debit/Credit','8a7c971e-091b-4e4e-9255-2cfafb9f405f');";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#23
0
        private List<Party> GetParties()
        {
            List<Party> list = new List<Party>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = from c in te.Parties
                            orderby c.PartyDate descending
                            select c;

                list = custs.ToList();
            }

            return list;
        }
        private List <PaymentType> GetPaymentTypes()
        {
            List <PaymentType> list = new List <PaymentType>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = from c in te.PaymentTypes
                            orderby c.PaymentTypeName descending
                            select c;

                list = custs.ToList();
            }

            return(list);
        }
示例#25
0
        private List <DateTime> GetOrderDates()
        {
            List <DateTime> list = new List <DateTime>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = from c in te.Orders
                            where c.PartyID == null
                            orderby c.OrderDate descending
                            select c.OrderDate;

                list = custs.Distinct().ToList();
            }

            return(list);
        }
        public void UpdateData()
        {
            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var unpaidOrders = from c in te.Orders
                                   where c.IsPaid == false &&
                                   c.OrderTotal != null
                                   select new UnpaidOrder
                {
                    OrderDate    = c.OrderDate,
                    CustomerName = c.Customer.CustomerName,
                    OrderTotal   = c.OrderTotal.Value,
                    IsPaid       = false
                };

                UnpaidOrdersGrid.ItemsSource = unpaidOrders;
            }
        }
        public void UpdateData()
        {
            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var unpaidOrders = from c in te.Orders
                                   where c.IsPaid == false
                                   && c.OrderTotal != null
                                   select new UnpaidOrder
                                   {
                                       OrderDate = c.OrderDate,
                                       CustomerName = c.Customer.CustomerName,
                                       OrderTotal = c.OrderTotal.Value,
                                       IsPaid = false
                                   };

                UnpaidOrdersGrid.ItemsSource = unpaidOrders;
            }
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            using (ThirtyOneEntities toe = new ThirtyOneEntities())
            {
                Guid  orderID = (PartyDataGrid.SelectedItem as Order).OrderID;
                Order order   = toe.Orders.Single(t => t.OrderID == orderID);

                order.IsPaid = IsPaidCheckBox.IsChecked.Value;

                if (PaymentTypeComboBox.SelectedItem != null)
                {
                    order.PaymentTypeID = (PaymentTypeComboBox.SelectedItem as PaymentType).PaymentTypeID;
                }
                else
                {
                    order.PaymentTypeID = GetNonePaymentTypeID();
                }

                toe.SaveChanges();
            }

            PartyDataGrid.SelectedIndex       = -1;
            CustomerNameTextBlock.Text        = string.Empty;
            OrderTotalTextBlock.Text          = string.Empty;
            IsPaidCheckBox.IsChecked          = false;
            PaymentTypeComboBox.SelectedIndex = -1;

            te.Dispose();
            te = new ThirtyOneEntities();

            Guid partyID = (PartyDateComboBox.SelectedItem as Party).PartyID;

            var orders = from t in te.Orders
                         where t.PartyID == partyID
                         select t;

            PartyDataGrid.ItemsSource = orders;
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (orderControl.CustomerID == Guid.Empty)
            {
                return;
            }

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                Order order = new Order();
                order.CustomerID    = orderControl.CustomerID;
                order.IsPaid        = orderControl.IsPaid;
                order.OrderDate     = Convert.ToDateTime(PartyDatePicker.Text);
                order.OrderID       = Guid.NewGuid();
                order.OrderShipping = orderControl.ShippingTotal;
                order.OrderSubTotal = orderControl.ProductSubTotal;
                order.OrderTax      = orderControl.TaxTotal;
                order.OrderTotal    = orderControl.TotalPrice;

                if (order.IsPaid && orderControl.PaymentTypeID != null)
                {
                    order.PaymentTypeID = orderControl.PaymentTypeID;
                }
                else
                {
                    order.PaymentTypeID = GetNonePaymentTypeID();
                }

                te.AddToOrders(order);
                te.SaveChanges();
            }

            orderControl.BeginRemoveStoryboard();

            Storyboard saveCompleteSB = (Storyboard)FindResource("SaveCompleteStoryboard");

            saveCompleteSB.Begin();
        }
        private List<Customer> GetCustomers()
        {
            List<Customer> list = new List<Customer>();
            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = te.Customers;

                list = custs.ToList();
            }

            return list;
        }
示例#31
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (OrderStackPanel.Children.Count == 0)
            {
                return;
            }

            this.Cursor = Cursors.Wait;

            bool hasOrderBeenAdded = false;

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                Guid  partyID = Guid.NewGuid();
                Party p       = new Party();
                p.PartyID    = partyID;
                p.PartyDate  = Convert.ToDateTime(PartyDatePicker.Text);
                p.PartyTotal = partyTotal;

                foreach (UIElement ele in OrderStackPanel.Children)
                {
                    if (ele is OrderControl)
                    {
                        OrderControl oc = ele as OrderControl;

                        if (oc.CustomerID == Guid.Empty)
                        {
                            continue;
                        }

                        if (oc.ProductSubTotal == 0)
                        {
                            continue;
                        }

                        hasOrderBeenAdded = true;

                        Order order = new Order();
                        order.CustomerID    = oc.CustomerID;
                        order.IsPaid        = oc.IsPaid;
                        order.OrderDate     = p.PartyDate;
                        order.OrderID       = Guid.NewGuid();
                        order.OrderShipping = oc.ShippingTotal;
                        order.OrderSubTotal = oc.ProductSubTotal;
                        order.OrderTax      = oc.TaxTotal;
                        order.OrderTotal    = oc.TotalPrice;
                        order.PartyID       = p.PartyID;

                        if (order.IsPaid)
                        {
                            order.PaymentTypeID = oc.PaymentTypeID;
                        }
                        else
                        {
                            order.PaymentTypeID = GetNonePaymentTypeID();
                        }

                        te.AddToOrders(order);

                        //oc.BeginRemoveStoryboard();
                    }
                }

                if (hasOrderBeenAdded)
                {
                    te.AddToParties(p);
                    te.SaveChanges();
                }
            }

            this.Cursor = Cursors.Arrow;
        }
示例#32
0
        public void UpdateData()
        {
            DateTime now          = DateTime.Now;
            DateTime startOfMonth = new DateTime(now.Year, now.Month, 1);
            DateTime endOfMonth   = new DateTime(now.Year, now.Month, 1).AddMonths(1);
            DateTime startOfYear  = new DateTime(now.Year, 1, 1);
            DateTime endOfYear    = new DateTime(now.Year, 1, 1).AddYears(1);

            double ordersTotal     = 0;
            double commissionTotal = 0;

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var thisMonth = from c in te.Orders
                                where c.OrderDate >= startOfMonth &&
                                c.OrderDate < endOfMonth &&
                                c.IsPaid == true
                                group c by c.IsPaid into g
                                select new
                {
                    MonthlyTotal = g.Sum(t => t.OrderSubTotal)
                };

                if (thisMonth.Count() > 0)
                {
                    ordersTotal         = (thisMonth.First().MonthlyTotal.HasValue) ? thisMonth.First().MonthlyTotal.Value : 0;
                    commissionTotal     = Math.Round(ordersTotal * .25, 2);
                    ThisMonthTotal.Text = string.Format("{0:c}", commissionTotal);
                }
                else
                {
                    ThisMonthTotal.Text = string.Format("{0:c}", 0);
                }

                var thisYear = from c in te.Orders
                               where c.OrderDate >= startOfYear &&
                               c.OrderDate < endOfYear &&
                               c.IsPaid == true
                               group c by c.IsPaid into g
                               select new
                {
                    YearlyTotal = g.Sum(t => t.OrderSubTotal)
                };

                if (thisYear.Count() > 0)
                {
                    ordersTotal     = (thisYear.First().YearlyTotal.HasValue) ? thisYear.First().YearlyTotal.Value : 0;
                    commissionTotal = Math.Round(ordersTotal * .25, 2);

                    ThisYearTotal.Text = string.Format("{0:c}", commissionTotal);
                }
                else
                {
                    ThisYearTotal.Text = string.Format("{0:c}", 0);
                }

                var total = from c in te.Orders
                            where c.IsPaid == true
                            group c by c.IsPaid into g
                            select new
                {
                    TotalTotal = g.Sum(t => t.OrderSubTotal)
                };

                if (total.Count() > 0)
                {
                    ordersTotal     = (total.First().TotalTotal.HasValue) ? total.First().TotalTotal.Value : 0;
                    commissionTotal = Math.Round(ordersTotal * .25, 2);

                    Total.Text = string.Format("{0:c}", commissionTotal);
                }
                else
                {
                    Total.Text = string.Format("{0:c}", 0);
                }
            }
        }
示例#33
0
        public void UpdateData()
        {
            DateTime now          = DateTime.Now;
            DateTime startOfMonth = new DateTime(now.Year, now.Month, 1);
            DateTime endOfMonth   = new DateTime(now.Year, now.Month, 1).AddMonths(1);
            DateTime startOfYear  = new DateTime(now.Year, 1, 1);
            DateTime endOfYear    = new DateTime(now.Year, 1, 1).AddYears(1);

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var thisMonth = from c in te.Orders
                                where c.OrderDate >= startOfMonth &&
                                c.OrderDate < endOfMonth &&
                                c.IsPaid == true
                                group c by c.IsPaid into g
                                select new
                {
                    MonthlyTotal = g.Sum(t => t.OrderSubTotal)
                };

                if (thisMonth.Count() != 0)
                {
                    ThisMonthTotal.Text = string.Format("{0:c}", thisMonth.First().MonthlyTotal);
                }
                else
                {
                    ThisMonthTotal.Text = string.Format("{0:c}", 0);
                }

                var thisYear = from c in te.Orders
                               where c.OrderDate >= startOfYear &&
                               c.OrderDate < endOfYear &&
                               c.IsPaid == true
                               group c by c.IsPaid into g
                               select new
                {
                    YearlyTotal = g.Sum(t => t.OrderSubTotal)
                };

                if (thisYear.Count() != 0)
                {
                    ThisYearTotal.Text = string.Format("{0:c}", thisYear.First().YearlyTotal);
                }
                else
                {
                    ThisYearTotal.Text = string.Format("{0:c}", 0);
                }

                var total = from c in te.Orders
                            where c.IsPaid == true
                            group c by c.IsPaid into g
                            select new
                {
                    TotalTotal = g.Sum(t => t.OrderSubTotal)
                };
                if (total.Count() != 0)
                {
                    Total.Text = string.Format("{0:c}", total.First().TotalTotal);
                }
                else
                {
                    Total.Text = string.Format("{0:c}", 0);
                }
            }
        }
示例#34
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (OrderStackPanel.Children.Count == 0)
                return;

            this.Cursor = Cursors.Wait;

            bool hasOrderBeenAdded = false;

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                Guid partyID = Guid.NewGuid();
                Party p = new Party();
                p.PartyID = partyID;
                p.PartyDate = Convert.ToDateTime(PartyDatePicker.Text);
                p.PartyTotal = partyTotal;

                foreach (UIElement ele in OrderStackPanel.Children)
                {
                    if (ele is OrderControl)
                    {
                        OrderControl oc = ele as OrderControl;

                        if (oc.CustomerID == Guid.Empty)
                            continue;

                        if (oc.ProductSubTotal == 0)
                            continue;

                        hasOrderBeenAdded = true;

                        Order order = new Order();
                        order.CustomerID = oc.CustomerID;
                        order.IsPaid = oc.IsPaid;
                        order.OrderDate = p.PartyDate;
                        order.OrderID = Guid.NewGuid();
                        order.OrderShipping = oc.ShippingTotal;
                        order.OrderSubTotal = oc.ProductSubTotal;
                        order.OrderTax = oc.TaxTotal;
                        order.OrderTotal = oc.TotalPrice;
                        order.PartyID = p.PartyID;

                        if (order.IsPaid)
                            order.PaymentTypeID = oc.PaymentTypeID;
                        else
                            order.PaymentTypeID = GetNonePaymentTypeID();

                        te.AddToOrders(order);

                        //oc.BeginRemoveStoryboard();
                    }
                }

                if (hasOrderBeenAdded)
                {
                    te.AddToParties(p);
                    te.SaveChanges();
                }
            }

            this.Cursor = Cursors.Arrow;
        }
示例#35
0
 private void CreatePaymentTypesTable()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "CREATE TABLE [PaymentTypes] ([PaymentType] nvarchar(100) NULL, [PaymentTypeID] uniqueidentifier NOT NULL  ROWGUIDCOL);";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#36
0
        private List<DateTime> GetOrderDates()
        {
            List<DateTime> list = new List<DateTime>();

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var custs = from c in te.Orders
                            where c.PartyID == null
                            orderby c.OrderDate descending
                            select c.OrderDate;

                list = custs.Distinct().ToList();
            }

            return list;
        }
示例#37
0
 private void CreatePaymentTypeData()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'None','c0a5d459-00b2-4ca1-a436-3a57744551e4');";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'Cash','8c2229c7-46d6-4dd7-b70f-fd53ae5bfbcc');";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'Check','4598225c-1175-46d1-8f62-dbdb2a859c3d');";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "INSERT INTO [PaymentTypes] ([PaymentType],[PaymentTypeID]) VALUES (N'Debit/Credit','8a7c971e-091b-4e4e-9255-2cfafb9f405f');";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
示例#38
0
 private void CreateTableContraints()
 {
     using (ThirtyOneEntities te = new ThirtyOneEntities())
     {
         string script = "ALTER TABLE [Customers] ADD CONSTRAINT [PK_Customers] PRIMARY KEY ([CustomerID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Orders] ADD CONSTRAINT [PK__Orders__00000000000000BB] PRIMARY KEY ([OrderID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Parties] ADD CONSTRAINT [PK_Parties] PRIMARY KEY ([PartyID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [PaymentTypes] ADD CONSTRAINT [PK__PaymentTypes__00000000000000DE] PRIMARY KEY ([PaymentTypeID]);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__Customers__0000000000000115] ON [Customers] ([CustomerID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__Orders__00000000000000A9] ON [Orders] ([OrderID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__Parties__000000000000012B] ON [Parties] ([PartyID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "CREATE UNIQUE INDEX [UQ__PaymentTypes__00000000000000D6] ON [PaymentTypes] ([PaymentTypeID] ASC);";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Orders] ADD CONSTRAINT [CustomerOrders] FOREIGN KEY ([CustomerID]) REFERENCES [Customers]([CustomerID]) ON DELETE NO ACTION ON UPDATE NO ACTION;";
         te.ExecuteStoreCommand(script, new object[] { });
         script = "ALTER TABLE [Orders] ADD CONSTRAINT [PaymentTypeOrders] FOREIGN KEY ([PaymentTypeID]) REFERENCES [PaymentTypes]([PaymentTypeID]) ON DELETE NO ACTION ON UPDATE NO ACTION;";
         te.ExecuteStoreCommand(script, new object[] { });
     }
 }
        public void UpdateData()
        {
            DateTime now = DateTime.Now;
            DateTime startOfMonth = new DateTime(now.Year, now.Month, 1);
            DateTime endOfMonth = new DateTime(now.Year, now.Month, 1).AddMonths(1);
            DateTime startOfYear = new DateTime(now.Year, 1, 1);
            DateTime endOfYear = new DateTime(now.Year, 1, 1).AddYears(1);

            double ordersTotal = 0;
            double commissionTotal = 0;

            using (ThirtyOneEntities te = new ThirtyOneEntities())
            {
                var thisMonth = from c in te.Orders
                                where c.OrderDate >= startOfMonth
                                && c.OrderDate < endOfMonth
                                && c.IsPaid == true
                                group c by c.IsPaid into g
                                select new
                                {
                                    MonthlyTotal = g.Sum(t => t.OrderSubTotal)
                                };

                if (thisMonth.Count() > 0)
                {
                    ordersTotal = (thisMonth.First().MonthlyTotal.HasValue) ? thisMonth.First().MonthlyTotal.Value : 0;
                    commissionTotal = Math.Round(ordersTotal * .25, 2);
                    ThisMonthTotal.Text = string.Format("{0:c}", commissionTotal);
                }
                else
                {
                    ThisMonthTotal.Text = string.Format("{0:c}", 0);
                }

                var thisYear = from c in te.Orders
                               where c.OrderDate >= startOfYear
                               && c.OrderDate < endOfYear
                               && c.IsPaid == true
                               group c by c.IsPaid into g
                               select new
                               {
                                   YearlyTotal = g.Sum(t => t.OrderSubTotal)
                               };

                if (thisYear.Count() > 0)
                {
                    ordersTotal = (thisYear.First().YearlyTotal.HasValue) ? thisYear.First().YearlyTotal.Value : 0;
                    commissionTotal = Math.Round(ordersTotal * .25, 2);

                    ThisYearTotal.Text = string.Format("{0:c}", commissionTotal);
                }
                else
                {
                    ThisYearTotal.Text = string.Format("{0:c}", 0);
                }

                var total = from c in te.Orders
                            where c.IsPaid == true
                            group c by c.IsPaid into g
                            select new
                            {
                                TotalTotal = g.Sum(t => t.OrderSubTotal)
                            };

                if (total.Count() > 0)
                {
                    ordersTotal = (total.First().TotalTotal.HasValue) ? total.First().TotalTotal.Value : 0;
                    commissionTotal = Math.Round(ordersTotal * .25, 2);

                    Total.Text = string.Format("{0:c}", commissionTotal);
                }
                else
                {
                    Total.Text = string.Format("{0:c}", 0);
                }
            }
        }
示例#40
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            using (ThirtyOneEntities toe = new ThirtyOneEntities())
            {
                Guid orderID = (PartyDataGrid.SelectedItem as Order).OrderID;
                Order order = toe.Orders.Single(t => t.OrderID == orderID);

                order.IsPaid = IsPaidCheckBox.IsChecked.Value;

                if (PaymentTypeComboBox.SelectedItem != null)
                    order.PaymentTypeID = (PaymentTypeComboBox.SelectedItem as PaymentType).PaymentTypeID;
                else
                    order.PaymentTypeID = GetNonePaymentTypeID();

                toe.SaveChanges();
            }

            PartyDataGrid.SelectedIndex = -1;
            CustomerNameTextBlock.Text = string.Empty;
            OrderTotalTextBlock.Text = string.Empty;
            IsPaidCheckBox.IsChecked = false;
            PaymentTypeComboBox.SelectedIndex = -1;

            te.Dispose();
            te = new ThirtyOneEntities();

            Guid partyID = (PartyDateComboBox.SelectedItem as Party).PartyID;

            var orders = from t in te.Orders
                            where t.PartyID == partyID
                            select t;

            PartyDataGrid.ItemsSource = orders;
        }