private void EditMethod()
 {
     SaleOfferUpdateViewModel.ID = _selectedSaleOffer.ID;
     _currentWindow.Hide();
     new SaleOfferUpdateWindow().ShowDialog();
     Load();
     _currentWindow.ShowDialog();
 }
Esempio n. 2
0
 private void ConvertMethod()
 {
     SupplyOfferConvertViewModel.ID = _selectedSupplyOffer.ID;
     _currentWindow.Hide();
     new SupplyOfferConvertWindow().ShowDialog();
     Load();
     _currentWindow.ShowDialog();
 }
Esempio n. 3
0
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (email_txt.Text == "")
            {
                email_txt.BorderBrush = Brushes.Red;
            }
            else
            {
                email_txt.BorderBrush = Brushes.LightGray;  //不是預設值
            }
            if (password_txt.Password == "")
            {
                password_txt.BorderBrush = Brushes.Red;
            }
            else
            {
                password_txt.BorderBrush = Brushes.LightGray;
            }

            var mySettings = new MetroDialogSettings()
            {
                AnimateShow = true,
                AnimateHide = true
            };

            var controller = await window.ShowProgressAsync("Please wait...", "Authenticating User", settings : mySettings);

            controller.SetIndeterminate();

            var result = dbContext.Members.AsEnumerable().FirstOrDefault(x =>
                                                                         x.Member_Account == email_txt.Text && x.Member_Password == password_txt.Password);

            await Task.Delay(2200);

            await controller.CloseAsync();

            if (result != null)
            {
                MessageBox.Show("登入成功");
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                window.Hide();
            }
            else
            {
                ErrorMessage.Content = "* 帳號或密碼不正確";
                password_txt.Clear();
            }
        }
 private void ShowDetialsMethod()
 {
     SupplyShowViewModel.ID = _selectedSupplyFuture.SupplyID;
     _currentWindow.Hide();
     new SupplyShowWindow().ShowDialog();
     _currentWindow.ShowDialog();
 }
Esempio n. 5
0
        private void PrintMethod()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DS ds = new DS();

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

            foreach (var item in _supplyOfferCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["Client"]     = _selectedSupplyOffer.Client.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.CostAfterTax), 2);
                ds.Sale[i]["TotalPrice"] = Math.Round(Convert.ToDecimal(item.CostTotalAfterTax), 2);
                ds.Sale[i]["BillPrice"]  = Math.Round(Convert.ToDecimal(_selectedSupplyOffer.CostAfterTax), 2);
                i++;
            }
            ReportWindow      rpt            = new ReportWindow();
            SupplyOfferReport supplyOfferRPT = new SupplyOfferReport();

            supplyOfferRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = supplyOfferRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            _currentWindow.ShowDialog();
        }
        private void ExecuteSave()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _saleOfferServ.AddSaleOffer(_newSaleOffer);
            int _saleOfferID = _saleOfferServ.GetLastSaleOfferID();

            foreach (var item in _saleOfferCategories)
            {
                SaleOfferCategory _saleOfferCategory = new SaleOfferCategory
                {
                    CategoryID              = item.CategoryID,
                    PriceAfterDiscount      = item.PriceAfterDiscount,
                    PriceTotalAfterDiscount = item.PriceTotalAfterDiscount,
                    Price              = item.Price,
                    PriceTotal         = item.PriceTotal,
                    Discount           = item.Discount,
                    DiscountValue      = item.DiscountValue,
                    DiscountValueTotal = item.DiscountValueTotal,
                    SaleOfferID        = _saleOfferID,
                    Qty = item.Qty
                };
                _saleOfferCategoryServ.AddSaleOfferCategory(_saleOfferCategory);
            }

            DS ds = new DS();

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

            foreach (var item in _saleOfferCategories)
            {
                ds.Sale.Rows.Add();
                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(_newSaleOffer.PriceAfterDiscount), 2);;
                i++;
            }
            ReportWindow    rpt          = new ReportWindow();
            SaleOfferReport saleOfferRPT = new SaleOfferReport();

            saleOfferRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = saleOfferRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            NewSaleOffer         = new SaleOffer();
            NewSaleOfferCategory = new SaleOfferCategoryVM();
            SaleOfferCategories  = new ObservableCollection <SaleOfferCategoryVM>();
            NewSaleOffer.Date    = DateTime.Now;
            OldPrices            = new ObservableCollection <SaleCategory>();
            _currentWindow.ShowDialog();
        }
        private void ExecuteSaveAsync()
        {
            Mouse.OverrideCursor        = Cursors.Wait;
            _selectedSupplyOffer.Client = _selectedClient;
            _supplyOfferServ.UpdateSupplyOffer(_selectedSupplyOffer);
            _supplyOfferCategoryServ.DeleteSupplyOfferCategories(ID);

            foreach (var item in _supplyOfferCategories)
            {
                SupplyOfferCategory _supplyOfferCategory = new SupplyOfferCategory
                {
                    CategoryID             = item.CategoryID,
                    Cost                   = item.Cost,
                    CostAfterDiscount      = item.CostAfterDiscount,
                    CostAfterTax           = item.CostAfterTax,
                    CostTotal              = item.CostTotal,
                    CostTotalAfterDiscount = item.CostTotalAfterDiscount,
                    CostTotalAfterTax      = item.CostTotalAfterTax,
                    Discount               = item.Discount,
                    DiscountValue          = item.DiscountValue,
                    DiscountValueTotal     = item.DiscountValueTotal,
                    SupplyOfferID          = ID,
                    Qty           = item.Qty,
                    Tax           = item.Tax,
                    TaxValue      = item.TaxValue,
                    TaxValueTotal = item.TaxValueTotal
                };
                _supplyOfferCategoryServ.AddSupplyOfferCategory(_supplyOfferCategory);
            }

            DS ds = new DS();

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

            foreach (var item in _supplyOfferCategories)
            {
                ds.Sale.Rows.Add();
                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.CostAfterTax), 2);
                ds.Sale[i]["TotalPrice"] = Math.Round(Convert.ToDecimal(item.CostTotalAfterTax), 2);
                ds.Sale[i]["BillPrice"]  = Math.Round(Convert.ToDecimal(_selectedSupplyOffer.CostAfterTax), 2);
                i++;
            }
            ReportWindow      rpt            = new ReportWindow();
            SupplyOfferReport supplyOfferRPT = new SupplyOfferReport();

            supplyOfferRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = supplyOfferRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            _currentWindow.Close();
        }
Esempio n. 8
0
        private async void EditMethod()
        {
            if (_saleServ.IsExistInRecalls(_selectedSale.ID) || !_saleServ.IsLastSale(_selectedSale.ID))
            {
                await _currentWindow.ShowMessageAsync("فشل التعديل", "لا يمكن تعديل هذه الفاتورة", MessageDialogStyle.Affirmative, new MetroDialogSettings()
                {
                    AffirmativeButtonText = "موافق",
                    DialogMessageFontSize = 25,
                    DialogTitleFontSize   = 30
                });

                return;
            }

            SaleUpdateViewModel.ID = _selectedSale.ID;
            _currentWindow.Hide();
            new SaleUpdateWindow().ShowDialog();
            Load();
            _currentWindow.ShowDialog();
        }
Esempio n. 9
0
        protected override void OnViewAttached(object view, object context)
        {
            base.OnViewAttached(view, context);

            _window = view as MainView;

            if (_window == null)
            {
                return;
            }

            //_window.Flyouts.FindChild<FlyoutsControl>("LogFlyouts")

            _window.StateChanged += (sender, args) =>
            {
                if (_window.WindowState == WindowState.Minimized && Settings.Default.MinimizeToTray)
                {
                    // Hide the window if minimized so it doesn't show up on the task bar
                    _window.Hide();
                }
            };

            _window.Closing += (sender, args) =>
            {
                if (Application.Current.ShutdownMode == ShutdownMode.OnExplicitShutdown)
                {
                    return;
                }

                // Cancel close and minimize if setting is set to minimize on close
                if (Settings.Default.MinimizeOnClose)
                {
                    args.Cancel         = true;
                    _window.WindowState = WindowState.Minimized;
                }
            };

            _window.Activated   += (sender, args) => IsDeactivated = false;
            _window.Deactivated += (sender, args) => IsDeactivated = true;

            // Minimize if set to
            if (Settings.Default.StartMinimized)
            {
                bool initialWindowActivate = true;
                _window.Activated += (sender, args) =>
                {
                    if (initialWindowActivate)
                    {
                        initialWindowActivate = false;
                        _window.WindowState   = WindowState.Minimized;
                    }
                };
            }
        }
 private void ShowBillsCategoriesMethod()
 {
     try
     {
         currentWindow.Hide();
         BillsCategoriesViewModel.ShiftID = _selectedShift.Shift.ID;
         new BillsCategoriesWindow().ShowDialog();
         currentWindow.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 private void ShowMethod()
 {
     try
     {
         BillShowViewModel.BillID = _selectedBill.Bill.ID;
         currentWindow.Hide();
         new BillShowWindow().ShowDialog();
         Load();
         currentWindow.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 private void ShowBillsCategoriesMethod()
 {
     try
     {
         using (var unitOfWork = new UnitOfWork(new GeneralDBContext()))
         {
             currentWindow.Hide();
             BillsCategoriesViewModel.ShiftID = unitOfWork.Shifts.FirstOrDefault(d => d.EndDate == null).ID;
             new BillsCategoriesWindow().ShowDialog();
             currentWindow.ShowDialog();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Esempio n. 13
0
        private void Sign(User user, MetroWindow window)
        {
            ClientServer client = new ClientServer(user?.UserConfig?.SavedCredential);

            if (user?.UserConfig?.SavedCredential != null)
            {
                var indicator = new IndicatorWindow();
                window.Hide();
                indicator.Show();
                if (client.CheckIsLogined())
                {
                    ClientServer.AuthenticationMounted = user?.UserConfig?.SavedCredential;
                    new MainWindow().Show();
                    indicator.Close();
                    window.Close();
                }
            }
        }
        public async void NavigateToViewMethodAsync(string destination)
        {
            try
            {
                switch (destination)
                {
                case "Backup":
                    BackupModel = new BackupDataModel();
                    backupDialog.DataContext = this;
                    await currentWindow.ShowMetroDialogAsync(backupDialog);

                    break;

                case "BackupRestore":
                    RestoreBackupModel = new RestoreBackupDataModel();
                    restoreBackupDialog.DataContext = this;
                    await currentWindow.ShowMetroDialogAsync(restoreBackupDialog);

                    break;

                case "User":
                    currentWindow.Hide();
                    new UserWindow().ShowDialog();
                    currentWindow.Show();
                    break;

                case "Shifts":
                    currentWindow.Hide();
                    new ShiftWindow().ShowDialog();
                    currentWindow.Show();
                    break;

                case "SignOut":
                    LoginModel = new LoginDataModel();
                    loginDialog.DataContext = this;
                    await currentWindow.ShowMetroDialogAsync(loginDialog);

                    break;


                case "Item":
                    currentWindow.Hide();
                    new ItemWindow().ShowDialog();
                    currentWindow.Show();
                    break;

                case "Cashier":
                    currentWindow.Hide();
                    new BillItemsWindow().ShowDialog();
                    currentWindow.Show();
                    if (IsSignOut)
                    {
                        LoginModel = new LoginDataModel();
                        loginDialog.DataContext = this;
                        await currentWindow.ShowMetroDialogAsync(loginDialog);
                    }
                    break;

                case "Bill":
                    currentWindow.Hide();
                    new BillWindow().ShowDialog();
                    currentWindow.Show();
                    break;

                case "Spending":
                    currentWindow.Hide();
                    new SpendingWindow().ShowDialog();
                    currentWindow.Show();
                    break;

                case "Safe":
                    currentWindow.Hide();
                    new SafeWindow().ShowDialog();
                    currentWindow.Show();
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void PrintMethod()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DS ds = new DS();

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

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]            = ID;
                ds.Sale[i]["Date"]          = _selectedSale.Date;
                ds.Sale[i]["Client"]        = _selectedSale.Client.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"]     = _selectedSale.PriceAfterDiscount;
                ds.Sale[i]["OldDebt"]       = Math.Abs(Convert.ToDecimal(_selectedSale.OldDebt));
                ds.Sale[i]["TransportCost"] = _selectedSale.TransportCost;
                ds.Sale[i]["BillTotal"]     = Math.Abs(Convert.ToDecimal(_selectedSale.PriceTotal));
                ds.Sale[i]["Paid"]          = _selectedSale.Paid;
                ds.Sale[i]["NewDebt"]       = Math.Abs(Convert.ToDecimal(_selectedSale.NewDebt));
                if (_selectedSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_selectedSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["Salesperson"] = _selectedSale.Salesperson.Name;
                ds.Sale[i]["PrintingMan"] = _selectedSale.PrintingMan;

                if (_selectedSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_selectedSale.OldDebt < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                ds.Sale[i]["Address"] = _selectedSale.Client.Address;
                try
                {
                    ToWord toWord = new ToWord(Math.Abs(Convert.ToDecimal(_selectedSale.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();
            _currentWindow.ShowDialog();

            //var dialog = new PrintDialog();
            //dialog.PrintVisual(_currentWindow, "ss");
            //bool? print = dialog.ShowDialog();
            //if (print.HasValue && print.Value)
            //{
            //    string startupPath = Environment.CurrentDirectory;
            //    printorderRPT.Load(startupPath + @"\..\..\PrintingOrderPaperRpt.rpt");
            //    printorderRPT.SetDataSource(ds.Tables["PrintOrder"]);
            //    printorderRPT.Subreports[0].SetDataSource(ds.Tables["PrintOrderRaws"]);
            //    printorderRPT.PrintOptions.PrinterName = dialog.PrintQueue.Name;
            //    try
            //    {
            //        printorderRPT.PrintToPrinter(1, true, 0, 0);
            //    }
            //    catch { }
            //}
        }
Esempio n. 16
0
        private void PrintMethod(string parameter)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DS ds = new DS();

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

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]           = ID;
                ds.Sale[i]["Date"]         = _selectedSale.Date;
                ds.Sale[i]["Client"]       = _selectedSale.Client.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"]    = _selectedSale.Price;
                ds.Sale[i]["OldDebt"]      = Math.Abs(Convert.ToDecimal(_selectedSale.OldDebt));
                ds.Sale[i]["BillTotal"]    = Math.Abs(Convert.ToDecimal(_selectedSale.PriceTotal));
                ds.Sale[i]["Paid"]         = _selectedSale.CashPaid;
                ds.Sale[i]["DiscountPaid"] = _selectedSale.DiscountPaid;
                ds.Sale[i]["NewDebt"]      = Math.Abs(Convert.ToDecimal(_selectedSale.NewDebt));
                if (_selectedSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_selectedSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }

                if (_selectedSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_selectedSale.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();
            _currentWindow.ShowDialog();
        }
        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();
        }
Esempio n. 18
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());
            }
        }
        private async void ExecuteSaveAsync()
        {
            if (NewSupply.Future == true && NewSupplyFuture.Place == null)
            {
                await _currentWindow.ShowMessageAsync("فشل الإضافة", "يجب كتابة مكان الدفع", MessageDialogStyle.Affirmative, new MetroDialogSettings()
                {
                    AffirmativeButtonText = "موافق",
                    DialogMessageFontSize = 25,
                    DialogTitleFontSize   = 30
                });

                return;
            }
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _newSupply.RegistrationDate = _dt;
            _supplyServ.AddSupply(_newSupply);
            int _supplyID = _supplyServ.GetLastSupplyID();

            foreach (var item in _supplyCategories)
            {
                SupplyCategory _supplyCategory = new SupplyCategory
                {
                    CategoryID             = item.CategoryID,
                    Cost                   = item.Cost,
                    CostAfterDiscount      = item.CostAfterDiscount,
                    CostAfterTax           = item.CostAfterTax,
                    CostTotal              = item.CostTotal,
                    CostTotalAfterDiscount = item.CostTotalAfterDiscount,
                    CostTotalAfterTax      = item.CostTotalAfterTax,
                    Discount               = item.Discount,
                    DiscountValue          = item.DiscountValue,
                    DiscountValueTotal     = item.DiscountValueTotal,
                    SupplyID               = _supplyID,
                    Qty           = item.Qty,
                    Tax           = item.Tax,
                    TaxValue      = item.TaxValue,
                    TaxValueTotal = item.TaxValueTotal,
                    Price         = item.Price
                };
                _supplyCategoryServ.AddSupplyCategory(_supplyCategory);

                Category cat = _categoryServ.GetCategory(item.CategoryID);
                if (cat.Qty + item.Qty != 0)
                {
                    cat.Cost = (item.CostTotalAfterDiscount + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty);
                }
                cat.Qty   = cat.Qty + item.Qty;
                cat.Price = item.Price;
                _categoryServ.UpdateCategory(cat);
            }

            if (_newSupply.Future == true)
            {
                _newSupplyFuture.Change   = _newSupply.Change;
                _newSupplyFuture.SupplyID = _supplyID;
                if (_newSupplyFuture.Cheque == false)
                {
                    _newSupplyFuture.ChequeNumber = null;
                }
                _supplyFutureServ.AddSupplyFuture(_newSupplyFuture);
                _placesSuggestions.Add(_newSupplyFuture.Place);
            }
            ClientAccount _account = new ClientAccount
            {
                ClientID         = _newSupply.ClientID,
                Date             = _newSupply.Date,
                RegistrationDate = _dt,
                Statement        = "فاتورة مشتريات رقم " + _supplyID,
                Credit           = _newSupply.CostAfterTax,
                Debit            = _newSupply.CashPaid
            };

            _clientAccountServ.AddAccount(_account);
            if (_newSupply.DiscountPaid != 0 || _newSupply.TotalDiscount != 0)
            {
                _account = new ClientAccount
                {
                    ClientID         = _newSupply.ClientID,
                    Date             = _newSupply.Date,
                    RegistrationDate = _dt,
                    Statement        = "خصومات فاتورة مشتريات رقم " + _supplyID,
                    Credit           = _newSupply.DiscountPaid,
                    Debit            = _newSupply.TotalDiscount
                };
                _clientAccountServ.AddAccount(_account);
            }
            if (_newSupply.CashPaid > 0)
            {
                Safe _safe = new Safe
                {
                    Date             = _newSupply.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مشتريات رقم " + _supplyID + " من العميل : " + _selectedClient.Name,
                    Amount           = -_newSupply.CashPaid,
                    Source           = 3
                };
                _safeServ.AddSafe(_safe);
            }

            DS ds = new DS();

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

            foreach (var item in _supplyCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]         = _supplyID;
                ds.Sale[i]["Date"]       = _newSupply.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.CostAfterTax), 2);
                ds.Sale[i]["TotalPrice"] = Math.Round(Convert.ToDecimal(item.CostTotalAfterTax), 2);
                ds.Sale[i]["BillPrice"]  = Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2);
                ds.Sale[i]["OldDebt"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2));

                ds.Sale[i]["Paid"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.CashPaid + _newSupply.DiscountPaid), 2));
                ds.Sale[i]["NewDebt"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.NewDebt), 2));
                if (_newSupply.NewDebt > 0)
                {
                    ds.Sale[i]["PrintingMan"] = "له";
                }
                else if (_newSupply.NewDebt < 0)
                {
                    ds.Sale[i]["PrintingMan"] = "عليه";
                }

                if (_newSupply.OldDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_newSupply.OldDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["BillTotal"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2));
                if (Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2) > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2) < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                i++;
            }
            ReportWindow rpt       = new ReportWindow();
            SupplyReport supplyRPT = new SupplyReport();

            supplyRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = supplyRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();

            NewSupply            = new Supply();
            NewSupplyCategory    = new SupplyCategoryVM();
            NewSupplyFuture      = new SupplyFuture();
            SupplyCategories     = new ObservableCollection <SupplyCategoryVM>();
            NewSupply.Date       = DateTime.Now;
            NewSupplyFuture.Date = DateTime.Now;
            OldCosts             = new ObservableCollection <SupplyCategory>();
            _currentWindow.ShowDialog();
        }
        private async void NavigateToViewMethodAsync(string destination)
        {
            switch (destination)
            {
            case "Store":
                _currentWindow.Hide();
                new StoreWindow().ShowDialog();
                _currentWindow.Show();
                break;

            case "Client":
                _currentWindow.Hide();
                new ClientWindow().ShowDialog();
                _currentWindow.Show();
                break;

            case "Supply":
                _currentWindow.Hide();
                new SupplyWindow().ShowDialog();
                _currentWindow.Show();
                break;

            case "Sale":
                _currentWindow.Hide();
                new SaleWindow().ShowDialog();
                _currentWindow.Show();
                break;

            case "Spending":
                _currentWindow.Hide();
                new SpendingWindow().ShowDialog();
                _currentWindow.Show();
                break;

            case "Safe":
                _currentWindow.Hide();
                new SafeWindow().ShowDialog();
                _currentWindow.Show();
                break;

            case "User":
                _userDialog.DataContext = this;
                CurrentUser             = userServ.GetUser();
                await _currentWindow.ShowMetroDialogAsync(_userDialog);

                break;

            case "SupplyFuture":
                new SupplyFutureDisplayWindow().ShowDialog();
                break;

            case "Backup":
                _backupDialog.DataContext = this;
                Url = "";
                await _currentWindow.ShowMetroDialogAsync(_backupDialog);

                break;

            case "BackupRestore":
                _restoreBackupDialog.DataContext = this;
                Url = "";
                await _currentWindow.ShowMetroDialogAsync(_restoreBackupDialog);

                break;

            default:
                break;
            }
        }