private void scanInvoiceNo(string invoiceNo)
        {
            if (saveInvoiceStatus(invoiceNo) < 0)
            {
                return;
            }

            DataSource.Invoice findInvoice = invoiceSet.SingleOrDefault <DataSource.Invoice>(p => p.InvoiceNo == invoiceNo);

            if (findInvoice != null)
            {
                MessageBox.Show("Already Scanned [" + invoiceNo + "]");
                return;
            }

            DataSource.Invoice lInvoice = lDataContext.Invoices.SingleOrDefault(p => p.InvoiceNo == invoiceNo);


            if (lInvoice == null)
            {
                MessageBox.Show("Scan : Can not find Invoice No [" + invoiceNo + "]");
                return;
            }

            DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.InvoiceId == lInvoice.Id);

            invoiceSet.Add(new DataSource.Invoice
            {
                Id           = lInvoice.Id,
                InvoiceNo    = lInvoice.InvoiceNo,
                DeliveryDate = lInvoice.DeliveryDate,
                Description  = lOrder.Description,
                Status       = lInvoice.Status
            });
        }
        private void RadGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
        {
            SunSeven.Models.HSOrderHistory lOrderHistory = e.EditedItem as SunSeven.Models.HSOrderHistory;

            DataSource.Order lOrder = lDataContext.Orders.FirstOrDefault(p => p.Id == lOrderHistory.OrderId);

            if (lOrder != null)
            {
                try
                {
                    lOrder.EmpDeliveryId = lOrderHistory.DeliveryPersonId;
                    lOrder.EmployeeId    = lOrderHistory.SalesPersonId;

                    DataSource.Invoice lInvoice = lDataContext.Invoices.Single(p => p.Id == lOrder.InvoiceId);

                    if (lInvoice != null)
                    {
                        lInvoice.DeliveryDate  = lOrderHistory.DeliveryDate;
                        lInvoice.EmpDeliveryId = lOrderHistory.DeliveryPersonId;
                        lInvoice.Description   = lOrderHistory.Description;
                        lDataContext.SubmitChanges();
                    }

                    if (lOrder != null)
                    {
                        lOrder.Description = lOrderHistory.InternalComment;
                        lDataContext.SubmitChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 3
0
        private void OnPrintOrderCommandExecuted(object Order)
        {
            DataSource.Order lOrder = Order as DataSource.Order;

            HSOrder lhsOrder = new HSOrder();

            SunSeven.Reports.ReportViewer lRptViewer = new Reports.ReportViewer(lhsOrder, lhsOrder.OrderItems);

            Window lWindows = Models.CommonFunction.GetApplicationWindow();

            if (lWindows != null)
            {
                lRptViewer.Owner = lWindows;
            }

            lRptViewer.ShowDialog();


            //open print dialog
            //using (PrintDialog printDlg = new PrintDialog())
            //{
            //    printDlg.AllowSomePages = true;
            //    printDlg.AllowCurrentPage = false;
            //    printDlg.UseEXDialog = true;

            //    if (System.Windows.Forms.DialogResult.OK == printDlg.ShowDialog())
            //    {
            //        ReportProcessor reportProcessor1 = new ReportProcessor();
            //        reportProcessor1.PrintReport(new SunSeven.Reports.ReportModel.rptInvoice(this, this.OrderItems), printDlg.PrinterSettings);
            //    }
            //}



            //Direct to default
            //try
            //{
            //    ReportProcessor reportProcessor = new ReportProcessor();
            //    reportProcessor.PrintReport(new SunSeven.Reports.ReportModel.rptInvoice(this, this.OrderItems), new PrinterSettings());
            //}
            //catch(Exception e)
            //{
            //    MessageBox.Show(e.Message);
            //}
        }
        private void GridContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            RadContextMenu menu        = (RadContextMenu)sender;
            RadMenuItem    clickedItem = e.OriginalSource as RadMenuItem;
            GridViewRow    row         = menu.GetClickedElement <GridViewRow>();

            if (clickedItem != null && row != null)
            {
                string header = Convert.ToString(clickedItem.Header);

                switch (header)
                {
                case "Add":

                    break;

                case "Edit":

                    DataSource.Invoice lSelectedInvoice = row.Item as DataSource.Invoice;

                    if (lSelectedInvoice != null)
                    {
                        DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.InvoiceId == lSelectedInvoice.Id);

                        if (lOrder == null)
                        {
                            MessageBox.Show("Failed to find Order Id [" + lSelectedInvoice.Id + "]");
                            return;
                        }

                        scannedOrderCommand?.Invoke(lOrder.Id);
                    }

                    break;

                case "Delete":

                    break;

                default:
                    break;
                }
            }
        }
        void OnGridMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement originalSender = e.OriginalSource as FrameworkElement;

            if (originalSender != null)
            {
                DataSource.Invoice lSelectedInvoice = originalSender.DataContext as DataSource.Invoice;

                if (lSelectedInvoice != null)
                {
                    DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.InvoiceId == lSelectedInvoice.Id);

                    if (lOrder == null)
                    {
                        MessageBox.Show("Failed to find Order Id [" + lSelectedInvoice.Id + "]");
                        return;
                    }

                    scannedOrderCommand?.Invoke(lOrder.Id);
                }
            }
        }
        private void RadGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
        {
            DataSource.Invoice gridInvoice = e.NewData as DataSource.Invoice;

            DataSource.Order   orgOrder   = lDataContext.Orders.Single(p => p.InvoiceId == gridInvoice.Id);
            DataSource.Invoice orgInvoice = lDataContext.Invoices.Single(p => p.Id == gridInvoice.Id);

            if (orgOrder != null)
            {
                orgOrder.Description = gridInvoice.Description;
                orgInvoice.Status    = gridInvoice.Status;

                try
                {
                    lDataContext.SubmitChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 7
0
        //public static void AddPriceHistory(HSOrderItem lOrderItems)
        //{
        //    JSDataContext lDataContext = new CommonFunction().JSDataContext();

        //    DataSource.PriceHistory lPriceHist = new PriceHistory();


        //    var lOrderHist = lDataContext.PriceHistories.SingleOrDefault(p => p.OrderId == lOrderItems.OrderId
        //            && p.ProductId == lOrderItems.ProductId && p.SellingUnitId == lOrderItems.SellingUnitId);

        //    lPriceHist.OrderId = lOrderItems.OrderId;
        //    lPriceHist.CustomerId = lOrderItems.CustomerId;
        //    lPriceHist.VatRate = lOrderItems.SelectedVat.Rate;
        //    lPriceHist.ProductId = lOrderItems.ProductId;
        //    lPriceHist.SellingUnitId = lOrderItems.SellingUnitId;
        //    lPriceHist.UnitPrice = lOrderItems.UnitPrice;

        //    if (lOrderHist == null)
        //    {
        //        lDataContext.PriceHistories.InsertOnSubmit(lPriceHist);
        //    }

        //    lDataContext.SubmitChanges();


        //}


        public static HSOrder PrintOrder(int?orderId)
        {
            if (orderId == null)
            {
                MessageBox.Show("Not Found Selected Order");
                return(null);
            }

            JSDataContext lDataContext = new CommonFunction().JSDataContext();

            HSOrder   lEditOrder = new HSOrder();
            HSInvoice lInvoice   = new HSInvoice();

            DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.Id == orderId);

            DataSource.vEmpDept lEmpDelivery = new DataSource.vEmpDept();


            //lEmpDelivery.Person = lOrder.Employee1.Person.LastName + "," + lOrder.Employee1.Person.FirstName;

            if (lOrder.Invoice.Employee != null)
            {
                lEmpDelivery.Person = lOrder.Invoice.Employee.Person.LastName + "," + lOrder.Invoice.Employee.Person.FirstName;
            }

            if (lOrder != null)
            {
                lEditOrder.Id                = lOrder.Id;
                lEditOrder.CustomerId        = lOrder.CustomerId;
                lEditOrder.SelectedCustomer  = lOrder.Customer;
                lEditOrder.SelectedDeliverer = lEmpDelivery;
                lEditOrder.OrderDate         = lOrder.OrderDate;
                lEditOrder.SellerId          = lOrder.EmployeeId;


                if (lOrder.Invoice != null)
                {
                    lInvoice.Id            = lOrder.Invoice.Id;
                    lInvoice.InvoiceNo     = lOrder.Invoice.InvoiceNo;
                    lInvoice.InvoiceDate   = lOrder.Invoice.InvoiceDate;
                    lInvoice.DeliveryDate  = lOrder.Invoice.DeliveryDate;
                    lEditOrder.DelivererId = lOrder.Invoice.EmpDeliveryId;
                    lInvoice.Description   = lOrder.Invoice.Description;
                    lEditOrder.Invoice     = lInvoice;
                }


                foreach (DataSource.OrderItem l in lOrder.OrderItems)
                {
                    lEditOrder.OrderItems.Add(new HSOrderItem
                    {
                        Id                  = l.Id,
                        CustomerId          = lOrder.CustomerId,
                        OrderId             = l.OrderId,
                        SalesStatusId       = l.SalesStatusId,
                        ProductId           = l.ProductId,
                        SelectedProduct     = l.Product,
                        UnitPrice           = l.UnitPrice,
                        VatId               = l.VatId,
                        VAT                 = l.VatRate.Name,
                        SelectedVat         = l.VatRate,
                        Quantity            = l.Quantity,
                        SellingUnitId       = l.SellingUnitId,
                        Unit                = l.SellingUnit.Unit,
                        SelectedSellingUnit = l.SellingUnit,
                        ProductName         = l.Product.Name,
                        ProductDescription  = l.Product.Description,
                        Description         = l.Description
                    });
                }
            }

            return(lEditOrder);
        }
Esempio n. 8
0
        private Boolean SavingEnded()
        {
            //System.Threading.Thread.Sleep(2000);


            DataSource.Invoice lInvoice = lDataContext.Invoices.SingleOrDefault(p => p.Id == this.Invoice.Id);


            if (lInvoice == null)
            {
                this.Invoice.InvoiceNo = GetInvoiceNo();

                DataSource.Invoice newInvoice = new DataSource.Invoice
                {
                    CustomerId    = this.CustomerId,
                    InvoiceNo     = this.Invoice.InvoiceNo,
                    InvoiceDate   = this.Invoice.InvoiceDate,
                    DeliveryDate  = this.Invoice.DeliveryDate,
                    Description   = this.Invoice.Description,
                    Status        = this.Invoice.InvoiceStatusId,
                    EmpDeliveryId = this.DelivererId
                };

                lDataContext.Invoices.InsertOnSubmit(newInvoice);

                try
                {
                    lDataContext.SubmitChanges();

                    this.Invoice.Id = newInvoice.Id;
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2627)
                    {
                        MessageBox.Show("Cannot insert duplicate Invoice No [" + this.Invoice.InvoiceNo + "] Please save again.");
                    }
                    else
                    {
                        MessageBox.Show("SqlException : " + ex.Message);
                    }

                    ChangeSet pendingChanges = lDataContext.GetChangeSet();

                    foreach (object obj in pendingChanges.Inserts)
                    {
                        var tableToDeleteFrom = lDataContext.GetTable(obj.GetType());
                        //(tableToDeleteFrom as DataSource.Invoice).InvoiceNo = GetInvoiceNo();

                        //lDataContext.SubmitChanges();

                        //this.Invoice.Id = newInvoice.Id;

                        tableToDeleteFrom.DeleteOnSubmit(obj);
                    }

                    return(false);
                }
                catch (Exception ex)
                {
                    this.Message = "Faled to Save - Invoice Detail";
                    return(false);
                }
            }
            else
            {
                lInvoice.CustomerId    = this.CustomerId;
                lInvoice.InvoiceNo     = this.Invoice.InvoiceNo;
                lInvoice.InvoiceDate   = this.Invoice.InvoiceDate;
                lInvoice.DeliveryDate  = this.Invoice.DeliveryDate;
                lInvoice.Description   = this.Invoice.Description;
                lInvoice.EmpDeliveryId = this.DelivererId;
                lInvoice.Status        = this.Invoice.InvoiceStatusId;
                try
                {
                    lDataContext.SubmitChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.Message = "Faled to Update - Invoice Detail";
                    return(false);
                }
            }


            DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.Id == this.Id);

            if (lOrder == null)
            {
                DataSource.Order lnewOrder = new DataSource.Order
                {
                    CustomerId    = this.CustomerId,
                    OrderDate     = this.OrderDate.Value,
                    InvoiceId     = (this.Invoice == null) ? null : this.Invoice.Id,
                    EmpDeliveryId = this.DelivererId,
                    EmployeeId    = this.SellerId,
                    RequiredDate  = DateTime.Now,
                    ShippedDate   = DateTime.Now,
                    Description   = this.Description
                };


                lDataContext.Orders.InsertOnSubmit(lnewOrder);

                try
                {
                    lDataContext.SubmitChanges();
                    this.Id = lnewOrder.Id;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.Message = "Faled to Save - Order Detail";
                    return(false);
                }
            }
            else
            {
                lOrder.CustomerId    = this.CustomerId;
                lOrder.OrderDate     = this.OrderDate.Value;
                lOrder.InvoiceId     = this.Invoice.Id;
                lOrder.EmpDeliveryId = this.DelivererId;
                lOrder.EmployeeId    = this.SellerId;
                lOrder.RequiredDate  = DateTime.Now;
                lOrder.ShippedDate   = DateTime.Now;
                lOrder.Description   = this.Description;

                try
                {
                    lDataContext.SubmitChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.Message = "Faled to Update - Order Detail";
                    return(false);
                }
            }


            foreach (HSSupplyItem l in this.SupplyItems)
            {
                if (l.Id == -1 || l.Id == null)
                {
                    DataSource.OrderItem lDSOrderItem = new OrderItem();

                    lDSOrderItem.OrderId       = this.Id.Value;
                    lDSOrderItem.SalesStatusId = l.SalesStatusId;
                    lDSOrderItem.ProductId     = l.ProductId;
                    lDSOrderItem.VatId         = l.VatId;
                    lDSOrderItem.UnitPrice     = l.UnitPrice;
                    lDSOrderItem.Quantity      = l.Quantity;
                    lDSOrderItem.SellingUnitId = (l.SellingUnitId == null) ? 0 : l.SellingUnitId;
                    lDSOrderItem.Description   = l.Description;
                    lDataContext.OrderItems.InsertOnSubmit(lDSOrderItem);

                    try
                    {
                        lDataContext.SubmitChanges();
                        l.Id = lDSOrderItem.Id;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        this.Message = "Faled to Save - OrderItem Detail";
                        return(false);
                    }
                }
                else
                {
                    DataSource.OrderItem lItem = lDataContext.OrderItems.SingleOrDefault(p => p.Id == l.Id);

                    lItem.OrderId       = this.Id.Value;
                    lItem.SalesStatusId = l.SalesStatusId;
                    lItem.ProductId     = l.ProductId;
                    lItem.VatId         = l.VatId;
                    lItem.UnitPrice     = l.UnitPrice;
                    lItem.Quantity      = l.Quantity;
                    lItem.SellingUnitId = (l.SellingUnitId == null) ? 0 : l.SellingUnitId;
                    lItem.Description   = l.Description;

                    try
                    {
                        lDataContext.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        this.Message = "Faled to Update - OrderItem Detail";
                        return(false);
                    }
                }
            }

            this.Message = "Saved Successfully...";

            return(false);
        }
        public OrderEditor(int?OrderId)
        {
            InitializeComponent();


            MainPage.CloseCommand -= MainPage_CloseCommand;
            MainPage.CloseCommand += MainPage_CloseCommand;


            this.comboStatus.IsEnabled   = true;
            this.comboCustomer.IsEnabled = true;

            if (MainPage.lCurrentUser.UserRole.Name == "Read Only")
            {
                this.comboStatus.IsEnabled   = false;
                this.comboCustomer.IsEnabled = false;
            }


            JSDataContext lDataContext = new CommonFunction().JSDataContext();

            HSOrder   lEditOrder = new HSOrder();
            HSInvoice lInvoice   = new HSInvoice();

            //comboDelivery.ItemsSource = new ViewModels.vmEmployee().DeliveryPerson;

            DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.Id == OrderId);

            if (lOrder != null)
            {
                lEditOrder.Id               = lOrder.Id;
                lEditOrder.CustomerId       = lOrder.CustomerId;
                lEditOrder.SelectedCustomer = lOrder.Customer;
                lEditOrder.OrderDate        = lOrder.OrderDate;
                lEditOrder.SellerId         = lOrder.EmployeeId;

                lEditOrder.Description = lOrder.Description;


                if (lOrder.Invoice != null)
                {
                    lInvoice.Id              = lOrder.Invoice.Id;
                    lInvoice.InvoiceNo       = lOrder.Invoice.InvoiceNo;
                    lInvoice.InvoiceDate     = lOrder.Invoice.InvoiceDate;
                    lInvoice.DeliveryDate    = lOrder.Invoice.DeliveryDate;
                    lEditOrder.DelivererId   = lOrder.Invoice.EmpDeliveryId;
                    lInvoice.Description     = lOrder.Invoice.Description;
                    lEditOrder.Invoice       = lInvoice;
                    lInvoice.InvoiceStatusId = lOrder.Invoice.Status;
                }

                lEditOrder.DeleteEnabled = true;
                if (MainPage.lCurrentUser.UserRole.Name == "Read Only")
                {
                    lEditOrder.DeleteEnabled = false;
                }


                foreach (DataSource.OrderItem l in lOrder.OrderItems)
                {
                    lEditOrder.OrderItems.Add(new HSOrderItem
                    {
                        Id                  = l.Id,
                        CustomerId          = lOrder.CustomerId,
                        OrderId             = l.OrderId,
                        SalesStatusId       = l.SalesStatusId,
                        ProductId           = l.ProductId,
                        SelectedProduct     = l.Product,
                        UnitPrice           = l.UnitPrice,
                        VatId               = l.VatId,
                        SelectedVat         = l.VatRate,
                        Quantity            = l.Quantity,
                        SellingUnitId       = l.SellingUnitId,
                        SelectedSellingUnit = l.SellingUnit,
                        ProductName         = l.Product.Name,
                        ProductDescription  = l.Product.Description,
                        VAT                 = l.VatRate.Name,
                        Unit                = l.SellingUnit.Unit,
                        Description         = l.Description
                    });
                }

                this.DataContext = lEditOrder;


                ObservableCollection <DataSource.vEmpDept> DeliveryPerson = new ObservableCollection <vEmpDept>();
                ObservableCollection <DataSource.vEmpDept> SalesPerson    = new ObservableCollection <vEmpDept>();

                foreach (var l in lDataContext.EmployeeAtWork(lOrder.Invoice.EmpDeliveryId, "Delivery"))
                {
                    DeliveryPerson.Add(new vEmpDept {
                        Id = l.Id, FirstName = l.FirstName, LastName = l.LastName, Person = l.Person, Department = l.Department
                    });
                }

                foreach (var l in lDataContext.EmployeeAtWork(lOrder.EmployeeId, "Sales"))
                {
                    SalesPerson.Add(new vEmpDept {
                        Id = l.Id, FirstName = l.FirstName, LastName = l.LastName, Person = l.Person, Department = l.Department
                    });
                }

                comboDelivery.ItemsSource = DeliveryPerson;
                comboEmployee.ItemsSource = SalesPerson;
            }
        }