private void ExecuteSave()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _newSale.RegistrationDate = _dt;
            _saleServ.AddSale(_newSale);
            int _saleID = _saleServ.GetLastSaleID();

            foreach (var item in _saleCategories)
            {
                SaleCategory _saleCategory = new SaleCategory
                {
                    CategoryID              = item.CategoryID,
                    Cost                    = item.Cost,
                    PriceAfterDiscount      = item.PriceAfterDiscount,
                    PriceTotalAfterDiscount = item.PriceTotalAfterDiscount,
                    CostTotal               = item.CostTotal,
                    Price                   = item.Price,
                    PriceTotal              = item.PriceTotal,
                    Discount                = item.Discount,
                    DiscountValue           = item.DiscountValue,
                    DiscountValueTotal      = item.DiscountValueTotal,
                    SaleID                  = _saleID,
                    Qty = item.Qty
                };
                _saleCategoryServ.AddSaleCategory(_saleCategory);

                Category cat = _categoryServ.GetCategory(item.CategoryID);
                cat.Qty = cat.Qty - item.Qty;
                _categoryServ.UpdateCategory(cat);
            }

            ClientAccount _account = new ClientAccount
            {
                ClientID         = _newSale.ClientID,
                Date             = _newSale.Date,
                RegistrationDate = _dt,
                Statement        = "فاتورة مبيعات رقم " + _saleID,
                Credit           = _newSale.Paid,
                Debit            = _newSale.PriceAfterDiscount + _newSale.TransportCost
            };

            _clientAccountServ.AddAccount(_account);

            if (_newSale.Paid > 0)
            {
                Safe _safe = new Safe
                {
                    Date             = _newSale.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مبيعات رقم " + _saleID + " للعميل: " + _selectedClient.Name,
                    Amount           = _newSale.Paid,
                    Source           = 4
                };
                _safeServ.AddSafe(_safe);
            }


            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]            = _saleID;
                ds.Sale[i]["Date"]          = _newSale.Date;
                ds.Sale[i]["Client"]        = _selectedClient.Name;
                ds.Sale[i]["Serial"]        = i + 1;
                ds.Sale[i]["Category"]      = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]           = item.Qty;
                ds.Sale[i]["Price"]         = Math.Round(Convert.ToDecimal(item.PriceAfterDiscount), 2);
                ds.Sale[i]["TotalPrice"]    = Math.Round(Convert.ToDecimal(item.PriceTotalAfterDiscount), 2);
                ds.Sale[i]["BillPrice"]     = Math.Round(Convert.ToDecimal(_newSale.PriceAfterDiscount), 2);;
                ds.Sale[i]["OldDebt"]       = Math.Abs(Convert.ToDecimal(_newSale.OldDebt));
                ds.Sale[i]["TransportCost"] = _newSale.TransportCost;
                ds.Sale[i]["BillTotal"]     = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.PriceTotal), 2));
                ds.Sale[i]["Paid"]          = _newSale.Paid;
                ds.Sale[i]["NewDebt"]       = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.NewDebt), 2));
                if (_newSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_newSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["Salesperson"] = _selectedSalesperson.Name;
                ds.Sale[i]["PrintingMan"] = _newSale.PrintingMan;

                if (_newSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_newSale.OldDebt < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                ds.Sale[i]["Address"] = _selectedClient.Address;
                try
                {
                    ToWord toWord = new ToWord(Math.Abs(Convert.ToDecimal(_newSale.NewDebt)), currencies[0]);
                    ds.Sale[i]["NewDebtAR"] = toWord.ConvertToArabic();
                }
                catch
                {
                    ds.Sale[i]["NewDebtAR"] = string.Empty;
                }
                i++;
            }
            ReportWindow rpt     = new ReportWindow();
            SaleReport   saleRPT = new SaleReport();

            saleRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = saleRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            NewSale         = new Sale();
            NewSaleCategory = new SaleCategoryVM();
            SaleCategories  = new ObservableCollection <SaleCategoryVM>();
            NewSale.Date    = DateTime.Now;
            OldPrices       = new ObservableCollection <SaleCategory>();
            _currentWindow.ShowDialog();
        }
Exemple #2
0
        private void ExecuteSave(string parameter)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                DateTime _dt = DateTime.Now;
                _newSale.RegistrationDate = _dt;
                _saleServ.AddSale(_newSale);
                int _saleID = _saleServ.GetLastSaleID();

                foreach (var item in _saleCategories)
                {
                    SaleCategory _saleCategory = new SaleCategory
                    {
                        CategoryID = item.CategoryID,
                        Cost       = item.Cost,
                        CostTotal  = item.CostTotal,
                        Price      = item.Price,
                        PriceTotal = item.PriceTotal,
                        SaleID     = _saleID,
                        Qty        = item.Qty
                    };
                    _saleCategoryServ.AddSaleCategory(_saleCategory);

                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    cat.Qty = cat.Qty - item.Qty;
                    _categoryServ.UpdateCategory(cat);
                }

                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _newSale.ClientID,
                    Date             = _newSale.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مبيعات رقم " + _saleID,
                    Credit           = _newSale.CashPaid + _newSale.DiscountPaid,
                    Debit            = _newSale.Price
                };
                _clientAccountServ.AddAccount(_account);

                if (_newSale.CashPaid > 0)
                {
                    Safe _safe = new Safe
                    {
                        Date             = _newSale.Date,
                        RegistrationDate = _dt,
                        Statement        = "فاتورة مبيعات رقم " + _saleID + " للعميل: " + _selectedClient.Name,
                        Amount           = _newSale.CashPaid,
                        Source           = 4
                    };
                    _safeServ.AddSafe(_safe);
                }

                DS ds = new DS();
                ds.Sale.Rows.Clear();
                int i = 0;
                foreach (var item in _saleCategories)
                {
                    ds.Sale.Rows.Add();
                    ds.Sale[i]["ID"]           = _saleID;
                    ds.Sale[i]["Date"]         = _newSale.Date;
                    ds.Sale[i]["Client"]       = _selectedClient.Name;
                    ds.Sale[i]["Serial"]       = i + 1;
                    ds.Sale[i]["Category"]     = item.Category + " " + item.Company;
                    ds.Sale[i]["Qty"]          = item.Qty;
                    ds.Sale[i]["Price"]        = Math.Round(Convert.ToDecimal(item.Price), 2);
                    ds.Sale[i]["TotalPrice"]   = Math.Round(Convert.ToDecimal(item.PriceTotal), 2);
                    ds.Sale[i]["BillPrice"]    = Math.Round(Convert.ToDecimal(_newSale.Price), 2);;
                    ds.Sale[i]["OldDebt"]      = Math.Abs(Convert.ToDecimal(_newSale.OldDebt));
                    ds.Sale[i]["BillTotal"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.PriceTotal), 2));
                    ds.Sale[i]["Paid"]         = _newSale.CashPaid;
                    ds.Sale[i]["DiscountPaid"] = _newSale.DiscountPaid;
                    ds.Sale[i]["NewDebt"]      = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.NewDebt), 2));
                    if (_newSale.NewDebt > 0)
                    {
                        ds.Sale[i]["Type"] = "له";
                    }
                    else if (_newSale.NewDebt < 0)
                    {
                        ds.Sale[i]["Type"] = "عليه";
                    }

                    if (_newSale.OldDebt > 0)
                    {
                        ds.Sale[i]["Type2"] = "له";
                    }
                    else if (_newSale.OldDebt < 0)
                    {
                        ds.Sale[i]["Type2"] = "عليه";
                    }

                    i++;
                }
                ReportWindow rpt = new ReportWindow();
                if (parameter == "Client")
                {
                    SaleReport saleRPT = new SaleReport();
                    saleRPT.SetDataSource(ds.Tables["Sale"]);
                    rpt.crv.ViewerCore.ReportSource = saleRPT;
                    Mouse.OverrideCursor            = null;
                }
                else
                {
                    SaleReport2 saleRPT = new SaleReport2();
                    saleRPT.SetDataSource(ds.Tables["Sale"]);
                    rpt.crv.ViewerCore.ReportSource = saleRPT;
                    Mouse.OverrideCursor            = null;
                }
                _currentWindow.Hide();
                rpt.ShowDialog();
                NewSale         = new Sale();
                NewSaleCategory = new SaleCategoryVM();
                SaleCategories  = new ObservableCollection <SaleCategoryVM>();
                NewSale.Date    = DateTime.Now;
                OldPrices       = new ObservableCollection <SaleCategory>();
                _currentWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }