Example #1
0
        public static void ShowArgInfoControl(ArgInfo argInfo, TemplateInfoControl templateInfoControl, TemplateInfo templateInfo)
        {
            var w = new MetroWindow {
                Height = 430, Width = 600, EnableDWMDropShadow = true, ResizeMode = ResizeMode.NoResize
            };

            w.LostFocus            += (ss, ee) => w.Focus();
            w.Title                 = "参数信息";
            w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            var control = new ArgInfoControl();

            control.Load(argInfo);

            control.OnCancelClose += (sender, args) => w.Close();

            control.OnOkClose += (ss, ee) =>
            {
                if (Tools.UpdateArgConfig(argInfo) != "")
                {
                    return;
                }
                templateInfoControl.Load(templateInfo, true);
                w.Close();
            };

            w.Content = control;
            w.ShowDialog();
        }
Example #2
0
        /// <summary>
        /// Thực hiện thao tác xóa nhóm (Được gọi bởi module RemoveGroup
        /// </summary>
        /// <param name="RemoveContact">Trạng thái xóa bạn bè hay không</param>
        /// <param name="GroupToRemove">Đối tượng chứa thông tin nhóm sẽ xóa</param>
        /// <param name="GroupMoveTo">Đối tượng chứa thông tin nhóm sẽ chuyển bạn bè tới (Mặc định Null)</param>
        public void DoRemoveGroup(bool RemoveContact, FriendGroup GroupToRemove, FriendGroup GroupMoveTo = null)
        {
            //Trường hợp nhóm bị xóa có bạn bè và người dùng muốn xóa bạn bè trong nhóm thì...
            if (GroupToRemove.Friends.Count > 0 && RemoveContact)
            {
                RemoveGroup(GroupToRemove.GroupID, RemoveContact); //Xóa nhóm và tất cả bạn bè trong nhóm
                GroupTree.RemoveGroup(GroupToRemove);              //Xóa nhóm trong cây dữ liệu
                treeFriend.UpdateLayout();
                removeGroupWin.Close();

                return;
            }
            else if (GroupToRemove.Friends.Count == 0)     //Trường hợp nhóm bị xóa không có bạn bè thì..
            {
                RemoveGroup(GroupToRemove.GroupID, false); //Xóa nhóm (Ko thực hiện thao tác xóa bạn bè)
                GroupTree.RemoveGroup(GroupToRemove);      //Xóa nhóm trong cây dữ liệu
                treeFriend.UpdateLayout();
                removeGroupWin.Close();

                return;
            }

            //Trường hợp di chuyển bạn bè tới nhóm mới trước khi xóa
            //Duyệt qua tất cả bạn bè có trong nhóm cần xóa
            foreach (Users child in GroupToRemove.Friends)
            {
                MoveContact(userId, child.UserID, GroupMoveTo.GroupID);  //Chuyển bạn bè sang nhóm mới (Cập nhập trên CSDL)
                GroupTree.MoveFriend(child, GroupToRemove, GroupMoveTo); //Chuyển bạn bè sang nhóm mới trong cây dữ liệu
            }

            GroupTree.RemoveGroup(GroupToRemove); //Xóa nhóm được chỉ định

            treeFriend.UpdateLayout();
            removeGroupWin.Close();
        }
 public void CloseDivisionDetailDialog()
 {
     if (divisionDetailView != null)
     {
         divisionDetailView.Close();
     }
 }
 public void CloseRacerDetailDialog()
 {
     if (racerDetailView != null)
     {
         racerDetailView.Close();
     }
 }
        private void ButtonCreate_Click(TextBox textBoxName, TextBox textBoxVersion, TextBox textBoxDirectory, MetroWindow win)
        {
            if (string.IsNullOrWhiteSpace(textBoxName.Text))
            {
                MessageBox.Show(LocalizedLangExtension.GetString("PleaseEnterName"));
                return;
            }
            if (string.IsNullOrWhiteSpace(textBoxVersion.Text))
            {
                MessageBox.Show(LocalizedLangExtension.GetString("PleaseEnterVersion"));
                return;
            }
            if (string.IsNullOrWhiteSpace(textBoxDirectory.Text.Replace("mod/", "")))
            {
                MessageBox.Show(LocalizedLangExtension.GetString("PleaseEnterDirectory"));
                return;
            }
            if (newTags.Count == 0)
            {
                MessageBox.Show(LocalizedLangExtension.GetString("PleaseSelectTag"));
                return;
            }

            string hoi4          = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + "Paradox Interactive" + "\\" + "Hearts of Iron IV";
            string hoi4ModFile   = hoi4 + "\\" + textBoxDirectory.Text + ".mod";
            string hoi4ModFolder = hoi4 + "\\" + textBoxDirectory.Text;

            //整合模组配置字符串
            string strDec = "";
            string strMod = "";

            strMod += string.Format("name=\"{0}\"\n", textBoxName.Text);
            strMod += string.Format("version=\"{0}\"\n", textBoxVersion.Text);
            strMod += "tags={\n";
            foreach (var item in newTags)
            {
                strMod += string.Format("\t\"{0}\"\n", item);
            }
            strMod += "}\n";
            strDec  = strMod;
            strMod += string.Format("path=\"{0}\"\n", hoi4ModFolder.Replace("\\", "/"));

            FileStream   fs = new FileStream(hoi4ModFile, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));

            sw.Write(strMod);
            sw.Close();
            fs.Close();

            Directory.CreateDirectory(hoi4ModFolder);

            FileStream   fs1 = new FileStream(hoi4ModFolder + "\\" + "descriptor.mod", FileMode.Create);
            StreamWriter sw1 = new StreamWriter(fs1, new UTF8Encoding(false));

            sw1.Write(strDec);
            sw1.Close();
            fs1.Close();

            win.Close();
        }
