Example #1
0
        private void View()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            answerTextBlock.Text = ddb.SelectRecipe().Count.ToString();
            ddb.Close();
        }
Example #2
0
        /// <summary>
        /// Recupere les 5 meilleurs recettes du meilleur cdr
        /// </summary>
        /// <param name="nb"></param>
        /// <returns></returns>
        private List <Recipe> GetTop5RecipesOfBestCdr(int nb = 5, bool ofWeek = false)
        {
            RecipeCreator bestCdr = GetTop5BestCDR(1, ofWeek).First(); // recupere le meilleur cdr
            DDB           ddb     = new DDB(User.DataBase, User.Username, User.Password);

            BestCDRAllTB.Text = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{bestCdr.Id}'" })[0].Name;
            List <Recipe> recipes = GetTop5Recipes(-1);                 // recupere les meilleurs recettes
            List <Recipe> top5RecipesOfBestCdr = new List <Recipe>();

            ddb.Close();

            nb = (nb == -1) ? recipes.Count() : nb;
            int cpt = 0;

            while (top5RecipesOfBestCdr.Count < nb && cpt < recipes.Count) // recupre les nb premieres
            {
                if (recipes[cpt].NumberCreator.Equals(bestCdr.Id))
                {
                    top5RecipesOfBestCdr.Add(recipes[cpt]);
                }

                cpt++;
            }

            return(top5RecipesOfBestCdr);
        }
        private void btn_TransferCreditorsAccountToNewFiscalYear_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var db             = DDB.NewContext();
                var fiscalYears    = db.tbl_glb_fiscal_year.OrderByDescending(x => x.glb_fiscal_year_id).ToList();
                var lastFiscalYear = fiscalYears.First();
                if (GlobalVariables.current_fiscal_year_id != lastFiscalYear.glb_fiscal_year_id)
                {
                    throw new Exception(string.Format("سال مالی جاری سال {0} و آخرین سال مالی سال {1} می باشد. لطفا با آخرین سال مالی وارد برنامه شوید.", GlobalVariables.current_fiscal_year_name, lastFiscalYear.glb_fiscal_year_name));
                }
                if (fiscalYears.Count == 1)
                {
                    throw new Exception("برنامه تنها یک سال مالی دارد");
                }

                var oldFiscalYear = fiscalYears[1];
                int fine;
                if (!int.TryParse(txtFine.Text, out fine))
                {
                    Messages.ErrorMessage("میزان جریمه را وارد نمائید");
                    return;
                }

                tbl_gnt_creditor.TransferCreditorAccountsToNewfiscalYear(fine, oldFiscalYear.glb_fiscal_year_id, lastFiscalYear.glb_fiscal_year_id);
                Messages.SuccessMessage("انتقال حساب");
            }
            catch (Exception exception)
            {
                Messages.ExceptionMessage(exception);
            }
        }
Example #4
0
        /// <summary>
        /// check if the basket can be created (enough product in stock)
        /// </summary>
        /// <param name="recipes"></param>
        /// <returns></returns>
        public static bool IsPossible(List <Recipe> recipes)
        {
            bool           isPossible = true;
            DDB            ddB        = new DDB(User.DataBase, User.Username, User.Password);
            List <Product> products   = ddB.SelectProduct();

            foreach (Recipe recipe in recipes)
            {
                List <ProductComposition> productCompositions = ddB.SelectProductComposition(new string[] { "nomRecette" }, new string[] { $"'{recipe.Name}'" });
                foreach (ProductComposition productComposition in productCompositions)
                {
                    Product product = products.FirstOrDefault(x => x.Reference == productComposition.RefProduct);
                    if (product != null)
                    {
                        product.CurrentQuantity -= productComposition.Quantity;
                        if (product.CurrentQuantity < 0)
                        {
                            isPossible = false;
                        }
                    }
                }
            }
            ddB.Close();

            return(isPossible);
        }
 private void DeleteFromCreditorAccount()
 {
     try
     {
         var db             = DDB.NewContext();
         var accountRecords = db.tbl_gnt_creditor_account.Where(x => x.gnt_creditor_account_gnt_service_id == selectedRecord.gnt_service_id);
         if (accountRecords.Count() > 0)
         {
             foreach (var record in accountRecords)
             {
                 db.tbl_gnt_creditor_account.DeleteObject(record);
             }
             db.SaveChanges();
             Messages.InformationMessage("مبلغ این سند از حساب سهامدار کسر شد");
         }
         else
         {
             Messages.WarningMessage("این سند در حساب سهامدار یافت نشد");
         }
     }
     catch (Exception exception)
     {
         Messages.ErrorMessage("بروز خطا هنگام به روز رسانی حساب سهامدار. متن کامل خطا : \r\n" + exception.CompleteMessages());
     }
 }
Example #6
0
        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            if (ddb.SelectRecipeCreator(new string[] { "numero" }, new string[] { $"'{User.ConnectedClient.PhoneNumber}'" }).Count == 0) //if is not a cdr
            {
                ddb.InsertRecipeCreator(User.ConnectedClient.PhoneNumber);
            }
            DoubleContainer <string, RecipeType> recipeType = CategoryComboBox.SelectedItem as DoubleContainer <string, RecipeType>;

            ddb.InsertRecipe(NameTextBox.Text, recipeType.OtherValue, DescTextBox.Text, User.ConnectedClient.PhoneNumber, Convert.ToInt32(PriceCB.SelectedValue),
                             HealthyCB.IsChecked == true ? true : false,
                             BioCB.IsChecked == true ? true : false,
                             VeganCB.IsChecked == true ? true : false,
                             ChimiCB.IsChecked == true ? true : false);                                  //operator ter because it's bool? not bool

            foreach (DoubleContainer <Product, ProductComposition> productComposition in this._products) // if the user change the name after adding the product composition
            {
                productComposition.OtherValue.RecipeName = NameTextBox.Text;
                ddb.Insert <ProductComposition>(productComposition.OtherValue);
            }
            ddb.Close();
            MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            mainWindow.DataContext = new MainMenu();
        }
Example #7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            User.DataBase = "cook";
            User.Username = usernameTB.Text;
            User.Password = passwordTB.Text;
            File.WriteAllLines(User.Path, new string[] { User.DataBase, User.Username, User.Password });

            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            //ddb.Command("drop database cook;");
            //ddb.Command($"create database cook;");
            string[] create = File.ReadAllLines("creation.sql");

            foreach (string line in create) //Excute the sql script
            {
                ddb.Command(line);          //creation of the table
            }
            string[] fill = File.ReadAllLines("peuplement.sql");

            foreach (string line in fill)
            {
                ddb.Command(line);                                            //fill the table
            }
            ddb.SelectRecipe().ForEach(x => Stock.UpdateMinMaxQuantities(x)); //a rajouter a moment des commandes
            ddb.SelectRecipe().ForEach(x => Stock.ManageOrder(x));
            Stock.RottenProducts();

            ddb.Close();
            MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            mainWindow.DataContext = new MainMenu();
        }
Example #8
0
        /// <summary>
        /// Sort the list of recipes depending on the name of the 'sender'
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Sort_Changed(object sender, RoutedEventArgs e)
        {
            DDB           ddb           = new DDB(User.DataBase, User.Username, User.Password);
            List <Recipe> listeRecettes = ddb.SelectRecipe();

            ddb.Close();

            if (((CheckBox)sender).Name.Equals(AlphabetiqueCB.Name))
            {
                listeRecettes.Sort((a, b) => (a.Name.CompareTo(b.Name)));
                NoteCB.IsChecked = false;
                PrixCB.IsChecked = false;
            }
            if (((CheckBox)sender).Name.Equals(NoteCB.Name))
            {
                listeRecettes.Sort((a, b) => (a.Rating.CompareTo(b.Rating)));
                AlphabetiqueCB.IsChecked = false;
                PrixCB.IsChecked         = false;
            }
            if (((CheckBox)sender).Name.Equals(PrixCB.Name))
            {
                listeRecettes.Sort((a, b) => (a.Price.CompareTo(b.Price)));
                NoteCB.IsChecked         = false;
                AlphabetiqueCB.IsChecked = false;
            }

            DataContext = new RecipesViewer(listeRecettes);
        }
Example #9
0
        /// <summary>
        /// Method appele a chaque commande. Elle permet de simuler la gestion des stockes
        /// </summary>
        /// <param name="recipe"></param>
        public static void ManageOrder(Recipe recipe, bool isOrder = false)
        {
            DDB ddB = new DDB(User.DataBase, User.Username, User.Password);

            List <ProductComposition> productCompositions = ddB.SelectProductComposition(new string[] { "nomRecette" }, new string[] { "'" + recipe.Name + "'" });

            List <Product> products = new List <Product>();

            productCompositions.ForEach(p => products.AddRange(ddB.SelectProduct(new string[] { "ref" }, new string[] { "'" + p.RefProduct + "'" })));

            products.ForEach(p => ConsumeProduct(p, productCompositions));

            if (isOrder)
            {
                recipe.Rating++; //equivalent à la notation de la recette à chaque fois que quelqu'un commande on l'incremente
                if (recipe.Rating == 10)
                {
                    recipe.Price += 2;
                }
                if (recipe.Rating == 50)
                {
                    recipe.Price     += 5;
                    recipe.IsTrending = true; //isTrending = true veut dire que la recette a été commandé plus de 50 fois
                }
                ddB.UpdateRecipe(recipe, new string[] { "nom" }, new string[] { $"'{recipe.Name}'" });
                PayingCDR(recipe);
            }

            ddB.Close();
        }
Example #10
0
 /// <summary>
 ///     .این تابع یک رکورد را دریافت می کند و آن را از جدول مربوط حذف می نماید
 /// </summary>
 /// <param name="recordForDelete" >
 ///     .رکوردی که می خواهید حذف می شود
 /// </param>
 /// <returns></returns>
 public Boolean DeleteRecord(RT recordForDelete, params Boolean[] askForConfirm)
 {
     try
     {
         if (recordForDelete == null)
         {
             Messages.InformationMessage("یک ردیف را برای حذف انتخاب کنید");
             return(false);
         }
         if ((askForConfirm.Length == 0) || (askForConfirm.Length == 1 && askForConfirm[0] == true))
         {
             MessageBoxResult r = Messages.DeleteMessage("ردیف");
             if (r == MessageBoxResult.No)
             {
                 return(false);
             }
         }
         return(DDB.CustomStoredProcedure(recordForDelete, StoredProcedures.Delete));
     }
     catch (System.Exception e)
     {
         Messages.ErrorMessage(e.Message);
     }
     return(false);
 }
Example #11
0
        private void btnPrintAllCreditors_Click(object sender, RoutedEventArgs e)
        {
            var db   = DDB.NewContext();
            var list = db.tbl_gnt_creditor.OrderBy(x => x.gnt_creditor_child_code).ToList();

            ShowAllCreditorsReport(list);
        }
Example #12
0
        public MainMenu()
        {
            InitializeComponent();
            LoadSettings();
            CDRButton.Visibility    = User.ConnectedClient != null ? Visibility.Visible : Visibility.Hidden;
            BaksetButton.Visibility = User.ConnectedClient != null ? Visibility.Visible : Visibility.Hidden;
            //DataContext = new WelcomePage();
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            if (ddb.IsOpen)
            {
                DataContext = new RecipesViewer(ddb.SelectRecipe());
                if (User.ConnectedClient != null)
                {
                    ClientTextBlock.Text = User.ConnectedClient.Name;
                    //ClientButton.IsEnabled = false; if we want to disconnect from the client account
                }
            }
            else
            {
                DemoButton.Visibility   = Visibility.Hidden;
                UserGrid.Visibility     = Visibility.Hidden;
                FilterBorder.Visibility = Visibility.Hidden;
                DataContext             = new BDDLogin();
            }
        }
Example #13
0
        private void btnPrintDebtors_Click(object sender, RoutedEventArgs e)
        {
            var db   = DDB.NewContext();
            var list = db.tbl_gnt_creditor.OrderBy(x => x.gnt_creditor_child_code).ToList().Where(x => x.gnt_creditor_account_remaining < 0).ToList();

            ShowDebtorsReport(list);
        }
Example #14
0
        private void btnPrintHelps_Click(object sender, RoutedEventArgs e)
        {
            var db   = DDB.NewContext();
            var list = db.tbl_gnt_creditor.Where(x => x.gnt_creditor_account_number.Trim() != "").ToList();

            ShowHelpsReport(list);
        }
Example #15
0
        private TextBlock GetTextBlock(ProductComposition productCompo, SolidColorBrush colorBrush, FontWeight fontWeight, int fontSize = 12)
        {
            DDB     ddb     = new DDB(User.DataBase, User.Username, User.Password);
            Product product = ddb.SelectProduct(new string[] { "ref" }, new string[] { $"'{productCompo.RefProduct}'" })[0];
            string  text    = productCompo.RefProduct;

            if (text.Length > 10)
            {
                string tmp = string.Empty;
                for (int i = 0;
                     i < 10;
                     i++)
                {
                    tmp += text[i];
                }
                text = $"{tmp} ...";
            }
            return(new TextBlock()
            {
                Text = $"{product.Name} {productCompo.Quantity}{product.Unit}",
                Margin = new Thickness(10),
                FontSize = fontSize,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Background = new SolidColorBrush(Colors.Transparent),
                FontWeight = fontWeight,
                Foreground = colorBrush,
                FontFamily = titleTB.FontFamily
            });
        }
        private void txt_gnt_deal_article_sell_jeribMinuteSecond_LostFocus(object sender, RoutedEventArgs e)
        {
            var dataBase = DDB.NewContext();

            if (selectedArticle.gnt_deal_article_gnt_water_id == 0)
            {
                return;
            }
            var ownership = new tbl_gnt_ownership();

            ownership.tbl_gnt_water        = dataBase.tbl_gnt_water.Where(w => w.gnt_water_id == selectedArticle.gnt_deal_article_gnt_water_id).First();
            ownership.gnt_ownership_jerib  = selectedArticle.gnt_deal_article_sell_jerib;
            ownership.gnt_ownership_minute = selectedArticle.gnt_deal_article_sell_minute;
            ownership.gnt_ownership_second = selectedArticle.gnt_deal_article_sell_second;

            selectedArticle.gnt_deal_article_sell_jerib           = ownership.gnt_ownership_correct_jerib;
            selectedArticle.gnt_deal_article_sell_minute          = ownership.gnt_ownership_correct_minute;
            selectedArticle.gnt_deal_article_sell_second          = ownership.gnt_ownership_correct_second;
            selectedArticle.gnt_deal_article_sell_credit          = ownership.gnt_ownership_correct_credit;
            selectedArticle.gnt_deal_article_sell_earth           = ownership.gnt_ownership_correct_earth;
            selectedArticle.gnt_deal_article_sell_all_price       = (int)Math.Round(selectedArticle.gnt_deal_article_sell_credit * selectedArticle.gnt_deal_article_sell_price);
            selectedArticle.gnt_deal_article_sell_agreement_price = selectedArticle.gnt_deal_article_sell_all_price;

            MoveCollectionViewArticle();
        }
Example #17
0
        private void FillCDROfTheWeek()
        {
            RecipeCreator bestCdrOfWeek = GetTop5BestCDR(1, true).First();
            DDB           ddb           = new DDB();

            CDRWeekTB.Text = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{bestCdrOfWeek.Id}'" }).First().Name;
            ddb.Close();
        }
Example #18
0
        private Client GetClient(string numberCreator)
        {
            DDB    ddb    = new DDB(User.DataBase, User.Username, User.Password);
            Client client = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{numberCreator}'" })[0];

            ddb.Close();
            return(client);
        }
Example #19
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            DDB     ddb     = new DDB(User.DataBase, User.Username, User.Password);
            Product product = ProductsComboBox.SelectedItem as Product;

            this._products.Add(new DoubleContainer <Product, ProductComposition>(product, new ProductComposition(Guid.NewGuid().ToString(), Convert.ToInt32(QuantityTextBox.Text), product.Reference, NameTextBox.Text)));
            InitializeProducts();
        }
Example #20
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     DDB.Connect();
     this.WindowState = WindowState.Maximized;
     ChangeBranchOperation();
     HideInaccessibleButtons();
     //CreateUserAccessItemsFromButtons();
 }
Example #21
0
        private int GetOrder(string recipeName)
        {
            DDB ddb      = new DDB(User.DataBase, User.Username, User.Password);
            int nbOrders = ddb.SelectOrder(new string[] { "nomRecette" }, new string[] { $"'{recipeName}'" }).Count();

            ddb.Close();
            return(nbOrders);
        }
Example #22
0
        public override void LoadData()
        {
            try
            {
                var levels  = FindSelectedLevels();
                var context = DDB.NewContext();
                List <tbl_acc_document_article> articles = new List <tbl_acc_document_article>();
                foreach (var document in ref_acc_document.ListAfterChange)
                {
                    articles.AddRange(context.tbl_acc_document_article.Where(x => x.acc_document_article_acc_document_id == document.acc_document_id).ToList());
                }

                allRecords = new List <stp_acc_rpt_cover_selResult>();

                foreach (int levelNo in levels)
                {
                    foreach (var article in articles)
                    {
                        var parentCA = GetParentCA(article, levelNo);
                        if (parentCA == null)
                        {
                            continue;
                        }
                        var findedCA = allRecords.Find(x => x.acc_rpt_cover_acc_chart_account_id == parentCA.acc_rpt_cover_acc_chart_account_id);
                        if (findedCA == null)
                        {
                            allRecords.Add(parentCA);
                        }
                        else
                        {
                            findedCA.acc_rpt_cover_acc_chart_account_credit += parentCA.acc_rpt_cover_acc_chart_account_credit;
                            findedCA.acc_rpt_cover_acc_chart_account_debt   += parentCA.acc_rpt_cover_acc_chart_account_debt;
                        }
                    }
                }
                foreach (var record in allRecords)
                {
                    record.acc_rpt_cover_remaining = Math.Abs(record.acc_rpt_cover_acc_chart_account_debt.Value - record.acc_rpt_cover_acc_chart_account_credit.Value);
                    if (record.acc_rpt_cover_acc_chart_account_debt > record.acc_rpt_cover_acc_chart_account_credit)
                    {
                        record.acc_rpt_cover_specification = "بدهکار";
                    }
                    else if (record.acc_rpt_cover_acc_chart_account_debt < record.acc_rpt_cover_acc_chart_account_credit)
                    {
                        record.acc_rpt_cover_specification = "بستانکار";
                    }
                    else
                    {
                        record.acc_rpt_cover_specification = "تراز";
                    }
                }
                allRecords = allRecords.OrderBy(x => x.acc_rpt_cover_acc_chart_account_code).ToList();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Example #23
0
        public void SupplierSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Supplier> suppliers = ddb.SelectSupplier();

            ddb.Close();
            Assert.AreEqual(0, suppliers.Count);
        }
Example #24
0
        private void LoadProducts()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            this._allProducts = ddb.SelectProduct();

            ProductsComboBox.ItemsSource   = this._allProducts;
            ProductsComboBox.SelectedIndex = 0;
        }
Example #25
0
        public void OrderSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Order> orders = ddb.SelectOrder();

            ddb.Close();
            Assert.AreEqual(0, orders.Count);
        }
Example #26
0
        public void CDRSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <RecipeCreator> cdrs = ddb.SelectRecipeCreator();

            ddb.Close();
            Assert.AreEqual(0, cdrs.Count);
        }
Example #27
0
        public void RecipeSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Recipe> recipes = ddb.SelectRecipe();

            ddb.Close();
            Assert.AreEqual(0, recipes.Count);
        }
Example #28
0
        public void ProductSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Product> products = ddb.SelectProduct();

            ddb.Close();
            Assert.AreEqual(0, products.Count);
        }
        private void btnCopyCosts_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var db = DDB.NewContext();

                var fiscalYears   = db.tbl_glb_fiscal_year.OrderByDescending(x => x.glb_fiscal_year_id).ToList();
                var newFiscalYear = fiscalYears.First();
                if (GlobalVariables.current_fiscal_year_id != newFiscalYear.glb_fiscal_year_id)
                {
                    throw new Exception(string.Format("سال مالی جاری سال {0} و آخرین سال مالی سال {1} می باشد. لطفا با آخرین سال مالی وارد برنامه شوید.", GlobalVariables.current_fiscal_year_name, newFiscalYear.glb_fiscal_year_name));
                }
                if (fiscalYears.Count == 1)
                {
                    throw new Exception("برنامه تنها یک سال مالی دارد");
                }
                var oldFiscalYear = fiscalYears[1];

                if (txtIncrease.Text.Trim() == "")
                {
                    Messages.ErrorMessage("لطفا میزان افزایش تعرفه را وارد نمایید ");
                    return;
                }

                var result = Messages.QuestionMessage_YesNo(string.Format("آیا مایلید تعرفه های دوره مالی {0} به تعرفه های دوره مالی {1} اضافه شود؟", oldFiscalYear.glb_fiscal_year_name, newFiscalYear.glb_fiscal_year_name));
                if (result != MessageBoxResult.Yes)
                {
                    return;
                }

                var oldCosts = db.tbl_gnt_cost_type.Where
                               (
                    x =>
                    x.gnt_cost_type_glb_fiscal_year_id == oldFiscalYear.glb_fiscal_year_id &&
                    x.gnt_cost_type_glb_branch_id == GlobalVariables.current_branch_id
                               );
                int increase = int.Parse(txtIncrease.Text);
                foreach (var oldCost in oldCosts)
                {
                    var newCost = new tbl_gnt_cost_type()
                    {
                        gnt_cost_type_glb_branch_id      = oldCost.gnt_cost_type_glb_branch_id,
                        gnt_cost_type_glb_fiscal_year_id = newFiscalYear.glb_fiscal_year_id,
                        gnt_cost_type_is_public          = oldCost.gnt_cost_type_is_public,
                        gnt_cost_type_name  = oldCost.gnt_cost_type_name,
                        gnt_cost_type_price = (int)Math.Round(oldCost.gnt_cost_type_price * (1 + (double)increase / 100)),
                    };
                    db.tbl_gnt_cost_type.AddObject(newCost);
                }
                db.SaveChanges();
                Messages.SuccessMessage("انتقال تعرفه ها");
            }
            catch (Exception exception)
            {
                Messages.ErrorMessage(exception.CompleteMessages());
            }
        }
Example #30
0
        public void ClientSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Client> clients = ddb.SelectClient();

            ddb.Close();
            Assert.AreEqual(0, clients.Count);
        }