Example #6
0
 public void CloseDialog()
 {
     if (windowDialog != null)
     {
         windowDialog.Close();
     }
 }
        private async void ExecuteCloseDialogAsync(string parameter)
        {
            switch (parameter)
            {
            case "Backup":
                await _currentWindow.HideMetroDialogAsync(_backupDialog);

                break;

            case "Restore":
                await _currentWindow.HideMetroDialogAsync(_restoreBackupDialog);

                break;

            case "User":
                await _currentWindow.HideMetroDialogAsync(_userDialog);

                break;

            case "Login":
                await _currentWindow.HideMetroDialogAsync(_loginDialog);

                _currentWindow.Close();
                break;

            default:
                break;
            }
        }
Example #8
0
    public void Configure(object parentWindow)
    {
        var win = new MetroWindow()
        {
            Title = "Configuration", Width = 300, Height = 100, WindowStartupLocation = WindowStartupLocation.CenterScreen, Owner = (Window)parentWindow, BorderThickness = new Thickness(0), GlowBrush = Brushes.Black, ResizeMode = ResizeMode.NoResize
        };
        var check = new CheckBox()
        {
            Content = "Add/remove Seymour automatically", Margin = new Thickness(5), IsChecked = ModSettings.ReadSetting <bool>("AutoAddRemove")
        };
        var butt = new Button()
        {
            Content = "Save", Margin = new Thickness(5)
        };
        var stack = new StackPanel()
        {
            Children = { check, butt }, Margin = new Thickness(5)
        };

        butt.Click += (sender, args) =>
        {
            ModSettings.WriteSetting("AutoAddRemove", check.IsChecked);
            win.Close();
        };
        win.Content = stack;
        win.ShowDialog();
    }
        private async void ExecuteCloseDialogAsync(string parameter)
        {
            try
            {
                switch (parameter)
                {
                case "Backup":
                    await currentWindow.HideMetroDialogAsync(backupDialog);

                    break;

                case "Restore":
                    await currentWindow.HideMetroDialogAsync(restoreBackupDialog);

                    break;

                case "startShift":
                    await currentWindow.HideMetroDialogAsync(startShiftDialog);

                    currentWindow.Close();
                    break;

                case "back":
                    await currentWindow.HideMetroDialogAsync(startShiftDialog);

                    LoginModel = new LoginDataModel();
                    loginDialog.DataContext = this;
                    await currentWindow.ShowMetroDialogAsync(loginDialog);

                    break;

                case "Login":
                    await currentWindow.HideMetroDialogAsync(loginDialog);

                    currentWindow.Close();
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        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();
        }
Example #11
0
 /// <summary>
 /// 关闭Popup
 /// </summary>
 /// <param name="obj"></param>
 private void ClosePopup(object obj)
 {
     //多个Popup时需要入栈
     if (popupWindowsStack.Count > 0)
     {
         MetroWindow popupWindow = popupWindowsStack.Pop() as MetroWindow;
         popupWindow.Close();
         popupWindow = null;
         GC.Collect();
     }
 }
Example #12
0
 /// <summary>
 /// 关闭对话框
 /// </summary>
 private void closePopView(bool b)
 {
     if (popupViewStack.Count > 0)
     {
         MetroWindow popupWindow = popupViewStack.Pop() as MetroWindow;
         popupWindow.MouseDown -= PopupWindows_MouseDown;
         popupWindow.Close();
         popupWindow = null;
         GC.Collect();
     }
 }
 private void ExecuteSignOut()
 {
     try
     {
         MainViewModel.IsSignOut = true;
         currentWindow.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Example #14
0
        private void AttemptLogin(object obj)
        {
            PasswordBox pwBox = obj as PasswordBox;


            User u = AuthenticateUser(LoginName, pwBox.Password, PIN);

            if (u != null)
            {
                MainWindow mw = new MainWindow();
                mw.WindowStyle = WindowStyle.SingleBorderWindow;
                mw.WindowState = WindowState.Maximized;

                mw.DataContext       = DesktopApplication.MainViewModel;
                Platform.CurrentUser = u;
                //Get this workstation
                if (DesktopApplication.Librarian.GetItems(typeof(Workstation), new List <RetrievalCriteria>()).Where(x => (x as Workstation).Name == Environment.MachineName).Any())
                {
                    DesktopApplication.MainViewModel.CurrentWorkstation = (Workstation)DesktopApplication.Librarian.GetItems(typeof(Workstation), new List <RetrievalCriteria>()).Where(x => (x as Workstation).Name == Environment.MachineName).First();
                }
                else
                {
                    Workstation w = new Workstation();
                    w.Name = Environment.MachineName;
                    DesktopApplication.Librarian.SaveItem(w);
                    DesktopApplication.MainViewModel.CurrentWorkstation = w;
                    logger.Info("New workstation " + w.Name + " created and saved");
                }

                if (DesktopApplication.Librarian.GetItems(typeof(NucMedPractice), new List <RetrievalCriteria>()).Any())
                {
                    DesktopApplication.CurrentPratice = (NucMedPractice)DesktopApplication.Librarian.GetItems(typeof(NucMedPractice), new List <RetrievalCriteria>()).First();
                }

                iRadiate.Desktop.Common.DesktopApplication.CurrentUser = u;
                iRadiate.Desktop.Common.DesktopApplication.MainWindow  = mw;
                mw.DataContext = DesktopApplication.MainViewModel;
                mw.InitializeComponent();
                mw.Show();
                Properties.Settings.Default.LastLoginName = u.LoginName;
                Properties.Settings.Default.Save();
                MetroWindow element = FindParent <MetroWindow>(pwBox);
                element.Close();
            }
            else
            {
                PopupMessage = "Login details not correct - try again";
                PopupOpen    = true;
                Password     = "";
                PIN          = "";
            }
        }
Example #15
0
 private MetroWindow GetTestWindow()
 {
     if (testWindow != null)
     {
         testWindow.Close();
     }
     testWindow = new MetroWindow()
     {
         Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner, Title = "Another Test...", Width = 500, Height = 300
     };
     testWindow.Closed += (o, args) => testWindow = null;
     return(testWindow);
 }
        public async void CloseWind(string Title, string Message, MessageDialogStyle settings)
        {
            MessageDialogResult result = await wind.ShowMessageAsync(Title, Message);

            if (result == MessageDialogResult.Negative)
            {
                await Task.Run(() => { wind.Close(); });
            }
            else
            {
                return;
            }
            //else return;
        }
        private void butSaveExecute(MetroWindow myWindow)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                MessageBox.Show("Пустое имя");
                return;
            }

            _bridge.AddEvent(new SimpleEventModel(Name, Description, DatePlanned));
            myWindow.Close();

            // Чтобы при повторном открытии приложения не сохрнились старые значения снесем эти
            Name        = null;
            Description = null;
            DatePlanned = DateTime.Now;
        }
Example #18
0
 /// <summary>
 /// 关闭提示框
 /// </summary>
 /// <param name="s"></param>
 /// <param name="e"></param>
 /// <param name="from"></param>
 private static void WinCloseTimer_Elapsed(object s, ElapsedEventArgs e, MetroWindow from)
 {
     try
     {
         if (from != null)
         {
             from.Dispatcher.BeginInvoke(new Action(() =>
             {
                 from.Close();
             }));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("弹出窗体出现异常:" + ex.Message);
     }
 }
Example #19
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 void PopupWindowWithBorder(string title, string text)
 {
     if (m_PopupWin != null)
     {
         m_PopupWin.Close();
     }
     m_PopupWin = new MetroWindow()
     {
         Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner, Title = title, Width = 500, Height = 300
     };
     m_PopupWin.Closed += (o, args) => m_PopupWin = null;
     m_PopupWin.Content = new TextBlock()
     {
         Text = text, FontSize = 28, FontWeight = FontWeights.Light, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center
     };
     m_PopupWin.BorderThickness = new Thickness(1);
     m_PopupWin.GlowBrush       = null;
     m_PopupWin.SetResourceReference(MetroWindow.BorderBrushProperty, "AccentColorBrush");
     m_PopupWin.Show();
 }
Example #21
0
        public NewInjection(Injection Injection = null, Patient patient = null)
        {
            if (window != null)
            {
                window.Close();
            }

            window = this;


            InitializeComponent();
            NewInjectionViewModel vm = new NewInjectionViewModel(Injection);

            DataContext = vm;


            if (Injection == null)
            {
                ThemeManager.Current.ChangeTheme(this, "Light.Green");
                DeleteButton.Visibility    = Visibility.Collapsed;
                DischargeButton.Visibility = Visibility.Collapsed;
                ReAdmitButton.Visibility   = Visibility.Collapsed;
                if (patient != null)
                {
                    vm.selectPatient(patient);
                }
            }
            else
            {
                ThemeManager.Current.ChangeTheme(this, "Light.Red");
                this.Title = "Modify Injection";
                if (Injection.patientStatus == "Discharged")
                {
                    DischargeButton.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ReAdmitButton.Visibility = Visibility.Collapsed;
                }
            }
        }
        public Control CreateControl(MetroWindow metroWindow, ClsLoginModel clsLogin, string menuId)
        {
            switch (menuId)
            {
            case "退出":
                metroWindow.Close();
                return(null);

            case "Bug 反馈":
                Process.Start("http://www.devapplication.com");
                return(null);

            case "关于我们":
                return(new About {
                    Owner = metroWindow
                });

            default:
                return(null);
            }
        }
 /// <summary>
 /// Initializes the database
 /// </summary>
 /// <param name="win">The windwow that calls this task.</param>
 public async void Init(MetroWindow win)
 {
     ActiveWindow = win;
     await ShowProgressDialog(CAP_LOADING, MSG_LOADING_DB);
     OracleTransactions.InitDatabase(
        async (BackgroundWorker worker, Object result) =>
     {
         string msg;
         if (result is Exception)
             msg = (result as Exception).Message;
         else
         {
             this.InitCompleted(result);
             msg = MSG_MEMORY_LOADED;
         }
         await CloseProgressDialog();
         await win.ShowMessageAsync(String.Empty, msg, MessageDialogStyle.Affirmative);
         win.Close();
         if (!(result is Exception) && DatabaseLoaded != null)
             this.DatabaseLoaded();
     });
 }
        private async void Deco()
        {
            var window = Application.Current.Windows.OfType <MetroWindow>().LastOrDefault();

            if (window != null)
            {
                var result = await window.ShowMessageAsync("Avertissement", "Voulez-vous vraiment vous déconnecter ?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                {
                    AffirmativeButtonText = "Oui",
                    NegativeButtonText    = "Non",
                    AnimateHide           = false,
                    AnimateShow           = true
                });

                if (result == MessageDialogResult.Affirmative)
                {
                    VueLogin vl = new VueLogin();
                    vuePrecedente.Show();
                    vuePrecedente.Close();
                    window.Close();
                    vl.Show();
                }
            }
        }
Example #25
0
        async void CloseCommandExecute(CancelEventArgs e)
        {
            if (CloseCommandCanExecute == false)
            {
                e.Cancel = true;
                var result = await _dialogCoordinator.ShowProgressAsync(this, "Even geduld..", "Bezig met afsluiten", true);

                result.Canceled += delegate { result.CloseAsync(); };
                result.SetProgress(0.3);
                await Task.Delay(100);

                result.SetProgress(0.5);
                await Task.Delay(100);

                result.SetProgress(0.7);
                await Task.Delay(100);

                result.SetProgress(1);
                await result.CloseAsync();

                CloseCommandCanExecute = true;
                metroWindow.Close();
            }
        }
Example #26
0
 public void Close()
 {
     _win.Close();
 }
Example #27
0
 private void ConsoleButton_OnClick(object sender, RoutedEventArgs e)
 {
     _logWindow?.Close();
     _logWindow = new LogViewer();
     _logWindow.Show();
 }
Example #28
0
        private void ExecuteSave()
        {
            try
            {
                Mouse.OverrideCursor      = Cursors.Wait;
                _selectedSale.Salesperson = SelectedSalesperson;
                _saleServ.UpdateSale(_selectedSale);
                _safeServ.DeleteSafe(_selectedSale.RegistrationDate);
                _clientAccountServ.DeleteAccount(_selectedSale.RegistrationDate);
                var saleCategories = _saleCategoryServ.GetSaleCategories(_selectedSale.ID);
                foreach (var item in saleCategories)
                {
                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    if (cat.Qty + item.Qty != 0)
                    {
                        cat.Cost = (item.CostTotal + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty);
                    }
                    cat.Qty = cat.Qty + item.Qty;
                    _categoryServ.UpdateCategory(cat);
                }
                _saleCategoryServ.DeleteSaleCategories(ID);
                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     = ID,
                        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         = _selectedSale.ClientID,
                    Date             = _selectedSale.Date,
                    RegistrationDate = _selectedSale.RegistrationDate,
                    Statement        = "فاتورة مبيعات رقم " + ID,
                    Credit           = _selectedSale.CashPaid + _selectedSale.DiscountPaid,
                    Debit            = _selectedSale.Price
                };
                _clientAccountServ.AddAccount(_account);

                if (_selectedSale.CashPaid > 0)
                {
                    Safe _safe = new Safe
                    {
                        Date             = _selectedSale.Date,
                        RegistrationDate = _selectedSale.RegistrationDate,
                        Statement        = "فاتورة مبيعات رقم " + ID + " للعميل: " + _selectedSale.Client.Name,
                        Amount           = _selectedSale.CashPaid,
                        Source           = 4
                    };
                    _safeServ.AddSafe(_safe);
                }
                Mouse.OverrideCursor = null;
                _currentWindow.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #29
0
        private void PrintMethod()
        {
            try
            {
                using (var unitOfWork = new UnitOfWork(new GeneralDBContext()))
                {
                    unitOfWork.Bills.Edit(_selectedBill);
                    unitOfWork.Safes.Remove(d => d.RegistrationDate == _selectedBill.RegistrationDate);
                    Safe safe = new Safe
                    {
                        Amount           = _selectedBill.Total,
                        CanDelete        = false,
                        RegistrationDate = _selectedBill.RegistrationDate,
                        Type             = true,
                        Statement        = $"فاتورة {_selectedBill.ID}",
                        UserID           = (int)_selectedBill.UserID
                    };
                    unitOfWork.Safes.Add(safe);
                    unitOfWork.BillsItems.Remove(s => s.BillID == BillID);
                    foreach (var item in BillItems)
                    {
                        unitOfWork.BillsItems.Add(new BillItem
                        {
                            BillID = BillID,
                            ItemID = item.ItemID,
                            Price  = item.Item.Price,
                            Qty    = item.Qty,
                            Total  = item.Qty * item.Item.Price
                        });
                    }
                    unitOfWork.Complete();

                    Mouse.OverrideCursor = Cursors.Wait;
                    int rnd = new Random().Next(1000, 9999);

                    List <int?> categoriesId = _billItems.Select(s => s.Item.CategoryID).Distinct().ToList();

                    foreach (var categoryId in categoriesId)
                    {
                        DS ds = new DS();
                        ds.Bill.Rows.Clear();
                        int i = 0;

                        foreach (var item in BillItems.Where(w => w.Item.CategoryID == categoryId))
                        {
                            ds.Bill.Rows.Add();
                            ds.Bill[i]["BillID"]    = $"#{rnd}#{_selectedBill.ID}#";
                            ds.Bill[i]["Date"]      = DateTime.Now.ToShortDateString();
                            ds.Bill[i]["Time"]      = DateTime.Now.ToString(" h:mm tt");
                            ds.Bill[i]["Type"]      = _selectedBill.Type;
                            ds.Bill[i]["Details"]   = _selectedBill.Details;
                            ds.Bill[i]["ItemQty"]   = item.Qty;
                            ds.Bill[i]["ItemName"]  = item.Item.Name;
                            ds.Bill[i]["ItemPrice"] = string.Format("{0:0.00}", item.Item.Price);;
                            ds.Bill[i]["BillTotal"] = string.Format("{0:0.00}", Math.Round(Convert.ToDecimal(BillItems.Where(w => w.Item.CategoryID == categoryId).Sum(s => s.Total)), 0));
                            i++;
                        }

                        BillItemsReport billItemsReport = new BillItemsReport();
                        billItemsReport.SetDataSource(ds.Tables["Bill"]);
                        Mouse.OverrideCursor = null;
                        billItemsReport.PrintToPrinter(1, false, 0, 15);
                    }



                    currentWindow.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
        private void ExecuteSave()
        {
            try
            {
                _supplyServ.UpdateSupply(_selectedSupply);
                _safeServ.DeleteSafe(_selectedSupply.RegistrationDate);
                _clientAccountServ.DeleteAccount(_selectedSupply.RegistrationDate);
                var supplyCategories = _supplyCategoryServ.GetSupplyCategories(_selectedSupply.ID);
                foreach (var item in supplyCategories)
                {
                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    if (cat.Qty - item.Qty != 0)
                    {
                        cat.Cost = ((cat.Cost * cat.Qty) - item.CostTotal) / (cat.Qty - item.Qty);
                    }
                    if (cat.Cost < 0)
                    {
                        cat.Cost = 0;
                    }
                    cat.Qty = cat.Qty - item.Qty;
                    _categoryServ.UpdateCategory(cat);
                }
                _supplyCategoryServ.DeleteSupplyCategories(ID);

                foreach (var item in _supplyCategories)
                {
                    SupplyCategory _supplyCategory = new SupplyCategory
                    {
                        CategoryID = item.CategoryID,
                        Cost       = item.Cost,
                        CostTotal  = item.CostTotal,
                        SupplyID   = ID,
                        Qty        = item.Qty,
                        Price      = item.Price
                    };
                    _supplyCategoryServ.AddSupplyCategory(_supplyCategory);

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


                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _selectedSupply.ClientID,
                    Date             = _selectedSupply.Date,
                    RegistrationDate = _selectedSupply.RegistrationDate,
                    Statement        = "فاتورة مشتريات رقم " + ID,
                    Credit           = _selectedSupply.Cost,
                    Debit            = _selectedSupply.CashPaid + _selectedSupply.DiscountPaid
                };
                _clientAccountServ.AddAccount(_account);

                if (_selectedSupply.CashPaid > 0)
                {
                    Safe _safe = new Safe
                    {
                        Date             = _selectedSupply.Date,
                        RegistrationDate = _selectedSupply.RegistrationDate,
                        Statement        = "فاتورة مشتريات رقم " + ID + " من العميل : " + _selectedSupply.Client.Name,
                        Amount           = -_selectedSupply.CashPaid,
                        Source           = 3
                    };
                    _safeServ.AddSafe(_safe);
                }
                _currentWindow.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }